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