18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 88c2e8227SGreg Roach * (at your option) any later version. 98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128c2e8227SGreg Roach * GNU General Public License for more details. 138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 158c2e8227SGreg Roach */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1976692c8bSGreg Roach 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 210e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 224ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 230e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site; 24e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree; 25*1e7a7a28SGreg Roachuse Illuminate\Support\Str; 26a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request; 278c2e8227SGreg Roach 288c2e8227SGreg Roach/** 298c2e8227SGreg Roach * Class WelcomeBlockModule 308c2e8227SGreg Roach */ 3137eb8894SGreg Roachclass WelcomeBlockModule extends AbstractModule implements ModuleBlockInterface 32c1010edaSGreg Roach{ 3349a243cbSGreg Roach use ModuleBlockTrait; 3449a243cbSGreg Roach 35961ec755SGreg Roach /** 364ca7e03cSGreg Roach * @var ModuleService 374ca7e03cSGreg Roach */ 384ca7e03cSGreg Roach private $module_service; 394ca7e03cSGreg Roach 404ca7e03cSGreg Roach /** 414ca7e03cSGreg Roach * UserWelcomeModule constructor. 424ca7e03cSGreg Roach * 434ca7e03cSGreg Roach * @param ModuleService $module_service 444ca7e03cSGreg Roach */ 454ca7e03cSGreg Roach public function __construct(ModuleService $module_service) 464ca7e03cSGreg Roach { 474ca7e03cSGreg Roach $this->module_service = $module_service; 484ca7e03cSGreg Roach } 494ca7e03cSGreg Roach 504ca7e03cSGreg Roach /** 510cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 52961ec755SGreg Roach * 53961ec755SGreg Roach * @return string 54961ec755SGreg Roach */ 5549a243cbSGreg Roach public function title(): string 56c1010edaSGreg Roach { 57bbb76c12SGreg Roach /* I18N: Name of a module */ 58bbb76c12SGreg Roach return I18N::translate('Home page'); 598c2e8227SGreg Roach } 608c2e8227SGreg Roach 61961ec755SGreg Roach /** 62961ec755SGreg Roach * A sentence describing what this module does. 63961ec755SGreg Roach * 64961ec755SGreg Roach * @return string 65961ec755SGreg Roach */ 6649a243cbSGreg Roach public function description(): string 67c1010edaSGreg Roach { 68bbb76c12SGreg Roach /* I18N: Description of the “Home page” module */ 69bbb76c12SGreg Roach return I18N::translate('A greeting message for site visitors.'); 708c2e8227SGreg Roach } 718c2e8227SGreg Roach 7276692c8bSGreg Roach /** 7376692c8bSGreg Roach * Generate the HTML content of this block. 7476692c8bSGreg Roach * 75e490cd80SGreg Roach * @param Tree $tree 7676692c8bSGreg Roach * @param int $block_id 775f2ae573SGreg Roach * @param string $ctype 78727f238cSGreg Roach * @param string[] $cfg 7976692c8bSGreg Roach * 8076692c8bSGreg Roach * @return string 8176692c8bSGreg Roach */ 825f2ae573SGreg Roach public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string 83c1010edaSGreg Roach { 84af343084SGreg Roach $individual = $tree->significantIndividual(Auth::user()); 8575d70144SGreg Roach 8675d70144SGreg Roach $links = []; 8775d70144SGreg Roach 8887cca37cSGreg Roach $pedigree_chart = $this->module_service->findByComponent(ModuleChartInterface::class, $tree, Auth::user()) 8949a243cbSGreg Roach ->filter(function (ModuleInterface $module): bool { 9049a243cbSGreg Roach return $module instanceof PedigreeChartModule; 9149a243cbSGreg Roach }); 9249a243cbSGreg Roach 9349a243cbSGreg Roach if ($pedigree_chart instanceof PedigreeChartModule) { 9475d70144SGreg Roach $links[] = [ 95c1010edaSGreg Roach 'url' => route('pedigree', [ 96c0935879SGreg Roach 'xref' => $individual->xref(), 97f4afa648SGreg Roach 'ged' => $individual->tree()->name(), 98c1010edaSGreg Roach ]), 9975d70144SGreg Roach 'title' => I18N::translate('Default chart'), 10075d70144SGreg Roach 'icon' => 'icon-pedigree', 10175d70144SGreg Roach ]; 1024eb71cfaSGreg Roach } 10375d70144SGreg Roach 10475d70144SGreg Roach $links[] = [ 105b1f1e4efSGreg Roach 'url' => $individual->url(), 10675d70144SGreg Roach 'title' => I18N::translate('Default individual'), 10775d70144SGreg Roach 'icon' => 'icon-indis', 10875d70144SGreg Roach ]; 10975d70144SGreg Roach 11015d603e7SGreg Roach if (Site::getPreference('USE_REGISTRATION_MODULE') === '1' && !Auth::check()) { 11175d70144SGreg Roach $links[] = [ 112571e6fcaSGreg Roach 'url' => route('register'), 11375d70144SGreg Roach 'title' => I18N::translate('Request a new user account'), 11475d70144SGreg Roach 'icon' => 'icon-user_add', 11575d70144SGreg Roach ]; 1168c2e8227SGreg Roach } 11775d70144SGreg Roach 118147e99aaSGreg Roach $content = view('modules/gedcom_block/welcome', ['links' => $links]); 1198c2e8227SGreg Roach 1206a8879feSGreg Roach if ($ctype !== '') { 121147e99aaSGreg Roach return view('modules/block-template', [ 122*1e7a7a28SGreg Roach 'block' => Str::kebab($this->name()), 123d034ca3bSGreg Roach 'id' => $block_id, 1241fa06fe3SGreg Roach 'config_url' => '', 125f4afa648SGreg Roach 'title' => $individual->tree()->title(), 12675d70144SGreg Roach 'content' => $content, 12775d70144SGreg Roach ]); 1288c2e8227SGreg Roach } 129b2ce94c6SRico Sonntag 130b2ce94c6SRico Sonntag return $content; 1318c2e8227SGreg Roach } 1328c2e8227SGreg Roach 1338c2e8227SGreg Roach /** {@inheritdoc} */ 134c1010edaSGreg Roach public function loadAjax(): bool 135c1010edaSGreg Roach { 1368c2e8227SGreg Roach return false; 1378c2e8227SGreg Roach } 1388c2e8227SGreg Roach 1398c2e8227SGreg Roach /** {@inheritdoc} */ 140c1010edaSGreg Roach public function isUserBlock(): bool 141c1010edaSGreg Roach { 1428c2e8227SGreg Roach return false; 1438c2e8227SGreg Roach } 1448c2e8227SGreg Roach 1458c2e8227SGreg Roach /** {@inheritdoc} */ 14663276d8fSGreg Roach public function isTreeBlock(): bool 147c1010edaSGreg Roach { 1488c2e8227SGreg Roach return true; 1498c2e8227SGreg Roach } 1508c2e8227SGreg Roach 15176692c8bSGreg Roach /** 152a45f9889SGreg Roach * Update the configuration for a block. 153a45f9889SGreg Roach * 154a45f9889SGreg Roach * @param Request $request 155a45f9889SGreg Roach * @param int $block_id 156a45f9889SGreg Roach * 157a45f9889SGreg Roach * @return void 158a45f9889SGreg Roach */ 159e364afe4SGreg Roach public function saveBlockConfiguration(Request $request, int $block_id): void 160a45f9889SGreg Roach { 161a45f9889SGreg Roach } 162a45f9889SGreg Roach 163a45f9889SGreg Roach /** 16476692c8bSGreg Roach * An HTML form to edit block settings 16576692c8bSGreg Roach * 166e490cd80SGreg Roach * @param Tree $tree 16776692c8bSGreg Roach * @param int $block_id 168a9430be8SGreg Roach * 169a9430be8SGreg Roach * @return void 17076692c8bSGreg Roach */ 171e364afe4SGreg Roach public function editBlockConfiguration(Tree $tree, int $block_id): void 172c1010edaSGreg Roach { 1738c2e8227SGreg Roach } 1748c2e8227SGreg Roach} 175