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 /* I18N: Name of a module */ 33 return I18N::translate('My page'); 34 } 35 36 /** {@inheritdoc} */ 37 public function getDescription() 38 { 39 /* I18N: Description of the “My page” module */ 40 return 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 /* I18N: A %s is the user’s name */ 86 $title = I18N::translate('Welcome %s', Auth::user()->getRealName()); 87 88 if ($template) { 89 return view('modules/block-template', [ 90 'block' => str_replace('_', '-', $this->getName()), 91 'id' => $block_id, 92 'config_url' => '', 93 'title' => $title, 94 'content' => $content, 95 ]); 96 } else { 97 return $content; 98 } 99 } 100 101 /** {@inheritdoc} */ 102 public function loadAjax(): bool 103 { 104 return false; 105 } 106 107 /** {@inheritdoc} */ 108 public function isUserBlock(): bool 109 { 110 return true; 111 } 112 113 /** {@inheritdoc} */ 114 public function isGedcomBlock(): bool 115 { 116 return false; 117 } 118 119 /** 120 * An HTML form to edit block settings 121 * 122 * @param Tree $tree 123 * @param int $block_id 124 * 125 * @return void 126 */ 127 public function configureBlock(Tree $tree, int $block_id) 128 { 129 } 130} 131