xref: /webtrees/app/Module/WelcomeBlockModule.php (revision c09358794665832df009408551d8543ccb6e3783)
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 */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
1976692c8bSGreg Roach
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
224eb71cfaSGreg Roachuse Fisharebest\Webtrees\Module;
230e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site;
24e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
25a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request;
268c2e8227SGreg Roach
278c2e8227SGreg Roach/**
288c2e8227SGreg Roach * Class WelcomeBlockModule
298c2e8227SGreg Roach */
30c1010edaSGreg Roachclass WelcomeBlockModule extends AbstractModule implements ModuleBlockInterface
31c1010edaSGreg Roach{
328c2e8227SGreg Roach    /** {@inheritdoc} */
338f53f488SRico Sonntag    public function getTitle(): string
34c1010edaSGreg Roach    {
35bbb76c12SGreg Roach        /* I18N: Name of a module */
36bbb76c12SGreg Roach        return I18N::translate('Home page');
378c2e8227SGreg Roach    }
388c2e8227SGreg Roach
398c2e8227SGreg Roach    /** {@inheritdoc} */
408f53f488SRico Sonntag    public function getDescription(): string
41c1010edaSGreg Roach    {
42bbb76c12SGreg Roach        /* I18N: Description of the “Home page” module */
43bbb76c12SGreg Roach        return I18N::translate('A greeting message for site visitors.');
448c2e8227SGreg Roach    }
458c2e8227SGreg Roach
4676692c8bSGreg Roach    /**
4776692c8bSGreg Roach     * Generate the HTML content of this block.
4876692c8bSGreg Roach     *
49e490cd80SGreg Roach     * @param Tree     $tree
5076692c8bSGreg Roach     * @param int      $block_id
5176692c8bSGreg Roach     * @param bool     $template
52727f238cSGreg Roach     * @param string[] $cfg
5376692c8bSGreg Roach     *
5476692c8bSGreg Roach     * @return string
5576692c8bSGreg Roach     */
56c1010edaSGreg Roach    public function getBlock(Tree $tree, int $block_id, bool $template = true, array $cfg = []): string
57c1010edaSGreg Roach    {
585fe1add5SGreg Roach        $individual = $tree->getSignificantIndividual();
5975d70144SGreg Roach
6075d70144SGreg Roach        $links = [];
6175d70144SGreg Roach
6275d70144SGreg Roach        if (Module::isActiveChart($individual->getTree(), 'pedigree_chart')) {
6375d70144SGreg Roach            $links[] = [
64c1010edaSGreg Roach                'url'   => route('pedigree', [
65*c0935879SGreg Roach                    'xref' => $individual->xref(),
66aa6f03bbSGreg Roach                    'ged'  => $individual->getTree()->name(),
67c1010edaSGreg Roach                ]),
6875d70144SGreg Roach                'title' => I18N::translate('Default chart'),
6975d70144SGreg Roach                'icon'  => 'icon-pedigree',
7075d70144SGreg Roach            ];
714eb71cfaSGreg Roach        }
7275d70144SGreg Roach
7375d70144SGreg Roach        $links[] = [
74b1f1e4efSGreg Roach            'url'   => $individual->url(),
7575d70144SGreg Roach            'title' => I18N::translate('Default individual'),
7675d70144SGreg Roach            'icon'  => 'icon-indis',
7775d70144SGreg Roach        ];
7875d70144SGreg Roach
7915d603e7SGreg Roach        if (Site::getPreference('USE_REGISTRATION_MODULE') === '1' && !Auth::check()) {
8075d70144SGreg Roach            $links[] = [
81571e6fcaSGreg Roach                'url'   => route('register'),
8275d70144SGreg Roach                'title' => I18N::translate('Request a new user account'),
8375d70144SGreg Roach                'icon'  => 'icon-user_add',
8475d70144SGreg Roach            ];
858c2e8227SGreg Roach        }
8675d70144SGreg Roach
87147e99aaSGreg Roach        $content = view('modules/gedcom_block/welcome', ['links' => $links]);
888c2e8227SGreg Roach
898c2e8227SGreg Roach        if ($template) {
90147e99aaSGreg Roach            return view('modules/block-template', [
91d034ca3bSGreg Roach                'block'      => str_replace('_', '-', $this->getName()),
92d034ca3bSGreg Roach                'id'         => $block_id,
931fa06fe3SGreg Roach                'config_url' => '',
94cc13d6d8SGreg Roach                'title'      => $individual->getTree()->title(),
9575d70144SGreg Roach                'content'    => $content,
9675d70144SGreg Roach            ]);
978c2e8227SGreg Roach        }
98b2ce94c6SRico Sonntag
99b2ce94c6SRico Sonntag        return $content;
1008c2e8227SGreg Roach    }
1018c2e8227SGreg Roach
1028c2e8227SGreg Roach    /** {@inheritdoc} */
103c1010edaSGreg Roach    public function loadAjax(): bool
104c1010edaSGreg Roach    {
1058c2e8227SGreg Roach        return false;
1068c2e8227SGreg Roach    }
1078c2e8227SGreg Roach
1088c2e8227SGreg Roach    /** {@inheritdoc} */
109c1010edaSGreg Roach    public function isUserBlock(): bool
110c1010edaSGreg Roach    {
1118c2e8227SGreg Roach        return false;
1128c2e8227SGreg Roach    }
1138c2e8227SGreg Roach
1148c2e8227SGreg Roach    /** {@inheritdoc} */
115c1010edaSGreg Roach    public function isGedcomBlock(): bool
116c1010edaSGreg Roach    {
1178c2e8227SGreg Roach        return true;
1188c2e8227SGreg Roach    }
1198c2e8227SGreg Roach
12076692c8bSGreg Roach    /**
121a45f9889SGreg Roach     * Update the configuration for a block.
122a45f9889SGreg Roach     *
123a45f9889SGreg Roach     * @param Request $request
124a45f9889SGreg Roach     * @param int     $block_id
125a45f9889SGreg Roach     *
126a45f9889SGreg Roach     * @return void
127a45f9889SGreg Roach     */
128a45f9889SGreg Roach    public function saveBlockConfiguration(Request $request, int $block_id)
129a45f9889SGreg Roach    {
130a45f9889SGreg Roach    }
131a45f9889SGreg Roach
132a45f9889SGreg Roach    /**
13376692c8bSGreg Roach     * An HTML form to edit block settings
13476692c8bSGreg Roach     *
135e490cd80SGreg Roach     * @param Tree $tree
13676692c8bSGreg Roach     * @param int  $block_id
137a9430be8SGreg Roach     *
138a9430be8SGreg Roach     * @return void
13976692c8bSGreg Roach     */
140a45f9889SGreg Roach    public function editBlockConfiguration(Tree $tree, int $block_id)
141c1010edaSGreg Roach    {
1428c2e8227SGreg Roach    }
1438c2e8227SGreg Roach}
144