@@ -28,210 +28,210 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class LineageBuilder |
| 30 | 30 | { |
| 31 | - private string $surname; |
|
| 32 | - private Tree $tree; |
|
| 33 | - private ?IndividualListModule $indilist_module; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var Collection<string, bool> $used_indis Individuals already processed |
|
| 37 | - */ |
|
| 38 | - private Collection $used_indis; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Constructor for Lineage Builder |
|
| 42 | - * |
|
| 43 | - * @param string $surname Reference surname |
|
| 44 | - * @param Tree $tree Gedcom tree |
|
| 45 | - */ |
|
| 46 | - public function __construct($surname, Tree $tree, IndividualListModule $indilist_module) |
|
| 47 | - { |
|
| 48 | - $this->surname = $surname; |
|
| 49 | - $this->tree = $tree; |
|
| 50 | - $this->indilist_module = $indilist_module; |
|
| 51 | - $this->used_indis = new Collection(); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Build all patronymic lineages for the reference surname. |
|
| 56 | - * |
|
| 57 | - * @return Collection<LineageRootNode>|NULL List of root patronymic lineages |
|
| 58 | - */ |
|
| 59 | - public function buildLineages(): ?Collection |
|
| 60 | - { |
|
| 61 | - if ($this->indilist_module === null) { |
|
| 62 | - return null; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale()); |
|
| 66 | - //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality |
|
| 67 | - if (count($indis) == 0) { |
|
| 68 | - return null; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $root_lineages = new Collection(); |
|
| 72 | - |
|
| 73 | - foreach ($indis as $indi) { |
|
| 74 | - /** @var Individual $indi */ |
|
| 75 | - if ($this->used_indis->get($indi->xref(), false) === false) { |
|
| 76 | - $indi_first = $this->getLineageRootIndividual($indi); |
|
| 77 | - if ($indi_first !== null) { |
|
| 78 | - // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
| 79 | - $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
| 80 | - } |
|
| 81 | - if ($indi_first === null) { |
|
| 82 | - continue; |
|
| 83 | - } |
|
| 84 | - $this->used_indis->put($indi_first->xref(), true); |
|
| 85 | - if ($indi_first->canShow()) { |
|
| 86 | - //Check if the root individual has brothers and sisters, without parents |
|
| 87 | - $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
| 88 | - if ($indi_first_child_family !== null) { |
|
| 89 | - $root_node = new LineageRootNode(null); |
|
| 90 | - $root_node->addFamily($indi_first_child_family); |
|
| 91 | - } else { |
|
| 92 | - $root_node = new LineageRootNode($indi_first); |
|
| 93 | - } |
|
| 94 | - $root_node = $this->buildLineage($root_node); |
|
| 95 | - $root_lineages->add($root_node); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
| 101 | - |
|
| 102 | - if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
| 103 | - return 0; |
|
| 104 | - } |
|
| 105 | - return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
| 106 | - }); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Retrieve the root individual, from any individual, by recursion. |
|
| 111 | - * The Root individual is the individual without a father, or without a mother holding the same name. |
|
| 112 | - * |
|
| 113 | - * @param Individual $indi |
|
| 114 | - * @return Individual|NULL Root individual |
|
| 115 | - */ |
|
| 116 | - private function getLineageRootIndividual(Individual $indi): ?Individual |
|
| 117 | - { |
|
| 118 | - $child_families = $indi->childFamilies(); |
|
| 119 | - if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
| 120 | - return null; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - foreach ($child_families as $child_family) { |
|
| 124 | - /** @var Family $child_family */ |
|
| 125 | - $child_family->husband(); |
|
| 126 | - if (($husb = $child_family->husband()) !== null) { |
|
| 127 | - if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
| 128 | - return $indi; |
|
| 129 | - } |
|
| 130 | - return $this->getLineageRootIndividual($husb); |
|
| 131 | - } elseif (($wife = $child_family->wife()) !== null) { |
|
| 132 | - if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
| 133 | - $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
| 134 | - $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
| 135 | - if ( |
|
| 136 | - $indi->canShowName() |
|
| 137 | - && $wife->canShowName() |
|
| 138 | - && I18N::comparator()($indi_surname, $wife_surname) == 0 |
|
| 139 | - ) { |
|
| 140 | - return $this->getLineageRootIndividual($wife); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - return $indi; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - return $indi; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Computes descendent Lineage from a node. |
|
| 151 | - * Uses recursion to build the lineage tree |
|
| 152 | - * |
|
| 153 | - * @param LineageNode $node |
|
| 154 | - * @return LineageNode Computed lineage |
|
| 155 | - */ |
|
| 156 | - private function buildLineage(LineageNode $node): LineageNode |
|
| 157 | - { |
|
| 158 | - $indi_surname = ''; |
|
| 159 | - |
|
| 160 | - $indi_node = $node->individual(); |
|
| 161 | - if ($indi_node !== null) { |
|
| 162 | - if ($node->families()->count() == 0) { |
|
| 163 | - foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
| 164 | - $node->addFamily($spouse_family); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
| 169 | - $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
| 170 | - |
|
| 171 | - //Tag the individual as used |
|
| 172 | - $this->used_indis->put($indi_node->xref(), true); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - foreach ($node->families() as $family_node) { |
|
| 176 | - /** @var Family $spouse_family */ |
|
| 177 | - $spouse_family = $family_node->family; |
|
| 178 | - $spouse_surname = ''; |
|
| 179 | - $spouse = null; |
|
| 180 | - if ( |
|
| 181 | - $indi_node !== null && |
|
| 182 | - ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
| 183 | - ) { |
|
| 184 | - $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $nb_children = $nb_natural = 0; |
|
| 188 | - |
|
| 189 | - foreach ($spouse_family->children() as $child) { |
|
| 190 | - if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
| 191 | - $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
| 192 | - |
|
| 193 | - $nb_children++; |
|
| 194 | - if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
| 195 | - //Print only lineages of children with the same surname as their mother |
|
| 196 | - //(supposing they are natural children) |
|
| 197 | - /** @psalm-suppress RedundantCondition */ |
|
| 198 | - if ( |
|
| 199 | - $spouse === null || |
|
| 200 | - ($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0) |
|
| 201 | - ) { |
|
| 202 | - if (I18N::comparator()($child_surname, $indi_surname) == 0) { |
|
| 203 | - $nb_natural++; |
|
| 204 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
| 205 | - $node_child = $this->buildLineage($node_child); |
|
| 206 | - $node->addChild($spouse_family, $node_child); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - } else { //If the root individual is the father |
|
| 210 | - $nb_natural++; |
|
| 211 | - //Print if the children does not bear the same name as his mother |
|
| 212 | - //(and different from his father) |
|
| 213 | - if ( |
|
| 214 | - mb_strlen($child_surname) == 0 || |
|
| 215 | - mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
| 216 | - I18N::comparator()($child_surname, $indi_surname) == 0 || |
|
| 217 | - I18N::comparator()($child_surname, $spouse_surname) != 0 |
|
| 218 | - ) { |
|
| 219 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
| 220 | - $node_child = $this->buildLineage($node_child); |
|
| 221 | - } else { |
|
| 222 | - $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
| 223 | - } |
|
| 224 | - $node->addChild($spouse_family, $node_child); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - //Do not print other children |
|
| 230 | - if (($nb_children - $nb_natural) > 0) { |
|
| 231 | - $node->addChild($spouse_family, null); |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $node; |
|
| 236 | - } |
|
| 31 | + private string $surname; |
|
| 32 | + private Tree $tree; |
|
| 33 | + private ?IndividualListModule $indilist_module; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var Collection<string, bool> $used_indis Individuals already processed |
|
| 37 | + */ |
|
| 38 | + private Collection $used_indis; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Constructor for Lineage Builder |
|
| 42 | + * |
|
| 43 | + * @param string $surname Reference surname |
|
| 44 | + * @param Tree $tree Gedcom tree |
|
| 45 | + */ |
|
| 46 | + public function __construct($surname, Tree $tree, IndividualListModule $indilist_module) |
|
| 47 | + { |
|
| 48 | + $this->surname = $surname; |
|
| 49 | + $this->tree = $tree; |
|
| 50 | + $this->indilist_module = $indilist_module; |
|
| 51 | + $this->used_indis = new Collection(); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Build all patronymic lineages for the reference surname. |
|
| 56 | + * |
|
| 57 | + * @return Collection<LineageRootNode>|NULL List of root patronymic lineages |
|
| 58 | + */ |
|
| 59 | + public function buildLineages(): ?Collection |
|
| 60 | + { |
|
| 61 | + if ($this->indilist_module === null) { |
|
| 62 | + return null; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale()); |
|
| 66 | + //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality |
|
| 67 | + if (count($indis) == 0) { |
|
| 68 | + return null; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $root_lineages = new Collection(); |
|
| 72 | + |
|
| 73 | + foreach ($indis as $indi) { |
|
| 74 | + /** @var Individual $indi */ |
|
| 75 | + if ($this->used_indis->get($indi->xref(), false) === false) { |
|
| 76 | + $indi_first = $this->getLineageRootIndividual($indi); |
|
| 77 | + if ($indi_first !== null) { |
|
| 78 | + // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
| 79 | + $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
| 80 | + } |
|
| 81 | + if ($indi_first === null) { |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 84 | + $this->used_indis->put($indi_first->xref(), true); |
|
| 85 | + if ($indi_first->canShow()) { |
|
| 86 | + //Check if the root individual has brothers and sisters, without parents |
|
| 87 | + $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
| 88 | + if ($indi_first_child_family !== null) { |
|
| 89 | + $root_node = new LineageRootNode(null); |
|
| 90 | + $root_node->addFamily($indi_first_child_family); |
|
| 91 | + } else { |
|
| 92 | + $root_node = new LineageRootNode($indi_first); |
|
| 93 | + } |
|
| 94 | + $root_node = $this->buildLineage($root_node); |
|
| 95 | + $root_lineages->add($root_node); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
| 101 | + |
|
| 102 | + if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
| 103 | + return 0; |
|
| 104 | + } |
|
| 105 | + return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
| 106 | + }); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Retrieve the root individual, from any individual, by recursion. |
|
| 111 | + * The Root individual is the individual without a father, or without a mother holding the same name. |
|
| 112 | + * |
|
| 113 | + * @param Individual $indi |
|
| 114 | + * @return Individual|NULL Root individual |
|
| 115 | + */ |
|
| 116 | + private function getLineageRootIndividual(Individual $indi): ?Individual |
|
| 117 | + { |
|
| 118 | + $child_families = $indi->childFamilies(); |
|
| 119 | + if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
| 120 | + return null; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + foreach ($child_families as $child_family) { |
|
| 124 | + /** @var Family $child_family */ |
|
| 125 | + $child_family->husband(); |
|
| 126 | + if (($husb = $child_family->husband()) !== null) { |
|
| 127 | + if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
| 128 | + return $indi; |
|
| 129 | + } |
|
| 130 | + return $this->getLineageRootIndividual($husb); |
|
| 131 | + } elseif (($wife = $child_family->wife()) !== null) { |
|
| 132 | + if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
| 133 | + $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
| 134 | + $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
| 135 | + if ( |
|
| 136 | + $indi->canShowName() |
|
| 137 | + && $wife->canShowName() |
|
| 138 | + && I18N::comparator()($indi_surname, $wife_surname) == 0 |
|
| 139 | + ) { |
|
| 140 | + return $this->getLineageRootIndividual($wife); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + return $indi; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + return $indi; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Computes descendent Lineage from a node. |
|
| 151 | + * Uses recursion to build the lineage tree |
|
| 152 | + * |
|
| 153 | + * @param LineageNode $node |
|
| 154 | + * @return LineageNode Computed lineage |
|
| 155 | + */ |
|
| 156 | + private function buildLineage(LineageNode $node): LineageNode |
|
| 157 | + { |
|
| 158 | + $indi_surname = ''; |
|
| 159 | + |
|
| 160 | + $indi_node = $node->individual(); |
|
| 161 | + if ($indi_node !== null) { |
|
| 162 | + if ($node->families()->count() == 0) { |
|
| 163 | + foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
| 164 | + $node->addFamily($spouse_family); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
| 169 | + $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
| 170 | + |
|
| 171 | + //Tag the individual as used |
|
| 172 | + $this->used_indis->put($indi_node->xref(), true); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + foreach ($node->families() as $family_node) { |
|
| 176 | + /** @var Family $spouse_family */ |
|
| 177 | + $spouse_family = $family_node->family; |
|
| 178 | + $spouse_surname = ''; |
|
| 179 | + $spouse = null; |
|
| 180 | + if ( |
|
| 181 | + $indi_node !== null && |
|
| 182 | + ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
| 183 | + ) { |
|
| 184 | + $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $nb_children = $nb_natural = 0; |
|
| 188 | + |
|
| 189 | + foreach ($spouse_family->children() as $child) { |
|
| 190 | + if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
| 191 | + $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
| 192 | + |
|
| 193 | + $nb_children++; |
|
| 194 | + if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
| 195 | + //Print only lineages of children with the same surname as their mother |
|
| 196 | + //(supposing they are natural children) |
|
| 197 | + /** @psalm-suppress RedundantCondition */ |
|
| 198 | + if ( |
|
| 199 | + $spouse === null || |
|
| 200 | + ($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0) |
|
| 201 | + ) { |
|
| 202 | + if (I18N::comparator()($child_surname, $indi_surname) == 0) { |
|
| 203 | + $nb_natural++; |
|
| 204 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
| 205 | + $node_child = $this->buildLineage($node_child); |
|
| 206 | + $node->addChild($spouse_family, $node_child); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + } else { //If the root individual is the father |
|
| 210 | + $nb_natural++; |
|
| 211 | + //Print if the children does not bear the same name as his mother |
|
| 212 | + //(and different from his father) |
|
| 213 | + if ( |
|
| 214 | + mb_strlen($child_surname) == 0 || |
|
| 215 | + mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
| 216 | + I18N::comparator()($child_surname, $indi_surname) == 0 || |
|
| 217 | + I18N::comparator()($child_surname, $spouse_surname) != 0 |
|
| 218 | + ) { |
|
| 219 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
| 220 | + $node_child = $this->buildLineage($node_child); |
|
| 221 | + } else { |
|
| 222 | + $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
| 223 | + } |
|
| 224 | + $node->addChild($spouse_family, $node_child); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + //Do not print other children |
|
| 230 | + if (($nb_children - $nb_natural) > 0) { |
|
| 231 | + $node->addChild($spouse_family, null); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $node; |
|
| 236 | + } |
|
| 237 | 237 | } |
@@ -1,14 +1,14 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
| 5 | - * |
|
| 6 | - * @package MyArtJaub\Webtrees |
|
| 7 | - * @subpackage Hooks |
|
| 8 | - * @author Jonathan Jaubart <[email protected]> |
|
| 9 | - * @copyright Copyright (c) 2011-2021, Jonathan Jaubart |
|
| 10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
| 11 | - */ |
|
| 4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
| 5 | + * |
|
| 6 | + * @package MyArtJaub\Webtrees |
|
| 7 | + * @subpackage Hooks |
|
| 8 | + * @author Jonathan Jaubart <[email protected]> |
|
| 9 | + * @copyright Copyright (c) 2011-2021, Jonathan Jaubart |
|
| 10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
| 11 | + */ |
|
| 12 | 12 | |
| 13 | 13 | declare(strict_types=1); |
| 14 | 14 | |
@@ -21,31 +21,31 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | interface CustomSimpleTagEditorInterface extends HookInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Add the tag in the hierarchy of the expected tags |
|
| 26 | - * |
|
| 27 | - * @param array<string, mixed> $expected_tags |
|
| 28 | - * @return array<string, mixed> |
|
| 29 | - */ |
|
| 30 | - public function addExpectedTags(array $expected_tags): array; |
|
| 24 | + /** |
|
| 25 | + * Add the tag in the hierarchy of the expected tags |
|
| 26 | + * |
|
| 27 | + * @param array<string, mixed> $expected_tags |
|
| 28 | + * @return array<string, mixed> |
|
| 29 | + */ |
|
| 30 | + public function addExpectedTags(array $expected_tags): array; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Try to get a label for a tag |
|
| 34 | - * |
|
| 35 | - * @param string $tag |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function getLabel(string $tag): string; |
|
| 32 | + /** |
|
| 33 | + * Try to get a label for a tag |
|
| 34 | + * |
|
| 35 | + * @param string $tag |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function getLabel(string $tag): string; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Returns HTML code for editing the custom tag. |
|
| 42 | - * |
|
| 43 | - * @param string $tag |
|
| 44 | - * @param string $id |
|
| 45 | - * @param string $name |
|
| 46 | - * @param string $value |
|
| 47 | - * @param Tree $tree |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function editForm(string $tag, string $id, string $name, string $value, Tree $tree): string; |
|
| 40 | + /** |
|
| 41 | + * Returns HTML code for editing the custom tag. |
|
| 42 | + * |
|
| 43 | + * @param string $tag |
|
| 44 | + * @param string $id |
|
| 45 | + * @param string $name |
|
| 46 | + * @param string $value |
|
| 47 | + * @param Tree $tree |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function editForm(string $tag, string $id, string $name, string $value, Tree $tree): string; |
|
| 51 | 51 | } |
@@ -23,104 +23,104 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class GeoAnalysisResults |
| 25 | 25 | { |
| 26 | - private GeoAnalysisResult $global; |
|
| 26 | + private GeoAnalysisResult $global; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var Collection<string, GeoAnalysisResult> $detailed |
|
| 30 | - */ |
|
| 31 | - private Collection $detailed; |
|
| 28 | + /** |
|
| 29 | + * @var Collection<string, GeoAnalysisResult> $detailed |
|
| 30 | + */ |
|
| 31 | + private Collection $detailed; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor for GeoAnalysisResults |
|
| 35 | - */ |
|
| 36 | - public function __construct() |
|
| 37 | - { |
|
| 38 | - $this->global = new GeoAnalysisResult('Global', 0); |
|
| 39 | - $this->detailed = new Collection(); |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor for GeoAnalysisResults |
|
| 35 | + */ |
|
| 36 | + public function __construct() |
|
| 37 | + { |
|
| 38 | + $this->global = new GeoAnalysisResult('Global', 0); |
|
| 39 | + $this->detailed = new Collection(); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Global result of the geographical analysis |
|
| 44 | - * |
|
| 45 | - * @return GeoAnalysisResult |
|
| 46 | - */ |
|
| 47 | - public function global(): GeoAnalysisResult |
|
| 48 | - { |
|
| 49 | - return $this->global; |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * Global result of the geographical analysis |
|
| 44 | + * |
|
| 45 | + * @return GeoAnalysisResult |
|
| 46 | + */ |
|
| 47 | + public function global(): GeoAnalysisResult |
|
| 48 | + { |
|
| 49 | + return $this->global; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * List of results by category of the geographical analysis |
|
| 54 | - * |
|
| 55 | - * @return Collection<string, GeoAnalysisResult> |
|
| 56 | - */ |
|
| 57 | - public function detailed(): Collection |
|
| 58 | - { |
|
| 59 | - return $this->detailed; |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * List of results by category of the geographical analysis |
|
| 54 | + * |
|
| 55 | + * @return Collection<string, GeoAnalysisResult> |
|
| 56 | + */ |
|
| 57 | + public function detailed(): Collection |
|
| 58 | + { |
|
| 59 | + return $this->detailed; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * List of results by category of the geographical analysis. |
|
| 64 | - * The list is sorted first by the category order, then by the category description |
|
| 65 | - * |
|
| 66 | - * @return Collection<string, GeoAnalysisResult> |
|
| 67 | - */ |
|
| 68 | - public function sortedDetailed(): Collection |
|
| 69 | - { |
|
| 70 | - return $this->detailed->sortBy([ |
|
| 71 | - fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => $a->order() <=> $b->order(), |
|
| 72 | - fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => |
|
| 73 | - I18N::comparator()($a->description(), $b->description()) |
|
| 74 | - ]); |
|
| 75 | - } |
|
| 62 | + /** |
|
| 63 | + * List of results by category of the geographical analysis. |
|
| 64 | + * The list is sorted first by the category order, then by the category description |
|
| 65 | + * |
|
| 66 | + * @return Collection<string, GeoAnalysisResult> |
|
| 67 | + */ |
|
| 68 | + public function sortedDetailed(): Collection |
|
| 69 | + { |
|
| 70 | + return $this->detailed->sortBy([ |
|
| 71 | + fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => $a->order() <=> $b->order(), |
|
| 72 | + fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => |
|
| 73 | + I18N::comparator()($a->description(), $b->description()) |
|
| 74 | + ]); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Add a GeoAnalysis Place to the global result |
|
| 79 | - * |
|
| 80 | - * @param GeoAnalysisPlace $place |
|
| 81 | - */ |
|
| 82 | - public function addPlace(GeoAnalysisPlace $place): void |
|
| 83 | - { |
|
| 84 | - $this->global()->addPlace($place); |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * Add a GeoAnalysis Place to the global result |
|
| 79 | + * |
|
| 80 | + * @param GeoAnalysisPlace $place |
|
| 81 | + */ |
|
| 82 | + public function addPlace(GeoAnalysisPlace $place): void |
|
| 83 | + { |
|
| 84 | + $this->global()->addPlace($place); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Add a new category to the list of results, if it does not exist yet |
|
| 89 | - * |
|
| 90 | - * @param string $description |
|
| 91 | - * @param int $order |
|
| 92 | - */ |
|
| 93 | - public function addCategory(string $description, int $order): void |
|
| 94 | - { |
|
| 95 | - if (!$this->detailed->has($description)) { |
|
| 96 | - $this->detailed->put($description, new GeoAnalysisResult($description, $order)); |
|
| 97 | - } |
|
| 98 | - } |
|
| 87 | + /** |
|
| 88 | + * Add a new category to the list of results, if it does not exist yet |
|
| 89 | + * |
|
| 90 | + * @param string $description |
|
| 91 | + * @param int $order |
|
| 92 | + */ |
|
| 93 | + public function addCategory(string $description, int $order): void |
|
| 94 | + { |
|
| 95 | + if (!$this->detailed->has($description)) { |
|
| 96 | + $this->detailed->put($description, new GeoAnalysisResult($description, $order)); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Add a GeoAnalysis Place to a category result, if the category exist. |
|
| 102 | - * |
|
| 103 | - * @param string $category_name |
|
| 104 | - * @param GeoAnalysisPlace $place |
|
| 105 | - */ |
|
| 106 | - public function addPlaceInCreatedCategory(string $category_name, GeoAnalysisPlace $place): void |
|
| 107 | - { |
|
| 108 | - if ($this->detailed->has($category_name)) { |
|
| 109 | - $this->detailed->get($category_name)->addPlace($place); |
|
| 110 | - } |
|
| 111 | - } |
|
| 100 | + /** |
|
| 101 | + * Add a GeoAnalysis Place to a category result, if the category exist. |
|
| 102 | + * |
|
| 103 | + * @param string $category_name |
|
| 104 | + * @param GeoAnalysisPlace $place |
|
| 105 | + */ |
|
| 106 | + public function addPlaceInCreatedCategory(string $category_name, GeoAnalysisPlace $place): void |
|
| 107 | + { |
|
| 108 | + if ($this->detailed->has($category_name)) { |
|
| 109 | + $this->detailed->get($category_name)->addPlace($place); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Add a GeoAnalysis Place to a category result, after creating the category if it does not exist. |
|
| 115 | - * |
|
| 116 | - * @param string $category_name |
|
| 117 | - * @param GeoAnalysisPlace $place |
|
| 118 | - */ |
|
| 119 | - public function addPlaceInCategory(string $category_name, int $category_order, GeoAnalysisPlace $place): void |
|
| 120 | - { |
|
| 121 | - if (!$this->detailed->has($category_name)) { |
|
| 122 | - $this->addCategory($category_name, $category_order); |
|
| 123 | - } |
|
| 124 | - $this->addPlaceInCreatedCategory($category_name, $place); |
|
| 125 | - } |
|
| 113 | + /** |
|
| 114 | + * Add a GeoAnalysis Place to a category result, after creating the category if it does not exist. |
|
| 115 | + * |
|
| 116 | + * @param string $category_name |
|
| 117 | + * @param GeoAnalysisPlace $place |
|
| 118 | + */ |
|
| 119 | + public function addPlaceInCategory(string $category_name, int $category_order, GeoAnalysisPlace $place): void |
|
| 120 | + { |
|
| 121 | + if (!$this->detailed->has($category_name)) { |
|
| 122 | + $this->addCategory($category_name, $category_order); |
|
| 123 | + } |
|
| 124 | + $this->addPlaceInCreatedCategory($category_name, $place); |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -25,105 +25,105 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class GenericPlaceMapperConfig implements PlaceMapperConfigInterface |
| 27 | 27 | { |
| 28 | - /** @var array<string, mixed> $config */ |
|
| 29 | - private array $config = []; |
|
| 28 | + /** @var array<string, mixed> $config */ |
|
| 29 | + private array $config = []; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Get the generic mapper's config |
|
| 33 | - * |
|
| 34 | - * @return array<string, mixed> |
|
| 35 | - */ |
|
| 36 | - public function config(): array |
|
| 37 | - { |
|
| 38 | - return $this->config; |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * Get the generic mapper's config |
|
| 33 | + * |
|
| 34 | + * @return array<string, mixed> |
|
| 35 | + */ |
|
| 36 | + public function config(): array |
|
| 37 | + { |
|
| 38 | + return $this->config; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Set the generic mapper's config |
|
| 43 | - * |
|
| 44 | - * @param array<string, mixed> $config |
|
| 45 | - * @return $this |
|
| 46 | - */ |
|
| 47 | - public function setConfig(array $config): self |
|
| 48 | - { |
|
| 49 | - $this->config = $config; |
|
| 50 | - return $this; |
|
| 51 | - } |
|
| 41 | + /** |
|
| 42 | + * Set the generic mapper's config |
|
| 43 | + * |
|
| 44 | + * @param array<string, mixed> $config |
|
| 45 | + * @return $this |
|
| 46 | + */ |
|
| 47 | + public function setConfig(array $config): self |
|
| 48 | + { |
|
| 49 | + $this->config = $config; |
|
| 50 | + return $this; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritDoc} |
|
| 55 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 56 | - */ |
|
| 57 | - public function get(string $key, $default = null) |
|
| 58 | - { |
|
| 59 | - return $this->config[$key] ?? $default; |
|
| 60 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritDoc} |
|
| 55 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 56 | + */ |
|
| 57 | + public function get(string $key, $default = null) |
|
| 58 | + { |
|
| 59 | + return $this->config[$key] ?? $default; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * {@inheritDoc} |
|
| 64 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 65 | - */ |
|
| 66 | - public function has(string $key): bool |
|
| 67 | - { |
|
| 68 | - return key_exists($key, $this->config); |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * {@inheritDoc} |
|
| 64 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 65 | + */ |
|
| 66 | + public function has(string $key): bool |
|
| 67 | + { |
|
| 68 | + return key_exists($key, $this->config); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * {@inheritDoc} |
|
| 73 | - * @see \JsonSerializable::jsonSerialize() |
|
| 74 | - */ |
|
| 75 | - public function jsonSerialize() |
|
| 76 | - { |
|
| 77 | - return [ |
|
| 78 | - 'class' => get_class($this), |
|
| 79 | - 'config' => $this->jsonSerializeConfig() |
|
| 80 | - ]; |
|
| 81 | - } |
|
| 71 | + /** |
|
| 72 | + * {@inheritDoc} |
|
| 73 | + * @see \JsonSerializable::jsonSerialize() |
|
| 74 | + */ |
|
| 75 | + public function jsonSerialize() |
|
| 76 | + { |
|
| 77 | + return [ |
|
| 78 | + 'class' => get_class($this), |
|
| 79 | + 'config' => $this->jsonSerializeConfig() |
|
| 80 | + ]; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Returns a representation of the mapper config compatible with Json serialisation |
|
| 85 | - * |
|
| 86 | - * @return mixed |
|
| 87 | - */ |
|
| 88 | - public function jsonSerializeConfig() |
|
| 89 | - { |
|
| 90 | - return $this->config; |
|
| 91 | - } |
|
| 83 | + /** |
|
| 84 | + * Returns a representation of the mapper config compatible with Json serialisation |
|
| 85 | + * |
|
| 86 | + * @return mixed |
|
| 87 | + */ |
|
| 88 | + public function jsonSerializeConfig() |
|
| 89 | + { |
|
| 90 | + return $this->config; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * {@inheritDoc} |
|
| 95 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 96 | - * |
|
| 97 | - * @param mixed $config |
|
| 98 | - * @return $this |
|
| 99 | - */ |
|
| 100 | - public function jsonDeserialize($config): self |
|
| 101 | - { |
|
| 102 | - if (is_string($config)) { |
|
| 103 | - return $this->jsonDeserialize(json_decode($config)); |
|
| 104 | - } |
|
| 105 | - if (is_array($config)) { |
|
| 106 | - return $this->setConfig($config); |
|
| 107 | - } |
|
| 108 | - return $this; |
|
| 109 | - } |
|
| 93 | + /** |
|
| 94 | + * {@inheritDoc} |
|
| 95 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 96 | + * |
|
| 97 | + * @param mixed $config |
|
| 98 | + * @return $this |
|
| 99 | + */ |
|
| 100 | + public function jsonDeserialize($config): self |
|
| 101 | + { |
|
| 102 | + if (is_string($config)) { |
|
| 103 | + return $this->jsonDeserialize(json_decode($config)); |
|
| 104 | + } |
|
| 105 | + if (is_array($config)) { |
|
| 106 | + return $this->setConfig($config); |
|
| 107 | + } |
|
| 108 | + return $this; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * {@inheritDoc} |
|
| 113 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 114 | - */ |
|
| 115 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 116 | - { |
|
| 117 | - return ''; |
|
| 118 | - } |
|
| 111 | + /** |
|
| 112 | + * {@inheritDoc} |
|
| 113 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 114 | + */ |
|
| 115 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 116 | + { |
|
| 117 | + return ''; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * {@inheritDoc} |
|
| 122 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 123 | - * @return $this |
|
| 124 | - */ |
|
| 125 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 126 | - { |
|
| 127 | - return $this; |
|
| 128 | - } |
|
| 120 | + /** |
|
| 121 | + * {@inheritDoc} |
|
| 122 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 123 | + * @return $this |
|
| 124 | + */ |
|
| 125 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 126 | + { |
|
| 127 | + return $this; |
|
| 128 | + } |
|
| 129 | 129 | } |
@@ -24,252 +24,252 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class TaskSchedule |
| 26 | 26 | { |
| 27 | - private int $id; |
|
| 28 | - private bool $enabled; |
|
| 29 | - private string $task_id; |
|
| 30 | - private Carbon $last_run; |
|
| 31 | - private bool $last_result; |
|
| 32 | - private CarbonInterval $frequency; |
|
| 33 | - private int $nb_occurrences; |
|
| 34 | - private bool $is_running; |
|
| 27 | + private int $id; |
|
| 28 | + private bool $enabled; |
|
| 29 | + private string $task_id; |
|
| 30 | + private Carbon $last_run; |
|
| 31 | + private bool $last_result; |
|
| 32 | + private CarbonInterval $frequency; |
|
| 33 | + private int $nb_occurrences; |
|
| 34 | + private bool $is_running; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for TaskSchedule |
|
| 38 | - * |
|
| 39 | - * @param int $id Schedule ID |
|
| 40 | - * @param string $task_id Task ID |
|
| 41 | - * @param bool $enabled Is the schedule enabled |
|
| 42 | - * @param Carbon $last_run Last successful run date/time |
|
| 43 | - * @param bool $last_result Result of the last run |
|
| 44 | - * @param CarbonInterval $frequency Schedule frequency |
|
| 45 | - * @param int $nb_occurrences Number of remaining occurrences to be run |
|
| 46 | - * @param bool $is_running Is the task currently running |
|
| 47 | - */ |
|
| 48 | - public function __construct( |
|
| 49 | - int $id, |
|
| 50 | - string $task_id, |
|
| 51 | - bool $enabled, |
|
| 52 | - Carbon $last_run, |
|
| 53 | - bool $last_result, |
|
| 54 | - CarbonInterval $frequency, |
|
| 55 | - int $nb_occurrences, |
|
| 56 | - bool $is_running |
|
| 57 | - ) { |
|
| 58 | - $this->id = $id; |
|
| 59 | - $this->task_id = $task_id; |
|
| 60 | - $this->enabled = $enabled; |
|
| 61 | - $this->last_run = $last_run; |
|
| 62 | - $this->last_result = $last_result; |
|
| 63 | - $this->frequency = $frequency; |
|
| 64 | - $this->nb_occurrences = $nb_occurrences; |
|
| 65 | - $this->is_running = $is_running; |
|
| 66 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for TaskSchedule |
|
| 38 | + * |
|
| 39 | + * @param int $id Schedule ID |
|
| 40 | + * @param string $task_id Task ID |
|
| 41 | + * @param bool $enabled Is the schedule enabled |
|
| 42 | + * @param Carbon $last_run Last successful run date/time |
|
| 43 | + * @param bool $last_result Result of the last run |
|
| 44 | + * @param CarbonInterval $frequency Schedule frequency |
|
| 45 | + * @param int $nb_occurrences Number of remaining occurrences to be run |
|
| 46 | + * @param bool $is_running Is the task currently running |
|
| 47 | + */ |
|
| 48 | + public function __construct( |
|
| 49 | + int $id, |
|
| 50 | + string $task_id, |
|
| 51 | + bool $enabled, |
|
| 52 | + Carbon $last_run, |
|
| 53 | + bool $last_result, |
|
| 54 | + CarbonInterval $frequency, |
|
| 55 | + int $nb_occurrences, |
|
| 56 | + bool $is_running |
|
| 57 | + ) { |
|
| 58 | + $this->id = $id; |
|
| 59 | + $this->task_id = $task_id; |
|
| 60 | + $this->enabled = $enabled; |
|
| 61 | + $this->last_run = $last_run; |
|
| 62 | + $this->last_result = $last_result; |
|
| 63 | + $this->frequency = $frequency; |
|
| 64 | + $this->nb_occurrences = $nb_occurrences; |
|
| 65 | + $this->is_running = $is_running; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Get the schedule ID. |
|
| 70 | - * |
|
| 71 | - * @return int |
|
| 72 | - */ |
|
| 73 | - public function id(): int |
|
| 74 | - { |
|
| 75 | - return $this->id; |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Get the schedule ID. |
|
| 70 | + * |
|
| 71 | + * @return int |
|
| 72 | + */ |
|
| 73 | + public function id(): int |
|
| 74 | + { |
|
| 75 | + return $this->id; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Get the task ID. |
|
| 80 | - * |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function taskId(): string |
|
| 84 | - { |
|
| 85 | - return $this->task_id; |
|
| 86 | - } |
|
| 78 | + /** |
|
| 79 | + * Get the task ID. |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function taskId(): string |
|
| 84 | + { |
|
| 85 | + return $this->task_id; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Returns whether the schedule is enabled |
|
| 90 | - * |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - public function isEnabled(): bool |
|
| 94 | - { |
|
| 95 | - return $this->enabled; |
|
| 96 | - } |
|
| 88 | + /** |
|
| 89 | + * Returns whether the schedule is enabled |
|
| 90 | + * |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + public function isEnabled(): bool |
|
| 94 | + { |
|
| 95 | + return $this->enabled; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Enable the schedule |
|
| 100 | - * |
|
| 101 | - * @return $this |
|
| 102 | - */ |
|
| 103 | - public function enable(): self |
|
| 104 | - { |
|
| 105 | - $this->enabled = true; |
|
| 106 | - return $this; |
|
| 107 | - } |
|
| 98 | + /** |
|
| 99 | + * Enable the schedule |
|
| 100 | + * |
|
| 101 | + * @return $this |
|
| 102 | + */ |
|
| 103 | + public function enable(): self |
|
| 104 | + { |
|
| 105 | + $this->enabled = true; |
|
| 106 | + return $this; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Disable the schedule |
|
| 111 | - * |
|
| 112 | - * @return $this |
|
| 113 | - */ |
|
| 114 | - public function disable(): self |
|
| 115 | - { |
|
| 116 | - $this->enabled = false; |
|
| 117 | - return $this; |
|
| 118 | - } |
|
| 109 | + /** |
|
| 110 | + * Disable the schedule |
|
| 111 | + * |
|
| 112 | + * @return $this |
|
| 113 | + */ |
|
| 114 | + public function disable(): self |
|
| 115 | + { |
|
| 116 | + $this->enabled = false; |
|
| 117 | + return $this; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Get the frequency of the schedule |
|
| 122 | - * |
|
| 123 | - * @return CarbonInterval |
|
| 124 | - */ |
|
| 125 | - public function frequency(): CarbonInterval |
|
| 126 | - { |
|
| 127 | - return $this->frequency; |
|
| 128 | - } |
|
| 120 | + /** |
|
| 121 | + * Get the frequency of the schedule |
|
| 122 | + * |
|
| 123 | + * @return CarbonInterval |
|
| 124 | + */ |
|
| 125 | + public function frequency(): CarbonInterval |
|
| 126 | + { |
|
| 127 | + return $this->frequency; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Set the frequency of the schedule |
|
| 132 | - * |
|
| 133 | - * @param CarbonInterval $frequency |
|
| 134 | - * @return $this |
|
| 135 | - */ |
|
| 136 | - public function setFrequency(CarbonInterval $frequency): self |
|
| 137 | - { |
|
| 138 | - $this->frequency = $frequency; |
|
| 139 | - return $this; |
|
| 140 | - } |
|
| 130 | + /** |
|
| 131 | + * Set the frequency of the schedule |
|
| 132 | + * |
|
| 133 | + * @param CarbonInterval $frequency |
|
| 134 | + * @return $this |
|
| 135 | + */ |
|
| 136 | + public function setFrequency(CarbonInterval $frequency): self |
|
| 137 | + { |
|
| 138 | + $this->frequency = $frequency; |
|
| 139 | + return $this; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Get the date/time of the last successful run. |
|
| 144 | - * |
|
| 145 | - * @return Carbon |
|
| 146 | - */ |
|
| 147 | - public function lastRunTime(): Carbon |
|
| 148 | - { |
|
| 149 | - return $this->last_run; |
|
| 150 | - } |
|
| 142 | + /** |
|
| 143 | + * Get the date/time of the last successful run. |
|
| 144 | + * |
|
| 145 | + * @return Carbon |
|
| 146 | + */ |
|
| 147 | + public function lastRunTime(): Carbon |
|
| 148 | + { |
|
| 149 | + return $this->last_run; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Set the last successful run date/time |
|
| 154 | - * |
|
| 155 | - * @param Carbon $last_run |
|
| 156 | - * @return $this |
|
| 157 | - */ |
|
| 158 | - public function setLastRunTime(Carbon $last_run): self |
|
| 159 | - { |
|
| 160 | - $this->last_run = $last_run; |
|
| 161 | - return $this; |
|
| 162 | - } |
|
| 152 | + /** |
|
| 153 | + * Set the last successful run date/time |
|
| 154 | + * |
|
| 155 | + * @param Carbon $last_run |
|
| 156 | + * @return $this |
|
| 157 | + */ |
|
| 158 | + public function setLastRunTime(Carbon $last_run): self |
|
| 159 | + { |
|
| 160 | + $this->last_run = $last_run; |
|
| 161 | + return $this; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Returns whether the last run was successful |
|
| 166 | - * |
|
| 167 | - * @return bool |
|
| 168 | - */ |
|
| 169 | - public function wasLastRunSuccess(): bool |
|
| 170 | - { |
|
| 171 | - return $this->last_result; |
|
| 172 | - } |
|
| 164 | + /** |
|
| 165 | + * Returns whether the last run was successful |
|
| 166 | + * |
|
| 167 | + * @return bool |
|
| 168 | + */ |
|
| 169 | + public function wasLastRunSuccess(): bool |
|
| 170 | + { |
|
| 171 | + return $this->last_result; |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * Set the last run result |
|
| 176 | - * |
|
| 177 | - * @param bool $last_result |
|
| 178 | - * @return $this |
|
| 179 | - */ |
|
| 180 | - public function setLastResult(bool $last_result): self |
|
| 181 | - { |
|
| 182 | - $this->last_result = $last_result; |
|
| 183 | - return $this; |
|
| 184 | - } |
|
| 174 | + /** |
|
| 175 | + * Set the last run result |
|
| 176 | + * |
|
| 177 | + * @param bool $last_result |
|
| 178 | + * @return $this |
|
| 179 | + */ |
|
| 180 | + public function setLastResult(bool $last_result): self |
|
| 181 | + { |
|
| 182 | + $this->last_result = $last_result; |
|
| 183 | + return $this; |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Get the number of remaining of occurrences of task runs. |
|
| 188 | - * Returns 0 if the tasks must be run indefinitely. |
|
| 189 | - * |
|
| 190 | - * @return int |
|
| 191 | - */ |
|
| 192 | - public function remainingOccurences(): int |
|
| 193 | - { |
|
| 194 | - return $this->nb_occurrences; |
|
| 195 | - } |
|
| 186 | + /** |
|
| 187 | + * Get the number of remaining of occurrences of task runs. |
|
| 188 | + * Returns 0 if the tasks must be run indefinitely. |
|
| 189 | + * |
|
| 190 | + * @return int |
|
| 191 | + */ |
|
| 192 | + public function remainingOccurences(): int |
|
| 193 | + { |
|
| 194 | + return $this->nb_occurrences; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Decrements the number of remaining occurences by 1. |
|
| 199 | - * The task will be disabled when the number reaches 0. |
|
| 200 | - * |
|
| 201 | - * @return $this |
|
| 202 | - */ |
|
| 203 | - public function decrementRemainingOccurences(): self |
|
| 204 | - { |
|
| 205 | - if ($this->nb_occurrences > 0) { |
|
| 206 | - $this->nb_occurrences--; |
|
| 207 | - if ($this->nb_occurrences == 0) { |
|
| 208 | - $this->disable(); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - return $this; |
|
| 212 | - } |
|
| 197 | + /** |
|
| 198 | + * Decrements the number of remaining occurences by 1. |
|
| 199 | + * The task will be disabled when the number reaches 0. |
|
| 200 | + * |
|
| 201 | + * @return $this |
|
| 202 | + */ |
|
| 203 | + public function decrementRemainingOccurences(): self |
|
| 204 | + { |
|
| 205 | + if ($this->nb_occurrences > 0) { |
|
| 206 | + $this->nb_occurrences--; |
|
| 207 | + if ($this->nb_occurrences == 0) { |
|
| 208 | + $this->disable(); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + return $this; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Set the number of remaining occurences of task runs. |
|
| 216 | - * |
|
| 217 | - * @param int $nb_occurrences |
|
| 218 | - * @return $this |
|
| 219 | - */ |
|
| 220 | - public function setRemainingOccurences(int $nb_occurrences): self |
|
| 221 | - { |
|
| 222 | - $this->nb_occurrences = $nb_occurrences; |
|
| 223 | - return $this; |
|
| 224 | - } |
|
| 214 | + /** |
|
| 215 | + * Set the number of remaining occurences of task runs. |
|
| 216 | + * |
|
| 217 | + * @param int $nb_occurrences |
|
| 218 | + * @return $this |
|
| 219 | + */ |
|
| 220 | + public function setRemainingOccurences(int $nb_occurrences): self |
|
| 221 | + { |
|
| 222 | + $this->nb_occurrences = $nb_occurrences; |
|
| 223 | + return $this; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Returns whether the task is running |
|
| 228 | - * @return bool |
|
| 229 | - */ |
|
| 230 | - public function isRunning(): bool |
|
| 231 | - { |
|
| 232 | - return $this->is_running; |
|
| 233 | - } |
|
| 226 | + /** |
|
| 227 | + * Returns whether the task is running |
|
| 228 | + * @return bool |
|
| 229 | + */ |
|
| 230 | + public function isRunning(): bool |
|
| 231 | + { |
|
| 232 | + return $this->is_running; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * Informs the schedule that the task is going to run |
|
| 237 | - * |
|
| 238 | - * @return $this |
|
| 239 | - */ |
|
| 240 | - public function startRunning(): self |
|
| 241 | - { |
|
| 242 | - $this->is_running = true; |
|
| 243 | - return $this; |
|
| 244 | - } |
|
| 235 | + /** |
|
| 236 | + * Informs the schedule that the task is going to run |
|
| 237 | + * |
|
| 238 | + * @return $this |
|
| 239 | + */ |
|
| 240 | + public function startRunning(): self |
|
| 241 | + { |
|
| 242 | + $this->is_running = true; |
|
| 243 | + return $this; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * Informs the schedule that the task has stopped running. |
|
| 248 | - * @return $this |
|
| 249 | - */ |
|
| 250 | - public function stopRunning(): self |
|
| 251 | - { |
|
| 252 | - $this->is_running = false; |
|
| 253 | - return $this; |
|
| 254 | - } |
|
| 246 | + /** |
|
| 247 | + * Informs the schedule that the task has stopped running. |
|
| 248 | + * @return $this |
|
| 249 | + */ |
|
| 250 | + public function stopRunning(): self |
|
| 251 | + { |
|
| 252 | + $this->is_running = false; |
|
| 253 | + return $this; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * Returns the schedule details as an associate array |
|
| 258 | - * |
|
| 259 | - * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 260 | - * @return array{id: int, task_id: string, enabled: bool, last_run: Carbon, last_result: bool, frequency: CarbonInterval, nb_occurrences: int, is_running: bool} |
|
| 261 | - */ |
|
| 262 | - public function toArray(): array |
|
| 263 | - { |
|
| 264 | - return [ |
|
| 265 | - 'id' => $this->id, |
|
| 266 | - 'task_id' => $this->task_id, |
|
| 267 | - 'enabled' => $this->enabled, |
|
| 268 | - 'last_run' => $this->last_run, |
|
| 269 | - 'last_result' => $this->last_result, |
|
| 270 | - 'frequency' => $this->frequency, |
|
| 271 | - 'nb_occurrences' => $this->nb_occurrences, |
|
| 272 | - 'is_running' => $this->is_running |
|
| 273 | - ]; |
|
| 274 | - } |
|
| 256 | + /** |
|
| 257 | + * Returns the schedule details as an associate array |
|
| 258 | + * |
|
| 259 | + * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 260 | + * @return array{id: int, task_id: string, enabled: bool, last_run: Carbon, last_result: bool, frequency: CarbonInterval, nb_occurrences: int, is_running: bool} |
|
| 261 | + */ |
|
| 262 | + public function toArray(): array |
|
| 263 | + { |
|
| 264 | + return [ |
|
| 265 | + 'id' => $this->id, |
|
| 266 | + 'task_id' => $this->task_id, |
|
| 267 | + 'enabled' => $this->enabled, |
|
| 268 | + 'last_run' => $this->last_run, |
|
| 269 | + 'last_result' => $this->last_result, |
|
| 270 | + 'frequency' => $this->frequency, |
|
| 271 | + 'nb_occurrences' => $this->nb_occurrences, |
|
| 272 | + 'is_running' => $this->is_running |
|
| 273 | + ]; |
|
| 274 | + } |
|
| 275 | 275 | } |
@@ -28,78 +28,78 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | abstract class AbstractHookCollector implements HookCollectorInterface, HookInterface |
| 30 | 30 | { |
| 31 | - /** @var Collection<THook> $hooks */ |
|
| 32 | - protected Collection $hooks; |
|
| 31 | + /** @var Collection<THook> $hooks */ |
|
| 32 | + protected Collection $hooks; |
|
| 33 | 33 | |
| 34 | - private ModuleInterface $module; |
|
| 34 | + private ModuleInterface $module; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for AbstractHookCollector |
|
| 38 | - * |
|
| 39 | - * @param ModuleInterface $module |
|
| 40 | - */ |
|
| 41 | - public function __construct(ModuleInterface $module) |
|
| 42 | - { |
|
| 43 | - $this->hooks = new Collection(); |
|
| 44 | - $this->module = $module; |
|
| 45 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for AbstractHookCollector |
|
| 38 | + * |
|
| 39 | + * @param ModuleInterface $module |
|
| 40 | + */ |
|
| 41 | + public function __construct(ModuleInterface $module) |
|
| 42 | + { |
|
| 43 | + $this->hooks = new Collection(); |
|
| 44 | + $this->module = $module; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * {@inheritDoc} |
|
| 49 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 50 | - */ |
|
| 51 | - public function module(): ModuleInterface |
|
| 52 | - { |
|
| 53 | - return $this->module; |
|
| 54 | - } |
|
| 47 | + /** |
|
| 48 | + * {@inheritDoc} |
|
| 49 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 50 | + */ |
|
| 51 | + public function module(): ModuleInterface |
|
| 52 | + { |
|
| 53 | + return $this->module; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * {@inheritDoc} |
|
| 58 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::name() |
|
| 59 | - */ |
|
| 60 | - public function name(): string |
|
| 61 | - { |
|
| 62 | - return $this->module->name() . '-' . |
|
| 63 | - mb_substr(str_replace('collector', '', mb_strtolower((new ReflectionClass($this))->getShortName())), 0, 64); |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * {@inheritDoc} |
|
| 58 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::name() |
|
| 59 | + */ |
|
| 60 | + public function name(): string |
|
| 61 | + { |
|
| 62 | + return $this->module->name() . '-' . |
|
| 63 | + mb_substr(str_replace('collector', '', mb_strtolower((new ReflectionClass($this))->getShortName())), 0, 64); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * {@inheritDoc} |
|
| 68 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::title() |
|
| 69 | - */ |
|
| 70 | - abstract public function title(): string; |
|
| 66 | + /** |
|
| 67 | + * {@inheritDoc} |
|
| 68 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::title() |
|
| 69 | + */ |
|
| 70 | + abstract public function title(): string; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * {@inheritDoc} |
|
| 74 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::description() |
|
| 75 | - */ |
|
| 76 | - abstract public function description(): string; |
|
| 72 | + /** |
|
| 73 | + * {@inheritDoc} |
|
| 74 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::description() |
|
| 75 | + */ |
|
| 76 | + abstract public function description(): string; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * {@inheritDoc} |
|
| 80 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hookInterface() |
|
| 81 | - */ |
|
| 82 | - abstract public function hookInterface(): string; |
|
| 78 | + /** |
|
| 79 | + * {@inheritDoc} |
|
| 80 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hookInterface() |
|
| 81 | + */ |
|
| 82 | + abstract public function hookInterface(): string; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * {@inheritDoc} |
|
| 86 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::register() |
|
| 87 | - */ |
|
| 88 | - public function register(HookInterface $hook_instance, int $order): void |
|
| 89 | - { |
|
| 90 | - if ($this->hooks->has($order)) { |
|
| 91 | - $this->hooks->splice($order + 1, 0, [$hook_instance]); |
|
| 92 | - } else { |
|
| 93 | - $this->hooks->put($order, $hook_instance); |
|
| 94 | - } |
|
| 95 | - } |
|
| 84 | + /** |
|
| 85 | + * {@inheritDoc} |
|
| 86 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::register() |
|
| 87 | + */ |
|
| 88 | + public function register(HookInterface $hook_instance, int $order): void |
|
| 89 | + { |
|
| 90 | + if ($this->hooks->has($order)) { |
|
| 91 | + $this->hooks->splice($order + 1, 0, [$hook_instance]); |
|
| 92 | + } else { |
|
| 93 | + $this->hooks->put($order, $hook_instance); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * {@inheritDoc} |
|
| 99 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hooks() |
|
| 100 | - */ |
|
| 101 | - public function hooks(): Collection |
|
| 102 | - { |
|
| 103 | - return $this->hooks->sortKeys(); |
|
| 104 | - } |
|
| 97 | + /** |
|
| 98 | + * {@inheritDoc} |
|
| 99 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hooks() |
|
| 100 | + */ |
|
| 101 | + public function hooks(): Collection |
|
| 102 | + { |
|
| 103 | + return $this->hooks->sortKeys(); |
|
| 104 | + } |
|
| 105 | 105 | } |