xref: /webtrees/app/Module/LoginBlockModule.php (revision bbb76c12bd7338ebbb054916678efe20cb71ce1f)
1e2a378d3SGreg Roach<?php
2e2a378d3SGreg Roach/**
3e2a378d3SGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 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 */
1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
1776692c8bSGreg Roach
180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site;
21e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
22e2a378d3SGreg Roach
23e2a378d3SGreg Roach/**
24e2a378d3SGreg Roach * Class LoginBlockModule
25e2a378d3SGreg Roach */
26c1010edaSGreg Roachclass LoginBlockModule extends AbstractModule implements ModuleBlockInterface
27c1010edaSGreg Roach{
28e2a378d3SGreg Roach    /** {@inheritdoc} */
29c1010edaSGreg Roach    public function getTitle()
30c1010edaSGreg Roach    {
31*bbb76c12SGreg Roach        /* I18N: Name of a module */
32*bbb76c12SGreg Roach        return I18N::translate('Sign in');
33e2a378d3SGreg Roach    }
34e2a378d3SGreg Roach
35e2a378d3SGreg Roach    /** {@inheritdoc} */
36c1010edaSGreg Roach    public function getDescription()
37c1010edaSGreg Roach    {
38*bbb76c12SGreg Roach        /* I18N: Description of the “Sign in” module */
39*bbb76c12SGreg Roach        return I18N::translate('An alternative way to sign in and sign out.');
40e2a378d3SGreg Roach    }
41e2a378d3SGreg Roach
4276692c8bSGreg Roach    /**
4376692c8bSGreg Roach     * Generate the HTML content of this block.
4476692c8bSGreg Roach     *
45e490cd80SGreg Roach     * @param Tree     $tree
4676692c8bSGreg Roach     * @param int      $block_id
4776692c8bSGreg Roach     * @param bool     $template
48727f238cSGreg Roach     * @param string[] $cfg
4976692c8bSGreg Roach     *
5076692c8bSGreg Roach     * @return string
5176692c8bSGreg Roach     */
52c1010edaSGreg Roach    public function getBlock(Tree $tree, int $block_id, bool $template = true, array $cfg = []): string
53c1010edaSGreg Roach    {
54e2a378d3SGreg Roach        if (Auth::check()) {
55cdc90107SGreg Roach            $title   = I18N::translate('Sign out');
56147e99aaSGreg Roach            $content = view('modules/login_block/sign-out', [
57cf30a8edSGreg Roach                'user' => Auth::user(),
58cf30a8edSGreg Roach            ]);
59e2a378d3SGreg Roach        } else {
60cdc90107SGreg Roach            $title   = I18N::translate('Sign in');
61147e99aaSGreg Roach            $content = view('modules/login_block/sign-in', [
62c1010edaSGreg Roach                'allow_register' => (bool)Site::getPreference('USE_REGISTRATION_MODULE'),
63cf30a8edSGreg Roach            ]);
64e2a378d3SGreg Roach        }
65e2a378d3SGreg Roach
66e2a378d3SGreg Roach        if ($template) {
67147e99aaSGreg Roach            return view('modules/block-template', [
689c6524dcSGreg Roach                'block'      => str_replace('_', '-', $this->getName()),
699c6524dcSGreg Roach                'id'         => $block_id,
709c6524dcSGreg Roach                'config_url' => '',
71cf30a8edSGreg Roach                'title'      => $title,
729c6524dcSGreg Roach                'content'    => $content,
739c6524dcSGreg Roach            ]);
74e2a378d3SGreg Roach        } else {
75e2a378d3SGreg Roach            return $content;
76e2a378d3SGreg Roach        }
77e2a378d3SGreg Roach    }
78e2a378d3SGreg Roach
79e2a378d3SGreg Roach    /** {@inheritdoc} */
80c1010edaSGreg Roach    public function loadAjax(): bool
81c1010edaSGreg Roach    {
82e2a378d3SGreg Roach        return false;
83e2a378d3SGreg Roach    }
84e2a378d3SGreg Roach
85e2a378d3SGreg Roach    /** {@inheritdoc} */
86c1010edaSGreg Roach    public function isUserBlock(): bool
87c1010edaSGreg Roach    {
88e2a378d3SGreg Roach        return true;
89e2a378d3SGreg Roach    }
90e2a378d3SGreg Roach
91e2a378d3SGreg Roach    /** {@inheritdoc} */
92c1010edaSGreg Roach    public function isGedcomBlock(): bool
93c1010edaSGreg Roach    {
94e2a378d3SGreg Roach        return true;
95e2a378d3SGreg Roach    }
96e2a378d3SGreg Roach
9776692c8bSGreg Roach    /**
9876692c8bSGreg Roach     * An HTML form to edit block settings
9976692c8bSGreg Roach     *
100e490cd80SGreg Roach     * @param Tree $tree
10176692c8bSGreg Roach     * @param int  $block_id
102a9430be8SGreg Roach     *
103a9430be8SGreg Roach     * @return void
10476692c8bSGreg Roach     */
105c1010edaSGreg Roach    public function configureBlock(Tree $tree, int $block_id)
106c1010edaSGreg Roach    {
107e2a378d3SGreg Roach    }
108e2a378d3SGreg Roach}
109