133c34396SGreg Roach<?php 233c34396SGreg Roach/** 333c34396SGreg Roach * webtrees: online genealogy 433c34396SGreg Roach * Copyright (C) 2019 webtrees development team 533c34396SGreg Roach * This program is free software: you can redistribute it and/or modify 633c34396SGreg Roach * it under the terms of the GNU General Public License as published by 733c34396SGreg Roach * the Free Software Foundation, either version 3 of the License, or 833c34396SGreg Roach * (at your option) any later version. 933c34396SGreg Roach * This program is distributed in the hope that it will be useful, 1033c34396SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1133c34396SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1233c34396SGreg Roach * GNU General Public License for more details. 1333c34396SGreg Roach * You should have received a copy of the GNU General Public License 1433c34396SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1533c34396SGreg Roach */ 1633c34396SGreg Roachdeclare(strict_types=1); 1733c34396SGreg Roach 1833c34396SGreg Roachnamespace Fisharebest\Webtrees\Module; 1933c34396SGreg Roach 2033c34396SGreg Roachuse Fisharebest\Webtrees\I18N; 2133c34396SGreg Roachuse Fisharebest\Webtrees\Tree; 2233c34396SGreg Roachuse Fisharebest\Webtrees\User; 2333c34396SGreg Roachuse Symfony\Component\HttpFoundation\Request; 2433c34396SGreg Roach 2533c34396SGreg Roach/** 2633c34396SGreg Roach * Class ContactsFooterModule - provide a link to the site owner. 2733c34396SGreg Roach */ 2833c34396SGreg Roachclass ContactsFooterModule extends AbstractModule implements ModuleFooterInterface 2933c34396SGreg Roach{ 3033c34396SGreg Roach use ModuleFooterTrait; 3133c34396SGreg Roach 3233c34396SGreg Roach /** @var Request */ 3333c34396SGreg Roach protected $request; 3433c34396SGreg Roach 3533c34396SGreg Roach /** @var Tree|null */ 3633c34396SGreg Roach protected $tree; 3733c34396SGreg Roach 3833c34396SGreg Roach /** @var User */ 3933c34396SGreg Roach protected $user; 4033c34396SGreg Roach 4133c34396SGreg Roach /** 42*d4c04956SGreg Roach * Dependency injection. 43*d4c04956SGreg Roach * 44*d4c04956SGreg Roach * @param Tree|null $tree 45*d4c04956SGreg Roach * @param User $user 46*d4c04956SGreg Roach * @param Request $request 47*d4c04956SGreg Roach */ 48*d4c04956SGreg Roach public function __construct(?Tree $tree, User $user, Request $request) 49*d4c04956SGreg Roach { 50*d4c04956SGreg Roach $this->tree = $tree; 51*d4c04956SGreg Roach $this->user = $user; 52*d4c04956SGreg Roach $this->request = $request; 53*d4c04956SGreg Roach } 54*d4c04956SGreg Roach 55*d4c04956SGreg Roach /** 5633c34396SGreg Roach * How should this module be labelled on tabs, footers, etc.? 5733c34396SGreg Roach * 5833c34396SGreg Roach * @return string 5933c34396SGreg Roach */ 6033c34396SGreg Roach public function title(): string 6133c34396SGreg Roach { 6233c34396SGreg Roach /* I18N: Name of a module */ 6333c34396SGreg Roach return I18N::translate('Contact information'); 6433c34396SGreg Roach } 6533c34396SGreg Roach 6633c34396SGreg Roach /** 6733c34396SGreg Roach * A sentence describing what this module does. 6833c34396SGreg Roach * 6933c34396SGreg Roach * @return string 7033c34396SGreg Roach */ 7133c34396SGreg Roach public function description(): string 7233c34396SGreg Roach { 7333c34396SGreg Roach /* I18N: Description of the “Hit counters” module */ 7433c34396SGreg Roach return I18N::translate('A link to the site contacts.'); 7533c34396SGreg Roach } 7633c34396SGreg Roach 7733c34396SGreg Roach /** 7833c34396SGreg Roach * The default position for this footer. It can be changed in the control panel. 7933c34396SGreg Roach * 8033c34396SGreg Roach * @return int 8133c34396SGreg Roach */ 8233c34396SGreg Roach public function defaultFooterOrder(): int 8333c34396SGreg Roach { 8433c34396SGreg Roach return 2; 8533c34396SGreg Roach } 8633c34396SGreg Roach 8733c34396SGreg Roach /** 8833c34396SGreg Roach * A footer, to be added at the bottom of every page. 8933c34396SGreg Roach * 9033c34396SGreg Roach * @return string 9133c34396SGreg Roach */ 9233c34396SGreg Roach public function getFooter(): string 9333c34396SGreg Roach { 9433c34396SGreg Roach if ($this->tree === null) { 9533c34396SGreg Roach return ''; 9633c34396SGreg Roach } 9733c34396SGreg Roach 9833c34396SGreg Roach $contact_user = User::find((int) $this->tree->getPreference('CONTACT_USER_ID')); 9933c34396SGreg Roach $webmaster_user = User::find((int) $this->tree->getPreference('WEBMASTER_USER_ID')); 10033c34396SGreg Roach 10133c34396SGreg Roach if ($contact_user instanceof User && $contact_user === $webmaster_user) { 10233c34396SGreg Roach return view('modules/contact-links/footer', [ 10333c34396SGreg Roach 'contact_links' => $this->contactLinkEverything($contact_user), 10433c34396SGreg Roach ]); 10533c34396SGreg Roach } 10633c34396SGreg Roach 10733c34396SGreg Roach if ($contact_user instanceof User && $webmaster_user instanceof User) { 10833c34396SGreg Roach return view('modules/contact-links/footer', [ 10933c34396SGreg Roach 'contact_links' => $this->contactLinkGenealogy($contact_user) . '<br>' . $this->contactLinkTechnical($webmaster_user), 11033c34396SGreg Roach ]); 11133c34396SGreg Roach } 11233c34396SGreg Roach 11333c34396SGreg Roach if ($contact_user instanceof User) { 11433c34396SGreg Roach return view('modules/contact-links/footer', [ 11533c34396SGreg Roach 'contact_links' => $this->contactLinkGenealogy($contact_user), 11633c34396SGreg Roach ]); 11733c34396SGreg Roach } 11833c34396SGreg Roach 11933c34396SGreg Roach if ($webmaster_user instanceof User) { 12033c34396SGreg Roach return view('modules/contact-links/footer', [ 12197350b3fSGreg Roach 'contact_links' => $this->contactLinkTechnical($webmaster_user), 12233c34396SGreg Roach ]); 12333c34396SGreg Roach } 12433c34396SGreg Roach 12533c34396SGreg Roach return ''; 12633c34396SGreg Roach } 12733c34396SGreg Roach 12833c34396SGreg Roach /** 12933c34396SGreg Roach * Create contact link for both technical and genealogy support. 13033c34396SGreg Roach * 13133c34396SGreg Roach * @param User $user 13233c34396SGreg Roach * 13333c34396SGreg Roach * @return string 13433c34396SGreg Roach */ 13533c34396SGreg Roach public function contactLinkEverything(User $user): string 13633c34396SGreg Roach { 13733c34396SGreg Roach return I18N::translate('For technical support or genealogy questions contact %s.', $this->contactLink($user)); 13833c34396SGreg Roach } 13933c34396SGreg Roach 14033c34396SGreg Roach /** 14133c34396SGreg Roach * Create contact link for genealogy support. 14233c34396SGreg Roach * 14333c34396SGreg Roach * @param User $user 14433c34396SGreg Roach * 14533c34396SGreg Roach * @return string 14633c34396SGreg Roach */ 14733c34396SGreg Roach public function contactLinkGenealogy(User $user): string 14833c34396SGreg Roach { 14933c34396SGreg Roach return I18N::translate('For help with genealogy questions contact %s.', $this->contactLink($user)); 15033c34396SGreg Roach } 15133c34396SGreg Roach 15233c34396SGreg Roach /** 15333c34396SGreg Roach * Create contact link for technical support. 15433c34396SGreg Roach * 15533c34396SGreg Roach * @param User $user 15633c34396SGreg Roach * 15733c34396SGreg Roach * @return string 15833c34396SGreg Roach */ 15933c34396SGreg Roach public function contactLinkTechnical(User $user): string 16033c34396SGreg Roach { 16133c34396SGreg Roach return I18N::translate('For technical support and information contact %s.', $this->contactLink($user)); 16233c34396SGreg Roach } 16333c34396SGreg Roach 16433c34396SGreg Roach /** 16533c34396SGreg Roach * Create a contact link for a user. 16633c34396SGreg Roach * 16733c34396SGreg Roach * @param User $user 16833c34396SGreg Roach * 16933c34396SGreg Roach * @return string 17033c34396SGreg Roach */ 17133c34396SGreg Roach private function contactLink(User $user): string 17233c34396SGreg Roach { 1731b7696b4SGreg Roach return view('modules/contact-links/contact', [ 1741b7696b4SGreg Roach 'request' => $this->request, 1751b7696b4SGreg Roach 'user' => $user, 1761b7696b4SGreg Roach 'tree' => $this->tree, 17733c34396SGreg Roach ]); 17833c34396SGreg Roach } 17933c34396SGreg Roach} 180