Passed
Branch feature/2.1-geodispersion-dev (1d61a8)
by Jonathan
61:21
created
src/Webtrees/Module/IsSourced/Data/NullFactSourceStatus.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -19,21 +19,21 @@
 block discarded – undo
19 19
  */
20 20
 class NullFactSourceStatus extends FactSourceStatus
21 21
 {
22
-    /**
23
-     * {@inheritDoc}
24
-     * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isSet()
25
-     */
26
-    public function isSet(): bool
27
-    {
28
-        return false;
29
-    }
22
+	/**
23
+	 * {@inheritDoc}
24
+	 * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isSet()
25
+	 */
26
+	public function isSet(): bool
27
+	{
28
+		return false;
29
+	}
30 30
 
31
-    /**
32
-     * {@inheritDoc}
33
-     * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\FactSourceStatus::combineWith()
34
-     */
35
-    public function combineWith(SourceStatus $other): SourceStatus
36
-    {
37
-        return $other;
38
-    }
31
+	/**
32
+	 * {@inheritDoc}
33
+	 * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\FactSourceStatus::combineWith()
34
+	 */
35
+	public function combineWith(SourceStatus $other): SourceStatus
36
+	{
37
+		return $other;
38
+	}
39 39
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/WelcomeBlock/Http/RequestHandlers/MatomoStats.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -31,64 +31,64 @@
 block discarded – undo
31 31
  */
32 32
 class MatomoStats implements RequestHandlerInterface
33 33
 {
34
-    use ViewResponseTrait;
34
+	use ViewResponseTrait;
35 35
 
36
-    /**
37
-     * @var WelcomeBlockModule|null $module
38
-     */
39
-    private $module;
36
+	/**
37
+	 * @var WelcomeBlockModule|null $module
38
+	 */
39
+	private $module;
40 40
 
41
-    /**
42
-     * @var MatomoStatsService $matomo_service
43
-     */
44
-    private $matomo_service;
41
+	/**
42
+	 * @var MatomoStatsService $matomo_service
43
+	 */
44
+	private $matomo_service;
45 45
 
46
-    /**
47
-     * Constructor for MatomoStats request handler
48
-     * @param ModuleService $module_service
49
-     * @param MatomoStatsService $matomo_service
50
-     */
51
-    public function __construct(
52
-        ModuleService $module_service,
53
-        MatomoStatsService $matomo_service
54
-    ) {
55
-        $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first();
56
-        $this->matomo_service = $matomo_service;
57
-    }
46
+	/**
47
+	 * Constructor for MatomoStats request handler
48
+	 * @param ModuleService $module_service
49
+	 * @param MatomoStatsService $matomo_service
50
+	 */
51
+	public function __construct(
52
+		ModuleService $module_service,
53
+		MatomoStatsService $matomo_service
54
+	) {
55
+		$this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first();
56
+		$this->matomo_service = $matomo_service;
57
+	}
58 58
 
59
-    /**
60
-     * {@inheritDoc}
61
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
62
-     */
63
-    public function handle(ServerRequestInterface $request): ResponseInterface
64
-    {
65
-        $this->layout = 'layouts/ajax';
59
+	/**
60
+	 * {@inheritDoc}
61
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
62
+	 */
63
+	public function handle(ServerRequestInterface $request): ResponseInterface
64
+	{
65
+		$this->layout = 'layouts/ajax';
66 66
 
67
-        if ($this->module === null) {
68
-            return $this->viewResponse('errors/unhandled-exception', [
69
-                'error' => 'The attached module could not be found.'
70
-            ], StatusCodeInterface::STATUS_NOT_FOUND);
71
-        }
67
+		if ($this->module === null) {
68
+			return $this->viewResponse('errors/unhandled-exception', [
69
+				'error' => 'The attached module could not be found.'
70
+			], StatusCodeInterface::STATUS_NOT_FOUND);
71
+		}
72 72
 
73
-        $block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT);
74
-        $nb_visits_year = $nb_visits_today = null;
73
+		$block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT);
74
+		$nb_visits_year = $nb_visits_today = null;
75 75
 
76
-        try {
77
-            if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) {
78
-                $nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0;
79
-                $nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0)
80
-                    + $nb_visits_today;
81
-            }
82
-        } catch (Throwable $ex) {
83
-            return $this->viewResponse('errors/unhandled-exception', [
84
-                'error' => I18N::translate('Error while retrieving Matomo statistics: ') .
85
-                    (Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details'))
86
-            ], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
87
-        }
76
+		try {
77
+			if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) {
78
+				$nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0;
79
+				$nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0)
80
+					+ $nb_visits_today;
81
+			}
82
+		} catch (Throwable $ex) {
83
+			return $this->viewResponse('errors/unhandled-exception', [
84
+				'error' => I18N::translate('Error while retrieving Matomo statistics: ') .
85
+					(Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details'))
86
+			], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
87
+		}
88 88
 
89
-        return $this->viewResponse($this->module->name() . '::matomo-stats', [
90
-            'visits_year'   =>  $nb_visits_year,
91
-            'visits_today'  =>  $nb_visits_today
92
-        ]);
93
-    }
89
+		return $this->viewResponse($this->module->name() . '::matomo-stats', [
90
+			'visits_year'   =>  $nb_visits_year,
91
+			'visits_today'  =>  $nb_visits_today
92
+		]);
93
+	}
94 94
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/WelcomeBlock/WelcomeBlockModule.php 1 patch
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -33,159 +33,159 @@
 block discarded – undo
33 33
  */
34 34
 class WelcomeBlockModule extends AbstractModule implements ModuleMyArtJaubInterface, ModuleBlockInterface
35 35
 {
36
-    use ModuleMyArtJaubTrait;
37
-    use ModuleBlockTrait;
38
-
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
42
-     */
43
-    public function title(): string
44
-    {
45
-        return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block');
46
-    }
47
-
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
51
-     */
52
-    public function description(): string
53
-    {
54
-        //phpcs:ignore Generic.Files.LineLength.TooLong
55
-        return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.');
56
-    }
57
-
58
-    /**
59
-     * {@inheritDoc}
60
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
61
-     */
62
-    public function loadRoutes(Map $router): void
63
-    {
64
-        $router->attach('', '', static function (Map $router): void {
65
-
66
-            $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void {
67
-
68
-                $router->get(MatomoStats::class, '/matomostats', MatomoStats::class);
69
-            });
70
-        });
71
-    }
72
-
73
-    /**
74
-     * {@inheritDoc}
75
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
76
-     */
77
-    public function customModuleVersion(): string
78
-    {
79
-        return '2.0.11-v.2';
80
-    }
81
-
82
-    /**
83
-     * {@inheritDoc}
84
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock()
85
-     */
86
-    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
87
-    {
88
-        $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class)
89
-            ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
90
-
91
-        $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class)
92
-            ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
93
-
94
-        $content = view($this->name() . '::block-embed', [
95
-            'block_id'                  =>  $block_id,
96
-            'fab_welcome_block_view'    =>  $fab_welcome_block_view,
97
-            'fab_login_block_view'      =>  $fab_login_block_view,
98
-            'matomo_enabled'            =>  $this->isMatomoEnabled($block_id),
99
-            'js_script_url'             =>  $this->assetUrl('js/welcomeblock.min.js')
100
-        ]);
101
-
102
-        if ($context !== self::CONTEXT_EMBED) {
103
-            return view('modules/block-template', [
104
-                'block'      => Str::kebab($this->name()),
105
-                'id'         => $block_id,
106
-                'config_url' => $this->configUrl($tree, $context, $block_id),
107
-                'title'      => $tree->title(),
108
-                'content'    => $content,
109
-            ]);
110
-        }
111
-
112
-        return $content;
113
-    }
114
-
115
-    /**
116
-     * {@inheritDoc}
117
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock()
118
-     */
119
-    public function isTreeBlock(): bool
120
-    {
121
-        return true;
122
-    }
123
-
124
-    /**
125
-     * {@inheritDoc}
126
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration()
127
-     */
128
-    public function editBlockConfiguration(Tree $tree, int $block_id): string
129
-    {
130
-        return view($this->name() . '::config', $this->matomoSettings($block_id));
131
-    }
132
-
133
-    /**
134
-     * {@inheritDoc}
135
-     * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration()
136
-     */
137
-    public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
138
-    {
139
-        $params = (array) $request->getParsedBody();
140
-
141
-        $matomo_enabled = $params['matomo_enabled'] == 'yes';
142
-        $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no');
143
-        if (!$matomo_enabled) {
144
-            return;
145
-        }
146
-
147
-        if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) {
148
-            FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger');
149
-            return;
150
-        }
151
-
152
-        if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) {
153
-            FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger');
154
-            return;
155
-        }
156
-
157
-        $this
158
-            ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url']))
159
-            ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token']))
160
-            ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']);
161
-
162
-        Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id);
163
-    }
164
-
165
-    /**
166
-     * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block
167
-     *
168
-     * @param int $block_id
169
-     * @return bool
170
-     */
171
-    public function isMatomoEnabled(int $block_id): bool
172
-    {
173
-        return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes';
174
-    }
175
-
176
-    /**
177
-     * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block
178
-     *
179
-     * @param int $block_id
180
-     * @return array<string, mixed>
181
-     */
182
-    public function matomoSettings(int $block_id): array
183
-    {
184
-        return [
185
-            'matomo_enabled' => $this->isMatomoEnabled($block_id),
186
-            'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'),
187
-            'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'),
188
-            'matomo_siteid'  => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0')
189
-        ];
190
-    }
36
+	use ModuleMyArtJaubTrait;
37
+	use ModuleBlockTrait;
38
+
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
42
+	 */
43
+	public function title(): string
44
+	{
45
+		return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block');
46
+	}
47
+
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
51
+	 */
52
+	public function description(): string
53
+	{
54
+		//phpcs:ignore Generic.Files.LineLength.TooLong
55
+		return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.');
56
+	}
57
+
58
+	/**
59
+	 * {@inheritDoc}
60
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
61
+	 */
62
+	public function loadRoutes(Map $router): void
63
+	{
64
+		$router->attach('', '', static function (Map $router): void {
65
+
66
+			$router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void {
67
+
68
+				$router->get(MatomoStats::class, '/matomostats', MatomoStats::class);
69
+			});
70
+		});
71
+	}
72
+
73
+	/**
74
+	 * {@inheritDoc}
75
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
76
+	 */
77
+	public function customModuleVersion(): string
78
+	{
79
+		return '2.0.11-v.2';
80
+	}
81
+
82
+	/**
83
+	 * {@inheritDoc}
84
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock()
85
+	 */
86
+	public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
87
+	{
88
+		$fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class)
89
+			->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
90
+
91
+		$fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class)
92
+			->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED);
93
+
94
+		$content = view($this->name() . '::block-embed', [
95
+			'block_id'                  =>  $block_id,
96
+			'fab_welcome_block_view'    =>  $fab_welcome_block_view,
97
+			'fab_login_block_view'      =>  $fab_login_block_view,
98
+			'matomo_enabled'            =>  $this->isMatomoEnabled($block_id),
99
+			'js_script_url'             =>  $this->assetUrl('js/welcomeblock.min.js')
100
+		]);
101
+
102
+		if ($context !== self::CONTEXT_EMBED) {
103
+			return view('modules/block-template', [
104
+				'block'      => Str::kebab($this->name()),
105
+				'id'         => $block_id,
106
+				'config_url' => $this->configUrl($tree, $context, $block_id),
107
+				'title'      => $tree->title(),
108
+				'content'    => $content,
109
+			]);
110
+		}
111
+
112
+		return $content;
113
+	}
114
+
115
+	/**
116
+	 * {@inheritDoc}
117
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock()
118
+	 */
119
+	public function isTreeBlock(): bool
120
+	{
121
+		return true;
122
+	}
123
+
124
+	/**
125
+	 * {@inheritDoc}
126
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration()
127
+	 */
128
+	public function editBlockConfiguration(Tree $tree, int $block_id): string
129
+	{
130
+		return view($this->name() . '::config', $this->matomoSettings($block_id));
131
+	}
132
+
133
+	/**
134
+	 * {@inheritDoc}
135
+	 * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration()
136
+	 */
137
+	public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
138
+	{
139
+		$params = (array) $request->getParsedBody();
140
+
141
+		$matomo_enabled = $params['matomo_enabled'] == 'yes';
142
+		$this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no');
143
+		if (!$matomo_enabled) {
144
+			return;
145
+		}
146
+
147
+		if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) {
148
+			FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger');
149
+			return;
150
+		}
151
+
152
+		if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) {
153
+			FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger');
154
+			return;
155
+		}
156
+
157
+		$this
158
+			->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url']))
159
+			->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token']))
160
+			->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']);
161
+
162
+		Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id);
163
+	}
164
+
165
+	/**
166
+	 * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block
167
+	 *
168
+	 * @param int $block_id
169
+	 * @return bool
170
+	 */
171
+	public function isMatomoEnabled(int $block_id): bool
172
+	{
173
+		return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes';
174
+	}
175
+
176
+	/**
177
+	 * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block
178
+	 *
179
+	 * @param int $block_id
180
+	 * @return array<string, mixed>
181
+	 */
182
+	public function matomoSettings(int $block_id): array
183
+	{
184
+		return [
185
+			'matomo_enabled' => $this->isMatomoEnabled($block_id),
186
+			'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'),
187
+			'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'),
188
+			'matomo_siteid'  => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0')
189
+		];
190
+	}
191 191
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/WelcomeBlock/Services/MatomoStatsService.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -29,93 +29,93 @@
 block discarded – undo
29 29
 class MatomoStatsService
30 30
 {
31 31
 
32
-    /**
33
-     * Returns the number of visits for the current year (up to the day before).
34
-     * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
35
-     *
36
-     * @param WelcomeBlockModule $module
37
-     * @param int $block_id
38
-     * @return int|NULL
39
-     */
40
-    public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
41
-    {
42
-        return Registry::cache()->file()->remember(
43
-            $module->name() . '-matomovisits-yearly-' . $block_id,
44
-            function () use ($module, $block_id): ?int {
45
-                $visits_year = $this->visits($module, $block_id, 'year');
46
-                if ($visits_year === null) {
47
-                    return null;
48
-                }
49
-                $visits_today = (int) $this->visits($module, $block_id, 'day');
32
+	/**
33
+	 * Returns the number of visits for the current year (up to the day before).
34
+	 * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
35
+	 *
36
+	 * @param WelcomeBlockModule $module
37
+	 * @param int $block_id
38
+	 * @return int|NULL
39
+	 */
40
+	public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
41
+	{
42
+		return Registry::cache()->file()->remember(
43
+			$module->name() . '-matomovisits-yearly-' . $block_id,
44
+			function () use ($module, $block_id): ?int {
45
+				$visits_year = $this->visits($module, $block_id, 'year');
46
+				if ($visits_year === null) {
47
+					return null;
48
+				}
49
+				$visits_today = (int) $this->visits($module, $block_id, 'day');
50 50
 
51
-                return $visits_year - $visits_today;
52
-            },
53
-            Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
54
-        );
55
-    }
51
+				return $visits_year - $visits_today;
52
+			},
53
+			Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
54
+		);
55
+	}
56 56
 
57
-    /**
58
-     * Returns the number of visits for the current day.
59
-     *
60
-     * @param WelcomeBlockModule $module
61
-     * @param int $block_id
62
-     * @return int|NULL
63
-     */
64
-    public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
65
-    {
66
-        return Registry::cache()->array()->remember(
67
-            $module->name() . '-matomovisits-daily-' . $block_id,
68
-            function () use ($module, $block_id): ?int {
69
-                return $this->visits($module, $block_id, 'day');
70
-            }
71
-        );
72
-    }
57
+	/**
58
+	 * Returns the number of visits for the current day.
59
+	 *
60
+	 * @param WelcomeBlockModule $module
61
+	 * @param int $block_id
62
+	 * @return int|NULL
63
+	 */
64
+	public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
65
+	{
66
+		return Registry::cache()->array()->remember(
67
+			$module->name() . '-matomovisits-daily-' . $block_id,
68
+			function () use ($module, $block_id): ?int {
69
+				return $this->visits($module, $block_id, 'day');
70
+			}
71
+		);
72
+	}
73 73
 
74
-    /**
75
-     * Invoke the Matomo API to retrieve the number of visits over a period.
76
-     *
77
-     * @param WelcomeBlockModule $module
78
-     * @param int $block_id
79
-     * @param string $period
80
-     * @return int|NULL
81
-     */
82
-    protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
83
-    {
84
-        $settings = $module->matomoSettings($block_id);
74
+	/**
75
+	 * Invoke the Matomo API to retrieve the number of visits over a period.
76
+	 *
77
+	 * @param WelcomeBlockModule $module
78
+	 * @param int $block_id
79
+	 * @param string $period
80
+	 * @return int|NULL
81
+	 */
82
+	protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
83
+	{
84
+		$settings = $module->matomoSettings($block_id);
85 85
 
86
-        if (
87
-            $settings['matomo_enabled'] === true
88
-            && mb_strlen($settings['matomo_url']) > 0
89
-            && mb_strlen($settings['matomo_token']) > 0
90
-            && $settings['matomo_siteid'] > 0
91
-        ) {
92
-            try {
93
-                $http_client = new Client([
94
-                    RequestOptions::TIMEOUT => 30
95
-                ]);
86
+		if (
87
+			$settings['matomo_enabled'] === true
88
+			&& mb_strlen($settings['matomo_url']) > 0
89
+			&& mb_strlen($settings['matomo_token']) > 0
90
+			&& $settings['matomo_siteid'] > 0
91
+		) {
92
+			try {
93
+				$http_client = new Client([
94
+					RequestOptions::TIMEOUT => 30
95
+				]);
96 96
 
97
-                $response = $http_client->get($settings['matomo_url'], [
98
-                    'query' =>  [
99
-                        'module'    =>  'API',
100
-                        'method'    =>  'VisitsSummary.getVisits',
101
-                        'idSite'    =>  $settings['matomo_siteid'],
102
-                        'period'    =>  $period,
103
-                        'date'      =>  'today',
104
-                        'token_auth' =>  $settings['matomo_token'],
105
-                        'format'    =>  'json'
106
-                    ]
107
-                ]);
97
+				$response = $http_client->get($settings['matomo_url'], [
98
+					'query' =>  [
99
+						'module'    =>  'API',
100
+						'method'    =>  'VisitsSummary.getVisits',
101
+						'idSite'    =>  $settings['matomo_siteid'],
102
+						'period'    =>  $period,
103
+						'date'      =>  'today',
104
+						'token_auth' =>  $settings['matomo_token'],
105
+						'format'    =>  'json'
106
+					]
107
+				]);
108 108
 
109
-                if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
110
-                    $result = json_decode((string) $response->getBody(), true)['value'] ?? null;
111
-                    if ($result !== null) {
112
-                        return (int)$result;
113
-                    }
114
-                }
115
-            } catch (RequestException $ex) {
116
-            }
117
-        }
109
+				if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
110
+					$result = json_decode((string) $response->getBody(), true)['value'] ?? null;
111
+					if ($result !== null) {
112
+						return (int)$result;
113
+					}
114
+				}
115
+			} catch (RequestException $ex) {
116
+			}
117
+		}
118 118
 
119
-        return null;
120
-    }
119
+		return null;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/Certificates/CertificatesModule.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -43,154 +43,154 @@
 block discarded – undo
43 43
  * Certificates Module.
44 44
  */
45 45
 class CertificatesModule extends AbstractModule implements
46
-    ModuleMyArtJaubInterface,
47
-    ModuleConfigInterface,
48
-    ModuleGlobalInterface,
49
-    ModuleListInterface
46
+	ModuleMyArtJaubInterface,
47
+	ModuleConfigInterface,
48
+	ModuleGlobalInterface,
49
+	ModuleListInterface
50 50
 {
51
-    use ModuleMyArtJaubTrait {
52
-        boot as traitBoot;
53
-    }
54
-    use ModuleConfigTrait;
55
-    use ModuleGlobalTrait;
56
-    use ModuleListTrait;
57
-
58
-    /**
59
-     * {@inheritDoc}
60
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
61
-     */
62
-    public function title(): string
63
-    {
64
-        return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates');
65
-    }
66
-
67
-    /**
68
-     * {@inheritDoc}
69
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
70
-     */
71
-    public function description(): string
72
-    {
73
-        //phpcs:ignore Generic.Files.LineLength.TooLong
74
-        return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.');
75
-    }
76
-
77
-    /**
78
-     * {@inheritDoc}
79
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
80
-     */
81
-    public function boot(): void
82
-    {
83
-        $this->traitBoot();
84
-        Registry::elementFactory()->register([
85
-            'FAM:SOUR:_ACT'     =>  new SourceCertificate(I18N::translate('Certificate')),
86
-            'FAM:*:SOUR:_ACT'   =>  new SourceCertificate(I18N::translate('Certificate')),
87
-            'INDI:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
88
-            'INDI:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate')),
89
-            'OBJE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
90
-            'OBJE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate')),
91
-            'NOTE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
92
-            'NOTE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'))
93
-        ]);
94
-    }
95
-
96
-    /**
97
-     * {@inheritDoc}
98
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
99
-     */
100
-    public function loadRoutes($router): void
101
-    {
102
-        $router->attach('', '', static function (Map $router): void {
103
-
104
-            $router->attach('', '/module-maj/certificates', static function (Map $router): void {
105
-
106
-                $router->attach('', '/admin', static function (Map $router): void {
107
-
108
-                    $router->get(AdminTreesPage::class, '/trees', AdminTreesPage::class)
109
-                        ->extras(['middleware' => [ AuthAdministrator::class ]]);
110
-
111
-                    $router->attach('', '/config/{tree}', static function (Map $router): void {
112
-
113
-                        $router->extras([
114
-                            'middleware' => [
115
-                                AuthManager::class,
116
-                            ],
117
-                        ]);
118
-                        $router->get(AdminConfigPage::class, '', AdminConfigPage::class);
119
-                        $router->post(AdminConfigAction::class, '', AdminConfigAction::class);
120
-                    });
121
-                });
122
-
123
-                $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class)
124
-                    ->extras([
125
-                        'middleware'            =>  [AuthTreePreference::class],
126
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
127
-                    ]);
128
-
129
-                $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void {
130
-
131
-                    $router->extras([
132
-                        'middleware'            =>  [AuthTreePreference::class],
133
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
134
-                    ]);
135
-
136
-                    $router->get(CertificatePage::class, '', CertificatePage::class);
137
-                    $router->get(CertificateImage::class, '/image', CertificateImage::class);
138
-                });
139
-            });
140
-        });
141
-    }
142
-
143
-    /**
144
-     * {@inheritDoc}
145
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
146
-     */
147
-    public function customModuleVersion(): string
148
-    {
149
-        return '2.1.0-v.1';
150
-    }
151
-
152
-    /**
153
-     * {@inheritDoc}
154
-     * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
155
-     */
156
-    public function getConfigLink(): string
157
-    {
158
-        return route(AdminTreesPage::class);
159
-    }
160
-
161
-    /**
162
-     * {@inheritDoc}
163
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
164
-     */
165
-    public function headContent(): string
166
-    {
167
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
168
-    }
169
-
170
-    /**
171
-     * {@inheritDoc}
172
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
173
-     */
174
-    public function listUrl(Tree $tree, array $parameters = []): string
175
-    {
176
-        return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters);
177
-    }
178
-
179
-    /**
180
-     * {@inheritDoc}
181
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
182
-     */
183
-    public function listMenuClass(): string
184
-    {
185
-        return 'menu-maj-certificates';
186
-    }
187
-
188
-    /**
189
-     * {@inheritDoc}
190
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty()
191
-     */
192
-    public function listIsEmpty(Tree $tree): bool
193
-    {
194
-        return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE);
195
-    }
51
+	use ModuleMyArtJaubTrait {
52
+		boot as traitBoot;
53
+	}
54
+	use ModuleConfigTrait;
55
+	use ModuleGlobalTrait;
56
+	use ModuleListTrait;
57
+
58
+	/**
59
+	 * {@inheritDoc}
60
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
61
+	 */
62
+	public function title(): string
63
+	{
64
+		return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates');
65
+	}
66
+
67
+	/**
68
+	 * {@inheritDoc}
69
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
70
+	 */
71
+	public function description(): string
72
+	{
73
+		//phpcs:ignore Generic.Files.LineLength.TooLong
74
+		return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.');
75
+	}
76
+
77
+	/**
78
+	 * {@inheritDoc}
79
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
80
+	 */
81
+	public function boot(): void
82
+	{
83
+		$this->traitBoot();
84
+		Registry::elementFactory()->register([
85
+			'FAM:SOUR:_ACT'     =>  new SourceCertificate(I18N::translate('Certificate')),
86
+			'FAM:*:SOUR:_ACT'   =>  new SourceCertificate(I18N::translate('Certificate')),
87
+			'INDI:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
88
+			'INDI:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate')),
89
+			'OBJE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
90
+			'OBJE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate')),
91
+			'NOTE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate')),
92
+			'NOTE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'))
93
+		]);
94
+	}
95
+
96
+	/**
97
+	 * {@inheritDoc}
98
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
99
+	 */
100
+	public function loadRoutes($router): void
101
+	{
102
+		$router->attach('', '', static function (Map $router): void {
103
+
104
+			$router->attach('', '/module-maj/certificates', static function (Map $router): void {
105
+
106
+				$router->attach('', '/admin', static function (Map $router): void {
107
+
108
+					$router->get(AdminTreesPage::class, '/trees', AdminTreesPage::class)
109
+						->extras(['middleware' => [ AuthAdministrator::class ]]);
110
+
111
+					$router->attach('', '/config/{tree}', static function (Map $router): void {
112
+
113
+						$router->extras([
114
+							'middleware' => [
115
+								AuthManager::class,
116
+							],
117
+						]);
118
+						$router->get(AdminConfigPage::class, '', AdminConfigPage::class);
119
+						$router->post(AdminConfigAction::class, '', AdminConfigAction::class);
120
+					});
121
+				});
122
+
123
+				$router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class)
124
+					->extras([
125
+						'middleware'            =>  [AuthTreePreference::class],
126
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
127
+					]);
128
+
129
+				$router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void {
130
+
131
+					$router->extras([
132
+						'middleware'            =>  [AuthTreePreference::class],
133
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
134
+					]);
135
+
136
+					$router->get(CertificatePage::class, '', CertificatePage::class);
137
+					$router->get(CertificateImage::class, '/image', CertificateImage::class);
138
+				});
139
+			});
140
+		});
141
+	}
142
+
143
+	/**
144
+	 * {@inheritDoc}
145
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
146
+	 */
147
+	public function customModuleVersion(): string
148
+	{
149
+		return '2.1.0-v.1';
150
+	}
151
+
152
+	/**
153
+	 * {@inheritDoc}
154
+	 * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
155
+	 */
156
+	public function getConfigLink(): string
157
+	{
158
+		return route(AdminTreesPage::class);
159
+	}
160
+
161
+	/**
162
+	 * {@inheritDoc}
163
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
164
+	 */
165
+	public function headContent(): string
166
+	{
167
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
168
+	}
169
+
170
+	/**
171
+	 * {@inheritDoc}
172
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
173
+	 */
174
+	public function listUrl(Tree $tree, array $parameters = []): string
175
+	{
176
+		return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters);
177
+	}
178
+
179
+	/**
180
+	 * {@inheritDoc}
181
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
182
+	 */
183
+	public function listMenuClass(): string
184
+	{
185
+		return 'menu-maj-certificates';
186
+	}
187
+
188
+	/**
189
+	 * {@inheritDoc}
190
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty()
191
+	 */
192
+	public function listIsEmpty(Tree $tree): bool
193
+	{
194
+		return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE);
195
+	}
196 196
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/Certificates/Model/Certificate.php 1 patch
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -25,212 +25,212 @@
 block discarded – undo
25 25
  */
26 26
 class Certificate
27 27
 {
28
-    /**
29
-     * Pattern to extract information from a file name.
30
-     * Specific to the author's workflow.
31
-     * @var string
32
-     */
33
-    private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong
34
-
35
-    /**
36
-     * @var Tree $tree
37
-     */
38
-    private $tree;
39
-
40
-    /**
41
-     * @var string $path
42
-     * */
43
-    private $path;
44
-
45
-    /**
46
-     * @var string|null $city
47
-     * $city */
48
-    private $city;
49
-
50
-    /**
51
-     * @var string|null $filename
52
-     */
53
-    private $filename;
54
-
55
-    /**
56
-     * @var string|null $extension
57
-     */
58
-    private $extension;
59
-
60
-    /**
61
-     * @var string|null $type
62
-     */
63
-    private $type;
64
-
65
-    /**
66
-     * @var string|null $description
67
-     */
68
-    private $description;
69
-
70
-    /**
71
-     * @var Date|null $date
72
-     */
73
-    private $date;
74
-
75
-    /**
76
-     * Contructor for Certificate
77
-     *
78
-     * @param Tree $tree
79
-     * @param string $path
80
-     */
81
-    public function __construct(Tree $tree, string $path)
82
-    {
83
-        $this->tree = $tree;
84
-        $this->path = $path;
85
-        $this->extractDataFromPath($path);
86
-    }
87
-
88
-    /**
89
-     * Populate fields from the filename, based on a predeterminate pattern.
90
-     * Logic specific to the author.
91
-     *
92
-     * @param string $path
93
-     */
94
-    protected function extractDataFromPath(string $path): void
95
-    {
96
-        $path_parts = pathinfo($path);
97
-        $this->city = $path_parts['dirname'];
98
-        $this->filename = $path_parts['filename'];
99
-        $this->extension = $path_parts['extension'] ?? '';
100
-
101
-        if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) {
102
-            $this->type = $match['type'];
103
-            $this->description = $match['descr'];
104
-
105
-            $day = $match['day'] ?? '';
106
-            $month_date = DateTime::createFromFormat('m', $match['month'] ?? '');
107
-            $month = $month_date !== false ? strtoupper($month_date->format('M')) : '';
108
-            $year = $match['year'] ?? '';
109
-
110
-            $this->date = new Date(sprintf('%s %s %s', $day, $month, $year));
111
-        } else {
112
-            $this->description = $this->filename;
113
-        }
114
-    }
115
-
116
-    /**
117
-     * Get the family tree of the certificate
118
-     *
119
-     * @return Tree
120
-     */
121
-    public function tree(): Tree
122
-    {
123
-        return $this->tree;
124
-    }
125
-
126
-    /**
127
-     * Get the path of the certificate in the file system.
128
-     *
129
-     * @return string
130
-     */
131
-    public function path(): string
132
-    {
133
-        return $this->path;
134
-    }
135
-
136
-    /**
137
-     * The the path of the certificate, in a Gedcom canonical form.
138
-     *
139
-     * @return string
140
-     */
141
-    public function gedcomPath(): string
142
-    {
143
-        return str_replace('\\', '/', $this->path);
144
-    }
145
-
146
-    /**
147
-     * Get the certificate name.
148
-     *
149
-     * @return string
150
-     */
151
-    public function name(): string
152
-    {
153
-        return $this->filename ?? '';
154
-    }
155
-
156
-    /**
157
-     * Get the certificate's city (the first level folder).
158
-     *
159
-     * @return string
160
-     */
161
-    public function city(): string
162
-    {
163
-        return $this->city ?? '';
164
-    }
165
-
166
-    /**
167
-     * Get the certificate's date. Extracted from the file name.
168
-     *
169
-     * @return Date
170
-     */
171
-    public function date(): Date
172
-    {
173
-        return $this->date ?? new Date('');
174
-    }
175
-
176
-    /**
177
-     * Get the certificate's type. Extracted from the file name.
178
-     *
179
-     * @return string
180
-     */
181
-    public function type(): string
182
-    {
183
-        return $this->type ?? '';
184
-    }
185
-
186
-    /**
187
-     * Get the certificate's description.  Extracted from the file name.
188
-     * @return string
189
-     */
190
-    public function description(): string
191
-    {
192
-        return $this->description ?? '';
193
-    }
194
-
195
-    /**
196
-     * Get the certificate's description to be used for sorting.
197
-     * This is based on surnames (at least 3 letters) found in the file name.
198
-     *
199
-     * @return string
200
-     */
201
-    public function sortDescription(): string
202
-    {
203
-        $sort_prefix = '';
204
-        if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) {
205
-            $sort_prefix = implode('_', array_map(function ($match) {
206
-                return $match[1];
207
-            }, $matches)) . '_';
208
-        }
209
-        return $sort_prefix . $this->description();
210
-    }
211
-
212
-    /**
213
-     * Get the certificate's MIME type.
214
-     *
215
-     * @return string
216
-     */
217
-    public function mimeType(): string
218
-    {
219
-        return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE;
220
-    }
221
-
222
-    /**
223
-     * Get the base parameters to be used in url referencing the certificate.
224
-     *
225
-     * @param UrlObfuscatorService $url_obfuscator_service
226
-     * @return array
227
-     */
228
-    public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array
229
-    {
230
-        $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class);
231
-        return [
232
-            'tree' => $this->tree->name(),
233
-            'cid' => $url_obfuscator_service->obfuscate($this->path)
234
-        ];
235
-    }
28
+	/**
29
+	 * Pattern to extract information from a file name.
30
+	 * Specific to the author's workflow.
31
+	 * @var string
32
+	 */
33
+	private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong
34
+
35
+	/**
36
+	 * @var Tree $tree
37
+	 */
38
+	private $tree;
39
+
40
+	/**
41
+	 * @var string $path
42
+	 * */
43
+	private $path;
44
+
45
+	/**
46
+	 * @var string|null $city
47
+	 * $city */
48
+	private $city;
49
+
50
+	/**
51
+	 * @var string|null $filename
52
+	 */
53
+	private $filename;
54
+
55
+	/**
56
+	 * @var string|null $extension
57
+	 */
58
+	private $extension;
59
+
60
+	/**
61
+	 * @var string|null $type
62
+	 */
63
+	private $type;
64
+
65
+	/**
66
+	 * @var string|null $description
67
+	 */
68
+	private $description;
69
+
70
+	/**
71
+	 * @var Date|null $date
72
+	 */
73
+	private $date;
74
+
75
+	/**
76
+	 * Contructor for Certificate
77
+	 *
78
+	 * @param Tree $tree
79
+	 * @param string $path
80
+	 */
81
+	public function __construct(Tree $tree, string $path)
82
+	{
83
+		$this->tree = $tree;
84
+		$this->path = $path;
85
+		$this->extractDataFromPath($path);
86
+	}
87
+
88
+	/**
89
+	 * Populate fields from the filename, based on a predeterminate pattern.
90
+	 * Logic specific to the author.
91
+	 *
92
+	 * @param string $path
93
+	 */
94
+	protected function extractDataFromPath(string $path): void
95
+	{
96
+		$path_parts = pathinfo($path);
97
+		$this->city = $path_parts['dirname'];
98
+		$this->filename = $path_parts['filename'];
99
+		$this->extension = $path_parts['extension'] ?? '';
100
+
101
+		if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) {
102
+			$this->type = $match['type'];
103
+			$this->description = $match['descr'];
104
+
105
+			$day = $match['day'] ?? '';
106
+			$month_date = DateTime::createFromFormat('m', $match['month'] ?? '');
107
+			$month = $month_date !== false ? strtoupper($month_date->format('M')) : '';
108
+			$year = $match['year'] ?? '';
109
+
110
+			$this->date = new Date(sprintf('%s %s %s', $day, $month, $year));
111
+		} else {
112
+			$this->description = $this->filename;
113
+		}
114
+	}
115
+
116
+	/**
117
+	 * Get the family tree of the certificate
118
+	 *
119
+	 * @return Tree
120
+	 */
121
+	public function tree(): Tree
122
+	{
123
+		return $this->tree;
124
+	}
125
+
126
+	/**
127
+	 * Get the path of the certificate in the file system.
128
+	 *
129
+	 * @return string
130
+	 */
131
+	public function path(): string
132
+	{
133
+		return $this->path;
134
+	}
135
+
136
+	/**
137
+	 * The the path of the certificate, in a Gedcom canonical form.
138
+	 *
139
+	 * @return string
140
+	 */
141
+	public function gedcomPath(): string
142
+	{
143
+		return str_replace('\\', '/', $this->path);
144
+	}
145
+
146
+	/**
147
+	 * Get the certificate name.
148
+	 *
149
+	 * @return string
150
+	 */
151
+	public function name(): string
152
+	{
153
+		return $this->filename ?? '';
154
+	}
155
+
156
+	/**
157
+	 * Get the certificate's city (the first level folder).
158
+	 *
159
+	 * @return string
160
+	 */
161
+	public function city(): string
162
+	{
163
+		return $this->city ?? '';
164
+	}
165
+
166
+	/**
167
+	 * Get the certificate's date. Extracted from the file name.
168
+	 *
169
+	 * @return Date
170
+	 */
171
+	public function date(): Date
172
+	{
173
+		return $this->date ?? new Date('');
174
+	}
175
+
176
+	/**
177
+	 * Get the certificate's type. Extracted from the file name.
178
+	 *
179
+	 * @return string
180
+	 */
181
+	public function type(): string
182
+	{
183
+		return $this->type ?? '';
184
+	}
185
+
186
+	/**
187
+	 * Get the certificate's description.  Extracted from the file name.
188
+	 * @return string
189
+	 */
190
+	public function description(): string
191
+	{
192
+		return $this->description ?? '';
193
+	}
194
+
195
+	/**
196
+	 * Get the certificate's description to be used for sorting.
197
+	 * This is based on surnames (at least 3 letters) found in the file name.
198
+	 *
199
+	 * @return string
200
+	 */
201
+	public function sortDescription(): string
202
+	{
203
+		$sort_prefix = '';
204
+		if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) {
205
+			$sort_prefix = implode('_', array_map(function ($match) {
206
+				return $match[1];
207
+			}, $matches)) . '_';
208
+		}
209
+		return $sort_prefix . $this->description();
210
+	}
211
+
212
+	/**
213
+	 * Get the certificate's MIME type.
214
+	 *
215
+	 * @return string
216
+	 */
217
+	public function mimeType(): string
218
+	{
219
+		return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE;
220
+	}
221
+
222
+	/**
223
+	 * Get the base parameters to be used in url referencing the certificate.
224
+	 *
225
+	 * @param UrlObfuscatorService $url_obfuscator_service
226
+	 * @return array
227
+	 */
228
+	public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array
229
+	{
230
+		$url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class);
231
+		return [
232
+			'tree' => $this->tree->name(),
233
+			'cid' => $url_obfuscator_service->obfuscate($this->path)
234
+		];
235
+	}
236 236
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/Certificates/Model/Watermark.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -19,112 +19,112 @@
 block discarded – undo
19 19
  */
20 20
 class Watermark
21 21
 {
22
-    /**
23
-     * Default font color for watermarks
24
-     * @var string DEFAULT_COLOR
25
-     * */
26
-    public const DEFAULT_COLOR = '#4D6DF3';
27
-
28
-    /**
29
-     * Default maximum font size for watermarks
30
-     * @var string DEFAULT_SIZE
31
-     * */
32
-    public const DEFAULT_SIZE = 18;
33
-
34
-    /**
35
-     * @var string $text
36
-     */
37
-    private $text;
38
-
39
-    /**
40
-     * @var string $color;
41
-     */
42
-    private $color;
43
-
44
-
45
-    /**
46
-     * @var int $size
47
-     */
48
-    private $size;
49
-
50
-    /**
51
-     * Constructor for Watermark data class
52
-     *
53
-     * @param string $text
54
-     * @param string $color
55
-     * @param int $size
56
-     */
57
-    public function __construct(string $text, string $color, int $size)
58
-    {
59
-        $this->text = $text;
60
-        $this->color = $color;
61
-        $this->size = $size;
62
-    }
63
-
64
-    /**
65
-     * Get the watermark text.
66
-     *
67
-     * @return string
68
-     */
69
-    public function text(): string
70
-    {
71
-        return $this->text;
72
-    }
73
-
74
-    /**
75
-     * Get the watermark font color.
76
-     *
77
-     * @return string
78
-     */
79
-    public function color(): string
80
-    {
81
-        return $this->color;
82
-    }
83
-
84
-    /**
85
-     * Get the watermark maximum font size.
86
-     * @return int
87
-     */
88
-    public function size(): int
89
-    {
90
-        return $this->size;
91
-    }
92
-
93
-    /**
94
-     * Return an estimate of the size in pixels of the watermark text length.
95
-     *
96
-     * @return int
97
-     */
98
-    public function textLengthEstimate(): int
99
-    {
100
-        return $this->stringLengthEstimate(mb_strlen($this->text), $this->size);
101
-    }
102
-
103
-    /**
104
-     * Decrease the font size if necessary, based on the image width.
105
-     *
106
-     * @param int $width
107
-     */
108
-    public function adjustSize(int $width): void
109
-    {
110
-        $len = mb_strlen($this->text);
111
-        while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) {
112
-            $this->size--;
113
-            if ($this->size == 2) {
114
-                return;
115
-            }
116
-        }
117
-    }
118
-
119
-    /**
120
-     * Return an estimate of the size in pixels of a text in a specified font size.
121
-     *
122
-     * @param int $text_length
123
-     * @param int $font_size
124
-     * @return int
125
-     */
126
-    private function stringLengthEstimate(int $text_length, int $font_size): int
127
-    {
128
-        return $text_length * (int) ceil(($font_size + 2) * 0.5);
129
-    }
22
+	/**
23
+	 * Default font color for watermarks
24
+	 * @var string DEFAULT_COLOR
25
+	 * */
26
+	public const DEFAULT_COLOR = '#4D6DF3';
27
+
28
+	/**
29
+	 * Default maximum font size for watermarks
30
+	 * @var string DEFAULT_SIZE
31
+	 * */
32
+	public const DEFAULT_SIZE = 18;
33
+
34
+	/**
35
+	 * @var string $text
36
+	 */
37
+	private $text;
38
+
39
+	/**
40
+	 * @var string $color;
41
+	 */
42
+	private $color;
43
+
44
+
45
+	/**
46
+	 * @var int $size
47
+	 */
48
+	private $size;
49
+
50
+	/**
51
+	 * Constructor for Watermark data class
52
+	 *
53
+	 * @param string $text
54
+	 * @param string $color
55
+	 * @param int $size
56
+	 */
57
+	public function __construct(string $text, string $color, int $size)
58
+	{
59
+		$this->text = $text;
60
+		$this->color = $color;
61
+		$this->size = $size;
62
+	}
63
+
64
+	/**
65
+	 * Get the watermark text.
66
+	 *
67
+	 * @return string
68
+	 */
69
+	public function text(): string
70
+	{
71
+		return $this->text;
72
+	}
73
+
74
+	/**
75
+	 * Get the watermark font color.
76
+	 *
77
+	 * @return string
78
+	 */
79
+	public function color(): string
80
+	{
81
+		return $this->color;
82
+	}
83
+
84
+	/**
85
+	 * Get the watermark maximum font size.
86
+	 * @return int
87
+	 */
88
+	public function size(): int
89
+	{
90
+		return $this->size;
91
+	}
92
+
93
+	/**
94
+	 * Return an estimate of the size in pixels of the watermark text length.
95
+	 *
96
+	 * @return int
97
+	 */
98
+	public function textLengthEstimate(): int
99
+	{
100
+		return $this->stringLengthEstimate(mb_strlen($this->text), $this->size);
101
+	}
102
+
103
+	/**
104
+	 * Decrease the font size if necessary, based on the image width.
105
+	 *
106
+	 * @param int $width
107
+	 */
108
+	public function adjustSize(int $width): void
109
+	{
110
+		$len = mb_strlen($this->text);
111
+		while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) {
112
+			$this->size--;
113
+			if ($this->size == 2) {
114
+				return;
115
+			}
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * Return an estimate of the size in pixels of a text in a specified font size.
121
+	 *
122
+	 * @param int $text_length
123
+	 * @param int $font_size
124
+	 * @return int
125
+	 */
126
+	private function stringLengthEstimate(int $text_length, int $font_size): int
127
+	{
128
+		return $text_length * (int) ceil(($font_size + 2) * 0.5);
129
+	}
130 130
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/Certificates/Http/RequestHandlers/CertificatesList.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -31,73 +31,73 @@
 block discarded – undo
31 31
  */
32 32
 class CertificatesList implements RequestHandlerInterface
33 33
 {
34
-    use ViewResponseTrait;
35
-
36
-    /**
37
-     * @var CertificatesModule|null $module
38
-     */
39
-    private $module;
40
-
41
-    /**
42
-     * @var CertificateFilesystemService $certif_filesystem
43
-     */
44
-    private $certif_filesystem;
45
-
46
-    /**
47
-     * @var UrlObfuscatorService $url_obfuscator_service
48
-     */
49
-    private $url_obfuscator_service;
50
-
51
-
52
-    /**
53
-     * Constructor for CertificatesList Request Handler
54
-     *
55
-     * @param ModuleService $module_service
56
-     */
57
-    public function __construct(
58
-        ModuleService $module_service,
59
-        CertificateFilesystemService $certif_filesystem,
60
-        UrlObfuscatorService $url_obfuscator_service
61
-    ) {
62
-        $this->module = $module_service->findByInterface(CertificatesModule::class)->first();
63
-        $this->certif_filesystem = $certif_filesystem;
64
-        $this->url_obfuscator_service = $url_obfuscator_service;
65
-    }
66
-
67
-    /**
68
-     * {@inheritDoc}
69
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
70
-     */
71
-    public function handle(ServerRequestInterface $request): ResponseInterface
72
-    {
73
-        if ($this->module === null) {
74
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
75
-        }
76
-
77
-        $tree = $request->getAttribute('tree');
78
-        assert($tree instanceof Tree);
79
-
80
-        $title = I18N::translate('Certificates');
81
-
82
-        $cities = array_map(function (string $item): array {
83
-            return [$this->url_obfuscator_service->obfuscate($item), $item];
84
-        }, $this->certif_filesystem->cities($tree));
85
-
86
-        $city = $request->getQueryParams()['cityobf'] ?? $request->getAttribute('cityobf') ?? '';
87
-
88
-        if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) {
89
-            $title = I18N::translate('Certificates for %s', $city);
90
-            $certificates = $this->certif_filesystem->certificatesForCity($tree, $city);
91
-        }
92
-
93
-        return $this->viewResponse($this->module->name() . '::certificates-list', [
94
-            'title'                     =>  $title,
95
-            'tree'                      =>  $tree,
96
-            'module_name'               =>  $this->module->name(),
97
-            'cities'                    =>  $cities,
98
-            'selected_city'             =>  $city,
99
-            'certificates_list'         =>  $certificates ?? collect(),
100
-            'url_obfuscator_service'    =>  $this->url_obfuscator_service
101
-        ]);
102
-    }
34
+	use ViewResponseTrait;
35
+
36
+	/**
37
+	 * @var CertificatesModule|null $module
38
+	 */
39
+	private $module;
40
+
41
+	/**
42
+	 * @var CertificateFilesystemService $certif_filesystem
43
+	 */
44
+	private $certif_filesystem;
45
+
46
+	/**
47
+	 * @var UrlObfuscatorService $url_obfuscator_service
48
+	 */
49
+	private $url_obfuscator_service;
50
+
51
+
52
+	/**
53
+	 * Constructor for CertificatesList Request Handler
54
+	 *
55
+	 * @param ModuleService $module_service
56
+	 */
57
+	public function __construct(
58
+		ModuleService $module_service,
59
+		CertificateFilesystemService $certif_filesystem,
60
+		UrlObfuscatorService $url_obfuscator_service
61
+	) {
62
+		$this->module = $module_service->findByInterface(CertificatesModule::class)->first();
63
+		$this->certif_filesystem = $certif_filesystem;
64
+		$this->url_obfuscator_service = $url_obfuscator_service;
65
+	}
66
+
67
+	/**
68
+	 * {@inheritDoc}
69
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
70
+	 */
71
+	public function handle(ServerRequestInterface $request): ResponseInterface
72
+	{
73
+		if ($this->module === null) {
74
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
75
+		}
76
+
77
+		$tree = $request->getAttribute('tree');
78
+		assert($tree instanceof Tree);
79
+
80
+		$title = I18N::translate('Certificates');
81
+
82
+		$cities = array_map(function (string $item): array {
83
+			return [$this->url_obfuscator_service->obfuscate($item), $item];
84
+		}, $this->certif_filesystem->cities($tree));
85
+
86
+		$city = $request->getQueryParams()['cityobf'] ?? $request->getAttribute('cityobf') ?? '';
87
+
88
+		if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) {
89
+			$title = I18N::translate('Certificates for %s', $city);
90
+			$certificates = $this->certif_filesystem->certificatesForCity($tree, $city);
91
+		}
92
+
93
+		return $this->viewResponse($this->module->name() . '::certificates-list', [
94
+			'title'                     =>  $title,
95
+			'tree'                      =>  $tree,
96
+			'module_name'               =>  $this->module->name(),
97
+			'cities'                    =>  $cities,
98
+			'selected_city'             =>  $city,
99
+			'certificates_list'         =>  $certificates ?? collect(),
100
+			'url_obfuscator_service'    =>  $this->url_obfuscator_service
101
+		]);
102
+	}
103 103
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/Certificates/Http/RequestHandlers/AdminTreesPage.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -30,51 +30,51 @@
 block discarded – undo
30 30
  */
31 31
 class AdminTreesPage implements RequestHandlerInterface
32 32
 {
33
-    use ViewResponseTrait;
33
+	use ViewResponseTrait;
34 34
 
35
-    /**
36
-     * @var CertificatesModule|null $module
37
-     */
38
-    private $module;
35
+	/**
36
+	 * @var CertificatesModule|null $module
37
+	 */
38
+	private $module;
39 39
 
40
-    /**
41
-     *
42
-     * @var TreeService $tree_service
43
-     */
44
-    private $tree_service;
40
+	/**
41
+	 *
42
+	 * @var TreeService $tree_service
43
+	 */
44
+	private $tree_service;
45 45
 
46
-    /**
47
-     * Constructor for Admin Trees request handler
48
-     *
49
-     * @param ModuleService $module_service
50
-     * @param TreeService $tree_service
51
-     */
52
-    public function __construct(ModuleService $module_service, TreeService $tree_service)
53
-    {
54
-        $this->module = $module_service->findByInterface(CertificatesModule::class)->first();
55
-        $this->tree_service = $tree_service;
56
-    }
46
+	/**
47
+	 * Constructor for Admin Trees request handler
48
+	 *
49
+	 * @param ModuleService $module_service
50
+	 * @param TreeService $tree_service
51
+	 */
52
+	public function __construct(ModuleService $module_service, TreeService $tree_service)
53
+	{
54
+		$this->module = $module_service->findByInterface(CertificatesModule::class)->first();
55
+		$this->tree_service = $tree_service;
56
+	}
57 57
 
58
-    /**
59
-     * {@inheritDoc}
60
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
61
-     */
62
-    public function handle(ServerRequestInterface $request): ResponseInterface
63
-    {
64
-        $this->layout = 'layouts/administration';
58
+	/**
59
+	 * {@inheritDoc}
60
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
61
+	 */
62
+	public function handle(ServerRequestInterface $request): ResponseInterface
63
+	{
64
+		$this->layout = 'layouts/administration';
65 65
 
66
-        if ($this->module === null) {
67
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
68
-        }
66
+		if ($this->module === null) {
67
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
68
+		}
69 69
 
70
-        $trees = $this->tree_service->all();
71
-        if ($trees->count() == 1) {
72
-            return redirect(route(AdminConfigPage::class, ['tree' => $trees->first()]));
73
-        }
70
+		$trees = $this->tree_service->all();
71
+		if ($trees->count() == 1) {
72
+			return redirect(route(AdminConfigPage::class, ['tree' => $trees->first()]));
73
+		}
74 74
 
75
-        return $this->viewResponse($this->module->name() . '::admin/trees', [
76
-            'title'             =>  $this->module->title(),
77
-            'trees'             =>  $this->tree_service->all()
78
-        ]);
79
-    }
75
+		return $this->viewResponse($this->module->name() . '::admin/trees', [
76
+			'title'             =>  $this->module->title(),
77
+			'trees'             =>  $this->tree_service->all()
78
+		]);
79
+	}
80 80
 }
Please login to merge, or discard this patch.