@@ -31,64 +31,64 @@ |
||
| 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 | } |
@@ -29,93 +29,93 @@ |
||
| 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 | } |
@@ -33,159 +33,159 @@ |
||
| 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 | - $router->tokens(['block_id' => '\d+']); |
|
| 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 | + $router->tokens(['block_id' => '\d+']); |
|
| 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 | } |
@@ -21,19 +21,19 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | interface ModuleMyArtJaubInterface extends ModuleCustomInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Add module routes to webtrees route loader |
|
| 26 | - * |
|
| 27 | - * @param Map $router |
|
| 28 | - */ |
|
| 29 | - public function loadRoutes(Map $router): void; |
|
| 24 | + /** |
|
| 25 | + * Add module routes to webtrees route loader |
|
| 26 | + * |
|
| 27 | + * @param Map $router |
|
| 28 | + */ |
|
| 29 | + public function loadRoutes(Map $router): void; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Returns the URL of the module specific stylesheets. |
|
| 33 | - * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
| 34 | - * and fallback to default.min.css if none are found |
|
| 35 | - * |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function moduleCssUrl(): string; |
|
| 31 | + /** |
|
| 32 | + * Returns the URL of the module specific stylesheets. |
|
| 33 | + * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
| 34 | + * and fallback to default.min.css if none are found |
|
| 35 | + * |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function moduleCssUrl(): string; |
|
| 39 | 39 | } |
@@ -25,63 +25,63 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class IsSourcedStatusHook implements RecordNameTextExtenderInterface |
| 27 | 27 | { |
| 28 | - private ModuleInterface $module; |
|
| 29 | - private SourceStatusService $source_status_service; |
|
| 28 | + private ModuleInterface $module; |
|
| 29 | + private SourceStatusService $source_status_service; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Constructor for IsSourcedStatusHook |
|
| 33 | - * |
|
| 34 | - * @param ModuleInterface $module |
|
| 35 | - * @param SourceStatusService $source_status_service |
|
| 36 | - */ |
|
| 37 | - public function __construct(ModuleInterface $module, SourceStatusService $source_status_service) |
|
| 38 | - { |
|
| 39 | - $this->module = $module; |
|
| 40 | - $this->source_status_service = $source_status_service; |
|
| 41 | - } |
|
| 31 | + /** |
|
| 32 | + * Constructor for IsSourcedStatusHook |
|
| 33 | + * |
|
| 34 | + * @param ModuleInterface $module |
|
| 35 | + * @param SourceStatusService $source_status_service |
|
| 36 | + */ |
|
| 37 | + public function __construct(ModuleInterface $module, SourceStatusService $source_status_service) |
|
| 38 | + { |
|
| 39 | + $this->module = $module; |
|
| 40 | + $this->source_status_service = $source_status_service; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * {@inheritDoc} |
|
| 45 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 46 | - */ |
|
| 47 | - public function module(): ModuleInterface |
|
| 48 | - { |
|
| 49 | - return $this->module; |
|
| 50 | - } |
|
| 43 | + /** |
|
| 44 | + * {@inheritDoc} |
|
| 45 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 46 | + */ |
|
| 47 | + public function module(): ModuleInterface |
|
| 48 | + { |
|
| 49 | + return $this->module; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
| 55 | - */ |
|
| 56 | - public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 57 | - { |
|
| 58 | - return ''; |
|
| 59 | - } |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
| 55 | + */ |
|
| 56 | + public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 57 | + { |
|
| 58 | + return ''; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * {@inheritDoc} |
|
| 63 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
| 64 | - */ |
|
| 65 | - public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 66 | - { |
|
| 67 | - if ($use_long && $record instanceof Individual) { |
|
| 68 | - return |
|
| 69 | - view($this->module()->name() . '::icons/source-status', [ |
|
| 70 | - 'module_name' => $this->module()->name(), |
|
| 71 | - 'source_status' => $this->source_status_service->sourceStatusForRecord($record), |
|
| 72 | - 'context' => 'INDI', |
|
| 73 | - 'size_style' => $size ]) . |
|
| 74 | - view($this->module()->name() . '::icons/source-status', [ |
|
| 75 | - 'module_name' => $this->module()->name(), |
|
| 76 | - 'source_status' => $this->source_status_service->sourceStatusForBirth($record), |
|
| 77 | - 'context' => 'INDI:BIRT', |
|
| 78 | - 'size_style' => $size ]) . |
|
| 79 | - ($record->isDead() ? view($this->module()->name() . '::icons/source-status', [ |
|
| 80 | - 'module_name' => $this->module()->name(), |
|
| 81 | - 'source_status' => $this->source_status_service->sourceStatusForDeath($record), |
|
| 82 | - 'context' => 'INDI:DEAT', |
|
| 83 | - 'size_style' => $size ]) : '') ; |
|
| 84 | - } |
|
| 85 | - return ''; |
|
| 86 | - } |
|
| 61 | + /** |
|
| 62 | + * {@inheritDoc} |
|
| 63 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
| 64 | + */ |
|
| 65 | + public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 66 | + { |
|
| 67 | + if ($use_long && $record instanceof Individual) { |
|
| 68 | + return |
|
| 69 | + view($this->module()->name() . '::icons/source-status', [ |
|
| 70 | + 'module_name' => $this->module()->name(), |
|
| 71 | + 'source_status' => $this->source_status_service->sourceStatusForRecord($record), |
|
| 72 | + 'context' => 'INDI', |
|
| 73 | + 'size_style' => $size ]) . |
|
| 74 | + view($this->module()->name() . '::icons/source-status', [ |
|
| 75 | + 'module_name' => $this->module()->name(), |
|
| 76 | + 'source_status' => $this->source_status_service->sourceStatusForBirth($record), |
|
| 77 | + 'context' => 'INDI:BIRT', |
|
| 78 | + 'size_style' => $size ]) . |
|
| 79 | + ($record->isDead() ? view($this->module()->name() . '::icons/source-status', [ |
|
| 80 | + 'module_name' => $this->module()->name(), |
|
| 81 | + 'source_status' => $this->source_status_service->sourceStatusForDeath($record), |
|
| 82 | + 'context' => 'INDI:DEAT', |
|
| 83 | + 'size_style' => $size ]) : '') ; |
|
| 84 | + } |
|
| 85 | + return ''; |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -30,183 +30,183 @@ |
||
| 30 | 30 | * Hook for adding columns with source statuses in datatables. |
| 31 | 31 | */ |
| 32 | 32 | class IsSourcedStatusColumnsHook implements |
| 33 | - FamilyDatatablesExtenderInterface, |
|
| 34 | - IndividualDatatablesExtenderInterface, |
|
| 35 | - SosaFamilyDatatablesExtenderInterface, |
|
| 36 | - SosaIndividualDatatablesExtenderInterface, |
|
| 37 | - SosaMissingDatatablesExtenderInterface |
|
| 33 | + FamilyDatatablesExtenderInterface, |
|
| 34 | + IndividualDatatablesExtenderInterface, |
|
| 35 | + SosaFamilyDatatablesExtenderInterface, |
|
| 36 | + SosaIndividualDatatablesExtenderInterface, |
|
| 37 | + SosaMissingDatatablesExtenderInterface |
|
| 38 | 38 | { |
| 39 | - private ModuleInterface $module; |
|
| 40 | - private SourceStatusService $source_status_service; |
|
| 39 | + private ModuleInterface $module; |
|
| 40 | + private SourceStatusService $source_status_service; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor for IsSourcedStatusColumnsHook |
|
| 44 | - * |
|
| 45 | - * @param ModuleInterface $module |
|
| 46 | - * @param SourceStatusService $source_status_service |
|
| 47 | - */ |
|
| 48 | - public function __construct(ModuleInterface $module, SourceStatusService $source_status_service) |
|
| 49 | - { |
|
| 50 | - $this->module = $module; |
|
| 51 | - $this->source_status_service = $source_status_service; |
|
| 52 | - } |
|
| 42 | + /** |
|
| 43 | + * Constructor for IsSourcedStatusColumnsHook |
|
| 44 | + * |
|
| 45 | + * @param ModuleInterface $module |
|
| 46 | + * @param SourceStatusService $source_status_service |
|
| 47 | + */ |
|
| 48 | + public function __construct(ModuleInterface $module, SourceStatusService $source_status_service) |
|
| 49 | + { |
|
| 50 | + $this->module = $module; |
|
| 51 | + $this->source_status_service = $source_status_service; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * {@inheritDoc} |
|
| 56 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 57 | - */ |
|
| 58 | - public function module(): ModuleInterface |
|
| 59 | - { |
|
| 60 | - return $this->module; |
|
| 61 | - } |
|
| 54 | + /** |
|
| 55 | + * {@inheritDoc} |
|
| 56 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 57 | + */ |
|
| 58 | + public function module(): ModuleInterface |
|
| 59 | + { |
|
| 60 | + return $this->module; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * {@inheritDoc} |
|
| 65 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\IndividualDatatablesExtenderInterface::individualColumns() |
|
| 66 | - */ |
|
| 67 | - public function individualColumns(iterable $records): array |
|
| 68 | - { |
|
| 69 | - $records = collect($records); |
|
| 70 | - return [ |
|
| 71 | - 'issourced' => [ |
|
| 72 | - 'birth' => [ |
|
| 73 | - 'position' => 7, |
|
| 74 | - 'column_def' => [ 'class' => 'text-center' ], |
|
| 75 | - 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 76 | - 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI:BIRT')->label()) |
|
| 77 | - ]), |
|
| 78 | - 'records' => $records->map(function (Individual $individual): array { |
|
| 79 | - $source_status = $this->source_status_service->sourceStatusForBirth($individual); |
|
| 80 | - return [ |
|
| 81 | - 'order' => $source_status->order(), |
|
| 82 | - 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 83 | - 'module_name' => $this->module()->name(), |
|
| 84 | - 'source_status' => $source_status, |
|
| 85 | - 'context' => 'INDI:BIRT', |
|
| 86 | - 'size_style' => '' ]) |
|
| 87 | - ]; |
|
| 88 | - })->toArray() |
|
| 89 | - ], |
|
| 90 | - 'death' => [ |
|
| 91 | - 'position' => 12, |
|
| 92 | - 'column_def' => [ 'class' => 'text-center' ], |
|
| 93 | - 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 94 | - 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI:DEAT')->label()) |
|
| 95 | - ]), |
|
| 96 | - 'records' => $records->map(function (Individual $individual): array { |
|
| 97 | - $source_status = $this->source_status_service->sourceStatusForDeath($individual); |
|
| 98 | - return $individual->isDead() ? [ |
|
| 99 | - 'order' => $source_status->order(), |
|
| 100 | - 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 101 | - 'module_name' => $this->module()->name(), |
|
| 102 | - 'source_status' => $source_status, |
|
| 103 | - 'context' => 'INDI:DEAT', |
|
| 104 | - 'size_style' => '' ]) |
|
| 105 | - ] : ['order' => 0, 'text' => '']; |
|
| 106 | - })->toArray() |
|
| 107 | - ] |
|
| 108 | - ] |
|
| 109 | - ]; |
|
| 110 | - } |
|
| 63 | + /** |
|
| 64 | + * {@inheritDoc} |
|
| 65 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\IndividualDatatablesExtenderInterface::individualColumns() |
|
| 66 | + */ |
|
| 67 | + public function individualColumns(iterable $records): array |
|
| 68 | + { |
|
| 69 | + $records = collect($records); |
|
| 70 | + return [ |
|
| 71 | + 'issourced' => [ |
|
| 72 | + 'birth' => [ |
|
| 73 | + 'position' => 7, |
|
| 74 | + 'column_def' => [ 'class' => 'text-center' ], |
|
| 75 | + 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 76 | + 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI:BIRT')->label()) |
|
| 77 | + ]), |
|
| 78 | + 'records' => $records->map(function (Individual $individual): array { |
|
| 79 | + $source_status = $this->source_status_service->sourceStatusForBirth($individual); |
|
| 80 | + return [ |
|
| 81 | + 'order' => $source_status->order(), |
|
| 82 | + 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 83 | + 'module_name' => $this->module()->name(), |
|
| 84 | + 'source_status' => $source_status, |
|
| 85 | + 'context' => 'INDI:BIRT', |
|
| 86 | + 'size_style' => '' ]) |
|
| 87 | + ]; |
|
| 88 | + })->toArray() |
|
| 89 | + ], |
|
| 90 | + 'death' => [ |
|
| 91 | + 'position' => 12, |
|
| 92 | + 'column_def' => [ 'class' => 'text-center' ], |
|
| 93 | + 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 94 | + 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI:DEAT')->label()) |
|
| 95 | + ]), |
|
| 96 | + 'records' => $records->map(function (Individual $individual): array { |
|
| 97 | + $source_status = $this->source_status_service->sourceStatusForDeath($individual); |
|
| 98 | + return $individual->isDead() ? [ |
|
| 99 | + 'order' => $source_status->order(), |
|
| 100 | + 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 101 | + 'module_name' => $this->module()->name(), |
|
| 102 | + 'source_status' => $source_status, |
|
| 103 | + 'context' => 'INDI:DEAT', |
|
| 104 | + 'size_style' => '' ]) |
|
| 105 | + ] : ['order' => 0, 'text' => '']; |
|
| 106 | + })->toArray() |
|
| 107 | + ] |
|
| 108 | + ] |
|
| 109 | + ]; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * {@inheritDoc} |
|
| 114 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FamilyDatatablesExtenderInterface::familyColumns() |
|
| 115 | - */ |
|
| 116 | - public function familyColumns(iterable $records): array |
|
| 117 | - { |
|
| 118 | - $records = collect($records); |
|
| 119 | - return [ |
|
| 120 | - 'issourced' => [ |
|
| 121 | - 'marr' => [ |
|
| 122 | - 'position' => 10, |
|
| 123 | - 'column_def' => [ 'class' => 'text-center' ], |
|
| 124 | - 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 125 | - 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('FAM:MARR')->label()) |
|
| 126 | - ]), |
|
| 127 | - 'records' => $records->map(function (Family $family): array { |
|
| 128 | - $source_status = $this->source_status_service->sourceStatusForMarriage($family); |
|
| 129 | - return $family->getMarriage() !== null ? [ |
|
| 130 | - 'order' => $source_status->order(), |
|
| 131 | - 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 132 | - 'module_name' => $this->module()->name(), |
|
| 133 | - 'source_status' => $source_status, |
|
| 134 | - 'context' => 'FAM:MARR', |
|
| 135 | - 'size_style' => '' ]) |
|
| 136 | - ] : ['order' => 0, 'text' => '']; |
|
| 137 | - })->toArray() |
|
| 138 | - ] |
|
| 139 | - ] |
|
| 140 | - ]; |
|
| 141 | - } |
|
| 112 | + /** |
|
| 113 | + * {@inheritDoc} |
|
| 114 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FamilyDatatablesExtenderInterface::familyColumns() |
|
| 115 | + */ |
|
| 116 | + public function familyColumns(iterable $records): array |
|
| 117 | + { |
|
| 118 | + $records = collect($records); |
|
| 119 | + return [ |
|
| 120 | + 'issourced' => [ |
|
| 121 | + 'marr' => [ |
|
| 122 | + 'position' => 10, |
|
| 123 | + 'column_def' => [ 'class' => 'text-center' ], |
|
| 124 | + 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 125 | + 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('FAM:MARR')->label()) |
|
| 126 | + ]), |
|
| 127 | + 'records' => $records->map(function (Family $family): array { |
|
| 128 | + $source_status = $this->source_status_service->sourceStatusForMarriage($family); |
|
| 129 | + return $family->getMarriage() !== null ? [ |
|
| 130 | + 'order' => $source_status->order(), |
|
| 131 | + 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 132 | + 'module_name' => $this->module()->name(), |
|
| 133 | + 'source_status' => $source_status, |
|
| 134 | + 'context' => 'FAM:MARR', |
|
| 135 | + 'size_style' => '' ]) |
|
| 136 | + ] : ['order' => 0, 'text' => '']; |
|
| 137 | + })->toArray() |
|
| 138 | + ] |
|
| 139 | + ] |
|
| 140 | + ]; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * {@inheritDoc} |
|
| 145 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaIndividualDatatablesExtenderInterface::sosaIndividualColumns() |
|
| 146 | - */ |
|
| 147 | - public function sosaIndividualColumns(iterable $records): array |
|
| 148 | - { |
|
| 149 | - $columns = $this->individualColumns($records); |
|
| 150 | - $columns['issourced']['birth']['position'] = 5; |
|
| 151 | - $columns['issourced']['death']['position'] = 8; |
|
| 152 | - return $columns; |
|
| 153 | - } |
|
| 143 | + /** |
|
| 144 | + * {@inheritDoc} |
|
| 145 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaIndividualDatatablesExtenderInterface::sosaIndividualColumns() |
|
| 146 | + */ |
|
| 147 | + public function sosaIndividualColumns(iterable $records): array |
|
| 148 | + { |
|
| 149 | + $columns = $this->individualColumns($records); |
|
| 150 | + $columns['issourced']['birth']['position'] = 5; |
|
| 151 | + $columns['issourced']['death']['position'] = 8; |
|
| 152 | + return $columns; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * {@inheritDoc} |
|
| 157 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaFamilyDatatablesExtenderInterface::sosaFamilyColumns() |
|
| 158 | - */ |
|
| 159 | - public function sosaFamilyColumns(iterable $records): array |
|
| 160 | - { |
|
| 161 | - return $this->familyColumns($records); |
|
| 162 | - } |
|
| 155 | + /** |
|
| 156 | + * {@inheritDoc} |
|
| 157 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaFamilyDatatablesExtenderInterface::sosaFamilyColumns() |
|
| 158 | + */ |
|
| 159 | + public function sosaFamilyColumns(iterable $records): array |
|
| 160 | + { |
|
| 161 | + return $this->familyColumns($records); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * {@inheritDoc} |
|
| 166 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaMissingDatatablesExtenderInterface::sosaMissingColumns() |
|
| 167 | - */ |
|
| 168 | - public function sosaMissingColumns(iterable $records): array |
|
| 169 | - { |
|
| 170 | - $records = collect($records); |
|
| 171 | - return [ |
|
| 172 | - 'issourced' => [ |
|
| 173 | - 'indi' => [ |
|
| 174 | - 'position' => 3, |
|
| 175 | - 'column_def' => [ 'class' => 'text-center' ], |
|
| 176 | - 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 177 | - 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI')->label()) |
|
| 178 | - ]), |
|
| 179 | - 'records' => $records->map(function (Individual $individual): array { |
|
| 180 | - $source_status = $this->source_status_service->sourceStatusForRecord($individual); |
|
| 181 | - return [ |
|
| 182 | - 'order' => $source_status->order(), |
|
| 183 | - 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 184 | - 'module_name' => $this->module()->name(), |
|
| 185 | - 'source_status' => $source_status, |
|
| 186 | - 'context' => 'INDI', |
|
| 187 | - 'size_style' => '' ]) |
|
| 188 | - ]; |
|
| 189 | - })->toArray() |
|
| 190 | - ], |
|
| 191 | - 'birth' => [ |
|
| 192 | - 'position' => 7, |
|
| 193 | - 'column_def' => [ 'class' => 'text-center' ], |
|
| 194 | - 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 195 | - 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI:BIRT')->label()) |
|
| 196 | - ]), |
|
| 197 | - 'records' => $records->map(function (Individual $individual): array { |
|
| 198 | - $source_status = $this->source_status_service->sourceStatusForBirth($individual); |
|
| 199 | - return [ |
|
| 200 | - 'order' => $source_status->order(), |
|
| 201 | - 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 202 | - 'module_name' => $this->module()->name(), |
|
| 203 | - 'source_status' => $source_status, |
|
| 204 | - 'context' => 'INDI:BIRT', |
|
| 205 | - 'size_style' => '' ]) |
|
| 206 | - ]; |
|
| 207 | - })->toArray() |
|
| 208 | - ] |
|
| 209 | - ] |
|
| 210 | - ]; |
|
| 211 | - } |
|
| 164 | + /** |
|
| 165 | + * {@inheritDoc} |
|
| 166 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaMissingDatatablesExtenderInterface::sosaMissingColumns() |
|
| 167 | + */ |
|
| 168 | + public function sosaMissingColumns(iterable $records): array |
|
| 169 | + { |
|
| 170 | + $records = collect($records); |
|
| 171 | + return [ |
|
| 172 | + 'issourced' => [ |
|
| 173 | + 'indi' => [ |
|
| 174 | + 'position' => 3, |
|
| 175 | + 'column_def' => [ 'class' => 'text-center' ], |
|
| 176 | + 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 177 | + 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI')->label()) |
|
| 178 | + ]), |
|
| 179 | + 'records' => $records->map(function (Individual $individual): array { |
|
| 180 | + $source_status = $this->source_status_service->sourceStatusForRecord($individual); |
|
| 181 | + return [ |
|
| 182 | + 'order' => $source_status->order(), |
|
| 183 | + 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 184 | + 'module_name' => $this->module()->name(), |
|
| 185 | + 'source_status' => $source_status, |
|
| 186 | + 'context' => 'INDI', |
|
| 187 | + 'size_style' => '' ]) |
|
| 188 | + ]; |
|
| 189 | + })->toArray() |
|
| 190 | + ], |
|
| 191 | + 'birth' => [ |
|
| 192 | + 'position' => 7, |
|
| 193 | + 'column_def' => [ 'class' => 'text-center' ], |
|
| 194 | + 'th' => view($this->module()->name() . '::components/column-th-issourced', [ |
|
| 195 | + 'title' => I18N::translate('%s sourced', Registry::elementFactory()->make('INDI:BIRT')->label()) |
|
| 196 | + ]), |
|
| 197 | + 'records' => $records->map(function (Individual $individual): array { |
|
| 198 | + $source_status = $this->source_status_service->sourceStatusForBirth($individual); |
|
| 199 | + return [ |
|
| 200 | + 'order' => $source_status->order(), |
|
| 201 | + 'text' => view($this->module()->name() . '::icons/source-status', [ |
|
| 202 | + 'module_name' => $this->module()->name(), |
|
| 203 | + 'source_status' => $source_status, |
|
| 204 | + 'context' => 'INDI:BIRT', |
|
| 205 | + 'size_style' => '' ]) |
|
| 206 | + ]; |
|
| 207 | + })->toArray() |
|
| 208 | + ] |
|
| 209 | + ] |
|
| 210 | + ]; |
|
| 211 | + } |
|
| 212 | 212 | } |
@@ -22,148 +22,148 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class SourceStatus |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var boolean $source_exist |
|
| 27 | - */ |
|
| 28 | - private $source_exist = false; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var boolean $has_document |
|
| 32 | - */ |
|
| 33 | - private $has_document = false; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Return whether the SourceStatus object contains relevant data. |
|
| 37 | - * |
|
| 38 | - * @return bool |
|
| 39 | - */ |
|
| 40 | - public function isSet(): bool |
|
| 41 | - { |
|
| 42 | - return true; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Returns whether the record contains a source. |
|
| 47 | - * |
|
| 48 | - * @return bool |
|
| 49 | - */ |
|
| 50 | - public function hasSource(): bool |
|
| 51 | - { |
|
| 52 | - return $this->source_exist; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Set whether the record contains a source. |
|
| 57 | - * |
|
| 58 | - * @param bool $source_exist |
|
| 59 | - * @return $this |
|
| 60 | - */ |
|
| 61 | - public function setHasSource(bool $source_exist): self |
|
| 62 | - { |
|
| 63 | - $this->source_exist = $source_exist; |
|
| 64 | - return $this; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Combine whether the record contains a source with the previous status. |
|
| 69 | - * |
|
| 70 | - * @param bool $source_exist |
|
| 71 | - * @return $this |
|
| 72 | - */ |
|
| 73 | - public function addHasSource(bool $source_exist): self |
|
| 74 | - { |
|
| 75 | - $this->source_exist = $this->source_exist || $source_exist; |
|
| 76 | - return $this; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Return whether the source citation is supported by a document. |
|
| 81 | - * Uses the _ACT tag from the MyArtJaub Certificates module. |
|
| 82 | - * |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public function hasSupportingDocument(): bool |
|
| 86 | - { |
|
| 87 | - return $this->hasSource() && $this->has_document; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Set whether the source citation is supported by a document. |
|
| 92 | - * |
|
| 93 | - * @param bool $has_document |
|
| 94 | - * @return $this |
|
| 95 | - */ |
|
| 96 | - public function setHasSupportingDocument(bool $has_document): self |
|
| 97 | - { |
|
| 98 | - $this->has_document = $has_document; |
|
| 99 | - return $this; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Combine whether the source citation is supported by a document with the previous status. |
|
| 104 | - * |
|
| 105 | - * @param bool $has_document |
|
| 106 | - * @return $this |
|
| 107 | - */ |
|
| 108 | - public function addHasSupportingDocument(bool $has_document): self |
|
| 109 | - { |
|
| 110 | - $this->has_document = $this->has_document || $has_document; |
|
| 111 | - return $this; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Check whether all possible criteria for defining a sourced element have been met. |
|
| 116 | - * |
|
| 117 | - * @return bool |
|
| 118 | - */ |
|
| 119 | - public function isFullySourced(): bool |
|
| 120 | - { |
|
| 121 | - return $this->hasSupportingDocument(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Get the label to display to describe the source status. |
|
| 126 | - * |
|
| 127 | - * @param string $context |
|
| 128 | - * @return string |
|
| 129 | - */ |
|
| 130 | - public function label(string $context): string |
|
| 131 | - { |
|
| 132 | - $context_label = Registry::elementFactory()->make($context)->label(); |
|
| 133 | - |
|
| 134 | - if (!$this->hasSource()) { |
|
| 135 | - return I18N::translate('%s not sourced', $context_label); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if ($this->hasSupportingDocument()) { |
|
| 139 | - return I18N::translate('%s sourced with a certificate', $context_label); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return I18N::translate('%s sourced', $context_label); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Get an indicative value to order source statuses |
|
| 147 | - * |
|
| 148 | - * @return int |
|
| 149 | - */ |
|
| 150 | - public function order(): int |
|
| 151 | - { |
|
| 152 | - return ($this->hasSource() ? 1 : 0) * (1 + ($this->hasSupportingDocument() ? 1 : 0)); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Return an element combining properties of the current object with another SourceStatus. |
|
| 157 | - * Do not use the initial object anymore, it may not appropriately describe the status anymore. |
|
| 158 | - * |
|
| 159 | - * @template T of SourceStatus |
|
| 160 | - * @param T $other |
|
| 161 | - * @return $this|T |
|
| 162 | - */ |
|
| 163 | - public function combineWith(SourceStatus $other) |
|
| 164 | - { |
|
| 165 | - $this->addHasSource($other->hasSource()); |
|
| 166 | - $this->addHasSupportingDocument($other->hasSource()); |
|
| 167 | - return $this; |
|
| 168 | - } |
|
| 25 | + /** |
|
| 26 | + * @var boolean $source_exist |
|
| 27 | + */ |
|
| 28 | + private $source_exist = false; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var boolean $has_document |
|
| 32 | + */ |
|
| 33 | + private $has_document = false; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Return whether the SourceStatus object contains relevant data. |
|
| 37 | + * |
|
| 38 | + * @return bool |
|
| 39 | + */ |
|
| 40 | + public function isSet(): bool |
|
| 41 | + { |
|
| 42 | + return true; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Returns whether the record contains a source. |
|
| 47 | + * |
|
| 48 | + * @return bool |
|
| 49 | + */ |
|
| 50 | + public function hasSource(): bool |
|
| 51 | + { |
|
| 52 | + return $this->source_exist; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Set whether the record contains a source. |
|
| 57 | + * |
|
| 58 | + * @param bool $source_exist |
|
| 59 | + * @return $this |
|
| 60 | + */ |
|
| 61 | + public function setHasSource(bool $source_exist): self |
|
| 62 | + { |
|
| 63 | + $this->source_exist = $source_exist; |
|
| 64 | + return $this; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Combine whether the record contains a source with the previous status. |
|
| 69 | + * |
|
| 70 | + * @param bool $source_exist |
|
| 71 | + * @return $this |
|
| 72 | + */ |
|
| 73 | + public function addHasSource(bool $source_exist): self |
|
| 74 | + { |
|
| 75 | + $this->source_exist = $this->source_exist || $source_exist; |
|
| 76 | + return $this; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Return whether the source citation is supported by a document. |
|
| 81 | + * Uses the _ACT tag from the MyArtJaub Certificates module. |
|
| 82 | + * |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public function hasSupportingDocument(): bool |
|
| 86 | + { |
|
| 87 | + return $this->hasSource() && $this->has_document; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Set whether the source citation is supported by a document. |
|
| 92 | + * |
|
| 93 | + * @param bool $has_document |
|
| 94 | + * @return $this |
|
| 95 | + */ |
|
| 96 | + public function setHasSupportingDocument(bool $has_document): self |
|
| 97 | + { |
|
| 98 | + $this->has_document = $has_document; |
|
| 99 | + return $this; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Combine whether the source citation is supported by a document with the previous status. |
|
| 104 | + * |
|
| 105 | + * @param bool $has_document |
|
| 106 | + * @return $this |
|
| 107 | + */ |
|
| 108 | + public function addHasSupportingDocument(bool $has_document): self |
|
| 109 | + { |
|
| 110 | + $this->has_document = $this->has_document || $has_document; |
|
| 111 | + return $this; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Check whether all possible criteria for defining a sourced element have been met. |
|
| 116 | + * |
|
| 117 | + * @return bool |
|
| 118 | + */ |
|
| 119 | + public function isFullySourced(): bool |
|
| 120 | + { |
|
| 121 | + return $this->hasSupportingDocument(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Get the label to display to describe the source status. |
|
| 126 | + * |
|
| 127 | + * @param string $context |
|
| 128 | + * @return string |
|
| 129 | + */ |
|
| 130 | + public function label(string $context): string |
|
| 131 | + { |
|
| 132 | + $context_label = Registry::elementFactory()->make($context)->label(); |
|
| 133 | + |
|
| 134 | + if (!$this->hasSource()) { |
|
| 135 | + return I18N::translate('%s not sourced', $context_label); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if ($this->hasSupportingDocument()) { |
|
| 139 | + return I18N::translate('%s sourced with a certificate', $context_label); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return I18N::translate('%s sourced', $context_label); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Get an indicative value to order source statuses |
|
| 147 | + * |
|
| 148 | + * @return int |
|
| 149 | + */ |
|
| 150 | + public function order(): int |
|
| 151 | + { |
|
| 152 | + return ($this->hasSource() ? 1 : 0) * (1 + ($this->hasSupportingDocument() ? 1 : 0)); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Return an element combining properties of the current object with another SourceStatus. |
|
| 157 | + * Do not use the initial object anymore, it may not appropriately describe the status anymore. |
|
| 158 | + * |
|
| 159 | + * @template T of SourceStatus |
|
| 160 | + * @param T $other |
|
| 161 | + * @return $this|T |
|
| 162 | + */ |
|
| 163 | + public function combineWith(SourceStatus $other) |
|
| 164 | + { |
|
| 165 | + $this->addHasSource($other->hasSource()); |
|
| 166 | + $this->addHasSupportingDocument($other->hasSource()); |
|
| 167 | + return $this; |
|
| 168 | + } |
|
| 169 | 169 | } |
@@ -22,231 +22,231 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class FactSourceStatus extends SourceStatus |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var boolean $has_date |
|
| 27 | - */ |
|
| 28 | - private $has_date = false; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var boolean $has_precise_date |
|
| 32 | - */ |
|
| 33 | - private $has_precise_date = false; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var boolean $has_source_date |
|
| 37 | - */ |
|
| 38 | - private $has_source_date = false; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var boolean $source_date_match |
|
| 42 | - */ |
|
| 43 | - private $source_date_match = false; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Return whether the fact is dated. |
|
| 47 | - * |
|
| 48 | - * @return bool |
|
| 49 | - */ |
|
| 50 | - public function factHasDate(): bool |
|
| 51 | - { |
|
| 52 | - return $this->has_date; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Set whether the fact is dated. |
|
| 57 | - * |
|
| 58 | - * @param bool $has_date |
|
| 59 | - * @return $this |
|
| 60 | - */ |
|
| 61 | - public function setFactHasDate(bool $has_date): self |
|
| 62 | - { |
|
| 63 | - $this->has_date = $has_date; |
|
| 64 | - return $this; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Combinate whether the fact is dated with the previous status. |
|
| 69 | - * |
|
| 70 | - * @param bool $has_date |
|
| 71 | - * @return $this |
|
| 72 | - */ |
|
| 73 | - public function addFactHasDate(bool $has_date): self |
|
| 74 | - { |
|
| 75 | - $this->has_date = $this->has_date || $has_date; |
|
| 76 | - return $this; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Return whether the fact is dated with a precise day. |
|
| 81 | - * Any date modifier will be considered as not precise. |
|
| 82 | - * A month or year will be considered as not precise. |
|
| 83 | - * |
|
| 84 | - * @return bool |
|
| 85 | - */ |
|
| 86 | - public function factHasPreciseDate(): bool |
|
| 87 | - { |
|
| 88 | - return $this->has_date && $this->has_precise_date; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Set whather the fact is dated with a precise day. |
|
| 93 | - * |
|
| 94 | - * @param bool $has_precise_date |
|
| 95 | - * @return $this |
|
| 96 | - */ |
|
| 97 | - public function setFactHasPreciseDate(bool $has_precise_date): self |
|
| 98 | - { |
|
| 99 | - $this->has_precise_date = $has_precise_date; |
|
| 100 | - return $this; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Combine whether the fact is dated with a precise day. |
|
| 105 | - * |
|
| 106 | - * @param bool $has_precise_date |
|
| 107 | - * @return $this |
|
| 108 | - */ |
|
| 109 | - public function addFactHasPreciseDate(bool $has_precise_date): self |
|
| 110 | - { |
|
| 111 | - $this->has_precise_date = $this->has_precise_date || $has_precise_date; |
|
| 112 | - return $this; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Return whether the source citation is dated. |
|
| 117 | - * |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public function sourceHasDate(): bool |
|
| 121 | - { |
|
| 122 | - return $this->has_source_date; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Set whether the source citation is dated. |
|
| 127 | - * |
|
| 128 | - * @param bool $has_source_date |
|
| 129 | - * @return $this |
|
| 130 | - */ |
|
| 131 | - public function setSourceHasDate(bool $has_source_date): self |
|
| 132 | - { |
|
| 133 | - $this->has_source_date = $has_source_date; |
|
| 134 | - return $this; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Combine whether the source citation is dated with the previous status. |
|
| 139 | - * |
|
| 140 | - * @param bool $has_source_date |
|
| 141 | - * @return $this |
|
| 142 | - */ |
|
| 143 | - public function addSourceHasDate(bool $has_source_date): self |
|
| 144 | - { |
|
| 145 | - $this->has_source_date = $this->has_source_date || $has_source_date; |
|
| 146 | - return $this; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Return whether the source citation date is close to the fact date. |
|
| 151 | - * |
|
| 152 | - * @return bool |
|
| 153 | - */ |
|
| 154 | - public function sourceMatchesFactDate(): bool |
|
| 155 | - { |
|
| 156 | - return $this->has_precise_date && $this->has_source_date && $this->source_date_match; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Set whether the source citation date is close to the fact date. |
|
| 161 | - * |
|
| 162 | - * @param bool $source_date_match |
|
| 163 | - * @return $this |
|
| 164 | - */ |
|
| 165 | - public function setSourceMatchesFactDate(bool $source_date_match): self |
|
| 166 | - { |
|
| 167 | - $this->source_date_match = $source_date_match; |
|
| 168 | - return $this; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Combine whether the source citation date is close to the fact date with the previous status. |
|
| 173 | - * |
|
| 174 | - * @param bool $source_date_match |
|
| 175 | - * @return $this |
|
| 176 | - */ |
|
| 177 | - public function addSourceMatchesFactDate(bool $source_date_match): self |
|
| 178 | - { |
|
| 179 | - $this->source_date_match = $this->source_date_match || $source_date_match; |
|
| 180 | - return $this; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * {@inheritDoc} |
|
| 185 | - * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isFullySourced() |
|
| 186 | - */ |
|
| 187 | - public function isFullySourced(): bool |
|
| 188 | - { |
|
| 189 | - return parent::isFullySourced() && $this->sourceMatchesFactDate(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * {@inheritDoc} |
|
| 194 | - * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::label() |
|
| 195 | - */ |
|
| 196 | - public function label(string $context): string |
|
| 197 | - { |
|
| 198 | - $context_label = Registry::elementFactory()->make($context)->label(); |
|
| 199 | - |
|
| 200 | - if ($this->factHasPreciseDate()) { |
|
| 201 | - if ($this->hasSource()) { |
|
| 202 | - if ($this->hasSupportingDocument()) { |
|
| 203 | - if ($this->sourceMatchesFactDate()) { |
|
| 204 | - return I18N::translate('%s sourced with exact certificate', $context_label); |
|
| 205 | - } else { |
|
| 206 | - return I18N::translate('%s sourced with a certificate', $context_label); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if ($this->sourceMatchesFactDate()) { |
|
| 211 | - return I18N::translate('%s precisely sourced', $context_label); |
|
| 212 | - } |
|
| 213 | - return I18N::translate('%s sourced', $context_label); |
|
| 214 | - } |
|
| 215 | - return I18N::translate('%s not sourced', $context_label); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if ($this->factHasDate()) { |
|
| 219 | - return I18N::translate('%s not precise', $context_label); |
|
| 220 | - } |
|
| 221 | - return I18N::translate('%s not found', $context_label); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * {@inheritDoc} |
|
| 226 | - * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::order() |
|
| 227 | - */ |
|
| 228 | - public function order(): int |
|
| 229 | - { |
|
| 230 | - return ($this->factHasDate() ? 1 : 0) * ($this->hasSource() ? 1 : -1) * |
|
| 231 | - ( 1 + ($this->factHasPreciseDate() ? 1 : 0) * (1 + |
|
| 232 | - 0b010 * ($this->sourceMatchesFactDate() ? 1 : 0) + |
|
| 233 | - 0b100 * ($this->hasSupportingDocument() ? 1 : 0) |
|
| 234 | - ) |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * {@inheritDoc} |
|
| 240 | - * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::combineWith() |
|
| 241 | - */ |
|
| 242 | - public function combineWith(SourceStatus $other) |
|
| 243 | - { |
|
| 244 | - if ($other instanceof FactSourceStatus) { |
|
| 245 | - $this->addFactHasDate($other->factHasDate()); |
|
| 246 | - $this->addFactHasPreciseDate($other->factHasPreciseDate()); |
|
| 247 | - $this->addSourceHasDate($other->sourceHasDate()); |
|
| 248 | - $this->addSourceMatchesFactDate($other->sourceMatchesFactDate()); |
|
| 249 | - } |
|
| 250 | - return parent::combineWith($other); |
|
| 251 | - } |
|
| 25 | + /** |
|
| 26 | + * @var boolean $has_date |
|
| 27 | + */ |
|
| 28 | + private $has_date = false; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var boolean $has_precise_date |
|
| 32 | + */ |
|
| 33 | + private $has_precise_date = false; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var boolean $has_source_date |
|
| 37 | + */ |
|
| 38 | + private $has_source_date = false; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var boolean $source_date_match |
|
| 42 | + */ |
|
| 43 | + private $source_date_match = false; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Return whether the fact is dated. |
|
| 47 | + * |
|
| 48 | + * @return bool |
|
| 49 | + */ |
|
| 50 | + public function factHasDate(): bool |
|
| 51 | + { |
|
| 52 | + return $this->has_date; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Set whether the fact is dated. |
|
| 57 | + * |
|
| 58 | + * @param bool $has_date |
|
| 59 | + * @return $this |
|
| 60 | + */ |
|
| 61 | + public function setFactHasDate(bool $has_date): self |
|
| 62 | + { |
|
| 63 | + $this->has_date = $has_date; |
|
| 64 | + return $this; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Combinate whether the fact is dated with the previous status. |
|
| 69 | + * |
|
| 70 | + * @param bool $has_date |
|
| 71 | + * @return $this |
|
| 72 | + */ |
|
| 73 | + public function addFactHasDate(bool $has_date): self |
|
| 74 | + { |
|
| 75 | + $this->has_date = $this->has_date || $has_date; |
|
| 76 | + return $this; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Return whether the fact is dated with a precise day. |
|
| 81 | + * Any date modifier will be considered as not precise. |
|
| 82 | + * A month or year will be considered as not precise. |
|
| 83 | + * |
|
| 84 | + * @return bool |
|
| 85 | + */ |
|
| 86 | + public function factHasPreciseDate(): bool |
|
| 87 | + { |
|
| 88 | + return $this->has_date && $this->has_precise_date; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Set whather the fact is dated with a precise day. |
|
| 93 | + * |
|
| 94 | + * @param bool $has_precise_date |
|
| 95 | + * @return $this |
|
| 96 | + */ |
|
| 97 | + public function setFactHasPreciseDate(bool $has_precise_date): self |
|
| 98 | + { |
|
| 99 | + $this->has_precise_date = $has_precise_date; |
|
| 100 | + return $this; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Combine whether the fact is dated with a precise day. |
|
| 105 | + * |
|
| 106 | + * @param bool $has_precise_date |
|
| 107 | + * @return $this |
|
| 108 | + */ |
|
| 109 | + public function addFactHasPreciseDate(bool $has_precise_date): self |
|
| 110 | + { |
|
| 111 | + $this->has_precise_date = $this->has_precise_date || $has_precise_date; |
|
| 112 | + return $this; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Return whether the source citation is dated. |
|
| 117 | + * |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public function sourceHasDate(): bool |
|
| 121 | + { |
|
| 122 | + return $this->has_source_date; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Set whether the source citation is dated. |
|
| 127 | + * |
|
| 128 | + * @param bool $has_source_date |
|
| 129 | + * @return $this |
|
| 130 | + */ |
|
| 131 | + public function setSourceHasDate(bool $has_source_date): self |
|
| 132 | + { |
|
| 133 | + $this->has_source_date = $has_source_date; |
|
| 134 | + return $this; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Combine whether the source citation is dated with the previous status. |
|
| 139 | + * |
|
| 140 | + * @param bool $has_source_date |
|
| 141 | + * @return $this |
|
| 142 | + */ |
|
| 143 | + public function addSourceHasDate(bool $has_source_date): self |
|
| 144 | + { |
|
| 145 | + $this->has_source_date = $this->has_source_date || $has_source_date; |
|
| 146 | + return $this; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Return whether the source citation date is close to the fact date. |
|
| 151 | + * |
|
| 152 | + * @return bool |
|
| 153 | + */ |
|
| 154 | + public function sourceMatchesFactDate(): bool |
|
| 155 | + { |
|
| 156 | + return $this->has_precise_date && $this->has_source_date && $this->source_date_match; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Set whether the source citation date is close to the fact date. |
|
| 161 | + * |
|
| 162 | + * @param bool $source_date_match |
|
| 163 | + * @return $this |
|
| 164 | + */ |
|
| 165 | + public function setSourceMatchesFactDate(bool $source_date_match): self |
|
| 166 | + { |
|
| 167 | + $this->source_date_match = $source_date_match; |
|
| 168 | + return $this; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Combine whether the source citation date is close to the fact date with the previous status. |
|
| 173 | + * |
|
| 174 | + * @param bool $source_date_match |
|
| 175 | + * @return $this |
|
| 176 | + */ |
|
| 177 | + public function addSourceMatchesFactDate(bool $source_date_match): self |
|
| 178 | + { |
|
| 179 | + $this->source_date_match = $this->source_date_match || $source_date_match; |
|
| 180 | + return $this; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * {@inheritDoc} |
|
| 185 | + * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isFullySourced() |
|
| 186 | + */ |
|
| 187 | + public function isFullySourced(): bool |
|
| 188 | + { |
|
| 189 | + return parent::isFullySourced() && $this->sourceMatchesFactDate(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * {@inheritDoc} |
|
| 194 | + * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::label() |
|
| 195 | + */ |
|
| 196 | + public function label(string $context): string |
|
| 197 | + { |
|
| 198 | + $context_label = Registry::elementFactory()->make($context)->label(); |
|
| 199 | + |
|
| 200 | + if ($this->factHasPreciseDate()) { |
|
| 201 | + if ($this->hasSource()) { |
|
| 202 | + if ($this->hasSupportingDocument()) { |
|
| 203 | + if ($this->sourceMatchesFactDate()) { |
|
| 204 | + return I18N::translate('%s sourced with exact certificate', $context_label); |
|
| 205 | + } else { |
|
| 206 | + return I18N::translate('%s sourced with a certificate', $context_label); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if ($this->sourceMatchesFactDate()) { |
|
| 211 | + return I18N::translate('%s precisely sourced', $context_label); |
|
| 212 | + } |
|
| 213 | + return I18N::translate('%s sourced', $context_label); |
|
| 214 | + } |
|
| 215 | + return I18N::translate('%s not sourced', $context_label); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if ($this->factHasDate()) { |
|
| 219 | + return I18N::translate('%s not precise', $context_label); |
|
| 220 | + } |
|
| 221 | + return I18N::translate('%s not found', $context_label); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * {@inheritDoc} |
|
| 226 | + * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::order() |
|
| 227 | + */ |
|
| 228 | + public function order(): int |
|
| 229 | + { |
|
| 230 | + return ($this->factHasDate() ? 1 : 0) * ($this->hasSource() ? 1 : -1) * |
|
| 231 | + ( 1 + ($this->factHasPreciseDate() ? 1 : 0) * (1 + |
|
| 232 | + 0b010 * ($this->sourceMatchesFactDate() ? 1 : 0) + |
|
| 233 | + 0b100 * ($this->hasSupportingDocument() ? 1 : 0) |
|
| 234 | + ) |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * {@inheritDoc} |
|
| 240 | + * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::combineWith() |
|
| 241 | + */ |
|
| 242 | + public function combineWith(SourceStatus $other) |
|
| 243 | + { |
|
| 244 | + if ($other instanceof FactSourceStatus) { |
|
| 245 | + $this->addFactHasDate($other->factHasDate()); |
|
| 246 | + $this->addFactHasPreciseDate($other->factHasPreciseDate()); |
|
| 247 | + $this->addSourceHasDate($other->sourceHasDate()); |
|
| 248 | + $this->addSourceMatchesFactDate($other->sourceMatchesFactDate()); |
|
| 249 | + } |
|
| 250 | + return parent::combineWith($other); |
|
| 251 | + } |
|
| 252 | 252 | } |
@@ -19,21 +19,21 @@ |
||
| 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) |
|
| 36 | - { |
|
| 37 | - return $other; |
|
| 38 | - } |
|
| 31 | + /** |
|
| 32 | + * {@inheritDoc} |
|
| 33 | + * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\FactSourceStatus::combineWith() |
|
| 34 | + */ |
|
| 35 | + public function combineWith(SourceStatus $other) |
|
| 36 | + { |
|
| 37 | + return $other; |
|
| 38 | + } |
|
| 39 | 39 | } |