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