133c34396SGreg Roach<?php 23976b470SGreg Roach 333c34396SGreg Roach/** 433c34396SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 633c34396SGreg Roach * This program is free software: you can redistribute it and/or modify 733c34396SGreg Roach * it under the terms of the GNU General Public License as published by 833c34396SGreg Roach * the Free Software Foundation, either version 3 of the License, or 933c34396SGreg Roach * (at your option) any later version. 1033c34396SGreg Roach * This program is distributed in the hope that it will be useful, 1133c34396SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1233c34396SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1333c34396SGreg Roach * GNU General Public License for more details. 1433c34396SGreg 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/>. 1633c34396SGreg Roach */ 17fcfa147eSGreg Roach 1833c34396SGreg Roachdeclare(strict_types=1); 1933c34396SGreg Roach 2033c34396SGreg Roachnamespace Fisharebest\Webtrees\Module; 2133c34396SGreg Roach 2233c34396SGreg Roachuse Fisharebest\Webtrees\I18N; 23e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 2433c34396SGreg Roachuse Fisharebest\Webtrees\User; 25b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 26a992e8c1SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 2733c34396SGreg Roach 2833c34396SGreg Roach/** 2933c34396SGreg Roach * Class ContactsFooterModule - provide a link to the site owner. 3033c34396SGreg Roach */ 3133c34396SGreg Roachclass ContactsFooterModule extends AbstractModule implements ModuleFooterInterface 3233c34396SGreg Roach{ 3333c34396SGreg Roach use ModuleFooterTrait; 3433c34396SGreg Roach 3543f2f523SGreg Roach private UserService $user_service; 36e5a6b4d4SGreg Roach 37e5a6b4d4SGreg Roach /** 38d4c04956SGreg Roach * Dependency injection. 39d4c04956SGreg Roach * 40e5a6b4d4SGreg Roach * @param UserService $user_service 41d4c04956SGreg Roach */ 426ccdf4f0SGreg Roach public function __construct(UserService $user_service) 43d4c04956SGreg Roach { 44e5a6b4d4SGreg Roach $this->user_service = $user_service; 45d4c04956SGreg Roach } 46d4c04956SGreg Roach 47d4c04956SGreg Roach /** 4833c34396SGreg Roach * How should this module be labelled on tabs, footers, etc.? 4933c34396SGreg Roach * 5033c34396SGreg Roach * @return string 5133c34396SGreg Roach */ 5233c34396SGreg Roach public function title(): string 5333c34396SGreg Roach { 5433c34396SGreg Roach /* I18N: Name of a module */ 5533c34396SGreg Roach return I18N::translate('Contact information'); 5633c34396SGreg Roach } 5733c34396SGreg Roach 5833c34396SGreg Roach public function description(): string 5933c34396SGreg Roach { 60b5e8e56bSGreg Roach /* I18N: Description of the “Contact information” module */ 6133c34396SGreg Roach return I18N::translate('A link to the site contacts.'); 6233c34396SGreg Roach } 6333c34396SGreg Roach 6433c34396SGreg Roach /** 6533c34396SGreg Roach * The default position for this footer. It can be changed in the control panel. 6633c34396SGreg Roach * 6733c34396SGreg Roach * @return int 6833c34396SGreg Roach */ 6933c34396SGreg Roach public function defaultFooterOrder(): int 7033c34396SGreg Roach { 7133c34396SGreg Roach return 2; 7233c34396SGreg Roach } 7333c34396SGreg Roach 7433c34396SGreg Roach /** 7533c34396SGreg Roach * A footer, to be added at the bottom of every page. 7633c34396SGreg Roach * 77a992e8c1SGreg Roach * @param ServerRequestInterface $request 780c8c69d4SGreg Roach * 7933c34396SGreg Roach * @return string 8033c34396SGreg Roach */ 81a992e8c1SGreg Roach public function getFooter(ServerRequestInterface $request): string 8233c34396SGreg Roach { 83b55cbc6bSGreg Roach $tree = Validator::attributes($request)->treeOptional(); 84a992e8c1SGreg Roach 850c8c69d4SGreg Roach if ($tree === null) { 8633c34396SGreg Roach return ''; 8733c34396SGreg Roach } 8833c34396SGreg Roach 890c8c69d4SGreg Roach $contact_user = $this->user_service->find((int) $tree->getPreference('CONTACT_USER_ID')); 900c8c69d4SGreg Roach $webmaster_user = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); 9133c34396SGreg Roach 9233c34396SGreg Roach if ($contact_user instanceof User && $contact_user === $webmaster_user) { 9333c34396SGreg Roach return view('modules/contact-links/footer', [ 94a992e8c1SGreg Roach 'contact_links' => $this->contactLinkEverything($contact_user, $request), 9533c34396SGreg Roach ]); 9633c34396SGreg Roach } 9733c34396SGreg Roach 9833c34396SGreg Roach if ($contact_user instanceof User && $webmaster_user instanceof User) { 9933c34396SGreg Roach return view('modules/contact-links/footer', [ 100a992e8c1SGreg Roach 'contact_links' => $this->contactLinkGenealogy($contact_user, $request) . '<br>' . $this->contactLinkTechnical($webmaster_user, $request), 10133c34396SGreg Roach ]); 10233c34396SGreg Roach } 10333c34396SGreg Roach 10433c34396SGreg Roach if ($contact_user instanceof User) { 10533c34396SGreg Roach return view('modules/contact-links/footer', [ 106a992e8c1SGreg Roach 'contact_links' => $this->contactLinkGenealogy($contact_user, $request), 10733c34396SGreg Roach ]); 10833c34396SGreg Roach } 10933c34396SGreg Roach 11033c34396SGreg Roach if ($webmaster_user instanceof User) { 11133c34396SGreg Roach return view('modules/contact-links/footer', [ 112a992e8c1SGreg Roach 'contact_links' => $this->contactLinkTechnical($webmaster_user, $request), 11333c34396SGreg Roach ]); 11433c34396SGreg Roach } 11533c34396SGreg Roach 11633c34396SGreg Roach return ''; 11733c34396SGreg Roach } 11833c34396SGreg Roach 11933c34396SGreg Roach /** 12033c34396SGreg Roach * Create contact link for both technical and genealogy support. 12133c34396SGreg Roach * 12286730b84SGreg Roach * @param User $user 123a992e8c1SGreg Roach * @param ServerRequestInterface $request 12433c34396SGreg Roach * 12533c34396SGreg Roach * @return string 12633c34396SGreg Roach */ 127a992e8c1SGreg Roach public function contactLinkEverything(User $user, ServerRequestInterface $request): string 12833c34396SGreg Roach { 129a992e8c1SGreg Roach return I18N::translate('For technical support or genealogy questions contact %s.', $this->user_service->contactLink($user, $request)); 13033c34396SGreg Roach } 13133c34396SGreg Roach 13233c34396SGreg Roach /** 13333c34396SGreg Roach * Create contact link for genealogy support. 13433c34396SGreg Roach * 13586730b84SGreg Roach * @param User $user 136a992e8c1SGreg Roach * @param ServerRequestInterface $request 13733c34396SGreg Roach * 13833c34396SGreg Roach * @return string 13933c34396SGreg Roach */ 140a992e8c1SGreg Roach public function contactLinkGenealogy(User $user, ServerRequestInterface $request): string 14133c34396SGreg Roach { 142a992e8c1SGreg Roach return I18N::translate('For help with genealogy questions contact %s.', $this->user_service->contactLink($user, $request)); 14333c34396SGreg Roach } 14433c34396SGreg Roach 14533c34396SGreg Roach /** 14633c34396SGreg Roach * Create contact link for technical support. 14733c34396SGreg Roach * 14886730b84SGreg Roach * @param User $user 149a992e8c1SGreg Roach * @param ServerRequestInterface $request 15033c34396SGreg Roach * 15133c34396SGreg Roach * @return string 15233c34396SGreg Roach */ 153a992e8c1SGreg Roach public function contactLinkTechnical(User $user, ServerRequestInterface $request): string 15433c34396SGreg Roach { 155a992e8c1SGreg Roach return I18N::translate('For technical support and information contact %s.', $this->user_service->contactLink($user, $request)); 15633c34396SGreg Roach } 15733c34396SGreg Roach} 158