xref: /webtrees/app/Module/UserWelcomeModule.php (revision e490cd80ad2d75f9f6adf9b41698ad3f3f058276)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roach/**
38c2e8227SGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 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;
19a0ebf380SGreg Roachuse Fisharebest\Webtrees\Html;
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
21a0ebf380SGreg Roachuse Fisharebest\Webtrees\Individual;
224eb71cfaSGreg Roachuse Fisharebest\Webtrees\Module;
23*e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
248c2e8227SGreg Roach
258c2e8227SGreg Roach/**
268c2e8227SGreg Roach * Class UserWelcomeModule
278c2e8227SGreg Roach */
28e2a378d3SGreg Roachclass UserWelcomeModule extends AbstractModule implements ModuleBlockInterface {
298c2e8227SGreg Roach	/** {@inheritdoc} */
308c2e8227SGreg Roach	public function getTitle() {
31d034ca3bSGreg Roach		return /* I18N: Name of a module */
32d034ca3bSGreg Roach			I18N::translate('My page');
338c2e8227SGreg Roach	}
348c2e8227SGreg Roach
358c2e8227SGreg Roach	/** {@inheritdoc} */
368c2e8227SGreg Roach	public function getDescription() {
37d034ca3bSGreg Roach		return /* I18N: Description of the “My page” module */
38d034ca3bSGreg Roach			I18N::translate('A greeting message and useful links for a user.');
398c2e8227SGreg Roach	}
408c2e8227SGreg Roach
4176692c8bSGreg Roach	/**
4276692c8bSGreg Roach	 * Generate the HTML content of this block.
4376692c8bSGreg Roach	 *
44*e490cd80SGreg Roach	 * @param Tree     $tree
4576692c8bSGreg Roach	 * @param int      $block_id
4676692c8bSGreg Roach	 * @param bool     $template
47727f238cSGreg Roach	 * @param string[] $cfg
4876692c8bSGreg Roach	 *
4976692c8bSGreg Roach	 * @return string
5076692c8bSGreg Roach	 */
51*e490cd80SGreg Roach	public function getBlock(Tree $tree, int $block_id, bool $template = true, array $cfg = []): string {
52*e490cd80SGreg Roach		$gedcomid   = $tree->getUserPreference(Auth::user(), 'gedcomid');
53*e490cd80SGreg Roach		$individual = Individual::getInstance($gedcomid, $tree);
54a0ebf380SGreg Roach		$links      = [];
55a0ebf380SGreg Roach
56c2faa3efSGreg Roach		if ($individual) {
57*e490cd80SGreg Roach			if (Module::isActiveChart($tree, 'pedigree_chart')) {
58a0ebf380SGreg Roach				$links[] = [
5946e0c9f2SGreg Roach					'url'   => route('pedigree', ['xref' => $individual->getXref(), 'ged' => $individual->getTree()->getName()]),
60a0ebf380SGreg Roach					'title' => I18N::translate('Default chart'),
61a0ebf380SGreg Roach					'icon'  => 'icon-pedigree',
62a0ebf380SGreg Roach				];
633f8a84f7SDavid Drury			}
64a0ebf380SGreg Roach
65a0ebf380SGreg Roach			$links[] = [
66b1f1e4efSGreg Roach				'url'   => $individual->url(),
67a0ebf380SGreg Roach				'title' => I18N::translate('My individual record'),
68a0ebf380SGreg Roach				'icon'  => 'icon-indis',
69a0ebf380SGreg Roach			];
708c2e8227SGreg Roach		}
71a0ebf380SGreg Roach
72a0ebf380SGreg Roach		$links[] = [
734653dc2eSGreg Roach			'url'   => route('my-account', []),
74a0ebf380SGreg Roach			'title' => I18N::translate('My account'),
75a0ebf380SGreg Roach			'icon'  => 'icon-mypage',
76a0ebf380SGreg Roach		];
77225e381fSGreg Roach		$content = view('blocks/welcome', ['links' => $links]);
788c2e8227SGreg Roach
798c2e8227SGreg Roach		if ($template) {
80225e381fSGreg Roach			return view('blocks/template', [
81d034ca3bSGreg Roach				'block'      => str_replace('_', '-', $this->getName()),
82d034ca3bSGreg Roach				'id'         => $block_id,
831fa06fe3SGreg Roach				'config_url' => '',
84d034ca3bSGreg Roach				'title'      => /* I18N: A %s is the user’s name */ I18N::translate('Welcome %s', Auth::user()->getRealName()),
85a0ebf380SGreg Roach				'content'    => $content,
86a0ebf380SGreg Roach			]);
878c2e8227SGreg Roach		} else {
888c2e8227SGreg Roach			return $content;
898c2e8227SGreg Roach		}
908c2e8227SGreg Roach	}
918c2e8227SGreg Roach
928c2e8227SGreg Roach	/** {@inheritdoc} */
93a9430be8SGreg Roach	public function loadAjax(): bool {
948c2e8227SGreg Roach		return false;
958c2e8227SGreg Roach	}
968c2e8227SGreg Roach
978c2e8227SGreg Roach	/** {@inheritdoc} */
98a9430be8SGreg Roach	public function isUserBlock(): bool {
998c2e8227SGreg Roach		return true;
1008c2e8227SGreg Roach	}
1018c2e8227SGreg Roach
1028c2e8227SGreg Roach	/** {@inheritdoc} */
103a9430be8SGreg Roach	public function isGedcomBlock(): bool {
1048c2e8227SGreg Roach		return false;
1058c2e8227SGreg Roach	}
1068c2e8227SGreg Roach
10776692c8bSGreg Roach	/**
10876692c8bSGreg Roach	 * An HTML form to edit block settings
10976692c8bSGreg Roach	 *
110*e490cd80SGreg Roach	 * @param Tree $tree
11176692c8bSGreg Roach	 * @param int  $block_id
112a9430be8SGreg Roach	 *
113a9430be8SGreg Roach	 * @return void
11476692c8bSGreg Roach	 */
115*e490cd80SGreg Roach	public function configureBlock(Tree $tree, int $block_id) {
1168c2e8227SGreg Roach	}
1178c2e8227SGreg Roach}
118