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