@@ -23,102 +23,102 @@ |
||
| 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 | - public function sortedDetailed(): Collection |
|
| 67 | - { |
|
| 68 | - return $this->detailed->sortBy([ |
|
| 69 | - fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => $a->order() <=> $b->order(), |
|
| 70 | - fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => |
|
| 71 | - I18N::comparator()($a->description(), $b->description()) |
|
| 72 | - ]); |
|
| 73 | - } |
|
| 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 | + public function sortedDetailed(): Collection |
|
| 67 | + { |
|
| 68 | + return $this->detailed->sortBy([ |
|
| 69 | + fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => $a->order() <=> $b->order(), |
|
| 70 | + fn(GeoAnalysisResult $a, GeoAnalysisResult $b): int => |
|
| 71 | + I18N::comparator()($a->description(), $b->description()) |
|
| 72 | + ]); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Add a GeoAnalysis Place to the global result |
|
| 77 | - * |
|
| 78 | - * @param GeoAnalysisPlace $place |
|
| 79 | - */ |
|
| 80 | - public function addPlace(GeoAnalysisPlace $place): void |
|
| 81 | - { |
|
| 82 | - $this->global()->addPlace($place); |
|
| 83 | - } |
|
| 75 | + /** |
|
| 76 | + * Add a GeoAnalysis Place to the global result |
|
| 77 | + * |
|
| 78 | + * @param GeoAnalysisPlace $place |
|
| 79 | + */ |
|
| 80 | + public function addPlace(GeoAnalysisPlace $place): void |
|
| 81 | + { |
|
| 82 | + $this->global()->addPlace($place); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Add a new category to the list of results, if it does not exist yet |
|
| 87 | - * |
|
| 88 | - * @param string $description |
|
| 89 | - * @param int $order |
|
| 90 | - */ |
|
| 91 | - public function addCategory(string $description, int $order): void |
|
| 92 | - { |
|
| 93 | - if (!$this->detailed->has($description)) { |
|
| 94 | - $this->detailed->put($description, new GeoAnalysisResult($description, $order)); |
|
| 95 | - } |
|
| 96 | - } |
|
| 85 | + /** |
|
| 86 | + * Add a new category to the list of results, if it does not exist yet |
|
| 87 | + * |
|
| 88 | + * @param string $description |
|
| 89 | + * @param int $order |
|
| 90 | + */ |
|
| 91 | + public function addCategory(string $description, int $order): void |
|
| 92 | + { |
|
| 93 | + if (!$this->detailed->has($description)) { |
|
| 94 | + $this->detailed->put($description, new GeoAnalysisResult($description, $order)); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Add a GeoAnalysis Place to a category result, if the category exist. |
|
| 100 | - * |
|
| 101 | - * @param string $category_name |
|
| 102 | - * @param GeoAnalysisPlace $place |
|
| 103 | - */ |
|
| 104 | - public function addPlaceInCreatedCategory(string $category_name, GeoAnalysisPlace $place): void |
|
| 105 | - { |
|
| 106 | - if ($this->detailed->has($category_name)) { |
|
| 107 | - $this->detailed->get($category_name)->addPlace($place); |
|
| 108 | - } |
|
| 109 | - } |
|
| 98 | + /** |
|
| 99 | + * Add a GeoAnalysis Place to a category result, if the category exist. |
|
| 100 | + * |
|
| 101 | + * @param string $category_name |
|
| 102 | + * @param GeoAnalysisPlace $place |
|
| 103 | + */ |
|
| 104 | + public function addPlaceInCreatedCategory(string $category_name, GeoAnalysisPlace $place): void |
|
| 105 | + { |
|
| 106 | + if ($this->detailed->has($category_name)) { |
|
| 107 | + $this->detailed->get($category_name)->addPlace($place); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Add a GeoAnalysis Place to a category result, after creating the category if it does not exist. |
|
| 113 | - * |
|
| 114 | - * @param string $category_name |
|
| 115 | - * @param GeoAnalysisPlace $place |
|
| 116 | - */ |
|
| 117 | - public function addPlaceInCategory(string $category_name, int $category_order, GeoAnalysisPlace $place): void |
|
| 118 | - { |
|
| 119 | - if (!$this->detailed->has($category_name)) { |
|
| 120 | - $this->addCategory($category_name, $category_order); |
|
| 121 | - } |
|
| 122 | - $this->addPlaceInCreatedCategory($category_name, $place); |
|
| 123 | - } |
|
| 111 | + /** |
|
| 112 | + * Add a GeoAnalysis Place to a category result, after creating the category if it does not exist. |
|
| 113 | + * |
|
| 114 | + * @param string $category_name |
|
| 115 | + * @param GeoAnalysisPlace $place |
|
| 116 | + */ |
|
| 117 | + public function addPlaceInCategory(string $category_name, int $category_order, GeoAnalysisPlace $place): void |
|
| 118 | + { |
|
| 119 | + if (!$this->detailed->has($category_name)) { |
|
| 120 | + $this->addCategory($category_name, $category_order); |
|
| 121 | + } |
|
| 122 | + $this->addPlaceInCreatedCategory($category_name, $place); |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -28,137 +28,137 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class GeoAnalysisPlace |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * The default place name for invalid places |
|
| 33 | - * @var string INVALID_PLACE |
|
| 34 | - */ |
|
| 35 | - private const INVALID_PLACE = '##INVALID##'; |
|
| 36 | - |
|
| 37 | - private Place $place; |
|
| 38 | - private int $depth; |
|
| 39 | - private bool $strict_depth; |
|
| 40 | - private bool $is_excluded; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Constructor for GeoAnalysisPlace |
|
| 44 | - * |
|
| 45 | - * @param Tree $tree Default tree |
|
| 46 | - * @param Place|null $place Place resulting from the analysis |
|
| 47 | - * @param int $depth Place hierarchy depth defined by the geographical analysis view |
|
| 48 | - * @param bool $strict_depth Checks whether places with a lower depth than defined should be flagged as invalid |
|
| 49 | - */ |
|
| 50 | - public function __construct(Tree $tree, ?Place $place, int $depth, bool $strict_depth = false) |
|
| 51 | - { |
|
| 52 | - $this->depth = $depth; |
|
| 53 | - $this->strict_depth = $strict_depth; |
|
| 54 | - $this->place = $this->extractPlace($place, $depth, $strict_depth) ?? new Place('', $tree); |
|
| 55 | - $this->is_excluded = false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Process the provided Place to determine its status for further usage |
|
| 60 | - * |
|
| 61 | - * @param Place|null $place |
|
| 62 | - * @param int $depth |
|
| 63 | - * @param bool $strict_depth |
|
| 64 | - * @return Place|NULL |
|
| 65 | - */ |
|
| 66 | - private function extractPlace(?Place $place, int $depth, bool $strict_depth): ?Place |
|
| 67 | - { |
|
| 68 | - if ($place === null) { |
|
| 69 | - return null; |
|
| 70 | - } |
|
| 71 | - if (mb_strlen($place->gedcomName()) === 0) { |
|
| 72 | - return null; |
|
| 73 | - } |
|
| 74 | - $parts = $place->lastParts($depth); |
|
| 75 | - if ($strict_depth && $parts->count() !== $depth) { |
|
| 76 | - return new Place(self::INVALID_PLACE, $place->tree()); |
|
| 77 | - } |
|
| 78 | - return new Place($parts->implode(', '), $place->tree()); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Get the GeoAnalysis Place key |
|
| 83 | - * |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public function key(): string |
|
| 87 | - { |
|
| 88 | - return $this->place->gedcomName(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Get the underlying Place object |
|
| 93 | - * |
|
| 94 | - * @return Place |
|
| 95 | - */ |
|
| 96 | - public function place(): Place |
|
| 97 | - { |
|
| 98 | - return $this->place; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Check if the GeoAnalysis Place is in the Known status |
|
| 103 | - * |
|
| 104 | - * @return bool |
|
| 105 | - */ |
|
| 106 | - public function isKnown(): bool |
|
| 107 | - { |
|
| 108 | - return !$this->isUnknown(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Check if the GeoAnalysis Place is in the Unknown status |
|
| 113 | - * |
|
| 114 | - * @return bool |
|
| 115 | - */ |
|
| 116 | - public function isUnknown(): bool |
|
| 117 | - { |
|
| 118 | - return mb_strlen($this->place->gedcomName()) === 0; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Check if the GeoAnalysis Place is in the Invalid status |
|
| 123 | - * |
|
| 124 | - * @return bool |
|
| 125 | - */ |
|
| 126 | - public function isInvalid(): bool |
|
| 127 | - { |
|
| 128 | - return $this->place->gedcomName() === self::INVALID_PLACE; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Check if the GeoAnalysis Place is in the Excluded status |
|
| 133 | - * |
|
| 134 | - * @return bool |
|
| 135 | - */ |
|
| 136 | - public function isExcluded(): bool |
|
| 137 | - { |
|
| 138 | - return $this->isUnknown() || $this->isInvalid() || $this->is_excluded; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Set the GeoAnalysis Place status to Found, if the parameter is true |
|
| 143 | - * |
|
| 144 | - * @param bool $include |
|
| 145 | - * @return $this |
|
| 146 | - */ |
|
| 147 | - public function include(bool $include = true): self |
|
| 148 | - { |
|
| 149 | - $this->is_excluded = !$include; |
|
| 150 | - return $this; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Set the GeoAnalysis Place status to Excluded, if the parameter is true |
|
| 155 | - * |
|
| 156 | - * @param bool $exclude |
|
| 157 | - * @return $this |
|
| 158 | - */ |
|
| 159 | - public function exclude(bool $exclude = true): self |
|
| 160 | - { |
|
| 161 | - $this->is_excluded = $exclude; |
|
| 162 | - return $this; |
|
| 163 | - } |
|
| 31 | + /** |
|
| 32 | + * The default place name for invalid places |
|
| 33 | + * @var string INVALID_PLACE |
|
| 34 | + */ |
|
| 35 | + private const INVALID_PLACE = '##INVALID##'; |
|
| 36 | + |
|
| 37 | + private Place $place; |
|
| 38 | + private int $depth; |
|
| 39 | + private bool $strict_depth; |
|
| 40 | + private bool $is_excluded; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Constructor for GeoAnalysisPlace |
|
| 44 | + * |
|
| 45 | + * @param Tree $tree Default tree |
|
| 46 | + * @param Place|null $place Place resulting from the analysis |
|
| 47 | + * @param int $depth Place hierarchy depth defined by the geographical analysis view |
|
| 48 | + * @param bool $strict_depth Checks whether places with a lower depth than defined should be flagged as invalid |
|
| 49 | + */ |
|
| 50 | + public function __construct(Tree $tree, ?Place $place, int $depth, bool $strict_depth = false) |
|
| 51 | + { |
|
| 52 | + $this->depth = $depth; |
|
| 53 | + $this->strict_depth = $strict_depth; |
|
| 54 | + $this->place = $this->extractPlace($place, $depth, $strict_depth) ?? new Place('', $tree); |
|
| 55 | + $this->is_excluded = false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Process the provided Place to determine its status for further usage |
|
| 60 | + * |
|
| 61 | + * @param Place|null $place |
|
| 62 | + * @param int $depth |
|
| 63 | + * @param bool $strict_depth |
|
| 64 | + * @return Place|NULL |
|
| 65 | + */ |
|
| 66 | + private function extractPlace(?Place $place, int $depth, bool $strict_depth): ?Place |
|
| 67 | + { |
|
| 68 | + if ($place === null) { |
|
| 69 | + return null; |
|
| 70 | + } |
|
| 71 | + if (mb_strlen($place->gedcomName()) === 0) { |
|
| 72 | + return null; |
|
| 73 | + } |
|
| 74 | + $parts = $place->lastParts($depth); |
|
| 75 | + if ($strict_depth && $parts->count() !== $depth) { |
|
| 76 | + return new Place(self::INVALID_PLACE, $place->tree()); |
|
| 77 | + } |
|
| 78 | + return new Place($parts->implode(', '), $place->tree()); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Get the GeoAnalysis Place key |
|
| 83 | + * |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public function key(): string |
|
| 87 | + { |
|
| 88 | + return $this->place->gedcomName(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Get the underlying Place object |
|
| 93 | + * |
|
| 94 | + * @return Place |
|
| 95 | + */ |
|
| 96 | + public function place(): Place |
|
| 97 | + { |
|
| 98 | + return $this->place; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Check if the GeoAnalysis Place is in the Known status |
|
| 103 | + * |
|
| 104 | + * @return bool |
|
| 105 | + */ |
|
| 106 | + public function isKnown(): bool |
|
| 107 | + { |
|
| 108 | + return !$this->isUnknown(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Check if the GeoAnalysis Place is in the Unknown status |
|
| 113 | + * |
|
| 114 | + * @return bool |
|
| 115 | + */ |
|
| 116 | + public function isUnknown(): bool |
|
| 117 | + { |
|
| 118 | + return mb_strlen($this->place->gedcomName()) === 0; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Check if the GeoAnalysis Place is in the Invalid status |
|
| 123 | + * |
|
| 124 | + * @return bool |
|
| 125 | + */ |
|
| 126 | + public function isInvalid(): bool |
|
| 127 | + { |
|
| 128 | + return $this->place->gedcomName() === self::INVALID_PLACE; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Check if the GeoAnalysis Place is in the Excluded status |
|
| 133 | + * |
|
| 134 | + * @return bool |
|
| 135 | + */ |
|
| 136 | + public function isExcluded(): bool |
|
| 137 | + { |
|
| 138 | + return $this->isUnknown() || $this->isInvalid() || $this->is_excluded; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Set the GeoAnalysis Place status to Found, if the parameter is true |
|
| 143 | + * |
|
| 144 | + * @param bool $include |
|
| 145 | + * @return $this |
|
| 146 | + */ |
|
| 147 | + public function include(bool $include = true): self |
|
| 148 | + { |
|
| 149 | + $this->is_excluded = !$include; |
|
| 150 | + return $this; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Set the GeoAnalysis Place status to Excluded, if the parameter is true |
|
| 155 | + * |
|
| 156 | + * @param bool $exclude |
|
| 157 | + * @return $this |
|
| 158 | + */ |
|
| 159 | + public function exclude(bool $exclude = true): self |
|
| 160 | + { |
|
| 161 | + $this->is_excluded = $exclude; |
|
| 162 | + return $this; |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -24,225 +24,225 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class GeoAnalysisResult |
| 26 | 26 | { |
| 27 | - private string $description; |
|
| 28 | - private int $order; |
|
| 29 | - private int $unknown_count; |
|
| 30 | - /** |
|
| 31 | - * @var Collection<GeoAnalysisResultItem> |
|
| 32 | - */ |
|
| 33 | - private Collection $places; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Constructor for GeoAnalysisResult |
|
| 37 | - * |
|
| 38 | - * @param string $description |
|
| 39 | - * @param int $order |
|
| 40 | - * @param Collection<GeoAnalysisResultItem> $places |
|
| 41 | - * @param int $unknown |
|
| 42 | - */ |
|
| 43 | - final public function __construct( |
|
| 44 | - string $description, |
|
| 45 | - int $order = 0, |
|
| 46 | - Collection $places = null, |
|
| 47 | - int $unknown = 0 |
|
| 48 | - ) { |
|
| 49 | - $this->description = $description; |
|
| 50 | - $this->order = $order; |
|
| 51 | - $this->places = $places ?? new Collection(); |
|
| 52 | - $this->unknown_count = $unknown; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Get the category description |
|
| 57 | - * |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function description(): string |
|
| 61 | - { |
|
| 62 | - return $this->description; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the category order |
|
| 67 | - * |
|
| 68 | - * @return int |
|
| 69 | - */ |
|
| 70 | - public function order(): int |
|
| 71 | - { |
|
| 72 | - return $this->order; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Add a place to the analysis result |
|
| 77 | - * |
|
| 78 | - * @param GeoAnalysisPlace $place |
|
| 79 | - */ |
|
| 80 | - public function addPlace(GeoAnalysisPlace $place): void |
|
| 81 | - { |
|
| 82 | - if ($place->isKnown()) { |
|
| 83 | - /** @var GeoAnalysisResultItem $item */ |
|
| 84 | - $item = $this->places->get($place->key(), new GeoAnalysisResultItem($place)); |
|
| 85 | - $this->places->put($item->key(), $item->increment()); |
|
| 86 | - } else { |
|
| 87 | - $this->addUnknown(); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Exclude a place from the analysis result |
|
| 93 | - * |
|
| 94 | - * @param GeoAnalysisPlace $place |
|
| 95 | - */ |
|
| 96 | - public function exclude(GeoAnalysisPlace $place): void |
|
| 97 | - { |
|
| 98 | - /** @var GeoAnalysisResultItem|null $item */ |
|
| 99 | - $item = $this->places->get($place->key()); |
|
| 100 | - if ($item !== null) { |
|
| 101 | - $item->place()->exclude(); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Add an unknown place to the analysis result |
|
| 107 | - */ |
|
| 108 | - public function addUnknown(): void |
|
| 109 | - { |
|
| 110 | - $this->unknown_count++; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Take a copy of the current analysis result |
|
| 115 | - * |
|
| 116 | - * @return static |
|
| 117 | - */ |
|
| 118 | - public function copy(): self |
|
| 119 | - { |
|
| 120 | - return new static( |
|
| 121 | - $this->description(), |
|
| 122 | - $this->order(), |
|
| 123 | - $this->places->map(fn(GeoAnalysisResultItem $item): GeoAnalysisResultItem => clone $item), |
|
| 124 | - $this->countUnknown() |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Merge the current analysis result with another. |
|
| 130 | - * The current object is modified, not the second one. |
|
| 131 | - * |
|
| 132 | - * @param GeoAnalysisResult $other |
|
| 133 | - * @return $this |
|
| 134 | - */ |
|
| 135 | - public function merge(GeoAnalysisResult $other): self |
|
| 136 | - { |
|
| 137 | - $this->places->each(function (GeoAnalysisResultItem $item) use ($other): void { |
|
| 138 | - if ($other->places->has($item->key())) { |
|
| 139 | - $item->place()->exclude( |
|
| 140 | - $item->place()->isExcluded() |
|
| 141 | - && $other->places->get($item->key())->place()->isExcluded() |
|
| 142 | - ); |
|
| 143 | - } |
|
| 144 | - }); |
|
| 145 | - |
|
| 146 | - $other->places->each(function (GeoAnalysisResultItem $item): void { |
|
| 147 | - if (!$this->places->has($item->key())) { |
|
| 148 | - $this->addPlace($item->place()); |
|
| 149 | - } |
|
| 150 | - }); |
|
| 151 | - |
|
| 152 | - return $this; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Get the count of Known places |
|
| 157 | - * |
|
| 158 | - * @return int |
|
| 159 | - */ |
|
| 160 | - public function countKnown(): int |
|
| 161 | - { |
|
| 162 | - return $this->places->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Get the count of Found places |
|
| 167 | - * |
|
| 168 | - * @return int |
|
| 169 | - */ |
|
| 170 | - public function countFound(): int |
|
| 171 | - { |
|
| 172 | - return $this->places |
|
| 173 | - ->reject(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()) |
|
| 174 | - ->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Get the count of Excluded places |
|
| 179 | - * |
|
| 180 | - * @return int |
|
| 181 | - */ |
|
| 182 | - public function countExcluded(): int |
|
| 183 | - { |
|
| 184 | - return $this->places |
|
| 185 | - ->filter(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()) |
|
| 186 | - ->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Get the count of Unknown places |
|
| 191 | - * |
|
| 192 | - * @return int |
|
| 193 | - */ |
|
| 194 | - public function countUnknown(): int |
|
| 195 | - { |
|
| 196 | - return $this->unknown_count; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Get the count of the most represented Place in the analysis result |
|
| 201 | - * |
|
| 202 | - * @return int |
|
| 203 | - */ |
|
| 204 | - public function maxCount(): int |
|
| 205 | - { |
|
| 206 | - return $this->places->max(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Get the list of Known places with their associated count |
|
| 211 | - * |
|
| 212 | - * @param bool $exclude_other |
|
| 213 | - * @return Collection<GeoAnalysisResultItem> |
|
| 214 | - */ |
|
| 215 | - public function knownPlaces(bool $exclude_other = false): Collection |
|
| 216 | - { |
|
| 217 | - if ($exclude_other) { |
|
| 218 | - return $this->places->reject(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()); |
|
| 219 | - } |
|
| 220 | - return $this->places; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Get the list of Known places with their associated count. |
|
| 225 | - * The list is sorted first by descending count, then by ascending Place name |
|
| 226 | - * |
|
| 227 | - * @param bool $exclude_other |
|
| 228 | - * @return Collection<GeoAnalysisResultItem> |
|
| 229 | - */ |
|
| 230 | - public function sortedKnownPlaces(bool $exclude_other = false): Collection |
|
| 231 | - { |
|
| 232 | - return $this->knownPlaces($exclude_other)->sortBy([ |
|
| 233 | - fn (GeoAnalysisResultItem $a, GeoAnalysisResultItem $b): int => $b->count() <=> $a->count(), |
|
| 234 | - fn (GeoAnalysisResultItem $a, GeoAnalysisResultItem $b): int => |
|
| 235 | - I18N::comparator()($a->place()->place()->gedcomName(), $b->place()->place()->gedcomName()) |
|
| 236 | - ]); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Get the list of Excluded places |
|
| 241 | - * |
|
| 242 | - * @return Collection<GeoAnalysisResultItem> |
|
| 243 | - */ |
|
| 244 | - public function excludedPlaces(): Collection |
|
| 245 | - { |
|
| 246 | - return $this->places->filter(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()); |
|
| 247 | - } |
|
| 27 | + private string $description; |
|
| 28 | + private int $order; |
|
| 29 | + private int $unknown_count; |
|
| 30 | + /** |
|
| 31 | + * @var Collection<GeoAnalysisResultItem> |
|
| 32 | + */ |
|
| 33 | + private Collection $places; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Constructor for GeoAnalysisResult |
|
| 37 | + * |
|
| 38 | + * @param string $description |
|
| 39 | + * @param int $order |
|
| 40 | + * @param Collection<GeoAnalysisResultItem> $places |
|
| 41 | + * @param int $unknown |
|
| 42 | + */ |
|
| 43 | + final public function __construct( |
|
| 44 | + string $description, |
|
| 45 | + int $order = 0, |
|
| 46 | + Collection $places = null, |
|
| 47 | + int $unknown = 0 |
|
| 48 | + ) { |
|
| 49 | + $this->description = $description; |
|
| 50 | + $this->order = $order; |
|
| 51 | + $this->places = $places ?? new Collection(); |
|
| 52 | + $this->unknown_count = $unknown; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Get the category description |
|
| 57 | + * |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function description(): string |
|
| 61 | + { |
|
| 62 | + return $this->description; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the category order |
|
| 67 | + * |
|
| 68 | + * @return int |
|
| 69 | + */ |
|
| 70 | + public function order(): int |
|
| 71 | + { |
|
| 72 | + return $this->order; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Add a place to the analysis result |
|
| 77 | + * |
|
| 78 | + * @param GeoAnalysisPlace $place |
|
| 79 | + */ |
|
| 80 | + public function addPlace(GeoAnalysisPlace $place): void |
|
| 81 | + { |
|
| 82 | + if ($place->isKnown()) { |
|
| 83 | + /** @var GeoAnalysisResultItem $item */ |
|
| 84 | + $item = $this->places->get($place->key(), new GeoAnalysisResultItem($place)); |
|
| 85 | + $this->places->put($item->key(), $item->increment()); |
|
| 86 | + } else { |
|
| 87 | + $this->addUnknown(); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Exclude a place from the analysis result |
|
| 93 | + * |
|
| 94 | + * @param GeoAnalysisPlace $place |
|
| 95 | + */ |
|
| 96 | + public function exclude(GeoAnalysisPlace $place): void |
|
| 97 | + { |
|
| 98 | + /** @var GeoAnalysisResultItem|null $item */ |
|
| 99 | + $item = $this->places->get($place->key()); |
|
| 100 | + if ($item !== null) { |
|
| 101 | + $item->place()->exclude(); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Add an unknown place to the analysis result |
|
| 107 | + */ |
|
| 108 | + public function addUnknown(): void |
|
| 109 | + { |
|
| 110 | + $this->unknown_count++; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Take a copy of the current analysis result |
|
| 115 | + * |
|
| 116 | + * @return static |
|
| 117 | + */ |
|
| 118 | + public function copy(): self |
|
| 119 | + { |
|
| 120 | + return new static( |
|
| 121 | + $this->description(), |
|
| 122 | + $this->order(), |
|
| 123 | + $this->places->map(fn(GeoAnalysisResultItem $item): GeoAnalysisResultItem => clone $item), |
|
| 124 | + $this->countUnknown() |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Merge the current analysis result with another. |
|
| 130 | + * The current object is modified, not the second one. |
|
| 131 | + * |
|
| 132 | + * @param GeoAnalysisResult $other |
|
| 133 | + * @return $this |
|
| 134 | + */ |
|
| 135 | + public function merge(GeoAnalysisResult $other): self |
|
| 136 | + { |
|
| 137 | + $this->places->each(function (GeoAnalysisResultItem $item) use ($other): void { |
|
| 138 | + if ($other->places->has($item->key())) { |
|
| 139 | + $item->place()->exclude( |
|
| 140 | + $item->place()->isExcluded() |
|
| 141 | + && $other->places->get($item->key())->place()->isExcluded() |
|
| 142 | + ); |
|
| 143 | + } |
|
| 144 | + }); |
|
| 145 | + |
|
| 146 | + $other->places->each(function (GeoAnalysisResultItem $item): void { |
|
| 147 | + if (!$this->places->has($item->key())) { |
|
| 148 | + $this->addPlace($item->place()); |
|
| 149 | + } |
|
| 150 | + }); |
|
| 151 | + |
|
| 152 | + return $this; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Get the count of Known places |
|
| 157 | + * |
|
| 158 | + * @return int |
|
| 159 | + */ |
|
| 160 | + public function countKnown(): int |
|
| 161 | + { |
|
| 162 | + return $this->places->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Get the count of Found places |
|
| 167 | + * |
|
| 168 | + * @return int |
|
| 169 | + */ |
|
| 170 | + public function countFound(): int |
|
| 171 | + { |
|
| 172 | + return $this->places |
|
| 173 | + ->reject(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()) |
|
| 174 | + ->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Get the count of Excluded places |
|
| 179 | + * |
|
| 180 | + * @return int |
|
| 181 | + */ |
|
| 182 | + public function countExcluded(): int |
|
| 183 | + { |
|
| 184 | + return $this->places |
|
| 185 | + ->filter(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()) |
|
| 186 | + ->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Get the count of Unknown places |
|
| 191 | + * |
|
| 192 | + * @return int |
|
| 193 | + */ |
|
| 194 | + public function countUnknown(): int |
|
| 195 | + { |
|
| 196 | + return $this->unknown_count; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Get the count of the most represented Place in the analysis result |
|
| 201 | + * |
|
| 202 | + * @return int |
|
| 203 | + */ |
|
| 204 | + public function maxCount(): int |
|
| 205 | + { |
|
| 206 | + return $this->places->max(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Get the list of Known places with their associated count |
|
| 211 | + * |
|
| 212 | + * @param bool $exclude_other |
|
| 213 | + * @return Collection<GeoAnalysisResultItem> |
|
| 214 | + */ |
|
| 215 | + public function knownPlaces(bool $exclude_other = false): Collection |
|
| 216 | + { |
|
| 217 | + if ($exclude_other) { |
|
| 218 | + return $this->places->reject(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()); |
|
| 219 | + } |
|
| 220 | + return $this->places; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Get the list of Known places with their associated count. |
|
| 225 | + * The list is sorted first by descending count, then by ascending Place name |
|
| 226 | + * |
|
| 227 | + * @param bool $exclude_other |
|
| 228 | + * @return Collection<GeoAnalysisResultItem> |
|
| 229 | + */ |
|
| 230 | + public function sortedKnownPlaces(bool $exclude_other = false): Collection |
|
| 231 | + { |
|
| 232 | + return $this->knownPlaces($exclude_other)->sortBy([ |
|
| 233 | + fn (GeoAnalysisResultItem $a, GeoAnalysisResultItem $b): int => $b->count() <=> $a->count(), |
|
| 234 | + fn (GeoAnalysisResultItem $a, GeoAnalysisResultItem $b): int => |
|
| 235 | + I18N::comparator()($a->place()->place()->gedcomName(), $b->place()->place()->gedcomName()) |
|
| 236 | + ]); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Get the list of Excluded places |
|
| 241 | + * |
|
| 242 | + * @return Collection<GeoAnalysisResultItem> |
|
| 243 | + */ |
|
| 244 | + public function excludedPlaces(): Collection |
|
| 245 | + { |
|
| 246 | + return $this->places->filter(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()); |
|
| 247 | + } |
|
| 248 | 248 | } |
@@ -27,59 +27,59 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class SimpleFilesystemMap implements MapDefinitionInterface |
| 29 | 29 | { |
| 30 | - private string $id; |
|
| 31 | - private string $title; |
|
| 32 | - private string $path; |
|
| 33 | - private FilesystemReader $filesystem; |
|
| 30 | + private string $id; |
|
| 31 | + private string $title; |
|
| 32 | + private string $path; |
|
| 33 | + private FilesystemReader $filesystem; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor for SimpleFilesystemMap |
|
| 37 | - * |
|
| 38 | - * @param string $id |
|
| 39 | - * @param string $title |
|
| 40 | - * @param FilesystemReader $filesystem |
|
| 41 | - * @param string $path |
|
| 42 | - */ |
|
| 43 | - public function __construct(string $id, string $title, FilesystemReader $filesystem, string $path) |
|
| 44 | - { |
|
| 45 | - $this->id = $id; |
|
| 46 | - $this->title = $title; |
|
| 47 | - $this->filesystem = $filesystem; |
|
| 48 | - $this->path = $path; |
|
| 49 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor for SimpleFilesystemMap |
|
| 37 | + * |
|
| 38 | + * @param string $id |
|
| 39 | + * @param string $title |
|
| 40 | + * @param FilesystemReader $filesystem |
|
| 41 | + * @param string $path |
|
| 42 | + */ |
|
| 43 | + public function __construct(string $id, string $title, FilesystemReader $filesystem, string $path) |
|
| 44 | + { |
|
| 45 | + $this->id = $id; |
|
| 46 | + $this->title = $title; |
|
| 47 | + $this->filesystem = $filesystem; |
|
| 48 | + $this->path = $path; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * {@inheritDoc} |
|
| 53 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::id() |
|
| 54 | - */ |
|
| 55 | - public function id(): string |
|
| 56 | - { |
|
| 57 | - return $this->id; |
|
| 58 | - } |
|
| 51 | + /** |
|
| 52 | + * {@inheritDoc} |
|
| 53 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::id() |
|
| 54 | + */ |
|
| 55 | + public function id(): string |
|
| 56 | + { |
|
| 57 | + return $this->id; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * {@inheritDoc} |
|
| 62 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::title() |
|
| 63 | - */ |
|
| 64 | - public function title(): string |
|
| 65 | - { |
|
| 66 | - return $this->title; |
|
| 67 | - } |
|
| 60 | + /** |
|
| 61 | + * {@inheritDoc} |
|
| 62 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::title() |
|
| 63 | + */ |
|
| 64 | + public function title(): string |
|
| 65 | + { |
|
| 66 | + return $this->title; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * {@inheritDoc} |
|
| 71 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::features() |
|
| 72 | - */ |
|
| 73 | - public function features(): array |
|
| 74 | - { |
|
| 75 | - $reader = new GeoJSONReader(); |
|
| 76 | - try { |
|
| 77 | - $feature_collection = $reader->read($this->filesystem->read($this->path)); |
|
| 78 | - if ($feature_collection instanceof FeatureCollection) { |
|
| 79 | - return $feature_collection->getFeatures(); |
|
| 80 | - } |
|
| 81 | - } catch (Throwable $ex) { |
|
| 82 | - } |
|
| 83 | - return []; |
|
| 84 | - } |
|
| 69 | + /** |
|
| 70 | + * {@inheritDoc} |
|
| 71 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::features() |
|
| 72 | + */ |
|
| 73 | + public function features(): array |
|
| 74 | + { |
|
| 75 | + $reader = new GeoJSONReader(); |
|
| 76 | + try { |
|
| 77 | + $feature_collection = $reader->read($this->filesystem->read($this->path)); |
|
| 78 | + if ($feature_collection instanceof FeatureCollection) { |
|
| 79 | + return $feature_collection->getFeatures(); |
|
| 80 | + } |
|
| 81 | + } catch (Throwable $ex) { |
|
| 82 | + } |
|
| 83 | + return []; |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -25,104 +25,104 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class GenericPlaceMapperConfig implements PlaceMapperConfigInterface |
| 27 | 27 | { |
| 28 | - private array $config = []; |
|
| 28 | + private array $config = []; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Get the generic mapper's config |
|
| 32 | - * |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 35 | - public function config(): array |
|
| 36 | - { |
|
| 37 | - return $this->config; |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Get the generic mapper's config |
|
| 32 | + * |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | + public function config(): array |
|
| 36 | + { |
|
| 37 | + return $this->config; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Set the generic mapper's config |
|
| 42 | - * |
|
| 43 | - * @param array $config |
|
| 44 | - * @return $this |
|
| 45 | - */ |
|
| 46 | - public function setConfig(array $config): self |
|
| 47 | - { |
|
| 48 | - $this->config = $config; |
|
| 49 | - return $this; |
|
| 50 | - } |
|
| 40 | + /** |
|
| 41 | + * Set the generic mapper's config |
|
| 42 | + * |
|
| 43 | + * @param array $config |
|
| 44 | + * @return $this |
|
| 45 | + */ |
|
| 46 | + public function setConfig(array $config): self |
|
| 47 | + { |
|
| 48 | + $this->config = $config; |
|
| 49 | + return $this; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 55 | - */ |
|
| 56 | - public function get(string $key, $default = null) |
|
| 57 | - { |
|
| 58 | - return $this->config[$key] ?? $default; |
|
| 59 | - } |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 55 | + */ |
|
| 56 | + public function get(string $key, $default = null) |
|
| 57 | + { |
|
| 58 | + return $this->config[$key] ?? $default; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * {@inheritDoc} |
|
| 63 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 64 | - */ |
|
| 65 | - public function has(string $key): bool |
|
| 66 | - { |
|
| 67 | - return key_exists($key, $this->config); |
|
| 68 | - } |
|
| 61 | + /** |
|
| 62 | + * {@inheritDoc} |
|
| 63 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 64 | + */ |
|
| 65 | + public function has(string $key): bool |
|
| 66 | + { |
|
| 67 | + return key_exists($key, $this->config); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * {@inheritDoc} |
|
| 72 | - * @see \JsonSerializable::jsonSerialize() |
|
| 73 | - */ |
|
| 74 | - public function jsonSerialize() |
|
| 75 | - { |
|
| 76 | - return [ |
|
| 77 | - 'class' => get_class($this), |
|
| 78 | - 'config' => $this->jsonSerializeConfig() |
|
| 79 | - ]; |
|
| 80 | - } |
|
| 70 | + /** |
|
| 71 | + * {@inheritDoc} |
|
| 72 | + * @see \JsonSerializable::jsonSerialize() |
|
| 73 | + */ |
|
| 74 | + public function jsonSerialize() |
|
| 75 | + { |
|
| 76 | + return [ |
|
| 77 | + 'class' => get_class($this), |
|
| 78 | + 'config' => $this->jsonSerializeConfig() |
|
| 79 | + ]; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Returns a representation of the mapper config compatible with Json serialisation |
|
| 84 | - * |
|
| 85 | - * @return mixed |
|
| 86 | - */ |
|
| 87 | - public function jsonSerializeConfig() |
|
| 88 | - { |
|
| 89 | - return $this->config; |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * Returns a representation of the mapper config compatible with Json serialisation |
|
| 84 | + * |
|
| 85 | + * @return mixed |
|
| 86 | + */ |
|
| 87 | + public function jsonSerializeConfig() |
|
| 88 | + { |
|
| 89 | + return $this->config; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * {@inheritDoc} |
|
| 94 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 95 | - * |
|
| 96 | - * @param mixed $config |
|
| 97 | - * @return $this |
|
| 98 | - */ |
|
| 99 | - public function jsonDeserialize($config): self |
|
| 100 | - { |
|
| 101 | - if (is_string($config)) { |
|
| 102 | - return $this->jsonDeserialize(json_decode($config)); |
|
| 103 | - } |
|
| 104 | - if (is_array($config)) { |
|
| 105 | - return $this->setConfig($config); |
|
| 106 | - } |
|
| 107 | - return $this; |
|
| 108 | - } |
|
| 92 | + /** |
|
| 93 | + * {@inheritDoc} |
|
| 94 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 95 | + * |
|
| 96 | + * @param mixed $config |
|
| 97 | + * @return $this |
|
| 98 | + */ |
|
| 99 | + public function jsonDeserialize($config): self |
|
| 100 | + { |
|
| 101 | + if (is_string($config)) { |
|
| 102 | + return $this->jsonDeserialize(json_decode($config)); |
|
| 103 | + } |
|
| 104 | + if (is_array($config)) { |
|
| 105 | + return $this->setConfig($config); |
|
| 106 | + } |
|
| 107 | + return $this; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * {@inheritDoc} |
|
| 112 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 113 | - */ |
|
| 114 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 115 | - { |
|
| 116 | - return ''; |
|
| 117 | - } |
|
| 110 | + /** |
|
| 111 | + * {@inheritDoc} |
|
| 112 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 113 | + */ |
|
| 114 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 115 | + { |
|
| 116 | + return ''; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * {@inheritDoc} |
|
| 121 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 122 | - * @return $this |
|
| 123 | - */ |
|
| 124 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 125 | - { |
|
| 126 | - return $this; |
|
| 127 | - } |
|
| 119 | + /** |
|
| 120 | + * {@inheritDoc} |
|
| 121 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 122 | + * @return $this |
|
| 123 | + */ |
|
| 124 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 125 | + { |
|
| 126 | + return $this; |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -23,92 +23,92 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class MapColorsConfig implements JsonSerializable |
| 25 | 25 | { |
| 26 | - private Color $default; |
|
| 27 | - private Color $stroke; |
|
| 28 | - private Color $max_value; |
|
| 29 | - private Color $hover; |
|
| 26 | + private Color $default; |
|
| 27 | + private Color $stroke; |
|
| 28 | + private Color $max_value; |
|
| 29 | + private Color $hover; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Constructor for MapColorsConfig |
|
| 33 | - * |
|
| 34 | - * @param Color $default |
|
| 35 | - * @param Color $stroke |
|
| 36 | - * @param Color $max_value |
|
| 37 | - * @param Color $hover |
|
| 38 | - */ |
|
| 39 | - public function __construct( |
|
| 40 | - Color $default, |
|
| 41 | - Color $stroke, |
|
| 42 | - Color $max_value, |
|
| 43 | - Color $hover |
|
| 44 | - ) { |
|
| 45 | - $this->default = $default; |
|
| 46 | - $this->stroke = $stroke; |
|
| 47 | - $this->max_value = $max_value; |
|
| 48 | - $this->hover = $hover; |
|
| 49 | - } |
|
| 31 | + /** |
|
| 32 | + * Constructor for MapColorsConfig |
|
| 33 | + * |
|
| 34 | + * @param Color $default |
|
| 35 | + * @param Color $stroke |
|
| 36 | + * @param Color $max_value |
|
| 37 | + * @param Color $hover |
|
| 38 | + */ |
|
| 39 | + public function __construct( |
|
| 40 | + Color $default, |
|
| 41 | + Color $stroke, |
|
| 42 | + Color $max_value, |
|
| 43 | + Color $hover |
|
| 44 | + ) { |
|
| 45 | + $this->default = $default; |
|
| 46 | + $this->stroke = $stroke; |
|
| 47 | + $this->max_value = $max_value; |
|
| 48 | + $this->hover = $hover; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Get the default color for the features |
|
| 53 | - * |
|
| 54 | - * @return Color |
|
| 55 | - */ |
|
| 56 | - public function defaultColor(): Color |
|
| 57 | - { |
|
| 58 | - return $this->default; |
|
| 59 | - } |
|
| 51 | + /** |
|
| 52 | + * Get the default color for the features |
|
| 53 | + * |
|
| 54 | + * @return Color |
|
| 55 | + */ |
|
| 56 | + public function defaultColor(): Color |
|
| 57 | + { |
|
| 58 | + return $this->default; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get the color for the features' strokes |
|
| 63 | - * |
|
| 64 | - * @return Color |
|
| 65 | - */ |
|
| 66 | - public function strokeColor(): Color |
|
| 67 | - { |
|
| 68 | - return $this->stroke; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Get the color for the features' strokes |
|
| 63 | + * |
|
| 64 | + * @return Color |
|
| 65 | + */ |
|
| 66 | + public function strokeColor(): Color |
|
| 67 | + { |
|
| 68 | + return $this->stroke; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Get the color for the features with the lowest count |
|
| 73 | - * |
|
| 74 | - * @return Color |
|
| 75 | - */ |
|
| 76 | - public function minValueColor(): Color |
|
| 77 | - { |
|
| 78 | - return new Rgb(255, 255, 255); |
|
| 79 | - } |
|
| 71 | + /** |
|
| 72 | + * Get the color for the features with the lowest count |
|
| 73 | + * |
|
| 74 | + * @return Color |
|
| 75 | + */ |
|
| 76 | + public function minValueColor(): Color |
|
| 77 | + { |
|
| 78 | + return new Rgb(255, 255, 255); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Get the color for the features with the highest count |
|
| 83 | - * |
|
| 84 | - * @return Color |
|
| 85 | - */ |
|
| 86 | - public function maxValueColor(): Color |
|
| 87 | - { |
|
| 88 | - return $this->max_value; |
|
| 89 | - } |
|
| 81 | + /** |
|
| 82 | + * Get the color for the features with the highest count |
|
| 83 | + * |
|
| 84 | + * @return Color |
|
| 85 | + */ |
|
| 86 | + public function maxValueColor(): Color |
|
| 87 | + { |
|
| 88 | + return $this->max_value; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Get the color for feature hovering |
|
| 93 | - * |
|
| 94 | - * @return Color |
|
| 95 | - */ |
|
| 96 | - public function hoverColor(): Color |
|
| 97 | - { |
|
| 98 | - return $this->hover; |
|
| 99 | - } |
|
| 91 | + /** |
|
| 92 | + * Get the color for feature hovering |
|
| 93 | + * |
|
| 94 | + * @return Color |
|
| 95 | + */ |
|
| 96 | + public function hoverColor(): Color |
|
| 97 | + { |
|
| 98 | + return $this->hover; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * {@inheritDoc} |
|
| 103 | - * @see JsonSerializable::jsonSerialize() |
|
| 104 | - */ |
|
| 105 | - public function jsonSerialize() |
|
| 106 | - { |
|
| 107 | - return [ |
|
| 108 | - 'default' => (string) $this->defaultColor()->toHex(), |
|
| 109 | - 'stroke' => (string) $this->strokeColor()->toHex(), |
|
| 110 | - 'maxvalue' => (string) $this->maxValueColor()->toHex(), |
|
| 111 | - 'hover' => (string) $this->hoverColor()->toHex(), |
|
| 112 | - ]; |
|
| 113 | - } |
|
| 101 | + /** |
|
| 102 | + * {@inheritDoc} |
|
| 103 | + * @see JsonSerializable::jsonSerialize() |
|
| 104 | + */ |
|
| 105 | + public function jsonSerialize() |
|
| 106 | + { |
|
| 107 | + return [ |
|
| 108 | + 'default' => (string) $this->defaultColor()->toHex(), |
|
| 109 | + 'stroke' => (string) $this->strokeColor()->toHex(), |
|
| 110 | + 'maxvalue' => (string) $this->maxValueColor()->toHex(), |
|
| 111 | + 'hover' => (string) $this->hoverColor()->toHex(), |
|
| 112 | + ]; |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -26,61 +26,61 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class NullPlaceMapperConfig implements PlaceMapperConfigInterface |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * {@inheritDoc} |
|
| 31 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 32 | - */ |
|
| 33 | - public function get(string $key, $default = null) |
|
| 34 | - { |
|
| 35 | - return $default; |
|
| 36 | - } |
|
| 29 | + /** |
|
| 30 | + * {@inheritDoc} |
|
| 31 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 32 | + */ |
|
| 33 | + public function get(string $key, $default = null) |
|
| 34 | + { |
|
| 35 | + return $default; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * {@inheritDoc} |
|
| 40 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 41 | - */ |
|
| 42 | - public function has(string $key): bool |
|
| 43 | - { |
|
| 44 | - return false; |
|
| 45 | - } |
|
| 38 | + /** |
|
| 39 | + * {@inheritDoc} |
|
| 40 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 41 | + */ |
|
| 42 | + public function has(string $key): bool |
|
| 43 | + { |
|
| 44 | + return false; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * {@inheritDoc} |
|
| 49 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 50 | - * |
|
| 51 | - * @param mixed $config |
|
| 52 | - * @return $this |
|
| 53 | - */ |
|
| 54 | - public function jsonDeserialize($config): self |
|
| 55 | - { |
|
| 56 | - return $this; |
|
| 57 | - } |
|
| 47 | + /** |
|
| 48 | + * {@inheritDoc} |
|
| 49 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 50 | + * |
|
| 51 | + * @param mixed $config |
|
| 52 | + * @return $this |
|
| 53 | + */ |
|
| 54 | + public function jsonDeserialize($config): self |
|
| 55 | + { |
|
| 56 | + return $this; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * {@inheritDoc} |
|
| 61 | - * @see JsonSerializable::jsonSerialize() |
|
| 62 | - */ |
|
| 63 | - public function jsonSerialize() |
|
| 64 | - { |
|
| 65 | - return []; |
|
| 66 | - } |
|
| 59 | + /** |
|
| 60 | + * {@inheritDoc} |
|
| 61 | + * @see JsonSerializable::jsonSerialize() |
|
| 62 | + */ |
|
| 63 | + public function jsonSerialize() |
|
| 64 | + { |
|
| 65 | + return []; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * {@inheritDoc} |
|
| 70 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 71 | - */ |
|
| 72 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 73 | - { |
|
| 74 | - return ''; |
|
| 75 | - } |
|
| 68 | + /** |
|
| 69 | + * {@inheritDoc} |
|
| 70 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 71 | + */ |
|
| 72 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 73 | + { |
|
| 74 | + return ''; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * {@inheritDoc} |
|
| 79 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 80 | - * @return $this |
|
| 81 | - */ |
|
| 82 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 83 | - { |
|
| 84 | - return $this; |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * {@inheritDoc} |
|
| 79 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 80 | + * @return $this |
|
| 81 | + */ |
|
| 82 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 83 | + { |
|
| 84 | + return $this; |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -23,51 +23,51 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class MapViewConfig implements MapViewConfigInterface |
| 25 | 25 | { |
| 26 | - private string $map_mapping_property; |
|
| 27 | - private PlaceMapperConfigInterface $mapper_config; |
|
| 26 | + private string $map_mapping_property; |
|
| 27 | + private PlaceMapperConfigInterface $mapper_config; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Constructor for MapViewConfig |
|
| 31 | - * |
|
| 32 | - * @param string $map_mapping_property |
|
| 33 | - * @param PlaceMapperConfigInterface $mapper_config |
|
| 34 | - */ |
|
| 35 | - public function __construct( |
|
| 36 | - string $map_mapping_property, |
|
| 37 | - PlaceMapperConfigInterface $mapper_config = null |
|
| 38 | - ) { |
|
| 39 | - $this->map_mapping_property = $map_mapping_property; |
|
| 40 | - $this->mapper_config = $mapper_config ?? new NullPlaceMapperConfig(); |
|
| 41 | - } |
|
| 29 | + /** |
|
| 30 | + * Constructor for MapViewConfig |
|
| 31 | + * |
|
| 32 | + * @param string $map_mapping_property |
|
| 33 | + * @param PlaceMapperConfigInterface $mapper_config |
|
| 34 | + */ |
|
| 35 | + public function __construct( |
|
| 36 | + string $map_mapping_property, |
|
| 37 | + PlaceMapperConfigInterface $mapper_config = null |
|
| 38 | + ) { |
|
| 39 | + $this->map_mapping_property = $map_mapping_property; |
|
| 40 | + $this->mapper_config = $mapper_config ?? new NullPlaceMapperConfig(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * {@inheritDoc} |
|
| 45 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapMappingProperty() |
|
| 46 | - */ |
|
| 47 | - public function mapMappingProperty(): string |
|
| 48 | - { |
|
| 49 | - return $this->map_mapping_property; |
|
| 50 | - } |
|
| 43 | + /** |
|
| 44 | + * {@inheritDoc} |
|
| 45 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapMappingProperty() |
|
| 46 | + */ |
|
| 47 | + public function mapMappingProperty(): string |
|
| 48 | + { |
|
| 49 | + return $this->map_mapping_property; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapperConfig() |
|
| 55 | - */ |
|
| 56 | - public function mapperConfig(): PlaceMapperConfigInterface |
|
| 57 | - { |
|
| 58 | - return $this->mapper_config; |
|
| 59 | - } |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapperConfig() |
|
| 55 | + */ |
|
| 56 | + public function mapperConfig(): PlaceMapperConfigInterface |
|
| 57 | + { |
|
| 58 | + return $this->mapper_config; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * {@inheritDoc} |
|
| 63 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::with() |
|
| 64 | - * @return static |
|
| 65 | - */ |
|
| 66 | - public function with(string $mapping_property, PlaceMapperConfigInterface $mapper_config): self |
|
| 67 | - { |
|
| 68 | - $new = clone $this; |
|
| 69 | - $new->map_mapping_property = $mapping_property; |
|
| 70 | - $new->mapper_config = $mapper_config; |
|
| 71 | - return $new; |
|
| 72 | - } |
|
| 61 | + /** |
|
| 62 | + * {@inheritDoc} |
|
| 63 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::with() |
|
| 64 | + * @return static |
|
| 65 | + */ |
|
| 66 | + public function with(string $mapping_property, PlaceMapperConfigInterface $mapper_config): self |
|
| 67 | + { |
|
| 68 | + $new = clone $this; |
|
| 69 | + $new->map_mapping_property = $mapping_property; |
|
| 70 | + $new->mapper_config = $mapper_config; |
|
| 71 | + return $new; |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -25,290 +25,290 @@ |
||
| 25 | 25 | class TaskSchedule |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Task Schedule ID |
|
| 30 | - * @var int $id |
|
| 31 | - */ |
|
| 32 | - private $id; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Task schedule status |
|
| 36 | - * @var bool $enabled |
|
| 37 | - */ |
|
| 38 | - private $enabled; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * ID of the task attached to schedule |
|
| 42 | - * @var string $task_id |
|
| 43 | - */ |
|
| 44 | - private $task_id; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Last updated date |
|
| 48 | - * @var Carbon $last_run |
|
| 49 | - */ |
|
| 50 | - private $last_run; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Last run result |
|
| 54 | - * @var bool $last_result |
|
| 55 | - */ |
|
| 56 | - private $last_result; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Task run frequency |
|
| 60 | - * @var CarbonInterval $frequency |
|
| 61 | - */ |
|
| 62 | - private $frequency; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Task remaining runs |
|
| 66 | - * @var int $nb_occurrences |
|
| 67 | - */ |
|
| 68 | - private $nb_occurrences; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Current running status of the task |
|
| 72 | - * @var bool $is_running |
|
| 73 | - */ |
|
| 74 | - private $is_running; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Constructor for TaskSchedule |
|
| 78 | - * |
|
| 79 | - * @param int $id Schedule ID |
|
| 80 | - * @param string $task_id Task ID |
|
| 81 | - * @param bool $enabled Is the schedule enabled |
|
| 82 | - * @param Carbon $last_run Last successful run date/time |
|
| 83 | - * @param bool $last_result Result of the last run |
|
| 84 | - * @param CarbonInterval $frequency Schedule frequency |
|
| 85 | - * @param int $nb_occurrences Number of remaining occurrences to be run |
|
| 86 | - * @param bool $is_running Is the task currently running |
|
| 87 | - */ |
|
| 88 | - public function __construct( |
|
| 89 | - int $id, |
|
| 90 | - string $task_id, |
|
| 91 | - bool $enabled, |
|
| 92 | - Carbon $last_run, |
|
| 93 | - bool $last_result, |
|
| 94 | - CarbonInterval $frequency, |
|
| 95 | - int $nb_occurrences, |
|
| 96 | - bool $is_running |
|
| 97 | - ) { |
|
| 98 | - $this->id = $id; |
|
| 99 | - $this->task_id = $task_id; |
|
| 100 | - $this->enabled = $enabled; |
|
| 101 | - $this->last_run = $last_run; |
|
| 102 | - $this->last_result = $last_result; |
|
| 103 | - $this->frequency = $frequency; |
|
| 104 | - $this->nb_occurrences = $nb_occurrences; |
|
| 105 | - $this->is_running = $is_running; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Get the schedule ID. |
|
| 110 | - * |
|
| 111 | - * @return int |
|
| 112 | - */ |
|
| 113 | - public function id(): int |
|
| 114 | - { |
|
| 115 | - return $this->id; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Get the task ID. |
|
| 120 | - * |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function taskId(): string |
|
| 124 | - { |
|
| 125 | - return $this->task_id; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Returns whether the schedule is enabled |
|
| 130 | - * |
|
| 131 | - * @return bool |
|
| 132 | - */ |
|
| 133 | - public function isEnabled(): bool |
|
| 134 | - { |
|
| 135 | - return $this->enabled; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Enable the schedule |
|
| 140 | - * |
|
| 141 | - * @return $this |
|
| 142 | - */ |
|
| 143 | - public function enable(): self |
|
| 144 | - { |
|
| 145 | - $this->enabled = true; |
|
| 146 | - return $this; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Disable the schedule |
|
| 151 | - * |
|
| 152 | - * @return $this |
|
| 153 | - */ |
|
| 154 | - public function disable(): self |
|
| 155 | - { |
|
| 156 | - $this->enabled = false; |
|
| 157 | - return $this; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Get the frequency of the schedule |
|
| 162 | - * |
|
| 163 | - * @return CarbonInterval |
|
| 164 | - */ |
|
| 165 | - public function frequency(): CarbonInterval |
|
| 166 | - { |
|
| 167 | - return $this->frequency; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Set the frequency of the schedule |
|
| 172 | - * |
|
| 173 | - * @param CarbonInterval $frequency |
|
| 174 | - * @return $this |
|
| 175 | - */ |
|
| 176 | - public function setFrequency(CarbonInterval $frequency): self |
|
| 177 | - { |
|
| 178 | - $this->frequency = $frequency; |
|
| 179 | - return $this; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Get the date/time of the last successful run. |
|
| 184 | - * |
|
| 185 | - * @return Carbon |
|
| 186 | - */ |
|
| 187 | - public function lastRunTime(): Carbon |
|
| 188 | - { |
|
| 189 | - return $this->last_run; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Set the last successful run date/time |
|
| 194 | - * |
|
| 195 | - * @param Carbon $last_run |
|
| 196 | - * @return $this |
|
| 197 | - */ |
|
| 198 | - public function setLastRunTime(Carbon $last_run): self |
|
| 199 | - { |
|
| 200 | - $this->last_run = $last_run; |
|
| 201 | - return $this; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns whether the last run was successful |
|
| 206 | - * |
|
| 207 | - * @return bool |
|
| 208 | - */ |
|
| 209 | - public function wasLastRunSuccess(): bool |
|
| 210 | - { |
|
| 211 | - return $this->last_result; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Set the last run result |
|
| 216 | - * |
|
| 217 | - * @param bool $last_result |
|
| 218 | - * @return $this |
|
| 219 | - */ |
|
| 220 | - public function setLastResult(bool $last_result): self |
|
| 221 | - { |
|
| 222 | - $this->last_result = $last_result; |
|
| 223 | - return $this; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Get the number of remaining of occurrences of task runs. |
|
| 228 | - * Returns 0 if the tasks must be run indefinitely. |
|
| 229 | - * |
|
| 230 | - * @return int |
|
| 231 | - */ |
|
| 232 | - public function remainingOccurences(): int |
|
| 233 | - { |
|
| 234 | - return $this->nb_occurrences; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Decrements the number of remaining occurences by 1. |
|
| 239 | - * The task will be disabled when the number reaches 0. |
|
| 240 | - * |
|
| 241 | - * @return $this |
|
| 242 | - */ |
|
| 243 | - public function decrementRemainingOccurences(): self |
|
| 244 | - { |
|
| 245 | - if ($this->nb_occurrences > 0) { |
|
| 246 | - $this->nb_occurrences--; |
|
| 247 | - if ($this->nb_occurrences == 0) { |
|
| 248 | - $this->disable(); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - return $this; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Set the number of remaining occurences of task runs. |
|
| 256 | - * |
|
| 257 | - * @param int $nb_occurrences |
|
| 258 | - * @return $this |
|
| 259 | - */ |
|
| 260 | - public function setRemainingOccurences(int $nb_occurrences): self |
|
| 261 | - { |
|
| 262 | - $this->nb_occurrences = $nb_occurrences; |
|
| 263 | - return $this; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Returns whether the task is running |
|
| 268 | - * @return bool |
|
| 269 | - */ |
|
| 270 | - public function isRunning(): bool |
|
| 271 | - { |
|
| 272 | - return $this->is_running; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Informs the schedule that the task is going to run |
|
| 277 | - * |
|
| 278 | - * @return $this |
|
| 279 | - */ |
|
| 280 | - public function startRunning(): self |
|
| 281 | - { |
|
| 282 | - $this->is_running = true; |
|
| 283 | - return $this; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Informs the schedule that the task has stopped running. |
|
| 288 | - * @return $this |
|
| 289 | - */ |
|
| 290 | - public function stopRunning(): self |
|
| 291 | - { |
|
| 292 | - $this->is_running = false; |
|
| 293 | - return $this; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Returns the schedule details as an associate array |
|
| 298 | - * |
|
| 299 | - * @return array |
|
| 300 | - */ |
|
| 301 | - public function toArray(): array |
|
| 302 | - { |
|
| 303 | - return [ |
|
| 304 | - 'id' => $this->id, |
|
| 305 | - 'task_id' => $this->task_id, |
|
| 306 | - 'enabled' => $this->enabled, |
|
| 307 | - 'last_run' => $this->last_run, |
|
| 308 | - 'last_result' => $this->last_result, |
|
| 309 | - 'frequency' => $this->frequency, |
|
| 310 | - 'nb_occurrences' => $this->nb_occurrences, |
|
| 311 | - 'is_running' => $this->is_running |
|
| 312 | - ]; |
|
| 313 | - } |
|
| 28 | + /** |
|
| 29 | + * Task Schedule ID |
|
| 30 | + * @var int $id |
|
| 31 | + */ |
|
| 32 | + private $id; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Task schedule status |
|
| 36 | + * @var bool $enabled |
|
| 37 | + */ |
|
| 38 | + private $enabled; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * ID of the task attached to schedule |
|
| 42 | + * @var string $task_id |
|
| 43 | + */ |
|
| 44 | + private $task_id; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Last updated date |
|
| 48 | + * @var Carbon $last_run |
|
| 49 | + */ |
|
| 50 | + private $last_run; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Last run result |
|
| 54 | + * @var bool $last_result |
|
| 55 | + */ |
|
| 56 | + private $last_result; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Task run frequency |
|
| 60 | + * @var CarbonInterval $frequency |
|
| 61 | + */ |
|
| 62 | + private $frequency; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Task remaining runs |
|
| 66 | + * @var int $nb_occurrences |
|
| 67 | + */ |
|
| 68 | + private $nb_occurrences; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Current running status of the task |
|
| 72 | + * @var bool $is_running |
|
| 73 | + */ |
|
| 74 | + private $is_running; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Constructor for TaskSchedule |
|
| 78 | + * |
|
| 79 | + * @param int $id Schedule ID |
|
| 80 | + * @param string $task_id Task ID |
|
| 81 | + * @param bool $enabled Is the schedule enabled |
|
| 82 | + * @param Carbon $last_run Last successful run date/time |
|
| 83 | + * @param bool $last_result Result of the last run |
|
| 84 | + * @param CarbonInterval $frequency Schedule frequency |
|
| 85 | + * @param int $nb_occurrences Number of remaining occurrences to be run |
|
| 86 | + * @param bool $is_running Is the task currently running |
|
| 87 | + */ |
|
| 88 | + public function __construct( |
|
| 89 | + int $id, |
|
| 90 | + string $task_id, |
|
| 91 | + bool $enabled, |
|
| 92 | + Carbon $last_run, |
|
| 93 | + bool $last_result, |
|
| 94 | + CarbonInterval $frequency, |
|
| 95 | + int $nb_occurrences, |
|
| 96 | + bool $is_running |
|
| 97 | + ) { |
|
| 98 | + $this->id = $id; |
|
| 99 | + $this->task_id = $task_id; |
|
| 100 | + $this->enabled = $enabled; |
|
| 101 | + $this->last_run = $last_run; |
|
| 102 | + $this->last_result = $last_result; |
|
| 103 | + $this->frequency = $frequency; |
|
| 104 | + $this->nb_occurrences = $nb_occurrences; |
|
| 105 | + $this->is_running = $is_running; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Get the schedule ID. |
|
| 110 | + * |
|
| 111 | + * @return int |
|
| 112 | + */ |
|
| 113 | + public function id(): int |
|
| 114 | + { |
|
| 115 | + return $this->id; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Get the task ID. |
|
| 120 | + * |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function taskId(): string |
|
| 124 | + { |
|
| 125 | + return $this->task_id; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Returns whether the schedule is enabled |
|
| 130 | + * |
|
| 131 | + * @return bool |
|
| 132 | + */ |
|
| 133 | + public function isEnabled(): bool |
|
| 134 | + { |
|
| 135 | + return $this->enabled; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Enable the schedule |
|
| 140 | + * |
|
| 141 | + * @return $this |
|
| 142 | + */ |
|
| 143 | + public function enable(): self |
|
| 144 | + { |
|
| 145 | + $this->enabled = true; |
|
| 146 | + return $this; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Disable the schedule |
|
| 151 | + * |
|
| 152 | + * @return $this |
|
| 153 | + */ |
|
| 154 | + public function disable(): self |
|
| 155 | + { |
|
| 156 | + $this->enabled = false; |
|
| 157 | + return $this; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Get the frequency of the schedule |
|
| 162 | + * |
|
| 163 | + * @return CarbonInterval |
|
| 164 | + */ |
|
| 165 | + public function frequency(): CarbonInterval |
|
| 166 | + { |
|
| 167 | + return $this->frequency; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Set the frequency of the schedule |
|
| 172 | + * |
|
| 173 | + * @param CarbonInterval $frequency |
|
| 174 | + * @return $this |
|
| 175 | + */ |
|
| 176 | + public function setFrequency(CarbonInterval $frequency): self |
|
| 177 | + { |
|
| 178 | + $this->frequency = $frequency; |
|
| 179 | + return $this; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Get the date/time of the last successful run. |
|
| 184 | + * |
|
| 185 | + * @return Carbon |
|
| 186 | + */ |
|
| 187 | + public function lastRunTime(): Carbon |
|
| 188 | + { |
|
| 189 | + return $this->last_run; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Set the last successful run date/time |
|
| 194 | + * |
|
| 195 | + * @param Carbon $last_run |
|
| 196 | + * @return $this |
|
| 197 | + */ |
|
| 198 | + public function setLastRunTime(Carbon $last_run): self |
|
| 199 | + { |
|
| 200 | + $this->last_run = $last_run; |
|
| 201 | + return $this; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns whether the last run was successful |
|
| 206 | + * |
|
| 207 | + * @return bool |
|
| 208 | + */ |
|
| 209 | + public function wasLastRunSuccess(): bool |
|
| 210 | + { |
|
| 211 | + return $this->last_result; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Set the last run result |
|
| 216 | + * |
|
| 217 | + * @param bool $last_result |
|
| 218 | + * @return $this |
|
| 219 | + */ |
|
| 220 | + public function setLastResult(bool $last_result): self |
|
| 221 | + { |
|
| 222 | + $this->last_result = $last_result; |
|
| 223 | + return $this; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Get the number of remaining of occurrences of task runs. |
|
| 228 | + * Returns 0 if the tasks must be run indefinitely. |
|
| 229 | + * |
|
| 230 | + * @return int |
|
| 231 | + */ |
|
| 232 | + public function remainingOccurences(): int |
|
| 233 | + { |
|
| 234 | + return $this->nb_occurrences; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Decrements the number of remaining occurences by 1. |
|
| 239 | + * The task will be disabled when the number reaches 0. |
|
| 240 | + * |
|
| 241 | + * @return $this |
|
| 242 | + */ |
|
| 243 | + public function decrementRemainingOccurences(): self |
|
| 244 | + { |
|
| 245 | + if ($this->nb_occurrences > 0) { |
|
| 246 | + $this->nb_occurrences--; |
|
| 247 | + if ($this->nb_occurrences == 0) { |
|
| 248 | + $this->disable(); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + return $this; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Set the number of remaining occurences of task runs. |
|
| 256 | + * |
|
| 257 | + * @param int $nb_occurrences |
|
| 258 | + * @return $this |
|
| 259 | + */ |
|
| 260 | + public function setRemainingOccurences(int $nb_occurrences): self |
|
| 261 | + { |
|
| 262 | + $this->nb_occurrences = $nb_occurrences; |
|
| 263 | + return $this; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Returns whether the task is running |
|
| 268 | + * @return bool |
|
| 269 | + */ |
|
| 270 | + public function isRunning(): bool |
|
| 271 | + { |
|
| 272 | + return $this->is_running; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Informs the schedule that the task is going to run |
|
| 277 | + * |
|
| 278 | + * @return $this |
|
| 279 | + */ |
|
| 280 | + public function startRunning(): self |
|
| 281 | + { |
|
| 282 | + $this->is_running = true; |
|
| 283 | + return $this; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Informs the schedule that the task has stopped running. |
|
| 288 | + * @return $this |
|
| 289 | + */ |
|
| 290 | + public function stopRunning(): self |
|
| 291 | + { |
|
| 292 | + $this->is_running = false; |
|
| 293 | + return $this; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Returns the schedule details as an associate array |
|
| 298 | + * |
|
| 299 | + * @return array |
|
| 300 | + */ |
|
| 301 | + public function toArray(): array |
|
| 302 | + { |
|
| 303 | + return [ |
|
| 304 | + 'id' => $this->id, |
|
| 305 | + 'task_id' => $this->task_id, |
|
| 306 | + 'enabled' => $this->enabled, |
|
| 307 | + 'last_run' => $this->last_run, |
|
| 308 | + 'last_result' => $this->last_result, |
|
| 309 | + 'frequency' => $this->frequency, |
|
| 310 | + 'nb_occurrences' => $this->nb_occurrences, |
|
| 311 | + 'is_running' => $this->is_running |
|
| 312 | + ]; |
|
| 313 | + } |
|
| 314 | 314 | } |