xref: /webtrees/app/Module/WelcomeBlockModule.php (revision c1010eda29c0909ed4d5d463f32d32bfefdd4dfe)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 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 */
16namespace Fisharebest\Webtrees\Module;
17
18use Fisharebest\Webtrees\Auth;
19use Fisharebest\Webtrees\I18N;
20use Fisharebest\Webtrees\Module;
21use Fisharebest\Webtrees\Site;
22use Fisharebest\Webtrees\Tree;
23
24/**
25 * Class WelcomeBlockModule
26 */
27class WelcomeBlockModule extends AbstractModule implements ModuleBlockInterface
28{
29    /** {@inheritdoc} */
30    public function getTitle()
31    {
32        return /* I18N: Name of a module */
33            I18N::translate('Home page');
34    }
35
36    /** {@inheritdoc} */
37    public function getDescription()
38    {
39        return /* I18N: Description of the “Home page” module */
40            I18N::translate('A greeting message for site visitors.');
41    }
42
43    /**
44     * Generate the HTML content of this block.
45     *
46     * @param Tree     $tree
47     * @param int      $block_id
48     * @param bool     $template
49     * @param string[] $cfg
50     *
51     * @return string
52     */
53    public function getBlock(Tree $tree, int $block_id, bool $template = true, array $cfg = []): string
54    {
55        $individual = $tree->getSignificantIndividual();
56
57        $links = [];
58
59        if (Module::isActiveChart($individual->getTree(), 'pedigree_chart')) {
60            $links[] = [
61                'url'   => route('pedigree', [
62                    'xref' => $individual->getXref(),
63                    'ged'  => $individual->getTree()->getName(),
64                ]),
65                'title' => I18N::translate('Default chart'),
66                'icon'  => 'icon-pedigree',
67            ];
68        }
69
70        $links[] = [
71            'url'   => $individual->url(),
72            'title' => I18N::translate('Default individual'),
73            'icon'  => 'icon-indis',
74        ];
75
76        if (Site::getPreference('USE_REGISTRATION_MODULE') === '1' && !Auth::check()) {
77            $links[] = [
78                'url'   => route('register'),
79                'title' => I18N::translate('Request a new user account'),
80                'icon'  => 'icon-user_add',
81            ];
82        }
83
84        $content = view('modules/gedcom_block/welcome', ['links' => $links]);
85
86        if ($template) {
87            return view('modules/block-template', [
88                'block'      => str_replace('_', '-', $this->getName()),
89                'id'         => $block_id,
90                'config_url' => '',
91                'title'      => $individual->getTree()->getTitle(),
92                'content'    => $content,
93            ]);
94        } else {
95            return $content;
96        }
97    }
98
99    /** {@inheritdoc} */
100    public function loadAjax(): bool
101    {
102        return false;
103    }
104
105    /** {@inheritdoc} */
106    public function isUserBlock(): bool
107    {
108        return false;
109    }
110
111    /** {@inheritdoc} */
112    public function isGedcomBlock(): bool
113    {
114        return true;
115    }
116
117    /**
118     * An HTML form to edit block settings
119     *
120     * @param Tree $tree
121     * @param int  $block_id
122     *
123     * @return void
124     */
125    public function configureBlock(Tree $tree, int $block_id)
126    {
127    }
128}
129