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