xref: /webtrees/app/Module/UserWelcomeModule.php (revision 911f5683b68340b4bad2bbca6e1ab7a3a15f46a7)
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\Individual;
22use Fisharebest\Webtrees\Module;
23use Fisharebest\Webtrees\Tree;
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 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		$gedcomid   = $tree->getUserPreference(Auth::user(), 'gedcomid');
53		$individual = Individual::getInstance($gedcomid, $tree);
54		$links      = [];
55
56		if ($individual) {
57			if (Module::isActiveChart($tree, 'pedigree_chart')) {
58				$links[] = [
59					'url'   => route('pedigree', ['xref' => $individual->getXref(), 'ged' => $individual->getTree()->getName()]),
60					'title' => I18N::translate('Default chart'),
61					'icon'  => 'icon-pedigree',
62				];
63			}
64
65			$links[] = [
66				'url'   => $individual->url(),
67				'title' => I18N::translate('My individual record'),
68				'icon'  => 'icon-indis',
69			];
70		}
71
72		$links[] = [
73			'url'   => route('my-account', []),
74			'title' => I18N::translate('My account'),
75			'icon'  => 'icon-mypage',
76		];
77		$content = view('blocks/welcome', ['links' => $links]);
78
79		if ($template) {
80			return view('blocks/template', [
81				'block'      => str_replace('_', '-', $this->getName()),
82				'id'         => $block_id,
83				'config_url' => '',
84				'title'      => /* I18N: A %s is the user’s name */ I18N::translate('Welcome %s', Auth::user()->getRealName()),
85				'content'    => $content,
86			]);
87		} else {
88			return $content;
89		}
90	}
91
92	/** {@inheritdoc} */
93	public function loadAjax(): bool {
94		return false;
95	}
96
97	/** {@inheritdoc} */
98	public function isUserBlock(): bool {
99		return true;
100	}
101
102	/** {@inheritdoc} */
103	public function isGedcomBlock(): bool {
104		return false;
105	}
106
107	/**
108	 * An HTML form to edit block settings
109	 *
110	 * @param Tree $tree
111	 * @param int  $block_id
112	 *
113	 * @return void
114	 */
115	public function configureBlock(Tree $tree, int $block_id) {
116	}
117}
118