xref: /webtrees/app/Module/WelcomeBlockModule.php (revision 8f53f488f13e53e44dc48778e8f51ec9f91352dd)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roach/**
38c2e8227SGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 webtrees development team
58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
88c2e8227SGreg Roach * (at your option) any later version.
98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
128c2e8227SGreg Roach * GNU General Public License for more details.
138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
158c2e8227SGreg Roach */
1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
1776692c8bSGreg Roach
180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
204eb71cfaSGreg Roachuse Fisharebest\Webtrees\Module;
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site;
22e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
23a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request;
248c2e8227SGreg Roach
258c2e8227SGreg Roach/**
268c2e8227SGreg Roach * Class WelcomeBlockModule
278c2e8227SGreg Roach */
28c1010edaSGreg Roachclass WelcomeBlockModule extends AbstractModule implements ModuleBlockInterface
29c1010edaSGreg Roach{
308c2e8227SGreg Roach    /** {@inheritdoc} */
31*8f53f488SRico Sonntag    public function getTitle(): string
32c1010edaSGreg Roach    {
33bbb76c12SGreg Roach        /* I18N: Name of a module */
34bbb76c12SGreg Roach        return I18N::translate('Home page');
358c2e8227SGreg Roach    }
368c2e8227SGreg Roach
378c2e8227SGreg Roach    /** {@inheritdoc} */
38*8f53f488SRico Sonntag    public function getDescription(): string
39c1010edaSGreg Roach    {
40bbb76c12SGreg Roach        /* I18N: Description of the “Home page” module */
41bbb76c12SGreg Roach        return I18N::translate('A greeting message for site visitors.');
428c2e8227SGreg Roach    }
438c2e8227SGreg Roach
4476692c8bSGreg Roach    /**
4576692c8bSGreg Roach     * Generate the HTML content of this block.
4676692c8bSGreg Roach     *
47e490cd80SGreg Roach     * @param Tree     $tree
4876692c8bSGreg Roach     * @param int      $block_id
4976692c8bSGreg Roach     * @param bool     $template
50727f238cSGreg Roach     * @param string[] $cfg
5176692c8bSGreg Roach     *
5276692c8bSGreg Roach     * @return string
5376692c8bSGreg Roach     */
54c1010edaSGreg Roach    public function getBlock(Tree $tree, int $block_id, bool $template = true, array $cfg = []): string
55c1010edaSGreg Roach    {
565fe1add5SGreg Roach        $individual = $tree->getSignificantIndividual();
5775d70144SGreg Roach
5875d70144SGreg Roach        $links = [];
5975d70144SGreg Roach
6075d70144SGreg Roach        if (Module::isActiveChart($individual->getTree(), 'pedigree_chart')) {
6175d70144SGreg Roach            $links[] = [
62c1010edaSGreg Roach                'url'   => route('pedigree', [
63c1010edaSGreg Roach                    'xref' => $individual->getXref(),
64c1010edaSGreg Roach                    'ged'  => $individual->getTree()->getName(),
65c1010edaSGreg Roach                ]),
6675d70144SGreg Roach                'title' => I18N::translate('Default chart'),
6775d70144SGreg Roach                'icon'  => 'icon-pedigree',
6875d70144SGreg Roach            ];
694eb71cfaSGreg Roach        }
7075d70144SGreg Roach
7175d70144SGreg Roach        $links[] = [
72b1f1e4efSGreg Roach            'url'   => $individual->url(),
7375d70144SGreg Roach            'title' => I18N::translate('Default individual'),
7475d70144SGreg Roach            'icon'  => 'icon-indis',
7575d70144SGreg Roach        ];
7675d70144SGreg Roach
7715d603e7SGreg Roach        if (Site::getPreference('USE_REGISTRATION_MODULE') === '1' && !Auth::check()) {
7875d70144SGreg Roach            $links[] = [
79571e6fcaSGreg Roach                'url'   => route('register'),
8075d70144SGreg Roach                'title' => I18N::translate('Request a new user account'),
8175d70144SGreg Roach                'icon'  => 'icon-user_add',
8275d70144SGreg Roach            ];
838c2e8227SGreg Roach        }
8475d70144SGreg Roach
85147e99aaSGreg Roach        $content = view('modules/gedcom_block/welcome', ['links' => $links]);
868c2e8227SGreg Roach
878c2e8227SGreg Roach        if ($template) {
88147e99aaSGreg Roach            return view('modules/block-template', [
89d034ca3bSGreg Roach                'block'      => str_replace('_', '-', $this->getName()),
90d034ca3bSGreg Roach                'id'         => $block_id,
911fa06fe3SGreg Roach                'config_url' => '',
9275d70144SGreg Roach                'title'      => $individual->getTree()->getTitle(),
9375d70144SGreg Roach                'content'    => $content,
9475d70144SGreg Roach            ]);
958c2e8227SGreg Roach        } else {
968c2e8227SGreg Roach            return $content;
978c2e8227SGreg Roach        }
988c2e8227SGreg Roach    }
998c2e8227SGreg Roach
1008c2e8227SGreg Roach    /** {@inheritdoc} */
101c1010edaSGreg Roach    public function loadAjax(): bool
102c1010edaSGreg Roach    {
1038c2e8227SGreg Roach        return false;
1048c2e8227SGreg Roach    }
1058c2e8227SGreg Roach
1068c2e8227SGreg Roach    /** {@inheritdoc} */
107c1010edaSGreg Roach    public function isUserBlock(): bool
108c1010edaSGreg Roach    {
1098c2e8227SGreg Roach        return false;
1108c2e8227SGreg Roach    }
1118c2e8227SGreg Roach
1128c2e8227SGreg Roach    /** {@inheritdoc} */
113c1010edaSGreg Roach    public function isGedcomBlock(): bool
114c1010edaSGreg Roach    {
1158c2e8227SGreg Roach        return true;
1168c2e8227SGreg Roach    }
1178c2e8227SGreg Roach
11876692c8bSGreg Roach    /**
119a45f9889SGreg Roach     * Update the configuration for a block.
120a45f9889SGreg Roach     *
121a45f9889SGreg Roach     * @param Request $request
122a45f9889SGreg Roach     * @param int     $block_id
123a45f9889SGreg Roach     *
124a45f9889SGreg Roach     * @return void
125a45f9889SGreg Roach     */
126a45f9889SGreg Roach    public function saveBlockConfiguration(Request $request, int $block_id)
127a45f9889SGreg Roach    {
128a45f9889SGreg Roach    }
129a45f9889SGreg Roach
130a45f9889SGreg Roach    /**
13176692c8bSGreg Roach     * An HTML form to edit block settings
13276692c8bSGreg Roach     *
133e490cd80SGreg Roach     * @param Tree $tree
13476692c8bSGreg Roach     * @param int  $block_id
135a9430be8SGreg Roach     *
136a9430be8SGreg Roach     * @return void
13776692c8bSGreg Roach     */
138a45f9889SGreg Roach    public function editBlockConfiguration(Tree $tree, int $block_id)
139c1010edaSGreg Roach    {
1408c2e8227SGreg Roach    }
1418c2e8227SGreg Roach}
142