xref: /webtrees/app/Statistics/Repository/ContactRepository.php (revision d11be7027e34e3121be11cc025421873364403f9)
18add1155SRico Sonntag<?php
23976b470SGreg Roach
38add1155SRico Sonntag/**
48add1155SRico Sonntag * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 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;
29dfc99c77SGreg Roachuse function assert;
308add1155SRico Sonntag
318add1155SRico Sonntag/**
328add1155SRico Sonntag * A repository providing methods for contact related statistics.
338add1155SRico Sonntag */
348add1155SRico Sonntagclass ContactRepository implements ContactRepositoryInterface
358add1155SRico Sonntag{
364c78e066SGreg Roach    private Tree $tree;
374c78e066SGreg Roach
384c78e066SGreg Roach    private UserService $user_service;
398add1155SRico Sonntag
408add1155SRico Sonntag    /**
418add1155SRico Sonntag     * @param Tree        $tree
42e5a6b4d4SGreg Roach     * @param UserService $user_service
438add1155SRico Sonntag     */
44e5a6b4d4SGreg Roach    public function __construct(Tree $tree, UserService $user_service)
458add1155SRico Sonntag    {
468add1155SRico Sonntag        $this->tree         = $tree;
47e5a6b4d4SGreg Roach        $this->user_service = $user_service;
488add1155SRico Sonntag    }
498add1155SRico Sonntag
508add1155SRico Sonntag    /**
510dcd9387SGreg Roach     * @return string
528add1155SRico Sonntag     */
538add1155SRico Sonntag    public function contactWebmaster(): string
548add1155SRico Sonntag    {
5586730b84SGreg Roach        $user_id = (int) $this->tree->getPreference('WEBMASTER_USER_ID');
5686730b84SGreg Roach        $user    = $this->user_service->find($user_id);
578add1155SRico Sonntag
588add1155SRico Sonntag        if ($user instanceof User) {
59a992e8c1SGreg Roach            $request = app(ServerRequestInterface::class);
60dfc99c77SGreg Roach            assert($request instanceof ServerRequestInterface);
61a992e8c1SGreg Roach
62a992e8c1SGreg Roach            return $this->user_service->contactLink($user, $request);
638add1155SRico Sonntag        }
648add1155SRico Sonntag
658add1155SRico Sonntag        return '';
668add1155SRico Sonntag    }
678add1155SRico Sonntag
688add1155SRico Sonntag    /**
690dcd9387SGreg Roach     * @return string
708add1155SRico Sonntag     */
718add1155SRico Sonntag    public function contactGedcom(): string
728add1155SRico Sonntag    {
7386730b84SGreg Roach        $user_id = (int) $this->tree->getPreference('CONTACT_USER_ID');
7486730b84SGreg Roach        $user    = $this->user_service->find($user_id);
758add1155SRico Sonntag
768add1155SRico Sonntag        if ($user instanceof User) {
77a992e8c1SGreg Roach            $request = app(ServerRequestInterface::class);
78dfc99c77SGreg Roach            assert($request instanceof ServerRequestInterface);
79a992e8c1SGreg Roach
80a992e8c1SGreg Roach            return $this->user_service->contactLink($user, $request);
818add1155SRico Sonntag        }
828add1155SRico Sonntag
838add1155SRico Sonntag        return '';
848add1155SRico Sonntag    }
858add1155SRico Sonntag}
86