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