xref: /webtrees/app/Statistics/Repository/ContactRepository.php (revision 89f7189b61a494347591c99bdb92afb7d8b66e1b)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Statistics\Repository;
21
22use Fisharebest\Webtrees\Services\UserService;
23use Fisharebest\Webtrees\Statistics\Repository\Interfaces\ContactRepositoryInterface;
24use Fisharebest\Webtrees\Tree;
25use Fisharebest\Webtrees\User;
26use Psr\Http\Message\ServerRequestInterface;
27
28use function app;
29
30/**
31 * A repository providing methods for contact related statistics.
32 */
33class ContactRepository implements ContactRepositoryInterface
34{
35    /**
36     * @var Tree
37     */
38    private $tree;
39    /**
40     * @var UserService
41     */
42    private $user_service;
43
44    /**
45     * Constructor.
46     *
47     * @param Tree        $tree
48     * @param UserService $user_service
49     */
50    public function __construct(Tree $tree, UserService $user_service)
51    {
52        $this->tree         = $tree;
53        $this->user_service = $user_service;
54    }
55
56    /**
57     * @return string
58     */
59    public function contactWebmaster(): string
60    {
61        $user_id = (int) $this->tree->getPreference('WEBMASTER_USER_ID');
62        $user    = $this->user_service->find($user_id);
63
64        if ($user instanceof User) {
65            $request = app(ServerRequestInterface::class);
66
67            return $this->user_service->contactLink($user, $request);
68        }
69
70        return '';
71    }
72
73    /**
74     * @return string
75     */
76    public function contactGedcom(): string
77    {
78        $user_id = (int) $this->tree->getPreference('CONTACT_USER_ID');
79        $user    = $this->user_service->find($user_id);
80
81        if ($user instanceof User) {
82            $request = app(ServerRequestInterface::class);
83
84            return $this->user_service->contactLink($user, $request);
85        }
86
87        return '';
88    }
89}
90