Passed
Push — feature/code-analysis ( 00c5b4...e321b8 )
by Jonathan
13:27
created
app/Module/GeoDispersion/Http/RequestHandlers/MapAdapterDeleteAction.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -32,67 +32,67 @@
 block discarded – undo
32 32
  */
33 33
 class MapAdapterDeleteAction implements RequestHandlerInterface
34 34
 {
35
-    private ?GeoDispersionModule $module;
36
-    private MapAdapterDataService $mapadapter_data_service;
35
+	private ?GeoDispersionModule $module;
36
+	private MapAdapterDataService $mapadapter_data_service;
37 37
 
38
-    /**
39
-     * Constructor for MapAdapterDeleteAction Request Handler
40
-     *
41
-     * @param ModuleService $module_service
42
-     * @param MapAdapterDataService $mapadapter_data_service
43
-     */
44
-    public function __construct(ModuleService $module_service, MapAdapterDataService $mapadapter_data_service)
45
-    {
46
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
47
-        $this->mapadapter_data_service = $mapadapter_data_service;
48
-    }
38
+	/**
39
+	 * Constructor for MapAdapterDeleteAction Request Handler
40
+	 *
41
+	 * @param ModuleService $module_service
42
+	 * @param MapAdapterDataService $mapadapter_data_service
43
+	 */
44
+	public function __construct(ModuleService $module_service, MapAdapterDataService $mapadapter_data_service)
45
+	{
46
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
47
+		$this->mapadapter_data_service = $mapadapter_data_service;
48
+	}
49 49
 
50
-    /**
51
-     * {@inheritDoc}
52
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
53
-     */
54
-    public function handle(ServerRequestInterface $request): ResponseInterface
55
-    {
56
-        $tree = Validator::attributes($request)->tree();
50
+	/**
51
+	 * {@inheritDoc}
52
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
53
+	 */
54
+	public function handle(ServerRequestInterface $request): ResponseInterface
55
+	{
56
+		$tree = Validator::attributes($request)->tree();
57 57
 
58
-        if ($this->module === null) {
59
-            FlashMessages::addMessage(
60
-                I18N::translate('The attached module could not be found.'),
61
-                'danger'
62
-            );
63
-            return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
64
-        }
58
+		if ($this->module === null) {
59
+			FlashMessages::addMessage(
60
+				I18N::translate('The attached module could not be found.'),
61
+				'danger'
62
+			);
63
+			return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
64
+		}
65 65
 
66
-        $adapter_id = Validator::attributes($request)->integer('adapter_id', -1);
67
-        $map_adapter = $this->mapadapter_data_service->find($adapter_id);
66
+		$adapter_id = Validator::attributes($request)->integer('adapter_id', -1);
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 “%s” does not exist.', I18N::number($adapter_id)),
72
-                'danger'
73
-            );
74
-            return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
75
-        }
69
+		if ($map_adapter === null) {
70
+			FlashMessages::addMessage(
71
+				I18N::translate('The map configuration with ID “%s” does not exist.', I18N::number($adapter_id)),
72
+				'danger'
73
+			);
74
+			return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
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 Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [
94
-            'tree'      => $tree->name(),
95
-            'view_id'   => $map_adapter->geoAnalysisViewId()
96
-        ]);
97
-    }
93
+		return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [
94
+			'tree'      => $tree->name(),
95
+			'view_id'   => $map_adapter->geoAnalysisViewId()
96
+		]);
97
+	}
98 98
 }
Please login to merge, or discard this patch.
Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewDeleteAction.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -32,64 +32,64 @@
 block discarded – undo
32 32
  */
33 33
 class GeoAnalysisViewDeleteAction 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 GeoAnalysisViewDeleteAction Request Handler
40
-     *
41
-     * @param ModuleService $module_service
42
-     * @param GeoAnalysisViewDataService $geoview_data_service
43
-     */
44
-    public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service)
45
-    {
46
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
47
-        $this->geoview_data_service = $geoview_data_service;
48
-    }
38
+	/**
39
+	 * Constructor for GeoAnalysisViewDeleteAction Request Handler
40
+	 *
41
+	 * @param ModuleService $module_service
42
+	 * @param GeoAnalysisViewDataService $geoview_data_service
43
+	 */
44
+	public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service)
45
+	{
46
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
47
+		$this->geoview_data_service = $geoview_data_service;
48
+	}
49 49
 
50
-    /**
51
-     * {@inheritDoc}
52
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
53
-     */
54
-    public function handle(ServerRequestInterface $request): ResponseInterface
55
-    {
56
-        $tree = Validator::attributes($request)->tree();
50
+	/**
51
+	 * {@inheritDoc}
52
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
53
+	 */
54
+	public function handle(ServerRequestInterface $request): ResponseInterface
55
+	{
56
+		$tree = Validator::attributes($request)->tree();
57 57
 
58
-        if ($this->module === null) {
59
-            FlashMessages::addMessage(
60
-                I18N::translate('The attached module could not be found.'),
61
-                'danger'
62
-            );
63
-            return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
64
-        }
58
+		if ($this->module === null) {
59
+			FlashMessages::addMessage(
60
+				I18N::translate('The attached module could not be found.'),
61
+				'danger'
62
+			);
63
+			return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
64
+		}
65 65
 
66
-        $view_id = Validator::attributes($request)->integer('view_id', -1);
67
-        $view = $this->geoview_data_service->find($tree, $view_id, true);
66
+		$view_id = Validator::attributes($request)->integer('view_id', -1);
67
+		$view = $this->geoview_data_service->find($tree, $view_id, true);
68 68
 
69
-        if ($view === null) {
70
-            FlashMessages::addMessage(
71
-                I18N::translate('The view with ID “%s” does not exist.', I18N::number($view_id)),
72
-                'danger'
73
-            );
74
-            return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
75
-        }
69
+		if ($view === null) {
70
+			FlashMessages::addMessage(
71
+				I18N::translate('The view with ID “%s” does not exist.', I18N::number($view_id)),
72
+				'danger'
73
+			);
74
+			return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
75
+		}
76 76
 
77
-        if ($this->geoview_data_service->delete($view) > 0) {
78
-            FlashMessages::addMessage(
79
-                I18N::translate('The geographical dispersion analysis view has been successfully deleted.'),
80
-                'success'
81
-            );
82
-            //phpcs:ignore Generic.Files.LineLength.TooLong
83
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been deleted.');
84
-        } else {
85
-            FlashMessages::addMessage(
86
-                I18N::translate('An error occured while deleting the geographical dispersion analysis view.'),
87
-                'danger'
88
-            );
89
-            //phpcs:ignore Generic.Files.LineLength.TooLong
90
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” could not be deleted. See error log.');
91
-        }
77
+		if ($this->geoview_data_service->delete($view) > 0) {
78
+			FlashMessages::addMessage(
79
+				I18N::translate('The geographical dispersion analysis view has been successfully deleted.'),
80
+				'success'
81
+			);
82
+			//phpcs:ignore Generic.Files.LineLength.TooLong
83
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been deleted.');
84
+		} else {
85
+			FlashMessages::addMessage(
86
+				I18N::translate('An error occured while deleting the geographical dispersion analysis view.'),
87
+				'danger'
88
+			);
89
+			//phpcs:ignore Generic.Files.LineLength.TooLong
90
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” could not be deleted. See error log.');
91
+		}
92 92
 
93
-        return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
94
-    }
93
+		return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
94
+	}
95 95
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Http/RequestHandlers/MapAdapterAddAction.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -38,95 +38,95 @@
 block discarded – undo
38 38
  */
39 39
 class MapAdapterAddAction implements RequestHandlerInterface
40 40
 {
41
-    private ?GeoDispersionModule $module;
42
-    private GeoAnalysisViewDataService $geoview_data_service;
43
-    private MapAdapterDataService $mapadapter_data_service;
44
-    private MapDefinitionsService $map_definition_service;
41
+	private ?GeoDispersionModule $module;
42
+	private GeoAnalysisViewDataService $geoview_data_service;
43
+	private MapAdapterDataService $mapadapter_data_service;
44
+	private MapDefinitionsService $map_definition_service;
45 45
 
46
-    /**
47
-     * Constructor for MapAdapterAddAction Request Handler
48
-     *
49
-     * @param ModuleService $module_service
50
-     * @param GeoAnalysisViewDataService $geoview_data_service
51
-     * @param MapAdapterDataService $mapadapter_data_service
52
-     * @param MapDefinitionsService $map_definition_service
53
-     */
54
-    public function __construct(
55
-        ModuleService $module_service,
56
-        GeoAnalysisViewDataService $geoview_data_service,
57
-        MapAdapterDataService $mapadapter_data_service,
58
-        MapDefinitionsService $map_definition_service
59
-    ) {
60
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
61
-        $this->geoview_data_service = $geoview_data_service;
62
-        $this->mapadapter_data_service = $mapadapter_data_service;
63
-        $this->map_definition_service = $map_definition_service;
64
-    }
46
+	/**
47
+	 * Constructor for MapAdapterAddAction Request Handler
48
+	 *
49
+	 * @param ModuleService $module_service
50
+	 * @param GeoAnalysisViewDataService $geoview_data_service
51
+	 * @param MapAdapterDataService $mapadapter_data_service
52
+	 * @param MapDefinitionsService $map_definition_service
53
+	 */
54
+	public function __construct(
55
+		ModuleService $module_service,
56
+		GeoAnalysisViewDataService $geoview_data_service,
57
+		MapAdapterDataService $mapadapter_data_service,
58
+		MapDefinitionsService $map_definition_service
59
+	) {
60
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
61
+		$this->geoview_data_service = $geoview_data_service;
62
+		$this->mapadapter_data_service = $mapadapter_data_service;
63
+		$this->map_definition_service = $map_definition_service;
64
+	}
65 65
 
66
-    /**
67
-     * {@inheritDoc}
68
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
69
-     */
70
-    public function handle(ServerRequestInterface $request): ResponseInterface
71
-    {
72
-        $tree = Validator::attributes($request)->tree();
66
+	/**
67
+	 * {@inheritDoc}
68
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
69
+	 */
70
+	public function handle(ServerRequestInterface $request): ResponseInterface
71
+	{
72
+		$tree = Validator::attributes($request)->tree();
73 73
 
74
-        if ($this->module === null) {
75
-            FlashMessages::addMessage(
76
-                I18N::translate('The attached module could not be found.'),
77
-                'danger'
78
-            );
79
-            return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
80
-        }
74
+		if ($this->module === null) {
75
+			FlashMessages::addMessage(
76
+				I18N::translate('The attached module could not be found.'),
77
+				'danger'
78
+			);
79
+			return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
80
+		}
81 81
 
82
-        $view_id = Validator::attributes($request)->integer('view_id', -1);
83
-        $view = $this->geoview_data_service->find($tree, $view_id);
82
+		$view_id = Validator::attributes($request)->integer('view_id', -1);
83
+		$view = $this->geoview_data_service->find($tree, $view_id);
84 84
 
85
-        $map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', ''));
86
-        $mapping_property   = Validator::parsedBody($request)->string('map_adapter_property_selected', '');
85
+		$map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', ''));
86
+		$mapping_property   = Validator::parsedBody($request)->string('map_adapter_property_selected', '');
87 87
 
88
-        $mapper = null;
89
-        try {
90
-            $mapper = app(Validator::parsedBody($request)->string('map_adapter_mapper', ''));
91
-        } catch (BindingResolutionException $ex) {
92
-        }
88
+		$mapper = null;
89
+		try {
90
+			$mapper = app(Validator::parsedBody($request)->string('map_adapter_mapper', ''));
91
+		} catch (BindingResolutionException $ex) {
92
+		}
93 93
 
94
-        if ($view === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) {
95
-            FlashMessages::addMessage(
96
-                I18N::translate('The parameters for the map configuration are not valid.'),
97
-                'danger'
98
-            );
99
-            return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
100
-        }
94
+		if ($view === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) {
95
+			FlashMessages::addMessage(
96
+				I18N::translate('The parameters for the map configuration are not valid.'),
97
+				'danger'
98
+			);
99
+			return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
100
+		}
101 101
 
102
-        $new_adapter_id = $this->mapadapter_data_service->insertGetId(
103
-            new GeoAnalysisMapAdapter(
104
-                0,
105
-                $view_id,
106
-                $map,
107
-                $mapper,
108
-                new MapViewConfig($mapping_property, $mapper->config()->withConfigUpdate($request))
109
-            )
110
-        );
111
-        if ($new_adapter_id > 0) {
112
-            FlashMessages::addMessage(
113
-                I18N::translate('The map configuration has been successfully added.'),
114
-                'success'
115
-            );
116
-            //phpcs:ignore Generic.Files.LineLength.TooLong
117
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $new_adapter_id . '” has been added.');
118
-        } else {
119
-            FlashMessages::addMessage(
120
-                I18N::translate('An error occured while adding a new map configuration.'),
121
-                'danger'
122
-            );
123
-            //phpcs:ignore Generic.Files.LineLength.TooLong
124
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter could not be added. See error log.');
125
-        }
102
+		$new_adapter_id = $this->mapadapter_data_service->insertGetId(
103
+			new GeoAnalysisMapAdapter(
104
+				0,
105
+				$view_id,
106
+				$map,
107
+				$mapper,
108
+				new MapViewConfig($mapping_property, $mapper->config()->withConfigUpdate($request))
109
+			)
110
+		);
111
+		if ($new_adapter_id > 0) {
112
+			FlashMessages::addMessage(
113
+				I18N::translate('The map configuration has been successfully added.'),
114
+				'success'
115
+			);
116
+			//phpcs:ignore Generic.Files.LineLength.TooLong
117
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $new_adapter_id . '” has been added.');
118
+		} else {
119
+			FlashMessages::addMessage(
120
+				I18N::translate('An error occured while adding a new map configuration.'),
121
+				'danger'
122
+			);
123
+			//phpcs:ignore Generic.Files.LineLength.TooLong
124
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter could not be added. See error log.');
125
+		}
126 126
 
127
-        return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [
128
-            'tree' => $tree->name(),
129
-            'view_id' => $view_id
130
-        ]);
131
-    }
127
+		return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [
128
+			'tree' => $tree->name(),
129
+			'view_id' => $view_id
130
+		]);
131
+	}
132 132
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewEditAction.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -35,87 +35,87 @@
 block discarded – undo
35 35
  */
36 36
 class GeoAnalysisViewEditAction implements RequestHandlerInterface
37 37
 {
38
-    private ?GeoDispersionModule $module;
39
-    private GeoAnalysisViewDataService $geoview_data_service;
40
-
41
-    /**
42
-     * Constructor for GeoAnalysisViewEditAction Request Handler
43
-     *
44
-     * @param ModuleService $module_service
45
-     * @param GeoAnalysisViewDataService $geoview_data_service
46
-     */
47
-    public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service)
48
-    {
49
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
50
-        $this->geoview_data_service = $geoview_data_service;
51
-    }
52
-
53
-    /**
54
-     * {@inheritDoc}
55
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
-     */
57
-    public function handle(ServerRequestInterface $request): ResponseInterface
58
-    {
59
-        $tree = Validator::attributes($request)->tree();
60
-
61
-        if ($this->module === null) {
62
-            FlashMessages::addMessage(
63
-                I18N::translate('The attached module could not be found.'),
64
-                'danger'
65
-            );
66
-            return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
67
-        }
68
-
69
-
70
-        $view_id = Validator::attributes($request)->integer('view_id', -1);
71
-        $view = $this->geoview_data_service->find($tree, $view_id, true);
72
-
73
-        $description    = Validator::parsedBody($request)->string('view_description', '');
74
-        $place_depth    = Validator::parsedBody($request)->integer('view_depth', 1);
75
-        $top_places     = Validator::parsedBody($request)->integer('view_top_places', 0);
76
-
77
-        $analysis = null;
78
-        try {
79
-            $analysis = app(Validator::parsedBody($request)->string('view_analysis', ''));
80
-        } catch (BindingResolutionException $ex) {
81
-        }
82
-
83
-        if (
84
-            $view === null
85
-            || $analysis === null || !($analysis instanceof GeoAnalysisInterface)
86
-            || $place_depth <= 0 && $top_places < 0
87
-        ) {
88
-            FlashMessages::addMessage(
89
-                I18N::translate('The parameters for view with ID “%s” are not valid.', I18N::number($view_id)),
90
-                'danger'
91
-            );
92
-            return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
93
-        }
94
-
95
-        $new_view = $view
96
-            ->with($view->isEnabled(), $description, $analysis, $place_depth, $top_places)
97
-            ->withGlobalSettingsUpdate($request);
98
-
99
-        try {
100
-            $this->geoview_data_service->update($new_view);
101
-            FlashMessages::addMessage(
102
-                I18N::translate('The geographical dispersion analysis view has been successfully updated.'),
103
-                'success'
104
-            );
105
-            //phpcs:ignore Generic.Files.LineLength.TooLong
106
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.');
107
-        } catch (Throwable $ex) {
108
-            FlashMessages::addMessage(
109
-                I18N::translate('An error occured while updating the geographical dispersion analysis view.'),
110
-                'danger'
111
-            );
112
-            //phpcs:ignore Generic.Files.LineLength.TooLong
113
-            Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage());
114
-        }
115
-
116
-        return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [
117
-            'tree' => $tree->name(),
118
-            'view_id' => $view->id()
119
-        ]);
120
-    }
38
+	private ?GeoDispersionModule $module;
39
+	private GeoAnalysisViewDataService $geoview_data_service;
40
+
41
+	/**
42
+	 * Constructor for GeoAnalysisViewEditAction Request Handler
43
+	 *
44
+	 * @param ModuleService $module_service
45
+	 * @param GeoAnalysisViewDataService $geoview_data_service
46
+	 */
47
+	public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service)
48
+	{
49
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
50
+		$this->geoview_data_service = $geoview_data_service;
51
+	}
52
+
53
+	/**
54
+	 * {@inheritDoc}
55
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
+	 */
57
+	public function handle(ServerRequestInterface $request): ResponseInterface
58
+	{
59
+		$tree = Validator::attributes($request)->tree();
60
+
61
+		if ($this->module === null) {
62
+			FlashMessages::addMessage(
63
+				I18N::translate('The attached module could not be found.'),
64
+				'danger'
65
+			);
66
+			return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
67
+		}
68
+
69
+
70
+		$view_id = Validator::attributes($request)->integer('view_id', -1);
71
+		$view = $this->geoview_data_service->find($tree, $view_id, true);
72
+
73
+		$description    = Validator::parsedBody($request)->string('view_description', '');
74
+		$place_depth    = Validator::parsedBody($request)->integer('view_depth', 1);
75
+		$top_places     = Validator::parsedBody($request)->integer('view_top_places', 0);
76
+
77
+		$analysis = null;
78
+		try {
79
+			$analysis = app(Validator::parsedBody($request)->string('view_analysis', ''));
80
+		} catch (BindingResolutionException $ex) {
81
+		}
82
+
83
+		if (
84
+			$view === null
85
+			|| $analysis === null || !($analysis instanceof GeoAnalysisInterface)
86
+			|| $place_depth <= 0 && $top_places < 0
87
+		) {
88
+			FlashMessages::addMessage(
89
+				I18N::translate('The parameters for view with ID “%s” are not valid.', I18N::number($view_id)),
90
+				'danger'
91
+			);
92
+			return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
93
+		}
94
+
95
+		$new_view = $view
96
+			->with($view->isEnabled(), $description, $analysis, $place_depth, $top_places)
97
+			->withGlobalSettingsUpdate($request);
98
+
99
+		try {
100
+			$this->geoview_data_service->update($new_view);
101
+			FlashMessages::addMessage(
102
+				I18N::translate('The geographical dispersion analysis view has been successfully updated.'),
103
+				'success'
104
+			);
105
+			//phpcs:ignore Generic.Files.LineLength.TooLong
106
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.');
107
+		} catch (Throwable $ex) {
108
+			FlashMessages::addMessage(
109
+				I18N::translate('An error occured while updating the geographical dispersion analysis view.'),
110
+				'danger'
111
+			);
112
+			//phpcs:ignore Generic.Files.LineLength.TooLong
113
+			Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage());
114
+		}
115
+
116
+		return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [
117
+			'tree' => $tree->name(),
118
+			'view_id' => $view->id()
119
+		]);
120
+	}
121 121
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewAddAction.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -36,81 +36,81 @@
 block discarded – undo
36 36
  */
37 37
 class GeoAnalysisViewAddAction implements RequestHandlerInterface
38 38
 {
39
-    private ?GeoDispersionModule $module;
40
-    private GeoAnalysisViewDataService $geoview_data_service;
39
+	private ?GeoDispersionModule $module;
40
+	private GeoAnalysisViewDataService $geoview_data_service;
41 41
 
42
-    /**
43
-     * Constructor for GeoAnalysisViewAddAction Request Handler
44
-     *
45
-     * @param ModuleService $module_service
46
-     * @param GeoAnalysisViewDataService $geoview_data_service
47
-     */
48
-    public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service)
49
-    {
50
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
51
-        $this->geoview_data_service = $geoview_data_service;
52
-    }
42
+	/**
43
+	 * Constructor for GeoAnalysisViewAddAction Request Handler
44
+	 *
45
+	 * @param ModuleService $module_service
46
+	 * @param GeoAnalysisViewDataService $geoview_data_service
47
+	 */
48
+	public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service)
49
+	{
50
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
51
+		$this->geoview_data_service = $geoview_data_service;
52
+	}
53 53
 
54
-    /**
55
-     * {@inheritDoc}
56
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
57
-     */
58
-    public function handle(ServerRequestInterface $request): ResponseInterface
59
-    {
60
-        $tree = Validator::attributes($request)->tree();
54
+	/**
55
+	 * {@inheritDoc}
56
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
57
+	 */
58
+	public function handle(ServerRequestInterface $request): ResponseInterface
59
+	{
60
+		$tree = Validator::attributes($request)->tree();
61 61
 
62
-        if ($this->module === null) {
63
-            FlashMessages::addMessage(
64
-                I18N::translate('The attached module could not be found.'),
65
-                'danger'
66
-            );
67
-            return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
68
-        }
62
+		if ($this->module === null) {
63
+			FlashMessages::addMessage(
64
+				I18N::translate('The attached module could not be found.'),
65
+				'danger'
66
+			);
67
+			return Registry::responseFactory()->redirect(HomePage::class, ['tree' => $tree->name()]);
68
+		}
69 69
 
70
-        $type           = Validator::parsedBody($request)->isInArray(['table', 'map'])->string('view_type', '');
71
-        $description    = Validator::parsedBody($request)->string('view_description', '');
72
-        $place_depth    = Validator::parsedBody($request)->integer('view_depth', 1);
70
+		$type           = Validator::parsedBody($request)->isInArray(['table', 'map'])->string('view_type', '');
71
+		$description    = Validator::parsedBody($request)->string('view_description', '');
72
+		$place_depth    = Validator::parsedBody($request)->integer('view_depth', 1);
73 73
 
74
-        $analysis = null;
75
-        try {
76
-            $analysis = app(Validator::parsedBody($request)->string('view_analysis', ''));
77
-        } catch (BindingResolutionException $ex) {
78
-        }
74
+		$analysis = null;
75
+		try {
76
+			$analysis = app(Validator::parsedBody($request)->string('view_analysis', ''));
77
+		} catch (BindingResolutionException $ex) {
78
+		}
79 79
 
80
-        if ($type === '' || $place_depth <= 0 || $analysis === null || !($analysis instanceof GeoAnalysisInterface)) {
81
-            FlashMessages::addMessage(
82
-                I18N::translate('The parameters for the new view are not valid.'),
83
-                'danger'
84
-            );
85
-            return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
86
-        }
80
+		if ($type === '' || $place_depth <= 0 || $analysis === null || !($analysis instanceof GeoAnalysisInterface)) {
81
+			FlashMessages::addMessage(
82
+				I18N::translate('The parameters for the new view are not valid.'),
83
+				'danger'
84
+			);
85
+			return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
86
+		}
87 87
 
88
-        if ($type === 'map') {
89
-            $new_view = new GeoAnalysisMap(0, $tree, true, $description, $analysis, $place_depth);
90
-        } else {
91
-            $new_view = new GeoAnalysisTable(0, $tree, true, $description, $analysis, $place_depth);
92
-        }
88
+		if ($type === 'map') {
89
+			$new_view = new GeoAnalysisMap(0, $tree, true, $description, $analysis, $place_depth);
90
+		} else {
91
+			$new_view = new GeoAnalysisTable(0, $tree, true, $description, $analysis, $place_depth);
92
+		}
93 93
 
94
-        $new_view_id = $this->geoview_data_service->insertGetId($new_view);
95
-        if ($new_view_id > 0) {
96
-            FlashMessages::addMessage(
97
-                I18N::translate('The geographical dispersion analysis view has been successfully added.'),
98
-                'success'
99
-            );
100
-            //phpcs:ignore Generic.Files.LineLength.TooLong
101
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $new_view_id . '” has been added.');
102
-            return Registry::responseFactory()->redirect(
103
-                GeoAnalysisViewEditPage::class,
104
-                ['tree' => $tree->name(), 'view_id' => $new_view_id ]
105
-            );
106
-        } else {
107
-            FlashMessages::addMessage(
108
-                I18N::translate('An error occured while adding the geographical dispersion analysis view.'),
109
-                'danger'
110
-            );
111
-            //phpcs:ignore Generic.Files.LineLength.TooLong
112
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : A new View could not be added. See error log.');
113
-            return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
114
-        }
115
-    }
94
+		$new_view_id = $this->geoview_data_service->insertGetId($new_view);
95
+		if ($new_view_id > 0) {
96
+			FlashMessages::addMessage(
97
+				I18N::translate('The geographical dispersion analysis view has been successfully added.'),
98
+				'success'
99
+			);
100
+			//phpcs:ignore Generic.Files.LineLength.TooLong
101
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $new_view_id . '” has been added.');
102
+			return Registry::responseFactory()->redirect(
103
+				GeoAnalysisViewEditPage::class,
104
+				['tree' => $tree->name(), 'view_id' => $new_view_id ]
105
+			);
106
+		} else {
107
+			FlashMessages::addMessage(
108
+				I18N::translate('An error occured while adding the geographical dispersion analysis view.'),
109
+				'danger'
110
+			);
111
+			//phpcs:ignore Generic.Files.LineLength.TooLong
112
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : A new View could not be added. See error log.');
113
+			return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
114
+		}
115
+	}
116 116
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/PlacesReferenceTableService.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -21,88 +21,88 @@
 block discarded – undo
21 21
  */
22 22
 class PlacesReferenceTableService
23 23
 {
24
-    /**
25
-     * Mapping format placeholder tags => table column names
26
-     * @var array<string, string>
27
-     */
28
-    private const COLUMN_MAPPING = [
29
-        'name'  =>  'majgr_place_name',
30
-        'id'    =>  'majgr_place_admin_id',
31
-        'zip'   =>  'majgr_place_zip',
32
-        'gov'   =>  'majgr_place_gov_id',
33
-        'mls'   =>  'majgr_place_mls_id'
34
-    ];
24
+	/**
25
+	 * Mapping format placeholder tags => table column names
26
+	 * @var array<string, string>
27
+	 */
28
+	private const COLUMN_MAPPING = [
29
+		'name'  =>  'majgr_place_name',
30
+		'id'    =>  'majgr_place_admin_id',
31
+		'zip'   =>  'majgr_place_zip',
32
+		'gov'   =>  'majgr_place_gov_id',
33
+		'mls'   =>  'majgr_place_mls_id'
34
+	];
35 35
 
36
-    /**
37
-     * Get the formatted target mapping value of a place defined by a source format.
38
-     *
39
-     * @param string $source
40
-     * @param string $source_format
41
-     * @param string $target_format
42
-     * @return string|NULL
43
-     */
44
-    public function targetId(string $source, string $source_format, string $target_format): ?string
45
-    {
46
-        // Extract parts for the WHERE clause
47
-        $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format);
48
-        $source_parts = preg_split('/[{}]/i', $source_format);
49
-        if ($source_parts === false) {
50
-            return null;
51
-        }
52
-        $source_parts = array_map(function (string $part): string {
53
-            if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54
-                return $this->columnName($column_id[1]);
55
-            }
56
-            return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57
-        }, array_filter($source_parts));
58
-        $source_parts[] = "'%'";
59
-        $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
36
+	/**
37
+	 * Get the formatted target mapping value of a place defined by a source format.
38
+	 *
39
+	 * @param string $source
40
+	 * @param string $source_format
41
+	 * @param string $target_format
42
+	 * @return string|NULL
43
+	 */
44
+	public function targetId(string $source, string $source_format, string $target_format): ?string
45
+	{
46
+		// Extract parts for the WHERE clause
47
+		$source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format);
48
+		$source_parts = preg_split('/[{}]/i', $source_format);
49
+		if ($source_parts === false) {
50
+			return null;
51
+		}
52
+		$source_parts = array_map(function (string $part): string {
53
+			if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54
+				return $this->columnName($column_id[1]);
55
+			}
56
+			return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57
+		}, array_filter($source_parts));
58
+		$source_parts[] = "'%'";
59
+		$concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
60 60
 
61
-        // Extract columns used in target
62
-        $columns = [];
63
-        if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) {
64
-            $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1])));
65
-        }
61
+		// Extract columns used in target
62
+		$columns = [];
63
+		if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) {
64
+			$columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1])));
65
+		}
66 66
 
67
-        // Get the mapping
68
-        $rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69
-            ->select($columns)
70
-            ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
71
-            ->get();
67
+		// Get the mapping
68
+		$rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69
+			->select($columns)
70
+			->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
71
+			->get();
72 72
 
73
-        // Format the output ID
74
-        if ($rows->count() === 0) {
75
-            return null;
76
-        }
73
+		// Format the output ID
74
+		if ($rows->count() === 0) {
75
+			return null;
76
+		}
77 77
 
78
-        $mapping = (array) $rows->first();
78
+		$mapping = (array) $rows->first();
79 79
 
80
-        return str_replace(
81
-            array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
82
-            array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
83
-            $target_format
84
-        );
85
-    }
80
+		return str_replace(
81
+			array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
82
+			array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
83
+			$target_format
84
+		);
85
+	}
86 86
 
87
-    /**
88
-     * Get the column name for a format placeholder tag
89
-     *
90
-     * @param string $placeholder
91
-     * @return string
92
-     */
93
-    private function columnName(string $placeholder): string
94
-    {
95
-        return self::COLUMN_MAPPING[$placeholder] ?? '';
96
-    }
87
+	/**
88
+	 * Get the column name for a format placeholder tag
89
+	 *
90
+	 * @param string $placeholder
91
+	 * @return string
92
+	 */
93
+	private function columnName(string $placeholder): string
94
+	{
95
+		return self::COLUMN_MAPPING[$placeholder] ?? '';
96
+	}
97 97
 
98
-    /**
99
-     * Sanitize string for use in a SQL query.
100
-     *
101
-     * @param string $string
102
-     * @return string
103
-     */
104
-    private function sanitizeString(string $string): string
105
-    {
106
-        return DB::connection()->getPdo()->quote($string);
107
-    }
98
+	/**
99
+	 * Sanitize string for use in a SQL query.
100
+	 *
101
+	 * @param string $string
102
+	 * @return string
103
+	 */
104
+	private function sanitizeString(string $string): string
105
+	{
106
+		return DB::connection()->getPdo()->quote($string);
107
+	}
108 108
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
         if ($source_parts === false) {
50 50
             return null;
51 51
         }
52
-        $source_parts = array_map(function (string $part): string {
52
+        $source_parts = array_map(function(string $part): string {
53 53
             if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54 54
                 return $this->columnName($column_id[1]);
55 55
             }
56 56
             return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57 57
         }, array_filter($source_parts));
58 58
         $source_parts[] = "'%'";
59
-        $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
59
+        $concat_statement = 'CONCAT('.implode(', ', $source_parts).')';
60 60
 
61 61
         // Extract columns used in target
62 62
         $columns = [];
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         // Get the mapping
68 68
         $rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69 69
             ->select($columns)
70
-            ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
70
+            ->whereRaw($this->sanitizeString($source)." LIKE ".$concat_statement)
71 71
             ->get();
72 72
 
73 73
         // Format the output ID
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
             return null;
76 76
         }
77 77
 
78
-        $mapping = (array) $rows->first();
78
+        $mapping = (array)$rows->first();
79 79
 
80 80
         return str_replace(
81
-            array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
81
+            array_map(fn($tag) => '{'.$tag.'}', $columns_select[1]),
82 82
             array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
83 83
             $target_format
84 84
         );
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/GeoAnalysisViewDataService.php 1 patch
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.
app/Module/GeoDispersion/Services/GeoAnalysisDataService.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -26,64 +26,64 @@
 block discarded – undo
26 26
  */
27 27
 class GeoAnalysisDataService
28 28
 {
29
-    /**
30
-     * Yields indviduals and family records for a specified tree.
31
-     *
32
-     * @param Tree $tree
33
-     * @return \Generator<\Fisharebest\Webtrees\GedcomRecord>
34
-     */
35
-    public function individualsAndFamilies(Tree $tree): Generator
36
-    {
37
-        yield from DB::table('individuals')
38
-            ->where('i_file', '=', $tree->id())
39
-            ->select(['individuals.*'])
40
-            ->get()
41
-            ->map(Registry::individualFactory()->mapper($tree))
42
-            ->filter(GedcomRecord::accessFilter())
43
-            ->all();
29
+	/**
30
+	 * Yields indviduals and family records for a specified tree.
31
+	 *
32
+	 * @param Tree $tree
33
+	 * @return \Generator<\Fisharebest\Webtrees\GedcomRecord>
34
+	 */
35
+	public function individualsAndFamilies(Tree $tree): Generator
36
+	{
37
+		yield from DB::table('individuals')
38
+			->where('i_file', '=', $tree->id())
39
+			->select(['individuals.*'])
40
+			->get()
41
+			->map(Registry::individualFactory()->mapper($tree))
42
+			->filter(GedcomRecord::accessFilter())
43
+			->all();
44 44
 
45
-        yield from DB::table('families')
46
-            ->where('f_file', '=', $tree->id())
47
-            ->select(['families.*'])
48
-            ->get()
49
-            ->map(Registry::familyFactory()->mapper($tree))
50
-            ->filter(GedcomRecord::accessFilter())
51
-            ->all();
52
-    }
45
+		yield from DB::table('families')
46
+			->where('f_file', '=', $tree->id())
47
+			->select(['families.*'])
48
+			->get()
49
+			->map(Registry::familyFactory()->mapper($tree))
50
+			->filter(GedcomRecord::accessFilter())
51
+			->all();
52
+	}
53 53
 
54
-    /**
55
-     * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest
56
-     * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first).
57
-     *
58
-     * {@internal The places are taken only from the individuals and families records.}
59
-     *
60
-     * @param Tree $tree
61
-     * @return array<int, string[]>
62
-     */
63
-    public function placeHierarchyExample(Tree $tree): array
64
-    {
65
-        $query_individuals = DB::table('individuals')
66
-            ->select(['i_gedcom AS g_gedcom'])
67
-            ->where('i_file', '=', $tree->id())
68
-            ->where('i_gedcom', 'like', '%2 PLAC %');
54
+	/**
55
+	 * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest
56
+	 * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first).
57
+	 *
58
+	 * {@internal The places are taken only from the individuals and families records.}
59
+	 *
60
+	 * @param Tree $tree
61
+	 * @return array<int, string[]>
62
+	 */
63
+	public function placeHierarchyExample(Tree $tree): array
64
+	{
65
+		$query_individuals = DB::table('individuals')
66
+			->select(['i_gedcom AS g_gedcom'])
67
+			->where('i_file', '=', $tree->id())
68
+			->where('i_gedcom', 'like', '%2 PLAC %');
69 69
 
70
-        $query_families = DB::table('families')
71
-            ->select(['f_gedcom AS g_gedcom'])
72
-            ->where('f_file', '=', $tree->id())
73
-            ->where('f_gedcom', 'like', '%2 PLAC %');
70
+		$query_families = DB::table('families')
71
+			->select(['f_gedcom AS g_gedcom'])
72
+			->where('f_file', '=', $tree->id())
73
+			->where('f_gedcom', 'like', '%2 PLAC %');
74 74
 
75
-        return $query_individuals->unionAll($query_families)
76
-            ->get()->pluck('g_gedcom')
77
-            ->flatMap(static function (string $gedcom): array {
78
-                preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches);
79
-                return $matches[1];
80
-            })
81
-            ->sort(I18N::comparator())->reverse()
82
-            ->mapWithKeys(static function (string $place): array {
83
-                $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place))));
84
-                return [ count($place_array) => $place_array ];
85
-            })
86
-            ->sortKeys()
87
-            ->last() ?? [];
88
-    }
75
+		return $query_individuals->unionAll($query_families)
76
+			->get()->pluck('g_gedcom')
77
+			->flatMap(static function (string $gedcom): array {
78
+				preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches);
79
+				return $matches[1];
80
+			})
81
+			->sort(I18N::comparator())->reverse()
82
+			->mapWithKeys(static function (string $place): array {
83
+				$place_array = array_reverse(array_filter(array_map('trim', explode(",", $place))));
84
+				return [ count($place_array) => $place_array ];
85
+			})
86
+			->sortKeys()
87
+			->last() ?? [];
88
+	}
89 89
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -74,14 +74,14 @@
 block discarded – undo
74 74
 
75 75
         return $query_individuals->unionAll($query_families)
76 76
             ->get()->pluck('g_gedcom')
77
-            ->flatMap(static function (string $gedcom): array {
77
+            ->flatMap(static function(string $gedcom): array {
78 78
                 preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches);
79 79
                 return $matches[1];
80 80
             })
81 81
             ->sort(I18N::comparator())->reverse()
82
-            ->mapWithKeys(static function (string $place): array {
82
+            ->mapWithKeys(static function(string $place): array {
83 83
                 $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place))));
84
-                return [ count($place_array) => $place_array ];
84
+                return [count($place_array) => $place_array];
85 85
             })
86 86
             ->sortKeys()
87 87
             ->last() ?? [];
Please login to merge, or discard this patch.
app/Module/GeoDispersion/GeoDispersionModule.php 1 patch
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -59,188 +59,188 @@
 block discarded – undo
59 59
  * Geographical Dispersion Module.
60 60
  */
61 61
 class GeoDispersionModule extends AbstractModule implements
62
-    ModuleMyArtJaubInterface,
63
-    ModuleChartInterface,
64
-    ModuleConfigInterface,
65
-    ModuleGlobalInterface,
66
-    ModuleGeoAnalysisProviderInterface,
67
-    ModulePlaceMapperProviderInterface
62
+	ModuleMyArtJaubInterface,
63
+	ModuleChartInterface,
64
+	ModuleConfigInterface,
65
+	ModuleGlobalInterface,
66
+	ModuleGeoAnalysisProviderInterface,
67
+	ModulePlaceMapperProviderInterface
68 68
 {
69
-    use ModuleMyArtJaubTrait {
70
-        boot as traitBoot;
71
-    }
72
-    use ModuleChartTrait;
73
-    use ModuleConfigTrait;
74
-    use ModuleGlobalTrait;
75
-
76
-    // How to update the database schema for this module
77
-    private const SCHEMA_TARGET_VERSION   = 3;
78
-    private const SCHEMA_SETTING_NAME     = 'MAJ_GEODISP_SCHEMA_VERSION';
79
-    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
80
-
81
-    /**
82
-     * {@inheritDoc}
83
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
84
-     */
85
-    public function title(): string
86
-    {
87
-        return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion');
88
-    }
89
-
90
-    /**
91
-     * {@inheritDoc}
92
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
93
-     */
94
-    public function description(): string
95
-    {
96
-        //phpcs:ignore Generic.Files.LineLength.TooLong
97
-        return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.');
98
-    }
99
-
100
-    /**
101
-     * {@inheritDoc}
102
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
103
-     */
104
-    public function boot(): void
105
-    {
106
-        $this->traitBoot();
107
-        app(MigrationService::class)->updateSchema(
108
-            self::SCHEMA_MIGRATION_PREFIX,
109
-            self::SCHEMA_SETTING_NAME,
110
-            self::SCHEMA_TARGET_VERSION
111
-        );
112
-    }
113
-
114
-    /**
115
-     * {@inheritDoc}
116
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
117
-     */
118
-    public function customModuleVersion(): string
119
-    {
120
-        return '2.1.18-v.2';
121
-    }
122
-
123
-    /**
124
-     * {@inheritDoc}
125
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
126
-     */
127
-    public function loadRoutes(Map $router): void
128
-    {
129
-        $router->attach('', '', static function (Map $router): void {
130
-
131
-            $router->attach('', '/module-maj/geodispersion', static function (Map $router): void {
132
-                $router->attach('', '/admin', static function (Map $router): void {
133
-                    $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class);
134
-
135
-                    $router->attach('', '/analysis-views/{tree}', static function (Map $router): void {
136
-                        $router->tokens(['view_id' => '\d+', 'enable' => '[01]']);
137
-                        $router->extras([
138
-                            'middleware' => [
139
-                                AuthManager::class,
140
-                            ],
141
-                        ]);
142
-                        $router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class);
143
-
144
-                        $router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class);
145
-                        $router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class);
146
-                        $router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class);
147
-                        $router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class);
148
-                        //phpcs:disable Generic.Files.LineLength.TooLong
149
-                        $router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class);
150
-                        $router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class);
151
-                        //phpcs:enable
152
-                    });
153
-
154
-                    $router->attach('', '/map-adapters/{tree}', static function (Map $router): void {
155
-                        $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']);
156
-                        $router->extras([
157
-                            'middleware' => [
158
-                                AuthManager::class,
159
-                            ],
160
-                        ]);
161
-
162
-                        $router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class);
163
-                        $router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class);
164
-                        $router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class);
165
-                        $router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class);
166
-                        //phpcs:disable Generic.Files.LineLength.TooLong
167
-                        $router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class);
168
-                        $router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class);
169
-                        $router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class);
170
-                        //phpcs:enable
171
-                    });
172
-
173
-                    //phpcs:ignore Generic.Files.LineLength.TooLong
174
-                    $router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class);
175
-                });
176
-
177
-                $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class);
178
-
179
-                $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void {
180
-                    $router->tokens(['view_id' => '\d+']);
181
-                    $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class);
182
-                    $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class);
183
-                });
184
-            });
185
-        });
186
-    }
187
-
188
-    public function getConfigLink(): string
189
-    {
190
-        return route(AdminConfigPage::class);
191
-    }
192
-
193
-    /**
194
-     * {@inheritDoc}
195
-     * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl()
196
-     *
197
-     * @param array<bool|int|string|array<mixed>|null> $parameters
198
-     */
199
-    public function chartUrl(Individual $individual, array $parameters = []): string
200
-    {
201
-        return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters);
202
-    }
203
-
204
-    /**
205
-     * {@inheritDoc}
206
-     * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass()
207
-     */
208
-    public function chartMenuClass(): string
209
-    {
210
-        return 'menu-maj-geodispersion';
211
-    }
212
-
213
-    /**
214
-     * {@inheritDoc}
215
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
216
-     */
217
-    public function headContent(): string
218
-    {
219
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
220
-    }
221
-
222
-    /**
223
-     * {@inheritDoc}
224
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers()
225
-     */
226
-    public function listPlaceMappers(): array
227
-    {
228
-        return [
229
-            CoordinatesPlaceMapper::class,
230
-            SimplePlaceMapper::class,
231
-            SimpleTopFilteredPlaceMapper::class
232
-        ];
233
-    }
234
-
235
-    /**
236
-     * {@inheritDoc}
237
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
238
-     */
239
-    public function listGeoAnalyses(): array
240
-    {
241
-        return [
242
-            AllEventsByCenturyGeoAnalysis::class,
243
-            AllEventsByTypeGeoAnalysis::class
244
-        ];
245
-    }
69
+	use ModuleMyArtJaubTrait {
70
+		boot as traitBoot;
71
+	}
72
+	use ModuleChartTrait;
73
+	use ModuleConfigTrait;
74
+	use ModuleGlobalTrait;
75
+
76
+	// How to update the database schema for this module
77
+	private const SCHEMA_TARGET_VERSION   = 3;
78
+	private const SCHEMA_SETTING_NAME     = 'MAJ_GEODISP_SCHEMA_VERSION';
79
+	private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
80
+
81
+	/**
82
+	 * {@inheritDoc}
83
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
84
+	 */
85
+	public function title(): string
86
+	{
87
+		return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion');
88
+	}
89
+
90
+	/**
91
+	 * {@inheritDoc}
92
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
93
+	 */
94
+	public function description(): string
95
+	{
96
+		//phpcs:ignore Generic.Files.LineLength.TooLong
97
+		return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.');
98
+	}
99
+
100
+	/**
101
+	 * {@inheritDoc}
102
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
103
+	 */
104
+	public function boot(): void
105
+	{
106
+		$this->traitBoot();
107
+		app(MigrationService::class)->updateSchema(
108
+			self::SCHEMA_MIGRATION_PREFIX,
109
+			self::SCHEMA_SETTING_NAME,
110
+			self::SCHEMA_TARGET_VERSION
111
+		);
112
+	}
113
+
114
+	/**
115
+	 * {@inheritDoc}
116
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
117
+	 */
118
+	public function customModuleVersion(): string
119
+	{
120
+		return '2.1.18-v.2';
121
+	}
122
+
123
+	/**
124
+	 * {@inheritDoc}
125
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
126
+	 */
127
+	public function loadRoutes(Map $router): void
128
+	{
129
+		$router->attach('', '', static function (Map $router): void {
130
+
131
+			$router->attach('', '/module-maj/geodispersion', static function (Map $router): void {
132
+				$router->attach('', '/admin', static function (Map $router): void {
133
+					$router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class);
134
+
135
+					$router->attach('', '/analysis-views/{tree}', static function (Map $router): void {
136
+						$router->tokens(['view_id' => '\d+', 'enable' => '[01]']);
137
+						$router->extras([
138
+							'middleware' => [
139
+								AuthManager::class,
140
+							],
141
+						]);
142
+						$router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class);
143
+
144
+						$router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class);
145
+						$router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class);
146
+						$router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class);
147
+						$router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class);
148
+						//phpcs:disable Generic.Files.LineLength.TooLong
149
+						$router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class);
150
+						$router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class);
151
+						//phpcs:enable
152
+					});
153
+
154
+					$router->attach('', '/map-adapters/{tree}', static function (Map $router): void {
155
+						$router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']);
156
+						$router->extras([
157
+							'middleware' => [
158
+								AuthManager::class,
159
+							],
160
+						]);
161
+
162
+						$router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class);
163
+						$router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class);
164
+						$router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class);
165
+						$router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class);
166
+						//phpcs:disable Generic.Files.LineLength.TooLong
167
+						$router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class);
168
+						$router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class);
169
+						$router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class);
170
+						//phpcs:enable
171
+					});
172
+
173
+					//phpcs:ignore Generic.Files.LineLength.TooLong
174
+					$router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class);
175
+				});
176
+
177
+				$router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class);
178
+
179
+				$router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void {
180
+					$router->tokens(['view_id' => '\d+']);
181
+					$router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class);
182
+					$router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class);
183
+				});
184
+			});
185
+		});
186
+	}
187
+
188
+	public function getConfigLink(): string
189
+	{
190
+		return route(AdminConfigPage::class);
191
+	}
192
+
193
+	/**
194
+	 * {@inheritDoc}
195
+	 * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl()
196
+	 *
197
+	 * @param array<bool|int|string|array<mixed>|null> $parameters
198
+	 */
199
+	public function chartUrl(Individual $individual, array $parameters = []): string
200
+	{
201
+		return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters);
202
+	}
203
+
204
+	/**
205
+	 * {@inheritDoc}
206
+	 * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass()
207
+	 */
208
+	public function chartMenuClass(): string
209
+	{
210
+		return 'menu-maj-geodispersion';
211
+	}
212
+
213
+	/**
214
+	 * {@inheritDoc}
215
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
216
+	 */
217
+	public function headContent(): string
218
+	{
219
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
220
+	}
221
+
222
+	/**
223
+	 * {@inheritDoc}
224
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers()
225
+	 */
226
+	public function listPlaceMappers(): array
227
+	{
228
+		return [
229
+			CoordinatesPlaceMapper::class,
230
+			SimplePlaceMapper::class,
231
+			SimpleTopFilteredPlaceMapper::class
232
+		];
233
+	}
234
+
235
+	/**
236
+	 * {@inheritDoc}
237
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
238
+	 */
239
+	public function listGeoAnalyses(): array
240
+	{
241
+		return [
242
+			AllEventsByCenturyGeoAnalysis::class,
243
+			AllEventsByTypeGeoAnalysis::class
244
+		];
245
+	}
246 246
 }
Please login to merge, or discard this patch.