xref: /webtrees/app/Statistics/Repository/ContactRepository.php (revision a34b54dc84837d4fd1e3b55dfaf41e1761acb658)
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 = $this->tree->getPreference('WEBMASTER_USER_ID');
58        $user    = $this->user_service->find((int) $user_id);
59
60        if ($user instanceof User) {
61            return view('modules/contact-links/contact', [
62                'request' => app()->make(Request::class),
63                'user'    => $user,
64                'tree'    => $this->tree,
65            ]);
66        }
67
68        return '';
69    }
70
71    /**
72     * @inheritDoc
73     */
74    public function contactGedcom(): string
75    {
76        $user_id = $this->tree->getPreference('CONTACT_USER_ID');
77        $user    = $this->user_service->find((int) $user_id);
78
79        if ($user instanceof User) {
80            return view('modules/contact-links/contact', [
81                'request' => app()->make(Request::class),
82                'user'    => $user,
83                'tree'    => $this->tree,
84            ]);
85        }
86
87        return '';
88    }
89}
90