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