Passed
Branch feature/2.1-geodispersion-dev (38d49e)
by Jonathan
04:17
created
Module/GeoDispersion/Http/RequestHandlers/MapAdapterDeleteAction.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -30,69 +30,69 @@
 block discarded – undo
30 30
  */
31 31
 class MapAdapterDeleteAction implements RequestHandlerInterface
32 32
 {
33
-    private ?GeoDispersionModule $module;
34
-    private MapAdapterDataService $mapadapter_data_service;
33
+	private ?GeoDispersionModule $module;
34
+	private MapAdapterDataService $mapadapter_data_service;
35 35
 
36
-    /**
37
-     * Constructor for MapAdapterDeleteAction Request Handler
38
-     *
39
-     * @param ModuleService $module_service
40
-     * @param MapAdapterDataService $mapadapter_data_service
41
-     */
42
-    public function __construct(ModuleService $module_service, MapAdapterDataService $mapadapter_data_service)
43
-    {
44
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
45
-        $this->mapadapter_data_service = $mapadapter_data_service;
46
-    }
36
+	/**
37
+	 * Constructor for MapAdapterDeleteAction Request Handler
38
+	 *
39
+	 * @param ModuleService $module_service
40
+	 * @param MapAdapterDataService $mapadapter_data_service
41
+	 */
42
+	public function __construct(ModuleService $module_service, MapAdapterDataService $mapadapter_data_service)
43
+	{
44
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
45
+		$this->mapadapter_data_service = $mapadapter_data_service;
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
51
-     */
52
-    public function handle(ServerRequestInterface $request): ResponseInterface
53
-    {
54
-        $tree = $request->getAttribute('tree');
55
-        assert($tree instanceof Tree);
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
51
+	 */
52
+	public function handle(ServerRequestInterface $request): ResponseInterface
53
+	{
54
+		$tree = $request->getAttribute('tree');
55
+		assert($tree instanceof Tree);
56 56
 
57
-        $admin_config_route = route(AdminConfigPage::class, ['tree' => $tree->name()]);
57
+		$admin_config_route = route(AdminConfigPage::class, ['tree' => $tree->name()]);
58 58
 
59
-        if ($this->module === null) {
60
-            FlashMessages::addMessage(
61
-                I18N::translate('The attached module could not be found.'),
62
-                'danger'
63
-            );
64
-            return redirect($admin_config_route);
65
-        }
66
-        $adapter_id = (int) $request->getAttribute('adapter_id');
67
-        $map_adapter = $this->mapadapter_data_service->find($adapter_id);
59
+		if ($this->module === null) {
60
+			FlashMessages::addMessage(
61
+				I18N::translate('The attached module could not be found.'),
62
+				'danger'
63
+			);
64
+			return redirect($admin_config_route);
65
+		}
66
+		$adapter_id = (int) $request->getAttribute('adapter_id');
67
+		$map_adapter = $this->mapadapter_data_service->find($adapter_id);
68 68
 
69
-        if ($map_adapter === null) {
70
-            FlashMessages::addMessage(
71
-                I18N::translate('The map configuration with ID “%d” does not exist.', I18N::number($adapter_id)),
72
-                'danger'
73
-            );
74
-            return redirect($admin_config_route);
75
-        }
69
+		if ($map_adapter === null) {
70
+			FlashMessages::addMessage(
71
+				I18N::translate('The map configuration with ID “%d” does not exist.', I18N::number($adapter_id)),
72
+				'danger'
73
+			);
74
+			return redirect($admin_config_route);
75
+		}
76 76
 
77
-        if ($this->mapadapter_data_service->delete($map_adapter) > 0) {
78
-            FlashMessages::addMessage(
79
-                I18N::translate('The map configuration has been successfully deleted'),
80
-                'success'
81
-            );
82
-            //phpcs:ignore Generic.Files.LineLength.TooLong
83
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been deleted.');
84
-        } else {
85
-            FlashMessages::addMessage(
86
-                I18N::translate('An error occured while deleting the map configuration'),
87
-                'danger'
88
-            );
89
-            //phpcs:ignore Generic.Files.LineLength.TooLong
90
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be deleted. See error log.');
91
-        }
77
+		if ($this->mapadapter_data_service->delete($map_adapter) > 0) {
78
+			FlashMessages::addMessage(
79
+				I18N::translate('The map configuration has been successfully deleted'),
80
+				'success'
81
+			);
82
+			//phpcs:ignore Generic.Files.LineLength.TooLong
83
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been deleted.');
84
+		} else {
85
+			FlashMessages::addMessage(
86
+				I18N::translate('An error occured while deleting the map configuration'),
87
+				'danger'
88
+			);
89
+			//phpcs:ignore Generic.Files.LineLength.TooLong
90
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be deleted. See error log.');
91
+		}
92 92
 
93
-        return redirect(route(GeoAnalysisViewEditPage::class, [
94
-            'tree'      => $tree->name(),
95
-            'view_id'   => $map_adapter->geoAnalysisViewId()
96
-        ]));
97
-    }
93
+		return redirect(route(GeoAnalysisViewEditPage::class, [
94
+			'tree'      => $tree->name(),
95
+			'view_id'   => $map_adapter->geoAnalysisViewId()
96
+		]));
97
+	}
98 98
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
             );
64 64
             return redirect($admin_config_route);
65 65
         }
66
-        $adapter_id = (int) $request->getAttribute('adapter_id');
66
+        $adapter_id = (int)$request->getAttribute('adapter_id');
67 67
         $map_adapter = $this->mapadapter_data_service->find($adapter_id);
68 68
 
69 69
         if ($map_adapter === null) {
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
                 'success'
81 81
             );
82 82
             //phpcs:ignore Generic.Files.LineLength.TooLong
83
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been deleted.');
83
+            Log::addConfigurationLog('Module '.$this->module->title().' : Map Adapter “'.$map_adapter->id().'” has been deleted.');
84 84
         } else {
85 85
             FlashMessages::addMessage(
86 86
                 I18N::translate('An error occured while deleting the map configuration'),
87 87
                 'danger'
88 88
             );
89 89
             //phpcs:ignore Generic.Files.LineLength.TooLong
90
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be deleted. See error log.');
90
+            Log::addConfigurationLog('Module '.$this->module->title().' : Map Adapter “'.$map_adapter->id().'” could not be deleted. See error log.');
91 91
         }
92 92
 
93 93
         return redirect(route(GeoAnalysisViewEditPage::class, [
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/Http/RequestHandlers/MapAdapterAddPage.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -32,68 +32,68 @@
 block discarded – undo
32 32
  */
33 33
 class MapAdapterAddPage implements RequestHandlerInterface
34 34
 {
35
-    use ViewResponseTrait;
35
+	use ViewResponseTrait;
36 36
 
37
-    private ?GeoDispersionModule $module;
38
-    private GeoAnalysisViewDataService $geoview_data_service;
39
-    private MapDefinitionsService $map_definition_service;
40
-    private PlaceMapperService $place_mapper_service;
37
+	private ?GeoDispersionModule $module;
38
+	private GeoAnalysisViewDataService $geoview_data_service;
39
+	private MapDefinitionsService $map_definition_service;
40
+	private PlaceMapperService $place_mapper_service;
41 41
 
42
-    /**
43
-     * Constructor for MapAdapterAddPage Request Handler
44
-     *
45
-     * @param ModuleService $module_service
46
-     * @param GeoAnalysisViewDataService $geoview_data_service
47
-     * @param MapDefinitionsService $map_definition_service
48
-     * @param PlaceMapperService $place_mapper_service
49
-     */
50
-    public function __construct(
51
-        ModuleService $module_service,
52
-        GeoAnalysisViewDataService $geoview_data_service,
53
-        MapDefinitionsService $map_definition_service,
54
-        PlaceMapperService $place_mapper_service
55
-    ) {
56
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
57
-        $this->geoview_data_service = $geoview_data_service;
58
-        $this->map_definition_service = $map_definition_service;
59
-        $this->place_mapper_service = $place_mapper_service;
60
-    }
42
+	/**
43
+	 * Constructor for MapAdapterAddPage Request Handler
44
+	 *
45
+	 * @param ModuleService $module_service
46
+	 * @param GeoAnalysisViewDataService $geoview_data_service
47
+	 * @param MapDefinitionsService $map_definition_service
48
+	 * @param PlaceMapperService $place_mapper_service
49
+	 */
50
+	public function __construct(
51
+		ModuleService $module_service,
52
+		GeoAnalysisViewDataService $geoview_data_service,
53
+		MapDefinitionsService $map_definition_service,
54
+		PlaceMapperService $place_mapper_service
55
+	) {
56
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
57
+		$this->geoview_data_service = $geoview_data_service;
58
+		$this->map_definition_service = $map_definition_service;
59
+		$this->place_mapper_service = $place_mapper_service;
60
+	}
61 61
 
62
-    /**
63
-     * {@inheritDoc}
64
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
65
-     */
66
-    public function handle(ServerRequestInterface $request): ResponseInterface
67
-    {
68
-        $this->layout = 'layouts/administration';
62
+	/**
63
+	 * {@inheritDoc}
64
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
65
+	 */
66
+	public function handle(ServerRequestInterface $request): ResponseInterface
67
+	{
68
+		$this->layout = 'layouts/administration';
69 69
 
70
-        if ($this->module === null) {
71
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
72
-        }
73
-        $tree = $request->getAttribute('tree');
74
-        assert($tree instanceof Tree);
70
+		if ($this->module === null) {
71
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
72
+		}
73
+		$tree = $request->getAttribute('tree');
74
+		assert($tree instanceof Tree);
75 75
 
76
-        $view_id = (int) $request->getAttribute('view_id');
77
-        $view = $this->geoview_data_service->find($tree, $view_id, true);
76
+		$view_id = (int) $request->getAttribute('view_id');
77
+		$view = $this->geoview_data_service->find($tree, $view_id, true);
78 78
 
79
-        if ($view === null) {
80
-            throw new HttpNotFoundException(
81
-                I18N::translate('The geographical dispersion analysis view could not be found.')
82
-            );
83
-        }
79
+		if ($view === null) {
80
+			throw new HttpNotFoundException(
81
+				I18N::translate('The geographical dispersion analysis view could not be found.')
82
+			);
83
+		}
84 84
 
85
-        return $this->viewResponse($this->module->name() . '::admin/map-adapter-edit', [
86
-            'module'            =>  $this->module,
87
-            'title'             =>  I18N::translate('Add a map configuration'),
88
-            'tree'              =>  $tree,
89
-            'view_id'           =>  $view_id,
90
-            'map_adapter'       =>  null,
91
-            'maps_list'         =>  $this->map_definition_service->all(),
92
-            'mappers_list'      =>  $this->place_mapper_service->all(),
93
-            'route_edit'        =>  route(MapAdapterAddAction::class, [
94
-                                        'tree'      => $tree->name(),
95
-                                        'view_id'   => $view_id
96
-                                    ])
97
-        ]);
98
-    }
85
+		return $this->viewResponse($this->module->name() . '::admin/map-adapter-edit', [
86
+			'module'            =>  $this->module,
87
+			'title'             =>  I18N::translate('Add a map configuration'),
88
+			'tree'              =>  $tree,
89
+			'view_id'           =>  $view_id,
90
+			'map_adapter'       =>  null,
91
+			'maps_list'         =>  $this->map_definition_service->all(),
92
+			'mappers_list'      =>  $this->place_mapper_service->all(),
93
+			'route_edit'        =>  route(MapAdapterAddAction::class, [
94
+										'tree'      => $tree->name(),
95
+										'view_id'   => $view_id
96
+									])
97
+		]);
98
+	}
99 99
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         $tree = $request->getAttribute('tree');
74 74
         assert($tree instanceof Tree);
75 75
 
76
-        $view_id = (int) $request->getAttribute('view_id');
76
+        $view_id = (int)$request->getAttribute('view_id');
77 77
         $view = $this->geoview_data_service->find($tree, $view_id, true);
78 78
 
79 79
         if ($view === null) {
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             );
83 83
         }
84 84
 
85
-        return $this->viewResponse($this->module->name() . '::admin/map-adapter-edit', [
85
+        return $this->viewResponse($this->module->name().'::admin/map-adapter-edit', [
86 86
             'module'            =>  $this->module,
87 87
             'title'             =>  I18N::translate('Add a map configuration'),
88 88
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewListData.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -32,79 +32,79 @@
 block discarded – undo
32 32
  */
33 33
 class GeoAnalysisViewListData implements RequestHandlerInterface
34 34
 {
35
-    private ?GeoDispersionModule $module;
36
-    private GeoAnalysisViewDataService $geoview_data_service;
37
-    private DatatablesService $datatables_service;
35
+	private ?GeoDispersionModule $module;
36
+	private GeoAnalysisViewDataService $geoview_data_service;
37
+	private DatatablesService $datatables_service;
38 38
 
39
-    /**
40
-     * Constructor for GeoAnalysisViewListData Request Handler
41
-     *
42
-     * @param ModuleService $module_service
43
-     * @param GeoAnalysisViewDataService $geoview_data_service
44
-     * @param DatatablesService $datatables_service
45
-     */
46
-    public function __construct(
47
-        ModuleService $module_service,
48
-        GeoAnalysisViewDataService $geoview_data_service,
49
-        DatatablesService $datatables_service
50
-    ) {
51
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
52
-        $this->geoview_data_service = $geoview_data_service;
53
-        $this->datatables_service = $datatables_service;
54
-    }
39
+	/**
40
+	 * Constructor for GeoAnalysisViewListData Request Handler
41
+	 *
42
+	 * @param ModuleService $module_service
43
+	 * @param GeoAnalysisViewDataService $geoview_data_service
44
+	 * @param DatatablesService $datatables_service
45
+	 */
46
+	public function __construct(
47
+		ModuleService $module_service,
48
+		GeoAnalysisViewDataService $geoview_data_service,
49
+		DatatablesService $datatables_service
50
+	) {
51
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
52
+		$this->geoview_data_service = $geoview_data_service;
53
+		$this->datatables_service = $datatables_service;
54
+	}
55 55
 
56
-    /**
57
-     * {@inheritDoc}
58
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
59
-     */
60
-    public function handle(ServerRequestInterface $request): ResponseInterface
61
-    {
62
-        if ($this->module === null) {
63
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
64
-        }
56
+	/**
57
+	 * {@inheritDoc}
58
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
59
+	 */
60
+	public function handle(ServerRequestInterface $request): ResponseInterface
61
+	{
62
+		if ($this->module === null) {
63
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
64
+		}
65 65
 
66
-        $tree = $request->getAttribute('tree');
67
-        assert($tree instanceof Tree);
66
+		$tree = $request->getAttribute('tree');
67
+		assert($tree instanceof Tree);
68 68
 
69
-        $module = $this->module;
70
-        $module_name = $this->module->name();
71
-        return response(['data' => $this->geoview_data_service->all($tree, true)
72
-            ->map(fn(AbstractGeoAnalysisView $view) => [
73
-                "edit" => view($module_name . '::admin/view-table-options', [
74
-                    'view_id' => $view->id(),
75
-                    'view_enabled' => $view->isEnabled(),
76
-                    'view_edit_route' => route(GeoAnalysisViewEditPage::class, [
77
-                        'tree' => $tree->name(),
78
-                        'view_id' => $view->id()
79
-                    ]),
80
-                    'view_delete_route' => route(GeoAnalysisViewDeleteAction::class, [
81
-                        'tree' => $tree->name(),
82
-                        'view_id' => $view->id()
83
-                    ]),
84
-                    'view_status_route' => route(GeoAnalysisViewStatusAction::class, [
85
-                        'tree' => $tree->name(),
86
-                        'view_id' => $view->id(),
87
-                        'enable' => $view->isEnabled() ? 0 : 1
88
-                    ]),
89
-                ]),
90
-                "enabled" =>  [
91
-                    'display' => view($module_name . '::components/yes-no-icons', ['yes' => $view->isEnabled()]),
92
-                    'raw' => $view->isEnabled() ? 0 : 1
93
-                ],
94
-                "type" =>  $view->icon($module),
95
-                "description" => [
96
-                    'display' => '<span dir="auto">' . e($view->description()) . '</span>',
97
-                    'raw' => e($view->description())
98
-                ],
99
-                "analysis" => [
100
-                    'display' => '<span dir="auto">' . e($view->analysis()->title()) . '</span>',
101
-                    'raw' => e($view->analysis()->title())
102
-                ],
103
-                "place_depth" => [
104
-                    'display' => I18N::number($view->placesDepth()),
105
-                    'raw' => $view->placesDepth()
106
-                ]
107
-            ])
108
-        ]);
109
-    }
69
+		$module = $this->module;
70
+		$module_name = $this->module->name();
71
+		return response(['data' => $this->geoview_data_service->all($tree, true)
72
+			->map(fn(AbstractGeoAnalysisView $view) => [
73
+				"edit" => view($module_name . '::admin/view-table-options', [
74
+					'view_id' => $view->id(),
75
+					'view_enabled' => $view->isEnabled(),
76
+					'view_edit_route' => route(GeoAnalysisViewEditPage::class, [
77
+						'tree' => $tree->name(),
78
+						'view_id' => $view->id()
79
+					]),
80
+					'view_delete_route' => route(GeoAnalysisViewDeleteAction::class, [
81
+						'tree' => $tree->name(),
82
+						'view_id' => $view->id()
83
+					]),
84
+					'view_status_route' => route(GeoAnalysisViewStatusAction::class, [
85
+						'tree' => $tree->name(),
86
+						'view_id' => $view->id(),
87
+						'enable' => $view->isEnabled() ? 0 : 1
88
+					]),
89
+				]),
90
+				"enabled" =>  [
91
+					'display' => view($module_name . '::components/yes-no-icons', ['yes' => $view->isEnabled()]),
92
+					'raw' => $view->isEnabled() ? 0 : 1
93
+				],
94
+				"type" =>  $view->icon($module),
95
+				"description" => [
96
+					'display' => '<span dir="auto">' . e($view->description()) . '</span>',
97
+					'raw' => e($view->description())
98
+				],
99
+				"analysis" => [
100
+					'display' => '<span dir="auto">' . e($view->analysis()->title()) . '</span>',
101
+					'raw' => e($view->analysis()->title())
102
+				],
103
+				"place_depth" => [
104
+					'display' => I18N::number($view->placesDepth()),
105
+					'raw' => $view->placesDepth()
106
+				]
107
+			])
108
+		]);
109
+	}
110 110
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
         $module_name = $this->module->name();
71 71
         return response(['data' => $this->geoview_data_service->all($tree, true)
72 72
             ->map(fn(AbstractGeoAnalysisView $view) => [
73
-                "edit" => view($module_name . '::admin/view-table-options', [
73
+                "edit" => view($module_name.'::admin/view-table-options', [
74 74
                     'view_id' => $view->id(),
75 75
                     'view_enabled' => $view->isEnabled(),
76 76
                     'view_edit_route' => route(GeoAnalysisViewEditPage::class, [
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
                     ]),
89 89
                 ]),
90 90
                 "enabled" =>  [
91
-                    'display' => view($module_name . '::components/yes-no-icons', ['yes' => $view->isEnabled()]),
91
+                    'display' => view($module_name.'::components/yes-no-icons', ['yes' => $view->isEnabled()]),
92 92
                     'raw' => $view->isEnabled() ? 0 : 1
93 93
                 ],
94 94
                 "type" =>  $view->icon($module),
95 95
                 "description" => [
96
-                    'display' => '<span dir="auto">' . e($view->description()) . '</span>',
96
+                    'display' => '<span dir="auto">'.e($view->description()).'</span>',
97 97
                     'raw' => e($view->description())
98 98
                 ],
99 99
                 "analysis" => [
100
-                    'display' => '<span dir="auto">' . e($view->analysis()->title()) . '</span>',
100
+                    'display' => '<span dir="auto">'.e($view->analysis()->title()).'</span>',
101 101
                     'raw' => e($view->analysis()->title())
102 102
                 ],
103 103
                 "place_depth" => [
Please login to merge, or discard this patch.
Module/GeoDispersion/Http/RequestHandlers/MapFeaturePropertyData.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -29,44 +29,44 @@
 block discarded – undo
29 29
  */
30 30
 class MapFeaturePropertyData implements RequestHandlerInterface
31 31
 {
32
-    private MapDefinitionsService $map_definition_service;
32
+	private MapDefinitionsService $map_definition_service;
33 33
 
34
-    /**
35
-     * Constructor for MapFeaturePropertyData Request Handler
36
-     *
37
-     * @param MapDefinitionsService $map_definition_service
38
-     */
39
-    public function __construct(
40
-        MapDefinitionsService $map_definition_service
41
-    ) {
42
-        $this->map_definition_service = $map_definition_service;
43
-    }
34
+	/**
35
+	 * Constructor for MapFeaturePropertyData Request Handler
36
+	 *
37
+	 * @param MapDefinitionsService $map_definition_service
38
+	 */
39
+	public function __construct(
40
+		MapDefinitionsService $map_definition_service
41
+	) {
42
+		$this->map_definition_service = $map_definition_service;
43
+	}
44 44
 
45
-    /**
46
-     * {@inheritDoc}
47
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
48
-     */
49
-    public function handle(ServerRequestInterface $request): ResponseInterface
50
-    {
51
-        $map_id = $request->getQueryParams()['map_id'] ?? $request->getAttribute('map_id') ?? '';
45
+	/**
46
+	 * {@inheritDoc}
47
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
48
+	 */
49
+	public function handle(ServerRequestInterface $request): ResponseInterface
50
+	{
51
+		$map_id = $request->getQueryParams()['map_id'] ?? $request->getAttribute('map_id') ?? '';
52 52
 
53
-        return response(Registry::cache()->file()->remember('map-properties-' . $map_id, function () use ($map_id) {
54
-            $map = $this->map_definition_service->find($map_id);
55
-            if ($map === null) {
56
-                throw new HttpNotFoundException(I18N::translate('The map could not be found.'));
57
-            }
53
+		return response(Registry::cache()->file()->remember('map-properties-' . $map_id, function () use ($map_id) {
54
+			$map = $this->map_definition_service->find($map_id);
55
+			if ($map === null) {
56
+				throw new HttpNotFoundException(I18N::translate('The map could not be found.'));
57
+			}
58 58
 
59
-            $features = [];
60
-            collect($map->features())
61
-                ->map(fn(Feature $feature): ?stdClass => $feature->getProperties())
62
-                ->filter()
63
-                ->map(fn(stdClass $properties) => array_keys(get_object_vars($properties)))
64
-                ->each(function (array $properties) use (&$features) {
65
-                    $features = count($features) === 0 ? $properties : array_intersect($features, $properties);
66
-                });
59
+			$features = [];
60
+			collect($map->features())
61
+				->map(fn(Feature $feature): ?stdClass => $feature->getProperties())
62
+				->filter()
63
+				->map(fn(stdClass $properties) => array_keys(get_object_vars($properties)))
64
+				->each(function (array $properties) use (&$features) {
65
+					$features = count($features) === 0 ? $properties : array_intersect($features, $properties);
66
+				});
67 67
 
68
-            usort($features, I18N::comparator());
69
-            return  $features;
70
-        }, 86400000));
71
-    }
68
+			usort($features, I18N::comparator());
69
+			return  $features;
70
+		}, 86400000));
71
+	}
72 72
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     {
51 51
         $map_id = $request->getQueryParams()['map_id'] ?? $request->getAttribute('map_id') ?? '';
52 52
 
53
-        return response(Registry::cache()->file()->remember('map-properties-' . $map_id, function () use ($map_id) {
53
+        return response(Registry::cache()->file()->remember('map-properties-'.$map_id, function() use ($map_id) {
54 54
             $map = $this->map_definition_service->find($map_id);
55 55
             if ($map === null) {
56 56
                 throw new HttpNotFoundException(I18N::translate('The map could not be found.'));
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
                 ->map(fn(Feature $feature): ?stdClass => $feature->getProperties())
62 62
                 ->filter()
63 63
                 ->map(fn(stdClass $properties) => array_keys(get_object_vars($properties)))
64
-                ->each(function (array $properties) use (&$features) {
64
+                ->each(function(array $properties) use (&$features) {
65 65
                     $features = count($features) === 0 ? $properties : array_intersect($features, $properties);
66 66
                 });
67 67
 
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/Http/RequestHandlers/MapAdapterEditAction.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -35,87 +35,87 @@
 block discarded – undo
35 35
  */
36 36
 class MapAdapterEditAction implements RequestHandlerInterface
37 37
 {
38
-    private ?GeoDispersionModule $module;
39
-    private MapAdapterDataService $mapadapter_data_service;
40
-    private MapDefinitionsService $map_definition_service;
38
+	private ?GeoDispersionModule $module;
39
+	private MapAdapterDataService $mapadapter_data_service;
40
+	private MapDefinitionsService $map_definition_service;
41 41
 
42
-    /**
43
-     * Constructor for MapAdapterEditAction Request Handler
44
-     *
45
-     * @param ModuleService $module_service
46
-     * @param MapAdapterDataService $mapadapter_data_service
47
-     * @param MapDefinitionsService $map_definition_service
48
-     */
49
-    public function __construct(
50
-        ModuleService $module_service,
51
-        MapAdapterDataService $mapadapter_data_service,
52
-        MapDefinitionsService $map_definition_service
53
-    ) {
54
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
55
-        $this->mapadapter_data_service = $mapadapter_data_service;
56
-        $this->map_definition_service = $map_definition_service;
57
-    }
42
+	/**
43
+	 * Constructor for MapAdapterEditAction Request Handler
44
+	 *
45
+	 * @param ModuleService $module_service
46
+	 * @param MapAdapterDataService $mapadapter_data_service
47
+	 * @param MapDefinitionsService $map_definition_service
48
+	 */
49
+	public function __construct(
50
+		ModuleService $module_service,
51
+		MapAdapterDataService $mapadapter_data_service,
52
+		MapDefinitionsService $map_definition_service
53
+	) {
54
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
55
+		$this->mapadapter_data_service = $mapadapter_data_service;
56
+		$this->map_definition_service = $map_definition_service;
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritDoc}
61
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
62
-     */
63
-    public function handle(ServerRequestInterface $request): ResponseInterface
64
-    {
65
-        $tree = $request->getAttribute('tree');
66
-        assert($tree instanceof Tree);
59
+	/**
60
+	 * {@inheritDoc}
61
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
62
+	 */
63
+	public function handle(ServerRequestInterface $request): ResponseInterface
64
+	{
65
+		$tree = $request->getAttribute('tree');
66
+		assert($tree instanceof Tree);
67 67
 
68
-        if ($this->module === null) {
69
-            FlashMessages::addMessage(
70
-                I18N::translate('The attached module could not be found.'),
71
-                'danger'
72
-            );
73
-            return redirect(route(AdminConfigPage::class, ['tree' => $tree]));
74
-        }
68
+		if ($this->module === null) {
69
+			FlashMessages::addMessage(
70
+				I18N::translate('The attached module could not be found.'),
71
+				'danger'
72
+			);
73
+			return redirect(route(AdminConfigPage::class, ['tree' => $tree]));
74
+		}
75 75
 
76
-        $adapter_id = (int) $request->getAttribute('adapter_id');
77
-        $map_adapter = $this->mapadapter_data_service->find($adapter_id);
76
+		$adapter_id = (int) $request->getAttribute('adapter_id');
77
+		$map_adapter = $this->mapadapter_data_service->find($adapter_id);
78 78
 
79
-        $params = (array) $request->getParsedBody();
79
+		$params = (array) $request->getParsedBody();
80 80
 
81
-        $map = $this->map_definition_service->find($params['map_adapter_map'] ?? '');
82
-        $mapping_property   = $params['map_adapter_property_selected'] ?? '';
81
+		$map = $this->map_definition_service->find($params['map_adapter_map'] ?? '');
82
+		$mapping_property   = $params['map_adapter_property_selected'] ?? '';
83 83
 
84
-        $mapper = null;
85
-        try {
86
-            $mapper = app($params['map_adapter_mapper'] ?? '');
87
-        } catch (BindingResolutionException $ex) {
88
-        }
84
+		$mapper = null;
85
+		try {
86
+			$mapper = app($params['map_adapter_mapper'] ?? '');
87
+		} catch (BindingResolutionException $ex) {
88
+		}
89 89
 
90
-        if ($map_adapter === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) {
91
-            FlashMessages::addMessage(
92
-                I18N::translate('The parameters for the map configuration are not valid.'),
93
-                'danger'
94
-            );
95
-            return redirect(route(AdminConfigPage::class, ['tree' => $tree]));
96
-        }
90
+		if ($map_adapter === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) {
91
+			FlashMessages::addMessage(
92
+				I18N::translate('The parameters for the map configuration are not valid.'),
93
+				'danger'
94
+			);
95
+			return redirect(route(AdminConfigPage::class, ['tree' => $tree]));
96
+		}
97 97
 
98
-        $mapper->setConfig($mapper->config()->withConfigUpdate($request));
99
-        $new_map_adapter = $map_adapter->with($map, $mapper, $mapping_property);
100
-        if ($this->mapadapter_data_service->update($new_map_adapter) > 0) {
101
-            FlashMessages::addMessage(
102
-                I18N::translate('The map configuration has been successfully updated'),
103
-                'success'
104
-            );
105
-            //phpcs:ignore Generic.Files.LineLength.TooLong
106
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.');
107
-        } else {
108
-            FlashMessages::addMessage(
109
-                I18N::translate('An error occured while updating the map configuration'),
110
-                'danger'
111
-            );
112
-            //phpcs:ignore Generic.Files.LineLength.TooLong
113
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be updated. See error log.');
114
-        }
98
+		$mapper->setConfig($mapper->config()->withConfigUpdate($request));
99
+		$new_map_adapter = $map_adapter->with($map, $mapper, $mapping_property);
100
+		if ($this->mapadapter_data_service->update($new_map_adapter) > 0) {
101
+			FlashMessages::addMessage(
102
+				I18N::translate('The map configuration has been successfully updated'),
103
+				'success'
104
+			);
105
+			//phpcs:ignore Generic.Files.LineLength.TooLong
106
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.');
107
+		} else {
108
+			FlashMessages::addMessage(
109
+				I18N::translate('An error occured while updating the map configuration'),
110
+				'danger'
111
+			);
112
+			//phpcs:ignore Generic.Files.LineLength.TooLong
113
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be updated. See error log.');
114
+		}
115 115
 
116
-        return redirect(route(GeoAnalysisViewEditPage::class, [
117
-            'tree' => $tree->name(),
118
-            'view_id' => $map_adapter->geoAnalysisViewId()
119
-        ]));
120
-    }
116
+		return redirect(route(GeoAnalysisViewEditPage::class, [
117
+			'tree' => $tree->name(),
118
+			'view_id' => $map_adapter->geoAnalysisViewId()
119
+		]));
120
+	}
121 121
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
             return redirect(route(AdminConfigPage::class, ['tree' => $tree]));
74 74
         }
75 75
 
76
-        $adapter_id = (int) $request->getAttribute('adapter_id');
76
+        $adapter_id = (int)$request->getAttribute('adapter_id');
77 77
         $map_adapter = $this->mapadapter_data_service->find($adapter_id);
78 78
 
79
-        $params = (array) $request->getParsedBody();
79
+        $params = (array)$request->getParsedBody();
80 80
 
81 81
         $map = $this->map_definition_service->find($params['map_adapter_map'] ?? '');
82
-        $mapping_property   = $params['map_adapter_property_selected'] ?? '';
82
+        $mapping_property = $params['map_adapter_property_selected'] ?? '';
83 83
 
84 84
         $mapper = null;
85 85
         try {
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
                 'success'
104 104
             );
105 105
             //phpcs:ignore Generic.Files.LineLength.TooLong
106
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.');
106
+            Log::addConfigurationLog('Module '.$this->module->title().' : Map Adapter “'.$map_adapter->id().'” has been updated.');
107 107
         } else {
108 108
             FlashMessages::addMessage(
109 109
                 I18N::translate('An error occured while updating the map configuration'),
110 110
                 'danger'
111 111
             );
112 112
             //phpcs:ignore Generic.Files.LineLength.TooLong
113
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be updated. See error log.');
113
+            Log::addConfigurationLog('Module '.$this->module->title().' : Map Adapter “'.$map_adapter->id().'” could not be updated. See error log.');
114 114
         }
115 115
 
116 116
         return redirect(route(GeoAnalysisViewEditPage::class, [
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/Views/AbstractGeoAnalysisView.php 1 patch
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -26,211 +26,211 @@
 block discarded – undo
26 26
  */
27 27
 abstract class AbstractGeoAnalysisView
28 28
 {
29
-    private int $id;
30
-    private Tree $tree;
31
-    private bool $enabled;
32
-    private string $description;
33
-    private GeoAnalysisInterface $geoanalysis;
34
-    private int $depth;
35
-    private int $detailed_top_places;
36
-    private bool $use_flags;
37
-
38
-    /**
39
-     * Constructor for AbstractGeoAnalysisView
40
-     *
41
-     * @param int $id
42
-     * @param Tree $tree
43
-     * @param bool $enabled
44
-     * @param string $description
45
-     * @param GeoAnalysisInterface $geoanalysis
46
-     * @param int $depth
47
-     * @param int $detailed_top_places
48
-     * @param bool $use_flags
49
-     */
50
-    final public function __construct(
51
-        int $id,
52
-        Tree $tree,
53
-        bool $enabled,
54
-        string $description,
55
-        GeoAnalysisInterface $geoanalysis,
56
-        int $depth,
57
-        int $detailed_top_places = 0,
58
-        bool $use_flags = false
59
-    ) {
60
-        $this->id = $id;
61
-        $this->tree = $tree;
62
-        $this->enabled = $enabled;
63
-        $this->description = $description;
64
-        $this->geoanalysis = $geoanalysis;
65
-        $this->depth = $depth;
66
-        $this->detailed_top_places = $detailed_top_places;
67
-        $this->use_flags = $use_flags;
68
-    }
69
-
70
-    /**
71
-     * Create a copy of the view with new properties.
72
-     *
73
-     * @param bool $enabled
74
-     * @param string $description
75
-     * @param GeoAnalysisInterface $geoanalysis
76
-     * @param int $depth
77
-     * @param int $detailed_top_places
78
-     * @param bool $use_flags
79
-     * @return self
80
-     */
81
-    public function with(
82
-        bool $enabled,
83
-        string $description,
84
-        GeoAnalysisInterface $geoanalysis,
85
-        int $depth,
86
-        int $detailed_top_places = 0,
87
-        bool $use_flags = false
88
-    ): self {
89
-        $new = clone $this;
90
-        $new->enabled = $enabled;
91
-        $new->description = $description;
92
-        $new->geoanalysis = $geoanalysis;
93
-        $new->depth = $depth;
94
-        $new->detailed_top_places = $detailed_top_places;
95
-        $new->use_flags = $use_flags;
96
-        return $new;
97
-    }
98
-
99
-    /**
100
-     * Get the view ID
101
-     *
102
-     * @return int
103
-     */
104
-    public function id(): int
105
-    {
106
-        return $this->id;
107
-    }
108
-
109
-    /**
110
-     * Get the view type for display
111
-     *
112
-     * @return string
113
-     */
114
-    abstract public function type(): string;
115
-
116
-    /**
117
-     * Get the icon for the view type
118
-     *
119
-     * @param ModuleInterface $module
120
-     * @return string
121
-     */
122
-    abstract public function icon(ModuleInterface $module): string;
123
-
124
-    /**
125
-     * Return the content of the global settings section of the config page
126
-     *
127
-     * @param ModuleInterface $module
128
-     * @return string
129
-     */
130
-    abstract public function globalSettingsContent(ModuleInterface $module): string;
131
-
132
-    /**
133
-     * Return a view with global settings updated according to the view rules
134
-     *
135
-     * @param ServerRequestInterface $request
136
-     * @return self
137
-     */
138
-    abstract public function withGlobalSettingsUpdate(ServerRequestInterface $request): self;
139
-
140
-    /**
141
-     * Returns the content of the view global tab
142
-     *
143
-     * @param ModuleInterface $module
144
-     * @param GeoAnalysisResult $result
145
-     * @param array $params
146
-     * @return string
147
-     */
148
-    abstract public function globalTabContent(
149
-        ModuleInterface $module,
150
-        GeoAnalysisResult $result,
151
-        array $params
152
-    ): string;
153
-
154
-    /**
155
-     * Returns the content of the view detailed tab
156
-     *
157
-     * @param ModuleInterface $module
158
-     * @param Collection $results
159
-     * @param array $params
160
-     * @return string
161
-     */
162
-    public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string
163
-    {
164
-        return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results'   =>  $results ]);
165
-    }
166
-
167
-    /**
168
-     * Get the tree to which the view belongs
169
-     *
170
-     * @return Tree
171
-     */
172
-    public function tree(): Tree
173
-    {
174
-        return $this->tree;
175
-    }
176
-
177
-    /**
178
-     * Get the description of the view
179
-     *
180
-     * @return string
181
-     */
182
-    public function description(): string
183
-    {
184
-        return $this->description;
185
-    }
186
-
187
-    /**
188
-     * Get whether the view is enabled
189
-     *
190
-     * @return bool
191
-     */
192
-    public function isEnabled(): bool
193
-    {
194
-        return $this->enabled;
195
-    }
196
-
197
-    /**
198
-     * Get the geographical dispersion analysis for the view
199
-     *
200
-     * @return GeoAnalysisInterface
201
-     */
202
-    public function analysis(): GeoAnalysisInterface
203
-    {
204
-        return $this->geoanalysis;
205
-    }
206
-
207
-    /**
208
-     * Get the place hierarchy depth for the view
209
-     *
210
-     * @return int
211
-     */
212
-    public function placesDepth(): int
213
-    {
214
-        return $this->depth;
215
-    }
216
-
217
-    /**
218
-     * Get the number of places to display in the detailed tab
219
-     *
220
-     * @return int
221
-     */
222
-    public function numberTopPlaces(): int
223
-    {
224
-        return $this->detailed_top_places;
225
-    }
226
-
227
-    /**
228
-     * Get whether flags should be used in the detailed tab
229
-     *
230
-     * @return bool
231
-     */
232
-    public function useFlags(): bool
233
-    {
234
-        return $this->use_flags;
235
-    }
29
+	private int $id;
30
+	private Tree $tree;
31
+	private bool $enabled;
32
+	private string $description;
33
+	private GeoAnalysisInterface $geoanalysis;
34
+	private int $depth;
35
+	private int $detailed_top_places;
36
+	private bool $use_flags;
37
+
38
+	/**
39
+	 * Constructor for AbstractGeoAnalysisView
40
+	 *
41
+	 * @param int $id
42
+	 * @param Tree $tree
43
+	 * @param bool $enabled
44
+	 * @param string $description
45
+	 * @param GeoAnalysisInterface $geoanalysis
46
+	 * @param int $depth
47
+	 * @param int $detailed_top_places
48
+	 * @param bool $use_flags
49
+	 */
50
+	final public function __construct(
51
+		int $id,
52
+		Tree $tree,
53
+		bool $enabled,
54
+		string $description,
55
+		GeoAnalysisInterface $geoanalysis,
56
+		int $depth,
57
+		int $detailed_top_places = 0,
58
+		bool $use_flags = false
59
+	) {
60
+		$this->id = $id;
61
+		$this->tree = $tree;
62
+		$this->enabled = $enabled;
63
+		$this->description = $description;
64
+		$this->geoanalysis = $geoanalysis;
65
+		$this->depth = $depth;
66
+		$this->detailed_top_places = $detailed_top_places;
67
+		$this->use_flags = $use_flags;
68
+	}
69
+
70
+	/**
71
+	 * Create a copy of the view with new properties.
72
+	 *
73
+	 * @param bool $enabled
74
+	 * @param string $description
75
+	 * @param GeoAnalysisInterface $geoanalysis
76
+	 * @param int $depth
77
+	 * @param int $detailed_top_places
78
+	 * @param bool $use_flags
79
+	 * @return self
80
+	 */
81
+	public function with(
82
+		bool $enabled,
83
+		string $description,
84
+		GeoAnalysisInterface $geoanalysis,
85
+		int $depth,
86
+		int $detailed_top_places = 0,
87
+		bool $use_flags = false
88
+	): self {
89
+		$new = clone $this;
90
+		$new->enabled = $enabled;
91
+		$new->description = $description;
92
+		$new->geoanalysis = $geoanalysis;
93
+		$new->depth = $depth;
94
+		$new->detailed_top_places = $detailed_top_places;
95
+		$new->use_flags = $use_flags;
96
+		return $new;
97
+	}
98
+
99
+	/**
100
+	 * Get the view ID
101
+	 *
102
+	 * @return int
103
+	 */
104
+	public function id(): int
105
+	{
106
+		return $this->id;
107
+	}
108
+
109
+	/**
110
+	 * Get the view type for display
111
+	 *
112
+	 * @return string
113
+	 */
114
+	abstract public function type(): string;
115
+
116
+	/**
117
+	 * Get the icon for the view type
118
+	 *
119
+	 * @param ModuleInterface $module
120
+	 * @return string
121
+	 */
122
+	abstract public function icon(ModuleInterface $module): string;
123
+
124
+	/**
125
+	 * Return the content of the global settings section of the config page
126
+	 *
127
+	 * @param ModuleInterface $module
128
+	 * @return string
129
+	 */
130
+	abstract public function globalSettingsContent(ModuleInterface $module): string;
131
+
132
+	/**
133
+	 * Return a view with global settings updated according to the view rules
134
+	 *
135
+	 * @param ServerRequestInterface $request
136
+	 * @return self
137
+	 */
138
+	abstract public function withGlobalSettingsUpdate(ServerRequestInterface $request): self;
139
+
140
+	/**
141
+	 * Returns the content of the view global tab
142
+	 *
143
+	 * @param ModuleInterface $module
144
+	 * @param GeoAnalysisResult $result
145
+	 * @param array $params
146
+	 * @return string
147
+	 */
148
+	abstract public function globalTabContent(
149
+		ModuleInterface $module,
150
+		GeoAnalysisResult $result,
151
+		array $params
152
+	): string;
153
+
154
+	/**
155
+	 * Returns the content of the view detailed tab
156
+	 *
157
+	 * @param ModuleInterface $module
158
+	 * @param Collection $results
159
+	 * @param array $params
160
+	 * @return string
161
+	 */
162
+	public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string
163
+	{
164
+		return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results'   =>  $results ]);
165
+	}
166
+
167
+	/**
168
+	 * Get the tree to which the view belongs
169
+	 *
170
+	 * @return Tree
171
+	 */
172
+	public function tree(): Tree
173
+	{
174
+		return $this->tree;
175
+	}
176
+
177
+	/**
178
+	 * Get the description of the view
179
+	 *
180
+	 * @return string
181
+	 */
182
+	public function description(): string
183
+	{
184
+		return $this->description;
185
+	}
186
+
187
+	/**
188
+	 * Get whether the view is enabled
189
+	 *
190
+	 * @return bool
191
+	 */
192
+	public function isEnabled(): bool
193
+	{
194
+		return $this->enabled;
195
+	}
196
+
197
+	/**
198
+	 * Get the geographical dispersion analysis for the view
199
+	 *
200
+	 * @return GeoAnalysisInterface
201
+	 */
202
+	public function analysis(): GeoAnalysisInterface
203
+	{
204
+		return $this->geoanalysis;
205
+	}
206
+
207
+	/**
208
+	 * Get the place hierarchy depth for the view
209
+	 *
210
+	 * @return int
211
+	 */
212
+	public function placesDepth(): int
213
+	{
214
+		return $this->depth;
215
+	}
216
+
217
+	/**
218
+	 * Get the number of places to display in the detailed tab
219
+	 *
220
+	 * @return int
221
+	 */
222
+	public function numberTopPlaces(): int
223
+	{
224
+		return $this->detailed_top_places;
225
+	}
226
+
227
+	/**
228
+	 * Get whether flags should be used in the detailed tab
229
+	 *
230
+	 * @return bool
231
+	 */
232
+	public function useFlags(): bool
233
+	{
234
+		return $this->use_flags;
235
+	}
236 236
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/Views/GeoAnalysisTable.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -21,50 +21,50 @@
 block discarded – undo
21 21
 
22 22
 class GeoAnalysisTable extends AbstractGeoAnalysisView
23 23
 {
24
-    /**
25
-     * {@inheritDoc}
26
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::type()
27
-     */
28
-    public function type(): string
29
-    {
30
-        return I18N::translateContext('GEODISPERSION', 'Table');
31
-    }
24
+	/**
25
+	 * {@inheritDoc}
26
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::type()
27
+	 */
28
+	public function type(): string
29
+	{
30
+		return I18N::translateContext('GEODISPERSION', 'Table');
31
+	}
32 32
 
33
-    /**
34
-     * {@inheritDoc}
35
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon()
36
-     */
37
-    public function icon(ModuleInterface $module): string
38
-    {
39
-        return view($module->name() . '::icons/view-table', ['type' => $this->type()]);
40
-    }
33
+	/**
34
+	 * {@inheritDoc}
35
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon()
36
+	 */
37
+	public function icon(ModuleInterface $module): string
38
+	{
39
+		return view($module->name() . '::icons/view-table', ['type' => $this->type()]);
40
+	}
41 41
 
42
-    /**
43
-     * {@inheritDoc}
44
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent()
45
-     */
46
-    public function globalSettingsContent(ModuleInterface $module): string
47
-    {
48
-        return '';
49
-    }
42
+	/**
43
+	 * {@inheritDoc}
44
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent()
45
+	 */
46
+	public function globalSettingsContent(ModuleInterface $module): string
47
+	{
48
+		return '';
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritDoc}
53
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate()
54
-     */
55
-    public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
56
-    {
57
-        return $this;
58
-    }
51
+	/**
52
+	 * {@inheritDoc}
53
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate()
54
+	 */
55
+	public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
56
+	{
57
+		return $this;
58
+	}
59 59
 
60
-    /**
61
-     * {@inheritDoc}
62
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent()
63
-     */
64
-    public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
65
-    {
66
-        return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [
67
-            'result'    =>  $result
68
-        ]);
69
-    }
60
+	/**
61
+	 * {@inheritDoc}
62
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent()
63
+	 */
64
+	public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
65
+	{
66
+		return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [
67
+			'result'    =>  $result
68
+		]);
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function icon(ModuleInterface $module): string
38 38
     {
39
-        return view($module->name() . '::icons/view-table', ['type' => $this->type()]);
39
+        return view($module->name().'::icons/view-table', ['type' => $this->type()]);
40 40
     }
41 41
 
42 42
     /**
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
65 65
     {
66
-        return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [
66
+        return view($module->name().'::geoanalysisview-tab-glb-table', $params + [
67 67
             'result'    =>  $result
68 68
         ]);
69 69
     }
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/Views/GeoAnalysisMap.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -29,127 +29,127 @@
 block discarded – undo
29 29
  */
30 30
 class GeoAnalysisMap extends AbstractGeoAnalysisView
31 31
 {
32
-    private ?MapColorsConfig $colors_config = null;
33
-
34
-    public function type(): string
35
-    {
36
-        return I18N::translateContext('GEODISPERSION', 'Map');
37
-    }
38
-
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon()
42
-     */
43
-    public function icon(ModuleInterface $module): string
44
-    {
45
-        return view($module->name() . '::icons/view-map', ['type' => $this->type()]);
46
-    }
47
-
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent()
51
-     */
52
-    public function globalSettingsContent(ModuleInterface $module): string
53
-    {
54
-        return view($module->name() . '::admin/view-edit-map', [
55
-            'module_name'   =>  $module->name(),
56
-            'view'          =>  $this,
57
-            'colors'        =>  $this->colors(),
58
-            'map_adapters'  =>  app(MapAdapterDataService::class)->allForView($this)
59
-        ]);
60
-    }
61
-
62
-    /**
63
-     * {@inheritDoc}
64
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate()
65
-     */
66
-    public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
67
-    {
68
-        $params = (array) $request->getParsedBody();
69
-
70
-        $default_color  = $params['view_map_color_default'] ?? '';
71
-        $stroke_color   = $params['view_map_color_stroke'] ?? '';
72
-        $maxvalue_color  = $params['view_map_color_maxvalue'] ?? '';
73
-        $hover_color  = $params['view_map_color_hover'] ?? '';
74
-
75
-        try {
76
-            return $this->withColors(new MapColorsConfig(
77
-                Hex::fromString($default_color),
78
-                Hex::fromString($stroke_color),
79
-                Hex::fromString($maxvalue_color),
80
-                Hex::fromString($hover_color)
81
-            ));
82
-        } catch (InvalidColorValue $ex) {
83
-        }
84
-
85
-        return $this;
86
-    }
87
-
88
-    /**
89
-     * {@inheritDoc}
90
-     * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent()
91
-     */
92
-    public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
93
-    {
94
-        $map_adapters = app(MapAdapterDataService::class)->allForView($this);
95
-
96
-        $adapter_result = null;
97
-        foreach ($map_adapters as $map_adapter) {
98
-            $adapter_result_tmp = $map_adapter->convert($result);
99
-            $adapter_result = $adapter_result === null ?
100
-                $adapter_result_tmp :
101
-                $adapter_result->merge($adapter_result_tmp);
102
-        }
103
-
104
-        if ($adapter_result === null) {
105
-            return view($module->name() . '::errors/tab-error', [
106
-                'message'   =>  I18N::translate('The map could not be loaded.'),
107
-            ]);
108
-        }
109
-
110
-        //phpcs:disable Generic.Files.LineLength.TooLong
111
-        $basemap_provider = [
112
-            'url'    => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
113
-            'options' => [
114
-                'attribution' => '<a href="https://www.openstreetmap.org/copyright">&copy; OpenStreetMap</a> contributors',
115
-                'max_zoom'    => 19
116
-            ]
117
-        ];
118
-        //phpcs:enable
119
-
120
-        return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [
121
-            'result'            =>  $adapter_result->geoAnalysisResult(),
122
-            'features'          =>  $adapter_result->features(),
123
-            'colors'            =>  $this->colors(),
124
-            'basemap_provider'  =>  $basemap_provider
125
-        ]);
126
-    }
127
-
128
-    /**
129
-     * Get the color scheme configuration for the map view
130
-     *
131
-     * @return MapColorsConfig
132
-     */
133
-    public function colors(): MapColorsConfig
134
-    {
135
-        return $this->colors_config ?? new MapColorsConfig(
136
-            new Rgb(245, 245, 245),
137
-            new Rgb(213, 213, 213),
138
-            new Rgb(4, 147, 171),
139
-            new Rgb(255, 102, 0)
140
-        );
141
-    }
142
-
143
-    /**
144
-     * Returns a map view with a new color scheme configuration
145
-     *
146
-     * @param MapColorsConfig $config
147
-     * @return self
148
-     */
149
-    public function withColors(?MapColorsConfig $config): self
150
-    {
151
-        $new = clone $this;
152
-        $new->colors_config = $config;
153
-        return $new;
154
-    }
32
+	private ?MapColorsConfig $colors_config = null;
33
+
34
+	public function type(): string
35
+	{
36
+		return I18N::translateContext('GEODISPERSION', 'Map');
37
+	}
38
+
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon()
42
+	 */
43
+	public function icon(ModuleInterface $module): string
44
+	{
45
+		return view($module->name() . '::icons/view-map', ['type' => $this->type()]);
46
+	}
47
+
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent()
51
+	 */
52
+	public function globalSettingsContent(ModuleInterface $module): string
53
+	{
54
+		return view($module->name() . '::admin/view-edit-map', [
55
+			'module_name'   =>  $module->name(),
56
+			'view'          =>  $this,
57
+			'colors'        =>  $this->colors(),
58
+			'map_adapters'  =>  app(MapAdapterDataService::class)->allForView($this)
59
+		]);
60
+	}
61
+
62
+	/**
63
+	 * {@inheritDoc}
64
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate()
65
+	 */
66
+	public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
67
+	{
68
+		$params = (array) $request->getParsedBody();
69
+
70
+		$default_color  = $params['view_map_color_default'] ?? '';
71
+		$stroke_color   = $params['view_map_color_stroke'] ?? '';
72
+		$maxvalue_color  = $params['view_map_color_maxvalue'] ?? '';
73
+		$hover_color  = $params['view_map_color_hover'] ?? '';
74
+
75
+		try {
76
+			return $this->withColors(new MapColorsConfig(
77
+				Hex::fromString($default_color),
78
+				Hex::fromString($stroke_color),
79
+				Hex::fromString($maxvalue_color),
80
+				Hex::fromString($hover_color)
81
+			));
82
+		} catch (InvalidColorValue $ex) {
83
+		}
84
+
85
+		return $this;
86
+	}
87
+
88
+	/**
89
+	 * {@inheritDoc}
90
+	 * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent()
91
+	 */
92
+	public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string
93
+	{
94
+		$map_adapters = app(MapAdapterDataService::class)->allForView($this);
95
+
96
+		$adapter_result = null;
97
+		foreach ($map_adapters as $map_adapter) {
98
+			$adapter_result_tmp = $map_adapter->convert($result);
99
+			$adapter_result = $adapter_result === null ?
100
+				$adapter_result_tmp :
101
+				$adapter_result->merge($adapter_result_tmp);
102
+		}
103
+
104
+		if ($adapter_result === null) {
105
+			return view($module->name() . '::errors/tab-error', [
106
+				'message'   =>  I18N::translate('The map could not be loaded.'),
107
+			]);
108
+		}
109
+
110
+		//phpcs:disable Generic.Files.LineLength.TooLong
111
+		$basemap_provider = [
112
+			'url'    => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
113
+			'options' => [
114
+				'attribution' => '<a href="https://www.openstreetmap.org/copyright">&copy; OpenStreetMap</a> contributors',
115
+				'max_zoom'    => 19
116
+			]
117
+		];
118
+		//phpcs:enable
119
+
120
+		return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [
121
+			'result'            =>  $adapter_result->geoAnalysisResult(),
122
+			'features'          =>  $adapter_result->features(),
123
+			'colors'            =>  $this->colors(),
124
+			'basemap_provider'  =>  $basemap_provider
125
+		]);
126
+	}
127
+
128
+	/**
129
+	 * Get the color scheme configuration for the map view
130
+	 *
131
+	 * @return MapColorsConfig
132
+	 */
133
+	public function colors(): MapColorsConfig
134
+	{
135
+		return $this->colors_config ?? new MapColorsConfig(
136
+			new Rgb(245, 245, 245),
137
+			new Rgb(213, 213, 213),
138
+			new Rgb(4, 147, 171),
139
+			new Rgb(255, 102, 0)
140
+		);
141
+	}
142
+
143
+	/**
144
+	 * Returns a map view with a new color scheme configuration
145
+	 *
146
+	 * @param MapColorsConfig $config
147
+	 * @return self
148
+	 */
149
+	public function withColors(?MapColorsConfig $config): self
150
+	{
151
+		$new = clone $this;
152
+		$new->colors_config = $config;
153
+		return $new;
154
+	}
155 155
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -9 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function icon(ModuleInterface $module): string
44 44
     {
45
-        return view($module->name() . '::icons/view-map', ['type' => $this->type()]);
45
+        return view($module->name().'::icons/view-map', ['type' => $this->type()]);
46 46
     }
47 47
 
48 48
     /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function globalSettingsContent(ModuleInterface $module): string
53 53
     {
54
-        return view($module->name() . '::admin/view-edit-map', [
54
+        return view($module->name().'::admin/view-edit-map', [
55 55
             'module_name'   =>  $module->name(),
56 56
             'view'          =>  $this,
57 57
             'colors'        =>  $this->colors(),
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function withGlobalSettingsUpdate(ServerRequestInterface $request): self
67 67
     {
68
-        $params = (array) $request->getParsedBody();
68
+        $params = (array)$request->getParsedBody();
69 69
 
70 70
         $default_color  = $params['view_map_color_default'] ?? '';
71 71
         $stroke_color   = $params['view_map_color_stroke'] ?? '';
72
-        $maxvalue_color  = $params['view_map_color_maxvalue'] ?? '';
73
-        $hover_color  = $params['view_map_color_hover'] ?? '';
72
+        $maxvalue_color = $params['view_map_color_maxvalue'] ?? '';
73
+        $hover_color = $params['view_map_color_hover'] ?? '';
74 74
 
75 75
         try {
76 76
             return $this->withColors(new MapColorsConfig(
@@ -97,12 +97,11 @@  discard block
 block discarded – undo
97 97
         foreach ($map_adapters as $map_adapter) {
98 98
             $adapter_result_tmp = $map_adapter->convert($result);
99 99
             $adapter_result = $adapter_result === null ?
100
-                $adapter_result_tmp :
101
-                $adapter_result->merge($adapter_result_tmp);
100
+                $adapter_result_tmp : $adapter_result->merge($adapter_result_tmp);
102 101
         }
103 102
 
104 103
         if ($adapter_result === null) {
105
-            return view($module->name() . '::errors/tab-error', [
104
+            return view($module->name().'::errors/tab-error', [
106 105
                 'message'   =>  I18N::translate('The map could not be loaded.'),
107 106
             ]);
108 107
         }
@@ -117,7 +116,7 @@  discard block
 block discarded – undo
117 116
         ];
118 117
         //phpcs:enable
119 118
 
120
-        return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [
119
+        return view($module->name().'::geoanalysisview-tab-glb-map', $params + [
121 120
             'result'            =>  $adapter_result->geoAnalysisResult(),
122 121
             'features'          =>  $adapter_result->features(),
123 122
             'colors'            =>  $this->colors(),
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/Services/GeoAnalysisViewDataService.php 2 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -32,186 +32,186 @@
 block discarded – undo
32 32
  */
33 33
 class GeoAnalysisViewDataService
34 34
 {
35
-    /**
36
-     * Find a Geographical dispersion analysis view by ID
37
-     *
38
-     * @param Tree $tree
39
-     * @param int $id
40
-     * @return AbstractGeoAnalysisView|NULL
41
-     */
42
-    public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView
43
-    {
44
-        return $this->all($tree, $include_disabled)
45
-            ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id);
46
-    }
47
-
48
-    /**
49
-     * Get all Geographical dispersion analysis views, with or without the disabled ones.
50
-     *
51
-     * {@internal It would ignore any view for which the class could not be loaded by the container}
52
-     *
53
-     * @param Tree $tree
54
-     * @param bool $include_disabled
55
-     * @return Collection<AbstractGeoAnalysisView>
56
-     */
57
-    public function all(Tree $tree, bool $include_disabled = false): Collection
58
-    {
59
-        return Registry::cache()->array()->remember(
60
-            'all-geodispersion-views',
61
-            function () use ($tree, $include_disabled): Collection {
62
-                return DB::table('maj_geodisp_views')
63
-                    ->select('maj_geodisp_views.*')
64
-                    ->where('majgv_gedcom_id', '=', $tree->id())
65
-                    ->get()
66
-                    ->map($this->viewMapper($tree))
67
-                    ->filter()
68
-                    ->filter($this->enabledFilter($include_disabled));
69
-            }
70
-        );
71
-    }
72
-
73
-    /**
74
-     * Insert a geographical dispersion analysis view object in the database.
75
-     *
76
-     * @param AbstractGeoAnalysisView $view
77
-     * @return int
78
-     */
79
-    public function insertGetId(AbstractGeoAnalysisView $view): int
80
-    {
81
-        return DB::table('maj_geodisp_views')
82
-            ->insertGetId([
83
-                'majgv_gedcom_id' => $view->tree()->id(),
84
-                'majgv_view_class' => get_class($view),
85
-                'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled',
86
-                'majgv_descr' => mb_substr($view->description(), 0, 248),
87
-                'majgv_analysis' => get_class($view->analysis()),
88
-                'majgv_place_depth' => $view->placesDepth()
89
-            ]);
90
-    }
91
-
92
-    /**
93
-     * Update a geographical dispersion analysis view object in the database.
94
-     *
95
-     * @param AbstractGeoAnalysisView $view
96
-     * @return int
97
-     */
98
-    public function update(AbstractGeoAnalysisView $view): int
99
-    {
100
-        return DB::table('maj_geodisp_views')
101
-            ->where('majgv_id', '=', $view->id())
102
-            ->update([
103
-                'majgv_gedcom_id' => $view->tree()->id(),
104
-                'majgv_view_class' => get_class($view),
105
-                'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled',
106
-                'majgv_descr' => mb_substr($view->description(), 0, 248),
107
-                'majgv_analysis' => get_class($view->analysis()),
108
-                'majgv_place_depth' => $view->placesDepth(),
109
-                'majgv_top_places' => $view->numberTopPlaces(),
110
-                'majgv_colors' => $view instanceof GeoAnalysisMap ? json_encode($view->colors()) : null
111
-            ]);
112
-    }
113
-
114
-    /**
115
-     * Update the status of a geographical dispersion analysis view object in the database.
116
-     *
117
-     * @param AbstractGeoAnalysisView $view
118
-     * @param bool $status
119
-     * @return int
120
-     */
121
-    public function updateStatus(AbstractGeoAnalysisView $view, bool $status): int
122
-    {
123
-        return DB::table('maj_geodisp_views')
124
-            ->where('majgv_id', '=', $view->id())
125
-            ->update(['majgv_status' => $status ? 'enabled' : 'disabled']);
126
-    }
127
-
128
-    /**
129
-     * Delete a geographical dispersion analysis view object from the database.
130
-     *
131
-     * @param AbstractGeoAnalysisView $view
132
-     * @return int
133
-     */
134
-    public function delete(AbstractGeoAnalysisView $view): int
135
-    {
136
-        return DB::table('maj_geodisp_views')
137
-            ->where('majgv_id', '=', $view->id())
138
-            ->delete();
139
-    }
140
-
141
-    /**
142
-     * Get the closure to create a AbstractGeoAnalysisView object from a row in the database.
143
-     * It returns null if the classes stored in the DB cannot be loaded through the Laravel container,
144
-     * or if the types do not match with the ones expected.
145
-     *
146
-     * @param Tree $tree
147
-     * @return Closure(\stdClass $row):?AbstractGeoAnalysisView
148
-     */
149
-    private function viewMapper(Tree $tree): Closure
150
-    {
151
-        return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView {
152
-            try {
153
-                $geoanalysis = app($row->majgv_analysis);
154
-                if (!($geoanalysis instanceof GeoAnalysisInterface)) {
155
-                    return null;
156
-                }
157
-
158
-                $view = app()->makeWith($row->majgv_view_class, [
159
-                    'id'                    =>  (int) $row->majgv_id,
160
-                    'tree'                  =>  $tree,
161
-                    'enabled'               =>  $row->majgv_status === 'enabled',
162
-                    'description'           =>  $row->majgv_descr,
163
-                    'geoanalysis'           =>  $geoanalysis,
164
-                    'depth'                 =>  (int) $row->majgv_place_depth,
165
-                    'detailed_top_places'   =>  (int) $row->majgv_top_places
166
-                ]);
167
-
168
-                if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) {
169
-                    $view = $view->withColors($this->colorsDecoder($row->majgv_colors));
170
-                }
171
-
172
-                return $view instanceof AbstractGeoAnalysisView ? $view : null;
173
-            } catch (BindingResolutionException $ex) {
174
-                return null;
175
-            }
176
-        };
177
-    }
178
-
179
-    /**
180
-     * Create a MapColorsConfig object from a JSON column value.
181
-     * Returns null if the JSON string is invalid, or if the colors are not valid.
182
-     *
183
-     * @param string $colors_config
184
-     * @return MapColorsConfig|NULL
185
-     */
186
-    private function colorsDecoder(string $colors_config): ?MapColorsConfig
187
-    {
188
-        $colors = json_decode($colors_config, true);
189
-        if (!is_array($colors) && count($colors) !== 4) {
190
-            return null;
191
-        }
192
-        try {
193
-            return new MapColorsConfig(
194
-                \Spatie\Color\Factory::fromString($colors['default'] ?? ''),
195
-                \Spatie\Color\Factory::fromString($colors['stroke'] ?? ''),
196
-                \Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''),
197
-                \Spatie\Color\Factory::fromString($colors['hover'] ?? '')
198
-            );
199
-        } catch (InvalidColorValue $ex) {
200
-            return null;
201
-        }
202
-    }
203
-
204
-    /**
205
-     * Get a closure to filter views by enabled/disabled status
206
-     *
207
-     * @param bool $include_disabled
208
-     *
209
-     * @return Closure(AbstractGeoAnalysisView $view):bool
210
-     */
211
-    private function enabledFilter(bool $include_disabled): Closure
212
-    {
213
-        return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool {
214
-            return $include_disabled || $view->isEnabled();
215
-        };
216
-    }
35
+	/**
36
+	 * Find a Geographical dispersion analysis view by ID
37
+	 *
38
+	 * @param Tree $tree
39
+	 * @param int $id
40
+	 * @return AbstractGeoAnalysisView|NULL
41
+	 */
42
+	public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView
43
+	{
44
+		return $this->all($tree, $include_disabled)
45
+			->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id);
46
+	}
47
+
48
+	/**
49
+	 * Get all Geographical dispersion analysis views, with or without the disabled ones.
50
+	 *
51
+	 * {@internal It would ignore any view for which the class could not be loaded by the container}
52
+	 *
53
+	 * @param Tree $tree
54
+	 * @param bool $include_disabled
55
+	 * @return Collection<AbstractGeoAnalysisView>
56
+	 */
57
+	public function all(Tree $tree, bool $include_disabled = false): Collection
58
+	{
59
+		return Registry::cache()->array()->remember(
60
+			'all-geodispersion-views',
61
+			function () use ($tree, $include_disabled): Collection {
62
+				return DB::table('maj_geodisp_views')
63
+					->select('maj_geodisp_views.*')
64
+					->where('majgv_gedcom_id', '=', $tree->id())
65
+					->get()
66
+					->map($this->viewMapper($tree))
67
+					->filter()
68
+					->filter($this->enabledFilter($include_disabled));
69
+			}
70
+		);
71
+	}
72
+
73
+	/**
74
+	 * Insert a geographical dispersion analysis view object in the database.
75
+	 *
76
+	 * @param AbstractGeoAnalysisView $view
77
+	 * @return int
78
+	 */
79
+	public function insertGetId(AbstractGeoAnalysisView $view): int
80
+	{
81
+		return DB::table('maj_geodisp_views')
82
+			->insertGetId([
83
+				'majgv_gedcom_id' => $view->tree()->id(),
84
+				'majgv_view_class' => get_class($view),
85
+				'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled',
86
+				'majgv_descr' => mb_substr($view->description(), 0, 248),
87
+				'majgv_analysis' => get_class($view->analysis()),
88
+				'majgv_place_depth' => $view->placesDepth()
89
+			]);
90
+	}
91
+
92
+	/**
93
+	 * Update a geographical dispersion analysis view object in the database.
94
+	 *
95
+	 * @param AbstractGeoAnalysisView $view
96
+	 * @return int
97
+	 */
98
+	public function update(AbstractGeoAnalysisView $view): int
99
+	{
100
+		return DB::table('maj_geodisp_views')
101
+			->where('majgv_id', '=', $view->id())
102
+			->update([
103
+				'majgv_gedcom_id' => $view->tree()->id(),
104
+				'majgv_view_class' => get_class($view),
105
+				'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled',
106
+				'majgv_descr' => mb_substr($view->description(), 0, 248),
107
+				'majgv_analysis' => get_class($view->analysis()),
108
+				'majgv_place_depth' => $view->placesDepth(),
109
+				'majgv_top_places' => $view->numberTopPlaces(),
110
+				'majgv_colors' => $view instanceof GeoAnalysisMap ? json_encode($view->colors()) : null
111
+			]);
112
+	}
113
+
114
+	/**
115
+	 * Update the status of a geographical dispersion analysis view object in the database.
116
+	 *
117
+	 * @param AbstractGeoAnalysisView $view
118
+	 * @param bool $status
119
+	 * @return int
120
+	 */
121
+	public function updateStatus(AbstractGeoAnalysisView $view, bool $status): int
122
+	{
123
+		return DB::table('maj_geodisp_views')
124
+			->where('majgv_id', '=', $view->id())
125
+			->update(['majgv_status' => $status ? 'enabled' : 'disabled']);
126
+	}
127
+
128
+	/**
129
+	 * Delete a geographical dispersion analysis view object from the database.
130
+	 *
131
+	 * @param AbstractGeoAnalysisView $view
132
+	 * @return int
133
+	 */
134
+	public function delete(AbstractGeoAnalysisView $view): int
135
+	{
136
+		return DB::table('maj_geodisp_views')
137
+			->where('majgv_id', '=', $view->id())
138
+			->delete();
139
+	}
140
+
141
+	/**
142
+	 * Get the closure to create a AbstractGeoAnalysisView object from a row in the database.
143
+	 * It returns null if the classes stored in the DB cannot be loaded through the Laravel container,
144
+	 * or if the types do not match with the ones expected.
145
+	 *
146
+	 * @param Tree $tree
147
+	 * @return Closure(\stdClass $row):?AbstractGeoAnalysisView
148
+	 */
149
+	private function viewMapper(Tree $tree): Closure
150
+	{
151
+		return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView {
152
+			try {
153
+				$geoanalysis = app($row->majgv_analysis);
154
+				if (!($geoanalysis instanceof GeoAnalysisInterface)) {
155
+					return null;
156
+				}
157
+
158
+				$view = app()->makeWith($row->majgv_view_class, [
159
+					'id'                    =>  (int) $row->majgv_id,
160
+					'tree'                  =>  $tree,
161
+					'enabled'               =>  $row->majgv_status === 'enabled',
162
+					'description'           =>  $row->majgv_descr,
163
+					'geoanalysis'           =>  $geoanalysis,
164
+					'depth'                 =>  (int) $row->majgv_place_depth,
165
+					'detailed_top_places'   =>  (int) $row->majgv_top_places
166
+				]);
167
+
168
+				if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) {
169
+					$view = $view->withColors($this->colorsDecoder($row->majgv_colors));
170
+				}
171
+
172
+				return $view instanceof AbstractGeoAnalysisView ? $view : null;
173
+			} catch (BindingResolutionException $ex) {
174
+				return null;
175
+			}
176
+		};
177
+	}
178
+
179
+	/**
180
+	 * Create a MapColorsConfig object from a JSON column value.
181
+	 * Returns null if the JSON string is invalid, or if the colors are not valid.
182
+	 *
183
+	 * @param string $colors_config
184
+	 * @return MapColorsConfig|NULL
185
+	 */
186
+	private function colorsDecoder(string $colors_config): ?MapColorsConfig
187
+	{
188
+		$colors = json_decode($colors_config, true);
189
+		if (!is_array($colors) && count($colors) !== 4) {
190
+			return null;
191
+		}
192
+		try {
193
+			return new MapColorsConfig(
194
+				\Spatie\Color\Factory::fromString($colors['default'] ?? ''),
195
+				\Spatie\Color\Factory::fromString($colors['stroke'] ?? ''),
196
+				\Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''),
197
+				\Spatie\Color\Factory::fromString($colors['hover'] ?? '')
198
+			);
199
+		} catch (InvalidColorValue $ex) {
200
+			return null;
201
+		}
202
+	}
203
+
204
+	/**
205
+	 * Get a closure to filter views by enabled/disabled status
206
+	 *
207
+	 * @param bool $include_disabled
208
+	 *
209
+	 * @return Closure(AbstractGeoAnalysisView $view):bool
210
+	 */
211
+	private function enabledFilter(bool $include_disabled): Closure
212
+	{
213
+		return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool {
214
+			return $include_disabled || $view->isEnabled();
215
+		};
216
+	}
217 217
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView
43 43
     {
44 44
         return $this->all($tree, $include_disabled)
45
-            ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id);
45
+            ->first(fn(AbstractGeoAnalysisView $view) : bool => $view->id() === $id);
46 46
     }
47 47
 
48 48
     /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     {
59 59
         return Registry::cache()->array()->remember(
60 60
             'all-geodispersion-views',
61
-            function () use ($tree, $include_disabled): Collection {
61
+            function() use ($tree, $include_disabled): Collection {
62 62
                 return DB::table('maj_geodisp_views')
63 63
                     ->select('maj_geodisp_views.*')
64 64
                     ->where('majgv_gedcom_id', '=', $tree->id())
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      */
149 149
     private function viewMapper(Tree $tree): Closure
150 150
     {
151
-        return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView {
151
+        return function(stdClass $row) use ($tree): ?AbstractGeoAnalysisView {
152 152
             try {
153 153
                 $geoanalysis = app($row->majgv_analysis);
154 154
                 if (!($geoanalysis instanceof GeoAnalysisInterface)) {
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
                 }
157 157
 
158 158
                 $view = app()->makeWith($row->majgv_view_class, [
159
-                    'id'                    =>  (int) $row->majgv_id,
159
+                    'id'                    =>  (int)$row->majgv_id,
160 160
                     'tree'                  =>  $tree,
161 161
                     'enabled'               =>  $row->majgv_status === 'enabled',
162 162
                     'description'           =>  $row->majgv_descr,
163 163
                     'geoanalysis'           =>  $geoanalysis,
164
-                    'depth'                 =>  (int) $row->majgv_place_depth,
165
-                    'detailed_top_places'   =>  (int) $row->majgv_top_places
164
+                    'depth'                 =>  (int)$row->majgv_place_depth,
165
+                    'detailed_top_places'   =>  (int)$row->majgv_top_places
166 166
                 ]);
167 167
 
168 168
                 if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) {
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
      */
211 211
     private function enabledFilter(bool $include_disabled): Closure
212 212
     {
213
-        return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool {
213
+        return function(AbstractGeoAnalysisView $view) use ($include_disabled): bool {
214 214
             return $include_disabled || $view->isEnabled();
215 215
         };
216 216
     }
Please login to merge, or discard this patch.