xref: /webtrees/app/Module/LoginBlockModule.php (revision 49a243cb5fe7c21b24e262552d556b018bfe3f41)
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\Auth;
21use Fisharebest\Webtrees\I18N;
22use Fisharebest\Webtrees\Site;
23use Fisharebest\Webtrees\Tree;
24use Symfony\Component\HttpFoundation\Request;
25
26/**
27 * Class LoginBlockModule
28 */
29class LoginBlockModule extends AbstractModule implements ModuleInterface, ModuleBlockInterface
30{
31    use ModuleBlockTrait;
32
33    /** {@inheritdoc} */
34    public function title(): string
35    {
36        /* I18N: Name of a module */
37        return I18N::translate('Sign in');
38    }
39
40    /** {@inheritdoc} */
41    public function description(): string
42    {
43        /* I18N: Description of the “Sign in” module */
44        return I18N::translate('An alternative way to sign in and sign out.');
45    }
46
47    /**
48     * Generate the HTML content of this block.
49     *
50     * @param Tree     $tree
51     * @param int      $block_id
52     * @param string   $ctype
53     * @param string[] $cfg
54     *
55     * @return string
56     */
57    public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
58    {
59        if (Auth::check()) {
60            $title   = I18N::translate('Sign out');
61            $content = view('modules/login_block/sign-out', [
62                'user' => Auth::user(),
63            ]);
64        } else {
65            $title   = I18N::translate('Sign in');
66            $content = view('modules/login_block/sign-in', [
67                'allow_register' => (bool) Site::getPreference('USE_REGISTRATION_MODULE'),
68            ]);
69        }
70
71        if ($ctype !== '') {
72            return view('modules/block-template', [
73                'block'      => str_replace('_', '-', $this->getName()),
74                'id'         => $block_id,
75                'config_url' => '',
76                'title'      => $title,
77                'content'    => $content,
78            ]);
79        }
80
81        return $content;
82    }
83
84    /** {@inheritdoc} */
85    public function loadAjax(): bool
86    {
87        return false;
88    }
89
90    /** {@inheritdoc} */
91    public function isUserBlock(): bool
92    {
93        return true;
94    }
95
96    /** {@inheritdoc} */
97    public function isGedcomBlock(): bool
98    {
99        return true;
100    }
101
102    /**
103     * Update the configuration for a block.
104     *
105     * @param Request $request
106     * @param int     $block_id
107     *
108     * @return void
109     */
110    public function saveBlockConfiguration(Request $request, int $block_id)
111    {
112    }
113
114    /**
115     * An HTML form to edit block settings
116     *
117     * @param Tree $tree
118     * @param int  $block_id
119     *
120     * @return void
121     */
122    public function editBlockConfiguration(Tree $tree, int $block_id)
123    {
124    }
125}
126