1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17declare(strict_types=1); 18 19namespace Fisharebest\Webtrees\Statistics\Repository; 20 21use Fisharebest\Webtrees\Services\UserService; 22use Fisharebest\Webtrees\Statistics\Repository\Interfaces\ContactRepositoryInterface; 23use Fisharebest\Webtrees\Tree; 24use Fisharebest\Webtrees\User; 25use Psr\Http\Message\ServerRequestInterface; 26 27use function app; 28 29/** 30 * A repository providing methods for contact related statistics. 31 */ 32class ContactRepository implements ContactRepositoryInterface 33{ 34 /** 35 * @var Tree 36 */ 37 private $tree; 38 /** 39 * @var UserService 40 */ 41 private $user_service; 42 43 /** 44 * Constructor. 45 * 46 * @param Tree $tree 47 * @param UserService $user_service 48 */ 49 public function __construct(Tree $tree, UserService $user_service) 50 { 51 $this->tree = $tree; 52 $this->user_service = $user_service; 53 } 54 55 /** 56 * @inheritDoc 57 */ 58 public function contactWebmaster(): string 59 { 60 $user_id = (int) $this->tree->getPreference('WEBMASTER_USER_ID'); 61 $user = $this->user_service->find($user_id); 62 63 if ($user instanceof User) { 64 $request = app(ServerRequestInterface::class); 65 66 return $this->user_service->contactLink($user, $request); 67 } 68 69 return ''; 70 } 71 72 /** 73 * @inheritDoc 74 */ 75 public function contactGedcom(): string 76 { 77 $user_id = (int) $this->tree->getPreference('CONTACT_USER_ID'); 78 $user = $this->user_service->find($user_id); 79 80 if ($user instanceof User) { 81 $request = app(ServerRequestInterface::class); 82 83 return $this->user_service->contactLink($user, $request); 84 } 85 86 return ''; 87 } 88} 89