xref: /webtrees/app/Statistics/Repository/ContactRepository.php (revision a992e8c1f5cff3fba48e8b69ec698e4e21142dc8)
18add1155SRico Sonntag<?php
23976b470SGreg Roach
38add1155SRico Sonntag/**
48add1155SRico Sonntag * webtrees: online genealogy
5242a7862SGreg Roach * Copyright (C) 2019 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
158add1155SRico Sonntag * along with this program. If not, see <http://www.gnu.org/licenses/>.
168add1155SRico Sonntag */
178add1155SRico Sonntagdeclare(strict_types=1);
188add1155SRico Sonntag
198add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Repository;
208add1155SRico Sonntag
21e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService;
228add1155SRico Sonntaguse Fisharebest\Webtrees\Statistics\Repository\Interfaces\ContactRepositoryInterface;
238add1155SRico Sonntaguse Fisharebest\Webtrees\Tree;
248add1155SRico Sonntaguse Fisharebest\Webtrees\User;
25*a992e8c1SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
26*a992e8c1SGreg Roach
27*a992e8c1SGreg Roachuse function app;
288add1155SRico Sonntag
298add1155SRico Sonntag/**
308add1155SRico Sonntag * A repository providing methods for contact related statistics.
318add1155SRico Sonntag */
328add1155SRico Sonntagclass ContactRepository implements ContactRepositoryInterface
338add1155SRico Sonntag{
348add1155SRico Sonntag    /**
358add1155SRico Sonntag     * @var Tree
368add1155SRico Sonntag     */
378add1155SRico Sonntag    private $tree;
38e5a6b4d4SGreg Roach    /**
39e5a6b4d4SGreg Roach     * @var UserService
40e5a6b4d4SGreg Roach     */
41e5a6b4d4SGreg Roach    private $user_service;
428add1155SRico Sonntag
438add1155SRico Sonntag    /**
448add1155SRico Sonntag     * Constructor.
458add1155SRico Sonntag     *
468add1155SRico Sonntag     * @param Tree        $tree
47e5a6b4d4SGreg Roach     * @param UserService $user_service
488add1155SRico Sonntag     */
49e5a6b4d4SGreg Roach    public function __construct(Tree $tree, UserService $user_service)
508add1155SRico Sonntag    {
518add1155SRico Sonntag        $this->tree         = $tree;
52e5a6b4d4SGreg Roach        $this->user_service = $user_service;
538add1155SRico Sonntag    }
548add1155SRico Sonntag
558add1155SRico Sonntag    /**
568add1155SRico Sonntag     * @inheritDoc
578add1155SRico Sonntag     */
588add1155SRico Sonntag    public function contactWebmaster(): string
598add1155SRico Sonntag    {
6086730b84SGreg Roach        $user_id = (int) $this->tree->getPreference('WEBMASTER_USER_ID');
6186730b84SGreg Roach        $user    = $this->user_service->find($user_id);
628add1155SRico Sonntag
638add1155SRico Sonntag        if ($user instanceof User) {
64*a992e8c1SGreg Roach            $request = app(ServerRequestInterface::class);
65*a992e8c1SGreg Roach
66*a992e8c1SGreg Roach            return $this->user_service->contactLink($user, $request);
678add1155SRico Sonntag        }
688add1155SRico Sonntag
698add1155SRico Sonntag        return '';
708add1155SRico Sonntag    }
718add1155SRico Sonntag
728add1155SRico Sonntag    /**
738add1155SRico Sonntag     * @inheritDoc
748add1155SRico Sonntag     */
758add1155SRico Sonntag    public function contactGedcom(): string
768add1155SRico Sonntag    {
7786730b84SGreg Roach        $user_id = (int) $this->tree->getPreference('CONTACT_USER_ID');
7886730b84SGreg Roach        $user    = $this->user_service->find($user_id);
798add1155SRico Sonntag
808add1155SRico Sonntag        if ($user instanceof User) {
81*a992e8c1SGreg Roach            $request = app(ServerRequestInterface::class);
82*a992e8c1SGreg Roach
83*a992e8c1SGreg Roach            return $this->user_service->contactLink($user, $request);
848add1155SRico Sonntag        }
858add1155SRico Sonntag
868add1155SRico Sonntag        return '';
878add1155SRico Sonntag    }
888add1155SRico Sonntag}
89