@@ -29,220 +29,220 @@ |
||
29 | 29 | class LineageBuilder |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * @var string $surname Reference surname |
|
34 | - */ |
|
35 | - private $surname; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var Tree $tree Reference tree |
|
39 | - */ |
|
40 | - private $tree; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var IndividualListModule $indilist_module |
|
44 | - */ |
|
45 | - private $indilist_module; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var Collection $used_indis Individuals already processed |
|
49 | - */ |
|
50 | - private $used_indis; |
|
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, IndividualListModule $indilist_module) |
|
59 | - { |
|
60 | - $this->surname = $surname; |
|
61 | - $this->tree = $tree; |
|
62 | - $this->indilist_module = $indilist_module; |
|
63 | - $this->used_indis = new Collection(); |
|
64 | - } |
|
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 | - if ($this->indilist_module === null) { |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale()); |
|
78 | - //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality |
|
79 | - if (count($indis) == 0) { |
|
80 | - return null; |
|
81 | - } |
|
82 | - |
|
83 | - $root_lineages = new Collection(); |
|
84 | - |
|
85 | - foreach ($indis as $indi) { |
|
86 | - /** @var Individual $indi */ |
|
87 | - if ($this->used_indis->get($indi->xref(), false) === false) { |
|
88 | - $indi_first = $this->getLineageRootIndividual($indi); |
|
89 | - if ($indi_first !== null) { |
|
90 | - // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
91 | - $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
92 | - } |
|
93 | - if ($indi_first === null) { |
|
94 | - continue; |
|
95 | - } |
|
96 | - $this->used_indis->put($indi_first->xref(), true); |
|
97 | - if ($indi_first->canShow()) { |
|
98 | - //Check if the root individual has brothers and sisters, without parents |
|
99 | - $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
100 | - if ($indi_first_child_family !== null) { |
|
101 | - $root_node = new LineageRootNode(null); |
|
102 | - $root_node->addFamily($indi_first_child_family); |
|
103 | - } else { |
|
104 | - $root_node = new LineageRootNode($indi_first); |
|
105 | - } |
|
106 | - $root_node = $this->buildLineage($root_node); |
|
107 | - $root_lineages->add($root_node); |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
113 | - |
|
114 | - if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
115 | - return 0; |
|
116 | - } |
|
117 | - return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
118 | - }); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Retrieve the root individual, from any individual, by recursion. |
|
123 | - * The Root individual is the individual without a father, or without a mother holding the same name. |
|
124 | - * |
|
125 | - * @param Individual $indi |
|
126 | - * @return Individual|NULL Root individual |
|
127 | - */ |
|
128 | - private function getLineageRootIndividual(Individual $indi): ?Individual |
|
129 | - { |
|
130 | - $child_families = $indi->childFamilies(); |
|
131 | - if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
132 | - return null; |
|
133 | - } |
|
134 | - |
|
135 | - foreach ($child_families as $child_family) { |
|
136 | - /** @var Family $child_family */ |
|
137 | - $child_family->husband(); |
|
138 | - if (($husb = $child_family->husband()) !== null) { |
|
139 | - if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
140 | - return $indi; |
|
141 | - } |
|
142 | - return $this->getLineageRootIndividual($husb); |
|
143 | - } elseif (($wife = $child_family->wife()) !== null) { |
|
144 | - if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
145 | - $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
146 | - $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
147 | - if ( |
|
148 | - $indi->canShowName() |
|
149 | - && $wife->canShowName() |
|
150 | - && I18N::strcasecmp($indi_surname, $wife_surname) == 0 |
|
151 | - ) { |
|
152 | - return $this->getLineageRootIndividual($wife); |
|
153 | - } |
|
154 | - } |
|
155 | - return $indi; |
|
156 | - } |
|
157 | - } |
|
158 | - return $indi; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Computes descendent Lineage from a node. |
|
163 | - * Uses recursion to build the lineage tree |
|
164 | - * |
|
165 | - * @param LineageNode $node |
|
166 | - * @return LineageNode Computed lineage |
|
167 | - */ |
|
168 | - private function buildLineage(LineageNode $node): LineageNode |
|
169 | - { |
|
170 | - $indi_surname = ''; |
|
171 | - |
|
172 | - $indi_node = $node->individual(); |
|
173 | - if ($indi_node !== null) { |
|
174 | - if ($node->families()->count() == 0) { |
|
175 | - foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
176 | - $node->addFamily($spouse_family); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
181 | - $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
182 | - |
|
183 | - //Tag the individual as used |
|
184 | - $this->used_indis->put($indi_node->xref(), true); |
|
185 | - } |
|
186 | - |
|
187 | - foreach ($node->families() as $family_node) { |
|
188 | - /** @var Family $spouse_family */ |
|
189 | - $spouse_family = $family_node->family; |
|
190 | - $spouse_surname = ''; |
|
191 | - $spouse = null; |
|
192 | - if ( |
|
193 | - $indi_node !== null && |
|
194 | - ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
195 | - ) { |
|
196 | - $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
197 | - } |
|
198 | - |
|
199 | - $nb_children = $nb_natural = 0; |
|
200 | - |
|
201 | - foreach ($spouse_family->children() as $child) { |
|
202 | - if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
203 | - $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
204 | - |
|
205 | - $nb_children++; |
|
206 | - if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
207 | - //Print only lineages of children with the same surname as their mother |
|
208 | - //(supposing they are natural children) |
|
209 | - if ( |
|
210 | - $spouse === null || |
|
211 | - ($spouse_surname !== '' && I18N::strcasecmp($child_surname, $spouse_surname) != 0) |
|
212 | - ) { |
|
213 | - if (I18N::strcasecmp($child_surname, $indi_surname) == 0) { |
|
214 | - $nb_natural++; |
|
215 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
216 | - $node_child = $this->buildLineage($node_child); |
|
217 | - $node->addChild($spouse_family, $node_child); |
|
218 | - } |
|
219 | - } |
|
220 | - } else { //If the root individual is the father |
|
221 | - $nb_natural++; |
|
222 | - //Print if the children does not bear the same name as his mother |
|
223 | - //(and different from his father) |
|
224 | - if ( |
|
225 | - mb_strlen($child_surname) == 0 || |
|
226 | - mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
227 | - I18N::strcasecmp($child_surname, $indi_surname) == 0 || |
|
228 | - I18N::strcasecmp($child_surname, $spouse_surname) != 0 |
|
229 | - ) { |
|
230 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
231 | - $node_child = $this->buildLineage($node_child); |
|
232 | - } else { |
|
233 | - $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
234 | - } |
|
235 | - $node->addChild($spouse_family, $node_child); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - //Do not print other children |
|
241 | - if (($nb_children - $nb_natural) > 0) { |
|
242 | - $node->addChild($spouse_family, null); |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - return $node; |
|
247 | - } |
|
32 | + /** |
|
33 | + * @var string $surname Reference surname |
|
34 | + */ |
|
35 | + private $surname; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var Tree $tree Reference tree |
|
39 | + */ |
|
40 | + private $tree; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var IndividualListModule $indilist_module |
|
44 | + */ |
|
45 | + private $indilist_module; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var Collection $used_indis Individuals already processed |
|
49 | + */ |
|
50 | + private $used_indis; |
|
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, IndividualListModule $indilist_module) |
|
59 | + { |
|
60 | + $this->surname = $surname; |
|
61 | + $this->tree = $tree; |
|
62 | + $this->indilist_module = $indilist_module; |
|
63 | + $this->used_indis = new Collection(); |
|
64 | + } |
|
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 | + if ($this->indilist_module === null) { |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale()); |
|
78 | + //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality |
|
79 | + if (count($indis) == 0) { |
|
80 | + return null; |
|
81 | + } |
|
82 | + |
|
83 | + $root_lineages = new Collection(); |
|
84 | + |
|
85 | + foreach ($indis as $indi) { |
|
86 | + /** @var Individual $indi */ |
|
87 | + if ($this->used_indis->get($indi->xref(), false) === false) { |
|
88 | + $indi_first = $this->getLineageRootIndividual($indi); |
|
89 | + if ($indi_first !== null) { |
|
90 | + // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
91 | + $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
92 | + } |
|
93 | + if ($indi_first === null) { |
|
94 | + continue; |
|
95 | + } |
|
96 | + $this->used_indis->put($indi_first->xref(), true); |
|
97 | + if ($indi_first->canShow()) { |
|
98 | + //Check if the root individual has brothers and sisters, without parents |
|
99 | + $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
100 | + if ($indi_first_child_family !== null) { |
|
101 | + $root_node = new LineageRootNode(null); |
|
102 | + $root_node->addFamily($indi_first_child_family); |
|
103 | + } else { |
|
104 | + $root_node = new LineageRootNode($indi_first); |
|
105 | + } |
|
106 | + $root_node = $this->buildLineage($root_node); |
|
107 | + $root_lineages->add($root_node); |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
113 | + |
|
114 | + if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
115 | + return 0; |
|
116 | + } |
|
117 | + return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
118 | + }); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Retrieve the root individual, from any individual, by recursion. |
|
123 | + * The Root individual is the individual without a father, or without a mother holding the same name. |
|
124 | + * |
|
125 | + * @param Individual $indi |
|
126 | + * @return Individual|NULL Root individual |
|
127 | + */ |
|
128 | + private function getLineageRootIndividual(Individual $indi): ?Individual |
|
129 | + { |
|
130 | + $child_families = $indi->childFamilies(); |
|
131 | + if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
132 | + return null; |
|
133 | + } |
|
134 | + |
|
135 | + foreach ($child_families as $child_family) { |
|
136 | + /** @var Family $child_family */ |
|
137 | + $child_family->husband(); |
|
138 | + if (($husb = $child_family->husband()) !== null) { |
|
139 | + if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
140 | + return $indi; |
|
141 | + } |
|
142 | + return $this->getLineageRootIndividual($husb); |
|
143 | + } elseif (($wife = $child_family->wife()) !== null) { |
|
144 | + if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
145 | + $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
146 | + $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
147 | + if ( |
|
148 | + $indi->canShowName() |
|
149 | + && $wife->canShowName() |
|
150 | + && I18N::strcasecmp($indi_surname, $wife_surname) == 0 |
|
151 | + ) { |
|
152 | + return $this->getLineageRootIndividual($wife); |
|
153 | + } |
|
154 | + } |
|
155 | + return $indi; |
|
156 | + } |
|
157 | + } |
|
158 | + return $indi; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Computes descendent Lineage from a node. |
|
163 | + * Uses recursion to build the lineage tree |
|
164 | + * |
|
165 | + * @param LineageNode $node |
|
166 | + * @return LineageNode Computed lineage |
|
167 | + */ |
|
168 | + private function buildLineage(LineageNode $node): LineageNode |
|
169 | + { |
|
170 | + $indi_surname = ''; |
|
171 | + |
|
172 | + $indi_node = $node->individual(); |
|
173 | + if ($indi_node !== null) { |
|
174 | + if ($node->families()->count() == 0) { |
|
175 | + foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
176 | + $node->addFamily($spouse_family); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
181 | + $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
182 | + |
|
183 | + //Tag the individual as used |
|
184 | + $this->used_indis->put($indi_node->xref(), true); |
|
185 | + } |
|
186 | + |
|
187 | + foreach ($node->families() as $family_node) { |
|
188 | + /** @var Family $spouse_family */ |
|
189 | + $spouse_family = $family_node->family; |
|
190 | + $spouse_surname = ''; |
|
191 | + $spouse = null; |
|
192 | + if ( |
|
193 | + $indi_node !== null && |
|
194 | + ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
195 | + ) { |
|
196 | + $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
197 | + } |
|
198 | + |
|
199 | + $nb_children = $nb_natural = 0; |
|
200 | + |
|
201 | + foreach ($spouse_family->children() as $child) { |
|
202 | + if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
203 | + $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
204 | + |
|
205 | + $nb_children++; |
|
206 | + if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
207 | + //Print only lineages of children with the same surname as their mother |
|
208 | + //(supposing they are natural children) |
|
209 | + if ( |
|
210 | + $spouse === null || |
|
211 | + ($spouse_surname !== '' && I18N::strcasecmp($child_surname, $spouse_surname) != 0) |
|
212 | + ) { |
|
213 | + if (I18N::strcasecmp($child_surname, $indi_surname) == 0) { |
|
214 | + $nb_natural++; |
|
215 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
216 | + $node_child = $this->buildLineage($node_child); |
|
217 | + $node->addChild($spouse_family, $node_child); |
|
218 | + } |
|
219 | + } |
|
220 | + } else { //If the root individual is the father |
|
221 | + $nb_natural++; |
|
222 | + //Print if the children does not bear the same name as his mother |
|
223 | + //(and different from his father) |
|
224 | + if ( |
|
225 | + mb_strlen($child_surname) == 0 || |
|
226 | + mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
227 | + I18N::strcasecmp($child_surname, $indi_surname) == 0 || |
|
228 | + I18N::strcasecmp($child_surname, $spouse_surname) != 0 |
|
229 | + ) { |
|
230 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
231 | + $node_child = $this->buildLineage($node_child); |
|
232 | + } else { |
|
233 | + $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
234 | + } |
|
235 | + $node->addChild($spouse_family, $node_child); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + //Do not print other children |
|
241 | + if (($nb_children - $nb_natural) > 0) { |
|
242 | + $node->addChild($spouse_family, null); |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + return $node; |
|
247 | + } |
|
248 | 248 | } |
@@ -25,117 +25,117 @@ |
||
25 | 25 | class LineageNode |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var Collection $linked_fams Spouse families linked to the node |
|
30 | - */ |
|
31 | - private $linked_fams; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var ?Individual $node_indi Reference individual for the node |
|
35 | - */ |
|
36 | - private $node_indi; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var LineageRootNode $root_node Root node of the lineage |
|
40 | - */ |
|
41 | - private $root_node; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var ?string $alt_surname Linked surname, used to link to another lineage |
|
45 | - */ |
|
46 | - private $alt_surname; |
|
47 | - |
|
48 | - /** |
|
49 | - * Constructor for Lineage node |
|
50 | - * |
|
51 | - * @param Individual $node_indi Main individual |
|
52 | - * @param LineageRootNode $root_node Node of the lineage root |
|
53 | - * @param null|string $alt_surname Follow-up surname |
|
54 | - */ |
|
55 | - public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null) |
|
56 | - { |
|
57 | - $this->node_indi = $node_indi; |
|
58 | - $this->root_node = $root_node; |
|
59 | - $this->alt_surname = $alt_surname; |
|
60 | - $this->linked_fams = new Collection(); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Add a spouse family to the node |
|
65 | - * |
|
66 | - * @param Family $fams |
|
67 | - * @return stdClass |
|
68 | - */ |
|
69 | - public function addFamily(Family $fams): object |
|
70 | - { |
|
71 | - if (!$this->linked_fams->has($fams->xref())) { |
|
72 | - $this->linked_fams->put($fams->xref(), (object) [ |
|
73 | - 'family' => $fams, |
|
74 | - 'children' => new Collection() |
|
75 | - ]); |
|
76 | - } |
|
77 | - return $this->linked_fams->get($fams->xref()); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Add a child LineageNode to the node |
|
82 | - * |
|
83 | - * @param Family $fams |
|
84 | - * @param LineageNode $child |
|
85 | - */ |
|
86 | - public function addChild(Family $fams, LineageNode $child = null): void |
|
87 | - { |
|
88 | - $this->addFamily($fams)->children->push($child); |
|
89 | - $this->root_node->incrementChildNodes(); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Returns the node individual |
|
94 | - * |
|
95 | - * @return Individual|NULL |
|
96 | - */ |
|
97 | - public function individual(): ?Individual |
|
98 | - { |
|
99 | - return $this->node_indi; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Returns the lineage root node individual |
|
104 | - * |
|
105 | - * @return LineageRootNode |
|
106 | - */ |
|
107 | - public function rootNode(): LineageRootNode |
|
108 | - { |
|
109 | - return $this->root_node; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Returns the spouse families linked to the node |
|
114 | - * |
|
115 | - * @return Collection |
|
116 | - */ |
|
117 | - public function families(): Collection |
|
118 | - { |
|
119 | - return $this->linked_fams; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns the follow-up surname |
|
124 | - * |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function followUpSurname(): string |
|
128 | - { |
|
129 | - return $this->alt_surname ?? ''; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Indicates whether the node has a follow up surname |
|
134 | - * |
|
135 | - * @return boolean |
|
136 | - */ |
|
137 | - public function hasFollowUpSurname(): bool |
|
138 | - { |
|
139 | - return mb_strlen($this->followUpSurname()) > 0 ; |
|
140 | - } |
|
28 | + /** |
|
29 | + * @var Collection $linked_fams Spouse families linked to the node |
|
30 | + */ |
|
31 | + private $linked_fams; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var ?Individual $node_indi Reference individual for the node |
|
35 | + */ |
|
36 | + private $node_indi; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var LineageRootNode $root_node Root node of the lineage |
|
40 | + */ |
|
41 | + private $root_node; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var ?string $alt_surname Linked surname, used to link to another lineage |
|
45 | + */ |
|
46 | + private $alt_surname; |
|
47 | + |
|
48 | + /** |
|
49 | + * Constructor for Lineage node |
|
50 | + * |
|
51 | + * @param Individual $node_indi Main individual |
|
52 | + * @param LineageRootNode $root_node Node of the lineage root |
|
53 | + * @param null|string $alt_surname Follow-up surname |
|
54 | + */ |
|
55 | + public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null) |
|
56 | + { |
|
57 | + $this->node_indi = $node_indi; |
|
58 | + $this->root_node = $root_node; |
|
59 | + $this->alt_surname = $alt_surname; |
|
60 | + $this->linked_fams = new Collection(); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Add a spouse family to the node |
|
65 | + * |
|
66 | + * @param Family $fams |
|
67 | + * @return stdClass |
|
68 | + */ |
|
69 | + public function addFamily(Family $fams): object |
|
70 | + { |
|
71 | + if (!$this->linked_fams->has($fams->xref())) { |
|
72 | + $this->linked_fams->put($fams->xref(), (object) [ |
|
73 | + 'family' => $fams, |
|
74 | + 'children' => new Collection() |
|
75 | + ]); |
|
76 | + } |
|
77 | + return $this->linked_fams->get($fams->xref()); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Add a child LineageNode to the node |
|
82 | + * |
|
83 | + * @param Family $fams |
|
84 | + * @param LineageNode $child |
|
85 | + */ |
|
86 | + public function addChild(Family $fams, LineageNode $child = null): void |
|
87 | + { |
|
88 | + $this->addFamily($fams)->children->push($child); |
|
89 | + $this->root_node->incrementChildNodes(); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Returns the node individual |
|
94 | + * |
|
95 | + * @return Individual|NULL |
|
96 | + */ |
|
97 | + public function individual(): ?Individual |
|
98 | + { |
|
99 | + return $this->node_indi; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Returns the lineage root node individual |
|
104 | + * |
|
105 | + * @return LineageRootNode |
|
106 | + */ |
|
107 | + public function rootNode(): LineageRootNode |
|
108 | + { |
|
109 | + return $this->root_node; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Returns the spouse families linked to the node |
|
114 | + * |
|
115 | + * @return Collection |
|
116 | + */ |
|
117 | + public function families(): Collection |
|
118 | + { |
|
119 | + return $this->linked_fams; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns the follow-up surname |
|
124 | + * |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function followUpSurname(): string |
|
128 | + { |
|
129 | + return $this->alt_surname ?? ''; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Indicates whether the node has a follow up surname |
|
134 | + * |
|
135 | + * @return boolean |
|
136 | + */ |
|
137 | + public function hasFollowUpSurname(): bool |
|
138 | + { |
|
139 | + return mb_strlen($this->followUpSurname()) > 0 ; |
|
140 | + } |
|
141 | 141 | } |
@@ -31,69 +31,69 @@ |
||
31 | 31 | */ |
32 | 32 | class LineagesPage implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var PatronymicLineageModule $module |
|
38 | - */ |
|
39 | - private $module; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var IndividualListModule $indilist_module |
|
43 | - */ |
|
44 | - private $indilist_module; |
|
45 | - |
|
46 | - /** |
|
47 | - * Constructor for LineagesPage Request handler |
|
48 | - * |
|
49 | - * @param ModuleService $module_service |
|
50 | - */ |
|
51 | - public function __construct(ModuleService $module_service) |
|
52 | - { |
|
53 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
54 | - $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
55 | - } |
|
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 | - } |
|
66 | - |
|
67 | - if ($this->indilist_module === null) { |
|
68 | - throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
69 | - } |
|
70 | - |
|
71 | - $tree = $request->getAttribute('tree'); |
|
72 | - assert($tree instanceof Tree); |
|
73 | - |
|
74 | - $surname = $request->getAttribute('surname'); |
|
75 | - |
|
76 | - $initial = mb_substr($surname, 0, 1); |
|
77 | - $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
78 | - ->reject(function ($count, $initial): bool { |
|
79 | - |
|
80 | - return $initial === '@' || $initial === ','; |
|
81 | - }); |
|
82 | - |
|
83 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
84 | - |
|
85 | - $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
86 | - |
|
87 | - return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
88 | - 'title' => $title, |
|
89 | - 'module' => $this->module, |
|
90 | - 'tree' => $tree, |
|
91 | - 'initials_list' => $initials_list, |
|
92 | - 'initial' => $initial, |
|
93 | - 'show_all' => 'no', |
|
94 | - 'surname' => $surname, |
|
95 | - 'lineages' => $lineages, |
|
96 | - 'nb_lineages' => $lineages !== null ? $lineages->count() : 0 |
|
97 | - ]); |
|
98 | - } |
|
34 | + use ViewResponseTrait; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var PatronymicLineageModule $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var IndividualListModule $indilist_module |
|
43 | + */ |
|
44 | + private $indilist_module; |
|
45 | + |
|
46 | + /** |
|
47 | + * Constructor for LineagesPage Request handler |
|
48 | + * |
|
49 | + * @param ModuleService $module_service |
|
50 | + */ |
|
51 | + public function __construct(ModuleService $module_service) |
|
52 | + { |
|
53 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
54 | + $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
55 | + } |
|
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 | + } |
|
66 | + |
|
67 | + if ($this->indilist_module === null) { |
|
68 | + throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
69 | + } |
|
70 | + |
|
71 | + $tree = $request->getAttribute('tree'); |
|
72 | + assert($tree instanceof Tree); |
|
73 | + |
|
74 | + $surname = $request->getAttribute('surname'); |
|
75 | + |
|
76 | + $initial = mb_substr($surname, 0, 1); |
|
77 | + $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
78 | + ->reject(function ($count, $initial): bool { |
|
79 | + |
|
80 | + return $initial === '@' || $initial === ','; |
|
81 | + }); |
|
82 | + |
|
83 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
84 | + |
|
85 | + $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
86 | + |
|
87 | + return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
88 | + 'title' => $title, |
|
89 | + 'module' => $this->module, |
|
90 | + 'tree' => $tree, |
|
91 | + 'initials_list' => $initials_list, |
|
92 | + 'initial' => $initial, |
|
93 | + 'show_all' => 'no', |
|
94 | + 'surname' => $surname, |
|
95 | + 'lineages' => $lineages, |
|
96 | + 'nb_lineages' => $lineages !== null ? $lineages->count() : 0 |
|
97 | + ]); |
|
98 | + } |
|
99 | 99 | } |
@@ -30,74 +30,74 @@ |
||
30 | 30 | */ |
31 | 31 | class SurnamesList implements RequestHandlerInterface |
32 | 32 | { |
33 | - use ViewResponseTrait; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var PatronymicLineageModule $module |
|
37 | - */ |
|
38 | - private $module; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var IndividualListModule $indilist_module |
|
42 | - */ |
|
43 | - private $indilist_module; |
|
44 | - |
|
45 | - /** |
|
46 | - * Constructor for SurnamesList Request Handler |
|
47 | - * |
|
48 | - * @param ModuleService $module_service |
|
49 | - */ |
|
50 | - public function __construct(ModuleService $module_service) |
|
51 | - { |
|
52 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
53 | - $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | - */ |
|
60 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | - { |
|
62 | - if ($this->module === null) { |
|
63 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | - } |
|
65 | - |
|
66 | - if ($this->indilist_module === null) { |
|
67 | - throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
68 | - } |
|
69 | - |
|
70 | - $tree = $request->getAttribute('tree'); |
|
71 | - assert($tree instanceof Tree); |
|
72 | - |
|
73 | - $initial = $request->getAttribute('alpha'); |
|
74 | - $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
75 | - ->reject(function ($count, $initial): bool { |
|
76 | - |
|
77 | - return $initial === '@' || $initial === ','; |
|
78 | - }); |
|
79 | - |
|
80 | - $show_all = $request->getQueryParams()['show_all'] ?? 'no'; |
|
81 | - |
|
82 | - if ($show_all === 'yes') { |
|
83 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
84 | - $surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale()); |
|
85 | - } elseif ($initial !== null && mb_strlen($initial) == 1) { |
|
86 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
87 | - $surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale()); |
|
88 | - } else { |
|
89 | - $title = I18N::translate('Patronymic Lineages'); |
|
90 | - $surnames = []; |
|
91 | - } |
|
92 | - |
|
93 | - return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
94 | - 'title' => $title, |
|
95 | - 'module' => $this->module, |
|
96 | - 'tree' => $tree, |
|
97 | - 'initials_list' => $initials_list, |
|
98 | - 'initial' => $initial, |
|
99 | - 'show_all' => $show_all, |
|
100 | - 'surnames' => $surnames |
|
101 | - ]); |
|
102 | - } |
|
33 | + use ViewResponseTrait; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var PatronymicLineageModule $module |
|
37 | + */ |
|
38 | + private $module; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var IndividualListModule $indilist_module |
|
42 | + */ |
|
43 | + private $indilist_module; |
|
44 | + |
|
45 | + /** |
|
46 | + * Constructor for SurnamesList Request Handler |
|
47 | + * |
|
48 | + * @param ModuleService $module_service |
|
49 | + */ |
|
50 | + public function __construct(ModuleService $module_service) |
|
51 | + { |
|
52 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
53 | + $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | + */ |
|
60 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | + { |
|
62 | + if ($this->module === null) { |
|
63 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | + } |
|
65 | + |
|
66 | + if ($this->indilist_module === null) { |
|
67 | + throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
68 | + } |
|
69 | + |
|
70 | + $tree = $request->getAttribute('tree'); |
|
71 | + assert($tree instanceof Tree); |
|
72 | + |
|
73 | + $initial = $request->getAttribute('alpha'); |
|
74 | + $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
75 | + ->reject(function ($count, $initial): bool { |
|
76 | + |
|
77 | + return $initial === '@' || $initial === ','; |
|
78 | + }); |
|
79 | + |
|
80 | + $show_all = $request->getQueryParams()['show_all'] ?? 'no'; |
|
81 | + |
|
82 | + if ($show_all === 'yes') { |
|
83 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
84 | + $surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale()); |
|
85 | + } elseif ($initial !== null && mb_strlen($initial) == 1) { |
|
86 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
87 | + $surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale()); |
|
88 | + } else { |
|
89 | + $title = I18N::translate('Patronymic Lineages'); |
|
90 | + $surnames = []; |
|
91 | + } |
|
92 | + |
|
93 | + return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
94 | + 'title' => $title, |
|
95 | + 'module' => $this->module, |
|
96 | + 'tree' => $tree, |
|
97 | + 'initials_list' => $initials_list, |
|
98 | + 'initial' => $initial, |
|
99 | + 'show_all' => $show_all, |
|
100 | + 'surnames' => $surnames |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | } |
@@ -33,95 +33,95 @@ |
||
33 | 33 | */ |
34 | 34 | class PatronymicLineageModule extends AbstractModuleMaj implements ModuleListInterface, ModuleGlobalInterface |
35 | 35 | { |
36 | - use ModuleListTrait; |
|
37 | - use ModuleGlobalTrait; |
|
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 | - } |
|
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 | - } |
|
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): void { |
|
65 | - |
|
66 | - $router->attach('', '/module-maj/lineages', static function (Map $router): void { |
|
67 | - |
|
68 | - $router->attach('', '/Page', static function (Map $router): void { |
|
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 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * {@inheritDoc} |
|
79 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
80 | - */ |
|
81 | - public function customModuleVersion(): string |
|
82 | - { |
|
83 | - return '2.0.7-v.1'; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * {@inheritDoc} |
|
88 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
89 | - */ |
|
90 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
91 | - { |
|
92 | - $surname = $parameters['surname'] ?? ''; |
|
93 | - |
|
94 | - $xref = app(ServerRequestInterface::class)->getAttribute('xref', ''); |
|
95 | - if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) { |
|
96 | - $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname']; |
|
97 | - } |
|
98 | - |
|
99 | - if ($surname !== '') { |
|
100 | - return route(LineagesPage::class, [ |
|
101 | - 'tree' => $tree->name(), |
|
102 | - 'surname' => $surname |
|
103 | - ] + $parameters); |
|
104 | - } |
|
105 | - return route(SurnamesList::class, [ |
|
106 | - 'tree' => $tree->name() |
|
107 | - ] + $parameters); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * {@inheritDoc} |
|
112 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
113 | - */ |
|
114 | - public function listMenuClass(): string |
|
115 | - { |
|
116 | - return 'menu-maj-patrolineage'; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * {@inheritDoc} |
|
121 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
122 | - */ |
|
123 | - public function headContent(): string |
|
124 | - { |
|
125 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
126 | - } |
|
36 | + use ModuleListTrait; |
|
37 | + use ModuleGlobalTrait; |
|
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 | + } |
|
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 | + } |
|
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): void { |
|
65 | + |
|
66 | + $router->attach('', '/module-maj/lineages', static function (Map $router): void { |
|
67 | + |
|
68 | + $router->attach('', '/Page', static function (Map $router): void { |
|
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 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * {@inheritDoc} |
|
79 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
80 | + */ |
|
81 | + public function customModuleVersion(): string |
|
82 | + { |
|
83 | + return '2.0.7-v.1'; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * {@inheritDoc} |
|
88 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
89 | + */ |
|
90 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
91 | + { |
|
92 | + $surname = $parameters['surname'] ?? ''; |
|
93 | + |
|
94 | + $xref = app(ServerRequestInterface::class)->getAttribute('xref', ''); |
|
95 | + if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) { |
|
96 | + $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname']; |
|
97 | + } |
|
98 | + |
|
99 | + if ($surname !== '') { |
|
100 | + return route(LineagesPage::class, [ |
|
101 | + 'tree' => $tree->name(), |
|
102 | + 'surname' => $surname |
|
103 | + ] + $parameters); |
|
104 | + } |
|
105 | + return route(SurnamesList::class, [ |
|
106 | + 'tree' => $tree->name() |
|
107 | + ] + $parameters); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * {@inheritDoc} |
|
112 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
113 | + */ |
|
114 | + public function listMenuClass(): string |
|
115 | + { |
|
116 | + return 'menu-maj-patrolineage'; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * {@inheritDoc} |
|
121 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
122 | + */ |
|
123 | + public function headContent(): string |
|
124 | + { |
|
125 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
126 | + } |
|
127 | 127 | } |
@@ -27,50 +27,50 @@ |
||
27 | 27 | */ |
28 | 28 | class MatomoStats implements RequestHandlerInterface |
29 | 29 | { |
30 | - use ViewResponseTrait; |
|
30 | + use ViewResponseTrait; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var WelcomeBlockModule |
|
34 | - */ |
|
35 | - private $module; |
|
32 | + /** |
|
33 | + * @var WelcomeBlockModule |
|
34 | + */ |
|
35 | + private $module; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var MatomoStatsService $matomo_service |
|
39 | - */ |
|
40 | - private $matomo_service; |
|
37 | + /** |
|
38 | + * @var MatomoStatsService $matomo_service |
|
39 | + */ |
|
40 | + private $matomo_service; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor for MatomoStats request handler |
|
44 | - * @param ModuleService $module_service |
|
45 | - * @param MatomoStatsService $matomo_service |
|
46 | - */ |
|
47 | - public function __construct( |
|
48 | - ModuleService $module_service, |
|
49 | - MatomoStatsService $matomo_service |
|
50 | - ) { |
|
51 | - $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first(); |
|
52 | - $this->matomo_service = $matomo_service; |
|
53 | - } |
|
42 | + /** |
|
43 | + * Constructor for MatomoStats request handler |
|
44 | + * @param ModuleService $module_service |
|
45 | + * @param MatomoStatsService $matomo_service |
|
46 | + */ |
|
47 | + public function __construct( |
|
48 | + ModuleService $module_service, |
|
49 | + MatomoStatsService $matomo_service |
|
50 | + ) { |
|
51 | + $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first(); |
|
52 | + $this->matomo_service = $matomo_service; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
58 | - */ |
|
59 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
60 | - { |
|
61 | - $this->layout = 'layouts/ajax'; |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
58 | + */ |
|
59 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
60 | + { |
|
61 | + $this->layout = 'layouts/ajax'; |
|
62 | 62 | |
63 | - $block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT); |
|
64 | - $nb_visits_year = $nb_visits_today = null; |
|
63 | + $block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT); |
|
64 | + $nb_visits_year = $nb_visits_today = null; |
|
65 | 65 | |
66 | - if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) { |
|
67 | - $nb_visits_today = (int) $this->matomo_service->visitsToday($this->module, $block_id); |
|
68 | - $nb_visits_year = (int) $this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today; |
|
69 | - } |
|
66 | + if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) { |
|
67 | + $nb_visits_today = (int) $this->matomo_service->visitsToday($this->module, $block_id); |
|
68 | + $nb_visits_year = (int) $this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today; |
|
69 | + } |
|
70 | 70 | |
71 | - return $this->viewResponse($this->module->name() . '::matomo-stats', [ |
|
72 | - 'visits_year' => $nb_visits_year, |
|
73 | - 'visits_today' => $nb_visits_today |
|
74 | - ]); |
|
75 | - } |
|
71 | + return $this->viewResponse($this->module->name() . '::matomo-stats', [ |
|
72 | + 'visits_year' => $nb_visits_year, |
|
73 | + 'visits_today' => $nb_visits_today |
|
74 | + ]); |
|
75 | + } |
|
76 | 76 | } |
@@ -30,157 +30,157 @@ |
||
30 | 30 | */ |
31 | 31 | class WelcomeBlockModule extends AbstractModuleMaj implements ModuleBlockInterface |
32 | 32 | { |
33 | - use ModuleBlockTrait; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritDoc} |
|
37 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
38 | - */ |
|
39 | - public function title(): string |
|
40 | - { |
|
41 | - return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * {@inheritDoc} |
|
46 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
47 | - */ |
|
48 | - public function description(): string |
|
49 | - { |
|
50 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
51 | - return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * {@inheritDoc} |
|
56 | - * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes() |
|
57 | - */ |
|
58 | - public function loadRoutes(Map $router): void |
|
59 | - { |
|
60 | - $router->attach('', '', static function (Map $router): void { |
|
61 | - |
|
62 | - $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
63 | - |
|
64 | - $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
65 | - }); |
|
66 | - }); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
72 | - */ |
|
73 | - public function customModuleVersion(): string |
|
74 | - { |
|
75 | - return '2.0.6-v.1'; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * {@inheritDoc} |
|
80 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
81 | - */ |
|
82 | - public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
83 | - { |
|
84 | - $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
85 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
86 | - |
|
87 | - $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
88 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
89 | - |
|
90 | - $content = view($this->name() . '::block-embed', [ |
|
91 | - 'block_id' => $block_id, |
|
92 | - 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
93 | - 'fab_login_block_view' => $fab_login_block_view, |
|
94 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id) |
|
95 | - ]); |
|
96 | - |
|
97 | - if ($context !== self::CONTEXT_EMBED) { |
|
98 | - return view('modules/block-template', [ |
|
99 | - 'block' => Str::kebab($this->name()), |
|
100 | - 'id' => $block_id, |
|
101 | - 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
102 | - 'title' => $tree->title(), |
|
103 | - 'content' => $content, |
|
104 | - ]); |
|
105 | - } |
|
106 | - |
|
107 | - return $content; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * {@inheritDoc} |
|
112 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
113 | - */ |
|
114 | - public function isTreeBlock(): bool |
|
115 | - { |
|
116 | - return true; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * {@inheritDoc} |
|
121 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
122 | - */ |
|
123 | - public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
124 | - { |
|
125 | - return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * {@inheritDoc} |
|
130 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
131 | - */ |
|
132 | - public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
133 | - { |
|
134 | - $params = (array) $request->getParsedBody(); |
|
135 | - |
|
136 | - $matomo_enabled = $params['matomo_enabled'] == 'yes'; |
|
137 | - $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
138 | - if (!$matomo_enabled) { |
|
139 | - return; |
|
140 | - } |
|
141 | - |
|
142 | - if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) { |
|
143 | - FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
144 | - return; |
|
145 | - } |
|
146 | - |
|
147 | - if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) { |
|
148 | - FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
149 | - return; |
|
150 | - } |
|
151 | - |
|
152 | - $this |
|
153 | - ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url'])) |
|
154 | - ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token'])) |
|
155 | - ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']); |
|
156 | - |
|
157 | - app('cache.files')->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
162 | - * |
|
163 | - * @param int $block_id |
|
164 | - * @return bool |
|
165 | - */ |
|
166 | - public function isMatomoEnabled(int $block_id): bool |
|
167 | - { |
|
168 | - return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
173 | - * |
|
174 | - * @param int $block_id |
|
175 | - * @return array<string, mixed> |
|
176 | - */ |
|
177 | - public function matomoSettings(int $block_id): array |
|
178 | - { |
|
179 | - return [ |
|
180 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
181 | - 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
182 | - 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
183 | - 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
184 | - ]; |
|
185 | - } |
|
33 | + use ModuleBlockTrait; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritDoc} |
|
37 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
38 | + */ |
|
39 | + public function title(): string |
|
40 | + { |
|
41 | + return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * {@inheritDoc} |
|
46 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
47 | + */ |
|
48 | + public function description(): string |
|
49 | + { |
|
50 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
51 | + return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * {@inheritDoc} |
|
56 | + * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes() |
|
57 | + */ |
|
58 | + public function loadRoutes(Map $router): void |
|
59 | + { |
|
60 | + $router->attach('', '', static function (Map $router): void { |
|
61 | + |
|
62 | + $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
63 | + |
|
64 | + $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
65 | + }); |
|
66 | + }); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
72 | + */ |
|
73 | + public function customModuleVersion(): string |
|
74 | + { |
|
75 | + return '2.0.6-v.1'; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * {@inheritDoc} |
|
80 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
81 | + */ |
|
82 | + public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
83 | + { |
|
84 | + $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
85 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
86 | + |
|
87 | + $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
88 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
89 | + |
|
90 | + $content = view($this->name() . '::block-embed', [ |
|
91 | + 'block_id' => $block_id, |
|
92 | + 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
93 | + 'fab_login_block_view' => $fab_login_block_view, |
|
94 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id) |
|
95 | + ]); |
|
96 | + |
|
97 | + if ($context !== self::CONTEXT_EMBED) { |
|
98 | + return view('modules/block-template', [ |
|
99 | + 'block' => Str::kebab($this->name()), |
|
100 | + 'id' => $block_id, |
|
101 | + 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
102 | + 'title' => $tree->title(), |
|
103 | + 'content' => $content, |
|
104 | + ]); |
|
105 | + } |
|
106 | + |
|
107 | + return $content; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * {@inheritDoc} |
|
112 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
113 | + */ |
|
114 | + public function isTreeBlock(): bool |
|
115 | + { |
|
116 | + return true; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * {@inheritDoc} |
|
121 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
122 | + */ |
|
123 | + public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
124 | + { |
|
125 | + return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * {@inheritDoc} |
|
130 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
131 | + */ |
|
132 | + public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
133 | + { |
|
134 | + $params = (array) $request->getParsedBody(); |
|
135 | + |
|
136 | + $matomo_enabled = $params['matomo_enabled'] == 'yes'; |
|
137 | + $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
138 | + if (!$matomo_enabled) { |
|
139 | + return; |
|
140 | + } |
|
141 | + |
|
142 | + if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) { |
|
143 | + FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
144 | + return; |
|
145 | + } |
|
146 | + |
|
147 | + if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) { |
|
148 | + FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
149 | + return; |
|
150 | + } |
|
151 | + |
|
152 | + $this |
|
153 | + ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url'])) |
|
154 | + ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token'])) |
|
155 | + ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']); |
|
156 | + |
|
157 | + app('cache.files')->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
162 | + * |
|
163 | + * @param int $block_id |
|
164 | + * @return bool |
|
165 | + */ |
|
166 | + public function isMatomoEnabled(int $block_id): bool |
|
167 | + { |
|
168 | + return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
173 | + * |
|
174 | + * @param int $block_id |
|
175 | + * @return array<string, mixed> |
|
176 | + */ |
|
177 | + public function matomoSettings(int $block_id): array |
|
178 | + { |
|
179 | + return [ |
|
180 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
181 | + 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
182 | + 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
183 | + 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
184 | + ]; |
|
185 | + } |
|
186 | 186 | } |
@@ -30,95 +30,95 @@ |
||
30 | 30 | class MatomoStatsService |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * Returns the number of visits for the current year (up to the day before). |
|
35 | - * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
36 | - * |
|
37 | - * @param WelcomeBlockModule $module |
|
38 | - * @param int $block_id |
|
39 | - * @return int|NULL |
|
40 | - */ |
|
41 | - public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
42 | - { |
|
43 | - $cache = Registry::cache()->file(); |
|
33 | + /** |
|
34 | + * Returns the number of visits for the current year (up to the day before). |
|
35 | + * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
36 | + * |
|
37 | + * @param WelcomeBlockModule $module |
|
38 | + * @param int $block_id |
|
39 | + * @return int|NULL |
|
40 | + */ |
|
41 | + public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
42 | + { |
|
43 | + $cache = Registry::cache()->file(); |
|
44 | 44 | |
45 | - return $cache->remember( |
|
46 | - $module->name() . '-matomovisits-yearly-' . $block_id, |
|
47 | - function () use ($module, $block_id): ?int { |
|
48 | - $visits_year = $this->visits($module, $block_id, 'year'); |
|
49 | - if ($visits_year === null) { |
|
50 | - return null; |
|
51 | - } |
|
52 | - $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
45 | + return $cache->remember( |
|
46 | + $module->name() . '-matomovisits-yearly-' . $block_id, |
|
47 | + function () use ($module, $block_id): ?int { |
|
48 | + $visits_year = $this->visits($module, $block_id, 'year'); |
|
49 | + if ($visits_year === null) { |
|
50 | + return null; |
|
51 | + } |
|
52 | + $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
53 | 53 | |
54 | - return $visits_year - $visits_today; |
|
55 | - }, |
|
56 | - Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
57 | - ); |
|
58 | - } |
|
54 | + return $visits_year - $visits_today; |
|
55 | + }, |
|
56 | + Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Returns the number of visits for the current day. |
|
62 | - * |
|
63 | - * @param WelcomeBlockModule $module |
|
64 | - * @param int $block_id |
|
65 | - * @return int|NULL |
|
66 | - */ |
|
67 | - public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
68 | - { |
|
69 | - return app('cache.array')->remember( |
|
70 | - $module->name() . '-matomovisits-daily-' . $block_id, |
|
71 | - function () use ($module, $block_id): ?int { |
|
72 | - return $this->visits($module, $block_id, 'day'); |
|
73 | - } |
|
74 | - ); |
|
75 | - } |
|
60 | + /** |
|
61 | + * Returns the number of visits for the current day. |
|
62 | + * |
|
63 | + * @param WelcomeBlockModule $module |
|
64 | + * @param int $block_id |
|
65 | + * @return int|NULL |
|
66 | + */ |
|
67 | + public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
68 | + { |
|
69 | + return app('cache.array')->remember( |
|
70 | + $module->name() . '-matomovisits-daily-' . $block_id, |
|
71 | + function () use ($module, $block_id): ?int { |
|
72 | + return $this->visits($module, $block_id, 'day'); |
|
73 | + } |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Invoke the Matomo API to retrieve the number of visits over a period. |
|
79 | - * |
|
80 | - * @param WelcomeBlockModule $module |
|
81 | - * @param int $block_id |
|
82 | - * @param string $period |
|
83 | - * @return int|NULL |
|
84 | - */ |
|
85 | - protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
86 | - { |
|
87 | - $settings = $module->matomoSettings($block_id); |
|
77 | + /** |
|
78 | + * Invoke the Matomo API to retrieve the number of visits over a period. |
|
79 | + * |
|
80 | + * @param WelcomeBlockModule $module |
|
81 | + * @param int $block_id |
|
82 | + * @param string $period |
|
83 | + * @return int|NULL |
|
84 | + */ |
|
85 | + protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
86 | + { |
|
87 | + $settings = $module->matomoSettings($block_id); |
|
88 | 88 | |
89 | - if ( |
|
90 | - $settings['matomo_enabled'] === true |
|
91 | - && mb_strlen($settings['matomo_url']) > 0 |
|
92 | - && mb_strlen($settings['matomo_token']) > 0 |
|
93 | - && $settings['matomo_siteid'] > 0 |
|
94 | - ) { |
|
95 | - try { |
|
96 | - $http_client = new Client([ |
|
97 | - RequestOptions::TIMEOUT => 30 |
|
98 | - ]); |
|
89 | + if ( |
|
90 | + $settings['matomo_enabled'] === true |
|
91 | + && mb_strlen($settings['matomo_url']) > 0 |
|
92 | + && mb_strlen($settings['matomo_token']) > 0 |
|
93 | + && $settings['matomo_siteid'] > 0 |
|
94 | + ) { |
|
95 | + try { |
|
96 | + $http_client = new Client([ |
|
97 | + RequestOptions::TIMEOUT => 30 |
|
98 | + ]); |
|
99 | 99 | |
100 | - $response = $http_client->get($settings['matomo_url'], [ |
|
101 | - 'query' => [ |
|
102 | - 'module' => 'API', |
|
103 | - 'method' => 'VisitsSummary.getVisits', |
|
104 | - 'idSite' => $settings['matomo_siteid'], |
|
105 | - 'period' => $period, |
|
106 | - 'date' => 'today', |
|
107 | - 'token_auth' => $settings['matomo_token'], |
|
108 | - 'format' => 'json' |
|
109 | - ] |
|
110 | - ]); |
|
100 | + $response = $http_client->get($settings['matomo_url'], [ |
|
101 | + 'query' => [ |
|
102 | + 'module' => 'API', |
|
103 | + 'method' => 'VisitsSummary.getVisits', |
|
104 | + 'idSite' => $settings['matomo_siteid'], |
|
105 | + 'period' => $period, |
|
106 | + 'date' => 'today', |
|
107 | + 'token_auth' => $settings['matomo_token'], |
|
108 | + 'format' => 'json' |
|
109 | + ] |
|
110 | + ]); |
|
111 | 111 | |
112 | - if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
113 | - $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
114 | - if ($result !== null) { |
|
115 | - return (int)$result; |
|
116 | - } |
|
117 | - } |
|
118 | - } catch (RequestException $ex) { |
|
119 | - } |
|
120 | - } |
|
112 | + if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
113 | + $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
114 | + if ($result !== null) { |
|
115 | + return (int)$result; |
|
116 | + } |
|
117 | + } |
|
118 | + } catch (RequestException $ex) { |
|
119 | + } |
|
120 | + } |
|
121 | 121 | |
122 | - return null; |
|
123 | - } |
|
122 | + return null; |
|
123 | + } |
|
124 | 124 | } |
@@ -40,123 +40,123 @@ |
||
40 | 40 | * Allow for tasks to be run on a (nearly-)regular schedule |
41 | 41 | */ |
42 | 42 | class AdminTasksModule extends AbstractModuleMaj implements |
43 | - ModuleCustomInterface, |
|
44 | - ModuleConfigInterface, |
|
45 | - ModuleGlobalInterface, |
|
46 | - ModuleTasksProviderInterface |
|
43 | + ModuleCustomInterface, |
|
44 | + ModuleConfigInterface, |
|
45 | + ModuleGlobalInterface, |
|
46 | + ModuleTasksProviderInterface |
|
47 | 47 | { |
48 | - use ModuleConfigTrait; |
|
49 | - use ModuleGlobalTrait; |
|
50 | - |
|
51 | - //How to update the database schema for this module |
|
52 | - private const SCHEMA_TARGET_VERSION = 2; |
|
53 | - private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
|
54 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
59 | - */ |
|
60 | - public function title(): string |
|
61 | - { |
|
62 | - return I18N::translate('Administration Tasks'); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * {@inheritDoc} |
|
67 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
68 | - */ |
|
69 | - public function description(): string |
|
70 | - { |
|
71 | - return I18N::translate('Manage and run nearly-scheduled administration tasks.'); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * {@inheritDoc} |
|
76 | - * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::boot() |
|
77 | - */ |
|
78 | - public function boot(): void |
|
79 | - { |
|
80 | - parent::boot(); |
|
81 | - app(MigrationService::class)->updateSchema( |
|
82 | - self::SCHEMA_MIGRATION_PREFIX, |
|
83 | - self::SCHEMA_SETTING_NAME, |
|
84 | - self::SCHEMA_TARGET_VERSION |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * {@inheritDoc} |
|
90 | - * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes() |
|
91 | - */ |
|
92 | - public function loadRoutes(Map $router): void |
|
93 | - { |
|
94 | - $router->attach('', '', static function (Map $router): void { |
|
95 | - |
|
96 | - $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
97 | - |
|
98 | - $router->attach('', '/admin', static function (Map $router): void { |
|
99 | - |
|
100 | - $router->extras([ |
|
101 | - 'middleware' => [ |
|
102 | - AuthAdministrator::class, |
|
103 | - ], |
|
104 | - ]); |
|
105 | - $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
106 | - |
|
107 | - $router->attach('', '/tasks', static function (Map $router): void { |
|
108 | - |
|
109 | - $router->get(TasksList::class, '', TasksList::class); |
|
110 | - $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
111 | - $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
112 | - $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
113 | - }); |
|
114 | - }); |
|
115 | - |
|
116 | - $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
117 | - ->allows(RequestMethodInterface::METHOD_POST); |
|
118 | - |
|
119 | - $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
120 | - ->extras(['middleware' => [AuthAdministrator::class]]); |
|
121 | - }); |
|
122 | - }); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * {@inheritDoc} |
|
127 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
128 | - */ |
|
129 | - public function customModuleVersion(): string |
|
130 | - { |
|
131 | - return '2.0.5-v.1'; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * {@inheritDoc} |
|
136 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
137 | - */ |
|
138 | - public function getConfigLink(): string |
|
139 | - { |
|
140 | - return route(AdminConfigPage::class); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * {@inheritDoc} |
|
145 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
146 | - */ |
|
147 | - public function bodyContent(): string |
|
148 | - { |
|
149 | - return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * {@inheritDoc} |
|
154 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Contracts\ModuleTasksProviderInterface::listTasks() |
|
155 | - */ |
|
156 | - public function listTasks(): array |
|
157 | - { |
|
158 | - return [ |
|
159 | - 'maj-healthcheck' => HealthCheckEmailTask::class |
|
160 | - ]; |
|
161 | - } |
|
48 | + use ModuleConfigTrait; |
|
49 | + use ModuleGlobalTrait; |
|
50 | + |
|
51 | + //How to update the database schema for this module |
|
52 | + private const SCHEMA_TARGET_VERSION = 2; |
|
53 | + private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
|
54 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
59 | + */ |
|
60 | + public function title(): string |
|
61 | + { |
|
62 | + return I18N::translate('Administration Tasks'); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * {@inheritDoc} |
|
67 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
68 | + */ |
|
69 | + public function description(): string |
|
70 | + { |
|
71 | + return I18N::translate('Manage and run nearly-scheduled administration tasks.'); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * {@inheritDoc} |
|
76 | + * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::boot() |
|
77 | + */ |
|
78 | + public function boot(): void |
|
79 | + { |
|
80 | + parent::boot(); |
|
81 | + app(MigrationService::class)->updateSchema( |
|
82 | + self::SCHEMA_MIGRATION_PREFIX, |
|
83 | + self::SCHEMA_SETTING_NAME, |
|
84 | + self::SCHEMA_TARGET_VERSION |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * {@inheritDoc} |
|
90 | + * @see \MyArtJaub\Webtrees\Module\AbstractModuleMaj::loadRoutes() |
|
91 | + */ |
|
92 | + public function loadRoutes(Map $router): void |
|
93 | + { |
|
94 | + $router->attach('', '', static function (Map $router): void { |
|
95 | + |
|
96 | + $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
97 | + |
|
98 | + $router->attach('', '/admin', static function (Map $router): void { |
|
99 | + |
|
100 | + $router->extras([ |
|
101 | + 'middleware' => [ |
|
102 | + AuthAdministrator::class, |
|
103 | + ], |
|
104 | + ]); |
|
105 | + $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
106 | + |
|
107 | + $router->attach('', '/tasks', static function (Map $router): void { |
|
108 | + |
|
109 | + $router->get(TasksList::class, '', TasksList::class); |
|
110 | + $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
111 | + $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
112 | + $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
113 | + }); |
|
114 | + }); |
|
115 | + |
|
116 | + $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
117 | + ->allows(RequestMethodInterface::METHOD_POST); |
|
118 | + |
|
119 | + $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
120 | + ->extras(['middleware' => [AuthAdministrator::class]]); |
|
121 | + }); |
|
122 | + }); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * {@inheritDoc} |
|
127 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
128 | + */ |
|
129 | + public function customModuleVersion(): string |
|
130 | + { |
|
131 | + return '2.0.5-v.1'; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * {@inheritDoc} |
|
136 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
137 | + */ |
|
138 | + public function getConfigLink(): string |
|
139 | + { |
|
140 | + return route(AdminConfigPage::class); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * {@inheritDoc} |
|
145 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
146 | + */ |
|
147 | + public function bodyContent(): string |
|
148 | + { |
|
149 | + return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * {@inheritDoc} |
|
154 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Contracts\ModuleTasksProviderInterface::listTasks() |
|
155 | + */ |
|
156 | + public function listTasks(): array |
|
157 | + { |
|
158 | + return [ |
|
159 | + 'maj-healthcheck' => HealthCheckEmailTask::class |
|
160 | + ]; |
|
161 | + } |
|
162 | 162 | } |