xref: /webtrees/app/Statistics/Repository/ContactRepository.php (revision 8136679edbff8170fb92bd6e8dd8df8eb645bb1a)
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\Statistics\Repository\Interfaces\ContactRepositoryInterface;
21use Fisharebest\Webtrees\Tree;
22use Fisharebest\Webtrees\User;
23use Symfony\Component\HttpFoundation\Request;
24
25/**
26 * A repository providing methods for contact related statistics.
27 */
28class ContactRepository implements ContactRepositoryInterface
29{
30    /**
31     * @var Tree
32     */
33    private $tree;
34
35    /**
36     * Constructor.
37     *
38     * @param Tree $tree
39     */
40    public function __construct(Tree $tree)
41    {
42        $this->tree = $tree;
43    }
44
45    /**
46     * @inheritDoc
47     */
48    public function contactWebmaster(): string
49    {
50        $user_id = $this->tree->getPreference('WEBMASTER_USER_ID');
51        $user    = User::find((int) $user_id);
52
53        if ($user instanceof User) {
54            return view('modules/contact-links/contact', [
55                'request' => app()->make(Request::class),
56                'user'    => $user,
57                'tree'    => $this->tree,
58            ]);
59        }
60
61        return '';
62    }
63
64    /**
65     * @inheritDoc
66     */
67    public function contactGedcom(): string
68    {
69        $user_id = $this->tree->getPreference('CONTACT_USER_ID');
70        $user    = User::find((int) $user_id);
71
72        if ($user instanceof User) {
73            return view('modules/contact-links/contact', [
74                'request' => app()->make(Request::class),
75                'user'    => $user,
76                'tree'    => $this->tree,
77            ]);
78        }
79
80        return '';
81    }
82}
83