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