1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Module; 19 20use Fisharebest\Webtrees\I18N; 21use Fisharebest\Webtrees\Services\UserService; 22use Fisharebest\Webtrees\Tree; 23use Fisharebest\Webtrees\User; 24use Symfony\Component\HttpFoundation\Request; 25 26/** 27 * Class ContactsFooterModule - provide a link to the site owner. 28 */ 29class ContactsFooterModule extends AbstractModule implements ModuleFooterInterface 30{ 31 use ModuleFooterTrait; 32 33 /** @var Request */ 34 protected $request; 35 36 /** 37 * @var UserService 38 */ 39 private $user_service; 40 41 /** 42 * Dependency injection. 43 * 44 * @param Request $request 45 * @param UserService $user_service 46 */ 47 public function __construct(Request $request, UserService $user_service) 48 { 49 $this->request = $request; 50 $this->user_service = $user_service; 51 } 52 53 /** 54 * How should this module be labelled on tabs, footers, etc.? 55 * 56 * @return string 57 */ 58 public function title(): string 59 { 60 /* I18N: Name of a module */ 61 return I18N::translate('Contact information'); 62 } 63 64 /** 65 * A sentence describing what this module does. 66 * 67 * @return string 68 */ 69 public function description(): string 70 { 71 /* I18N: Description of the “Hit counters” module */ 72 return I18N::translate('A link to the site contacts.'); 73 } 74 75 /** 76 * The default position for this footer. It can be changed in the control panel. 77 * 78 * @return int 79 */ 80 public function defaultFooterOrder(): int 81 { 82 return 2; 83 } 84 85 /** 86 * A footer, to be added at the bottom of every page. 87 * 88 * @param Tree|null $tree 89 * 90 * @return string 91 */ 92 public function getFooter(?Tree $tree): string 93 { 94 if ($tree === null) { 95 return ''; 96 } 97 98 $contact_user = $this->user_service->find((int) $tree->getPreference('CONTACT_USER_ID')); 99 $webmaster_user = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); 100 101 if ($contact_user instanceof User && $contact_user === $webmaster_user) { 102 return view('modules/contact-links/footer', [ 103 'contact_links' => $this->contactLinkEverything($contact_user), 104 ]); 105 } 106 107 if ($contact_user instanceof User && $webmaster_user instanceof User) { 108 return view('modules/contact-links/footer', [ 109 'contact_links' => $this->contactLinkGenealogy($contact_user) . '<br>' . $this->contactLinkTechnical($webmaster_user), 110 ]); 111 } 112 113 if ($contact_user instanceof User) { 114 return view('modules/contact-links/footer', [ 115 'contact_links' => $this->contactLinkGenealogy($contact_user), 116 ]); 117 } 118 119 if ($webmaster_user instanceof User) { 120 return view('modules/contact-links/footer', [ 121 'contact_links' => $this->contactLinkTechnical($webmaster_user), 122 ]); 123 } 124 125 return ''; 126 } 127 128 /** 129 * Create contact link for both technical and genealogy support. 130 * 131 * @param User $user 132 * 133 * @return string 134 */ 135 public function contactLinkEverything(User $user): string 136 { 137 return I18N::translate('For technical support or genealogy questions contact %s.', $this->user_service->contactLink($user)); 138 } 139 140 /** 141 * Create contact link for genealogy support. 142 * 143 * @param User $user 144 * 145 * @return string 146 */ 147 public function contactLinkGenealogy(User $user): string 148 { 149 return I18N::translate('For help with genealogy questions contact %s.', $this->user_service->contactLink($user)); 150 } 151 152 /** 153 * Create contact link for technical support. 154 * 155 * @param User $user 156 * 157 * @return string 158 */ 159 public function contactLinkTechnical(User $user): string 160 { 161 return I18N::translate('For technical support and information contact %s.', $this->user_service->contactLink($user)); 162 } 163} 164