xref: /webtrees/app/Module/ContactsFooterModule.php (revision 3cfcc809af53e831fa6cafac7b274a2cb407db6e)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\Module;
20
21use Fisharebest\Webtrees\I18N;
22use Fisharebest\Webtrees\Services\UserService;
23use Fisharebest\Webtrees\User;
24use Psr\Http\Message\ServerRequestInterface;
25
26/**
27 * Class ContactsFooterModule - provide a link to the site owner.
28 */
29class ContactsFooterModule extends AbstractModule implements ModuleFooterInterface
30{
31    use ModuleFooterTrait;
32
33    /**
34     * @var UserService
35     */
36    private $user_service;
37
38    /**
39     * Dependency injection.
40     *
41     * @param UserService $user_service
42     */
43    public function __construct(UserService $user_service)
44    {
45        $this->user_service = $user_service;
46    }
47
48    /**
49     * How should this module be labelled on tabs, footers, etc.?
50     *
51     * @return string
52     */
53    public function title(): string
54    {
55        /* I18N: Name of a module */
56        return I18N::translate('Contact information');
57    }
58
59    /**
60     * A sentence describing what this module does.
61     *
62     * @return string
63     */
64    public function description(): string
65    {
66        /* I18N: Description of the “Hit counters” module */
67        return I18N::translate('A link to the site contacts.');
68    }
69
70    /**
71     * The default position for this footer.  It can be changed in the control panel.
72     *
73     * @return int
74     */
75    public function defaultFooterOrder(): int
76    {
77        return 2;
78    }
79
80    /**
81     * A footer, to be added at the bottom of every page.
82     *
83     * @param ServerRequestInterface $request
84     *
85     * @return string
86     */
87    public function getFooter(ServerRequestInterface $request): string
88    {
89        $tree = $request->getAttribute('tree');
90
91        if ($tree === null) {
92            return '';
93        }
94
95        $contact_user   = $this->user_service->find((int) $tree->getPreference('CONTACT_USER_ID'));
96        $webmaster_user = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID'));
97
98        if ($contact_user instanceof User && $contact_user === $webmaster_user) {
99            return view('modules/contact-links/footer', [
100                'contact_links' => $this->contactLinkEverything($contact_user, $request),
101            ]);
102        }
103
104        if ($contact_user instanceof User && $webmaster_user instanceof User) {
105            return view('modules/contact-links/footer', [
106                'contact_links' => $this->contactLinkGenealogy($contact_user, $request) . '<br>' . $this->contactLinkTechnical($webmaster_user, $request),
107            ]);
108        }
109
110        if ($contact_user instanceof User) {
111            return view('modules/contact-links/footer', [
112                'contact_links' => $this->contactLinkGenealogy($contact_user, $request),
113            ]);
114        }
115
116        if ($webmaster_user instanceof User) {
117            return view('modules/contact-links/footer', [
118                'contact_links' => $this->contactLinkTechnical($webmaster_user, $request),
119            ]);
120        }
121
122        return '';
123    }
124
125    /**
126     * Create contact link for both technical and genealogy support.
127     *
128     * @param User                   $user
129     * @param ServerRequestInterface $request
130     *
131     * @return string
132     */
133    public function contactLinkEverything(User $user, ServerRequestInterface $request): string
134    {
135        return I18N::translate('For technical support or genealogy questions contact %s.', $this->user_service->contactLink($user, $request));
136    }
137
138    /**
139     * Create contact link for genealogy support.
140     *
141     * @param User                   $user
142     * @param ServerRequestInterface $request
143     *
144     * @return string
145     */
146    public function contactLinkGenealogy(User $user, ServerRequestInterface $request): string
147    {
148        return I18N::translate('For help with genealogy questions contact %s.', $this->user_service->contactLink($user, $request));
149    }
150
151    /**
152     * Create contact link for technical support.
153     *
154     * @param User                   $user
155     * @param ServerRequestInterface $request
156     *
157     * @return string
158     */
159    public function contactLinkTechnical(User $user, ServerRequestInterface $request): string
160    {
161        return I18N::translate('For technical support and information contact %s.', $this->user_service->contactLink($user, $request));
162    }
163}
164