xref: /webtrees/app/Statistics/Repository/ContactRepository.php (revision 4c78e066e3ba48f4c71bb900fac88b9e85e97474)
18add1155SRico Sonntag<?php
23976b470SGreg Roach
38add1155SRico Sonntag/**
48add1155SRico Sonntag * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
68add1155SRico Sonntag * This program is free software: you can redistribute it and/or modify
78add1155SRico Sonntag * it under the terms of the GNU General Public License as published by
88add1155SRico Sonntag * the Free Software Foundation, either version 3 of the License, or
98add1155SRico Sonntag * (at your option) any later version.
108add1155SRico Sonntag * This program is distributed in the hope that it will be useful,
118add1155SRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of
128add1155SRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138add1155SRico Sonntag * GNU General Public License for more details.
148add1155SRico Sonntag * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
168add1155SRico Sonntag */
17fcfa147eSGreg Roach
188add1155SRico Sonntagdeclare(strict_types=1);
198add1155SRico Sonntag
208add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Repository;
218add1155SRico Sonntag
22e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService;
238add1155SRico Sonntaguse Fisharebest\Webtrees\Statistics\Repository\Interfaces\ContactRepositoryInterface;
248add1155SRico Sonntaguse Fisharebest\Webtrees\Tree;
258add1155SRico Sonntaguse Fisharebest\Webtrees\User;
26a992e8c1SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
27a992e8c1SGreg Roach
28a992e8c1SGreg Roachuse function app;
298add1155SRico Sonntag
308add1155SRico Sonntag/**
318add1155SRico Sonntag * A repository providing methods for contact related statistics.
328add1155SRico Sonntag */
338add1155SRico Sonntagclass ContactRepository implements ContactRepositoryInterface
348add1155SRico Sonntag{
35*4c78e066SGreg Roach    private Tree $tree;
36*4c78e066SGreg Roach
37*4c78e066SGreg Roach    private UserService $user_service;
388add1155SRico Sonntag
398add1155SRico Sonntag    /**
408add1155SRico Sonntag     * @param Tree        $tree
41e5a6b4d4SGreg Roach     * @param UserService $user_service
428add1155SRico Sonntag     */
43e5a6b4d4SGreg Roach    public function __construct(Tree $tree, UserService $user_service)
448add1155SRico Sonntag    {
458add1155SRico Sonntag        $this->tree         = $tree;
46e5a6b4d4SGreg Roach        $this->user_service = $user_service;
478add1155SRico Sonntag    }
488add1155SRico Sonntag
498add1155SRico Sonntag    /**
500dcd9387SGreg Roach     * @return string
518add1155SRico Sonntag     */
528add1155SRico Sonntag    public function contactWebmaster(): string
538add1155SRico Sonntag    {
5486730b84SGreg Roach        $user_id = (int) $this->tree->getPreference('WEBMASTER_USER_ID');
5586730b84SGreg Roach        $user    = $this->user_service->find($user_id);
568add1155SRico Sonntag
578add1155SRico Sonntag        if ($user instanceof User) {
58a992e8c1SGreg Roach            $request = app(ServerRequestInterface::class);
59a992e8c1SGreg Roach
60a992e8c1SGreg Roach            return $this->user_service->contactLink($user, $request);
618add1155SRico Sonntag        }
628add1155SRico Sonntag
638add1155SRico Sonntag        return '';
648add1155SRico Sonntag    }
658add1155SRico Sonntag
668add1155SRico Sonntag    /**
670dcd9387SGreg Roach     * @return string
688add1155SRico Sonntag     */
698add1155SRico Sonntag    public function contactGedcom(): string
708add1155SRico Sonntag    {
7186730b84SGreg Roach        $user_id = (int) $this->tree->getPreference('CONTACT_USER_ID');
7286730b84SGreg Roach        $user    = $this->user_service->find($user_id);
738add1155SRico Sonntag
748add1155SRico Sonntag        if ($user instanceof User) {
75a992e8c1SGreg Roach            $request = app(ServerRequestInterface::class);
76a992e8c1SGreg Roach
77a992e8c1SGreg Roach            return $this->user_service->contactLink($user, $request);
788add1155SRico Sonntag        }
798add1155SRico Sonntag
808add1155SRico Sonntag        return '';
818add1155SRico Sonntag    }
828add1155SRico Sonntag}
83