1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Module; 21 22use Fisharebest\Webtrees\Auth; 23use Fisharebest\Webtrees\Http\RequestHandlers\RegisterPage; 24use Fisharebest\Webtrees\I18N; 25use Fisharebest\Webtrees\Services\ModuleService; 26use Fisharebest\Webtrees\Site; 27use Fisharebest\Webtrees\Tree; 28use Illuminate\Support\Str; 29 30/** 31 * Class WelcomeBlockModule 32 */ 33class WelcomeBlockModule extends AbstractModule implements ModuleBlockInterface 34{ 35 use ModuleBlockTrait; 36 37 /** 38 * @var ModuleService 39 */ 40 private $module_service; 41 42 /** 43 * WelcomeBlockModule constructor. 44 * 45 * @param ModuleService $module_service 46 */ 47 public function __construct(ModuleService $module_service) 48 { 49 $this->module_service = $module_service; 50 } 51 52 /** 53 * How should this module be identified in the control panel, etc.? 54 * 55 * @return string 56 */ 57 public function title(): string 58 { 59 /* I18N: Name of a module */ 60 return I18N::translate('Home page'); 61 } 62 63 /** 64 * A sentence describing what this module does. 65 * 66 * @return string 67 */ 68 public function description(): string 69 { 70 /* I18N: Description of the “Home page” module */ 71 return I18N::translate('A greeting message for site visitors.'); 72 } 73 74 /** 75 * Generate the HTML content of this block. 76 * 77 * @param Tree $tree 78 * @param int $block_id 79 * @param string $context 80 * @param string[] $config 81 * 82 * @return string 83 */ 84 public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string 85 { 86 $individual = $tree->significantIndividual(Auth::user()); 87 88 $links = []; 89 90 $pedigree_chart = $this->module_service 91 ->findByComponent(ModuleChartInterface::class, $tree, Auth::user()) 92 ->first(static function (ModuleInterface $module): bool { 93 return $module instanceof PedigreeChartModule; 94 }); 95 96 if ($pedigree_chart instanceof PedigreeChartModule) { 97 $links[] = [ 98 $pedigree_chart->chartUrl($individual), 99 'url' => $pedigree_chart->chartUrl($individual), 100 'title' => I18N::translate('Default chart'), 101 'icon' => 'icon-pedigree', 102 ]; 103 } 104 105 $links[] = [ 106 'url' => $individual->url(), 107 'title' => I18N::translate('Default individual'), 108 'icon' => 'icon-indis', 109 ]; 110 111 if (Site::getPreference('USE_REGISTRATION_MODULE') === '1' && !Auth::check()) { 112 $links[] = [ 113 'url' => route(RegisterPage::class, ['tree' => $tree->name()]), 114 'title' => I18N::translate('Request a new user account'), 115 'icon' => 'icon-user_add', 116 ]; 117 } 118 119 $content = view('modules/gedcom_block/welcome', ['links' => $links]); 120 121 if ($context !== self::CONTEXT_EMBED) { 122 return view('modules/block-template', [ 123 'block' => Str::kebab($this->name()), 124 'id' => $block_id, 125 'config_url' => '', 126 'title' => $individual->tree()->title(), 127 'content' => $content, 128 ]); 129 } 130 131 return $content; 132 } 133 134 /** 135 * Should this block load asynchronously using AJAX? 136 * 137 * Simple blocks are faster in-line, more complex ones can be loaded later. 138 * 139 * @return bool 140 */ 141 public function loadAjax(): bool 142 { 143 return false; 144 } 145 146 /** 147 * Can this block be shown on the user’s home page? 148 * 149 * @return bool 150 */ 151 public function isUserBlock(): bool 152 { 153 return false; 154 } 155 156 /** 157 * Can this block be shown on the tree’s home page? 158 * 159 * @return bool 160 */ 161 public function isTreeBlock(): bool 162 { 163 return true; 164 } 165} 166