xref: /webtrees/app/Module/LoginBlockModule.php (revision a45f98897789fc9ff88705eb09ae5f037bf49c10)
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;
22*a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request;
23e2a378d3SGreg Roach
24e2a378d3SGreg Roach/**
25e2a378d3SGreg Roach * Class LoginBlockModule
26e2a378d3SGreg Roach */
27c1010edaSGreg Roachclass LoginBlockModule extends AbstractModule implements ModuleBlockInterface
28c1010edaSGreg Roach{
29e2a378d3SGreg Roach    /** {@inheritdoc} */
30c1010edaSGreg Roach    public function getTitle()
31c1010edaSGreg Roach    {
32bbb76c12SGreg Roach        /* I18N: Name of a module */
33bbb76c12SGreg Roach        return I18N::translate('Sign in');
34e2a378d3SGreg Roach    }
35e2a378d3SGreg Roach
36e2a378d3SGreg Roach    /** {@inheritdoc} */
37c1010edaSGreg Roach    public function getDescription()
38c1010edaSGreg Roach    {
39bbb76c12SGreg Roach        /* I18N: Description of the “Sign in” module */
40bbb76c12SGreg Roach        return I18N::translate('An alternative way to sign in and sign out.');
41e2a378d3SGreg Roach    }
42e2a378d3SGreg Roach
4376692c8bSGreg Roach    /**
4476692c8bSGreg Roach     * Generate the HTML content of this block.
4576692c8bSGreg Roach     *
46e490cd80SGreg Roach     * @param Tree     $tree
4776692c8bSGreg Roach     * @param int      $block_id
4876692c8bSGreg Roach     * @param bool     $template
49727f238cSGreg Roach     * @param string[] $cfg
5076692c8bSGreg Roach     *
5176692c8bSGreg Roach     * @return string
5276692c8bSGreg Roach     */
53c1010edaSGreg Roach    public function getBlock(Tree $tree, int $block_id, bool $template = true, array $cfg = []): string
54c1010edaSGreg Roach    {
55e2a378d3SGreg Roach        if (Auth::check()) {
56cdc90107SGreg Roach            $title   = I18N::translate('Sign out');
57147e99aaSGreg Roach            $content = view('modules/login_block/sign-out', [
58cf30a8edSGreg Roach                'user' => Auth::user(),
59cf30a8edSGreg Roach            ]);
60e2a378d3SGreg Roach        } else {
61cdc90107SGreg Roach            $title   = I18N::translate('Sign in');
62147e99aaSGreg Roach            $content = view('modules/login_block/sign-in', [
63c1010edaSGreg Roach                'allow_register' => (bool)Site::getPreference('USE_REGISTRATION_MODULE'),
64cf30a8edSGreg Roach            ]);
65e2a378d3SGreg Roach        }
66e2a378d3SGreg Roach
67e2a378d3SGreg Roach        if ($template) {
68147e99aaSGreg Roach            return view('modules/block-template', [
699c6524dcSGreg Roach                'block'      => str_replace('_', '-', $this->getName()),
709c6524dcSGreg Roach                'id'         => $block_id,
719c6524dcSGreg Roach                'config_url' => '',
72cf30a8edSGreg Roach                'title'      => $title,
739c6524dcSGreg Roach                'content'    => $content,
749c6524dcSGreg Roach            ]);
75e2a378d3SGreg Roach        } else {
76e2a378d3SGreg Roach            return $content;
77e2a378d3SGreg Roach        }
78e2a378d3SGreg Roach    }
79e2a378d3SGreg Roach
80e2a378d3SGreg Roach    /** {@inheritdoc} */
81c1010edaSGreg Roach    public function loadAjax(): bool
82c1010edaSGreg Roach    {
83e2a378d3SGreg Roach        return false;
84e2a378d3SGreg Roach    }
85e2a378d3SGreg Roach
86e2a378d3SGreg Roach    /** {@inheritdoc} */
87c1010edaSGreg Roach    public function isUserBlock(): bool
88c1010edaSGreg Roach    {
89e2a378d3SGreg Roach        return true;
90e2a378d3SGreg Roach    }
91e2a378d3SGreg Roach
92e2a378d3SGreg Roach    /** {@inheritdoc} */
93c1010edaSGreg Roach    public function isGedcomBlock(): bool
94c1010edaSGreg Roach    {
95e2a378d3SGreg Roach        return true;
96e2a378d3SGreg Roach    }
97e2a378d3SGreg Roach
9876692c8bSGreg Roach    /**
99*a45f9889SGreg Roach     * Update the configuration for a block.
100*a45f9889SGreg Roach     *
101*a45f9889SGreg Roach     * @param Request $request
102*a45f9889SGreg Roach     * @param int     $block_id
103*a45f9889SGreg Roach     *
104*a45f9889SGreg Roach     * @return void
105*a45f9889SGreg Roach     */
106*a45f9889SGreg Roach    public function saveBlockConfiguration(Request $request, int $block_id)
107*a45f9889SGreg Roach    {
108*a45f9889SGreg Roach    }
109*a45f9889SGreg Roach
110*a45f9889SGreg Roach    /**
11176692c8bSGreg Roach     * An HTML form to edit block settings
11276692c8bSGreg Roach     *
113e490cd80SGreg Roach     * @param Tree $tree
11476692c8bSGreg Roach     * @param int  $block_id
115a9430be8SGreg Roach     *
116a9430be8SGreg Roach     * @return void
11776692c8bSGreg Roach     */
118*a45f9889SGreg Roach    public function editBlockConfiguration(Tree $tree, int $block_id)
119c1010edaSGreg Roach    {
120e2a378d3SGreg Roach    }
121e2a378d3SGreg Roach}
122