xref: /webtrees/app/Module/UserWelcomeModule.php (revision 76a5e7c78a07f5736a3cd5b7437c8f18dc196a5e)
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\I18N;
20use Fisharebest\Webtrees\Module;
21use Fisharebest\Webtrees\Theme;
22
23/**
24 * Class UserWelcomeModule
25 */
26class UserWelcomeModule extends AbstractModule implements ModuleBlockInterface {
27	/** {@inheritdoc} */
28	public function getTitle() {
29		return /* I18N: Name of a module */ I18N::translate('My page');
30	}
31
32	/** {@inheritdoc} */
33	public function getDescription() {
34		return /* I18N: Description of the “My page” module */ I18N::translate('A greeting message and useful links for a user.');
35	}
36
37	/**
38	 * Generate the HTML content of this block.
39	 *
40	 * @param int      $block_id
41	 * @param bool     $template
42	 * @param string[] $cfg
43	 *
44	 * @return string
45	 */
46	public function getBlock($block_id, $template = true, $cfg = []) {
47		global $WT_TREE;
48
49		$id      = $this->getName() . $block_id;
50		$class   = $this->getName() . '_block';
51		$title   = /* I18N: A greeting; %s is the user’s name */ I18N::translate('Welcome %s', '<span dir="auto">' . Auth::user()->getRealNameHtml() . '</span>');
52		$content = '<div class="row">';
53		$content .= '<div class="col"><a href="edituser.php"><i class="icon-mypage"></i><br>' . I18N::translate('My account') . '</a></div>';
54
55		$gedcomid = $WT_TREE->getUserPreference(Auth::user(), 'gedcomid');
56
57		if ($gedcomid) {
58			if (Module::isActiveChart($WT_TREE, 'pedigree_chart')) {
59				$content .= '<div class="col"><a href="pedigree.php?rootid=' . $gedcomid . '&amp;ged=' . $WT_TREE->getNameUrl() . '"><i class="icon-pedigree"></i><br>' . I18N::translate('My pedigree') . '</a></div>';
60			}
61			$content .= '<div class="col"><a href="individual.php?pid=' . $gedcomid . '&amp;ged=' . $WT_TREE->getNameUrl() . '"><i class="icon-indis"></i><br>' . I18N::translate('My individual record') . '</a></div>';
62		}
63		$content .= '</div>';
64
65		if ($template) {
66			return Theme::theme()->formatBlock($id, $title, $class, $content);
67		} else {
68			return $content;
69		}
70	}
71
72	/** {@inheritdoc} */
73	public function loadAjax() {
74		return false;
75	}
76
77	/** {@inheritdoc} */
78	public function isUserBlock() {
79		return true;
80	}
81
82	/** {@inheritdoc} */
83	public function isGedcomBlock() {
84		return false;
85	}
86
87	/**
88	 * An HTML form to edit block settings
89	 *
90	 * @param int $block_id
91	 */
92	public function configureBlock($block_id) {
93	}
94}
95