xref: /webtrees/app/Module/LoginBlockModule.php (revision 26684e686fb5ab50ecb57e7e6c6a0a55852d2203)
1e2a378d3SGreg Roach<?php
2e2a378d3SGreg Roach/**
3e2a378d3SGreg Roach * webtrees: online genealogy
48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
5e2a378d3SGreg Roach * This program is free software: you can redistribute it and/or modify
6e2a378d3SGreg Roach * it under the terms of the GNU General Public License as published by
7e2a378d3SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8e2a378d3SGreg Roach * (at your option) any later version.
9e2a378d3SGreg Roach * This program is distributed in the hope that it will be useful,
10e2a378d3SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11e2a378d3SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12e2a378d3SGreg Roach * GNU General Public License for more details.
13e2a378d3SGreg Roach * You should have received a copy of the GNU General Public License
14e2a378d3SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15e2a378d3SGreg Roach */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
1976692c8bSGreg Roach
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site;
23e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
24a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request;
25e2a378d3SGreg Roach
26e2a378d3SGreg Roach/**
27e2a378d3SGreg Roach * Class LoginBlockModule
28e2a378d3SGreg Roach */
2949a243cbSGreg Roachclass LoginBlockModule extends AbstractModule implements ModuleInterface, ModuleBlockInterface
30c1010edaSGreg Roach{
3149a243cbSGreg Roach    use ModuleBlockTrait;
3249a243cbSGreg Roach
33961ec755SGreg Roach    /**
34961ec755SGreg Roach     * How should this module be labelled on tabs, menus, etc.?
35961ec755SGreg Roach     *
36961ec755SGreg Roach     * @return string
37961ec755SGreg Roach     */
3849a243cbSGreg Roach    public function title(): string
39c1010edaSGreg Roach    {
40bbb76c12SGreg Roach        /* I18N: Name of a module */
41bbb76c12SGreg Roach        return I18N::translate('Sign in');
42e2a378d3SGreg Roach    }
43e2a378d3SGreg Roach
44961ec755SGreg Roach    /**
45961ec755SGreg Roach     * A sentence describing what this module does.
46961ec755SGreg Roach     *
47961ec755SGreg Roach     * @return string
48961ec755SGreg Roach     */
4949a243cbSGreg Roach    public function description(): string
50c1010edaSGreg Roach    {
51bbb76c12SGreg Roach        /* I18N: Description of the “Sign in” module */
52bbb76c12SGreg Roach        return I18N::translate('An alternative way to sign in and sign out.');
53e2a378d3SGreg Roach    }
54e2a378d3SGreg Roach
5576692c8bSGreg Roach    /**
5676692c8bSGreg Roach     * Generate the HTML content of this block.
5776692c8bSGreg Roach     *
58e490cd80SGreg Roach     * @param Tree     $tree
5976692c8bSGreg Roach     * @param int      $block_id
605f2ae573SGreg Roach     * @param string   $ctype
61727f238cSGreg Roach     * @param string[] $cfg
6276692c8bSGreg Roach     *
6376692c8bSGreg Roach     * @return string
6476692c8bSGreg Roach     */
655f2ae573SGreg Roach    public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
66c1010edaSGreg Roach    {
67e2a378d3SGreg Roach        if (Auth::check()) {
68cdc90107SGreg Roach            $title   = I18N::translate('Sign out');
69147e99aaSGreg Roach            $content = view('modules/login_block/sign-out', [
70cf30a8edSGreg Roach                'user' => Auth::user(),
71cf30a8edSGreg Roach            ]);
72e2a378d3SGreg Roach        } else {
73cdc90107SGreg Roach            $title   = I18N::translate('Sign in');
74147e99aaSGreg Roach            $content = view('modules/login_block/sign-in', [
75c1010edaSGreg Roach                'allow_register' => (bool) Site::getPreference('USE_REGISTRATION_MODULE'),
76cf30a8edSGreg Roach            ]);
77e2a378d3SGreg Roach        }
78e2a378d3SGreg Roach
796a8879feSGreg Roach        if ($ctype !== '') {
80147e99aaSGreg Roach            return view('modules/block-template', [
81*26684e68SGreg Roach                'block'      => str_replace('_', '-', $this->name()),
829c6524dcSGreg Roach                'id'         => $block_id,
839c6524dcSGreg Roach                'config_url' => '',
84cf30a8edSGreg Roach                'title'      => $title,
859c6524dcSGreg Roach                'content'    => $content,
869c6524dcSGreg Roach            ]);
87e2a378d3SGreg Roach        }
88b2ce94c6SRico Sonntag
89b2ce94c6SRico Sonntag        return $content;
90e2a378d3SGreg Roach    }
91e2a378d3SGreg Roach
92e2a378d3SGreg Roach    /** {@inheritdoc} */
93c1010edaSGreg Roach    public function loadAjax(): bool
94c1010edaSGreg Roach    {
95e2a378d3SGreg Roach        return false;
96e2a378d3SGreg Roach    }
97e2a378d3SGreg Roach
98e2a378d3SGreg Roach    /** {@inheritdoc} */
99c1010edaSGreg Roach    public function isUserBlock(): bool
100c1010edaSGreg Roach    {
101e2a378d3SGreg Roach        return true;
102e2a378d3SGreg Roach    }
103e2a378d3SGreg Roach
104e2a378d3SGreg Roach    /** {@inheritdoc} */
105c1010edaSGreg Roach    public function isGedcomBlock(): bool
106c1010edaSGreg Roach    {
107e2a378d3SGreg Roach        return true;
108e2a378d3SGreg Roach    }
109e2a378d3SGreg Roach
11076692c8bSGreg Roach    /**
111a45f9889SGreg Roach     * Update the configuration for a block.
112a45f9889SGreg Roach     *
113a45f9889SGreg Roach     * @param Request $request
114a45f9889SGreg Roach     * @param int     $block_id
115a45f9889SGreg Roach     *
116a45f9889SGreg Roach     * @return void
117a45f9889SGreg Roach     */
118a45f9889SGreg Roach    public function saveBlockConfiguration(Request $request, int $block_id)
119a45f9889SGreg Roach    {
120a45f9889SGreg Roach    }
121a45f9889SGreg Roach
122a45f9889SGreg Roach    /**
12376692c8bSGreg Roach     * An HTML form to edit block settings
12476692c8bSGreg Roach     *
125e490cd80SGreg Roach     * @param Tree $tree
12676692c8bSGreg Roach     * @param int  $block_id
127a9430be8SGreg Roach     *
128a9430be8SGreg Roach     * @return void
12976692c8bSGreg Roach     */
130a45f9889SGreg Roach    public function editBlockConfiguration(Tree $tree, int $block_id)
131c1010edaSGreg Roach    {
132e2a378d3SGreg Roach    }
133e2a378d3SGreg Roach}
134