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