133c34396SGreg Roach<?php 23976b470SGreg Roach 333c34396SGreg Roach/** 433c34396SGreg Roach * webtrees: online genealogy 533c34396SGreg Roach * Copyright (C) 2019 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 1533c34396SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1633c34396SGreg Roach */ 17*fcfa147eSGreg 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; 25a992e8c1SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 2633c34396SGreg Roach 2733c34396SGreg Roach/** 2833c34396SGreg Roach * Class ContactsFooterModule - provide a link to the site owner. 2933c34396SGreg Roach */ 3033c34396SGreg Roachclass ContactsFooterModule extends AbstractModule implements ModuleFooterInterface 3133c34396SGreg Roach{ 3233c34396SGreg Roach use ModuleFooterTrait; 3333c34396SGreg Roach 3433c34396SGreg Roach /** 35e5a6b4d4SGreg Roach * @var UserService 36e5a6b4d4SGreg Roach */ 37e5a6b4d4SGreg Roach private $user_service; 38e5a6b4d4SGreg Roach 39e5a6b4d4SGreg Roach /** 40d4c04956SGreg Roach * Dependency injection. 41d4c04956SGreg Roach * 42e5a6b4d4SGreg Roach * @param UserService $user_service 43d4c04956SGreg Roach */ 446ccdf4f0SGreg Roach public function __construct(UserService $user_service) 45d4c04956SGreg Roach { 46e5a6b4d4SGreg Roach $this->user_service = $user_service; 47d4c04956SGreg Roach } 48d4c04956SGreg Roach 49d4c04956SGreg Roach /** 5033c34396SGreg Roach * How should this module be labelled on tabs, footers, etc.? 5133c34396SGreg Roach * 5233c34396SGreg Roach * @return string 5333c34396SGreg Roach */ 5433c34396SGreg Roach public function title(): string 5533c34396SGreg Roach { 5633c34396SGreg Roach /* I18N: Name of a module */ 5733c34396SGreg Roach return I18N::translate('Contact information'); 5833c34396SGreg Roach } 5933c34396SGreg Roach 6033c34396SGreg Roach /** 6133c34396SGreg Roach * A sentence describing what this module does. 6233c34396SGreg Roach * 6333c34396SGreg Roach * @return string 6433c34396SGreg Roach */ 6533c34396SGreg Roach public function description(): string 6633c34396SGreg Roach { 6733c34396SGreg Roach /* I18N: Description of the “Hit counters” module */ 6833c34396SGreg Roach return I18N::translate('A link to the site contacts.'); 6933c34396SGreg Roach } 7033c34396SGreg Roach 7133c34396SGreg Roach /** 7233c34396SGreg Roach * The default position for this footer. It can be changed in the control panel. 7333c34396SGreg Roach * 7433c34396SGreg Roach * @return int 7533c34396SGreg Roach */ 7633c34396SGreg Roach public function defaultFooterOrder(): int 7733c34396SGreg Roach { 7833c34396SGreg Roach return 2; 7933c34396SGreg Roach } 8033c34396SGreg Roach 8133c34396SGreg Roach /** 8233c34396SGreg Roach * A footer, to be added at the bottom of every page. 8333c34396SGreg Roach * 84a992e8c1SGreg Roach * @param ServerRequestInterface $request 850c8c69d4SGreg Roach * 8633c34396SGreg Roach * @return string 8733c34396SGreg Roach */ 88a992e8c1SGreg Roach public function getFooter(ServerRequestInterface $request): string 8933c34396SGreg Roach { 90a992e8c1SGreg Roach $tree = $request->getAttribute('tree'); 91a992e8c1SGreg Roach 920c8c69d4SGreg Roach if ($tree === null) { 9333c34396SGreg Roach return ''; 9433c34396SGreg Roach } 9533c34396SGreg Roach 960c8c69d4SGreg Roach $contact_user = $this->user_service->find((int) $tree->getPreference('CONTACT_USER_ID')); 970c8c69d4SGreg Roach $webmaster_user = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); 9833c34396SGreg Roach 9933c34396SGreg Roach if ($contact_user instanceof User && $contact_user === $webmaster_user) { 10033c34396SGreg Roach return view('modules/contact-links/footer', [ 101a992e8c1SGreg Roach 'contact_links' => $this->contactLinkEverything($contact_user, $request), 10233c34396SGreg Roach ]); 10333c34396SGreg Roach } 10433c34396SGreg Roach 10533c34396SGreg Roach if ($contact_user instanceof User && $webmaster_user instanceof User) { 10633c34396SGreg Roach return view('modules/contact-links/footer', [ 107a992e8c1SGreg Roach 'contact_links' => $this->contactLinkGenealogy($contact_user, $request) . '<br>' . $this->contactLinkTechnical($webmaster_user, $request), 10833c34396SGreg Roach ]); 10933c34396SGreg Roach } 11033c34396SGreg Roach 11133c34396SGreg Roach if ($contact_user instanceof User) { 11233c34396SGreg Roach return view('modules/contact-links/footer', [ 113a992e8c1SGreg Roach 'contact_links' => $this->contactLinkGenealogy($contact_user, $request), 11433c34396SGreg Roach ]); 11533c34396SGreg Roach } 11633c34396SGreg Roach 11733c34396SGreg Roach if ($webmaster_user instanceof User) { 11833c34396SGreg Roach return view('modules/contact-links/footer', [ 119a992e8c1SGreg Roach 'contact_links' => $this->contactLinkTechnical($webmaster_user, $request), 12033c34396SGreg Roach ]); 12133c34396SGreg Roach } 12233c34396SGreg Roach 12333c34396SGreg Roach return ''; 12433c34396SGreg Roach } 12533c34396SGreg Roach 12633c34396SGreg Roach /** 12733c34396SGreg Roach * Create contact link for both technical and genealogy support. 12833c34396SGreg Roach * 12986730b84SGreg Roach * @param User $user 130a992e8c1SGreg Roach * @param ServerRequestInterface $request 13133c34396SGreg Roach * 13233c34396SGreg Roach * @return string 13333c34396SGreg Roach */ 134a992e8c1SGreg Roach public function contactLinkEverything(User $user, ServerRequestInterface $request): string 13533c34396SGreg Roach { 136a992e8c1SGreg Roach return I18N::translate('For technical support or genealogy questions contact %s.', $this->user_service->contactLink($user, $request)); 13733c34396SGreg Roach } 13833c34396SGreg Roach 13933c34396SGreg Roach /** 14033c34396SGreg Roach * Create contact link for genealogy support. 14133c34396SGreg Roach * 14286730b84SGreg Roach * @param User $user 143a992e8c1SGreg Roach * @param ServerRequestInterface $request 14433c34396SGreg Roach * 14533c34396SGreg Roach * @return string 14633c34396SGreg Roach */ 147a992e8c1SGreg Roach public function contactLinkGenealogy(User $user, ServerRequestInterface $request): string 14833c34396SGreg Roach { 149a992e8c1SGreg Roach return I18N::translate('For help with genealogy questions contact %s.', $this->user_service->contactLink($user, $request)); 15033c34396SGreg Roach } 15133c34396SGreg Roach 15233c34396SGreg Roach /** 15333c34396SGreg Roach * Create contact link for technical support. 15433c34396SGreg Roach * 15586730b84SGreg Roach * @param User $user 156a992e8c1SGreg Roach * @param ServerRequestInterface $request 15733c34396SGreg Roach * 15833c34396SGreg Roach * @return string 15933c34396SGreg Roach */ 160a992e8c1SGreg Roach public function contactLinkTechnical(User $user, ServerRequestInterface $request): string 16133c34396SGreg Roach { 162a992e8c1SGreg Roach return I18N::translate('For technical support and information contact %s.', $this->user_service->contactLink($user, $request)); 16333c34396SGreg Roach } 16433c34396SGreg Roach} 165