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