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\Module; 23use Fisharebest\Webtrees\Site; 24use Fisharebest\Webtrees\Tree; 25use Symfony\Component\HttpFoundation\Request; 26 27/** 28 * Class WelcomeBlockModule 29 */ 30class WelcomeBlockModule extends AbstractModule implements ModuleBlockInterface 31{ 32 use ModuleBlockTrait; 33 34 /** 35 * How should this module be labelled on tabs, menus, etc.? 36 * 37 * @return string 38 */ 39 public function title(): string 40 { 41 /* I18N: Name of a module */ 42 return I18N::translate('Home page'); 43 } 44 45 /** 46 * A sentence describing what this module does. 47 * 48 * @return string 49 */ 50 public function description(): string 51 { 52 /* I18N: Description of the “Home page” module */ 53 return I18N::translate('A greeting message for site visitors.'); 54 } 55 56 /** 57 * Generate the HTML content of this block. 58 * 59 * @param Tree $tree 60 * @param int $block_id 61 * @param string $ctype 62 * @param string[] $cfg 63 * 64 * @return string 65 */ 66 public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string 67 { 68 $individual = $tree->significantIndividual(Auth::user()); 69 70 $links = []; 71 72 $pedigree_chart = Module::findByComponent('chart', $tree, Auth::user()) 73 ->filter(function (ModuleInterface $module): bool { 74 return $module instanceof PedigreeChartModule; 75 }); 76 77 if ($pedigree_chart instanceof PedigreeChartModule) { 78 $links[] = [ 79 'url' => route('pedigree', [ 80 'xref' => $individual->xref(), 81 'ged' => $individual->tree()->name(), 82 ]), 83 'title' => I18N::translate('Default chart'), 84 'icon' => 'icon-pedigree', 85 ]; 86 } 87 88 $links[] = [ 89 'url' => $individual->url(), 90 'title' => I18N::translate('Default individual'), 91 'icon' => 'icon-indis', 92 ]; 93 94 if (Site::getPreference('USE_REGISTRATION_MODULE') === '1' && !Auth::check()) { 95 $links[] = [ 96 'url' => route('register'), 97 'title' => I18N::translate('Request a new user account'), 98 'icon' => 'icon-user_add', 99 ]; 100 } 101 102 $content = view('modules/gedcom_block/welcome', ['links' => $links]); 103 104 if ($ctype !== '') { 105 return view('modules/block-template', [ 106 'block' => str_replace('_', '-', $this->name()), 107 'id' => $block_id, 108 'config_url' => '', 109 'title' => $individual->tree()->title(), 110 'content' => $content, 111 ]); 112 } 113 114 return $content; 115 } 116 117 /** {@inheritdoc} */ 118 public function loadAjax(): bool 119 { 120 return false; 121 } 122 123 /** {@inheritdoc} */ 124 public function isUserBlock(): bool 125 { 126 return false; 127 } 128 129 /** {@inheritdoc} */ 130 public function isTreeBlock(): bool 131 { 132 return true; 133 } 134 135 /** 136 * Update the configuration for a block. 137 * 138 * @param Request $request 139 * @param int $block_id 140 * 141 * @return void 142 */ 143 public function saveBlockConfiguration(Request $request, int $block_id) 144 { 145 } 146 147 /** 148 * An HTML form to edit block settings 149 * 150 * @param Tree $tree 151 * @param int $block_id 152 * 153 * @return void 154 */ 155 public function editBlockConfiguration(Tree $tree, int $block_id) 156 { 157 } 158} 159