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