18c2e8227SGreg Roach<?php 23976b470SGreg Roach 38c2e8227SGreg Roach/** 48c2e8227SGreg Roach * webtrees: online genealogy 58fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 68c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 78c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 88c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 98c2e8227SGreg Roach * (at your option) any later version. 108c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 118c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 128c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138c2e8227SGreg Roach * GNU General Public License for more details. 148c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 158c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 168c2e8227SGreg Roach */ 17*fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 2176692c8bSGreg Roach 220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 2356f9a9c1SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\RegisterPage; 240e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 254ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 260e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site; 27e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree; 281e7a7a28SGreg Roachuse Illuminate\Support\Str; 298c2e8227SGreg Roach 308c2e8227SGreg Roach/** 318c2e8227SGreg Roach * Class WelcomeBlockModule 328c2e8227SGreg Roach */ 3337eb8894SGreg Roachclass WelcomeBlockModule extends AbstractModule implements ModuleBlockInterface 34c1010edaSGreg Roach{ 3549a243cbSGreg Roach use ModuleBlockTrait; 3649a243cbSGreg Roach 37961ec755SGreg Roach /** 384ca7e03cSGreg Roach * @var ModuleService 394ca7e03cSGreg Roach */ 404ca7e03cSGreg Roach private $module_service; 414ca7e03cSGreg Roach 424ca7e03cSGreg Roach /** 434ca7e03cSGreg Roach * UserWelcomeModule constructor. 444ca7e03cSGreg Roach * 454ca7e03cSGreg Roach * @param ModuleService $module_service 464ca7e03cSGreg Roach */ 474ca7e03cSGreg Roach public function __construct(ModuleService $module_service) 484ca7e03cSGreg Roach { 494ca7e03cSGreg Roach $this->module_service = $module_service; 504ca7e03cSGreg Roach } 514ca7e03cSGreg Roach 524ca7e03cSGreg Roach /** 530cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 54961ec755SGreg Roach * 55961ec755SGreg Roach * @return string 56961ec755SGreg Roach */ 5749a243cbSGreg Roach public function title(): string 58c1010edaSGreg Roach { 59bbb76c12SGreg Roach /* I18N: Name of a module */ 60bbb76c12SGreg Roach return I18N::translate('Home page'); 618c2e8227SGreg Roach } 628c2e8227SGreg Roach 63961ec755SGreg Roach /** 64961ec755SGreg Roach * A sentence describing what this module does. 65961ec755SGreg Roach * 66961ec755SGreg Roach * @return string 67961ec755SGreg Roach */ 6849a243cbSGreg Roach public function description(): string 69c1010edaSGreg Roach { 70bbb76c12SGreg Roach /* I18N: Description of the “Home page” module */ 71bbb76c12SGreg Roach return I18N::translate('A greeting message for site visitors.'); 728c2e8227SGreg Roach } 738c2e8227SGreg Roach 7476692c8bSGreg Roach /** 7576692c8bSGreg Roach * Generate the HTML content of this block. 7676692c8bSGreg Roach * 77e490cd80SGreg Roach * @param Tree $tree 7876692c8bSGreg Roach * @param int $block_id 793caaa4d2SGreg Roach * @param string $context 803caaa4d2SGreg Roach * @param string[] $config 8176692c8bSGreg Roach * 8276692c8bSGreg Roach * @return string 8376692c8bSGreg Roach */ 843caaa4d2SGreg Roach public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string 85c1010edaSGreg Roach { 86af343084SGreg Roach $individual = $tree->significantIndividual(Auth::user()); 8775d70144SGreg Roach 8875d70144SGreg Roach $links = []; 8975d70144SGreg Roach 900797053bSGreg Roach $pedigree_chart = $this->module_service 910797053bSGreg Roach ->findByComponent(ModuleChartInterface::class, $tree, Auth::user()) 920797053bSGreg Roach ->first(static function (ModuleInterface $module): bool { 9349a243cbSGreg Roach return $module instanceof PedigreeChartModule; 940797053bSGreg Roach }); 9549a243cbSGreg Roach 9649a243cbSGreg Roach if ($pedigree_chart instanceof PedigreeChartModule) { 9775d70144SGreg Roach $links[] = [ 98f7dacbc4SGreg Roach $pedigree_chart->chartUrl($individual), 99f7dacbc4SGreg Roach 'url' => $pedigree_chart->chartUrl($individual), 10075d70144SGreg Roach 'title' => I18N::translate('Default chart'), 10175d70144SGreg Roach 'icon' => 'icon-pedigree', 10275d70144SGreg Roach ]; 1034eb71cfaSGreg Roach } 10475d70144SGreg Roach 10575d70144SGreg Roach $links[] = [ 106b1f1e4efSGreg Roach 'url' => $individual->url(), 10775d70144SGreg Roach 'title' => I18N::translate('Default individual'), 10875d70144SGreg Roach 'icon' => 'icon-indis', 10975d70144SGreg Roach ]; 11075d70144SGreg Roach 11115d603e7SGreg Roach if (Site::getPreference('USE_REGISTRATION_MODULE') === '1' && !Auth::check()) { 11275d70144SGreg Roach $links[] = [ 11356f9a9c1SGreg Roach 'url' => route(RegisterPage::class), 11475d70144SGreg Roach 'title' => I18N::translate('Request a new user account'), 11575d70144SGreg Roach 'icon' => 'icon-user_add', 11675d70144SGreg Roach ]; 1178c2e8227SGreg Roach } 11875d70144SGreg Roach 119147e99aaSGreg Roach $content = view('modules/gedcom_block/welcome', ['links' => $links]); 1208c2e8227SGreg Roach 1213caaa4d2SGreg Roach if ($context !== self::CONTEXT_EMBED) { 122147e99aaSGreg Roach return view('modules/block-template', [ 1231e7a7a28SGreg Roach 'block' => Str::kebab($this->name()), 124d034ca3bSGreg Roach 'id' => $block_id, 1251fa06fe3SGreg Roach 'config_url' => '', 126f4afa648SGreg Roach 'title' => $individual->tree()->title(), 12775d70144SGreg Roach 'content' => $content, 12875d70144SGreg Roach ]); 1298c2e8227SGreg Roach } 130b2ce94c6SRico Sonntag 131b2ce94c6SRico Sonntag return $content; 1328c2e8227SGreg Roach } 1338c2e8227SGreg Roach 1343caaa4d2SGreg Roach /** 1353caaa4d2SGreg Roach * Should this block load asynchronously using AJAX? 1363caaa4d2SGreg Roach * 1373caaa4d2SGreg Roach * Simple blocks are faster in-line, more complex ones can be loaded later. 1383caaa4d2SGreg Roach * 1393caaa4d2SGreg Roach * @return bool 1403caaa4d2SGreg Roach */ 141c1010edaSGreg Roach public function loadAjax(): bool 142c1010edaSGreg Roach { 1438c2e8227SGreg Roach return false; 1448c2e8227SGreg Roach } 1458c2e8227SGreg Roach 1463caaa4d2SGreg Roach /** 1473caaa4d2SGreg Roach * Can this block be shown on the user’s home page? 1483caaa4d2SGreg Roach * 1493caaa4d2SGreg Roach * @return bool 1503caaa4d2SGreg Roach */ 151c1010edaSGreg Roach public function isUserBlock(): bool 152c1010edaSGreg Roach { 1538c2e8227SGreg Roach return false; 1548c2e8227SGreg Roach } 1558c2e8227SGreg Roach 1563caaa4d2SGreg Roach /** 1573caaa4d2SGreg Roach * Can this block be shown on the tree’s home page? 1583caaa4d2SGreg Roach * 1593caaa4d2SGreg Roach * @return bool 1603caaa4d2SGreg Roach */ 16163276d8fSGreg Roach public function isTreeBlock(): bool 162c1010edaSGreg Roach { 1638c2e8227SGreg Roach return true; 1648c2e8227SGreg Roach } 1658c2e8227SGreg Roach} 166