xref: /webtrees/app/Statistics/Repository/ContactRepository.php (revision e5a6b4d4f6f6e7ff2fba7ae2cf27546ae68a79cc)
18add1155SRico Sonntag<?php
28add1155SRico Sonntag/**
38add1155SRico Sonntag * webtrees: online genealogy
48add1155SRico Sonntag * Copyright (C) 2018 webtrees development team
58add1155SRico Sonntag * This program is free software: you can redistribute it and/or modify
68add1155SRico Sonntag * it under the terms of the GNU General Public License as published by
78add1155SRico Sonntag * the Free Software Foundation, either version 3 of the License, or
88add1155SRico Sonntag * (at your option) any later version.
98add1155SRico Sonntag * This program is distributed in the hope that it will be useful,
108add1155SRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of
118add1155SRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
128add1155SRico Sonntag * GNU General Public License for more details.
138add1155SRico Sonntag * You should have received a copy of the GNU General Public License
148add1155SRico Sonntag * along with this program. If not, see <http://www.gnu.org/licenses/>.
158add1155SRico Sonntag */
168add1155SRico Sonntagdeclare(strict_types=1);
178add1155SRico Sonntag
188add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Repository;
198add1155SRico Sonntag
20*e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService;
218add1155SRico Sonntaguse Fisharebest\Webtrees\Statistics\Repository\Interfaces\ContactRepositoryInterface;
228add1155SRico Sonntaguse Fisharebest\Webtrees\Tree;
238add1155SRico Sonntaguse Fisharebest\Webtrees\User;
248add1155SRico Sonntaguse Symfony\Component\HttpFoundation\Request;
258add1155SRico Sonntag
268add1155SRico Sonntag/**
278add1155SRico Sonntag * A repository providing methods for contact related statistics.
288add1155SRico Sonntag */
298add1155SRico Sonntagclass ContactRepository implements ContactRepositoryInterface
308add1155SRico Sonntag{
318add1155SRico Sonntag    /**
328add1155SRico Sonntag     * @var Tree
338add1155SRico Sonntag     */
348add1155SRico Sonntag    private $tree;
35*e5a6b4d4SGreg Roach    /**
36*e5a6b4d4SGreg Roach     * @var UserService
37*e5a6b4d4SGreg Roach     */
38*e5a6b4d4SGreg Roach    private $user_service;
398add1155SRico Sonntag
408add1155SRico Sonntag    /**
418add1155SRico Sonntag     * Constructor.
428add1155SRico Sonntag     *
438add1155SRico Sonntag     * @param Tree        $tree
44*e5a6b4d4SGreg Roach     * @param UserService $user_service
458add1155SRico Sonntag     */
46*e5a6b4d4SGreg Roach    public function __construct(Tree $tree, UserService $user_service)
478add1155SRico Sonntag    {
488add1155SRico Sonntag        $this->tree         = $tree;
49*e5a6b4d4SGreg Roach        $this->user_service = $user_service;
508add1155SRico Sonntag    }
518add1155SRico Sonntag
528add1155SRico Sonntag    /**
538add1155SRico Sonntag     * @inheritDoc
548add1155SRico Sonntag     */
558add1155SRico Sonntag    public function contactWebmaster(): string
568add1155SRico Sonntag    {
578add1155SRico Sonntag        $user_id = $this->tree->getPreference('WEBMASTER_USER_ID');
58*e5a6b4d4SGreg Roach        $user    = $this->user_service->find((int) $user_id);
598add1155SRico Sonntag
608add1155SRico Sonntag        if ($user instanceof User) {
618add1155SRico Sonntag            return view('modules/contact-links/contact', [
628add1155SRico Sonntag                'request' => app()->make(Request::class),
638add1155SRico Sonntag                'user'    => $user,
648add1155SRico Sonntag                'tree'    => $this->tree,
658add1155SRico Sonntag            ]);
668add1155SRico Sonntag        }
678add1155SRico Sonntag
688add1155SRico Sonntag        return '';
698add1155SRico Sonntag    }
708add1155SRico Sonntag
718add1155SRico Sonntag    /**
728add1155SRico Sonntag     * @inheritDoc
738add1155SRico Sonntag     */
748add1155SRico Sonntag    public function contactGedcom(): string
758add1155SRico Sonntag    {
768add1155SRico Sonntag        $user_id = $this->tree->getPreference('CONTACT_USER_ID');
77*e5a6b4d4SGreg Roach        $user    = $this->user_service->find((int) $user_id);
788add1155SRico Sonntag
798add1155SRico Sonntag        if ($user instanceof User) {
808add1155SRico Sonntag            return view('modules/contact-links/contact', [
818add1155SRico Sonntag                'request' => app()->make(Request::class),
828add1155SRico Sonntag                'user'    => $user,
838add1155SRico Sonntag                'tree'    => $this->tree,
848add1155SRico Sonntag            ]);
858add1155SRico Sonntag        }
868add1155SRico Sonntag
878add1155SRico Sonntag        return '';
888add1155SRico Sonntag    }
898add1155SRico Sonntag}
90