149a243cbSGreg Roach<?php 23976b470SGreg Roach 349a243cbSGreg Roach/** 449a243cbSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg Roach * along with this program. If not, see <https://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; 238e0e1b25SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\TreePageBlockEdit; 248e0e1b25SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\UserPageBlockEdit; 253caaa4d2SGreg Roachuse Fisharebest\Webtrees\Tree; 263caaa4d2SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 273976b470SGreg Roach 283caaa4d2SGreg Roachuse function route; 293caaa4d2SGreg Roach 3049a243cbSGreg Roach/** 3149a243cbSGreg Roach * Trait ModuleBlockTrait - default implementation of ModuleBlockInterface 3249a243cbSGreg Roach */ 3349a243cbSGreg Roachtrait ModuleBlockTrait 3449a243cbSGreg Roach{ 353caaa4d2SGreg Roach /** 361b8d6713SGreg Roach * Generate the HTML content of this block. 371b8d6713SGreg Roach * 381b8d6713SGreg Roach * @param Tree $tree 391b8d6713SGreg Roach * @param int $block_id 401b8d6713SGreg Roach * @param string $context 4176d39c55SGreg Roach * @param array<string,string> $config 421b8d6713SGreg Roach * 431b8d6713SGreg Roach * @return string 441b8d6713SGreg Roach */ 451b8d6713SGreg Roach public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string 461b8d6713SGreg Roach { 471b8d6713SGreg Roach return ''; 481b8d6713SGreg Roach } 491b8d6713SGreg Roach 501b8d6713SGreg Roach /** 511b8d6713SGreg Roach * Should this block load asynchronously using AJAX? 521b8d6713SGreg Roach * 531b8d6713SGreg Roach * Simple blocks are faster in-line, more complex ones can be loaded later. 541b8d6713SGreg Roach * 551b8d6713SGreg Roach * @return bool 561b8d6713SGreg Roach */ 571b8d6713SGreg Roach public function loadAjax(): bool 581b8d6713SGreg Roach { 591b8d6713SGreg Roach return false; 601b8d6713SGreg Roach } 611b8d6713SGreg Roach 621b8d6713SGreg Roach /** 631b8d6713SGreg Roach * Can this block be shown on the user’s home page? 641b8d6713SGreg Roach * 651b8d6713SGreg Roach * @return bool 661b8d6713SGreg Roach */ 671b8d6713SGreg Roach public function isUserBlock(): bool 681b8d6713SGreg Roach { 691b8d6713SGreg Roach return false; 701b8d6713SGreg Roach } 711b8d6713SGreg Roach 721b8d6713SGreg Roach /** 731b8d6713SGreg Roach * Can this block be shown on the tree’s home page? 741b8d6713SGreg Roach * 751b8d6713SGreg Roach * @return bool 761b8d6713SGreg Roach */ 771b8d6713SGreg Roach public function isTreeBlock(): bool 781b8d6713SGreg Roach { 791b8d6713SGreg Roach return false; 801b8d6713SGreg Roach } 811b8d6713SGreg Roach 821b8d6713SGreg Roach /** 833caaa4d2SGreg Roach * @param Tree $tree 843caaa4d2SGreg Roach * @param string $context 853caaa4d2SGreg Roach * @param int $block_id 863caaa4d2SGreg Roach * 873caaa4d2SGreg Roach * @return string 883caaa4d2SGreg Roach */ 898b02deb4SGreg Roach protected function configUrl(Tree $tree, string $context, int $block_id): string 908b02deb4SGreg Roach { 915b91a3bcSGreg Roach if ($context === ModuleBlockInterface::CONTEXT_TREE_PAGE && Auth::isManager($tree)) { 928e0e1b25SGreg Roach return route(TreePageBlockEdit::class, [ 933caaa4d2SGreg Roach 'block_id' => $block_id, 94d72b284aSGreg Roach 'tree' => $tree->name(), 953caaa4d2SGreg Roach ]); 963caaa4d2SGreg Roach } 973caaa4d2SGreg Roach 985b91a3bcSGreg Roach if ($context === ModuleBlockInterface::CONTEXT_USER_PAGE && Auth::check()) { 998e0e1b25SGreg Roach return route(UserPageBlockEdit::class, [ 1003caaa4d2SGreg Roach 'block_id' => $block_id, 1015afbc57aSGreg Roach 'tree' => $tree->name(), 1023caaa4d2SGreg Roach ]); 1033caaa4d2SGreg Roach } 1043caaa4d2SGreg Roach 1053caaa4d2SGreg Roach return ''; 1063caaa4d2SGreg Roach } 1073caaa4d2SGreg Roach 1083caaa4d2SGreg Roach /** 1093caaa4d2SGreg Roach * Update the configuration for a block. 1103caaa4d2SGreg Roach * 1113caaa4d2SGreg Roach * @param ServerRequestInterface $request 1123caaa4d2SGreg Roach * @param int $block_id 1133caaa4d2SGreg Roach * 1143caaa4d2SGreg Roach * @return void 1153caaa4d2SGreg Roach */ 1163caaa4d2SGreg Roach public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void 1173caaa4d2SGreg Roach { 1183caaa4d2SGreg Roach } 1193caaa4d2SGreg Roach 1203caaa4d2SGreg Roach /** 1213caaa4d2SGreg Roach * An HTML form to edit block settings 1223caaa4d2SGreg Roach * 1233caaa4d2SGreg Roach * @param Tree $tree 1243caaa4d2SGreg Roach * @param int $block_id 1253caaa4d2SGreg Roach * 1263caaa4d2SGreg Roach * @return string 1273caaa4d2SGreg Roach */ 1283caaa4d2SGreg Roach public function editBlockConfiguration(Tree $tree, int $block_id): string 1293caaa4d2SGreg Roach { 1303caaa4d2SGreg Roach return ''; 1313caaa4d2SGreg Roach } 13249a243cbSGreg Roach} 133