@@ -30,71 +30,71 @@ |
||
30 | 30 | */ |
31 | 31 | class SurnamesList implements RequestHandlerInterface |
32 | 32 | { |
33 | - use ViewResponseTrait; |
|
33 | + use ViewResponseTrait; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var PatronymicLineageModule $module |
|
37 | - */ |
|
38 | - private $module; |
|
35 | + /** |
|
36 | + * @var PatronymicLineageModule $module |
|
37 | + */ |
|
38 | + private $module; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var IndividualListService $indilist_service |
|
42 | - */ |
|
43 | - private $indilist_service; |
|
40 | + /** |
|
41 | + * @var IndividualListService $indilist_service |
|
42 | + */ |
|
43 | + private $indilist_service; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Constructor for SurnamesList Request Handler |
|
47 | - * |
|
48 | - * @param ModuleService $module_service |
|
49 | - * @param IndividualListService $indilist_service |
|
50 | - */ |
|
51 | - public function __construct(ModuleService $module_service, IndividualListService $indilist_service) |
|
52 | - { |
|
53 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
54 | - $this->indilist_service = $indilist_service; |
|
55 | - } |
|
45 | + /** |
|
46 | + * Constructor for SurnamesList Request Handler |
|
47 | + * |
|
48 | + * @param ModuleService $module_service |
|
49 | + * @param IndividualListService $indilist_service |
|
50 | + */ |
|
51 | + public function __construct(ModuleService $module_service, IndividualListService $indilist_service) |
|
52 | + { |
|
53 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
54 | + $this->indilist_service = $indilist_service; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
60 | - */ |
|
61 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
62 | - { |
|
63 | - if ($this->module === null) { |
|
64 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
65 | - } |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
60 | + */ |
|
61 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
62 | + { |
|
63 | + if ($this->module === null) { |
|
64 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
65 | + } |
|
66 | 66 | |
67 | - $tree = $request->getAttribute('tree'); |
|
68 | - assert($tree instanceof Tree); |
|
67 | + $tree = $request->getAttribute('tree'); |
|
68 | + assert($tree instanceof Tree); |
|
69 | 69 | |
70 | - $initial = $request->getAttribute('alpha'); |
|
71 | - $initials_list = collect($this->indilist_service->surnameAlpha(false, false, I18N::locale())) |
|
72 | - ->reject(function ($count, $initial) { |
|
70 | + $initial = $request->getAttribute('alpha'); |
|
71 | + $initials_list = collect($this->indilist_service->surnameAlpha(false, false, I18N::locale())) |
|
72 | + ->reject(function ($count, $initial) { |
|
73 | 73 | |
74 | - return $initial === '@' || $initial === ','; |
|
75 | - }); |
|
74 | + return $initial === '@' || $initial === ','; |
|
75 | + }); |
|
76 | 76 | |
77 | - $show_all = $request->getQueryParams()['show_all'] ?? 'no'; |
|
77 | + $show_all = $request->getQueryParams()['show_all'] ?? 'no'; |
|
78 | 78 | |
79 | - if ($show_all === 'yes') { |
|
80 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
81 | - $surnames = $this->indilist_service->surnames('', '', false, false, I18N::locale()); |
|
82 | - } elseif ($initial !== null && mb_strlen($initial) == 1) { |
|
83 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
84 | - $surnames = $this->indilist_service->surnames('', $initial, false, false, I18N::locale()); |
|
85 | - } else { |
|
86 | - $title = I18N::translate('Patronymic Lineages'); |
|
87 | - $surnames = []; |
|
88 | - } |
|
79 | + if ($show_all === 'yes') { |
|
80 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
81 | + $surnames = $this->indilist_service->surnames('', '', false, false, I18N::locale()); |
|
82 | + } elseif ($initial !== null && mb_strlen($initial) == 1) { |
|
83 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
84 | + $surnames = $this->indilist_service->surnames('', $initial, false, false, I18N::locale()); |
|
85 | + } else { |
|
86 | + $title = I18N::translate('Patronymic Lineages'); |
|
87 | + $surnames = []; |
|
88 | + } |
|
89 | 89 | |
90 | - return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
91 | - 'title' => $title, |
|
92 | - 'module' => $this->module, |
|
93 | - 'tree' => $tree, |
|
94 | - 'initials_list' => $initials_list, |
|
95 | - 'initial' => $initial, |
|
96 | - 'show_all' => $show_all, |
|
97 | - 'surnames' => $surnames |
|
98 | - ]); |
|
99 | - } |
|
90 | + return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
91 | + 'title' => $title, |
|
92 | + 'module' => $this->module, |
|
93 | + 'tree' => $tree, |
|
94 | + 'initials_list' => $initials_list, |
|
95 | + 'initial' => $initial, |
|
96 | + 'show_all' => $show_all, |
|
97 | + 'surnames' => $surnames |
|
98 | + ]); |
|
99 | + } |
|
100 | 100 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | $initial = $request->getAttribute('alpha'); |
71 | 71 | $initials_list = collect($this->indilist_service->surnameAlpha(false, false, I18N::locale())) |
72 | - ->reject(function ($count, $initial) { |
|
72 | + ->reject(function($count, $initial) { |
|
73 | 73 | |
74 | 74 | return $initial === '@' || $initial === ','; |
75 | 75 | }); |
@@ -77,17 +77,17 @@ discard block |
||
77 | 77 | $show_all = $request->getQueryParams()['show_all'] ?? 'no'; |
78 | 78 | |
79 | 79 | if ($show_all === 'yes') { |
80 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
80 | + $title = I18N::translate('Patronymic Lineages').' — '.I18N::translate('All'); |
|
81 | 81 | $surnames = $this->indilist_service->surnames('', '', false, false, I18N::locale()); |
82 | 82 | } elseif ($initial !== null && mb_strlen($initial) == 1) { |
83 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
83 | + $title = I18N::translate('Patronymic Lineages').' — '.$initial; |
|
84 | 84 | $surnames = $this->indilist_service->surnames('', $initial, false, false, I18N::locale()); |
85 | 85 | } else { |
86 | - $title = I18N::translate('Patronymic Lineages'); |
|
86 | + $title = I18N::translate('Patronymic Lineages'); |
|
87 | 87 | $surnames = []; |
88 | 88 | } |
89 | 89 | |
90 | - return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
90 | + return $this->viewResponse($this->module->name().'::surnames-page', [ |
|
91 | 91 | 'title' => $title, |
92 | 92 | 'module' => $this->module, |
93 | 93 | 'tree' => $tree, |
@@ -31,66 +31,66 @@ |
||
31 | 31 | */ |
32 | 32 | class LineagesPage implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
34 | + use ViewResponseTrait; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var PatronymicLineageModule $module |
|
38 | - */ |
|
39 | - private $module; |
|
36 | + /** |
|
37 | + * @var PatronymicLineageModule $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var IndividualListService $indilist_service |
|
43 | - */ |
|
44 | - private $indilist_service; |
|
41 | + /** |
|
42 | + * @var IndividualListService $indilist_service |
|
43 | + */ |
|
44 | + private $indilist_service; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Constructor for LineagesPage Request handler |
|
48 | - * |
|
49 | - * @param ModuleService $module_service |
|
50 | - * @param IndividualListService $indilist_service |
|
51 | - */ |
|
52 | - public function __construct(ModuleService $module_service, IndividualListService $indilist_service) |
|
53 | - { |
|
54 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
55 | - $this->indilist_service = $indilist_service; |
|
56 | - } |
|
46 | + /** |
|
47 | + * Constructor for LineagesPage Request handler |
|
48 | + * |
|
49 | + * @param ModuleService $module_service |
|
50 | + * @param IndividualListService $indilist_service |
|
51 | + */ |
|
52 | + public function __construct(ModuleService $module_service, IndividualListService $indilist_service) |
|
53 | + { |
|
54 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
55 | + $this->indilist_service = $indilist_service; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | - */ |
|
62 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | - { |
|
64 | - if ($this->module === null) { |
|
65 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
66 | - } |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | + */ |
|
62 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | + { |
|
64 | + if ($this->module === null) { |
|
65 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
66 | + } |
|
67 | 67 | |
68 | - $tree = $request->getAttribute('tree'); |
|
69 | - assert($tree instanceof Tree); |
|
68 | + $tree = $request->getAttribute('tree'); |
|
69 | + assert($tree instanceof Tree); |
|
70 | 70 | |
71 | - $surname = $request->getAttribute('surname'); |
|
71 | + $surname = $request->getAttribute('surname'); |
|
72 | 72 | |
73 | - $initial = mb_substr($surname, 0, 1); |
|
74 | - $initials_list = collect($this->indilist_service->surnameAlpha(false, false, I18N::locale())) |
|
75 | - ->reject(function ($count, $initial) { |
|
73 | + $initial = mb_substr($surname, 0, 1); |
|
74 | + $initials_list = collect($this->indilist_service->surnameAlpha(false, false, I18N::locale())) |
|
75 | + ->reject(function ($count, $initial) { |
|
76 | 76 | |
77 | - return $initial === '@' || $initial === ','; |
|
78 | - }); |
|
77 | + return $initial === '@' || $initial === ','; |
|
78 | + }); |
|
79 | 79 | |
80 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
80 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
81 | 81 | |
82 | - $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
82 | + $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
83 | 83 | |
84 | - return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
85 | - 'title' => $title, |
|
86 | - 'module' => $this->module, |
|
87 | - 'tree' => $tree, |
|
88 | - 'initials_list' => $initials_list, |
|
89 | - 'initial' => $initial, |
|
90 | - 'show_all' => 'no', |
|
91 | - 'surname' => $surname, |
|
92 | - 'lineages' => $lineages, |
|
93 | - 'nb_lineages' => $lineages->count() |
|
94 | - ]); |
|
95 | - } |
|
84 | + return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
85 | + 'title' => $title, |
|
86 | + 'module' => $this->module, |
|
87 | + 'tree' => $tree, |
|
88 | + 'initials_list' => $initials_list, |
|
89 | + 'initial' => $initial, |
|
90 | + 'show_all' => 'no', |
|
91 | + 'surname' => $surname, |
|
92 | + 'lineages' => $lineages, |
|
93 | + 'nb_lineages' => $lineages->count() |
|
94 | + ]); |
|
95 | + } |
|
96 | 96 | } |
@@ -72,16 +72,16 @@ |
||
72 | 72 | |
73 | 73 | $initial = mb_substr($surname, 0, 1); |
74 | 74 | $initials_list = collect($this->indilist_service->surnameAlpha(false, false, I18N::locale())) |
75 | - ->reject(function ($count, $initial) { |
|
75 | + ->reject(function($count, $initial) { |
|
76 | 76 | |
77 | 77 | return $initial === '@' || $initial === ','; |
78 | 78 | }); |
79 | 79 | |
80 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
80 | + $title = I18N::translate('Patronymic Lineages').' — '.$surname; |
|
81 | 81 | |
82 | 82 | $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
83 | 83 | |
84 | - return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
84 | + return $this->viewResponse($this->module->name().'::lineages-page', [ |
|
85 | 85 | 'title' => $title, |
86 | 86 | 'module' => $this->module, |
87 | 87 | 'tree' => $tree, |
@@ -33,86 +33,86 @@ |
||
33 | 33 | */ |
34 | 34 | class PatronymicLineageModule extends AbstractModuleMaj implements ModuleListInterface, ModuleGlobalInterface |
35 | 35 | { |
36 | - use ModuleListTrait; |
|
37 | - use ModuleGlobalTrait; |
|
36 | + use ModuleListTrait; |
|
37 | + use ModuleGlobalTrait; |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritDoc} |
|
41 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
42 | - */ |
|
43 | - public function title(): string |
|
44 | - { |
|
45 | - return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages'); |
|
46 | - } |
|
39 | + /** |
|
40 | + * {@inheritDoc} |
|
41 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
42 | + */ |
|
43 | + public function title(): string |
|
44 | + { |
|
45 | + return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages'); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
51 | - */ |
|
52 | - public function description(): string |
|
53 | - { |
|
54 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
55 | - return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.'); |
|
56 | - } |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
51 | + */ |
|
52 | + public function description(): string |
|
53 | + { |
|
54 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
55 | + return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.'); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes() |
|
61 | - */ |
|
62 | - public function loadRoutes(Map $router): void |
|
63 | - { |
|
64 | - $router->attach('', '', static function (Map $router) { |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes() |
|
61 | + */ |
|
62 | + public function loadRoutes(Map $router): void |
|
63 | + { |
|
64 | + $router->attach('', '', static function (Map $router) { |
|
65 | 65 | |
66 | - $router->attach('', '/module-maj/lineages', static function (Map $router) { |
|
66 | + $router->attach('', '/module-maj/lineages', static function (Map $router) { |
|
67 | 67 | |
68 | - $router->attach('', '/Page', static function (Map $router) { |
|
68 | + $router->attach('', '/Page', static function (Map $router) { |
|
69 | 69 | |
70 | - $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class); |
|
71 | - $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class); |
|
72 | - }); |
|
73 | - }); |
|
74 | - }); |
|
75 | - } |
|
70 | + $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class); |
|
71 | + $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class); |
|
72 | + }); |
|
73 | + }); |
|
74 | + }); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * {@inheritDoc} |
|
79 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
80 | - */ |
|
81 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
82 | - { |
|
83 | - $surname = $parameters['surname'] ?? ''; |
|
77 | + /** |
|
78 | + * {@inheritDoc} |
|
79 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
80 | + */ |
|
81 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
82 | + { |
|
83 | + $surname = $parameters['surname'] ?? ''; |
|
84 | 84 | |
85 | - $xref = app(ServerRequestInterface::class)->getAttribute('xref', ''); |
|
86 | - if ($xref !== '' && $individual = Factory::individual()->make($xref, $tree)) { |
|
87 | - $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname']; |
|
88 | - } |
|
85 | + $xref = app(ServerRequestInterface::class)->getAttribute('xref', ''); |
|
86 | + if ($xref !== '' && $individual = Factory::individual()->make($xref, $tree)) { |
|
87 | + $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname']; |
|
88 | + } |
|
89 | 89 | |
90 | - if ($surname !== '') { |
|
91 | - return route(LineagesPage::class, [ |
|
92 | - 'tree' => $tree->name(), |
|
93 | - 'surname' => $surname |
|
94 | - ] + $parameters); |
|
95 | - } |
|
96 | - return route(SurnamesList::class, [ |
|
97 | - 'tree' => $tree->name() |
|
98 | - ] + $parameters); |
|
99 | - } |
|
90 | + if ($surname !== '') { |
|
91 | + return route(LineagesPage::class, [ |
|
92 | + 'tree' => $tree->name(), |
|
93 | + 'surname' => $surname |
|
94 | + ] + $parameters); |
|
95 | + } |
|
96 | + return route(SurnamesList::class, [ |
|
97 | + 'tree' => $tree->name() |
|
98 | + ] + $parameters); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * {@inheritDoc} |
|
103 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
104 | - */ |
|
105 | - public function listMenuClass(): string |
|
106 | - { |
|
107 | - return 'menu-maj-patrolineage'; |
|
108 | - } |
|
101 | + /** |
|
102 | + * {@inheritDoc} |
|
103 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
104 | + */ |
|
105 | + public function listMenuClass(): string |
|
106 | + { |
|
107 | + return 'menu-maj-patrolineage'; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * {@inheritDoc} |
|
112 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
113 | - */ |
|
114 | - public function headContent(): string |
|
115 | - { |
|
116 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
117 | - } |
|
110 | + /** |
|
111 | + * {@inheritDoc} |
|
112 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
113 | + */ |
|
114 | + public function headContent(): string |
|
115 | + { |
|
116 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
117 | + } |
|
118 | 118 | } |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function loadRoutes(Map $router): void |
63 | 63 | { |
64 | - $router->attach('', '', static function (Map $router) { |
|
64 | + $router->attach('', '', static function(Map $router) { |
|
65 | 65 | |
66 | - $router->attach('', '/module-maj/lineages', static function (Map $router) { |
|
66 | + $router->attach('', '/module-maj/lineages', static function(Map $router) { |
|
67 | 67 | |
68 | - $router->attach('', '/Page', static function (Map $router) { |
|
68 | + $router->attach('', '/Page', static function(Map $router) { |
|
69 | 69 | |
70 | 70 | $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class); |
71 | 71 | $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class); |
@@ -113,6 +113,6 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function headContent(): string |
115 | 115 | { |
116 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
116 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
117 | 117 | } |
118 | 118 | } |
@@ -24,68 +24,68 @@ |
||
24 | 24 | class LineageRootNode extends LineageNode |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var Collection $places Places for the lineage node |
|
29 | - */ |
|
30 | - private $places; |
|
27 | + /** |
|
28 | + * @var Collection $places Places for the lineage node |
|
29 | + */ |
|
30 | + private $places; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var int $nb_children Number of node childs |
|
34 | - */ |
|
35 | - private $nb_children; |
|
32 | + /** |
|
33 | + * @var int $nb_children Number of node childs |
|
34 | + */ |
|
35 | + private $nb_children; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for LineageRootNode |
|
39 | - * |
|
40 | - * @param Individual|null $node_indi |
|
41 | - */ |
|
42 | - public function __construct(?Individual $node_indi = null) |
|
43 | - { |
|
44 | - parent::__construct($node_indi, $this); |
|
45 | - $this->places = new Collection(); |
|
46 | - $this->nb_children = 0; |
|
47 | - } |
|
37 | + /** |
|
38 | + * Constructor for LineageRootNode |
|
39 | + * |
|
40 | + * @param Individual|null $node_indi |
|
41 | + */ |
|
42 | + public function __construct(?Individual $node_indi = null) |
|
43 | + { |
|
44 | + parent::__construct($node_indi, $this); |
|
45 | + $this->places = new Collection(); |
|
46 | + $this->nb_children = 0; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Adds a place to the list of lineage's place |
|
51 | - * |
|
52 | - * @param Place $place |
|
53 | - */ |
|
54 | - public function addPlace(Place $place): void |
|
55 | - { |
|
56 | - $place_name = $place->gedcomName(); |
|
57 | - if (mb_strlen($place_name) > 0) { |
|
58 | - $this->places->put($place_name, $this->places->get($place_name, 0) + 1); |
|
59 | - } |
|
60 | - } |
|
49 | + /** |
|
50 | + * Adds a place to the list of lineage's place |
|
51 | + * |
|
52 | + * @param Place $place |
|
53 | + */ |
|
54 | + public function addPlace(Place $place): void |
|
55 | + { |
|
56 | + $place_name = $place->gedcomName(); |
|
57 | + if (mb_strlen($place_name) > 0) { |
|
58 | + $this->places->put($place_name, $this->places->get($place_name, 0) + 1); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Returns the number of child nodes. |
|
64 | - * This number is more to be used as indication rather than an accurate one. |
|
65 | - * |
|
66 | - * @return int |
|
67 | - */ |
|
68 | - public function numberChildNodes(): int |
|
69 | - { |
|
70 | - return $this->nb_children; |
|
71 | - } |
|
62 | + /** |
|
63 | + * Returns the number of child nodes. |
|
64 | + * This number is more to be used as indication rather than an accurate one. |
|
65 | + * |
|
66 | + * @return int |
|
67 | + */ |
|
68 | + public function numberChildNodes(): int |
|
69 | + { |
|
70 | + return $this->nb_children; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Increments the number of child nodes by one |
|
75 | - * |
|
76 | - */ |
|
77 | - public function incrementChildNodes(): void |
|
78 | - { |
|
79 | - $this->nb_children++; |
|
80 | - } |
|
73 | + /** |
|
74 | + * Increments the number of child nodes by one |
|
75 | + * |
|
76 | + */ |
|
77 | + public function incrementChildNodes(): void |
|
78 | + { |
|
79 | + $this->nb_children++; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Returns the list of place for the lineage |
|
84 | - * |
|
85 | - * @return Collection |
|
86 | - */ |
|
87 | - public function places(): Collection |
|
88 | - { |
|
89 | - return $this->places; |
|
90 | - } |
|
82 | + /** |
|
83 | + * Returns the list of place for the lineage |
|
84 | + * |
|
85 | + * @return Collection |
|
86 | + */ |
|
87 | + public function places(): Collection |
|
88 | + { |
|
89 | + return $this->places; |
|
90 | + } |
|
91 | 91 | } |
@@ -24,117 +24,117 @@ |
||
24 | 24 | class LineageNode |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var Collection $linked_fams Spouse families linked to the node |
|
29 | - */ |
|
30 | - private $linked_fams; |
|
27 | + /** |
|
28 | + * @var Collection $linked_fams Spouse families linked to the node |
|
29 | + */ |
|
30 | + private $linked_fams; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var ?Individual $node_indi Reference individual for the node |
|
34 | - */ |
|
35 | - private $node_indi; |
|
32 | + /** |
|
33 | + * @var ?Individual $node_indi Reference individual for the node |
|
34 | + */ |
|
35 | + private $node_indi; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var LineageRootNode $root_node Root node of the lineage |
|
39 | - */ |
|
40 | - private $root_node; |
|
37 | + /** |
|
38 | + * @var LineageRootNode $root_node Root node of the lineage |
|
39 | + */ |
|
40 | + private $root_node; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var ?string $alt_surname Linked surname, used to link to another lineage |
|
44 | - */ |
|
45 | - private $alt_surname; |
|
42 | + /** |
|
43 | + * @var ?string $alt_surname Linked surname, used to link to another lineage |
|
44 | + */ |
|
45 | + private $alt_surname; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Constructor for Lineage node |
|
49 | - * |
|
50 | - * @param Individual $node_indi Main individual |
|
51 | - * @param LineageRootNode $root_node Node of the lineage root |
|
52 | - * @param null|string $alt_surname Follow-up surname |
|
53 | - */ |
|
54 | - public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null) |
|
55 | - { |
|
56 | - $this->node_indi = $node_indi; |
|
57 | - $this->root_node = $root_node; |
|
58 | - $this->alt_surname = $alt_surname; |
|
59 | - $this->linked_fams = new Collection(); |
|
60 | - } |
|
47 | + /** |
|
48 | + * Constructor for Lineage node |
|
49 | + * |
|
50 | + * @param Individual $node_indi Main individual |
|
51 | + * @param LineageRootNode $root_node Node of the lineage root |
|
52 | + * @param null|string $alt_surname Follow-up surname |
|
53 | + */ |
|
54 | + public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null) |
|
55 | + { |
|
56 | + $this->node_indi = $node_indi; |
|
57 | + $this->root_node = $root_node; |
|
58 | + $this->alt_surname = $alt_surname; |
|
59 | + $this->linked_fams = new Collection(); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Add a spouse family to the node |
|
64 | - * |
|
65 | - * @param Family $fams |
|
66 | - * @return object |
|
67 | - */ |
|
68 | - public function addFamily(Family $fams): object |
|
69 | - { |
|
70 | - if (!$this->linked_fams->has($fams->xref())) { |
|
71 | - $this->linked_fams->put($fams->xref(), (object) [ |
|
72 | - 'family' => $fams, |
|
73 | - 'children' => new Collection() |
|
74 | - ]); |
|
75 | - } |
|
76 | - return $this->linked_fams->get($fams->xref()); |
|
77 | - } |
|
62 | + /** |
|
63 | + * Add a spouse family to the node |
|
64 | + * |
|
65 | + * @param Family $fams |
|
66 | + * @return object |
|
67 | + */ |
|
68 | + public function addFamily(Family $fams): object |
|
69 | + { |
|
70 | + if (!$this->linked_fams->has($fams->xref())) { |
|
71 | + $this->linked_fams->put($fams->xref(), (object) [ |
|
72 | + 'family' => $fams, |
|
73 | + 'children' => new Collection() |
|
74 | + ]); |
|
75 | + } |
|
76 | + return $this->linked_fams->get($fams->xref()); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Add a child LineageNode to the node |
|
81 | - * |
|
82 | - * @param Family $fams |
|
83 | - * @param LineageNode $child |
|
84 | - */ |
|
85 | - public function addChild(Family $fams, LineageNode $child = null): void |
|
86 | - { |
|
87 | - $this->addFamily($fams)->children->push($child); |
|
88 | - $this->root_node->incrementChildNodes(); |
|
89 | - } |
|
79 | + /** |
|
80 | + * Add a child LineageNode to the node |
|
81 | + * |
|
82 | + * @param Family $fams |
|
83 | + * @param LineageNode $child |
|
84 | + */ |
|
85 | + public function addChild(Family $fams, LineageNode $child = null): void |
|
86 | + { |
|
87 | + $this->addFamily($fams)->children->push($child); |
|
88 | + $this->root_node->incrementChildNodes(); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Returns the node individual |
|
93 | - * |
|
94 | - * @return Individual|NULL |
|
95 | - */ |
|
96 | - public function individual(): ?Individual |
|
97 | - { |
|
98 | - return $this->node_indi; |
|
99 | - } |
|
91 | + /** |
|
92 | + * Returns the node individual |
|
93 | + * |
|
94 | + * @return Individual|NULL |
|
95 | + */ |
|
96 | + public function individual(): ?Individual |
|
97 | + { |
|
98 | + return $this->node_indi; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Returns the lineage root node individual |
|
103 | - * |
|
104 | - * @return LineageRootNode |
|
105 | - */ |
|
106 | - public function rootNode(): LineageRootNode |
|
107 | - { |
|
108 | - return $this->root_node; |
|
109 | - } |
|
101 | + /** |
|
102 | + * Returns the lineage root node individual |
|
103 | + * |
|
104 | + * @return LineageRootNode |
|
105 | + */ |
|
106 | + public function rootNode(): LineageRootNode |
|
107 | + { |
|
108 | + return $this->root_node; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Returns the spouse families linked to the node |
|
113 | - * |
|
114 | - * @return Collection |
|
115 | - */ |
|
116 | - public function families(): Collection |
|
117 | - { |
|
118 | - return $this->linked_fams; |
|
119 | - } |
|
111 | + /** |
|
112 | + * Returns the spouse families linked to the node |
|
113 | + * |
|
114 | + * @return Collection |
|
115 | + */ |
|
116 | + public function families(): Collection |
|
117 | + { |
|
118 | + return $this->linked_fams; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Returns the follow-up surname |
|
123 | - * |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public function followUpSurname(): string |
|
127 | - { |
|
128 | - return $this->alt_surname ?? ''; |
|
129 | - } |
|
121 | + /** |
|
122 | + * Returns the follow-up surname |
|
123 | + * |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public function followUpSurname(): string |
|
127 | + { |
|
128 | + return $this->alt_surname ?? ''; |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Indicates whether the node has a follow up surname |
|
133 | - * |
|
134 | - * @return boolean |
|
135 | - */ |
|
136 | - public function hasFollowUpSurname(): bool |
|
137 | - { |
|
138 | - return mb_strlen($this->followUpSurname()) > 0 ; |
|
139 | - } |
|
131 | + /** |
|
132 | + * Indicates whether the node has a follow up surname |
|
133 | + * |
|
134 | + * @return boolean |
|
135 | + */ |
|
136 | + public function hasFollowUpSurname(): bool |
|
137 | + { |
|
138 | + return mb_strlen($this->followUpSurname()) > 0 ; |
|
139 | + } |
|
140 | 140 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function addFamily(Family $fams): object |
69 | 69 | { |
70 | 70 | if (!$this->linked_fams->has($fams->xref())) { |
71 | - $this->linked_fams->put($fams->xref(), (object) [ |
|
71 | + $this->linked_fams->put($fams->xref(), (object)[ |
|
72 | 72 | 'family' => $fams, |
73 | 73 | 'children' => new Collection() |
74 | 74 | ]); |
@@ -135,6 +135,6 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function hasFollowUpSurname(): bool |
137 | 137 | { |
138 | - return mb_strlen($this->followUpSurname()) > 0 ; |
|
138 | + return mb_strlen($this->followUpSurname()) > 0; |
|
139 | 139 | } |
140 | 140 | } |
@@ -29,212 +29,212 @@ |
||
29 | 29 | class LineageBuilder |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * @var string $surname Reference surname |
|
34 | - */ |
|
35 | - private $surname; |
|
32 | + /** |
|
33 | + * @var string $surname Reference surname |
|
34 | + */ |
|
35 | + private $surname; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var Tree $tree Reference tree |
|
39 | - */ |
|
40 | - private $tree; |
|
37 | + /** |
|
38 | + * @var Tree $tree Reference tree |
|
39 | + */ |
|
40 | + private $tree; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var IndividualListService $indilist_service |
|
44 | - */ |
|
45 | - private $indilist_service; |
|
42 | + /** |
|
43 | + * @var IndividualListService $indilist_service |
|
44 | + */ |
|
45 | + private $indilist_service; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var Collection $used_indis Individuals already processed |
|
49 | - */ |
|
50 | - private $used_indis; |
|
47 | + /** |
|
48 | + * @var Collection $used_indis Individuals already processed |
|
49 | + */ |
|
50 | + private $used_indis; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Constructor for Lineage Builder |
|
54 | - * |
|
55 | - * @param string $surname Reference surname |
|
56 | - * @param Tree $tree Gedcom tree |
|
57 | - */ |
|
58 | - public function __construct($surname, Tree $tree, IndividualListService $indilist_service) |
|
59 | - { |
|
60 | - $this->surname = $surname; |
|
61 | - $this->tree = $tree; |
|
62 | - $this->indilist_service = $indilist_service; |
|
63 | - $this->used_indis = new Collection(); |
|
64 | - } |
|
52 | + /** |
|
53 | + * Constructor for Lineage Builder |
|
54 | + * |
|
55 | + * @param string $surname Reference surname |
|
56 | + * @param Tree $tree Gedcom tree |
|
57 | + */ |
|
58 | + public function __construct($surname, Tree $tree, IndividualListService $indilist_service) |
|
59 | + { |
|
60 | + $this->surname = $surname; |
|
61 | + $this->tree = $tree; |
|
62 | + $this->indilist_service = $indilist_service; |
|
63 | + $this->used_indis = new Collection(); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Build all patronymic lineages for the reference surname. |
|
68 | - * |
|
69 | - * @return Collection|NULL List of root patronymic lineages |
|
70 | - */ |
|
71 | - public function buildLineages(): ?Collection |
|
72 | - { |
|
73 | - $indis = $this->indilist_service->individuals($this->surname, '', '', false, false, I18N::locale()); |
|
74 | - //Warning - the IndividualListService returns a clone of individuals objects. Cannot be used for object equality |
|
75 | - if (count($indis) == 0) { |
|
76 | - return null; |
|
77 | - } |
|
66 | + /** |
|
67 | + * Build all patronymic lineages for the reference surname. |
|
68 | + * |
|
69 | + * @return Collection|NULL List of root patronymic lineages |
|
70 | + */ |
|
71 | + public function buildLineages(): ?Collection |
|
72 | + { |
|
73 | + $indis = $this->indilist_service->individuals($this->surname, '', '', false, false, I18N::locale()); |
|
74 | + //Warning - the IndividualListService returns a clone of individuals objects. Cannot be used for object equality |
|
75 | + if (count($indis) == 0) { |
|
76 | + return null; |
|
77 | + } |
|
78 | 78 | |
79 | - $root_lineages = new Collection(); |
|
79 | + $root_lineages = new Collection(); |
|
80 | 80 | |
81 | - foreach ($indis as $indi) { |
|
82 | - /** @var Individual $indi */ |
|
83 | - if (!$this->used_indis->get($indi->xref(), false)) { |
|
84 | - $indi_first = $this->getLineageRootIndividual($indi); |
|
85 | - if ($indi_first !== null) { |
|
86 | - // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
87 | - $indi_first = Factory::individual()->make($indi_first->xref(), $this->tree); |
|
88 | - } |
|
89 | - if ($indi_first === null) { |
|
90 | - continue; |
|
91 | - } |
|
92 | - $this->used_indis->put($indi_first->xref(), true); |
|
93 | - if ($indi_first->canShow()) { |
|
94 | - //Check if the root individual has brothers and sisters, without parents |
|
95 | - $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
96 | - if ($indi_first_child_family !== null) { |
|
97 | - $root_node = new LineageRootNode(null); |
|
98 | - $root_node->addFamily($indi_first_child_family); |
|
99 | - } else { |
|
100 | - $root_node = new LineageRootNode($indi_first); |
|
101 | - } |
|
102 | - $root_node = $this->buildLineage($root_node); |
|
103 | - if ($root_node !== null) { |
|
104 | - $root_lineages->add($root_node); |
|
105 | - } |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
81 | + foreach ($indis as $indi) { |
|
82 | + /** @var Individual $indi */ |
|
83 | + if (!$this->used_indis->get($indi->xref(), false)) { |
|
84 | + $indi_first = $this->getLineageRootIndividual($indi); |
|
85 | + if ($indi_first !== null) { |
|
86 | + // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
87 | + $indi_first = Factory::individual()->make($indi_first->xref(), $this->tree); |
|
88 | + } |
|
89 | + if ($indi_first === null) { |
|
90 | + continue; |
|
91 | + } |
|
92 | + $this->used_indis->put($indi_first->xref(), true); |
|
93 | + if ($indi_first->canShow()) { |
|
94 | + //Check if the root individual has brothers and sisters, without parents |
|
95 | + $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
96 | + if ($indi_first_child_family !== null) { |
|
97 | + $root_node = new LineageRootNode(null); |
|
98 | + $root_node->addFamily($indi_first_child_family); |
|
99 | + } else { |
|
100 | + $root_node = new LineageRootNode($indi_first); |
|
101 | + } |
|
102 | + $root_node = $this->buildLineage($root_node); |
|
103 | + if ($root_node !== null) { |
|
104 | + $root_lineages->add($root_node); |
|
105 | + } |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | 109 | |
110 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
110 | + return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
111 | 111 | |
112 | - if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
113 | - return 0; |
|
114 | - } |
|
115 | - return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
116 | - }); |
|
117 | - } |
|
112 | + if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
113 | + return 0; |
|
114 | + } |
|
115 | + return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
116 | + }); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Retrieve the root individual, from any individual, by recursion. |
|
121 | - * The Root individual is the individual without a father, or without a mother holding the same name. |
|
122 | - * |
|
123 | - * @param Individual $indi |
|
124 | - * @return Individual|NULL Root individual |
|
125 | - */ |
|
126 | - private function getLineageRootIndividual(Individual $indi): ?Individual |
|
127 | - { |
|
128 | - $child_families = $indi->childFamilies(); |
|
129 | - if ($this->used_indis->get($indi->xref(), false)) { |
|
130 | - return null; |
|
131 | - } |
|
119 | + /** |
|
120 | + * Retrieve the root individual, from any individual, by recursion. |
|
121 | + * The Root individual is the individual without a father, or without a mother holding the same name. |
|
122 | + * |
|
123 | + * @param Individual $indi |
|
124 | + * @return Individual|NULL Root individual |
|
125 | + */ |
|
126 | + private function getLineageRootIndividual(Individual $indi): ?Individual |
|
127 | + { |
|
128 | + $child_families = $indi->childFamilies(); |
|
129 | + if ($this->used_indis->get($indi->xref(), false)) { |
|
130 | + return null; |
|
131 | + } |
|
132 | 132 | |
133 | - foreach ($child_families as $child_family) { |
|
134 | - /** @var Family $child_family */ |
|
135 | - $child_family->husband(); |
|
136 | - if ($husb = $child_family->husband()) { |
|
137 | - if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
138 | - return $indi; |
|
139 | - } |
|
140 | - return $this->getLineageRootIndividual($husb); |
|
141 | - } elseif ($wife = $child_family->wife()) { |
|
142 | - if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
143 | - $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
144 | - $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
145 | - if ( |
|
146 | - $indi->canShowName() |
|
147 | - && $wife->canShowName() |
|
148 | - && I18N::strcasecmp($indi_surname, $wife_surname) == 0 |
|
149 | - ) { |
|
150 | - return $this->getLineageRootIndividual($wife); |
|
151 | - } |
|
152 | - } |
|
153 | - return $indi; |
|
154 | - } |
|
155 | - } |
|
156 | - return $indi; |
|
157 | - } |
|
133 | + foreach ($child_families as $child_family) { |
|
134 | + /** @var Family $child_family */ |
|
135 | + $child_family->husband(); |
|
136 | + if ($husb = $child_family->husband()) { |
|
137 | + if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
138 | + return $indi; |
|
139 | + } |
|
140 | + return $this->getLineageRootIndividual($husb); |
|
141 | + } elseif ($wife = $child_family->wife()) { |
|
142 | + if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
143 | + $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
144 | + $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
145 | + if ( |
|
146 | + $indi->canShowName() |
|
147 | + && $wife->canShowName() |
|
148 | + && I18N::strcasecmp($indi_surname, $wife_surname) == 0 |
|
149 | + ) { |
|
150 | + return $this->getLineageRootIndividual($wife); |
|
151 | + } |
|
152 | + } |
|
153 | + return $indi; |
|
154 | + } |
|
155 | + } |
|
156 | + return $indi; |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Computes descendent Lineage from a node. |
|
161 | - * Uses recursion to build the lineage tree |
|
162 | - * |
|
163 | - * @param LineageNode $node |
|
164 | - * @return LineageNode Computed lineage |
|
165 | - */ |
|
166 | - private function buildLineage(LineageNode $node): LineageNode |
|
167 | - { |
|
168 | - $indi_surname = ''; |
|
159 | + /** |
|
160 | + * Computes descendent Lineage from a node. |
|
161 | + * Uses recursion to build the lineage tree |
|
162 | + * |
|
163 | + * @param LineageNode $node |
|
164 | + * @return LineageNode Computed lineage |
|
165 | + */ |
|
166 | + private function buildLineage(LineageNode $node): LineageNode |
|
167 | + { |
|
168 | + $indi_surname = ''; |
|
169 | 169 | |
170 | - $indi_node = $node->individual(); |
|
171 | - if ($indi_node !== null) { |
|
172 | - if ($node->families()->count() == 0) { |
|
173 | - foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
174 | - $node->addFamily($spouse_family); |
|
175 | - } |
|
176 | - } |
|
170 | + $indi_node = $node->individual(); |
|
171 | + if ($indi_node !== null) { |
|
172 | + if ($node->families()->count() == 0) { |
|
173 | + foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
174 | + $node->addFamily($spouse_family); |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
179 | - $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
178 | + $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
179 | + $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
180 | 180 | |
181 | - //Tag the individual as used |
|
182 | - $this->used_indis->put($indi_node->xref(), true); |
|
183 | - } |
|
181 | + //Tag the individual as used |
|
182 | + $this->used_indis->put($indi_node->xref(), true); |
|
183 | + } |
|
184 | 184 | |
185 | - foreach ($node->families() as $family_node) { |
|
186 | - /** @var Family $spouse_family */ |
|
187 | - $spouse_family = $family_node->family; |
|
188 | - $spouse_surname = ''; |
|
189 | - $spouse = null; |
|
190 | - if ($indi_node !== null && ($spouse = $spouse_family->spouse($indi_node)) && $spouse->canShowName()) { |
|
191 | - $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
192 | - } |
|
185 | + foreach ($node->families() as $family_node) { |
|
186 | + /** @var Family $spouse_family */ |
|
187 | + $spouse_family = $family_node->family; |
|
188 | + $spouse_surname = ''; |
|
189 | + $spouse = null; |
|
190 | + if ($indi_node !== null && ($spouse = $spouse_family->spouse($indi_node)) && $spouse->canShowName()) { |
|
191 | + $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
192 | + } |
|
193 | 193 | |
194 | - $nb_children = $nb_natural = 0; |
|
194 | + $nb_children = $nb_natural = 0; |
|
195 | 195 | |
196 | - foreach ($spouse_family->children() as $child) { |
|
197 | - if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
198 | - $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
196 | + foreach ($spouse_family->children() as $child) { |
|
197 | + if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
198 | + $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
199 | 199 | |
200 | - $nb_children++; |
|
201 | - if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
202 | - //Print only lineages of children with the same surname as their mother |
|
203 | - //(supposing they are natural children) |
|
204 | - if (!$spouse || ($spouse_surname && I18N::strcasecmp($child_surname, $spouse_surname) != 0)) { |
|
205 | - if (I18N::strcasecmp($child_surname, $indi_surname) == 0) { |
|
206 | - $nb_natural++; |
|
207 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
208 | - $node_child = $this->buildLineage($node_child); |
|
209 | - $node->addChild($spouse_family, $node_child); |
|
210 | - } |
|
211 | - } |
|
212 | - } else { //If the root individual is the father |
|
213 | - $nb_natural++; |
|
214 | - //Print if the children does not bear the same name as his mother |
|
215 | - //(and different from his father) |
|
216 | - if ( |
|
217 | - mb_strlen($child_surname) == 0 || |
|
218 | - mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
219 | - I18N::strcasecmp($child_surname, $indi_surname) == 0 || |
|
220 | - I18N::strcasecmp($child_surname, $spouse_surname) != 0 |
|
221 | - ) { |
|
222 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
223 | - $node_child = $this->buildLineage($node_child); |
|
224 | - } else { |
|
225 | - $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
226 | - } |
|
227 | - $node->addChild($spouse_family, $node_child); |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
200 | + $nb_children++; |
|
201 | + if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
202 | + //Print only lineages of children with the same surname as their mother |
|
203 | + //(supposing they are natural children) |
|
204 | + if (!$spouse || ($spouse_surname && I18N::strcasecmp($child_surname, $spouse_surname) != 0)) { |
|
205 | + if (I18N::strcasecmp($child_surname, $indi_surname) == 0) { |
|
206 | + $nb_natural++; |
|
207 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
208 | + $node_child = $this->buildLineage($node_child); |
|
209 | + $node->addChild($spouse_family, $node_child); |
|
210 | + } |
|
211 | + } |
|
212 | + } else { //If the root individual is the father |
|
213 | + $nb_natural++; |
|
214 | + //Print if the children does not bear the same name as his mother |
|
215 | + //(and different from his father) |
|
216 | + if ( |
|
217 | + mb_strlen($child_surname) == 0 || |
|
218 | + mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
219 | + I18N::strcasecmp($child_surname, $indi_surname) == 0 || |
|
220 | + I18N::strcasecmp($child_surname, $spouse_surname) != 0 |
|
221 | + ) { |
|
222 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
223 | + $node_child = $this->buildLineage($node_child); |
|
224 | + } else { |
|
225 | + $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
226 | + } |
|
227 | + $node->addChild($spouse_family, $node_child); |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | 231 | |
232 | - //Do not print other children |
|
233 | - if (($nb_children - $nb_natural) > 0) { |
|
234 | - $node->addChild($spouse_family, null); |
|
235 | - } |
|
236 | - } |
|
232 | + //Do not print other children |
|
233 | + if (($nb_children - $nb_natural) > 0) { |
|
234 | + $node->addChild($spouse_family, null); |
|
235 | + } |
|
236 | + } |
|
237 | 237 | |
238 | - return $node; |
|
239 | - } |
|
238 | + return $node; |
|
239 | + } |
|
240 | 240 | } |
@@ -107,7 +107,7 @@ |
||
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
110 | + return $root_lineages->sort(function(LineageRootNode $a, LineageRootNode $b) { |
|
111 | 111 | |
112 | 112 | if ($a->numberChildNodes() == $b->numberChildNodes()) { |
113 | 113 | return 0; |
@@ -26,89 +26,89 @@ |
||
26 | 26 | */ |
27 | 27 | abstract class AbstractModuleMaj extends AbstractModule implements ModuleCustomInterface |
28 | 28 | { |
29 | - use ModuleCustomTrait; |
|
29 | + use ModuleCustomTrait; |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritDoc} |
|
33 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
34 | - */ |
|
35 | - public function boot() : void |
|
36 | - { |
|
37 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
31 | + /** |
|
32 | + * {@inheritDoc} |
|
33 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
34 | + */ |
|
35 | + public function boot() : void |
|
36 | + { |
|
37 | + View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
38 | 38 | |
39 | - $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
40 | - } |
|
39 | + $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * {@inheritDoc} |
|
44 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
45 | - */ |
|
46 | - public function resourcesFolder(): string |
|
47 | - { |
|
48 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
49 | - } |
|
42 | + /** |
|
43 | + * {@inheritDoc} |
|
44 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
45 | + */ |
|
46 | + public function resourcesFolder(): string |
|
47 | + { |
|
48 | + return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * {@inheritDoc} |
|
53 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
54 | - */ |
|
55 | - public function customModuleAuthorName() : string |
|
56 | - { |
|
57 | - return 'Jonathan Jaubart'; |
|
58 | - } |
|
51 | + /** |
|
52 | + * {@inheritDoc} |
|
53 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
54 | + */ |
|
55 | + public function customModuleAuthorName() : string |
|
56 | + { |
|
57 | + return 'Jonathan Jaubart'; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritDoc} |
|
62 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
63 | - */ |
|
64 | - public function customModuleSupportUrl() : string |
|
65 | - { |
|
66 | - return 'https://github.com/jon48/webtrees-lib'; |
|
67 | - } |
|
60 | + /** |
|
61 | + * {@inheritDoc} |
|
62 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
63 | + */ |
|
64 | + public function customModuleSupportUrl() : string |
|
65 | + { |
|
66 | + return 'https://github.com/jon48/webtrees-lib'; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
72 | - */ |
|
73 | - public function customTranslations(string $language) : array |
|
74 | - { |
|
75 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
72 | + */ |
|
73 | + public function customTranslations(string $language) : array |
|
74 | + { |
|
75 | + $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
76 | 76 | |
77 | - try { |
|
78 | - $translation = new Translation($translation_file); |
|
79 | - return $translation->asArray(); |
|
80 | - } catch (\Exception $e) { } |
|
77 | + try { |
|
78 | + $translation = new Translation($translation_file); |
|
79 | + return $translation->asArray(); |
|
80 | + } catch (\Exception $e) { } |
|
81 | 81 | |
82 | - return array(); |
|
83 | - } |
|
82 | + return array(); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Add module routes to webtrees route loader |
|
87 | - * |
|
88 | - * @param Map $router |
|
89 | - */ |
|
90 | - public abstract function loadRoutes(Map $router) : void; |
|
85 | + /** |
|
86 | + * Add module routes to webtrees route loader |
|
87 | + * |
|
88 | + * @param Map $router |
|
89 | + */ |
|
90 | + public abstract function loadRoutes(Map $router) : void; |
|
91 | 91 | |
92 | - /** |
|
93 | - * Returns the URL of the module specific stylesheets. |
|
94 | - * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
95 | - * and fallback to default.min.css if none are found |
|
96 | - * |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function moduleCssUrl() : string |
|
100 | - { |
|
101 | - /** @var ModuleThemeInterface $theme */ |
|
102 | - $theme = app(ModuleThemeInterface::class); |
|
103 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
92 | + /** |
|
93 | + * Returns the URL of the module specific stylesheets. |
|
94 | + * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
95 | + * and fallback to default.min.css if none are found |
|
96 | + * |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function moduleCssUrl() : string |
|
100 | + { |
|
101 | + /** @var ModuleThemeInterface $theme */ |
|
102 | + $theme = app(ModuleThemeInterface::class); |
|
103 | + $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
104 | 104 | |
105 | - if(file_exists($css_file)) { |
|
106 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
107 | - } |
|
108 | - else { |
|
109 | - return $this->assetUrl('css/default.min.css'); |
|
110 | - } |
|
111 | - } |
|
105 | + if(file_exists($css_file)) { |
|
106 | + return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
107 | + } |
|
108 | + else { |
|
109 | + return $this->assetUrl('css/default.min.css'); |
|
110 | + } |
|
111 | + } |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | 115 | \ No newline at end of file |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function boot() : void |
36 | 36 | { |
37 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
37 | + View::registerNamespace($this->name(), $this->resourcesFolder().'views/'); |
|
38 | 38 | |
39 | 39 | $this->loadRoutes(app(RouterContainer::class)->getMap()); |
40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function resourcesFolder(): string |
47 | 47 | { |
48 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
48 | + return Webtrees::MODULES_DIR.trim($this->name(), '_').'/resources/'; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function customTranslations(string $language) : array |
74 | 74 | { |
75 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
75 | + $translation_file = $this->resourcesFolder().'lang/'.$language.'/messages.php'; |
|
76 | 76 | |
77 | 77 | try { |
78 | 78 | $translation = new Translation($translation_file); |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | { |
101 | 101 | /** @var ModuleThemeInterface $theme */ |
102 | 102 | $theme = app(ModuleThemeInterface::class); |
103 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
103 | + $css_file = $this->resourcesFolder().'css/'.$theme->name().'.min.css'; |
|
104 | 104 | |
105 | - if(file_exists($css_file)) { |
|
106 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
105 | + if (file_exists($css_file)) { |
|
106 | + return $this->assetUrl('css/'.$theme->name().'.min.css'); |
|
107 | 107 | } |
108 | 108 | else { |
109 | 109 | return $this->assetUrl('css/default.min.css'); |
@@ -104,8 +104,7 @@ |
||
104 | 104 | |
105 | 105 | if(file_exists($css_file)) { |
106 | 106 | return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
107 | - } |
|
108 | - else { |
|
107 | + } else { |
|
109 | 108 | return $this->assetUrl('css/default.min.css'); |
110 | 109 | } |
111 | 110 | } |
@@ -33,252 +33,252 @@ |
||
33 | 33 | */ |
34 | 34 | class TaskScheduleService |
35 | 35 | { |
36 | - /** |
|
37 | - * Time-out after which the task will be considered not running any more. |
|
38 | - * In seconds, default 5 mins. |
|
39 | - * @var integer |
|
40 | - */ |
|
41 | - public const TASK_TIME_OUT = 600; |
|
36 | + /** |
|
37 | + * Time-out after which the task will be considered not running any more. |
|
38 | + * In seconds, default 5 mins. |
|
39 | + * @var integer |
|
40 | + */ |
|
41 | + public const TASK_TIME_OUT = 600; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var Collection $available_tasks |
|
45 | - */ |
|
46 | - private $available_tasks; |
|
43 | + /** |
|
44 | + * @var Collection $available_tasks |
|
45 | + */ |
|
46 | + private $available_tasks; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Returns all Tasks schedules in database. |
|
50 | - * Stored records can be synchronised with the tasks actually available to the system. |
|
51 | - * |
|
52 | - * @param bool $sync_available Should tasks synchronised with available ones |
|
53 | - * @param bool $include_disabled Should disabled tasks be returned |
|
54 | - * @return Collection Collection of TaskSchedule |
|
55 | - */ |
|
56 | - public function all(bool $sync_available = false, bool $include_disabled = true): Collection |
|
57 | - { |
|
58 | - $tasks_schedules = DB::table('maj_admintasks') |
|
59 | - ->select() |
|
60 | - ->get() |
|
61 | - ->map(self::rowMapper()); |
|
48 | + /** |
|
49 | + * Returns all Tasks schedules in database. |
|
50 | + * Stored records can be synchronised with the tasks actually available to the system. |
|
51 | + * |
|
52 | + * @param bool $sync_available Should tasks synchronised with available ones |
|
53 | + * @param bool $include_disabled Should disabled tasks be returned |
|
54 | + * @return Collection Collection of TaskSchedule |
|
55 | + */ |
|
56 | + public function all(bool $sync_available = false, bool $include_disabled = true): Collection |
|
57 | + { |
|
58 | + $tasks_schedules = DB::table('maj_admintasks') |
|
59 | + ->select() |
|
60 | + ->get() |
|
61 | + ->map(self::rowMapper()); |
|
62 | 62 | |
63 | - if ($sync_available) { |
|
64 | - $available_tasks = clone $this->available(); |
|
65 | - foreach ($tasks_schedules as $task_schedule) { |
|
66 | - /** @var TaskSchedule $task_schedule */ |
|
67 | - if ($available_tasks->has($task_schedule->taskId())) { |
|
68 | - $available_tasks->forget($task_schedule->taskId()); |
|
69 | - } else { |
|
70 | - $this->delete($task_schedule); |
|
71 | - } |
|
72 | - } |
|
63 | + if ($sync_available) { |
|
64 | + $available_tasks = clone $this->available(); |
|
65 | + foreach ($tasks_schedules as $task_schedule) { |
|
66 | + /** @var TaskSchedule $task_schedule */ |
|
67 | + if ($available_tasks->has($task_schedule->taskId())) { |
|
68 | + $available_tasks->forget($task_schedule->taskId()); |
|
69 | + } else { |
|
70 | + $this->delete($task_schedule); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - foreach ($available_tasks as $task_name => $task) { |
|
75 | - /** @var TaskInterface $task */ |
|
76 | - $this->insertTask($task_name, $task->defaultFrequency()); |
|
77 | - } |
|
74 | + foreach ($available_tasks as $task_name => $task) { |
|
75 | + /** @var TaskInterface $task */ |
|
76 | + $this->insertTask($task_name, $task->defaultFrequency()); |
|
77 | + } |
|
78 | 78 | |
79 | - return $this->all(false, $include_disabled); |
|
80 | - } |
|
79 | + return $this->all(false, $include_disabled); |
|
80 | + } |
|
81 | 81 | |
82 | - return $tasks_schedules; |
|
83 | - } |
|
82 | + return $tasks_schedules; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Returns tasks exposed through modules implementing ModuleTasksProviderInterface. |
|
87 | - * |
|
88 | - * @return Collection |
|
89 | - */ |
|
90 | - public function available(): Collection |
|
91 | - { |
|
92 | - if ($this->available_tasks === null) { |
|
93 | - $tasks_providers = app(ModuleService::class)->findByInterface(ModuleTasksProviderInterface::class); |
|
85 | + /** |
|
86 | + * Returns tasks exposed through modules implementing ModuleTasksProviderInterface. |
|
87 | + * |
|
88 | + * @return Collection |
|
89 | + */ |
|
90 | + public function available(): Collection |
|
91 | + { |
|
92 | + if ($this->available_tasks === null) { |
|
93 | + $tasks_providers = app(ModuleService::class)->findByInterface(ModuleTasksProviderInterface::class); |
|
94 | 94 | |
95 | - $this->available_tasks = new Collection(); |
|
96 | - foreach ($tasks_providers as $task_provider) { |
|
97 | - $this->available_tasks = $this->available_tasks->merge($task_provider->listTasks()); |
|
98 | - } |
|
99 | - } |
|
100 | - return $this->available_tasks; |
|
101 | - } |
|
95 | + $this->available_tasks = new Collection(); |
|
96 | + foreach ($tasks_providers as $task_provider) { |
|
97 | + $this->available_tasks = $this->available_tasks->merge($task_provider->listTasks()); |
|
98 | + } |
|
99 | + } |
|
100 | + return $this->available_tasks; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Find a task schedule by its ID. |
|
105 | - * |
|
106 | - * @param int $task_schedule_id |
|
107 | - * @return TaskSchedule|NULL |
|
108 | - */ |
|
109 | - public function find(int $task_schedule_id): ?TaskSchedule |
|
110 | - { |
|
111 | - return DB::table('maj_admintasks') |
|
112 | - ->select() |
|
113 | - ->where('majat_id', '=', $task_schedule_id) |
|
114 | - ->get() |
|
115 | - ->map(self::rowMapper()) |
|
116 | - ->first(); |
|
117 | - } |
|
103 | + /** |
|
104 | + * Find a task schedule by its ID. |
|
105 | + * |
|
106 | + * @param int $task_schedule_id |
|
107 | + * @return TaskSchedule|NULL |
|
108 | + */ |
|
109 | + public function find(int $task_schedule_id): ?TaskSchedule |
|
110 | + { |
|
111 | + return DB::table('maj_admintasks') |
|
112 | + ->select() |
|
113 | + ->where('majat_id', '=', $task_schedule_id) |
|
114 | + ->get() |
|
115 | + ->map(self::rowMapper()) |
|
116 | + ->first(); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Add a new task schedule with the specified task ID, and frequency if defined. |
|
121 | - * Uses default for other settings. |
|
122 | - * |
|
123 | - * @param string $task_id |
|
124 | - * @param int $frequency |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - public function insertTask(string $task_id, int $frequency = 0): bool |
|
128 | - { |
|
129 | - $values = ['majat_task_id' => $task_id]; |
|
130 | - if ($frequency > 0) { |
|
131 | - $values['majat_frequency'] = $frequency; |
|
132 | - } |
|
119 | + /** |
|
120 | + * Add a new task schedule with the specified task ID, and frequency if defined. |
|
121 | + * Uses default for other settings. |
|
122 | + * |
|
123 | + * @param string $task_id |
|
124 | + * @param int $frequency |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + public function insertTask(string $task_id, int $frequency = 0): bool |
|
128 | + { |
|
129 | + $values = ['majat_task_id' => $task_id]; |
|
130 | + if ($frequency > 0) { |
|
131 | + $values['majat_frequency'] = $frequency; |
|
132 | + } |
|
133 | 133 | |
134 | - return DB::table('maj_admintasks') |
|
135 | - ->insert($values); |
|
136 | - } |
|
134 | + return DB::table('maj_admintasks') |
|
135 | + ->insert($values); |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * Update a task schedule. |
|
140 | - * Returns the number of tasks schedules updated. |
|
141 | - * |
|
142 | - * @param TaskSchedule $task_schedule |
|
143 | - * @return int |
|
144 | - */ |
|
145 | - public function update(TaskSchedule $task_schedule): int |
|
146 | - { |
|
147 | - return DB::table('maj_admintasks') |
|
148 | - ->where('majat_id', '=', $task_schedule->id()) |
|
149 | - ->update([ |
|
150 | - 'majat_status' => $task_schedule->isEnabled() ? 'enabled' : 'disabled', |
|
151 | - 'majat_last_run' => $task_schedule->lastRunTime(), |
|
152 | - 'majat_last_result' => $task_schedule->wasLastRunSuccess(), |
|
153 | - 'majat_frequency' => $task_schedule->frequency()->totalMinutes, |
|
154 | - 'majat_nb_occur' => $task_schedule->remainingOccurences(), |
|
155 | - 'majat_running' => $task_schedule->isRunning() |
|
156 | - ]); |
|
157 | - } |
|
138 | + /** |
|
139 | + * Update a task schedule. |
|
140 | + * Returns the number of tasks schedules updated. |
|
141 | + * |
|
142 | + * @param TaskSchedule $task_schedule |
|
143 | + * @return int |
|
144 | + */ |
|
145 | + public function update(TaskSchedule $task_schedule): int |
|
146 | + { |
|
147 | + return DB::table('maj_admintasks') |
|
148 | + ->where('majat_id', '=', $task_schedule->id()) |
|
149 | + ->update([ |
|
150 | + 'majat_status' => $task_schedule->isEnabled() ? 'enabled' : 'disabled', |
|
151 | + 'majat_last_run' => $task_schedule->lastRunTime(), |
|
152 | + 'majat_last_result' => $task_schedule->wasLastRunSuccess(), |
|
153 | + 'majat_frequency' => $task_schedule->frequency()->totalMinutes, |
|
154 | + 'majat_nb_occur' => $task_schedule->remainingOccurences(), |
|
155 | + 'majat_running' => $task_schedule->isRunning() |
|
156 | + ]); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Delete a task schedule. |
|
161 | - * |
|
162 | - * @param TaskSchedule $task_schedule |
|
163 | - * @return int |
|
164 | - */ |
|
165 | - public function delete(TaskSchedule $task_schedule): int |
|
166 | - { |
|
167 | - return DB::table('maj_admintasks') |
|
168 | - ->where('majat_id', '=', $task_schedule->id()) |
|
169 | - ->delete(); |
|
170 | - } |
|
159 | + /** |
|
160 | + * Delete a task schedule. |
|
161 | + * |
|
162 | + * @param TaskSchedule $task_schedule |
|
163 | + * @return int |
|
164 | + */ |
|
165 | + public function delete(TaskSchedule $task_schedule): int |
|
166 | + { |
|
167 | + return DB::table('maj_admintasks') |
|
168 | + ->where('majat_id', '=', $task_schedule->id()) |
|
169 | + ->delete(); |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * Find a task by its name |
|
174 | - * |
|
175 | - * @param string $task_id |
|
176 | - * @return TaskInterface|NULL |
|
177 | - */ |
|
178 | - public function findTask(string $task_id): ?TaskInterface |
|
179 | - { |
|
180 | - if ($this->available()->has($task_id)) { |
|
181 | - return app($this->available()->get($task_id)); |
|
182 | - } |
|
183 | - return null; |
|
184 | - } |
|
172 | + /** |
|
173 | + * Find a task by its name |
|
174 | + * |
|
175 | + * @param string $task_id |
|
176 | + * @return TaskInterface|NULL |
|
177 | + */ |
|
178 | + public function findTask(string $task_id): ?TaskInterface |
|
179 | + { |
|
180 | + if ($this->available()->has($task_id)) { |
|
181 | + return app($this->available()->get($task_id)); |
|
182 | + } |
|
183 | + return null; |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Retrieve all tasks that are candidates to be run. |
|
188 | - * |
|
189 | - * @param bool $force Should the run be forced |
|
190 | - * @param string $task_id Specific task ID to be run |
|
191 | - * @return Collection |
|
192 | - */ |
|
193 | - public function findTasksToRun(bool $force, string $task_id = null): Collection |
|
194 | - { |
|
195 | - $query = DB::table('maj_admintasks') |
|
196 | - ->select() |
|
197 | - ->where('majat_status', '=', 'enabled') |
|
198 | - ->where(function (Builder $query) { |
|
186 | + /** |
|
187 | + * Retrieve all tasks that are candidates to be run. |
|
188 | + * |
|
189 | + * @param bool $force Should the run be forced |
|
190 | + * @param string $task_id Specific task ID to be run |
|
191 | + * @return Collection |
|
192 | + */ |
|
193 | + public function findTasksToRun(bool $force, string $task_id = null): Collection |
|
194 | + { |
|
195 | + $query = DB::table('maj_admintasks') |
|
196 | + ->select() |
|
197 | + ->where('majat_status', '=', 'enabled') |
|
198 | + ->where(function (Builder $query) { |
|
199 | 199 | |
200 | - $query->where('majat_running', '=', 0) |
|
201 | - ->orWhere('majat_last_run', '<=', Carbon::now()->subSeconds(self::TASK_TIME_OUT)); |
|
202 | - }); |
|
200 | + $query->where('majat_running', '=', 0) |
|
201 | + ->orWhere('majat_last_run', '<=', Carbon::now()->subSeconds(self::TASK_TIME_OUT)); |
|
202 | + }); |
|
203 | 203 | |
204 | - if (!$force) { |
|
205 | - $query->where(function (Builder $query) { |
|
204 | + if (!$force) { |
|
205 | + $query->where(function (Builder $query) { |
|
206 | 206 | |
207 | - $query->where('majat_running', '=', 0) |
|
208 | - ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()'); |
|
209 | - }); |
|
210 | - } |
|
207 | + $query->where('majat_running', '=', 0) |
|
208 | + ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()'); |
|
209 | + }); |
|
210 | + } |
|
211 | 211 | |
212 | - if ($task_id !== null) { |
|
213 | - $query->where('majat_task_id', '=', $task_id); |
|
214 | - } |
|
212 | + if ($task_id !== null) { |
|
213 | + $query->where('majat_task_id', '=', $task_id); |
|
214 | + } |
|
215 | 215 | |
216 | - return $query->get()->map(self::rowMapper()); |
|
217 | - } |
|
216 | + return $query->get()->map(self::rowMapper()); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Run the task associated with the schedule. |
|
221 | - * The task will run if either forced to, or its next scheduled run time has been exceeded. |
|
222 | - * The last run time is recorded only if the task is successful. |
|
223 | - * |
|
224 | - * @param TaskSchedule $task_schedule |
|
225 | - * @param boolean $force |
|
226 | - */ |
|
227 | - public function run(TaskSchedule $task_schedule, $force = false): void |
|
228 | - { |
|
229 | - /** @var TaskSchedule $task_schedule */ |
|
230 | - $task_schedule = DB::table('maj_admintasks') |
|
231 | - ->select() |
|
232 | - ->where('majat_id', '=', $task_schedule->id()) |
|
233 | - ->lockForUpdate() |
|
234 | - ->get() |
|
235 | - ->map(self::rowMapper()) |
|
236 | - ->first(); |
|
219 | + /** |
|
220 | + * Run the task associated with the schedule. |
|
221 | + * The task will run if either forced to, or its next scheduled run time has been exceeded. |
|
222 | + * The last run time is recorded only if the task is successful. |
|
223 | + * |
|
224 | + * @param TaskSchedule $task_schedule |
|
225 | + * @param boolean $force |
|
226 | + */ |
|
227 | + public function run(TaskSchedule $task_schedule, $force = false): void |
|
228 | + { |
|
229 | + /** @var TaskSchedule $task_schedule */ |
|
230 | + $task_schedule = DB::table('maj_admintasks') |
|
231 | + ->select() |
|
232 | + ->where('majat_id', '=', $task_schedule->id()) |
|
233 | + ->lockForUpdate() |
|
234 | + ->get() |
|
235 | + ->map(self::rowMapper()) |
|
236 | + ->first(); |
|
237 | 237 | |
238 | - if ( |
|
239 | - !$task_schedule->isRunning() && |
|
240 | - ($force || $task_schedule->lastRunTime()->add($task_schedule->frequency())->lessThan(Carbon::now())) && |
|
241 | - $task_schedule->setLastResult(false) && // @phpstan-ignore-line Used as setter, not as a condition |
|
242 | - $task = $this->findTask($task_schedule->taskId()) |
|
243 | - ) { |
|
244 | - $task_schedule->startRunning(); |
|
245 | - $this->update($task_schedule); |
|
238 | + if ( |
|
239 | + !$task_schedule->isRunning() && |
|
240 | + ($force || $task_schedule->lastRunTime()->add($task_schedule->frequency())->lessThan(Carbon::now())) && |
|
241 | + $task_schedule->setLastResult(false) && // @phpstan-ignore-line Used as setter, not as a condition |
|
242 | + $task = $this->findTask($task_schedule->taskId()) |
|
243 | + ) { |
|
244 | + $task_schedule->startRunning(); |
|
245 | + $this->update($task_schedule); |
|
246 | 246 | |
247 | - try { |
|
248 | - $task_schedule->setLastResult($task->run($task_schedule)); |
|
249 | - } catch (Exception $ex) { |
|
250 | - } |
|
247 | + try { |
|
248 | + $task_schedule->setLastResult($task->run($task_schedule)); |
|
249 | + } catch (Exception $ex) { |
|
250 | + } |
|
251 | 251 | |
252 | - if ($task_schedule->wasLastRunSuccess()) { |
|
253 | - $task_schedule->setLastRunTime(Carbon::now()); |
|
254 | - $task_schedule->decrementRemainingOccurences(); |
|
255 | - } |
|
256 | - $task_schedule->stopRunning(); |
|
257 | - $this->update($task_schedule); |
|
258 | - } else { |
|
259 | - $this->update($task_schedule); |
|
260 | - } |
|
261 | - } |
|
252 | + if ($task_schedule->wasLastRunSuccess()) { |
|
253 | + $task_schedule->setLastRunTime(Carbon::now()); |
|
254 | + $task_schedule->decrementRemainingOccurences(); |
|
255 | + } |
|
256 | + $task_schedule->stopRunning(); |
|
257 | + $this->update($task_schedule); |
|
258 | + } else { |
|
259 | + $this->update($task_schedule); |
|
260 | + } |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * Mapper to return a TaskSchedule object from an object. |
|
265 | - * |
|
266 | - * @return Closure |
|
267 | - */ |
|
268 | - public static function rowMapper(): Closure |
|
269 | - { |
|
270 | - return static function (stdClass $row): TaskSchedule { |
|
263 | + /** |
|
264 | + * Mapper to return a TaskSchedule object from an object. |
|
265 | + * |
|
266 | + * @return Closure |
|
267 | + */ |
|
268 | + public static function rowMapper(): Closure |
|
269 | + { |
|
270 | + return static function (stdClass $row): TaskSchedule { |
|
271 | 271 | |
272 | - return new TaskSchedule( |
|
273 | - (int) $row->majat_id, |
|
274 | - $row->majat_task_id, |
|
275 | - $row->majat_status === 'enabled', |
|
276 | - Carbon::parse($row->majat_last_run), |
|
277 | - (bool) $row->majat_last_result, |
|
278 | - CarbonInterval::minutes($row->majat_frequency), |
|
279 | - (int) $row->majat_nb_occur, |
|
280 | - (bool) $row->majat_running |
|
281 | - ); |
|
282 | - }; |
|
283 | - } |
|
272 | + return new TaskSchedule( |
|
273 | + (int) $row->majat_id, |
|
274 | + $row->majat_task_id, |
|
275 | + $row->majat_status === 'enabled', |
|
276 | + Carbon::parse($row->majat_last_run), |
|
277 | + (bool) $row->majat_last_result, |
|
278 | + CarbonInterval::minutes($row->majat_frequency), |
|
279 | + (int) $row->majat_nb_occur, |
|
280 | + (bool) $row->majat_running |
|
281 | + ); |
|
282 | + }; |
|
283 | + } |
|
284 | 284 | } |
@@ -195,14 +195,14 @@ discard block |
||
195 | 195 | $query = DB::table('maj_admintasks') |
196 | 196 | ->select() |
197 | 197 | ->where('majat_status', '=', 'enabled') |
198 | - ->where(function (Builder $query) { |
|
198 | + ->where(function(Builder $query) { |
|
199 | 199 | |
200 | 200 | $query->where('majat_running', '=', 0) |
201 | 201 | ->orWhere('majat_last_run', '<=', Carbon::now()->subSeconds(self::TASK_TIME_OUT)); |
202 | 202 | }); |
203 | 203 | |
204 | 204 | if (!$force) { |
205 | - $query->where(function (Builder $query) { |
|
205 | + $query->where(function(Builder $query) { |
|
206 | 206 | |
207 | 207 | $query->where('majat_running', '=', 0) |
208 | 208 | ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()'); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | if ( |
239 | 239 | !$task_schedule->isRunning() && |
240 | 240 | ($force || $task_schedule->lastRunTime()->add($task_schedule->frequency())->lessThan(Carbon::now())) && |
241 | - $task_schedule->setLastResult(false) && // @phpstan-ignore-line Used as setter, not as a condition |
|
241 | + $task_schedule->setLastResult(false) && // @phpstan-ignore-line Used as setter, not as a condition |
|
242 | 242 | $task = $this->findTask($task_schedule->taskId()) |
243 | 243 | ) { |
244 | 244 | $task_schedule->startRunning(); |
@@ -267,17 +267,17 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public static function rowMapper(): Closure |
269 | 269 | { |
270 | - return static function (stdClass $row): TaskSchedule { |
|
270 | + return static function(stdClass $row): TaskSchedule { |
|
271 | 271 | |
272 | 272 | return new TaskSchedule( |
273 | - (int) $row->majat_id, |
|
273 | + (int)$row->majat_id, |
|
274 | 274 | $row->majat_task_id, |
275 | 275 | $row->majat_status === 'enabled', |
276 | 276 | Carbon::parse($row->majat_last_run), |
277 | - (bool) $row->majat_last_result, |
|
277 | + (bool)$row->majat_last_result, |
|
278 | 278 | CarbonInterval::minutes($row->majat_frequency), |
279 | - (int) $row->majat_nb_occur, |
|
280 | - (bool) $row->majat_running |
|
279 | + (int)$row->majat_nb_occur, |
|
280 | + (bool)$row->majat_running |
|
281 | 281 | ); |
282 | 282 | }; |
283 | 283 | } |
@@ -27,101 +27,101 @@ |
||
27 | 27 | */ |
28 | 28 | class HealthCheckService |
29 | 29 | { |
30 | - /** |
|
31 | - * Returns a query collating all gedcom records, for use in other queries |
|
32 | - * |
|
33 | - * @param Tree $tree |
|
34 | - * @return Builder |
|
35 | - */ |
|
36 | - private function allGedcomRecords(Tree $tree): Builder |
|
37 | - { |
|
38 | - return DB::table('individuals') |
|
39 | - ->select(DB::raw("'indi' AS ged_type"), 'i_id AS ged_id')->where('i_file', '=', $tree->id()) |
|
40 | - ->unionAll(DB::table('families') |
|
41 | - ->select(DB::raw("'fam' AS ged_type"), 'f_id AS ged_id')->where('f_file', '=', $tree->id())) |
|
42 | - ->unionAll(DB::table('sources') |
|
43 | - ->select(DB::raw("'sour' AS ged_type"), 's_id AS ged_id')->where('s_file', '=', $tree->id())) |
|
44 | - ->unionAll(DB::table('media') |
|
45 | - ->select(DB::raw("'media' AS ged_type"), 'm_id AS ged_id')->where('m_file', '=', $tree->id())) |
|
46 | - ->unionAll(DB::table('other') |
|
47 | - ->select(DB::raw('LOWER(o_type) AS ged_type'), 'o_id AS ged_id')->where('o_file', '=', $tree->id())); |
|
48 | - } |
|
30 | + /** |
|
31 | + * Returns a query collating all gedcom records, for use in other queries |
|
32 | + * |
|
33 | + * @param Tree $tree |
|
34 | + * @return Builder |
|
35 | + */ |
|
36 | + private function allGedcomRecords(Tree $tree): Builder |
|
37 | + { |
|
38 | + return DB::table('individuals') |
|
39 | + ->select(DB::raw("'indi' AS ged_type"), 'i_id AS ged_id')->where('i_file', '=', $tree->id()) |
|
40 | + ->unionAll(DB::table('families') |
|
41 | + ->select(DB::raw("'fam' AS ged_type"), 'f_id AS ged_id')->where('f_file', '=', $tree->id())) |
|
42 | + ->unionAll(DB::table('sources') |
|
43 | + ->select(DB::raw("'sour' AS ged_type"), 's_id AS ged_id')->where('s_file', '=', $tree->id())) |
|
44 | + ->unionAll(DB::table('media') |
|
45 | + ->select(DB::raw("'media' AS ged_type"), 'm_id AS ged_id')->where('m_file', '=', $tree->id())) |
|
46 | + ->unionAll(DB::table('other') |
|
47 | + ->select(DB::raw('LOWER(o_type) AS ged_type'), 'o_id AS ged_id')->where('o_file', '=', $tree->id())); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns the count of gedcom records by type in a Tree, as a keyed Collection. |
|
52 | - * |
|
53 | - * Collection output: |
|
54 | - * - Key : gedcom record type |
|
55 | - * - Value: count of records |
|
56 | - * |
|
57 | - * @param Tree $tree |
|
58 | - * @return Collection |
|
59 | - */ |
|
60 | - public function countByRecordType(Tree $tree): Collection |
|
61 | - { |
|
62 | - return DB::query() |
|
63 | - ->fromSub($this->allGedcomRecords($tree), 'gedrecords') |
|
64 | - ->select('ged_type', new Expression('COUNT(ged_id) AS total')) |
|
65 | - ->groupBy('ged_type') |
|
66 | - ->pluck('total', 'ged_type'); |
|
67 | - } |
|
50 | + /** |
|
51 | + * Returns the count of gedcom records by type in a Tree, as a keyed Collection. |
|
52 | + * |
|
53 | + * Collection output: |
|
54 | + * - Key : gedcom record type |
|
55 | + * - Value: count of records |
|
56 | + * |
|
57 | + * @param Tree $tree |
|
58 | + * @return Collection |
|
59 | + */ |
|
60 | + public function countByRecordType(Tree $tree): Collection |
|
61 | + { |
|
62 | + return DB::query() |
|
63 | + ->fromSub($this->allGedcomRecords($tree), 'gedrecords') |
|
64 | + ->select('ged_type', new Expression('COUNT(ged_id) AS total')) |
|
65 | + ->groupBy('ged_type') |
|
66 | + ->pluck('total', 'ged_type'); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Returns the count of gedcom records changes by type in a Tree across a number of days, as a keyed Collection. |
|
71 | - * |
|
72 | - * Collection output: |
|
73 | - * - Key : gedcom record type |
|
74 | - * - Value: count of changes |
|
75 | - * |
|
76 | - * @param Tree $tree |
|
77 | - * @return Collection |
|
78 | - */ |
|
79 | - public function changesByRecordType(Tree $tree, int $nb_days): Collection |
|
80 | - { |
|
81 | - return DB::table('change') |
|
82 | - ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree) { |
|
69 | + /** |
|
70 | + * Returns the count of gedcom records changes by type in a Tree across a number of days, as a keyed Collection. |
|
71 | + * |
|
72 | + * Collection output: |
|
73 | + * - Key : gedcom record type |
|
74 | + * - Value: count of changes |
|
75 | + * |
|
76 | + * @param Tree $tree |
|
77 | + * @return Collection |
|
78 | + */ |
|
79 | + public function changesByRecordType(Tree $tree, int $nb_days): Collection |
|
80 | + { |
|
81 | + return DB::table('change') |
|
82 | + ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree) { |
|
83 | 83 | |
84 | - $join->on('change.xref', '=', 'gedrecords.ged_id') |
|
85 | - ->where('change.gedcom_id', '=', $tree->id()); |
|
86 | - }) |
|
87 | - ->select('ged_type AS type', new Expression('COUNT(change_id) AS count')) |
|
88 | - ->where('change.status', '', 'accepted') |
|
89 | - ->where('change.change_time', '>=', Carbon::now()->subDays($nb_days)) |
|
90 | - ->groupBy('ged_type') |
|
91 | - ->pluck('total', 'ged_type'); |
|
92 | - } |
|
84 | + $join->on('change.xref', '=', 'gedrecords.ged_id') |
|
85 | + ->where('change.gedcom_id', '=', $tree->id()); |
|
86 | + }) |
|
87 | + ->select('ged_type AS type', new Expression('COUNT(change_id) AS count')) |
|
88 | + ->where('change.status', '', 'accepted') |
|
89 | + ->where('change.change_time', '>=', Carbon::now()->subDays($nb_days)) |
|
90 | + ->groupBy('ged_type') |
|
91 | + ->pluck('total', 'ged_type'); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Return the error logs associated with a tree across a number of days, grouped by error message, as a Collection. |
|
96 | - * |
|
97 | - * Collection output: |
|
98 | - * - Value: stdClass object |
|
99 | - * - log message: Error log message |
|
100 | - * - type: 'site' if no associated Tree, the Tree ID otherwise |
|
101 | - * - nblogs: The number of occurence of the same error message |
|
102 | - * - lastoccurred: Date/time of the last occurence of the error message |
|
103 | - * |
|
104 | - * @param Tree $tree |
|
105 | - * @param int $nb_days |
|
106 | - * @return Collection |
|
107 | - */ |
|
108 | - public function errorLogs(Tree $tree, int $nb_days): Collection |
|
109 | - { |
|
110 | - return DB::table('log') |
|
111 | - ->select( |
|
112 | - 'log_message', |
|
113 | - new Expression("IFNULL(gedcom_id, 'site') as type"), |
|
114 | - new Expression('COUNT(log_id) AS nblogs'), |
|
115 | - new Expression('MAX(log_time) AS lastoccurred') |
|
116 | - ) |
|
117 | - ->where('log_type', '=', 'error') |
|
118 | - ->where(function (Builder $query) use ($tree) { |
|
119 | - $query->where('gedcom_id', '=', $tree->id()) |
|
120 | - ->orWhereNull('gedcom_id'); |
|
121 | - }) |
|
122 | - ->where('log_time', '>=', Carbon::now()->subDays($nb_days)) |
|
123 | - ->groupBy('log_message', 'gedcom_id') |
|
124 | - ->orderByDesc('lastoccurred') |
|
125 | - ->get(); |
|
126 | - } |
|
94 | + /** |
|
95 | + * Return the error logs associated with a tree across a number of days, grouped by error message, as a Collection. |
|
96 | + * |
|
97 | + * Collection output: |
|
98 | + * - Value: stdClass object |
|
99 | + * - log message: Error log message |
|
100 | + * - type: 'site' if no associated Tree, the Tree ID otherwise |
|
101 | + * - nblogs: The number of occurence of the same error message |
|
102 | + * - lastoccurred: Date/time of the last occurence of the error message |
|
103 | + * |
|
104 | + * @param Tree $tree |
|
105 | + * @param int $nb_days |
|
106 | + * @return Collection |
|
107 | + */ |
|
108 | + public function errorLogs(Tree $tree, int $nb_days): Collection |
|
109 | + { |
|
110 | + return DB::table('log') |
|
111 | + ->select( |
|
112 | + 'log_message', |
|
113 | + new Expression("IFNULL(gedcom_id, 'site') as type"), |
|
114 | + new Expression('COUNT(log_id) AS nblogs'), |
|
115 | + new Expression('MAX(log_time) AS lastoccurred') |
|
116 | + ) |
|
117 | + ->where('log_type', '=', 'error') |
|
118 | + ->where(function (Builder $query) use ($tree) { |
|
119 | + $query->where('gedcom_id', '=', $tree->id()) |
|
120 | + ->orWhereNull('gedcom_id'); |
|
121 | + }) |
|
122 | + ->where('log_time', '>=', Carbon::now()->subDays($nb_days)) |
|
123 | + ->groupBy('log_message', 'gedcom_id') |
|
124 | + ->orderByDesc('lastoccurred') |
|
125 | + ->get(); |
|
126 | + } |
|
127 | 127 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | public function changesByRecordType(Tree $tree, int $nb_days): Collection |
80 | 80 | { |
81 | 81 | return DB::table('change') |
82 | - ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree) { |
|
82 | + ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function(JoinClause $join) use ($tree) { |
|
83 | 83 | |
84 | 84 | $join->on('change.xref', '=', 'gedrecords.ged_id') |
85 | 85 | ->where('change.gedcom_id', '=', $tree->id()); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | new Expression('MAX(log_time) AS lastoccurred') |
116 | 116 | ) |
117 | 117 | ->where('log_type', '=', 'error') |
118 | - ->where(function (Builder $query) use ($tree) { |
|
118 | + ->where(function(Builder $query) use ($tree) { |
|
119 | 119 | $query->where('gedcom_id', '=', $tree->id()) |
120 | 120 | ->orWhereNull('gedcom_id'); |
121 | 121 | }) |