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