@@ -31,40 +31,40 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class AuthTreePreference implements MiddlewareInterface |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * {@inheritDoc} |
|
| 36 | - * @see \Psr\Http\Server\MiddlewareInterface::process() |
|
| 37 | - */ |
|
| 38 | - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 39 | - { |
|
| 40 | - $tree = Validator::attributes($request)->tree(); |
|
| 41 | - $route = Validator::attributes($request)->route(); |
|
| 42 | - $user = Validator::attributes($request)->user(); |
|
| 34 | + /** |
|
| 35 | + * {@inheritDoc} |
|
| 36 | + * @see \Psr\Http\Server\MiddlewareInterface::process() |
|
| 37 | + */ |
|
| 38 | + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 39 | + { |
|
| 40 | + $tree = Validator::attributes($request)->tree(); |
|
| 41 | + $route = Validator::attributes($request)->route(); |
|
| 42 | + $user = Validator::attributes($request)->user(); |
|
| 43 | 43 | |
| 44 | - $permission_preference = $route->extras['permission_preference'] ?? ''; |
|
| 45 | - $permission_level = $permission_preference === '' ? '' : $tree->getPreference($permission_preference); |
|
| 44 | + $permission_preference = $route->extras['permission_preference'] ?? ''; |
|
| 45 | + $permission_level = $permission_preference === '' ? '' : $tree->getPreference($permission_preference); |
|
| 46 | 46 | |
| 47 | - // Permissions are configured |
|
| 48 | - if (is_numeric($permission_level)) { |
|
| 49 | - // Logged in with the correct role? |
|
| 50 | - if (Auth::accessLevel($tree, $user) <= (int) $permission_level) { |
|
| 51 | - return $handler->handle($request); |
|
| 52 | - } |
|
| 47 | + // Permissions are configured |
|
| 48 | + if (is_numeric($permission_level)) { |
|
| 49 | + // Logged in with the correct role? |
|
| 50 | + if (Auth::accessLevel($tree, $user) <= (int) $permission_level) { |
|
| 51 | + return $handler->handle($request); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - // Logged in, but without the correct role? |
|
| 55 | - if ($user instanceof User) { |
|
| 56 | - throw new HttpAccessDeniedException(); |
|
| 57 | - } |
|
| 58 | - } |
|
| 54 | + // Logged in, but without the correct role? |
|
| 55 | + if ($user instanceof User) { |
|
| 56 | + throw new HttpAccessDeniedException(); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - // Permissions no configured, or not logged in |
|
| 61 | - if ($request->getMethod() === RequestMethodInterface::METHOD_POST) { |
|
| 62 | - throw new HttpAccessDeniedException(); |
|
| 63 | - } |
|
| 60 | + // Permissions no configured, or not logged in |
|
| 61 | + if ($request->getMethod() === RequestMethodInterface::METHOD_POST) { |
|
| 62 | + throw new HttpAccessDeniedException(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return Registry::responseFactory()->redirect( |
|
| 66 | - LoginPage::class, |
|
| 67 | - ['tree' => $tree->name(), 'url' => (string) $request->getUri()] |
|
| 68 | - ); |
|
| 69 | - } |
|
| 65 | + return Registry::responseFactory()->redirect( |
|
| 66 | + LoginPage::class, |
|
| 67 | + ['tree' => $tree->name(), 'url' => (string) $request->getUri()] |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | // Permissions are configured |
| 48 | 48 | if (is_numeric($permission_level)) { |
| 49 | 49 | // Logged in with the correct role? |
| 50 | - if (Auth::accessLevel($tree, $user) <= (int) $permission_level) { |
|
| 50 | + if (Auth::accessLevel($tree, $user) <= (int)$permission_level) { |
|
| 51 | 51 | return $handler->handle($request); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | return Registry::responseFactory()->redirect( |
| 66 | 66 | LoginPage::class, |
| 67 | - ['tree' => $tree->name(), 'url' => (string) $request->getUri()] |
|
| 67 | + ['tree' => $tree->name(), 'url' => (string)$request->getUri()] |
|
| 68 | 68 | ); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -23,252 +23,252 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class TaskSchedule |
| 25 | 25 | { |
| 26 | - private int $id; |
|
| 27 | - private bool $enabled; |
|
| 28 | - private string $task_id; |
|
| 29 | - private CarbonInterface $last_run; |
|
| 30 | - private bool $last_result; |
|
| 31 | - private int $frequency; |
|
| 32 | - private int $nb_occurrences; |
|
| 33 | - private bool $is_running; |
|
| 26 | + private int $id; |
|
| 27 | + private bool $enabled; |
|
| 28 | + private string $task_id; |
|
| 29 | + private CarbonInterface $last_run; |
|
| 30 | + private bool $last_result; |
|
| 31 | + private int $frequency; |
|
| 32 | + private int $nb_occurrences; |
|
| 33 | + private bool $is_running; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor for TaskSchedule |
|
| 37 | - * |
|
| 38 | - * @param int $id Schedule ID |
|
| 39 | - * @param string $task_id Task ID |
|
| 40 | - * @param bool $enabled Is the schedule enabled |
|
| 41 | - * @param CarbonInterface $last_run Last successful run date/time |
|
| 42 | - * @param bool $last_result Result of the last run |
|
| 43 | - * @param int $frequency Schedule frequency in minutes |
|
| 44 | - * @param int $nb_occurrences Number of remaining occurrences to be run |
|
| 45 | - * @param bool $is_running Is the task currently running |
|
| 46 | - */ |
|
| 47 | - public function __construct( |
|
| 48 | - int $id, |
|
| 49 | - string $task_id, |
|
| 50 | - bool $enabled, |
|
| 51 | - CarbonInterface $last_run, |
|
| 52 | - bool $last_result, |
|
| 53 | - int $frequency, |
|
| 54 | - int $nb_occurrences, |
|
| 55 | - bool $is_running |
|
| 56 | - ) { |
|
| 57 | - $this->id = $id; |
|
| 58 | - $this->task_id = $task_id; |
|
| 59 | - $this->enabled = $enabled; |
|
| 60 | - $this->last_run = $last_run; |
|
| 61 | - $this->last_result = $last_result; |
|
| 62 | - $this->frequency = $frequency; |
|
| 63 | - $this->nb_occurrences = $nb_occurrences; |
|
| 64 | - $this->is_running = $is_running; |
|
| 65 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor for TaskSchedule |
|
| 37 | + * |
|
| 38 | + * @param int $id Schedule ID |
|
| 39 | + * @param string $task_id Task ID |
|
| 40 | + * @param bool $enabled Is the schedule enabled |
|
| 41 | + * @param CarbonInterface $last_run Last successful run date/time |
|
| 42 | + * @param bool $last_result Result of the last run |
|
| 43 | + * @param int $frequency Schedule frequency in minutes |
|
| 44 | + * @param int $nb_occurrences Number of remaining occurrences to be run |
|
| 45 | + * @param bool $is_running Is the task currently running |
|
| 46 | + */ |
|
| 47 | + public function __construct( |
|
| 48 | + int $id, |
|
| 49 | + string $task_id, |
|
| 50 | + bool $enabled, |
|
| 51 | + CarbonInterface $last_run, |
|
| 52 | + bool $last_result, |
|
| 53 | + int $frequency, |
|
| 54 | + int $nb_occurrences, |
|
| 55 | + bool $is_running |
|
| 56 | + ) { |
|
| 57 | + $this->id = $id; |
|
| 58 | + $this->task_id = $task_id; |
|
| 59 | + $this->enabled = $enabled; |
|
| 60 | + $this->last_run = $last_run; |
|
| 61 | + $this->last_result = $last_result; |
|
| 62 | + $this->frequency = $frequency; |
|
| 63 | + $this->nb_occurrences = $nb_occurrences; |
|
| 64 | + $this->is_running = $is_running; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Get the schedule ID. |
|
| 69 | - * |
|
| 70 | - * @return int |
|
| 71 | - */ |
|
| 72 | - public function id(): int |
|
| 73 | - { |
|
| 74 | - return $this->id; |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * Get the schedule ID. |
|
| 69 | + * |
|
| 70 | + * @return int |
|
| 71 | + */ |
|
| 72 | + public function id(): int |
|
| 73 | + { |
|
| 74 | + return $this->id; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Get the task ID. |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function taskId(): string |
|
| 83 | - { |
|
| 84 | - return $this->task_id; |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * Get the task ID. |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function taskId(): string |
|
| 83 | + { |
|
| 84 | + return $this->task_id; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Returns whether the schedule is enabled |
|
| 89 | - * |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function isEnabled(): bool |
|
| 93 | - { |
|
| 94 | - return $this->enabled; |
|
| 95 | - } |
|
| 87 | + /** |
|
| 88 | + * Returns whether the schedule is enabled |
|
| 89 | + * |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function isEnabled(): bool |
|
| 93 | + { |
|
| 94 | + return $this->enabled; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Enable the schedule |
|
| 99 | - * |
|
| 100 | - * @return $this |
|
| 101 | - */ |
|
| 102 | - public function enable(): self |
|
| 103 | - { |
|
| 104 | - $this->enabled = true; |
|
| 105 | - return $this; |
|
| 106 | - } |
|
| 97 | + /** |
|
| 98 | + * Enable the schedule |
|
| 99 | + * |
|
| 100 | + * @return $this |
|
| 101 | + */ |
|
| 102 | + public function enable(): self |
|
| 103 | + { |
|
| 104 | + $this->enabled = true; |
|
| 105 | + return $this; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Disable the schedule |
|
| 110 | - * |
|
| 111 | - * @return $this |
|
| 112 | - */ |
|
| 113 | - public function disable(): self |
|
| 114 | - { |
|
| 115 | - $this->enabled = false; |
|
| 116 | - return $this; |
|
| 117 | - } |
|
| 108 | + /** |
|
| 109 | + * Disable the schedule |
|
| 110 | + * |
|
| 111 | + * @return $this |
|
| 112 | + */ |
|
| 113 | + public function disable(): self |
|
| 114 | + { |
|
| 115 | + $this->enabled = false; |
|
| 116 | + return $this; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Get the frequency of the schedule |
|
| 121 | - * |
|
| 122 | - * @return int |
|
| 123 | - */ |
|
| 124 | - public function frequency(): int |
|
| 125 | - { |
|
| 126 | - return $this->frequency; |
|
| 127 | - } |
|
| 119 | + /** |
|
| 120 | + * Get the frequency of the schedule |
|
| 121 | + * |
|
| 122 | + * @return int |
|
| 123 | + */ |
|
| 124 | + public function frequency(): int |
|
| 125 | + { |
|
| 126 | + return $this->frequency; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Set the frequency of the schedule |
|
| 131 | - * |
|
| 132 | - * @param int $frequency |
|
| 133 | - * @return $this |
|
| 134 | - */ |
|
| 135 | - public function setFrequency(int $frequency): self |
|
| 136 | - { |
|
| 137 | - $this->frequency = $frequency; |
|
| 138 | - return $this; |
|
| 139 | - } |
|
| 129 | + /** |
|
| 130 | + * Set the frequency of the schedule |
|
| 131 | + * |
|
| 132 | + * @param int $frequency |
|
| 133 | + * @return $this |
|
| 134 | + */ |
|
| 135 | + public function setFrequency(int $frequency): self |
|
| 136 | + { |
|
| 137 | + $this->frequency = $frequency; |
|
| 138 | + return $this; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Get the date/time of the last successful run. |
|
| 143 | - * |
|
| 144 | - * @return CarbonInterface |
|
| 145 | - */ |
|
| 146 | - public function lastRunTime(): CarbonInterface |
|
| 147 | - { |
|
| 148 | - return $this->last_run; |
|
| 149 | - } |
|
| 141 | + /** |
|
| 142 | + * Get the date/time of the last successful run. |
|
| 143 | + * |
|
| 144 | + * @return CarbonInterface |
|
| 145 | + */ |
|
| 146 | + public function lastRunTime(): CarbonInterface |
|
| 147 | + { |
|
| 148 | + return $this->last_run; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Set the last successful run date/time |
|
| 153 | - * |
|
| 154 | - * @param CarbonInterface $last_run |
|
| 155 | - * @return $this |
|
| 156 | - */ |
|
| 157 | - public function setLastRunTime(CarbonInterface $last_run): self |
|
| 158 | - { |
|
| 159 | - $this->last_run = $last_run; |
|
| 160 | - return $this; |
|
| 161 | - } |
|
| 151 | + /** |
|
| 152 | + * Set the last successful run date/time |
|
| 153 | + * |
|
| 154 | + * @param CarbonInterface $last_run |
|
| 155 | + * @return $this |
|
| 156 | + */ |
|
| 157 | + public function setLastRunTime(CarbonInterface $last_run): self |
|
| 158 | + { |
|
| 159 | + $this->last_run = $last_run; |
|
| 160 | + return $this; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * Returns whether the last run was successful |
|
| 165 | - * |
|
| 166 | - * @return bool |
|
| 167 | - */ |
|
| 168 | - public function wasLastRunSuccess(): bool |
|
| 169 | - { |
|
| 170 | - return $this->last_result; |
|
| 171 | - } |
|
| 163 | + /** |
|
| 164 | + * Returns whether the last run was successful |
|
| 165 | + * |
|
| 166 | + * @return bool |
|
| 167 | + */ |
|
| 168 | + public function wasLastRunSuccess(): bool |
|
| 169 | + { |
|
| 170 | + return $this->last_result; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * Set the last run result |
|
| 175 | - * |
|
| 176 | - * @param bool $last_result |
|
| 177 | - * @return $this |
|
| 178 | - */ |
|
| 179 | - public function setLastResult(bool $last_result): self |
|
| 180 | - { |
|
| 181 | - $this->last_result = $last_result; |
|
| 182 | - return $this; |
|
| 183 | - } |
|
| 173 | + /** |
|
| 174 | + * Set the last run result |
|
| 175 | + * |
|
| 176 | + * @param bool $last_result |
|
| 177 | + * @return $this |
|
| 178 | + */ |
|
| 179 | + public function setLastResult(bool $last_result): self |
|
| 180 | + { |
|
| 181 | + $this->last_result = $last_result; |
|
| 182 | + return $this; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * Get the number of remaining of occurrences of task runs. |
|
| 187 | - * Returns 0 if the tasks must be run indefinitely. |
|
| 188 | - * |
|
| 189 | - * @return int |
|
| 190 | - */ |
|
| 191 | - public function remainingOccurrences(): int |
|
| 192 | - { |
|
| 193 | - return $this->nb_occurrences; |
|
| 194 | - } |
|
| 185 | + /** |
|
| 186 | + * Get the number of remaining of occurrences of task runs. |
|
| 187 | + * Returns 0 if the tasks must be run indefinitely. |
|
| 188 | + * |
|
| 189 | + * @return int |
|
| 190 | + */ |
|
| 191 | + public function remainingOccurrences(): int |
|
| 192 | + { |
|
| 193 | + return $this->nb_occurrences; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Decrements the number of remaining occurrences by 1. |
|
| 198 | - * The task will be disabled when the number reaches 0. |
|
| 199 | - * |
|
| 200 | - * @return $this |
|
| 201 | - */ |
|
| 202 | - public function decrementRemainingOccurrences(): self |
|
| 203 | - { |
|
| 204 | - if ($this->nb_occurrences > 0) { |
|
| 205 | - $this->nb_occurrences--; |
|
| 206 | - if ($this->nb_occurrences === 0) { |
|
| 207 | - $this->disable(); |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - return $this; |
|
| 211 | - } |
|
| 196 | + /** |
|
| 197 | + * Decrements the number of remaining occurrences by 1. |
|
| 198 | + * The task will be disabled when the number reaches 0. |
|
| 199 | + * |
|
| 200 | + * @return $this |
|
| 201 | + */ |
|
| 202 | + public function decrementRemainingOccurrences(): self |
|
| 203 | + { |
|
| 204 | + if ($this->nb_occurrences > 0) { |
|
| 205 | + $this->nb_occurrences--; |
|
| 206 | + if ($this->nb_occurrences === 0) { |
|
| 207 | + $this->disable(); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + return $this; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Set the number of remaining occurrences of task runs. |
|
| 215 | - * |
|
| 216 | - * @param int $nb_occurrences |
|
| 217 | - * @return $this |
|
| 218 | - */ |
|
| 219 | - public function setRemainingOccurrences(int $nb_occurrences): self |
|
| 220 | - { |
|
| 221 | - $this->nb_occurrences = $nb_occurrences; |
|
| 222 | - return $this; |
|
| 223 | - } |
|
| 213 | + /** |
|
| 214 | + * Set the number of remaining occurrences of task runs. |
|
| 215 | + * |
|
| 216 | + * @param int $nb_occurrences |
|
| 217 | + * @return $this |
|
| 218 | + */ |
|
| 219 | + public function setRemainingOccurrences(int $nb_occurrences): self |
|
| 220 | + { |
|
| 221 | + $this->nb_occurrences = $nb_occurrences; |
|
| 222 | + return $this; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Returns whether the task is running |
|
| 227 | - * @return bool |
|
| 228 | - */ |
|
| 229 | - public function isRunning(): bool |
|
| 230 | - { |
|
| 231 | - return $this->is_running; |
|
| 232 | - } |
|
| 225 | + /** |
|
| 226 | + * Returns whether the task is running |
|
| 227 | + * @return bool |
|
| 228 | + */ |
|
| 229 | + public function isRunning(): bool |
|
| 230 | + { |
|
| 231 | + return $this->is_running; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Informs the schedule that the task is going to run |
|
| 236 | - * |
|
| 237 | - * @return $this |
|
| 238 | - */ |
|
| 239 | - public function startRunning(): self |
|
| 240 | - { |
|
| 241 | - $this->is_running = true; |
|
| 242 | - return $this; |
|
| 243 | - } |
|
| 234 | + /** |
|
| 235 | + * Informs the schedule that the task is going to run |
|
| 236 | + * |
|
| 237 | + * @return $this |
|
| 238 | + */ |
|
| 239 | + public function startRunning(): self |
|
| 240 | + { |
|
| 241 | + $this->is_running = true; |
|
| 242 | + return $this; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Informs the schedule that the task has stopped running. |
|
| 247 | - * @return $this |
|
| 248 | - */ |
|
| 249 | - public function stopRunning(): self |
|
| 250 | - { |
|
| 251 | - $this->is_running = false; |
|
| 252 | - return $this; |
|
| 253 | - } |
|
| 245 | + /** |
|
| 246 | + * Informs the schedule that the task has stopped running. |
|
| 247 | + * @return $this |
|
| 248 | + */ |
|
| 249 | + public function stopRunning(): self |
|
| 250 | + { |
|
| 251 | + $this->is_running = false; |
|
| 252 | + return $this; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Returns the schedule details as an associate array |
|
| 257 | - * |
|
| 258 | - * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 259 | - * @return array{id: int, task_id: string, enabled: bool, last_run: CarbonInterface, last_result: bool, frequency: int, nb_occurrences: int, is_running: bool} |
|
| 260 | - */ |
|
| 261 | - public function toArray(): array |
|
| 262 | - { |
|
| 263 | - return [ |
|
| 264 | - 'id' => $this->id, |
|
| 265 | - 'task_id' => $this->task_id, |
|
| 266 | - 'enabled' => $this->enabled, |
|
| 267 | - 'last_run' => $this->last_run, |
|
| 268 | - 'last_result' => $this->last_result, |
|
| 269 | - 'frequency' => $this->frequency, |
|
| 270 | - 'nb_occurrences' => $this->nb_occurrences, |
|
| 271 | - 'is_running' => $this->is_running |
|
| 272 | - ]; |
|
| 273 | - } |
|
| 255 | + /** |
|
| 256 | + * Returns the schedule details as an associate array |
|
| 257 | + * |
|
| 258 | + * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 259 | + * @return array{id: int, task_id: string, enabled: bool, last_run: CarbonInterface, last_result: bool, frequency: int, nb_occurrences: int, is_running: bool} |
|
| 260 | + */ |
|
| 261 | + public function toArray(): array |
|
| 262 | + { |
|
| 263 | + return [ |
|
| 264 | + 'id' => $this->id, |
|
| 265 | + 'task_id' => $this->task_id, |
|
| 266 | + 'enabled' => $this->enabled, |
|
| 267 | + 'last_run' => $this->last_run, |
|
| 268 | + 'last_result' => $this->last_result, |
|
| 269 | + 'frequency' => $this->frequency, |
|
| 270 | + 'nb_occurrences' => $this->nb_occurrences, |
|
| 271 | + 'is_running' => $this->is_running |
|
| 272 | + ]; |
|
| 273 | + } |
|
| 274 | 274 | } |
@@ -31,58 +31,58 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class SosaComputeAction implements RequestHandlerInterface |
| 33 | 33 | { |
| 34 | - private UserService $user_service; |
|
| 34 | + private UserService $user_service; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for SosaConfigAction Request Handler |
|
| 38 | - * |
|
| 39 | - * @param UserService $user_service |
|
| 40 | - */ |
|
| 41 | - public function __construct(UserService $user_service) |
|
| 42 | - { |
|
| 43 | - $this->user_service = $user_service; |
|
| 44 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for SosaConfigAction Request Handler |
|
| 38 | + * |
|
| 39 | + * @param UserService $user_service |
|
| 40 | + */ |
|
| 41 | + public function __construct(UserService $user_service) |
|
| 42 | + { |
|
| 43 | + $this->user_service = $user_service; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * {@inheritDoc} |
|
| 48 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 49 | - */ |
|
| 50 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 51 | - { |
|
| 52 | - $tree = Validator::attributes($request)->tree(); |
|
| 46 | + /** |
|
| 47 | + * {@inheritDoc} |
|
| 48 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 49 | + */ |
|
| 50 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 51 | + { |
|
| 52 | + $tree = Validator::attributes($request)->tree(); |
|
| 53 | 53 | |
| 54 | - // Cannot use Validator with negative integers issue webtrees #4408 |
|
| 55 | - // $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
|
| 56 | - $parsed_body = (array) $request->getParsedBody(); |
|
| 57 | - $user_id = (int) filter_var($parsed_body['user_id'] ?? Auth::id(), FILTER_VALIDATE_INT); |
|
| 54 | + // Cannot use Validator with negative integers issue webtrees #4408 |
|
| 55 | + // $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
|
| 56 | + $parsed_body = (array) $request->getParsedBody(); |
|
| 57 | + $user_id = (int) filter_var($parsed_body['user_id'] ?? Auth::id(), FILTER_VALIDATE_INT); |
|
| 58 | 58 | |
| 59 | - $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
|
| 59 | + $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
|
| 60 | 60 | |
| 61 | - if (($user_id === -1 && Auth::isManager($tree)) || Auth::id() === $user_id) { |
|
| 62 | - $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 61 | + if (($user_id === -1 && Auth::isManager($tree)) || Auth::id() === $user_id) { |
|
| 62 | + $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 63 | 63 | |
| 64 | - /** @var SosaCalculatorService $sosa_calc_service */ |
|
| 65 | - $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
| 64 | + /** @var SosaCalculatorService $sosa_calc_service */ |
|
| 65 | + $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
| 66 | 66 | |
| 67 | - if ( |
|
| 68 | - $partial_from !== '' && |
|
| 69 | - ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
| 70 | - ) { |
|
| 71 | - $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
| 72 | - } else { |
|
| 73 | - $res = $sosa_calc_service->computeAll(); |
|
| 74 | - } |
|
| 67 | + if ( |
|
| 68 | + $partial_from !== '' && |
|
| 69 | + ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
| 70 | + ) { |
|
| 71 | + $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
| 72 | + } else { |
|
| 73 | + $res = $sosa_calc_service->computeAll(); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return $res ? |
|
| 77 | - Registry::responseFactory()->response() : |
|
| 78 | - Registry::responseFactory()->response( |
|
| 79 | - I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
| 80 | - StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - return Registry::responseFactory()->response( |
|
| 84 | - I18N::translate('You do not have permission to modify the user.'), |
|
| 85 | - StatusCodeInterface::STATUS_FORBIDDEN |
|
| 86 | - ); |
|
| 87 | - } |
|
| 76 | + return $res ? |
|
| 77 | + Registry::responseFactory()->response() : |
|
| 78 | + Registry::responseFactory()->response( |
|
| 79 | + I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
| 80 | + StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + return Registry::responseFactory()->response( |
|
| 84 | + I18N::translate('You do not have permission to modify the user.'), |
|
| 85 | + StatusCodeInterface::STATUS_FORBIDDEN |
|
| 86 | + ); |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | // Cannot use Validator with negative integers issue webtrees #4408 |
| 55 | 55 | // $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
| 56 | - $parsed_body = (array) $request->getParsedBody(); |
|
| 57 | - $user_id = (int) filter_var($parsed_body['user_id'] ?? Auth::id(), FILTER_VALIDATE_INT); |
|
| 56 | + $parsed_body = (array)$request->getParsedBody(); |
|
| 57 | + $user_id = (int)filter_var($parsed_body['user_id'] ?? Auth::id(), FILTER_VALIDATE_INT); |
|
| 58 | 58 | |
| 59 | 59 | $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
| 60 | 60 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
| 63 | 63 | |
| 64 | 64 | /** @var SosaCalculatorService $sosa_calc_service */ |
| 65 | - $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
| 65 | + $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, ['tree' => $tree, 'user' => $user]); |
|
| 66 | 66 | |
| 67 | 67 | if ( |
| 68 | 68 | $partial_from !== '' && |
@@ -74,8 +74,7 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | return $res ? |
| 77 | - Registry::responseFactory()->response() : |
|
| 78 | - Registry::responseFactory()->response( |
|
| 77 | + Registry::responseFactory()->response() : Registry::responseFactory()->response( |
|
| 79 | 78 | I18N::translate('An error occurred while computing Sosa ancestors.'), |
| 80 | 79 | StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
| 81 | 80 | ); |
@@ -28,39 +28,39 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class SosaComputeModal implements RequestHandlerInterface |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var SosaModule|null $module |
|
| 33 | - */ |
|
| 34 | - private $module; |
|
| 31 | + /** |
|
| 32 | + * @var SosaModule|null $module |
|
| 33 | + */ |
|
| 34 | + private $module; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for SosaComputeModal Request Handler |
|
| 38 | - * |
|
| 39 | - * @param ModuleService $module_service |
|
| 40 | - */ |
|
| 41 | - public function __construct(ModuleService $module_service) |
|
| 42 | - { |
|
| 43 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 44 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for SosaComputeModal Request Handler |
|
| 38 | + * |
|
| 39 | + * @param ModuleService $module_service |
|
| 40 | + */ |
|
| 41 | + public function __construct(ModuleService $module_service) |
|
| 42 | + { |
|
| 43 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * {@inheritDoc} |
|
| 48 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 49 | - */ |
|
| 50 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 51 | - { |
|
| 52 | - if ($this->module === null) { |
|
| 53 | - return Registry::responseFactory()->response(view('modals/error', [ |
|
| 54 | - 'title' => I18N::translate('Error'), |
|
| 55 | - 'error' => I18N::translate('The attached module could not be found.') |
|
| 56 | - ])); |
|
| 57 | - } |
|
| 46 | + /** |
|
| 47 | + * {@inheritDoc} |
|
| 48 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 49 | + */ |
|
| 50 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 51 | + { |
|
| 52 | + if ($this->module === null) { |
|
| 53 | + return Registry::responseFactory()->response(view('modals/error', [ |
|
| 54 | + 'title' => I18N::translate('Error'), |
|
| 55 | + 'error' => I18N::translate('The attached module could not be found.') |
|
| 56 | + ])); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $tree = Validator::attributes($request)->tree(); |
|
| 59 | + $tree = Validator::attributes($request)->tree(); |
|
| 60 | 60 | |
| 61 | - return Registry::responseFactory()->response(view($this->module->name() . '::modals/sosa-compute', [ |
|
| 62 | - 'tree' => $tree, |
|
| 63 | - 'xref' => Validator::attributes($request)->isXref()->string('xref', '') |
|
| 64 | - ])); |
|
| 65 | - } |
|
| 61 | + return Registry::responseFactory()->response(view($this->module->name() . '::modals/sosa-compute', [ |
|
| 62 | + 'tree' => $tree, |
|
| 63 | + 'xref' => Validator::attributes($request)->isXref()->string('xref', '') |
|
| 64 | + ])); |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | |
| 59 | 59 | $tree = Validator::attributes($request)->tree(); |
| 60 | 60 | |
| 61 | - return Registry::responseFactory()->response(view($this->module->name() . '::modals/sosa-compute', [ |
|
| 61 | + return Registry::responseFactory()->response(view($this->module->name().'::modals/sosa-compute', [ |
|
| 62 | 62 | 'tree' => $tree, |
| 63 | 63 | 'xref' => Validator::attributes($request)->isXref()->string('xref', '') |
| 64 | 64 | ])); |
@@ -33,75 +33,75 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class SosaConfig implements RequestHandlerInterface |
| 35 | 35 | { |
| 36 | - use ViewResponseTrait; |
|
| 36 | + use ViewResponseTrait; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var SosaModule|null $module |
|
| 40 | - */ |
|
| 41 | - private $module; |
|
| 38 | + /** |
|
| 39 | + * @var SosaModule|null $module |
|
| 40 | + */ |
|
| 41 | + private $module; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Constructor for SosaConfig Request Handler |
|
| 45 | - * |
|
| 46 | - * @param ModuleService $module_service |
|
| 47 | - */ |
|
| 48 | - public function __construct(ModuleService $module_service) |
|
| 49 | - { |
|
| 50 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * Constructor for SosaConfig Request Handler |
|
| 45 | + * |
|
| 46 | + * @param ModuleService $module_service |
|
| 47 | + */ |
|
| 48 | + public function __construct(ModuleService $module_service) |
|
| 49 | + { |
|
| 50 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritDoc} |
|
| 55 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 56 | - */ |
|
| 57 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 58 | - { |
|
| 59 | - if ($this->module === null) { |
|
| 60 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritDoc} |
|
| 55 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 56 | + */ |
|
| 57 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 58 | + { |
|
| 59 | + if ($this->module === null) { |
|
| 60 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $tree = Validator::attributes($request)->tree(); |
|
| 63 | + $tree = Validator::attributes($request)->tree(); |
|
| 64 | 64 | |
| 65 | - $users_root = array(); |
|
| 66 | - if (Auth::check()) { |
|
| 67 | - /** @var \Fisharebest\Webtrees\User $user */ |
|
| 68 | - $user = Auth::user(); |
|
| 69 | - $users_root[] = [ |
|
| 70 | - 'user' => $user, |
|
| 71 | - 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'), |
|
| 72 | - 'max_gen' => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN') |
|
| 73 | - ]; |
|
| 65 | + $users_root = array(); |
|
| 66 | + if (Auth::check()) { |
|
| 67 | + /** @var \Fisharebest\Webtrees\User $user */ |
|
| 68 | + $user = Auth::user(); |
|
| 69 | + $users_root[] = [ |
|
| 70 | + 'user' => $user, |
|
| 71 | + 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'), |
|
| 72 | + 'max_gen' => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN') |
|
| 73 | + ]; |
|
| 74 | 74 | |
| 75 | - if (Auth::isManager($tree)) { |
|
| 76 | - $default_user = new DefaultUser(); |
|
| 77 | - $users_root[] = [ |
|
| 78 | - 'user' => $default_user, |
|
| 79 | - 'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'), |
|
| 80 | - 'max_gen' => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN') |
|
| 81 | - ]; |
|
| 82 | - } |
|
| 83 | - } |
|
| 75 | + if (Auth::isManager($tree)) { |
|
| 76 | + $default_user = new DefaultUser(); |
|
| 77 | + $users_root[] = [ |
|
| 78 | + 'user' => $default_user, |
|
| 79 | + 'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'), |
|
| 80 | + 'max_gen' => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN') |
|
| 81 | + ]; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // Use the system max generations if not set |
|
| 86 | - $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
|
| 87 | - foreach ($users_root as $key => $user_root) { |
|
| 88 | - $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
|
| 89 | - (int) $user_root['max_gen'] : |
|
| 90 | - $max_gen_system; |
|
| 91 | - }; |
|
| 85 | + // Use the system max generations if not set |
|
| 86 | + $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
|
| 87 | + foreach ($users_root as $key => $user_root) { |
|
| 88 | + $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
|
| 89 | + (int) $user_root['max_gen'] : |
|
| 90 | + $max_gen_system; |
|
| 91 | + }; |
|
| 92 | 92 | |
| 93 | - // Cannot use Validator with negative integers issue webtrees #4408 |
|
| 94 | - $selected_user_id = (int) filter_var($request->getQueryParams()['user_id'] ?? 0, FILTER_VALIDATE_INT); |
|
| 93 | + // Cannot use Validator with negative integers issue webtrees #4408 |
|
| 94 | + $selected_user_id = (int) filter_var($request->getQueryParams()['user_id'] ?? 0, FILTER_VALIDATE_INT); |
|
| 95 | 95 | |
| 96 | - return $this->viewResponse($this->module->name() . '::config-page', [ |
|
| 97 | - 'module_name' => $this->module->name(), |
|
| 98 | - 'title' => I18N::translate('Sosa Configuration'), |
|
| 99 | - 'tree' => $tree, |
|
| 100 | - 'user_id' => Validator::attributes($request)->user(), |
|
| 101 | - //'selected_user_id' => Validator::queryParams($request)->integer('user_id', 0), // See webtree #4408 |
|
| 102 | - 'selected_user_id' => $selected_user_id, |
|
| 103 | - 'immediate_compute' => Validator::queryParams($request)->string('compute', '') === 'yes', |
|
| 104 | - 'users_root' => $users_root |
|
| 105 | - ]); |
|
| 106 | - } |
|
| 96 | + return $this->viewResponse($this->module->name() . '::config-page', [ |
|
| 97 | + 'module_name' => $this->module->name(), |
|
| 98 | + 'title' => I18N::translate('Sosa Configuration'), |
|
| 99 | + 'tree' => $tree, |
|
| 100 | + 'user_id' => Validator::attributes($request)->user(), |
|
| 101 | + //'selected_user_id' => Validator::queryParams($request)->integer('user_id', 0), // See webtree #4408 |
|
| 102 | + 'selected_user_id' => $selected_user_id, |
|
| 103 | + 'immediate_compute' => Validator::queryParams($request)->string('compute', '') === 'yes', |
|
| 104 | + 'users_root' => $users_root |
|
| 105 | + ]); |
|
| 106 | + } |
|
| 107 | 107 | } |
@@ -86,14 +86,13 @@ |
||
| 86 | 86 | $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
| 87 | 87 | foreach ($users_root as $key => $user_root) { |
| 88 | 88 | $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
| 89 | - (int) $user_root['max_gen'] : |
|
| 90 | - $max_gen_system; |
|
| 89 | + (int)$user_root['max_gen'] : $max_gen_system; |
|
| 91 | 90 | }; |
| 92 | 91 | |
| 93 | 92 | // Cannot use Validator with negative integers issue webtrees #4408 |
| 94 | - $selected_user_id = (int) filter_var($request->getQueryParams()['user_id'] ?? 0, FILTER_VALIDATE_INT); |
|
| 93 | + $selected_user_id = (int)filter_var($request->getQueryParams()['user_id'] ?? 0, FILTER_VALIDATE_INT); |
|
| 95 | 94 | |
| 96 | - return $this->viewResponse($this->module->name() . '::config-page', [ |
|
| 95 | + return $this->viewResponse($this->module->name().'::config-page', [ |
|
| 97 | 96 | 'module_name' => $this->module->name(), |
| 98 | 97 | 'title' => I18N::translate('Sosa Configuration'), |
| 99 | 98 | 'tree' => $tree, |
@@ -35,79 +35,79 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class AncestorsListIndividual implements RequestHandlerInterface |
| 37 | 37 | { |
| 38 | - use ViewResponseTrait; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var SosaModule|null $module |
|
| 42 | - */ |
|
| 43 | - private $module; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var SosaRecordsService $sosa_record_service |
|
| 47 | - */ |
|
| 48 | - private $sosa_record_service; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Constructor for AncestorsListIndividual Request Handler |
|
| 52 | - * |
|
| 53 | - * @param ModuleService $module_service |
|
| 54 | - * @param SosaRecordsService $sosa_record_service |
|
| 55 | - */ |
|
| 56 | - public function __construct( |
|
| 57 | - ModuleService $module_service, |
|
| 58 | - SosaRecordsService $sosa_record_service |
|
| 59 | - ) { |
|
| 60 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 61 | - $this->sosa_record_service = $sosa_record_service; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * {@inheritDoc} |
|
| 66 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 67 | - */ |
|
| 68 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 69 | - { |
|
| 70 | - $this->layout = 'layouts/ajax'; |
|
| 71 | - |
|
| 72 | - if ($this->module === null) { |
|
| 73 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $tree = Validator::attributes($request)->tree(); |
|
| 77 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
| 78 | - $current_gen = Validator::attributes($request)->integer('gen', 0); |
|
| 79 | - |
|
| 80 | - if ($current_gen <= 0) { |
|
| 81 | - return Registry::responseFactory()->response( |
|
| 82 | - 'Invalid generation', |
|
| 83 | - StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY |
|
| 84 | - ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen); |
|
| 88 | - $nb_ancestors_all = $list_ancestors->count(); |
|
| 89 | - |
|
| 90 | - /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */ |
|
| 91 | - $list_ancestors = $list_ancestors |
|
| 92 | - ->filter(function (stdClass $value) use ($tree): bool { |
|
| 93 | - $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
| 94 | - return $indi !== null && $indi->canShowName(); |
|
| 95 | - }) |
|
| 96 | - ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
| 97 | - $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
| 98 | - return [(int) $value->majs_sosa => $indi]; |
|
| 99 | - }); |
|
| 100 | - |
|
| 101 | - $nb_ancestors_shown = $list_ancestors->count(); |
|
| 102 | - |
|
| 103 | - return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [ |
|
| 104 | - 'module_name' => $this->module->name(), |
|
| 105 | - 'title' => I18N::translate('Sosa Ancestors'), |
|
| 106 | - 'tree' => $tree, |
|
| 107 | - 'list_ancestors' => $list_ancestors, |
|
| 108 | - 'nb_ancestors_all' => $nb_ancestors_all, |
|
| 109 | - 'nb_ancestors_theor' => pow(2, $current_gen - 1), |
|
| 110 | - 'nb_ancestors_shown' => $nb_ancestors_shown |
|
| 111 | - ]); |
|
| 112 | - } |
|
| 38 | + use ViewResponseTrait; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var SosaModule|null $module |
|
| 42 | + */ |
|
| 43 | + private $module; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var SosaRecordsService $sosa_record_service |
|
| 47 | + */ |
|
| 48 | + private $sosa_record_service; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Constructor for AncestorsListIndividual Request Handler |
|
| 52 | + * |
|
| 53 | + * @param ModuleService $module_service |
|
| 54 | + * @param SosaRecordsService $sosa_record_service |
|
| 55 | + */ |
|
| 56 | + public function __construct( |
|
| 57 | + ModuleService $module_service, |
|
| 58 | + SosaRecordsService $sosa_record_service |
|
| 59 | + ) { |
|
| 60 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 61 | + $this->sosa_record_service = $sosa_record_service; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * {@inheritDoc} |
|
| 66 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 67 | + */ |
|
| 68 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 69 | + { |
|
| 70 | + $this->layout = 'layouts/ajax'; |
|
| 71 | + |
|
| 72 | + if ($this->module === null) { |
|
| 73 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $tree = Validator::attributes($request)->tree(); |
|
| 77 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
| 78 | + $current_gen = Validator::attributes($request)->integer('gen', 0); |
|
| 79 | + |
|
| 80 | + if ($current_gen <= 0) { |
|
| 81 | + return Registry::responseFactory()->response( |
|
| 82 | + 'Invalid generation', |
|
| 83 | + StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen); |
|
| 88 | + $nb_ancestors_all = $list_ancestors->count(); |
|
| 89 | + |
|
| 90 | + /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */ |
|
| 91 | + $list_ancestors = $list_ancestors |
|
| 92 | + ->filter(function (stdClass $value) use ($tree): bool { |
|
| 93 | + $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
| 94 | + return $indi !== null && $indi->canShowName(); |
|
| 95 | + }) |
|
| 96 | + ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
| 97 | + $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
| 98 | + return [(int) $value->majs_sosa => $indi]; |
|
| 99 | + }); |
|
| 100 | + |
|
| 101 | + $nb_ancestors_shown = $list_ancestors->count(); |
|
| 102 | + |
|
| 103 | + return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [ |
|
| 104 | + 'module_name' => $this->module->name(), |
|
| 105 | + 'title' => I18N::translate('Sosa Ancestors'), |
|
| 106 | + 'tree' => $tree, |
|
| 107 | + 'list_ancestors' => $list_ancestors, |
|
| 108 | + 'nb_ancestors_all' => $nb_ancestors_all, |
|
| 109 | + 'nb_ancestors_theor' => pow(2, $current_gen - 1), |
|
| 110 | + 'nb_ancestors_shown' => $nb_ancestors_shown |
|
| 111 | + ]); |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -89,18 +89,18 @@ |
||
| 89 | 89 | |
| 90 | 90 | /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */ |
| 91 | 91 | $list_ancestors = $list_ancestors |
| 92 | - ->filter(function (stdClass $value) use ($tree): bool { |
|
| 92 | + ->filter(function(stdClass $value) use ($tree): bool { |
|
| 93 | 93 | $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
| 94 | 94 | return $indi !== null && $indi->canShowName(); |
| 95 | 95 | }) |
| 96 | - ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
| 96 | + ->mapWithKeys(function(stdClass $value) use ($tree): array { |
|
| 97 | 97 | $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
| 98 | - return [(int) $value->majs_sosa => $indi]; |
|
| 98 | + return [(int)$value->majs_sosa => $indi]; |
|
| 99 | 99 | }); |
| 100 | 100 | |
| 101 | 101 | $nb_ancestors_shown = $list_ancestors->count(); |
| 102 | 102 | |
| 103 | - return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [ |
|
| 103 | + return $this->viewResponse($this->module->name().'::list-ancestors-indi-tab', [ |
|
| 104 | 104 | 'module_name' => $this->module->name(), |
| 105 | 105 | 'title' => I18N::translate('Sosa Ancestors'), |
| 106 | 106 | 'tree' => $tree, |
@@ -35,78 +35,78 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class AncestorsListFamily implements RequestHandlerInterface |
| 37 | 37 | { |
| 38 | - use ViewResponseTrait; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var SosaModule|null $module |
|
| 42 | - */ |
|
| 43 | - private $module; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var SosaRecordsService $sosa_record_service |
|
| 47 | - */ |
|
| 48 | - private $sosa_record_service; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Constructor for AncestorsListFamily Request Handler |
|
| 52 | - * |
|
| 53 | - * @param ModuleService $module_service |
|
| 54 | - * @param SosaRecordsService $sosa_record_service |
|
| 55 | - */ |
|
| 56 | - public function __construct( |
|
| 57 | - ModuleService $module_service, |
|
| 58 | - SosaRecordsService $sosa_record_service |
|
| 59 | - ) { |
|
| 60 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 61 | - $this->sosa_record_service = $sosa_record_service; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * {@inheritDoc} |
|
| 66 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 67 | - */ |
|
| 68 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 69 | - { |
|
| 70 | - $this->layout = 'layouts/ajax'; |
|
| 71 | - |
|
| 72 | - if ($this->module === null) { |
|
| 73 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $tree = Validator::attributes($request)->tree(); |
|
| 77 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
| 78 | - $current_gen = Validator::attributes($request)->integer('gen', 0); |
|
| 79 | - |
|
| 80 | - if ($current_gen <= 0) { |
|
| 81 | - return Registry::responseFactory()->response( |
|
| 82 | - 'Invalid generation', |
|
| 83 | - StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY |
|
| 84 | - ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen); |
|
| 88 | - $nb_families_all = $list_families->count(); |
|
| 89 | - |
|
| 90 | - /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */ |
|
| 91 | - $list_families = $list_families |
|
| 92 | - ->filter(function (stdClass $value) use ($tree): bool { |
|
| 93 | - $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
| 94 | - return $fam !== null && $fam->canShow(); |
|
| 95 | - }) |
|
| 96 | - ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
| 97 | - $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
| 98 | - return [(int) $value->majs_sosa => $fam]; |
|
| 99 | - }); |
|
| 100 | - |
|
| 101 | - $nb_families_shown = $list_families->count(); |
|
| 102 | - |
|
| 103 | - return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [ |
|
| 104 | - 'module_name' => $this->module->name(), |
|
| 105 | - 'title' => I18N::translate('Sosa Ancestors'), |
|
| 106 | - 'tree' => $tree, |
|
| 107 | - 'list_families' => $list_families, |
|
| 108 | - 'nb_families_all' => $nb_families_all, |
|
| 109 | - 'nb_families_shown' => $nb_families_shown |
|
| 110 | - ]); |
|
| 111 | - } |
|
| 38 | + use ViewResponseTrait; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var SosaModule|null $module |
|
| 42 | + */ |
|
| 43 | + private $module; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var SosaRecordsService $sosa_record_service |
|
| 47 | + */ |
|
| 48 | + private $sosa_record_service; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Constructor for AncestorsListFamily Request Handler |
|
| 52 | + * |
|
| 53 | + * @param ModuleService $module_service |
|
| 54 | + * @param SosaRecordsService $sosa_record_service |
|
| 55 | + */ |
|
| 56 | + public function __construct( |
|
| 57 | + ModuleService $module_service, |
|
| 58 | + SosaRecordsService $sosa_record_service |
|
| 59 | + ) { |
|
| 60 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 61 | + $this->sosa_record_service = $sosa_record_service; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * {@inheritDoc} |
|
| 66 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 67 | + */ |
|
| 68 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 69 | + { |
|
| 70 | + $this->layout = 'layouts/ajax'; |
|
| 71 | + |
|
| 72 | + if ($this->module === null) { |
|
| 73 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $tree = Validator::attributes($request)->tree(); |
|
| 77 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
| 78 | + $current_gen = Validator::attributes($request)->integer('gen', 0); |
|
| 79 | + |
|
| 80 | + if ($current_gen <= 0) { |
|
| 81 | + return Registry::responseFactory()->response( |
|
| 82 | + 'Invalid generation', |
|
| 83 | + StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen); |
|
| 88 | + $nb_families_all = $list_families->count(); |
|
| 89 | + |
|
| 90 | + /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */ |
|
| 91 | + $list_families = $list_families |
|
| 92 | + ->filter(function (stdClass $value) use ($tree): bool { |
|
| 93 | + $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
| 94 | + return $fam !== null && $fam->canShow(); |
|
| 95 | + }) |
|
| 96 | + ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
| 97 | + $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
| 98 | + return [(int) $value->majs_sosa => $fam]; |
|
| 99 | + }); |
|
| 100 | + |
|
| 101 | + $nb_families_shown = $list_families->count(); |
|
| 102 | + |
|
| 103 | + return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [ |
|
| 104 | + 'module_name' => $this->module->name(), |
|
| 105 | + 'title' => I18N::translate('Sosa Ancestors'), |
|
| 106 | + 'tree' => $tree, |
|
| 107 | + 'list_families' => $list_families, |
|
| 108 | + 'nb_families_all' => $nb_families_all, |
|
| 109 | + 'nb_families_shown' => $nb_families_shown |
|
| 110 | + ]); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -89,18 +89,18 @@ |
||
| 89 | 89 | |
| 90 | 90 | /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */ |
| 91 | 91 | $list_families = $list_families |
| 92 | - ->filter(function (stdClass $value) use ($tree): bool { |
|
| 92 | + ->filter(function(stdClass $value) use ($tree): bool { |
|
| 93 | 93 | $fam = Registry::familyFactory()->make($value->f_id, $tree); |
| 94 | 94 | return $fam !== null && $fam->canShow(); |
| 95 | 95 | }) |
| 96 | - ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
| 96 | + ->mapWithKeys(function(stdClass $value) use ($tree): array { |
|
| 97 | 97 | $fam = Registry::familyFactory()->make($value->f_id, $tree); |
| 98 | - return [(int) $value->majs_sosa => $fam]; |
|
| 98 | + return [(int)$value->majs_sosa => $fam]; |
|
| 99 | 99 | }); |
| 100 | 100 | |
| 101 | 101 | $nb_families_shown = $list_families->count(); |
| 102 | 102 | |
| 103 | - return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [ |
|
| 103 | + return $this->viewResponse($this->module->name().'::list-ancestors-fam-tab', [ |
|
| 104 | 104 | 'module_name' => $this->module->name(), |
| 105 | 105 | 'title' => I18N::translate('Sosa Ancestors'), |
| 106 | 106 | 'tree' => $tree, |
@@ -31,54 +31,54 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class SosaConfigAction implements RequestHandlerInterface |
| 33 | 33 | { |
| 34 | - private UserService $user_service; |
|
| 35 | - private SosaRecordsService $sosa_record_service; |
|
| 34 | + private UserService $user_service; |
|
| 35 | + private SosaRecordsService $sosa_record_service; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Constructor for SosaConfigAction Request Handler |
|
| 39 | - * |
|
| 40 | - * @param UserService $user_service |
|
| 41 | - * @param SosaRecordsService $sosa_records_service |
|
| 42 | - */ |
|
| 43 | - public function __construct(UserService $user_service, SosaRecordsService $sosa_records_service) |
|
| 44 | - { |
|
| 45 | - $this->user_service = $user_service; |
|
| 46 | - $this->sosa_record_service = $sosa_records_service; |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * Constructor for SosaConfigAction Request Handler |
|
| 39 | + * |
|
| 40 | + * @param UserService $user_service |
|
| 41 | + * @param SosaRecordsService $sosa_records_service |
|
| 42 | + */ |
|
| 43 | + public function __construct(UserService $user_service, SosaRecordsService $sosa_records_service) |
|
| 44 | + { |
|
| 45 | + $this->user_service = $user_service; |
|
| 46 | + $this->sosa_record_service = $sosa_records_service; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * {@inheritDoc} |
|
| 51 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 52 | - */ |
|
| 53 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 54 | - { |
|
| 55 | - $tree = Validator::attributes($request)->tree(); |
|
| 49 | + /** |
|
| 50 | + * {@inheritDoc} |
|
| 51 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 52 | + */ |
|
| 53 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 54 | + { |
|
| 55 | + $tree = Validator::attributes($request)->tree(); |
|
| 56 | 56 | |
| 57 | - // Cannot use Validator with negative integers issue webtrees #4408 |
|
| 58 | - //$user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
|
| 59 | - $parsed_body = (array) $request->getParsedBody(); |
|
| 60 | - $user_id = (int) filter_var($parsed_body['sosa-userid'] ?? 0, FILTER_VALIDATE_INT); |
|
| 61 | - $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
|
| 62 | - $max_gen = Validator::parsedBody($request)->integer( |
|
| 63 | - 'sosa-maxgen', |
|
| 64 | - $this->sosa_record_service->maxSystemGenerations() |
|
| 65 | - ); |
|
| 57 | + // Cannot use Validator with negative integers issue webtrees #4408 |
|
| 58 | + //$user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
|
| 59 | + $parsed_body = (array) $request->getParsedBody(); |
|
| 60 | + $user_id = (int) filter_var($parsed_body['sosa-userid'] ?? 0, FILTER_VALIDATE_INT); |
|
| 61 | + $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
|
| 62 | + $max_gen = Validator::parsedBody($request)->integer( |
|
| 63 | + 'sosa-maxgen', |
|
| 64 | + $this->sosa_record_service->maxSystemGenerations() |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - if (Auth::id() === $user_id || ($user_id === -1 && Auth::isManager($tree))) { |
|
| 68 | - $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 69 | - if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
| 70 | - $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
| 71 | - $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
| 72 | - FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
| 73 | - return Registry::responseFactory()->redirect(SosaConfig::class, [ |
|
| 74 | - 'tree' => $tree->name(), |
|
| 75 | - 'compute' => 'yes', |
|
| 76 | - 'user_id' => $user_id |
|
| 77 | - ]); |
|
| 78 | - } |
|
| 79 | - } |
|
| 67 | + if (Auth::id() === $user_id || ($user_id === -1 && Auth::isManager($tree))) { |
|
| 68 | + $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 69 | + if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
| 70 | + $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
| 71 | + $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
| 72 | + FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
| 73 | + return Registry::responseFactory()->redirect(SosaConfig::class, [ |
|
| 74 | + 'tree' => $tree->name(), |
|
| 75 | + 'compute' => 'yes', |
|
| 76 | + 'user_id' => $user_id |
|
| 77 | + ]); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
| 82 | - return Registry::responseFactory()->redirect(SosaConfig::class, ['tree' => $tree->name()]); |
|
| 83 | - } |
|
| 81 | + FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
| 82 | + return Registry::responseFactory()->redirect(SosaConfig::class, ['tree' => $tree->name()]); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | // Cannot use Validator with negative integers issue webtrees #4408 |
| 58 | 58 | //$user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
| 59 | - $parsed_body = (array) $request->getParsedBody(); |
|
| 60 | - $user_id = (int) filter_var($parsed_body['sosa-userid'] ?? 0, FILTER_VALIDATE_INT); |
|
| 59 | + $parsed_body = (array)$request->getParsedBody(); |
|
| 60 | + $user_id = (int)filter_var($parsed_body['sosa-userid'] ?? 0, FILTER_VALIDATE_INT); |
|
| 61 | 61 | $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
| 62 | 62 | $max_gen = Validator::parsedBody($request)->integer( |
| 63 | 63 | 'sosa-maxgen', |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
| 69 | 69 | if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
| 70 | 70 | $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
| 71 | - $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
| 71 | + $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string)$max_gen); |
|
| 72 | 72 | FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
| 73 | 73 | return Registry::responseFactory()->redirect(SosaConfig::class, [ |
| 74 | 74 | 'tree' => $tree->name(), |
@@ -33,49 +33,49 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class PedigreeCollapseData implements RequestHandlerInterface |
| 35 | 35 | { |
| 36 | - /** |
|
| 37 | - * @var SosaModule|null $module |
|
| 38 | - */ |
|
| 39 | - private $module; |
|
| 36 | + /** |
|
| 37 | + * @var SosaModule|null $module |
|
| 38 | + */ |
|
| 39 | + private $module; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Constructor for PedigreeCollapseData Request Handler |
|
| 43 | - * |
|
| 44 | - * @param ModuleService $module_service |
|
| 45 | - */ |
|
| 46 | - public function __construct(ModuleService $module_service) |
|
| 47 | - { |
|
| 48 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 49 | - } |
|
| 41 | + /** |
|
| 42 | + * Constructor for PedigreeCollapseData Request Handler |
|
| 43 | + * |
|
| 44 | + * @param ModuleService $module_service |
|
| 45 | + */ |
|
| 46 | + public function __construct(ModuleService $module_service) |
|
| 47 | + { |
|
| 48 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * {@inheritDoc} |
|
| 53 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 54 | - */ |
|
| 55 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 56 | - { |
|
| 57 | - if ($this->module === null) { |
|
| 58 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 59 | - } |
|
| 51 | + /** |
|
| 52 | + * {@inheritDoc} |
|
| 53 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 54 | + */ |
|
| 55 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 56 | + { |
|
| 57 | + if ($this->module === null) { |
|
| 58 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $tree = Validator::attributes($request)->tree(); |
|
| 62 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
| 61 | + $tree = Validator::attributes($request)->tree(); |
|
| 62 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
| 63 | 63 | |
| 64 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
| 65 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
| 66 | - $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData(); |
|
| 64 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
| 65 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
| 66 | + $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData(); |
|
| 67 | 67 | |
| 68 | - $response = [ 'cells' => [] ]; |
|
| 69 | - $last_pedi_collapse = 0; |
|
| 70 | - foreach ($pedi_collapse_data as $gen => $rec) { |
|
| 71 | - $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [ |
|
| 72 | - 'pedi_collapse_roots' => $rec['pedi_collapse_roots'], |
|
| 73 | - 'pedi_collapse_xgen' => $rec['pedi_collapse_xgen'] |
|
| 74 | - ]); |
|
| 75 | - $last_pedi_collapse = $rec['pedi_collapse_roots']; |
|
| 76 | - } |
|
| 77 | - $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2); |
|
| 68 | + $response = [ 'cells' => [] ]; |
|
| 69 | + $last_pedi_collapse = 0; |
|
| 70 | + foreach ($pedi_collapse_data as $gen => $rec) { |
|
| 71 | + $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [ |
|
| 72 | + 'pedi_collapse_roots' => $rec['pedi_collapse_roots'], |
|
| 73 | + 'pedi_collapse_xgen' => $rec['pedi_collapse_xgen'] |
|
| 74 | + ]); |
|
| 75 | + $last_pedi_collapse = $rec['pedi_collapse_roots']; |
|
| 76 | + } |
|
| 77 | + $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2); |
|
| 78 | 78 | |
| 79 | - return Registry::responseFactory()->response($response); |
|
| 80 | - } |
|
| 79 | + return Registry::responseFactory()->response($response); |
|
| 80 | + } |
|
| 81 | 81 | } |