@@ -32,74 +32,74 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class GeoAnalysisViewListData implements RequestHandlerInterface |
| 34 | 34 | { |
| 35 | - private ?GeoDispersionModule $module; |
|
| 36 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
| 35 | + private ?GeoDispersionModule $module; |
|
| 36 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor for GeoAnalysisViewListData Request Handler |
|
| 40 | - * |
|
| 41 | - * @param ModuleService $module_service |
|
| 42 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 43 | - */ |
|
| 44 | - public function __construct( |
|
| 45 | - ModuleService $module_service, |
|
| 46 | - GeoAnalysisViewDataService $geoview_data_service |
|
| 47 | - ) { |
|
| 48 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 49 | - $this->geoview_data_service = $geoview_data_service; |
|
| 50 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor for GeoAnalysisViewListData Request Handler |
|
| 40 | + * |
|
| 41 | + * @param ModuleService $module_service |
|
| 42 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 43 | + */ |
|
| 44 | + public function __construct( |
|
| 45 | + ModuleService $module_service, |
|
| 46 | + GeoAnalysisViewDataService $geoview_data_service |
|
| 47 | + ) { |
|
| 48 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 49 | + $this->geoview_data_service = $geoview_data_service; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 55 | - */ |
|
| 56 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 57 | - { |
|
| 58 | - if ($this->module === null) { |
|
| 59 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 55 | + */ |
|
| 56 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 57 | + { |
|
| 58 | + if ($this->module === null) { |
|
| 59 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $tree = Validator::attributes($request)->tree(); |
|
| 62 | + $tree = Validator::attributes($request)->tree(); |
|
| 63 | 63 | |
| 64 | - $module = $this->module; |
|
| 65 | - $module_name = $this->module->name(); |
|
| 66 | - return Registry::responseFactory()->response(['data' => $this->geoview_data_service->all($tree, true) |
|
| 67 | - ->map(fn(AbstractGeoAnalysisView $view) => [ |
|
| 68 | - 'edit' => view($module_name . '::admin/view-table-options', [ |
|
| 69 | - 'view_id' => $view->id(), |
|
| 70 | - 'view_enabled' => $view->isEnabled(), |
|
| 71 | - 'view_edit_route' => route(GeoAnalysisViewEditPage::class, [ |
|
| 72 | - 'tree' => $tree->name(), |
|
| 73 | - 'view_id' => $view->id() |
|
| 74 | - ]), |
|
| 75 | - 'view_delete_route' => route(GeoAnalysisViewDeleteAction::class, [ |
|
| 76 | - 'tree' => $tree->name(), |
|
| 77 | - 'view_id' => $view->id() |
|
| 78 | - ]), |
|
| 79 | - 'view_status_route' => route(GeoAnalysisViewStatusAction::class, [ |
|
| 80 | - 'tree' => $tree->name(), |
|
| 81 | - 'view_id' => $view->id(), |
|
| 82 | - 'enable' => $view->isEnabled() ? 0 : 1 |
|
| 83 | - ]), |
|
| 84 | - ]), |
|
| 85 | - 'enabled' => [ |
|
| 86 | - 'display' => view($module_name . '::components/yes-no-icons', ['yes' => $view->isEnabled()]), |
|
| 87 | - 'raw' => $view->isEnabled() ? 0 : 1 |
|
| 88 | - ], |
|
| 89 | - 'type' => $view->icon($module), |
|
| 90 | - 'description' => [ |
|
| 91 | - 'display' => '<bdi>' . e($view->description()) . '</bdi>', |
|
| 92 | - 'raw' => e($view->description()) |
|
| 93 | - ], |
|
| 94 | - 'analysis' => [ |
|
| 95 | - 'display' => '<bdi>' . e($view->analysis()->title()) . '</bdi>', |
|
| 96 | - 'raw' => e($view->analysis()->title()) |
|
| 97 | - ], |
|
| 98 | - 'place_depth' => [ |
|
| 99 | - 'display' => I18N::number($view->placesDepth()), |
|
| 100 | - 'raw' => $view->placesDepth() |
|
| 101 | - ] |
|
| 102 | - ]) |
|
| 103 | - ]); |
|
| 104 | - } |
|
| 64 | + $module = $this->module; |
|
| 65 | + $module_name = $this->module->name(); |
|
| 66 | + return Registry::responseFactory()->response(['data' => $this->geoview_data_service->all($tree, true) |
|
| 67 | + ->map(fn(AbstractGeoAnalysisView $view) => [ |
|
| 68 | + 'edit' => view($module_name . '::admin/view-table-options', [ |
|
| 69 | + 'view_id' => $view->id(), |
|
| 70 | + 'view_enabled' => $view->isEnabled(), |
|
| 71 | + 'view_edit_route' => route(GeoAnalysisViewEditPage::class, [ |
|
| 72 | + 'tree' => $tree->name(), |
|
| 73 | + 'view_id' => $view->id() |
|
| 74 | + ]), |
|
| 75 | + 'view_delete_route' => route(GeoAnalysisViewDeleteAction::class, [ |
|
| 76 | + 'tree' => $tree->name(), |
|
| 77 | + 'view_id' => $view->id() |
|
| 78 | + ]), |
|
| 79 | + 'view_status_route' => route(GeoAnalysisViewStatusAction::class, [ |
|
| 80 | + 'tree' => $tree->name(), |
|
| 81 | + 'view_id' => $view->id(), |
|
| 82 | + 'enable' => $view->isEnabled() ? 0 : 1 |
|
| 83 | + ]), |
|
| 84 | + ]), |
|
| 85 | + 'enabled' => [ |
|
| 86 | + 'display' => view($module_name . '::components/yes-no-icons', ['yes' => $view->isEnabled()]), |
|
| 87 | + 'raw' => $view->isEnabled() ? 0 : 1 |
|
| 88 | + ], |
|
| 89 | + 'type' => $view->icon($module), |
|
| 90 | + 'description' => [ |
|
| 91 | + 'display' => '<bdi>' . e($view->description()) . '</bdi>', |
|
| 92 | + 'raw' => e($view->description()) |
|
| 93 | + ], |
|
| 94 | + 'analysis' => [ |
|
| 95 | + 'display' => '<bdi>' . e($view->analysis()->title()) . '</bdi>', |
|
| 96 | + 'raw' => e($view->analysis()->title()) |
|
| 97 | + ], |
|
| 98 | + 'place_depth' => [ |
|
| 99 | + 'display' => I18N::number($view->placesDepth()), |
|
| 100 | + 'raw' => $view->placesDepth() |
|
| 101 | + ] |
|
| 102 | + ]) |
|
| 103 | + ]); |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $module_name = $this->module->name(); |
| 66 | 66 | return Registry::responseFactory()->response(['data' => $this->geoview_data_service->all($tree, true) |
| 67 | 67 | ->map(fn(AbstractGeoAnalysisView $view) => [ |
| 68 | - 'edit' => view($module_name . '::admin/view-table-options', [ |
|
| 68 | + 'edit' => view($module_name.'::admin/view-table-options', [ |
|
| 69 | 69 | 'view_id' => $view->id(), |
| 70 | 70 | 'view_enabled' => $view->isEnabled(), |
| 71 | 71 | 'view_edit_route' => route(GeoAnalysisViewEditPage::class, [ |
@@ -83,16 +83,16 @@ discard block |
||
| 83 | 83 | ]), |
| 84 | 84 | ]), |
| 85 | 85 | 'enabled' => [ |
| 86 | - 'display' => view($module_name . '::components/yes-no-icons', ['yes' => $view->isEnabled()]), |
|
| 86 | + 'display' => view($module_name.'::components/yes-no-icons', ['yes' => $view->isEnabled()]), |
|
| 87 | 87 | 'raw' => $view->isEnabled() ? 0 : 1 |
| 88 | 88 | ], |
| 89 | 89 | 'type' => $view->icon($module), |
| 90 | 90 | 'description' => [ |
| 91 | - 'display' => '<bdi>' . e($view->description()) . '</bdi>', |
|
| 91 | + 'display' => '<bdi>'.e($view->description()).'</bdi>', |
|
| 92 | 92 | 'raw' => e($view->description()) |
| 93 | 93 | ], |
| 94 | 94 | 'analysis' => [ |
| 95 | - 'display' => '<bdi>' . e($view->analysis()->title()) . '</bdi>', |
|
| 95 | + 'display' => '<bdi>'.e($view->analysis()->title()).'</bdi>', |
|
| 96 | 96 | 'raw' => e($view->analysis()->title()) |
| 97 | 97 | ], |
| 98 | 98 | 'place_depth' => [ |
@@ -37,95 +37,95 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class MapAdapterAddAction implements RequestHandlerInterface |
| 39 | 39 | { |
| 40 | - private ?GeoDispersionModule $module; |
|
| 41 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
| 42 | - private MapAdapterDataService $mapadapter_data_service; |
|
| 43 | - private MapDefinitionsService $map_definition_service; |
|
| 40 | + private ?GeoDispersionModule $module; |
|
| 41 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
| 42 | + private MapAdapterDataService $mapadapter_data_service; |
|
| 43 | + private MapDefinitionsService $map_definition_service; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Constructor for MapAdapterAddAction Request Handler |
|
| 47 | - * |
|
| 48 | - * @param ModuleService $module_service |
|
| 49 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 50 | - * @param MapAdapterDataService $mapadapter_data_service |
|
| 51 | - * @param MapDefinitionsService $map_definition_service |
|
| 52 | - */ |
|
| 53 | - public function __construct( |
|
| 54 | - ModuleService $module_service, |
|
| 55 | - GeoAnalysisViewDataService $geoview_data_service, |
|
| 56 | - MapAdapterDataService $mapadapter_data_service, |
|
| 57 | - MapDefinitionsService $map_definition_service |
|
| 58 | - ) { |
|
| 59 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 60 | - $this->geoview_data_service = $geoview_data_service; |
|
| 61 | - $this->mapadapter_data_service = $mapadapter_data_service; |
|
| 62 | - $this->map_definition_service = $map_definition_service; |
|
| 63 | - } |
|
| 45 | + /** |
|
| 46 | + * Constructor for MapAdapterAddAction Request Handler |
|
| 47 | + * |
|
| 48 | + * @param ModuleService $module_service |
|
| 49 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 50 | + * @param MapAdapterDataService $mapadapter_data_service |
|
| 51 | + * @param MapDefinitionsService $map_definition_service |
|
| 52 | + */ |
|
| 53 | + public function __construct( |
|
| 54 | + ModuleService $module_service, |
|
| 55 | + GeoAnalysisViewDataService $geoview_data_service, |
|
| 56 | + MapAdapterDataService $mapadapter_data_service, |
|
| 57 | + MapDefinitionsService $map_definition_service |
|
| 58 | + ) { |
|
| 59 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 60 | + $this->geoview_data_service = $geoview_data_service; |
|
| 61 | + $this->mapadapter_data_service = $mapadapter_data_service; |
|
| 62 | + $this->map_definition_service = $map_definition_service; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * {@inheritDoc} |
|
| 67 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 68 | - */ |
|
| 69 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 70 | - { |
|
| 71 | - $tree = Validator::attributes($request)->tree(); |
|
| 65 | + /** |
|
| 66 | + * {@inheritDoc} |
|
| 67 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 68 | + */ |
|
| 69 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 70 | + { |
|
| 71 | + $tree = Validator::attributes($request)->tree(); |
|
| 72 | 72 | |
| 73 | - if ($this->module === null) { |
|
| 74 | - FlashMessages::addMessage( |
|
| 75 | - I18N::translate('The attached module could not be found.'), |
|
| 76 | - 'danger' |
|
| 77 | - ); |
|
| 78 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 79 | - } |
|
| 73 | + if ($this->module === null) { |
|
| 74 | + FlashMessages::addMessage( |
|
| 75 | + I18N::translate('The attached module could not be found.'), |
|
| 76 | + 'danger' |
|
| 77 | + ); |
|
| 78 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
| 82 | - $view = $this->geoview_data_service->find($tree, $view_id); |
|
| 81 | + $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
| 82 | + $view = $this->geoview_data_service->find($tree, $view_id); |
|
| 83 | 83 | |
| 84 | - $map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', '')); |
|
| 85 | - $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
|
| 84 | + $map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', '')); |
|
| 85 | + $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
|
| 86 | 86 | |
| 87 | - $mapper = null; |
|
| 88 | - try { |
|
| 89 | - $mapper = app(Validator::parsedBody($request)->string('map_adapter_mapper', '')); |
|
| 90 | - } catch (BindingResolutionException $ex) { |
|
| 91 | - } |
|
| 87 | + $mapper = null; |
|
| 88 | + try { |
|
| 89 | + $mapper = app(Validator::parsedBody($request)->string('map_adapter_mapper', '')); |
|
| 90 | + } catch (BindingResolutionException $ex) { |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - if ($view === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
|
| 94 | - FlashMessages::addMessage( |
|
| 95 | - I18N::translate('The parameters for the map configuration are not valid.'), |
|
| 96 | - 'danger' |
|
| 97 | - ); |
|
| 98 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 99 | - } |
|
| 93 | + if ($view === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
|
| 94 | + FlashMessages::addMessage( |
|
| 95 | + I18N::translate('The parameters for the map configuration are not valid.'), |
|
| 96 | + 'danger' |
|
| 97 | + ); |
|
| 98 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - $new_adapter_id = $this->mapadapter_data_service->insertGetId( |
|
| 102 | - new GeoAnalysisMapAdapter( |
|
| 103 | - 0, |
|
| 104 | - $view_id, |
|
| 105 | - $map, |
|
| 106 | - $mapper, |
|
| 107 | - new MapViewConfig($mapping_property, $mapper->config()->withConfigUpdate($request)) |
|
| 108 | - ) |
|
| 109 | - ); |
|
| 110 | - if ($new_adapter_id > 0) { |
|
| 111 | - FlashMessages::addMessage( |
|
| 112 | - I18N::translate('The map configuration has been successfully added.'), |
|
| 113 | - 'success' |
|
| 114 | - ); |
|
| 115 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 116 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $new_adapter_id . '” has been added.'); |
|
| 117 | - } else { |
|
| 118 | - FlashMessages::addMessage( |
|
| 119 | - I18N::translate('An error occured while adding a new map configuration.'), |
|
| 120 | - 'danger' |
|
| 121 | - ); |
|
| 122 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 123 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter could not be added. See error log.'); |
|
| 124 | - } |
|
| 101 | + $new_adapter_id = $this->mapadapter_data_service->insertGetId( |
|
| 102 | + new GeoAnalysisMapAdapter( |
|
| 103 | + 0, |
|
| 104 | + $view_id, |
|
| 105 | + $map, |
|
| 106 | + $mapper, |
|
| 107 | + new MapViewConfig($mapping_property, $mapper->config()->withConfigUpdate($request)) |
|
| 108 | + ) |
|
| 109 | + ); |
|
| 110 | + if ($new_adapter_id > 0) { |
|
| 111 | + FlashMessages::addMessage( |
|
| 112 | + I18N::translate('The map configuration has been successfully added.'), |
|
| 113 | + 'success' |
|
| 114 | + ); |
|
| 115 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 116 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $new_adapter_id . '” has been added.'); |
|
| 117 | + } else { |
|
| 118 | + FlashMessages::addMessage( |
|
| 119 | + I18N::translate('An error occured while adding a new map configuration.'), |
|
| 120 | + 'danger' |
|
| 121 | + ); |
|
| 122 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 123 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter could not be added. See error log.'); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
|
| 127 | - 'tree' => $tree->name(), |
|
| 128 | - 'view_id' => $view_id |
|
| 129 | - ]); |
|
| 130 | - } |
|
| 126 | + return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
|
| 127 | + 'tree' => $tree->name(), |
|
| 128 | + 'view_id' => $view_id |
|
| 129 | + ]); |
|
| 130 | + } |
|
| 131 | 131 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $view = $this->geoview_data_service->find($tree, $view_id); |
| 83 | 83 | |
| 84 | 84 | $map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', '')); |
| 85 | - $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
|
| 85 | + $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
|
| 86 | 86 | |
| 87 | 87 | $mapper = null; |
| 88 | 88 | try { |
@@ -113,14 +113,14 @@ discard block |
||
| 113 | 113 | 'success' |
| 114 | 114 | ); |
| 115 | 115 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 116 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $new_adapter_id . '” has been added.'); |
|
| 116 | + Log::addConfigurationLog('Module '.$this->module->title().' : Map Adapter “'.$new_adapter_id.'” has been added.'); |
|
| 117 | 117 | } else { |
| 118 | 118 | FlashMessages::addMessage( |
| 119 | 119 | I18N::translate('An error occured while adding a new map configuration.'), |
| 120 | 120 | 'danger' |
| 121 | 121 | ); |
| 122 | 122 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 123 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter could not be added. See error log.'); |
|
| 123 | + Log::addConfigurationLog('Module '.$this->module->title().' : Map Adapter could not be added. See error log.'); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
@@ -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 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | { |
| 64 | 64 | return [ |
| 65 | 65 | 'topPlaces' => $this->topPlaces() |
| 66 | - ->map(fn(Place $place): array => [ $place->tree()->id(), $place->gedcomName() ]) |
|
| 66 | + ->map(fn(Place $place): array => [$place->tree()->id(), $place->gedcomName()]) |
|
| 67 | 67 | ->toArray() |
| 68 | 68 | ]; |
| 69 | 69 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | ->filter( |
| 87 | 87 | /** @psalm-suppress MissingClosureParamType */ |
| 88 | 88 | fn($item): bool => is_array($item) && count($item) === 2 |
| 89 | - )->map(function (array $item): ?Place { |
|
| 89 | + )->map(function(array $item): ?Place { |
|
| 90 | 90 | try { |
| 91 | 91 | return new Place($item[1], $this->tree_service->find($item[0])); |
| 92 | 92 | } catch (RuntimeException $ex) { |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function configContent(ModuleInterface $module, Tree $tree): string |
| 108 | 108 | { |
| 109 | - return view($module->name() . '::mappers/filtered-top-config', [ |
|
| 109 | + return view($module->name().'::mappers/filtered-top-config', [ |
|
| 110 | 110 | 'tree' => $tree, |
| 111 | 111 | 'top_places' => $this->topPlaces() |
| 112 | 112 | ]); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $top_places = Validator::parsedBody($request)->array('mapper_filt_top_places'); |
| 129 | 129 | $config = ['topPlaces' => []]; |
| 130 | 130 | foreach ($top_places as $top_place_id) { |
| 131 | - $place = Place::find((int) $top_place_id, $tree); |
|
| 131 | + $place = Place::find((int)$top_place_id, $tree); |
|
| 132 | 132 | if (mb_strlen($place->gedcomName()) > 0) { |
| 133 | 133 | $config['topPlaces'][] = $place; |
| 134 | 134 | } |
@@ -32,66 +32,66 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class LineagesPage implements RequestHandlerInterface |
| 34 | 34 | { |
| 35 | - use ViewResponseTrait; |
|
| 35 | + use ViewResponseTrait; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var PatronymicLineageModule|null $module |
|
| 39 | - */ |
|
| 40 | - private $module; |
|
| 37 | + /** |
|
| 38 | + * @var PatronymicLineageModule|null $module |
|
| 39 | + */ |
|
| 40 | + private $module; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var IndividualListModule|null $indilist_module |
|
| 44 | - */ |
|
| 45 | - private $indilist_module; |
|
| 42 | + /** |
|
| 43 | + * @var IndividualListModule|null $indilist_module |
|
| 44 | + */ |
|
| 45 | + private $indilist_module; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Constructor for LineagesPage Request handler |
|
| 49 | - * |
|
| 50 | - * @param ModuleService $module_service |
|
| 51 | - */ |
|
| 52 | - public function __construct(ModuleService $module_service) |
|
| 53 | - { |
|
| 54 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
| 55 | - $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
| 56 | - } |
|
| 47 | + /** |
|
| 48 | + * Constructor for LineagesPage Request handler |
|
| 49 | + * |
|
| 50 | + * @param ModuleService $module_service |
|
| 51 | + */ |
|
| 52 | + public function __construct(ModuleService $module_service) |
|
| 53 | + { |
|
| 54 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
| 55 | + $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * {@inheritDoc} |
|
| 60 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 61 | - */ |
|
| 62 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 63 | - { |
|
| 64 | - if ($this->module === null) { |
|
| 65 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * {@inheritDoc} |
|
| 60 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 61 | + */ |
|
| 62 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 63 | + { |
|
| 64 | + if ($this->module === null) { |
|
| 65 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - if ($this->indilist_module === null) { |
|
| 69 | - throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
| 70 | - } |
|
| 68 | + if ($this->indilist_module === null) { |
|
| 69 | + throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $tree = Validator::attributes($request)->tree(); |
|
| 73 | - $surname = Validator::attributes($request)->string('surname', ''); |
|
| 72 | + $tree = Validator::attributes($request)->tree(); |
|
| 73 | + $surname = Validator::attributes($request)->string('surname', ''); |
|
| 74 | 74 | |
| 75 | - $initial = mb_substr($surname, 0, 1); |
|
| 76 | - $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
| 77 | - ->reject(function (int $count, string $initial): bool { |
|
| 78 | - return $initial === '@' || $initial === ','; |
|
| 79 | - }); |
|
| 75 | + $initial = mb_substr($surname, 0, 1); |
|
| 76 | + $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
| 77 | + ->reject(function (int $count, string $initial): bool { |
|
| 78 | + return $initial === '@' || $initial === ','; |
|
| 79 | + }); |
|
| 80 | 80 | |
| 81 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
| 81 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
| 82 | 82 | |
| 83 | - $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
| 83 | + $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
| 84 | 84 | |
| 85 | - return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
| 86 | - 'title' => $title, |
|
| 87 | - 'module' => $this->module, |
|
| 88 | - 'tree' => $tree, |
|
| 89 | - 'initials_list' => $initials_list, |
|
| 90 | - 'initial' => $initial, |
|
| 91 | - 'show_all' => 'no', |
|
| 92 | - 'surname' => $surname, |
|
| 93 | - 'lineages' => $lineages, |
|
| 94 | - 'nb_lineages' => $lineages !== null ? $lineages->count() : 0 |
|
| 95 | - ]); |
|
| 96 | - } |
|
| 85 | + return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
| 86 | + 'title' => $title, |
|
| 87 | + 'module' => $this->module, |
|
| 88 | + 'tree' => $tree, |
|
| 89 | + 'initials_list' => $initials_list, |
|
| 90 | + 'initial' => $initial, |
|
| 91 | + 'show_all' => 'no', |
|
| 92 | + 'surname' => $surname, |
|
| 93 | + 'lineages' => $lineages, |
|
| 94 | + 'nb_lineages' => $lineages !== null ? $lineages->count() : 0 |
|
| 95 | + ]); |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -31,59 +31,59 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class SurnamesList implements RequestHandlerInterface |
| 33 | 33 | { |
| 34 | - use ViewResponseTrait; |
|
| 34 | + use ViewResponseTrait; |
|
| 35 | 35 | |
| 36 | - private ?PatronymicLineageModule $module; |
|
| 36 | + private ?PatronymicLineageModule $module; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor for SurnamesList Request Handler |
|
| 40 | - * |
|
| 41 | - * @param ModuleService $module_service |
|
| 42 | - */ |
|
| 43 | - public function __construct(ModuleService $module_service) |
|
| 44 | - { |
|
| 45 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
| 46 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor for SurnamesList Request Handler |
|
| 40 | + * |
|
| 41 | + * @param ModuleService $module_service |
|
| 42 | + */ |
|
| 43 | + public function __construct(ModuleService $module_service) |
|
| 44 | + { |
|
| 45 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * {@inheritDoc} |
|
| 50 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 51 | - */ |
|
| 52 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 53 | - { |
|
| 54 | - if ($this->module === null) { |
|
| 55 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * {@inheritDoc} |
|
| 50 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 51 | + */ |
|
| 52 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 53 | + { |
|
| 54 | + if ($this->module === null) { |
|
| 55 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $tree = Validator::attributes($request)->tree(); |
|
| 59 | - $initial = Validator::attributes($request)->string('alpha', ''); |
|
| 58 | + $tree = Validator::attributes($request)->tree(); |
|
| 59 | + $initial = Validator::attributes($request)->string('alpha', ''); |
|
| 60 | 60 | |
| 61 | - $initials_list = collect($this->module->surnameAlpha($tree, false, false, I18N::locale())) |
|
| 62 | - ->reject(function (int $count, string $initial): bool { |
|
| 63 | - return $initial === '@' || $initial === ','; |
|
| 64 | - }); |
|
| 61 | + $initials_list = collect($this->module->surnameAlpha($tree, false, false, I18N::locale())) |
|
| 62 | + ->reject(function (int $count, string $initial): bool { |
|
| 63 | + return $initial === '@' || $initial === ','; |
|
| 64 | + }); |
|
| 65 | 65 | |
| 66 | - $show_all = Validator::queryParams($request)->string('show_all', 'no'); |
|
| 66 | + $show_all = Validator::queryParams($request)->string('show_all', 'no'); |
|
| 67 | 67 | |
| 68 | - if ($show_all === 'yes') { |
|
| 69 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
| 70 | - $surnames = $this->module->surnames($tree, '', '', false, false, I18N::locale()); |
|
| 71 | - } elseif (mb_strlen($initial) === 1) { |
|
| 72 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
| 73 | - $surnames = $this->module->surnames($tree, '', $initial, false, false, I18N::locale()); |
|
| 74 | - } else { |
|
| 75 | - $title = I18N::translate('Patronymic Lineages'); |
|
| 76 | - $surnames = []; |
|
| 77 | - } |
|
| 68 | + if ($show_all === 'yes') { |
|
| 69 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
| 70 | + $surnames = $this->module->surnames($tree, '', '', false, false, I18N::locale()); |
|
| 71 | + } elseif (mb_strlen($initial) === 1) { |
|
| 72 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
| 73 | + $surnames = $this->module->surnames($tree, '', $initial, false, false, I18N::locale()); |
|
| 74 | + } else { |
|
| 75 | + $title = I18N::translate('Patronymic Lineages'); |
|
| 76 | + $surnames = []; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
| 80 | - 'title' => $title, |
|
| 81 | - 'module' => $this->module, |
|
| 82 | - 'tree' => $tree, |
|
| 83 | - 'initials_list' => $initials_list, |
|
| 84 | - 'initial' => $initial, |
|
| 85 | - 'show_all' => $show_all, |
|
| 86 | - 'surnames' => $surnames |
|
| 87 | - ]); |
|
| 88 | - } |
|
| 79 | + return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
| 80 | + 'title' => $title, |
|
| 81 | + 'module' => $this->module, |
|
| 82 | + 'tree' => $tree, |
|
| 83 | + 'initials_list' => $initials_list, |
|
| 84 | + 'initial' => $initial, |
|
| 85 | + 'show_all' => $show_all, |
|
| 86 | + 'surnames' => $surnames |
|
| 87 | + ]); |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -59,24 +59,24 @@ |
||
| 59 | 59 | $initial = Validator::attributes($request)->string('alpha', ''); |
| 60 | 60 | |
| 61 | 61 | $initials_list = collect($this->module->surnameAlpha($tree, false, false, I18N::locale())) |
| 62 | - ->reject(function (int $count, string $initial): bool { |
|
| 62 | + ->reject(function(int $count, string $initial): bool { |
|
| 63 | 63 | return $initial === '@' || $initial === ','; |
| 64 | 64 | }); |
| 65 | 65 | |
| 66 | 66 | $show_all = Validator::queryParams($request)->string('show_all', 'no'); |
| 67 | 67 | |
| 68 | 68 | if ($show_all === 'yes') { |
| 69 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
| 69 | + $title = I18N::translate('Patronymic Lineages').' — '.I18N::translate('All'); |
|
| 70 | 70 | $surnames = $this->module->surnames($tree, '', '', false, false, I18N::locale()); |
| 71 | 71 | } elseif (mb_strlen($initial) === 1) { |
| 72 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
| 72 | + $title = I18N::translate('Patronymic Lineages').' — '.$initial; |
|
| 73 | 73 | $surnames = $this->module->surnames($tree, '', $initial, false, false, I18N::locale()); |
| 74 | 74 | } else { |
| 75 | - $title = I18N::translate('Patronymic Lineages'); |
|
| 75 | + $title = I18N::translate('Patronymic Lineages'); |
|
| 76 | 76 | $surnames = []; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
| 79 | + return $this->viewResponse($this->module->name().'::surnames-page', [ |
|
| 80 | 80 | 'title' => $title, |
| 81 | 81 | 'module' => $this->module, |
| 82 | 82 | 'tree' => $tree, |
@@ -28,213 +28,213 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class LineageBuilder |
| 30 | 30 | { |
| 31 | - private string $surname; |
|
| 32 | - private Tree $tree; |
|
| 33 | - private PatronymicLineageModule $patrolineage_module; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var Collection<string, bool> $used_indis Individuals already processed |
|
| 37 | - */ |
|
| 38 | - private Collection $used_indis; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Constructor for Lineage Builder |
|
| 42 | - * |
|
| 43 | - * @param string $surname Reference surname |
|
| 44 | - * @param Tree $tree Gedcom tree |
|
| 45 | - */ |
|
| 46 | - public function __construct(string $surname, Tree $tree, PatronymicLineageModule $patrolineage_module) |
|
| 47 | - { |
|
| 48 | - $this->surname = $surname; |
|
| 49 | - $this->tree = $tree; |
|
| 50 | - $this->patrolineage_module = $patrolineage_module; |
|
| 51 | - $this->used_indis = new Collection(); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Build all patronymic lineages for the reference surname. |
|
| 56 | - * |
|
| 57 | - * @return Collection<LineageRootNode>|NULL List of root patronymic lineages |
|
| 58 | - */ |
|
| 59 | - public function buildLineages(): ?Collection |
|
| 60 | - { |
|
| 61 | - $indis = $this->patrolineage_module->individuals( |
|
| 62 | - $this->tree, |
|
| 63 | - $this->surname, |
|
| 64 | - '', |
|
| 65 | - '', |
|
| 66 | - false, |
|
| 67 | - false, |
|
| 68 | - I18N::locale() |
|
| 69 | - ); |
|
| 70 | - //Warning - the individuals method returns a clone of individuals objects. Cannot be used for object equality |
|
| 71 | - if (count($indis) === 0) { |
|
| 72 | - return null; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $root_lineages = new Collection(); |
|
| 76 | - |
|
| 77 | - foreach ($indis as $indi) { |
|
| 78 | - /** @var Individual $indi */ |
|
| 79 | - if ($this->used_indis->get($indi->xref(), false) === false) { |
|
| 80 | - $indi_first = $this->getLineageRootIndividual($indi); |
|
| 81 | - if ($indi_first !== null) { |
|
| 82 | - // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
| 83 | - $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
| 84 | - } |
|
| 85 | - if ($indi_first === null) { |
|
| 86 | - continue; |
|
| 87 | - } |
|
| 88 | - $this->used_indis->put($indi_first->xref(), true); |
|
| 89 | - if ($indi_first->canShow()) { |
|
| 90 | - //Check if the root individual has brothers and sisters, without parents |
|
| 91 | - $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
| 92 | - if ($indi_first_child_family !== null) { |
|
| 93 | - $root_node = new LineageRootNode(null); |
|
| 94 | - $root_node->addFamily($indi_first_child_family); |
|
| 95 | - } else { |
|
| 96 | - $root_node = new LineageRootNode($indi_first); |
|
| 97 | - } |
|
| 98 | - $root_node = $this->buildLineage($root_node); |
|
| 99 | - $root_lineages->add($root_node); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
| 105 | - if ($a->numberChildNodes() === $b->numberChildNodes()) { |
|
| 106 | - return 0; |
|
| 107 | - } |
|
| 108 | - return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
| 109 | - })->values(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Retrieve the root individual, from any individual, by recursion. |
|
| 114 | - * The Root individual is the individual without a father, or without a mother holding the same name. |
|
| 115 | - * |
|
| 116 | - * @param Individual $indi |
|
| 117 | - * @return Individual|NULL Root individual |
|
| 118 | - */ |
|
| 119 | - private function getLineageRootIndividual(Individual $indi): ?Individual |
|
| 120 | - { |
|
| 121 | - $child_families = $indi->childFamilies(); |
|
| 122 | - if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
| 123 | - return null; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - foreach ($child_families as $child_family) { |
|
| 127 | - /** @var Family $child_family */ |
|
| 128 | - $child_family->husband(); |
|
| 129 | - if (($husb = $child_family->husband()) !== null) { |
|
| 130 | - if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) === '') { |
|
| 131 | - return $indi; |
|
| 132 | - } |
|
| 133 | - return $this->getLineageRootIndividual($husb); |
|
| 134 | - } elseif (($wife = $child_family->wife()) !== null) { |
|
| 135 | - if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) === '')) { |
|
| 136 | - $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
| 137 | - $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
| 138 | - if ( |
|
| 139 | - $indi->canShowName() |
|
| 140 | - && $wife->canShowName() |
|
| 141 | - && I18N::comparator()($indi_surname, $wife_surname) === 0 |
|
| 142 | - ) { |
|
| 143 | - return $this->getLineageRootIndividual($wife); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - return $indi; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - return $indi; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Computes descendent Lineage from a node. |
|
| 154 | - * Uses recursion to build the lineage tree |
|
| 155 | - * |
|
| 156 | - * @param LineageNode $node |
|
| 157 | - * @return LineageNode Computed lineage |
|
| 158 | - */ |
|
| 159 | - private function buildLineage(LineageNode $node): LineageNode |
|
| 160 | - { |
|
| 161 | - $indi_surname = ''; |
|
| 162 | - |
|
| 163 | - $indi_node = $node->individual(); |
|
| 164 | - if ($indi_node !== null) { |
|
| 165 | - if ($node->families()->count() === 0) { |
|
| 166 | - foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
| 167 | - $node->addFamily($spouse_family); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
| 172 | - $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
| 173 | - |
|
| 174 | - //Tag the individual as used |
|
| 175 | - $this->used_indis->put($indi_node->xref(), true); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - foreach ($node->families() as $family_node) { |
|
| 179 | - /** @var Family $spouse_family */ |
|
| 180 | - $spouse_family = $family_node->family; |
|
| 181 | - $spouse_surname = ''; |
|
| 182 | - $spouse = null; |
|
| 183 | - if ( |
|
| 184 | - $indi_node !== null && |
|
| 185 | - ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
| 186 | - ) { |
|
| 187 | - $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $nb_children = $nb_natural = 0; |
|
| 191 | - |
|
| 192 | - foreach ($spouse_family->children() as $child) { |
|
| 193 | - if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) === '')) { |
|
| 194 | - $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
| 195 | - |
|
| 196 | - $nb_children++; |
|
| 197 | - if ($indi_node !== null && $indi_node->sex() === 'F') { //If the root individual is the mother |
|
| 198 | - //Print only lineages of children with the same surname as their mother |
|
| 199 | - //(supposing they are natural children) |
|
| 200 | - /** @psalm-suppress RedundantCondition */ |
|
| 201 | - if ( |
|
| 202 | - $spouse === null || |
|
| 203 | - ($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0) |
|
| 204 | - ) { |
|
| 205 | - if (I18N::comparator()($child_surname, $indi_surname) === 0) { |
|
| 206 | - $nb_natural++; |
|
| 207 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
| 208 | - $node_child = $this->buildLineage($node_child); |
|
| 209 | - $node->addChild($spouse_family, $node_child); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } else { //If the root individual is the father |
|
| 213 | - $nb_natural++; |
|
| 214 | - //Print if the children does not bear the same name as his mother |
|
| 215 | - //(and different from his father) |
|
| 216 | - if ( |
|
| 217 | - mb_strlen($child_surname) === 0 || |
|
| 218 | - mb_strlen($indi_surname) === 0 || mb_strlen($spouse_surname) === 0 || |
|
| 219 | - I18N::comparator()($child_surname, $indi_surname) === 0 || |
|
| 220 | - I18N::comparator()($child_surname, $spouse_surname) != 0 |
|
| 221 | - ) { |
|
| 222 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
| 223 | - $node_child = $this->buildLineage($node_child); |
|
| 224 | - } else { |
|
| 225 | - $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
| 226 | - } |
|
| 227 | - $node->addChild($spouse_family, $node_child); |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - //Do not print other children |
|
| 233 | - if (($nb_children - $nb_natural) > 0) { |
|
| 234 | - $node->addChild($spouse_family, null); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - return $node; |
|
| 239 | - } |
|
| 31 | + private string $surname; |
|
| 32 | + private Tree $tree; |
|
| 33 | + private PatronymicLineageModule $patrolineage_module; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var Collection<string, bool> $used_indis Individuals already processed |
|
| 37 | + */ |
|
| 38 | + private Collection $used_indis; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Constructor for Lineage Builder |
|
| 42 | + * |
|
| 43 | + * @param string $surname Reference surname |
|
| 44 | + * @param Tree $tree Gedcom tree |
|
| 45 | + */ |
|
| 46 | + public function __construct(string $surname, Tree $tree, PatronymicLineageModule $patrolineage_module) |
|
| 47 | + { |
|
| 48 | + $this->surname = $surname; |
|
| 49 | + $this->tree = $tree; |
|
| 50 | + $this->patrolineage_module = $patrolineage_module; |
|
| 51 | + $this->used_indis = new Collection(); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Build all patronymic lineages for the reference surname. |
|
| 56 | + * |
|
| 57 | + * @return Collection<LineageRootNode>|NULL List of root patronymic lineages |
|
| 58 | + */ |
|
| 59 | + public function buildLineages(): ?Collection |
|
| 60 | + { |
|
| 61 | + $indis = $this->patrolineage_module->individuals( |
|
| 62 | + $this->tree, |
|
| 63 | + $this->surname, |
|
| 64 | + '', |
|
| 65 | + '', |
|
| 66 | + false, |
|
| 67 | + false, |
|
| 68 | + I18N::locale() |
|
| 69 | + ); |
|
| 70 | + //Warning - the individuals method returns a clone of individuals objects. Cannot be used for object equality |
|
| 71 | + if (count($indis) === 0) { |
|
| 72 | + return null; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $root_lineages = new Collection(); |
|
| 76 | + |
|
| 77 | + foreach ($indis as $indi) { |
|
| 78 | + /** @var Individual $indi */ |
|
| 79 | + if ($this->used_indis->get($indi->xref(), false) === false) { |
|
| 80 | + $indi_first = $this->getLineageRootIndividual($indi); |
|
| 81 | + if ($indi_first !== null) { |
|
| 82 | + // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
| 83 | + $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
| 84 | + } |
|
| 85 | + if ($indi_first === null) { |
|
| 86 | + continue; |
|
| 87 | + } |
|
| 88 | + $this->used_indis->put($indi_first->xref(), true); |
|
| 89 | + if ($indi_first->canShow()) { |
|
| 90 | + //Check if the root individual has brothers and sisters, without parents |
|
| 91 | + $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
| 92 | + if ($indi_first_child_family !== null) { |
|
| 93 | + $root_node = new LineageRootNode(null); |
|
| 94 | + $root_node->addFamily($indi_first_child_family); |
|
| 95 | + } else { |
|
| 96 | + $root_node = new LineageRootNode($indi_first); |
|
| 97 | + } |
|
| 98 | + $root_node = $this->buildLineage($root_node); |
|
| 99 | + $root_lineages->add($root_node); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
| 105 | + if ($a->numberChildNodes() === $b->numberChildNodes()) { |
|
| 106 | + return 0; |
|
| 107 | + } |
|
| 108 | + return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
| 109 | + })->values(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Retrieve the root individual, from any individual, by recursion. |
|
| 114 | + * The Root individual is the individual without a father, or without a mother holding the same name. |
|
| 115 | + * |
|
| 116 | + * @param Individual $indi |
|
| 117 | + * @return Individual|NULL Root individual |
|
| 118 | + */ |
|
| 119 | + private function getLineageRootIndividual(Individual $indi): ?Individual |
|
| 120 | + { |
|
| 121 | + $child_families = $indi->childFamilies(); |
|
| 122 | + if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
| 123 | + return null; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + foreach ($child_families as $child_family) { |
|
| 127 | + /** @var Family $child_family */ |
|
| 128 | + $child_family->husband(); |
|
| 129 | + if (($husb = $child_family->husband()) !== null) { |
|
| 130 | + if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) === '') { |
|
| 131 | + return $indi; |
|
| 132 | + } |
|
| 133 | + return $this->getLineageRootIndividual($husb); |
|
| 134 | + } elseif (($wife = $child_family->wife()) !== null) { |
|
| 135 | + if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) === '')) { |
|
| 136 | + $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
| 137 | + $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
| 138 | + if ( |
|
| 139 | + $indi->canShowName() |
|
| 140 | + && $wife->canShowName() |
|
| 141 | + && I18N::comparator()($indi_surname, $wife_surname) === 0 |
|
| 142 | + ) { |
|
| 143 | + return $this->getLineageRootIndividual($wife); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + return $indi; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + return $indi; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Computes descendent Lineage from a node. |
|
| 154 | + * Uses recursion to build the lineage tree |
|
| 155 | + * |
|
| 156 | + * @param LineageNode $node |
|
| 157 | + * @return LineageNode Computed lineage |
|
| 158 | + */ |
|
| 159 | + private function buildLineage(LineageNode $node): LineageNode |
|
| 160 | + { |
|
| 161 | + $indi_surname = ''; |
|
| 162 | + |
|
| 163 | + $indi_node = $node->individual(); |
|
| 164 | + if ($indi_node !== null) { |
|
| 165 | + if ($node->families()->count() === 0) { |
|
| 166 | + foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
| 167 | + $node->addFamily($spouse_family); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
| 172 | + $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
| 173 | + |
|
| 174 | + //Tag the individual as used |
|
| 175 | + $this->used_indis->put($indi_node->xref(), true); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + foreach ($node->families() as $family_node) { |
|
| 179 | + /** @var Family $spouse_family */ |
|
| 180 | + $spouse_family = $family_node->family; |
|
| 181 | + $spouse_surname = ''; |
|
| 182 | + $spouse = null; |
|
| 183 | + if ( |
|
| 184 | + $indi_node !== null && |
|
| 185 | + ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
| 186 | + ) { |
|
| 187 | + $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $nb_children = $nb_natural = 0; |
|
| 191 | + |
|
| 192 | + foreach ($spouse_family->children() as $child) { |
|
| 193 | + if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) === '')) { |
|
| 194 | + $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
| 195 | + |
|
| 196 | + $nb_children++; |
|
| 197 | + if ($indi_node !== null && $indi_node->sex() === 'F') { //If the root individual is the mother |
|
| 198 | + //Print only lineages of children with the same surname as their mother |
|
| 199 | + //(supposing they are natural children) |
|
| 200 | + /** @psalm-suppress RedundantCondition */ |
|
| 201 | + if ( |
|
| 202 | + $spouse === null || |
|
| 203 | + ($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0) |
|
| 204 | + ) { |
|
| 205 | + if (I18N::comparator()($child_surname, $indi_surname) === 0) { |
|
| 206 | + $nb_natural++; |
|
| 207 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
| 208 | + $node_child = $this->buildLineage($node_child); |
|
| 209 | + $node->addChild($spouse_family, $node_child); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } else { //If the root individual is the father |
|
| 213 | + $nb_natural++; |
|
| 214 | + //Print if the children does not bear the same name as his mother |
|
| 215 | + //(and different from his father) |
|
| 216 | + if ( |
|
| 217 | + mb_strlen($child_surname) === 0 || |
|
| 218 | + mb_strlen($indi_surname) === 0 || mb_strlen($spouse_surname) === 0 || |
|
| 219 | + I18N::comparator()($child_surname, $indi_surname) === 0 || |
|
| 220 | + I18N::comparator()($child_surname, $spouse_surname) != 0 |
|
| 221 | + ) { |
|
| 222 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
| 223 | + $node_child = $this->buildLineage($node_child); |
|
| 224 | + } else { |
|
| 225 | + $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
| 226 | + } |
|
| 227 | + $node->addChild($spouse_family, $node_child); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + //Do not print other children |
|
| 233 | + if (($nb_children - $nb_natural) > 0) { |
|
| 234 | + $node->addChild($spouse_family, null); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + return $node; |
|
| 239 | + } |
|
| 240 | 240 | } |
@@ -101,7 +101,7 @@ |
||
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
| 104 | + return $root_lineages->sort(function(LineageRootNode $a, LineageRootNode $b) { |
|
| 105 | 105 | if ($a->numberChildNodes() === $b->numberChildNodes()) { |
| 106 | 106 | return 0; |
| 107 | 107 | } |
@@ -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 | } |
@@ -30,71 +30,71 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class AdminConfigAction implements RequestHandlerInterface |
| 32 | 32 | { |
| 33 | - private ?CertificatesModule $module; |
|
| 33 | + private ?CertificatesModule $module; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor for Admin Config Action request handler |
|
| 37 | - * |
|
| 38 | - * @param ModuleService $module_service |
|
| 39 | - */ |
|
| 40 | - public function __construct(ModuleService $module_service) |
|
| 41 | - { |
|
| 42 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 43 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor for Admin Config Action request handler |
|
| 37 | + * |
|
| 38 | + * @param ModuleService $module_service |
|
| 39 | + */ |
|
| 40 | + public function __construct(ModuleService $module_service) |
|
| 41 | + { |
|
| 42 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * {@inheritDoc} |
|
| 47 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 48 | - */ |
|
| 49 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 50 | - { |
|
| 51 | - $tree = Validator::attributes($request)->tree(); |
|
| 45 | + /** |
|
| 46 | + * {@inheritDoc} |
|
| 47 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 48 | + */ |
|
| 49 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 50 | + { |
|
| 51 | + $tree = Validator::attributes($request)->tree(); |
|
| 52 | 52 | |
| 53 | - if ($this->module === null) { |
|
| 54 | - FlashMessages::addMessage( |
|
| 55 | - I18N::translate('The attached module could not be found.'), |
|
| 56 | - 'danger' |
|
| 57 | - ); |
|
| 58 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 59 | - } |
|
| 53 | + if ($this->module === null) { |
|
| 54 | + FlashMessages::addMessage( |
|
| 55 | + I18N::translate('The attached module could not be found.'), |
|
| 56 | + 'danger' |
|
| 57 | + ); |
|
| 58 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $tree->setPreference( |
|
| 62 | - 'MAJ_CERTIF_SHOW_CERT', |
|
| 63 | - (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_CERT', Auth::PRIV_HIDE) |
|
| 64 | - ); |
|
| 65 | - $tree->setPreference( |
|
| 66 | - 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
|
| 67 | - (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_NO_WATERMARK', Auth::PRIV_HIDE) |
|
| 68 | - ); |
|
| 69 | - $tree->setPreference( |
|
| 70 | - 'MAJ_CERTIF_WM_DEFAULT', |
|
| 71 | - Validator::parsedBody($request)->string('MAJ_CERTIF_WM_DEFAULT', '') |
|
| 72 | - ); |
|
| 61 | + $tree->setPreference( |
|
| 62 | + 'MAJ_CERTIF_SHOW_CERT', |
|
| 63 | + (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_CERT', Auth::PRIV_HIDE) |
|
| 64 | + ); |
|
| 65 | + $tree->setPreference( |
|
| 66 | + 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
|
| 67 | + (string) Validator::parsedBody($request)->integer('MAJ_CERTIF_SHOW_NO_WATERMARK', Auth::PRIV_HIDE) |
|
| 68 | + ); |
|
| 69 | + $tree->setPreference( |
|
| 70 | + 'MAJ_CERTIF_WM_DEFAULT', |
|
| 71 | + Validator::parsedBody($request)->string('MAJ_CERTIF_WM_DEFAULT', '') |
|
| 72 | + ); |
|
| 73 | 73 | |
| 74 | - $tree->setPreference( |
|
| 75 | - 'MAJ_CERTIF_WM_FONT_MAXSIZE', |
|
| 76 | - (string) ( |
|
| 77 | - Validator::parsedBody($request)->isBetween(0, PHP_INT_MAX)->integer('MAJ_CERTIF_WM_FONT_MAXSIZE', 18) |
|
| 78 | - ) |
|
| 79 | - ); |
|
| 74 | + $tree->setPreference( |
|
| 75 | + 'MAJ_CERTIF_WM_FONT_MAXSIZE', |
|
| 76 | + (string) ( |
|
| 77 | + Validator::parsedBody($request)->isBetween(0, PHP_INT_MAX)->integer('MAJ_CERTIF_WM_FONT_MAXSIZE', 18) |
|
| 78 | + ) |
|
| 79 | + ); |
|
| 80 | 80 | |
| 81 | - // Only accept valid color for MAJ_WM_FONT_COLOR |
|
| 82 | - $watermark_color = Validator::parsedBody($request)->string('MAJ_CERTIF_WM_FONT_COLOR', ''); |
|
| 83 | - if (preg_match('/#([a-fA-F0-9]{3}){1,2}/', $watermark_color) === 1) { |
|
| 84 | - $tree->setPreference('MAJ_CERTIF_WM_FONT_COLOR', $watermark_color); |
|
| 85 | - } |
|
| 81 | + // Only accept valid color for MAJ_WM_FONT_COLOR |
|
| 82 | + $watermark_color = Validator::parsedBody($request)->string('MAJ_CERTIF_WM_FONT_COLOR', ''); |
|
| 83 | + if (preg_match('/#([a-fA-F0-9]{3}){1,2}/', $watermark_color) === 1) { |
|
| 84 | + $tree->setPreference('MAJ_CERTIF_WM_FONT_COLOR', $watermark_color); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - // Only accept valid folders for MAJ_CERT_ROOTDIR |
|
| 88 | - $cert_root_dir = Validator::parsedBody($request)->string('MAJ_CERTIF_ROOTDIR', ''); |
|
| 89 | - $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir) ?? ''; |
|
| 90 | - $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
| 91 | - $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
|
| 87 | + // Only accept valid folders for MAJ_CERT_ROOTDIR |
|
| 88 | + $cert_root_dir = Validator::parsedBody($request)->string('MAJ_CERTIF_ROOTDIR', ''); |
|
| 89 | + $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir) ?? ''; |
|
| 90 | + $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
| 91 | + $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
|
| 92 | 92 | |
| 93 | - FlashMessages::addMessage( |
|
| 94 | - I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
| 95 | - 'success' |
|
| 96 | - ); |
|
| 93 | + FlashMessages::addMessage( |
|
| 94 | + I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
| 95 | + 'success' |
|
| 96 | + ); |
|
| 97 | 97 | |
| 98 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 99 | - } |
|
| 98 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -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 | } |
@@ -100,7 +100,7 @@ |
||
| 100 | 100 | return Registry::responseFactory()->redirect(TreePage::class, ['tree' => $tree->name()]); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - return $this->viewResponse($this->module->name() . '::certificate-page', [ |
|
| 103 | + return $this->viewResponse($this->module->name().'::certificate-page', [ |
|
| 104 | 104 | 'title' => I18N::translate('Certificate - %s', $certificate->name()), |
| 105 | 105 | 'tree' => $tree, |
| 106 | 106 | 'module_name' => $this->module->name(), |