xref: /webtrees/app/Module/UserWelcomeModule.php (revision 0a016d046f63b3b1ece7ec913216782c17f0cbad)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2017 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\Individual;
22use Fisharebest\Webtrees\Module;
23use Fisharebest\Webtrees\View;
24
25/**
26 * Class UserWelcomeModule
27 */
28class UserWelcomeModule extends AbstractModule implements ModuleBlockInterface {
29	/** {@inheritdoc} */
30	public function getTitle() {
31		return /* I18N: Name of a module */
32			I18N::translate('My page');
33	}
34
35	/** {@inheritdoc} */
36	public function getDescription() {
37		return /* I18N: Description of the “My page” module */
38			I18N::translate('A greeting message and useful links for a user.');
39	}
40
41	/**
42	 * Generate the HTML content of this block.
43	 *
44	 * @param int      $block_id
45	 * @param bool     $template
46	 * @param string[] $cfg
47	 *
48	 * @return string
49	 */
50	public function getBlock($block_id, $template = true, $cfg = []) {
51		global $WT_TREE;
52
53		$gedcomid   = $WT_TREE->getUserPreference(Auth::user(), 'gedcomid');
54		$individual = Individual::getInstance($gedcomid, $WT_TREE);
55		$links      = [];
56
57		if ($individual) {
58			if (Module::isActiveChart($WT_TREE, 'pedigree_chart')) {
59				$links[] = [
60					'url'   => Html::url('pedigree.php', ['rootid' => $individual->getXref(), 'ged' => $individual->getTree()->getName()]),
61					'title' => I18N::translate('Default chart'),
62					'icon'  => 'icon-pedigree',
63				];
64			}
65
66			$links[] = [
67				'url'   => $individual->getRawUrl(),
68				'title' => I18N::translate('My individual record'),
69				'icon'  => 'icon-indis',
70			];
71		}
72
73		$links[] = [
74			'url'   => Html::url('edituser.php', []),
75			'title' => I18N::translate('My account'),
76			'icon'  => 'icon-mypage',
77		];
78		$content = View::make('blocks/welcome', ['links' => $links]);
79
80		if ($template) {
81			return View::make('blocks/template', [
82				'block'      => str_replace('_', '-', $this->getName()),
83				'id'         => $block_id,
84				'config_url' => '',
85				'title'      => /* I18N: A %s is the user’s name */ I18N::translate('Welcome %s', Auth::user()->getRealName()),
86				'content'    => $content,
87			]);
88		} else {
89			return $content;
90		}
91	}
92
93	/** {@inheritdoc} */
94	public function loadAjax() {
95		return false;
96	}
97
98	/** {@inheritdoc} */
99	public function isUserBlock() {
100		return true;
101	}
102
103	/** {@inheritdoc} */
104	public function isGedcomBlock() {
105		return false;
106	}
107
108	/**
109	 * An HTML form to edit block settings
110	 *
111	 * @param int $block_id
112	 */
113	public function configureBlock($block_id) {
114	}
115}
116