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; 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 int $block_id 44 * @param bool $template 45 * @param string[] $cfg 46 * 47 * @return string 48 */ 49 public function getBlock($block_id, $template = true, $cfg = []): string { 50 global $WT_TREE; 51 52 $gedcomid = $WT_TREE->getUserPreference(Auth::user(), 'gedcomid'); 53 $individual = Individual::getInstance($gedcomid, $WT_TREE); 54 $links = []; 55 56 if ($individual) { 57 if (Module::isActiveChart($WT_TREE, 'pedigree_chart')) { 58 $links[] = [ 59 'url' => Html::url('pedigree.php', ['rootid' => $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' => Html::url('edituser.php', []), 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 int $block_id 111 * 112 * @return void 113 */ 114 public function configureBlock($block_id) { 115 } 116} 117