xref: /webtrees/app/Statistics/Repository/ContactRepository.php (revision 43f2f523bcb6d4090564d23802872c0679ede6bc)
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    private Tree $tree;
36
37    private UserService $user_service;
38
39    /**
40     * @param Tree        $tree
41     * @param UserService $user_service
42     */
43    public function __construct(Tree $tree, UserService $user_service)
44    {
45        $this->tree         = $tree;
46        $this->user_service = $user_service;
47    }
48
49    /**
50     * @return string
51     */
52    public function contactWebmaster(): string
53    {
54        $user_id = (int) $this->tree->getPreference('WEBMASTER_USER_ID');
55        $user    = $this->user_service->find($user_id);
56
57        if ($user instanceof User) {
58            $request = app(ServerRequestInterface::class);
59
60            return $this->user_service->contactLink($user, $request);
61        }
62
63        return '';
64    }
65
66    /**
67     * @return string
68     */
69    public function contactGedcom(): string
70    {
71        $user_id = (int) $this->tree->getPreference('CONTACT_USER_ID');
72        $user    = $this->user_service->find($user_id);
73
74        if ($user instanceof User) {
75            $request = app(ServerRequestInterface::class);
76
77            return $this->user_service->contactLink($user, $request);
78        }
79
80        return '';
81    }
82}
83