@@ -29,111 +29,111 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class FilteredTopPlaceMapperConfig extends GenericPlaceMapperConfig |
| 31 | 31 | { |
| 32 | - private TreeService $tree_service; |
|
| 32 | + private TreeService $tree_service; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * FilteredTopPlaceMapperConfig |
|
| 36 | - * |
|
| 37 | - * @param TreeService $tree_service |
|
| 38 | - */ |
|
| 39 | - public function __construct(TreeService $tree_service) |
|
| 40 | - { |
|
| 41 | - $this->tree_service = $tree_service; |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * FilteredTopPlaceMapperConfig |
|
| 36 | + * |
|
| 37 | + * @param TreeService $tree_service |
|
| 38 | + */ |
|
| 39 | + public function __construct(TreeService $tree_service) |
|
| 40 | + { |
|
| 41 | + $this->tree_service = $tree_service; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Get the configured Top Places to filter on |
|
| 46 | - * |
|
| 47 | - * @return Collection<Place> |
|
| 48 | - */ |
|
| 49 | - public function topPlaces(): Collection |
|
| 50 | - { |
|
| 51 | - return collect($this->get('topPlaces', [])) |
|
| 52 | - ->filter( |
|
| 53 | - /** @psalm-suppress MissingClosureParamType */ |
|
| 54 | - fn($item): bool => $item instanceof Place |
|
| 55 | - ); |
|
| 56 | - } |
|
| 44 | + /** |
|
| 45 | + * Get the configured Top Places to filter on |
|
| 46 | + * |
|
| 47 | + * @return Collection<Place> |
|
| 48 | + */ |
|
| 49 | + public function topPlaces(): Collection |
|
| 50 | + { |
|
| 51 | + return collect($this->get('topPlaces', [])) |
|
| 52 | + ->filter( |
|
| 53 | + /** @psalm-suppress MissingClosureParamType */ |
|
| 54 | + fn($item): bool => $item instanceof Place |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * {@inheritDoc} |
|
| 60 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonSerializeConfig() |
|
| 61 | - */ |
|
| 62 | - public function jsonSerializeConfig() |
|
| 63 | - { |
|
| 64 | - return [ |
|
| 65 | - 'topPlaces' => $this->topPlaces() |
|
| 66 | - ->map(fn(Place $place): array => [ $place->tree()->id(), $place->gedcomName() ]) |
|
| 67 | - ->toArray() |
|
| 68 | - ]; |
|
| 69 | - } |
|
| 58 | + /** |
|
| 59 | + * {@inheritDoc} |
|
| 60 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonSerializeConfig() |
|
| 61 | + */ |
|
| 62 | + public function jsonSerializeConfig() |
|
| 63 | + { |
|
| 64 | + return [ |
|
| 65 | + 'topPlaces' => $this->topPlaces() |
|
| 66 | + ->map(fn(Place $place): array => [ $place->tree()->id(), $place->gedcomName() ]) |
|
| 67 | + ->toArray() |
|
| 68 | + ]; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * {@inheritDoc} |
|
| 73 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonDeserialize() |
|
| 74 | - * |
|
| 75 | - * @param mixed $config |
|
| 76 | - * @return $this |
|
| 77 | - */ |
|
| 78 | - public function jsonDeserialize($config): self |
|
| 79 | - { |
|
| 80 | - if (is_string($config)) { |
|
| 81 | - return $this->jsonDeserialize(json_decode($config)); |
|
| 82 | - } |
|
| 83 | - if (is_array($config)) { |
|
| 84 | - $this->setConfig([ |
|
| 85 | - 'topPlaces' => collect($config['topPlaces'] ?? []) |
|
| 86 | - ->filter( |
|
| 87 | - /** @psalm-suppress MissingClosureParamType */ |
|
| 88 | - fn($item): bool => is_array($item) && count($item) === 2 |
|
| 89 | - )->map(function (array $item): ?Place { |
|
| 90 | - try { |
|
| 91 | - return new Place($item[1], $this->tree_service->find($item[0])); |
|
| 92 | - } catch (RuntimeException $ex) { |
|
| 93 | - return null; |
|
| 94 | - } |
|
| 95 | - }) |
|
| 96 | - ->filter() |
|
| 97 | - ->toArray() |
|
| 98 | - ]); |
|
| 99 | - } |
|
| 100 | - return $this; |
|
| 101 | - } |
|
| 71 | + /** |
|
| 72 | + * {@inheritDoc} |
|
| 73 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonDeserialize() |
|
| 74 | + * |
|
| 75 | + * @param mixed $config |
|
| 76 | + * @return $this |
|
| 77 | + */ |
|
| 78 | + public function jsonDeserialize($config): self |
|
| 79 | + { |
|
| 80 | + if (is_string($config)) { |
|
| 81 | + return $this->jsonDeserialize(json_decode($config)); |
|
| 82 | + } |
|
| 83 | + if (is_array($config)) { |
|
| 84 | + $this->setConfig([ |
|
| 85 | + 'topPlaces' => collect($config['topPlaces'] ?? []) |
|
| 86 | + ->filter( |
|
| 87 | + /** @psalm-suppress MissingClosureParamType */ |
|
| 88 | + fn($item): bool => is_array($item) && count($item) === 2 |
|
| 89 | + )->map(function (array $item): ?Place { |
|
| 90 | + try { |
|
| 91 | + return new Place($item[1], $this->tree_service->find($item[0])); |
|
| 92 | + } catch (RuntimeException $ex) { |
|
| 93 | + return null; |
|
| 94 | + } |
|
| 95 | + }) |
|
| 96 | + ->filter() |
|
| 97 | + ->toArray() |
|
| 98 | + ]); |
|
| 99 | + } |
|
| 100 | + return $this; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * {@inheritDoc} |
|
| 105 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::configContent() |
|
| 106 | - */ |
|
| 107 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 108 | - { |
|
| 109 | - return view($module->name() . '::mappers/filtered-top-config', [ |
|
| 110 | - 'tree' => $tree, |
|
| 111 | - 'top_places' => $this->topPlaces() |
|
| 112 | - ]); |
|
| 113 | - } |
|
| 103 | + /** |
|
| 104 | + * {@inheritDoc} |
|
| 105 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::configContent() |
|
| 106 | + */ |
|
| 107 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 108 | + { |
|
| 109 | + return view($module->name() . '::mappers/filtered-top-config', [ |
|
| 110 | + 'tree' => $tree, |
|
| 111 | + 'top_places' => $this->topPlaces() |
|
| 112 | + ]); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * {@inheritDoc} |
|
| 117 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::withConfigUpdate() |
|
| 118 | - * @return $this |
|
| 119 | - */ |
|
| 120 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 121 | - { |
|
| 122 | - $tree = Validator::attributes($request)->treeOptional(); |
|
| 115 | + /** |
|
| 116 | + * {@inheritDoc} |
|
| 117 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::withConfigUpdate() |
|
| 118 | + * @return $this |
|
| 119 | + */ |
|
| 120 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 121 | + { |
|
| 122 | + $tree = Validator::attributes($request)->treeOptional(); |
|
| 123 | 123 | |
| 124 | - if ($tree === null) { |
|
| 125 | - return $this; |
|
| 126 | - } |
|
| 124 | + if ($tree === null) { |
|
| 125 | + return $this; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - $top_places = Validator::parsedBody($request)->array('mapper_filt_top_places'); |
|
| 129 | - $config = ['topPlaces' => []]; |
|
| 130 | - foreach ($top_places as $top_place_id) { |
|
| 131 | - $place = Place::find((int) $top_place_id, $tree); |
|
| 132 | - if (mb_strlen($place->gedcomName()) > 0) { |
|
| 133 | - $config['topPlaces'][] = $place; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $this->setConfig($config); |
|
| 137 | - return $this; |
|
| 138 | - } |
|
| 128 | + $top_places = Validator::parsedBody($request)->array('mapper_filt_top_places'); |
|
| 129 | + $config = ['topPlaces' => []]; |
|
| 130 | + foreach ($top_places as $top_place_id) { |
|
| 131 | + $place = Place::find((int) $top_place_id, $tree); |
|
| 132 | + if (mb_strlen($place->gedcomName()) > 0) { |
|
| 133 | + $config['topPlaces'][] = $place; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $this->setConfig($config); |
|
| 137 | + return $this; |
|
| 138 | + } |
|
| 139 | 139 | } |
@@ -39,164 +39,164 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class CertificateImageFactory extends ImageFactory implements ImageFactoryInterface |
| 41 | 41 | { |
| 42 | - /** |
|
| 43 | - * @var CertificateFilesystemService $filesystem_service |
|
| 44 | - */ |
|
| 45 | - private $filesystem_service; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Constructor for the Certificate Image Factory |
|
| 49 | - * |
|
| 50 | - * @param CertificateFilesystemService $filesystem_service |
|
| 51 | - */ |
|
| 52 | - public function __construct(CertificateFilesystemService $filesystem_service) |
|
| 53 | - { |
|
| 54 | - $this->filesystem_service = $filesystem_service; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Check is a file MIME type is supported by the system. |
|
| 59 | - * |
|
| 60 | - * @param string $mime |
|
| 61 | - * @return bool |
|
| 62 | - */ |
|
| 63 | - public function isMimeTypeSupported(string $mime): bool |
|
| 64 | - { |
|
| 65 | - return array_key_exists($mime, self::SUPPORTED_FORMATS); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Create a full-size version of a certificate. |
|
| 70 | - * |
|
| 71 | - * @param Certificate $certificate |
|
| 72 | - * @param bool $add_watermark |
|
| 73 | - * @param Watermark $watermark |
|
| 74 | - * @throws InvalidArgumentException |
|
| 75 | - * @return ResponseInterface |
|
| 76 | - */ |
|
| 77 | - public function certificateFileResponse( |
|
| 78 | - Certificate $certificate, |
|
| 79 | - bool $add_watermark = false, |
|
| 80 | - Watermark $watermark = null |
|
| 81 | - ): ResponseInterface { |
|
| 82 | - $filesystem = $this->filesystem_service->filesystem($certificate->tree()); |
|
| 83 | - $filename = $certificate->path(); |
|
| 84 | - |
|
| 85 | - if (!$add_watermark) { |
|
| 86 | - return $this->fileResponse($filesystem, $filename, false); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - try { |
|
| 90 | - $image = $this->imageManager()->make($filesystem->readStream($filename)); |
|
| 91 | - $image = $this->autorotateImage($image); |
|
| 92 | - |
|
| 93 | - if ($watermark === null) { |
|
| 94 | - throw new InvalidArgumentException('Watermark data not defined'); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $width = $image->width(); |
|
| 98 | - $height = $image->height(); |
|
| 99 | - |
|
| 100 | - $watermark->adjustSize($width); |
|
| 101 | - $watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5); |
|
| 102 | - $watermark_y = $watermark->size() * 12 + 1; |
|
| 103 | - |
|
| 104 | - $font_definition = function (AbstractFont $font) use ($watermark): void { |
|
| 105 | - $font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf'); |
|
| 106 | - $font->color($watermark->color()); |
|
| 107 | - $font->size($watermark->size()); |
|
| 108 | - $font->valign('top'); |
|
| 109 | - }; |
|
| 110 | - |
|
| 111 | - for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) { |
|
| 112 | - for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) { |
|
| 113 | - $image = $image->text($watermark->text(), $i, $j, $font_definition); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $format = static::SUPPORTED_FORMATS[$image->mime()] ?? 'jpg'; |
|
| 118 | - $quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY); |
|
| 119 | - $data = (string) $image->encode($format, $quality); |
|
| 120 | - |
|
| 121 | - return $this->imageResponse($data, $image->mime(), ''); |
|
| 122 | - } catch (NotReadableException $ex) { |
|
| 123 | - return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION)) |
|
| 124 | - ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
| 125 | - } catch (FilesystemException | UnableToReadFile $ex) { |
|
| 126 | - return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND); |
|
| 127 | - } catch (Throwable $ex) { |
|
| 128 | - return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR) |
|
| 129 | - ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Does a full-sized certificate need a watermark? |
|
| 135 | - * |
|
| 136 | - * @param Certificate $certificate |
|
| 137 | - * @param UserInterface $user |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - public function certificateNeedsWatermark(Certificate $certificate, UserInterface $user): bool |
|
| 141 | - { |
|
| 142 | - $tree = $certificate->tree(); |
|
| 143 | - $watermark_level = (int) ($tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK', (string) Auth::PRIV_HIDE)); |
|
| 144 | - |
|
| 145 | - return Auth::accessLevel($tree, $user) > $watermark_level; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Neutralise the methods associated with MediaFile. |
|
| 150 | - */ |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * {@inheritDoc} |
|
| 154 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileResponse() |
|
| 155 | - */ |
|
| 156 | - public function mediaFileResponse(MediaFile $media_file, bool $add_watermark, bool $download): ResponseInterface |
|
| 157 | - { |
|
| 158 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * {@inheritDoc} |
|
| 163 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileThumbnailResponse() |
|
| 164 | - */ |
|
| 165 | - public function mediaFileThumbnailResponse( |
|
| 166 | - MediaFile $media_file, |
|
| 167 | - int $width, |
|
| 168 | - int $height, |
|
| 169 | - string $fit, |
|
| 170 | - bool $add_watermark |
|
| 171 | - ): ResponseInterface { |
|
| 172 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * {@inheritDoc} |
|
| 177 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::createWatermark() |
|
| 178 | - */ |
|
| 179 | - public function createWatermark(int $width, int $height, MediaFile $media_file): Image |
|
| 180 | - { |
|
| 181 | - |
|
| 182 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * {@inheritDoc} |
|
| 187 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::fileNeedsWatermark() |
|
| 188 | - */ |
|
| 189 | - public function fileNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
| 190 | - { |
|
| 191 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * {@inheritDoc} |
|
| 196 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::thumbnailNeedsWatermark() |
|
| 197 | - */ |
|
| 198 | - public function thumbnailNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
| 199 | - { |
|
| 200 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 201 | - } |
|
| 42 | + /** |
|
| 43 | + * @var CertificateFilesystemService $filesystem_service |
|
| 44 | + */ |
|
| 45 | + private $filesystem_service; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Constructor for the Certificate Image Factory |
|
| 49 | + * |
|
| 50 | + * @param CertificateFilesystemService $filesystem_service |
|
| 51 | + */ |
|
| 52 | + public function __construct(CertificateFilesystemService $filesystem_service) |
|
| 53 | + { |
|
| 54 | + $this->filesystem_service = $filesystem_service; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Check is a file MIME type is supported by the system. |
|
| 59 | + * |
|
| 60 | + * @param string $mime |
|
| 61 | + * @return bool |
|
| 62 | + */ |
|
| 63 | + public function isMimeTypeSupported(string $mime): bool |
|
| 64 | + { |
|
| 65 | + return array_key_exists($mime, self::SUPPORTED_FORMATS); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Create a full-size version of a certificate. |
|
| 70 | + * |
|
| 71 | + * @param Certificate $certificate |
|
| 72 | + * @param bool $add_watermark |
|
| 73 | + * @param Watermark $watermark |
|
| 74 | + * @throws InvalidArgumentException |
|
| 75 | + * @return ResponseInterface |
|
| 76 | + */ |
|
| 77 | + public function certificateFileResponse( |
|
| 78 | + Certificate $certificate, |
|
| 79 | + bool $add_watermark = false, |
|
| 80 | + Watermark $watermark = null |
|
| 81 | + ): ResponseInterface { |
|
| 82 | + $filesystem = $this->filesystem_service->filesystem($certificate->tree()); |
|
| 83 | + $filename = $certificate->path(); |
|
| 84 | + |
|
| 85 | + if (!$add_watermark) { |
|
| 86 | + return $this->fileResponse($filesystem, $filename, false); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + try { |
|
| 90 | + $image = $this->imageManager()->make($filesystem->readStream($filename)); |
|
| 91 | + $image = $this->autorotateImage($image); |
|
| 92 | + |
|
| 93 | + if ($watermark === null) { |
|
| 94 | + throw new InvalidArgumentException('Watermark data not defined'); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $width = $image->width(); |
|
| 98 | + $height = $image->height(); |
|
| 99 | + |
|
| 100 | + $watermark->adjustSize($width); |
|
| 101 | + $watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5); |
|
| 102 | + $watermark_y = $watermark->size() * 12 + 1; |
|
| 103 | + |
|
| 104 | + $font_definition = function (AbstractFont $font) use ($watermark): void { |
|
| 105 | + $font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf'); |
|
| 106 | + $font->color($watermark->color()); |
|
| 107 | + $font->size($watermark->size()); |
|
| 108 | + $font->valign('top'); |
|
| 109 | + }; |
|
| 110 | + |
|
| 111 | + for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) { |
|
| 112 | + for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) { |
|
| 113 | + $image = $image->text($watermark->text(), $i, $j, $font_definition); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $format = static::SUPPORTED_FORMATS[$image->mime()] ?? 'jpg'; |
|
| 118 | + $quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY); |
|
| 119 | + $data = (string) $image->encode($format, $quality); |
|
| 120 | + |
|
| 121 | + return $this->imageResponse($data, $image->mime(), ''); |
|
| 122 | + } catch (NotReadableException $ex) { |
|
| 123 | + return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION)) |
|
| 124 | + ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
| 125 | + } catch (FilesystemException | UnableToReadFile $ex) { |
|
| 126 | + return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND); |
|
| 127 | + } catch (Throwable $ex) { |
|
| 128 | + return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR) |
|
| 129 | + ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Does a full-sized certificate need a watermark? |
|
| 135 | + * |
|
| 136 | + * @param Certificate $certificate |
|
| 137 | + * @param UserInterface $user |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + public function certificateNeedsWatermark(Certificate $certificate, UserInterface $user): bool |
|
| 141 | + { |
|
| 142 | + $tree = $certificate->tree(); |
|
| 143 | + $watermark_level = (int) ($tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK', (string) Auth::PRIV_HIDE)); |
|
| 144 | + |
|
| 145 | + return Auth::accessLevel($tree, $user) > $watermark_level; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Neutralise the methods associated with MediaFile. |
|
| 150 | + */ |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * {@inheritDoc} |
|
| 154 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileResponse() |
|
| 155 | + */ |
|
| 156 | + public function mediaFileResponse(MediaFile $media_file, bool $add_watermark, bool $download): ResponseInterface |
|
| 157 | + { |
|
| 158 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * {@inheritDoc} |
|
| 163 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileThumbnailResponse() |
|
| 164 | + */ |
|
| 165 | + public function mediaFileThumbnailResponse( |
|
| 166 | + MediaFile $media_file, |
|
| 167 | + int $width, |
|
| 168 | + int $height, |
|
| 169 | + string $fit, |
|
| 170 | + bool $add_watermark |
|
| 171 | + ): ResponseInterface { |
|
| 172 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * {@inheritDoc} |
|
| 177 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::createWatermark() |
|
| 178 | + */ |
|
| 179 | + public function createWatermark(int $width, int $height, MediaFile $media_file): Image |
|
| 180 | + { |
|
| 181 | + |
|
| 182 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * {@inheritDoc} |
|
| 187 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::fileNeedsWatermark() |
|
| 188 | + */ |
|
| 189 | + public function fileNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
| 190 | + { |
|
| 191 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * {@inheritDoc} |
|
| 196 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::thumbnailNeedsWatermark() |
|
| 197 | + */ |
|
| 198 | + public function thumbnailNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
| 199 | + { |
|
| 200 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 201 | + } |
|
| 202 | 202 | } |
@@ -35,79 +35,79 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class CertificatePage implements RequestHandlerInterface |
| 37 | 37 | { |
| 38 | - use ViewResponseTrait; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var CertificatesModule|null $module |
|
| 42 | - */ |
|
| 43 | - private $module; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var CertificateFilesystemService $certif_filesystem |
|
| 47 | - */ |
|
| 48 | - private $certif_filesystem; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var CertificateDataService $certif_data_service |
|
| 52 | - */ |
|
| 53 | - private $certif_data_service; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var UrlObfuscatorService $url_obfuscator_service |
|
| 57 | - */ |
|
| 58 | - private $url_obfuscator_service; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Constructor for CertificatePage Request Handler |
|
| 63 | - * |
|
| 64 | - * @param ModuleService $module_service |
|
| 65 | - * @param CertificateFilesystemService $certif_filesystem |
|
| 66 | - * @param CertificateDataService $certif_data_service |
|
| 67 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
| 68 | - */ |
|
| 69 | - public function __construct( |
|
| 70 | - ModuleService $module_service, |
|
| 71 | - CertificateFilesystemService $certif_filesystem, |
|
| 72 | - CertificateDataService $certif_data_service, |
|
| 73 | - UrlObfuscatorService $url_obfuscator_service |
|
| 74 | - ) { |
|
| 75 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 76 | - $this->certif_filesystem = $certif_filesystem; |
|
| 77 | - $this->certif_data_service = $certif_data_service; |
|
| 78 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * {@inheritDoc} |
|
| 83 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 84 | - */ |
|
| 85 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 86 | - { |
|
| 87 | - if ($this->module === null) { |
|
| 88 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $tree = Validator::attributes($request)->tree(); |
|
| 92 | - |
|
| 93 | - $certif_path = Validator::attributes($request)->string('cid', ''); |
|
| 94 | - if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
| 95 | - $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - if (!isset($certificate)) { |
|
| 99 | - FlashMessages::addMessage('The requested certificate is not valid.'); |
|
| 100 | - return Registry::responseFactory()->redirect(TreePage::class, ['tree' => $tree->name()]); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return $this->viewResponse($this->module->name() . '::certificate-page', [ |
|
| 104 | - 'title' => I18N::translate('Certificate - %s', $certificate->name()), |
|
| 105 | - 'tree' => $tree, |
|
| 106 | - 'module_name' => $this->module->name(), |
|
| 107 | - 'certificate' => $certificate, |
|
| 108 | - 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
| 109 | - 'linked_individuals' => $this->certif_data_service->linkedIndividuals($certificate), |
|
| 110 | - 'linked_families' => $this->certif_data_service->linkedFamilies($certificate) |
|
| 111 | - ]); |
|
| 112 | - } |
|
| 38 | + use ViewResponseTrait; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var CertificatesModule|null $module |
|
| 42 | + */ |
|
| 43 | + private $module; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var CertificateFilesystemService $certif_filesystem |
|
| 47 | + */ |
|
| 48 | + private $certif_filesystem; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var CertificateDataService $certif_data_service |
|
| 52 | + */ |
|
| 53 | + private $certif_data_service; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var UrlObfuscatorService $url_obfuscator_service |
|
| 57 | + */ |
|
| 58 | + private $url_obfuscator_service; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Constructor for CertificatePage Request Handler |
|
| 63 | + * |
|
| 64 | + * @param ModuleService $module_service |
|
| 65 | + * @param CertificateFilesystemService $certif_filesystem |
|
| 66 | + * @param CertificateDataService $certif_data_service |
|
| 67 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
| 68 | + */ |
|
| 69 | + public function __construct( |
|
| 70 | + ModuleService $module_service, |
|
| 71 | + CertificateFilesystemService $certif_filesystem, |
|
| 72 | + CertificateDataService $certif_data_service, |
|
| 73 | + UrlObfuscatorService $url_obfuscator_service |
|
| 74 | + ) { |
|
| 75 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 76 | + $this->certif_filesystem = $certif_filesystem; |
|
| 77 | + $this->certif_data_service = $certif_data_service; |
|
| 78 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * {@inheritDoc} |
|
| 83 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 84 | + */ |
|
| 85 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 86 | + { |
|
| 87 | + if ($this->module === null) { |
|
| 88 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $tree = Validator::attributes($request)->tree(); |
|
| 92 | + |
|
| 93 | + $certif_path = Validator::attributes($request)->string('cid', ''); |
|
| 94 | + if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
| 95 | + $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + if (!isset($certificate)) { |
|
| 99 | + FlashMessages::addMessage('The requested certificate is not valid.'); |
|
| 100 | + return Registry::responseFactory()->redirect(TreePage::class, ['tree' => $tree->name()]); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return $this->viewResponse($this->module->name() . '::certificate-page', [ |
|
| 104 | + 'title' => I18N::translate('Certificate - %s', $certificate->name()), |
|
| 105 | + 'tree' => $tree, |
|
| 106 | + 'module_name' => $this->module->name(), |
|
| 107 | + 'certificate' => $certificate, |
|
| 108 | + 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
| 109 | + 'linked_individuals' => $this->certif_data_service->linkedIndividuals($certificate), |
|
| 110 | + 'linked_families' => $this->certif_data_service->linkedFamilies($certificate) |
|
| 111 | + ]); |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -19,112 +19,112 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Watermark |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Default font color for watermarks |
|
| 24 | - * @var string DEFAULT_COLOR |
|
| 25 | - * */ |
|
| 26 | - public const DEFAULT_COLOR = '#4D6DF3'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Default maximum font size for watermarks |
|
| 30 | - * @var int DEFAULT_SIZE |
|
| 31 | - * */ |
|
| 32 | - public const DEFAULT_SIZE = 18; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string $text |
|
| 36 | - */ |
|
| 37 | - private $text; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var string $color; |
|
| 41 | - */ |
|
| 42 | - private $color; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var int $size |
|
| 47 | - */ |
|
| 48 | - private $size; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Constructor for Watermark data class |
|
| 52 | - * |
|
| 53 | - * @param string $text |
|
| 54 | - * @param string $color |
|
| 55 | - * @param int $size |
|
| 56 | - */ |
|
| 57 | - public function __construct(string $text, string $color, int $size) |
|
| 58 | - { |
|
| 59 | - $this->text = $text; |
|
| 60 | - $this->color = $color; |
|
| 61 | - $this->size = $size; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the watermark text. |
|
| 66 | - * |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function text(): string |
|
| 70 | - { |
|
| 71 | - return $this->text; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Get the watermark font color. |
|
| 76 | - * |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public function color(): string |
|
| 80 | - { |
|
| 81 | - return $this->color; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Get the watermark maximum font size. |
|
| 86 | - * @return int |
|
| 87 | - */ |
|
| 88 | - public function size(): int |
|
| 89 | - { |
|
| 90 | - return $this->size; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Return an estimate of the size in pixels of the watermark text length. |
|
| 95 | - * |
|
| 96 | - * @return int |
|
| 97 | - */ |
|
| 98 | - public function textLengthEstimate(): int |
|
| 99 | - { |
|
| 100 | - return $this->stringLengthEstimate(mb_strlen($this->text), $this->size); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Decrease the font size if necessary, based on the image width. |
|
| 105 | - * |
|
| 106 | - * @param int $width |
|
| 107 | - */ |
|
| 108 | - public function adjustSize(int $width): void |
|
| 109 | - { |
|
| 110 | - $len = mb_strlen($this->text); |
|
| 111 | - while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) { |
|
| 112 | - $this->size--; |
|
| 113 | - if ($this->size === 2) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Return an estimate of the size in pixels of a text in a specified font size. |
|
| 121 | - * |
|
| 122 | - * @param int $text_length |
|
| 123 | - * @param int $font_size |
|
| 124 | - * @return int |
|
| 125 | - */ |
|
| 126 | - private function stringLengthEstimate(int $text_length, int $font_size): int |
|
| 127 | - { |
|
| 128 | - return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
| 129 | - } |
|
| 22 | + /** |
|
| 23 | + * Default font color for watermarks |
|
| 24 | + * @var string DEFAULT_COLOR |
|
| 25 | + * */ |
|
| 26 | + public const DEFAULT_COLOR = '#4D6DF3'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Default maximum font size for watermarks |
|
| 30 | + * @var int DEFAULT_SIZE |
|
| 31 | + * */ |
|
| 32 | + public const DEFAULT_SIZE = 18; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var string $text |
|
| 36 | + */ |
|
| 37 | + private $text; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var string $color; |
|
| 41 | + */ |
|
| 42 | + private $color; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var int $size |
|
| 47 | + */ |
|
| 48 | + private $size; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Constructor for Watermark data class |
|
| 52 | + * |
|
| 53 | + * @param string $text |
|
| 54 | + * @param string $color |
|
| 55 | + * @param int $size |
|
| 56 | + */ |
|
| 57 | + public function __construct(string $text, string $color, int $size) |
|
| 58 | + { |
|
| 59 | + $this->text = $text; |
|
| 60 | + $this->color = $color; |
|
| 61 | + $this->size = $size; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the watermark text. |
|
| 66 | + * |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function text(): string |
|
| 70 | + { |
|
| 71 | + return $this->text; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Get the watermark font color. |
|
| 76 | + * |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public function color(): string |
|
| 80 | + { |
|
| 81 | + return $this->color; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Get the watermark maximum font size. |
|
| 86 | + * @return int |
|
| 87 | + */ |
|
| 88 | + public function size(): int |
|
| 89 | + { |
|
| 90 | + return $this->size; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Return an estimate of the size in pixels of the watermark text length. |
|
| 95 | + * |
|
| 96 | + * @return int |
|
| 97 | + */ |
|
| 98 | + public function textLengthEstimate(): int |
|
| 99 | + { |
|
| 100 | + return $this->stringLengthEstimate(mb_strlen($this->text), $this->size); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Decrease the font size if necessary, based on the image width. |
|
| 105 | + * |
|
| 106 | + * @param int $width |
|
| 107 | + */ |
|
| 108 | + public function adjustSize(int $width): void |
|
| 109 | + { |
|
| 110 | + $len = mb_strlen($this->text); |
|
| 111 | + while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) { |
|
| 112 | + $this->size--; |
|
| 113 | + if ($this->size === 2) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Return an estimate of the size in pixels of a text in a specified font size. |
|
| 121 | + * |
|
| 122 | + * @param int $text_length |
|
| 123 | + * @param int $font_size |
|
| 124 | + * @return int |
|
| 125 | + */ |
|
| 126 | + private function stringLengthEstimate(int $text_length, int $font_size): int |
|
| 127 | + { |
|
| 128 | + return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -30,87 +30,87 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SourceCertificateIconHook implements FactSourceTextExtenderInterface |
| 32 | 32 | { |
| 33 | - private CertificatesModule $module; |
|
| 34 | - private UrlObfuscatorService $url_obfuscator_service; |
|
| 33 | + private CertificatesModule $module; |
|
| 34 | + private UrlObfuscatorService $url_obfuscator_service; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for SourceCertificateIconHook |
|
| 38 | - * |
|
| 39 | - * @param CertificatesModule $module |
|
| 40 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
| 41 | - */ |
|
| 42 | - public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
| 43 | - { |
|
| 44 | - $this->module = $module; |
|
| 45 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 46 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for SourceCertificateIconHook |
|
| 38 | + * |
|
| 39 | + * @param CertificatesModule $module |
|
| 40 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
| 41 | + */ |
|
| 42 | + public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
| 43 | + { |
|
| 44 | + $this->module = $module; |
|
| 45 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * {@inheritDoc} |
|
| 50 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 51 | - */ |
|
| 52 | - public function module(): ModuleInterface |
|
| 53 | - { |
|
| 54 | - return $this->module; |
|
| 55 | - } |
|
| 48 | + /** |
|
| 49 | + * {@inheritDoc} |
|
| 50 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 51 | + */ |
|
| 52 | + public function module(): ModuleInterface |
|
| 53 | + { |
|
| 54 | + return $this->module; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * {@inheritDoc} |
|
| 59 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
| 60 | - */ |
|
| 61 | - public function factSourcePrepend(Tree $tree, $fact): string |
|
| 62 | - { |
|
| 63 | - $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
| 64 | - if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level) { |
|
| 65 | - $path = $this->extractPath($fact); |
|
| 57 | + /** |
|
| 58 | + * {@inheritDoc} |
|
| 59 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
| 60 | + */ |
|
| 61 | + public function factSourcePrepend(Tree $tree, $fact): string |
|
| 62 | + { |
|
| 63 | + $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
| 64 | + if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level) { |
|
| 65 | + $path = $this->extractPath($fact); |
|
| 66 | 66 | |
| 67 | - if ($path !== '') { |
|
| 68 | - $certificate = new Certificate($tree, $path); |
|
| 69 | - return view($this->module->name() . '::components/certificate-icon', [ |
|
| 70 | - 'module_name' => $this->module->name(), |
|
| 71 | - 'certificate' => $certificate, |
|
| 72 | - 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
| 73 | - 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
| 74 | - ]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - return ''; |
|
| 78 | - } |
|
| 67 | + if ($path !== '') { |
|
| 68 | + $certificate = new Certificate($tree, $path); |
|
| 69 | + return view($this->module->name() . '::components/certificate-icon', [ |
|
| 70 | + 'module_name' => $this->module->name(), |
|
| 71 | + 'certificate' => $certificate, |
|
| 72 | + 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
| 73 | + 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
| 74 | + ]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + return ''; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Extract path from the provided fact objet. |
|
| 82 | - * |
|
| 83 | - * @param \Fisharebest\Webtrees\Fact|array<array<\Fisharebest\Webtrees\Contracts\ElementInterface|string>> $fact |
|
| 84 | - * @return string |
|
| 85 | - * @psalm-suppress RedundantConditionGivenDocblockType |
|
| 86 | - */ |
|
| 87 | - private function extractPath($fact): string |
|
| 88 | - { |
|
| 89 | - if ($fact instanceof Fact && $fact->target() instanceof Source) { |
|
| 90 | - return $fact->attribute('_ACT'); |
|
| 91 | - } elseif ( |
|
| 92 | - is_array($fact) && count($fact) === 2 |
|
| 93 | - && null !== ($source_elements = $fact[0]) && is_array($source_elements) // @phpstan-ignore-line |
|
| 94 | - && null !== ($source_values = $fact[1]) && is_array($source_values) // @phpstan-ignore-line |
|
| 95 | - ) { |
|
| 96 | - foreach ($source_elements as $key => $element) { |
|
| 97 | - if ( |
|
| 98 | - $element instanceof SourceCertificate |
|
| 99 | - && isset($source_values[$key]) && is_string($source_values[$key]) |
|
| 100 | - ) { |
|
| 101 | - return $element->canonical($source_values[$key]); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - return ''; |
|
| 106 | - } |
|
| 80 | + /** |
|
| 81 | + * Extract path from the provided fact objet. |
|
| 82 | + * |
|
| 83 | + * @param \Fisharebest\Webtrees\Fact|array<array<\Fisharebest\Webtrees\Contracts\ElementInterface|string>> $fact |
|
| 84 | + * @return string |
|
| 85 | + * @psalm-suppress RedundantConditionGivenDocblockType |
|
| 86 | + */ |
|
| 87 | + private function extractPath($fact): string |
|
| 88 | + { |
|
| 89 | + if ($fact instanceof Fact && $fact->target() instanceof Source) { |
|
| 90 | + return $fact->attribute('_ACT'); |
|
| 91 | + } elseif ( |
|
| 92 | + is_array($fact) && count($fact) === 2 |
|
| 93 | + && null !== ($source_elements = $fact[0]) && is_array($source_elements) // @phpstan-ignore-line |
|
| 94 | + && null !== ($source_values = $fact[1]) && is_array($source_values) // @phpstan-ignore-line |
|
| 95 | + ) { |
|
| 96 | + foreach ($source_elements as $key => $element) { |
|
| 97 | + if ( |
|
| 98 | + $element instanceof SourceCertificate |
|
| 99 | + && isset($source_values[$key]) && is_string($source_values[$key]) |
|
| 100 | + ) { |
|
| 101 | + return $element->canonical($source_values[$key]); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + return ''; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * {@inheritDoc} |
|
| 110 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
| 111 | - */ |
|
| 112 | - public function factSourceAppend(Tree $tree, $fact): string |
|
| 113 | - { |
|
| 114 | - return ''; |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * {@inheritDoc} |
|
| 110 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
| 111 | + */ |
|
| 112 | + public function factSourceAppend(Tree $tree, $fact): string |
|
| 113 | + { |
|
| 114 | + return ''; |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -31,58 +31,58 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class ModulesHooksAction extends AbstractModuleComponentAction |
| 33 | 33 | { |
| 34 | - protected HookService $hook_service; |
|
| 34 | + protected HookService $hook_service; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for ModulesHooksAction Request Handler |
|
| 38 | - * |
|
| 39 | - * @param ModuleService $module_service |
|
| 40 | - * @param TreeService $tree_service |
|
| 41 | - * @param HookService $hook_service |
|
| 42 | - */ |
|
| 43 | - public function __construct(ModuleService $module_service, TreeService $tree_service, HookService $hook_service) |
|
| 44 | - { |
|
| 45 | - parent::__construct($module_service, $tree_service); |
|
| 46 | - $this->hook_service = $hook_service; |
|
| 47 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for ModulesHooksAction Request Handler |
|
| 38 | + * |
|
| 39 | + * @param ModuleService $module_service |
|
| 40 | + * @param TreeService $tree_service |
|
| 41 | + * @param HookService $hook_service |
|
| 42 | + */ |
|
| 43 | + public function __construct(ModuleService $module_service, TreeService $tree_service, HookService $hook_service) |
|
| 44 | + { |
|
| 45 | + parent::__construct($module_service, $tree_service); |
|
| 46 | + $this->hook_service = $hook_service; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * {@inheritDoc} |
|
| 51 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 52 | - */ |
|
| 53 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 54 | - { |
|
| 55 | - $hook_name = Validator::attributes($request)->string('hook_name', ''); |
|
| 56 | - $hook_collector = $this->hook_service->find($hook_name, true); |
|
| 57 | - if ($hook_collector === null) { |
|
| 58 | - FlashMessages::addMessage(I18N::translate('The hook with name “%s” does not exist.', $hook_name), 'danger'); |
|
| 59 | - return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
| 60 | - } |
|
| 49 | + /** |
|
| 50 | + * {@inheritDoc} |
|
| 51 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 52 | + */ |
|
| 53 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 54 | + { |
|
| 55 | + $hook_name = Validator::attributes($request)->string('hook_name', ''); |
|
| 56 | + $hook_collector = $this->hook_service->find($hook_name, true); |
|
| 57 | + if ($hook_collector === null) { |
|
| 58 | + FlashMessages::addMessage(I18N::translate('The hook with name “%s” does not exist.', $hook_name), 'danger'); |
|
| 59 | + return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - foreach ($hook_collector->hooks() as $hook) { |
|
| 63 | - $this->updateStatus(get_class($hook->module()), $request); |
|
| 64 | - } |
|
| 62 | + foreach ($hook_collector->hooks() as $hook) { |
|
| 63 | + $this->updateStatus(get_class($hook->module()), $request); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $this->updateHookOrder($hook_collector, $request); |
|
| 66 | + $this->updateHookOrder($hook_collector, $request); |
|
| 67 | 67 | |
| 68 | - FlashMessages::addMessage(I18N::translate('The hook preferences have been updated.'), 'success'); |
|
| 68 | + FlashMessages::addMessage(I18N::translate('The hook preferences have been updated.'), 'success'); |
|
| 69 | 69 | |
| 70 | - return Registry::responseFactory()->redirect(ModulesHooksPage::class, ['hook_name' => $hook_name]); |
|
| 71 | - } |
|
| 70 | + return Registry::responseFactory()->redirect(ModulesHooksPage::class, ['hook_name' => $hook_name]); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Update the order of modules for a hook interface. |
|
| 75 | - * |
|
| 76 | - * @param HookCollectorInterface $hook_collector |
|
| 77 | - * @param ServerRequestInterface $request |
|
| 78 | - */ |
|
| 79 | - protected function updateHookOrder(HookCollectorInterface $hook_collector, ServerRequestInterface $request): void |
|
| 80 | - { |
|
| 81 | - $order = Validator::parsedBody($request)->array('order'); |
|
| 82 | - $order = array_flip($order); |
|
| 73 | + /** |
|
| 74 | + * Update the order of modules for a hook interface. |
|
| 75 | + * |
|
| 76 | + * @param HookCollectorInterface $hook_collector |
|
| 77 | + * @param ServerRequestInterface $request |
|
| 78 | + */ |
|
| 79 | + protected function updateHookOrder(HookCollectorInterface $hook_collector, ServerRequestInterface $request): void |
|
| 80 | + { |
|
| 81 | + $order = Validator::parsedBody($request)->array('order'); |
|
| 82 | + $order = array_flip($order); |
|
| 83 | 83 | |
| 84 | - foreach ($hook_collector->hooks() as $hook) { |
|
| 85 | - $this->hook_service->updateOrder($hook_collector, $hook->module(), $order[$hook->module()->name()] ?? 0); |
|
| 86 | - } |
|
| 87 | - } |
|
| 84 | + foreach ($hook_collector->hooks() as $hook) { |
|
| 85 | + $this->hook_service->updateOrder($hook_collector, $hook->module(), $order[$hook->module()->name()] ?? 0); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -31,54 +31,54 @@ |
||
| 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 | - $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
|
| 55 | - $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
|
| 54 | + $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
|
| 55 | + $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
|
| 56 | 56 | |
| 57 | - if (($user_id === -1 && Auth::isManager($tree)) || Auth::id() === $user_id) { |
|
| 58 | - $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 57 | + if (($user_id === -1 && Auth::isManager($tree)) || Auth::id() === $user_id) { |
|
| 58 | + $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 59 | 59 | |
| 60 | - /** @var SosaCalculatorService $sosa_calc_service */ |
|
| 61 | - $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
| 60 | + /** @var SosaCalculatorService $sosa_calc_service */ |
|
| 61 | + $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
| 62 | 62 | |
| 63 | - if ( |
|
| 64 | - $partial_from !== '' && |
|
| 65 | - ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
| 66 | - ) { |
|
| 67 | - $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
| 68 | - } else { |
|
| 69 | - $res = $sosa_calc_service->computeAll(); |
|
| 70 | - } |
|
| 63 | + if ( |
|
| 64 | + $partial_from !== '' && |
|
| 65 | + ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
| 66 | + ) { |
|
| 67 | + $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
| 68 | + } else { |
|
| 69 | + $res = $sosa_calc_service->computeAll(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return $res ? |
|
| 73 | - Registry::responseFactory()->response() : |
|
| 74 | - Registry::responseFactory()->response( |
|
| 75 | - I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
| 76 | - StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - return Registry::responseFactory()->response( |
|
| 80 | - I18N::translate('You do not have permission to modify the user.'), |
|
| 81 | - StatusCodeInterface::STATUS_FORBIDDEN |
|
| 82 | - ); |
|
| 83 | - } |
|
| 72 | + return $res ? |
|
| 73 | + Registry::responseFactory()->response() : |
|
| 74 | + Registry::responseFactory()->response( |
|
| 75 | + I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
| 76 | + StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + return Registry::responseFactory()->response( |
|
| 80 | + I18N::translate('You do not have permission to modify the user.'), |
|
| 81 | + StatusCodeInterface::STATUS_FORBIDDEN |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -33,71 +33,71 @@ |
||
| 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 | - return $this->viewResponse($this->module->name() . '::config-page', [ |
|
| 94 | - 'module_name' => $this->module->name(), |
|
| 95 | - 'title' => I18N::translate('Sosa Configuration'), |
|
| 96 | - 'tree' => $tree, |
|
| 97 | - 'user_id' => Validator::attributes($request)->user(), |
|
| 98 | - 'selected_user_id' => Validator::queryParams($request)->integer('user_id', 0), |
|
| 99 | - 'immediate_compute' => Validator::queryParams($request)->string('compute', '') === 'yes', |
|
| 100 | - 'users_root' => $users_root |
|
| 101 | - ]); |
|
| 102 | - } |
|
| 93 | + return $this->viewResponse($this->module->name() . '::config-page', [ |
|
| 94 | + 'module_name' => $this->module->name(), |
|
| 95 | + 'title' => I18N::translate('Sosa Configuration'), |
|
| 96 | + 'tree' => $tree, |
|
| 97 | + 'user_id' => Validator::attributes($request)->user(), |
|
| 98 | + 'selected_user_id' => Validator::queryParams($request)->integer('user_id', 0), |
|
| 99 | + 'immediate_compute' => Validator::queryParams($request)->string('compute', '') === 'yes', |
|
| 100 | + 'users_root' => $users_root |
|
| 101 | + ]); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -31,51 +31,51 @@ |
||
| 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 | - $user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
|
| 58 | - $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
|
| 59 | - $max_gen = Validator::parsedBody($request)->integer( |
|
| 60 | - 'sosa-maxgen', |
|
| 61 | - $this->sosa_record_service->maxSystemGenerations() |
|
| 62 | - ); |
|
| 57 | + $user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
|
| 58 | + $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
|
| 59 | + $max_gen = Validator::parsedBody($request)->integer( |
|
| 60 | + 'sosa-maxgen', |
|
| 61 | + $this->sosa_record_service->maxSystemGenerations() |
|
| 62 | + ); |
|
| 63 | 63 | |
| 64 | - if (Auth::id() === $user_id || ($user_id === -1 && Auth::isManager($tree))) { |
|
| 65 | - $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 66 | - if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
| 67 | - $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
| 68 | - $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
| 69 | - FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
| 70 | - return Registry::responseFactory()->redirect(SosaConfig::class, [ |
|
| 71 | - 'tree' => $tree->name(), |
|
| 72 | - 'compute' => 'yes', |
|
| 73 | - 'user_id' => $user_id |
|
| 74 | - ]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 64 | + if (Auth::id() === $user_id || ($user_id === -1 && Auth::isManager($tree))) { |
|
| 65 | + $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 66 | + if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
| 67 | + $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
| 68 | + $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
| 69 | + FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
| 70 | + return Registry::responseFactory()->redirect(SosaConfig::class, [ |
|
| 71 | + 'tree' => $tree->name(), |
|
| 72 | + 'compute' => 'yes', |
|
| 73 | + 'user_id' => $user_id |
|
| 74 | + ]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
| 79 | - return Registry::responseFactory()->redirect(SosaConfig::class, ['tree' => $tree->name()]); |
|
| 80 | - } |
|
| 78 | + FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
| 79 | + return Registry::responseFactory()->redirect(SosaConfig::class, ['tree' => $tree->name()]); |
|
| 80 | + } |
|
| 81 | 81 | } |