149a243cbSGreg Roach<?php 23976b470SGreg Roach 349a243cbSGreg Roach/** 449a243cbSGreg Roach * webtrees: online genealogy 549a243cbSGreg Roach * Copyright (C) 2019 webtrees development team 649a243cbSGreg Roach * This program is free software: you can redistribute it and/or modify 749a243cbSGreg Roach * it under the terms of the GNU General Public License as published by 849a243cbSGreg Roach * the Free Software Foundation, either version 3 of the License, or 949a243cbSGreg Roach * (at your option) any later version. 1049a243cbSGreg Roach * This program is distributed in the hope that it will be useful, 1149a243cbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1249a243cbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1349a243cbSGreg Roach * GNU General Public License for more details. 1449a243cbSGreg Roach * You should have received a copy of the GNU General Public License 1549a243cbSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1649a243cbSGreg Roach */ 17fcfa147eSGreg Roach 1849a243cbSGreg Roachdeclare(strict_types=1); 1949a243cbSGreg Roach 2049a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module; 2149a243cbSGreg Roach 223caaa4d2SGreg Roachuse Fisharebest\Webtrees\Auth; 233caaa4d2SGreg Roachuse Fisharebest\Webtrees\Tree; 243caaa4d2SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 253976b470SGreg Roach 263caaa4d2SGreg Roachuse function route; 273caaa4d2SGreg Roach 2849a243cbSGreg Roach/** 2949a243cbSGreg Roach * Trait ModuleBlockTrait - default implementation of ModuleBlockInterface 3049a243cbSGreg Roach */ 3149a243cbSGreg Roachtrait ModuleBlockTrait 3249a243cbSGreg Roach{ 333caaa4d2SGreg Roach /** 34*1b8d6713SGreg Roach * Generate the HTML content of this block. 35*1b8d6713SGreg Roach * 36*1b8d6713SGreg Roach * @param Tree $tree 37*1b8d6713SGreg Roach * @param int $block_id 38*1b8d6713SGreg Roach * @param string $context 39*1b8d6713SGreg Roach * @param array $config 40*1b8d6713SGreg Roach * 41*1b8d6713SGreg Roach * @return string 42*1b8d6713SGreg Roach */ 43*1b8d6713SGreg Roach public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string 44*1b8d6713SGreg Roach { 45*1b8d6713SGreg Roach return ''; 46*1b8d6713SGreg Roach } 47*1b8d6713SGreg Roach 48*1b8d6713SGreg Roach /** 49*1b8d6713SGreg Roach * Should this block load asynchronously using AJAX? 50*1b8d6713SGreg Roach * 51*1b8d6713SGreg Roach * Simple blocks are faster in-line, more complex ones can be loaded later. 52*1b8d6713SGreg Roach * 53*1b8d6713SGreg Roach * @return bool 54*1b8d6713SGreg Roach */ 55*1b8d6713SGreg Roach public function loadAjax(): bool 56*1b8d6713SGreg Roach { 57*1b8d6713SGreg Roach return false; 58*1b8d6713SGreg Roach } 59*1b8d6713SGreg Roach 60*1b8d6713SGreg Roach /** 61*1b8d6713SGreg Roach * Can this block be shown on the user’s home page? 62*1b8d6713SGreg Roach * 63*1b8d6713SGreg Roach * @return bool 64*1b8d6713SGreg Roach */ 65*1b8d6713SGreg Roach public function isUserBlock(): bool 66*1b8d6713SGreg Roach { 67*1b8d6713SGreg Roach return false; 68*1b8d6713SGreg Roach } 69*1b8d6713SGreg Roach 70*1b8d6713SGreg Roach /** 71*1b8d6713SGreg Roach * Can this block be shown on the tree’s home page? 72*1b8d6713SGreg Roach * 73*1b8d6713SGreg Roach * @return bool 74*1b8d6713SGreg Roach */ 75*1b8d6713SGreg Roach public function isTreeBlock(): bool 76*1b8d6713SGreg Roach { 77*1b8d6713SGreg Roach return false; 78*1b8d6713SGreg Roach } 79*1b8d6713SGreg Roach 80*1b8d6713SGreg Roach /** 813caaa4d2SGreg Roach * @param Tree $tree 823caaa4d2SGreg Roach * @param string $context 833caaa4d2SGreg Roach * @param int $block_id 843caaa4d2SGreg Roach * 853caaa4d2SGreg Roach * @return string 863caaa4d2SGreg Roach */ 878b02deb4SGreg Roach protected function configUrl(Tree $tree, string $context, int $block_id): string 888b02deb4SGreg Roach { 893caaa4d2SGreg Roach if ($context === self::CONTEXT_TREE_PAGE && Auth::isManager($tree)) { 903caaa4d2SGreg Roach return route('tree-page-block-edit', [ 913caaa4d2SGreg Roach 'block_id' => $block_id, 92d72b284aSGreg Roach 'tree' => $tree->name(), 933caaa4d2SGreg Roach ]); 943caaa4d2SGreg Roach } 953caaa4d2SGreg Roach 963caaa4d2SGreg Roach if ($context === self::CONTEXT_USER_PAGE && Auth::check()) { 973caaa4d2SGreg Roach return route('user-page-block-edit', [ 983caaa4d2SGreg Roach 'block_id' => $block_id, 995afbc57aSGreg Roach 'tree' => $tree->name(), 1003caaa4d2SGreg Roach ]); 1013caaa4d2SGreg Roach } 1023caaa4d2SGreg Roach 1033caaa4d2SGreg Roach return ''; 1043caaa4d2SGreg Roach } 1053caaa4d2SGreg Roach 1063caaa4d2SGreg Roach /** 1073caaa4d2SGreg Roach * Update the configuration for a block. 1083caaa4d2SGreg Roach * 1093caaa4d2SGreg Roach * @param ServerRequestInterface $request 1103caaa4d2SGreg Roach * @param int $block_id 1113caaa4d2SGreg Roach * 1123caaa4d2SGreg Roach * @return void 1133caaa4d2SGreg Roach */ 1143caaa4d2SGreg Roach public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void 1153caaa4d2SGreg Roach { 1163caaa4d2SGreg Roach } 1173caaa4d2SGreg Roach 1183caaa4d2SGreg Roach /** 1193caaa4d2SGreg Roach * An HTML form to edit block settings 1203caaa4d2SGreg Roach * 1213caaa4d2SGreg Roach * @param Tree $tree 1223caaa4d2SGreg Roach * @param int $block_id 1233caaa4d2SGreg Roach * 1243caaa4d2SGreg Roach * @return string 1253caaa4d2SGreg Roach */ 1263caaa4d2SGreg Roach public function editBlockConfiguration(Tree $tree, int $block_id): string 1273caaa4d2SGreg Roach { 1283caaa4d2SGreg Roach return ''; 1293caaa4d2SGreg Roach } 13049a243cbSGreg Roach} 131