xref: /webtrees/app/Module/ContactsFooterModule.php (revision e5a6b4d4f6f6e7ff2fba7ae2cf27546ae68a79cc)
133c34396SGreg Roach<?php
233c34396SGreg Roach/**
333c34396SGreg Roach * webtrees: online genealogy
433c34396SGreg Roach * Copyright (C) 2019 webtrees development team
533c34396SGreg Roach * This program is free software: you can redistribute it and/or modify
633c34396SGreg Roach * it under the terms of the GNU General Public License as published by
733c34396SGreg Roach * the Free Software Foundation, either version 3 of the License, or
833c34396SGreg Roach * (at your option) any later version.
933c34396SGreg Roach * This program is distributed in the hope that it will be useful,
1033c34396SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1133c34396SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1233c34396SGreg Roach * GNU General Public License for more details.
1333c34396SGreg Roach * You should have received a copy of the GNU General Public License
1433c34396SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1533c34396SGreg Roach */
1633c34396SGreg Roachdeclare(strict_types=1);
1733c34396SGreg Roach
1833c34396SGreg Roachnamespace Fisharebest\Webtrees\Module;
1933c34396SGreg Roach
20*e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
2133c34396SGreg Roachuse Fisharebest\Webtrees\I18N;
22*e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService;
2333c34396SGreg Roachuse Fisharebest\Webtrees\Tree;
2433c34396SGreg Roachuse Fisharebest\Webtrees\User;
2533c34396SGreg Roachuse Symfony\Component\HttpFoundation\Request;
2633c34396SGreg Roach
2733c34396SGreg Roach/**
2833c34396SGreg Roach * Class ContactsFooterModule - provide a link to the site owner.
2933c34396SGreg Roach */
3033c34396SGreg Roachclass ContactsFooterModule extends AbstractModule implements ModuleFooterInterface
3133c34396SGreg Roach{
3233c34396SGreg Roach    use ModuleFooterTrait;
3333c34396SGreg Roach
3433c34396SGreg Roach    /** @var Request */
3533c34396SGreg Roach    protected $request;
3633c34396SGreg Roach
3733c34396SGreg Roach    /** @var Tree|null */
3833c34396SGreg Roach    protected $tree;
3933c34396SGreg Roach
4033c34396SGreg Roach    /** @var User */
4133c34396SGreg Roach    protected $user;
4233c34396SGreg Roach
4333c34396SGreg Roach    /**
44*e5a6b4d4SGreg Roach     * @var UserService
45*e5a6b4d4SGreg Roach     */
46*e5a6b4d4SGreg Roach    private $user_service;
47*e5a6b4d4SGreg Roach
48*e5a6b4d4SGreg Roach    /**
49d4c04956SGreg Roach     * Dependency injection.
50d4c04956SGreg Roach     *
51d4c04956SGreg Roach     * @param Tree|null     $tree
52*e5a6b4d4SGreg Roach     * @param UserInterface $user
53d4c04956SGreg Roach     * @param Request       $request
54*e5a6b4d4SGreg Roach     * @param UserService   $user_service
55d4c04956SGreg Roach     */
56*e5a6b4d4SGreg Roach    public function __construct(?Tree $tree, UserInterface $user, Request $request, UserService $user_service)
57d4c04956SGreg Roach    {
58d4c04956SGreg Roach        $this->tree    = $tree;
59d4c04956SGreg Roach        $this->user    = $user;
60d4c04956SGreg Roach        $this->request = $request;
61*e5a6b4d4SGreg Roach        $this->user_service = $user_service;
62d4c04956SGreg Roach    }
63d4c04956SGreg Roach
64d4c04956SGreg Roach    /**
6533c34396SGreg Roach     * How should this module be labelled on tabs, footers, etc.?
6633c34396SGreg Roach     *
6733c34396SGreg Roach     * @return string
6833c34396SGreg Roach     */
6933c34396SGreg Roach    public function title(): string
7033c34396SGreg Roach    {
7133c34396SGreg Roach        /* I18N: Name of a module */
7233c34396SGreg Roach        return I18N::translate('Contact information');
7333c34396SGreg Roach    }
7433c34396SGreg Roach
7533c34396SGreg Roach    /**
7633c34396SGreg Roach     * A sentence describing what this module does.
7733c34396SGreg Roach     *
7833c34396SGreg Roach     * @return string
7933c34396SGreg Roach     */
8033c34396SGreg Roach    public function description(): string
8133c34396SGreg Roach    {
8233c34396SGreg Roach        /* I18N: Description of the “Hit counters” module */
8333c34396SGreg Roach        return I18N::translate('A link to the site contacts.');
8433c34396SGreg Roach    }
8533c34396SGreg Roach
8633c34396SGreg Roach    /**
8733c34396SGreg Roach     * The default position for this footer.  It can be changed in the control panel.
8833c34396SGreg Roach     *
8933c34396SGreg Roach     * @return int
9033c34396SGreg Roach     */
9133c34396SGreg Roach    public function defaultFooterOrder(): int
9233c34396SGreg Roach    {
9333c34396SGreg Roach        return 2;
9433c34396SGreg Roach    }
9533c34396SGreg Roach
9633c34396SGreg Roach    /**
9733c34396SGreg Roach     * A footer, to be added at the bottom of every page.
9833c34396SGreg Roach     *
9933c34396SGreg Roach     * @return string
10033c34396SGreg Roach     */
10133c34396SGreg Roach    public function getFooter(): string
10233c34396SGreg Roach    {
10333c34396SGreg Roach        if ($this->tree === null) {
10433c34396SGreg Roach            return '';
10533c34396SGreg Roach        }
10633c34396SGreg Roach
107*e5a6b4d4SGreg Roach        $contact_user   = $this->user_service->find((int) $this->tree->getPreference('CONTACT_USER_ID'));
108*e5a6b4d4SGreg Roach        $webmaster_user = $this->user_service->find((int) $this->tree->getPreference('WEBMASTER_USER_ID'));
10933c34396SGreg Roach
11033c34396SGreg Roach        if ($contact_user instanceof User && $contact_user === $webmaster_user) {
11133c34396SGreg Roach            return view('modules/contact-links/footer', [
11233c34396SGreg Roach                'contact_links' => $this->contactLinkEverything($contact_user),
11333c34396SGreg Roach            ]);
11433c34396SGreg Roach        }
11533c34396SGreg Roach
11633c34396SGreg Roach        if ($contact_user instanceof User && $webmaster_user instanceof User) {
11733c34396SGreg Roach            return view('modules/contact-links/footer', [
11833c34396SGreg Roach                'contact_links' => $this->contactLinkGenealogy($contact_user) . '<br>' . $this->contactLinkTechnical($webmaster_user),
11933c34396SGreg Roach            ]);
12033c34396SGreg Roach        }
12133c34396SGreg Roach
12233c34396SGreg Roach        if ($contact_user instanceof User) {
12333c34396SGreg Roach            return view('modules/contact-links/footer', [
12433c34396SGreg Roach                'contact_links' => $this->contactLinkGenealogy($contact_user),
12533c34396SGreg Roach            ]);
12633c34396SGreg Roach        }
12733c34396SGreg Roach
12833c34396SGreg Roach        if ($webmaster_user instanceof User) {
12933c34396SGreg Roach            return view('modules/contact-links/footer', [
13097350b3fSGreg Roach                'contact_links' => $this->contactLinkTechnical($webmaster_user),
13133c34396SGreg Roach            ]);
13233c34396SGreg Roach        }
13333c34396SGreg Roach
13433c34396SGreg Roach        return '';
13533c34396SGreg Roach    }
13633c34396SGreg Roach
13733c34396SGreg Roach    /**
13833c34396SGreg Roach     * Create contact link for both technical and genealogy support.
13933c34396SGreg Roach     *
140*e5a6b4d4SGreg Roach     * @param UserInterface $user
14133c34396SGreg Roach     *
14233c34396SGreg Roach     * @return string
14333c34396SGreg Roach     */
144*e5a6b4d4SGreg Roach    public function contactLinkEverything(UserInterface $user): string
14533c34396SGreg Roach    {
14633c34396SGreg Roach        return I18N::translate('For technical support or genealogy questions contact %s.', $this->contactLink($user));
14733c34396SGreg Roach    }
14833c34396SGreg Roach
14933c34396SGreg Roach    /**
15033c34396SGreg Roach     * Create contact link for genealogy support.
15133c34396SGreg Roach     *
152*e5a6b4d4SGreg Roach     * @param UserInterface $user
15333c34396SGreg Roach     *
15433c34396SGreg Roach     * @return string
15533c34396SGreg Roach     */
156*e5a6b4d4SGreg Roach    public function contactLinkGenealogy(UserInterface $user): string
15733c34396SGreg Roach    {
15833c34396SGreg Roach        return I18N::translate('For help with genealogy questions contact %s.', $this->contactLink($user));
15933c34396SGreg Roach    }
16033c34396SGreg Roach
16133c34396SGreg Roach    /**
16233c34396SGreg Roach     * Create contact link for technical support.
16333c34396SGreg Roach     *
164*e5a6b4d4SGreg Roach     * @param UserInterface $user
16533c34396SGreg Roach     *
16633c34396SGreg Roach     * @return string
16733c34396SGreg Roach     */
168*e5a6b4d4SGreg Roach    public function contactLinkTechnical(UserInterface $user): string
16933c34396SGreg Roach    {
17033c34396SGreg Roach        return I18N::translate('For technical support and information contact %s.', $this->contactLink($user));
17133c34396SGreg Roach    }
17233c34396SGreg Roach
17333c34396SGreg Roach    /**
17433c34396SGreg Roach     * Create a contact link for a user.
17533c34396SGreg Roach     *
176*e5a6b4d4SGreg Roach     * @param UserInterface $user
17733c34396SGreg Roach     *
17833c34396SGreg Roach     * @return string
17933c34396SGreg Roach     */
180*e5a6b4d4SGreg Roach    private function contactLink(UserInterface $user): string
18133c34396SGreg Roach    {
1821b7696b4SGreg Roach        return view('modules/contact-links/contact', [
1831b7696b4SGreg Roach            'request' => $this->request,
1841b7696b4SGreg Roach            'user'    => $user,
1851b7696b4SGreg Roach            'tree'    => $this->tree,
18633c34396SGreg Roach        ]);
18733c34396SGreg Roach    }
18833c34396SGreg Roach}
189