1b3a775f6SGreg Roach<?php 2b3a775f6SGreg Roach 3b3a775f6SGreg Roach/** 4b3a775f6SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6b3a775f6SGreg Roach * This program is free software: you can redistribute it and/or modify 7b3a775f6SGreg Roach * it under the terms of the GNU General Public License as published by 8b3a775f6SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9b3a775f6SGreg Roach * (at your option) any later version. 10b3a775f6SGreg Roach * This program is distributed in the hope that it will be useful, 11b3a775f6SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12b3a775f6SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13b3a775f6SGreg Roach * GNU General Public License for more details. 14b3a775f6SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16b3a775f6SGreg Roach */ 17b3a775f6SGreg Roach 18b3a775f6SGreg Roachdeclare(strict_types=1); 19b3a775f6SGreg Roach 20b3a775f6SGreg Roachnamespace Fisharebest\Webtrees\Module; 21b3a775f6SGreg Roach 22b3a775f6SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 23b3a775f6SGreg Roachuse Fisharebest\Webtrees\I18N; 24b3a775f6SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 25b3a775f6SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 26b3a775f6SGreg Roachuse Fisharebest\Webtrees\Tree; 27b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 28b3a775f6SGreg Roachuse Illuminate\Support\Collection; 29b3a775f6SGreg Roachuse Psr\Http\Message\ResponseInterface; 30b3a775f6SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 31b3a775f6SGreg Roach 32b3a775f6SGreg Roachuse function view; 33b3a775f6SGreg Roach 34b3a775f6SGreg Roach/** 35b3a775f6SGreg Roach * Class PrivacyPolicy - to comply with the GDPR and similar local laws. 36b3a775f6SGreg Roach */ 37b3a775f6SGreg Roachclass PrivacyPolicy extends AbstractModule implements ModuleFooterInterface 38b3a775f6SGreg Roach{ 39b3a775f6SGreg Roach use ModuleFooterTrait; 40b3a775f6SGreg Roach 4143f2f523SGreg Roach private ModuleService $module_service; 42b3a775f6SGreg Roach 4343f2f523SGreg Roach private UserService $user_service; 44b3a775f6SGreg Roach 45b3a775f6SGreg Roach /** 46b3a775f6SGreg Roach * Dependency injection. 47b3a775f6SGreg Roach * 48b3a775f6SGreg Roach * @param ModuleService $module_service 49b3a775f6SGreg Roach * @param UserService $user_service 50b3a775f6SGreg Roach */ 51b3a775f6SGreg Roach public function __construct(ModuleService $module_service, UserService $user_service) 52b3a775f6SGreg Roach { 53b3a775f6SGreg Roach $this->module_service = $module_service; 54b3a775f6SGreg Roach $this->user_service = $user_service; 55b3a775f6SGreg Roach } 56b3a775f6SGreg Roach 57b3a775f6SGreg Roach /** 58b3a775f6SGreg Roach * How should this module be labelled on tabs, footers, etc.? 59b3a775f6SGreg Roach * 60b3a775f6SGreg Roach * @return string 61b3a775f6SGreg Roach */ 62b3a775f6SGreg Roach public function title(): string 63b3a775f6SGreg Roach { 64b3a775f6SGreg Roach /* I18N: Name of a module */ 65b3a775f6SGreg Roach return I18N::translate('Privacy policy'); 66b3a775f6SGreg Roach } 67b3a775f6SGreg Roach 68b3a775f6SGreg Roach public function description(): string 69b3a775f6SGreg Roach { 70b3a775f6SGreg Roach /* I18N: Description of the “Cookie warning” module */ 71b3a775f6SGreg Roach return I18N::translate('Show a privacy policy.'); 72b3a775f6SGreg Roach } 73b3a775f6SGreg Roach 74b3a775f6SGreg Roach /** 75b3a775f6SGreg Roach * The default position for this footer. It can be changed in the control panel. 76b3a775f6SGreg Roach * 77b3a775f6SGreg Roach * @return int 78b3a775f6SGreg Roach */ 79b3a775f6SGreg Roach public function defaultFooterOrder(): int 80b3a775f6SGreg Roach { 81b3a775f6SGreg Roach return 4; 82b3a775f6SGreg Roach } 83b3a775f6SGreg Roach 84b3a775f6SGreg Roach /** 85b3a775f6SGreg Roach * A footer, to be added at the bottom of every page. 86b3a775f6SGreg Roach * 87b3a775f6SGreg Roach * @param ServerRequestInterface $request 88b3a775f6SGreg Roach * 89b3a775f6SGreg Roach * @return string 90b3a775f6SGreg Roach */ 91b3a775f6SGreg Roach public function getFooter(ServerRequestInterface $request): string 92b3a775f6SGreg Roach { 93b55cbc6bSGreg Roach $tree = Validator::attributes($request)->treeOptional(); 94b55cbc6bSGreg Roach $user = Validator::attributes($request)->user(); 95b3a775f6SGreg Roach 96b3a775f6SGreg Roach if ($tree === null) { 97b3a775f6SGreg Roach return ''; 98b3a775f6SGreg Roach } 99b3a775f6SGreg Roach 100b3a775f6SGreg Roach return view('modules/privacy-policy/footer', [ 101b3a775f6SGreg Roach 'tree' => $tree, 102b3a775f6SGreg Roach 'uses_analytics' => $this->analyticsModules($tree, $user)->isNotEmpty(), 103b3a775f6SGreg Roach ]); 104b3a775f6SGreg Roach } 105b3a775f6SGreg Roach 106b3a775f6SGreg Roach /** 107b3a775f6SGreg Roach * @param ServerRequestInterface $request 108b3a775f6SGreg Roach * 109b3a775f6SGreg Roach * @return ResponseInterface 110b3a775f6SGreg Roach */ 111b3a775f6SGreg Roach public function getPageAction(ServerRequestInterface $request): ResponseInterface 112b3a775f6SGreg Roach { 113b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 114b55cbc6bSGreg Roach $user = Validator::attributes($request)->user(); 115b3a775f6SGreg Roach 116b3a775f6SGreg Roach $title = I18N::translate('Privacy policy'); 117b3a775f6SGreg Roach 118b3a775f6SGreg Roach return $this->viewResponse('modules/privacy-policy/page', [ 119b3a775f6SGreg Roach 'administrators' => $this->user_service->administrators(), 120b3a775f6SGreg Roach 'analytics' => $this->analyticsModules($tree, $user), 121b3a775f6SGreg Roach 'title' => $title, 122b3a775f6SGreg Roach 'tree' => $tree, 123b3a775f6SGreg Roach ]); 124b3a775f6SGreg Roach } 125b3a775f6SGreg Roach 126b3a775f6SGreg Roach /** 127b3a775f6SGreg Roach * @param Tree $tree 128b3a775f6SGreg Roach * @param UserInterface $user 129b3a775f6SGreg Roach * 13036779af1SGreg Roach * @return Collection<int,ModuleAnalyticsInterface> 131b3a775f6SGreg Roach */ 132b3a775f6SGreg Roach protected function analyticsModules(Tree $tree, UserInterface $user): Collection 133b3a775f6SGreg Roach { 134b3a775f6SGreg Roach return $this->module_service 135b3a775f6SGreg Roach ->findByComponent(ModuleAnalyticsInterface::class, $tree, $user) 136*f25fc0f9SGreg Roach ->filter(static fn (ModuleAnalyticsInterface $module): bool => $module->isTracker()); 137b3a775f6SGreg Roach } 138b3a775f6SGreg Roach} 139