18add1155SRico Sonntag<?php 23976b470SGreg Roach 38add1155SRico Sonntag/** 48add1155SRico Sonntag * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 68add1155SRico Sonntag * This program is free software: you can redistribute it and/or modify 78add1155SRico Sonntag * it under the terms of the GNU General Public License as published by 88add1155SRico Sonntag * the Free Software Foundation, either version 3 of the License, or 98add1155SRico Sonntag * (at your option) any later version. 108add1155SRico Sonntag * This program is distributed in the hope that it will be useful, 118add1155SRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of 128add1155SRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138add1155SRico Sonntag * GNU General Public License for more details. 148add1155SRico Sonntag * 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/>. 168add1155SRico Sonntag */ 17fcfa147eSGreg Roach 188add1155SRico Sonntagdeclare(strict_types=1); 198add1155SRico Sonntag 208add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Repository; 218add1155SRico Sonntag 22*d35568b4SGreg Roachuse Fisharebest\Webtrees\Registry; 23e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 248add1155SRico Sonntaguse Fisharebest\Webtrees\Statistics\Repository\Interfaces\ContactRepositoryInterface; 258add1155SRico Sonntaguse Fisharebest\Webtrees\Tree; 268add1155SRico Sonntaguse Fisharebest\Webtrees\User; 27a992e8c1SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 28a992e8c1SGreg Roach 298add1155SRico Sonntag/** 308add1155SRico Sonntag * A repository providing methods for contact related statistics. 318add1155SRico Sonntag */ 328add1155SRico Sonntagclass ContactRepository implements ContactRepositoryInterface 338add1155SRico Sonntag{ 344c78e066SGreg Roach private Tree $tree; 354c78e066SGreg Roach 364c78e066SGreg Roach private UserService $user_service; 378add1155SRico Sonntag 388add1155SRico Sonntag /** 398add1155SRico Sonntag * @param Tree $tree 40e5a6b4d4SGreg Roach * @param UserService $user_service 418add1155SRico Sonntag */ 42e5a6b4d4SGreg Roach public function __construct(Tree $tree, UserService $user_service) 438add1155SRico Sonntag { 448add1155SRico Sonntag $this->tree = $tree; 45e5a6b4d4SGreg Roach $this->user_service = $user_service; 468add1155SRico Sonntag } 478add1155SRico Sonntag 488add1155SRico Sonntag /** 490dcd9387SGreg Roach * @return string 508add1155SRico Sonntag */ 518add1155SRico Sonntag public function contactWebmaster(): string 528add1155SRico Sonntag { 5386730b84SGreg Roach $user_id = (int) $this->tree->getPreference('WEBMASTER_USER_ID'); 5486730b84SGreg Roach $user = $this->user_service->find($user_id); 558add1155SRico Sonntag 568add1155SRico Sonntag if ($user instanceof User) { 57*d35568b4SGreg Roach $request = Registry::container()->get(ServerRequestInterface::class); 58a992e8c1SGreg Roach 59a992e8c1SGreg Roach return $this->user_service->contactLink($user, $request); 608add1155SRico Sonntag } 618add1155SRico Sonntag 628add1155SRico Sonntag return ''; 638add1155SRico Sonntag } 648add1155SRico Sonntag 658add1155SRico Sonntag /** 660dcd9387SGreg Roach * @return string 678add1155SRico Sonntag */ 688add1155SRico Sonntag public function contactGedcom(): string 698add1155SRico Sonntag { 7086730b84SGreg Roach $user_id = (int) $this->tree->getPreference('CONTACT_USER_ID'); 7186730b84SGreg Roach $user = $this->user_service->find($user_id); 728add1155SRico Sonntag 738add1155SRico Sonntag if ($user instanceof User) { 74*d35568b4SGreg Roach $request = Registry::container()->get(ServerRequestInterface::class); 75a992e8c1SGreg Roach 76a992e8c1SGreg Roach return $this->user_service->contactLink($user, $request); 778add1155SRico Sonntag } 788add1155SRico Sonntag 798add1155SRico Sonntag return ''; 808add1155SRico Sonntag } 818add1155SRico Sonntag} 82