xref: /webtrees/app/Module/WelcomeBlockModule.php (revision be9a728c03bbf624813113eeca03830a7825a5b1)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roach/**
38c2e8227SGreg Roach * webtrees: online genealogy
46bdf7674SGreg Roach * Copyright (C) 2017 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;
1975d70144SGreg Roachuse Fisharebest\Webtrees\Html;
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
214eb71cfaSGreg Roachuse Fisharebest\Webtrees\Module;
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site;
2375d70144SGreg Roachuse Fisharebest\Webtrees\View;
248c2e8227SGreg Roach
258c2e8227SGreg Roach/**
268c2e8227SGreg Roach * Class WelcomeBlockModule
278c2e8227SGreg Roach */
28e2a378d3SGreg Roachclass WelcomeBlockModule extends AbstractModule implements ModuleBlockInterface {
298c2e8227SGreg Roach	/** {@inheritdoc} */
308c2e8227SGreg Roach	public function getTitle() {
3175d70144SGreg Roach		return /* I18N: Name of a module */
3275d70144SGreg Roach			I18N::translate('Home page');
338c2e8227SGreg Roach	}
348c2e8227SGreg Roach
358c2e8227SGreg Roach	/** {@inheritdoc} */
368c2e8227SGreg Roach	public function getDescription() {
3775d70144SGreg Roach		return /* I18N: Description of the “Home page” module */
3875d70144SGreg Roach			I18N::translate('A greeting message for site visitors.');
398c2e8227SGreg Roach	}
408c2e8227SGreg Roach
4176692c8bSGreg Roach	/**
4276692c8bSGreg Roach	 * Generate the HTML content of this block.
4376692c8bSGreg Roach	 *
4476692c8bSGreg Roach	 * @param int      $block_id
4576692c8bSGreg Roach	 * @param bool     $template
46727f238cSGreg Roach	 * @param string[] $cfg
4776692c8bSGreg Roach	 *
4876692c8bSGreg Roach	 * @return string
4976692c8bSGreg Roach	 */
50a9430be8SGreg Roach	public function getBlock($block_id, $template = true, $cfg = []): string {
5175d70144SGreg Roach		global $controller;
528c2e8227SGreg Roach
5375d70144SGreg Roach		$individual = $controller->getSignificantIndividual();
5475d70144SGreg Roach
5575d70144SGreg Roach		$links = [];
5675d70144SGreg Roach
5775d70144SGreg Roach		if (Module::isActiveChart($individual->getTree(), 'pedigree_chart')) {
5875d70144SGreg Roach			$links[] = [
5975d70144SGreg Roach				'url'   => Html::url('pedigree.php', ['rootid' => $individual->getXref(), 'ged' => $individual->getTree()->getName()]),
6075d70144SGreg Roach				'title' => I18N::translate('Default chart'),
6175d70144SGreg Roach				'icon'  => 'icon-pedigree',
6275d70144SGreg Roach			];
634eb71cfaSGreg Roach		}
6475d70144SGreg Roach
6575d70144SGreg Roach		$links[] = [
6675d70144SGreg Roach			'url'   => $individual->getRawUrl(),
6775d70144SGreg Roach			'title' => I18N::translate('Default individual'),
6875d70144SGreg Roach			'icon'  => 'icon-indis',
6975d70144SGreg Roach		];
7075d70144SGreg Roach
7115d603e7SGreg Roach		if (Site::getPreference('USE_REGISTRATION_MODULE') === '1' && !Auth::check()) {
7275d70144SGreg Roach			$links[] = [
7375d70144SGreg Roach				'url'   => Html::url(WT_LOGIN_URL, ['action' => 'register']),
7475d70144SGreg Roach				'title' => I18N::translate('Request a new user account'),
7575d70144SGreg Roach				'icon'  => 'icon-user_add',
7675d70144SGreg Roach			];
778c2e8227SGreg Roach		}
7875d70144SGreg Roach
7975d70144SGreg Roach		$content = View::make('blocks/welcome', ['links' => $links]);
808c2e8227SGreg Roach
818c2e8227SGreg Roach		if ($template) {
8275d70144SGreg Roach			return View::make('blocks/template', [
83d034ca3bSGreg Roach				'block'      => str_replace('_', '-', $this->getName()),
84d034ca3bSGreg Roach				'id'         => $block_id,
851fa06fe3SGreg Roach				'config_url' => '',
8675d70144SGreg Roach				'title'      => $individual->getTree()->getTitle(),
8775d70144SGreg Roach				'content'    => $content,
8875d70144SGreg Roach			]);
898c2e8227SGreg Roach		} else {
908c2e8227SGreg Roach			return $content;
918c2e8227SGreg Roach		}
928c2e8227SGreg Roach	}
938c2e8227SGreg Roach
948c2e8227SGreg Roach	/** {@inheritdoc} */
95a9430be8SGreg Roach	public function loadAjax(): bool {
968c2e8227SGreg Roach		return false;
978c2e8227SGreg Roach	}
988c2e8227SGreg Roach
998c2e8227SGreg Roach	/** {@inheritdoc} */
100a9430be8SGreg Roach	public function isUserBlock(): bool {
1018c2e8227SGreg Roach		return false;
1028c2e8227SGreg Roach	}
1038c2e8227SGreg Roach
1048c2e8227SGreg Roach	/** {@inheritdoc} */
105a9430be8SGreg Roach	public function isGedcomBlock(): bool {
1068c2e8227SGreg Roach		return true;
1078c2e8227SGreg Roach	}
1088c2e8227SGreg Roach
10976692c8bSGreg Roach	/**
11076692c8bSGreg Roach	 * An HTML form to edit block settings
11176692c8bSGreg Roach	 *
11276692c8bSGreg Roach	 * @param int $block_id
113a9430be8SGreg Roach	 *
114a9430be8SGreg Roach	 * @return void
11576692c8bSGreg Roach	 */
116*be9a728cSGreg Roach	public function configureBlock($block_id) {
1178c2e8227SGreg Roach	}
1188c2e8227SGreg Roach}
119