18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 48fcd0d32SGreg Roach * Copyright (C) 2019 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 */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1976692c8bSGreg Roach 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 210e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 22a0ebf380SGreg Roachuse Fisharebest\Webtrees\Individual; 234eb71cfaSGreg Roachuse Fisharebest\Webtrees\Module; 24e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree; 25a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request; 268c2e8227SGreg Roach 278c2e8227SGreg Roach/** 288c2e8227SGreg Roach * Class UserWelcomeModule 298c2e8227SGreg Roach */ 3049a243cbSGreg Roachclass UserWelcomeModule extends AbstractModule implements ModuleInterface, ModuleBlockInterface 31c1010edaSGreg Roach{ 3249a243cbSGreg Roach use ModuleBlockTrait; 3349a243cbSGreg Roach 34961ec755SGreg Roach /** 35961ec755SGreg Roach * How should this module be labelled on tabs, menus, etc.? 36961ec755SGreg Roach * 37961ec755SGreg Roach * @return string 38961ec755SGreg Roach */ 3949a243cbSGreg Roach public function title(): string 40c1010edaSGreg Roach { 41bbb76c12SGreg Roach /* I18N: Name of a module */ 42bbb76c12SGreg Roach return I18N::translate('My page'); 438c2e8227SGreg Roach } 448c2e8227SGreg Roach 45961ec755SGreg Roach /** 46961ec755SGreg Roach * A sentence describing what this module does. 47961ec755SGreg Roach * 48961ec755SGreg Roach * @return string 49961ec755SGreg Roach */ 5049a243cbSGreg Roach public function description(): string 51c1010edaSGreg Roach { 52bbb76c12SGreg Roach /* I18N: Description of the “My page” module */ 53bbb76c12SGreg Roach return I18N::translate('A greeting message and useful links for a user.'); 548c2e8227SGreg Roach } 558c2e8227SGreg Roach 5676692c8bSGreg Roach /** 5776692c8bSGreg Roach * Generate the HTML content of this block. 5876692c8bSGreg Roach * 59e490cd80SGreg Roach * @param Tree $tree 6076692c8bSGreg Roach * @param int $block_id 615f2ae573SGreg Roach * @param string $ctype 62727f238cSGreg Roach * @param string[] $cfg 6376692c8bSGreg Roach * 6476692c8bSGreg Roach * @return string 6576692c8bSGreg Roach */ 665f2ae573SGreg Roach public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string 67c1010edaSGreg Roach { 68e490cd80SGreg Roach $gedcomid = $tree->getUserPreference(Auth::user(), 'gedcomid'); 69e490cd80SGreg Roach $individual = Individual::getInstance($gedcomid, $tree); 70a0ebf380SGreg Roach $links = []; 71a0ebf380SGreg Roach 7249a243cbSGreg Roach $pedigree_chart = Module::activeCharts($tree) 7349a243cbSGreg Roach ->filter(function (ModuleInterface $module): bool { 7449a243cbSGreg Roach return $module instanceof PedigreeChartModule; 7549a243cbSGreg Roach }); 7649a243cbSGreg Roach 7749a243cbSGreg Roach if ($individual instanceof Individual) { 7849a243cbSGreg Roach if ($pedigree_chart instanceof PedigreeChartModule) { 79a0ebf380SGreg Roach $links[] = [ 80c1010edaSGreg Roach 'url' => route('pedigree', [ 81c0935879SGreg Roach 'xref' => $individual->xref(), 82f4afa648SGreg Roach 'ged' => $individual->tree()->name(), 83c1010edaSGreg Roach ]), 84a0ebf380SGreg Roach 'title' => I18N::translate('Default chart'), 85a0ebf380SGreg Roach 'icon' => 'icon-pedigree', 86a0ebf380SGreg Roach ]; 873f8a84f7SDavid Drury } 88a0ebf380SGreg Roach 89a0ebf380SGreg Roach $links[] = [ 90b1f1e4efSGreg Roach 'url' => $individual->url(), 91a0ebf380SGreg Roach 'title' => I18N::translate('My individual record'), 92a0ebf380SGreg Roach 'icon' => 'icon-indis', 93a0ebf380SGreg Roach ]; 948c2e8227SGreg Roach } 95a0ebf380SGreg Roach 96a0ebf380SGreg Roach $links[] = [ 974653dc2eSGreg Roach 'url' => route('my-account', []), 98a0ebf380SGreg Roach 'title' => I18N::translate('My account'), 99a0ebf380SGreg Roach 'icon' => 'icon-mypage', 100a0ebf380SGreg Roach ]; 101147e99aaSGreg Roach $content = view('modules/user_welcome/welcome', ['links' => $links]); 1028c2e8227SGreg Roach 103334b74ddSGreg Roach $real_name = '<span dir="auto">' . e(Auth::user()->getRealName()) . '</span>'; 104334b74ddSGreg Roach 105bbb76c12SGreg Roach /* I18N: A %s is the user’s name */ 106334b74ddSGreg Roach $title = I18N::translate('Welcome %s', $real_name); 107bbb76c12SGreg Roach 1086a8879feSGreg Roach if ($ctype !== '') { 109147e99aaSGreg Roach return view('modules/block-template', [ 110*26684e68SGreg Roach 'block' => str_replace('_', '-', $this->name()), 111d034ca3bSGreg Roach 'id' => $block_id, 1121fa06fe3SGreg Roach 'config_url' => '', 113bbb76c12SGreg Roach 'title' => $title, 114a0ebf380SGreg Roach 'content' => $content, 115a0ebf380SGreg Roach ]); 1168c2e8227SGreg Roach } 117b2ce94c6SRico Sonntag 118b2ce94c6SRico Sonntag return $content; 1198c2e8227SGreg Roach } 1208c2e8227SGreg Roach 1218c2e8227SGreg Roach /** {@inheritdoc} */ 122c1010edaSGreg Roach public function loadAjax(): bool 123c1010edaSGreg Roach { 1248c2e8227SGreg Roach return false; 1258c2e8227SGreg Roach } 1268c2e8227SGreg Roach 1278c2e8227SGreg Roach /** {@inheritdoc} */ 128c1010edaSGreg Roach public function isUserBlock(): bool 129c1010edaSGreg Roach { 1308c2e8227SGreg Roach return true; 1318c2e8227SGreg Roach } 1328c2e8227SGreg Roach 1338c2e8227SGreg Roach /** {@inheritdoc} */ 134c1010edaSGreg Roach public function isGedcomBlock(): bool 135c1010edaSGreg Roach { 1368c2e8227SGreg Roach return false; 1378c2e8227SGreg Roach } 1388c2e8227SGreg Roach 13976692c8bSGreg Roach /** 140a45f9889SGreg Roach * Update the configuration for a block. 141a45f9889SGreg Roach * 142a45f9889SGreg Roach * @param Request $request 143a45f9889SGreg Roach * @param int $block_id 144a45f9889SGreg Roach * 145a45f9889SGreg Roach * @return void 146a45f9889SGreg Roach */ 147a45f9889SGreg Roach public function saveBlockConfiguration(Request $request, int $block_id) 148a45f9889SGreg Roach { 149a45f9889SGreg Roach } 150a45f9889SGreg Roach 151a45f9889SGreg Roach /** 15276692c8bSGreg Roach * An HTML form to edit block settings 15376692c8bSGreg Roach * 154e490cd80SGreg Roach * @param Tree $tree 15576692c8bSGreg Roach * @param int $block_id 156a9430be8SGreg Roach * 157a9430be8SGreg Roach * @return void 15876692c8bSGreg Roach */ 159a45f9889SGreg Roach public function editBlockConfiguration(Tree $tree, int $block_id) 160c1010edaSGreg Roach { 1618c2e8227SGreg Roach } 1628c2e8227SGreg Roach} 163