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 22*852ede8cSGreg Roachuse Fisharebest\Webtrees\Auth; 23*852ede8cSGreg Roachuse Fisharebest\Webtrees\Individual; 24*852ede8cSGreg Roachuse Fisharebest\Webtrees\Tree; 258eaf8709SGreg Roachuse Illuminate\Support\Collection; 26*852ede8cSGreg Roachuse Psr\Http\Message\ResponseInterface; 27*852ede8cSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 28*852ede8cSGreg Roachuse Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; 29*852ede8cSGreg Roach 30*852ede8cSGreg Roachuse function assert; 31*852ede8cSGreg Roachuse function response; 32*852ede8cSGreg Roachuse function view; 338eaf8709SGreg Roach 3449a243cbSGreg Roach/** 3549a243cbSGreg Roach * Trait ModuleTabTrait - default implementation of ModuleTabInterface 3649a243cbSGreg Roach */ 3749a243cbSGreg Roachtrait ModuleTabTrait 3849a243cbSGreg Roach{ 3949a243cbSGreg Roach /** @var int The default position for this tab. It can be changed in the control panel. */ 40fb7a0427SGreg Roach protected $tab_order; 4149a243cbSGreg Roach 4249a243cbSGreg Roach /** 43e284d69fSGreg Roach * @return string 44e284d69fSGreg Roach */ 45e284d69fSGreg Roach abstract public function title(): string; 46e284d69fSGreg Roach 47e284d69fSGreg Roach /** 48*852ede8cSGreg Roach * Get a the current access level for a module 49*852ede8cSGreg Roach * 50*852ede8cSGreg Roach * @param Tree $tree 51*852ede8cSGreg Roach * @param string $interface 52*852ede8cSGreg Roach * 53*852ede8cSGreg Roach * @return int 54*852ede8cSGreg Roach */ 55*852ede8cSGreg Roach abstract public function accessLevel(Tree $tree, string $interface): int; 56*852ede8cSGreg Roach 57*852ede8cSGreg Roach /** 58*852ede8cSGreg Roach * Generate the HTML content of this tab. 59*852ede8cSGreg Roach * 60*852ede8cSGreg Roach * @param Individual $individual 61*852ede8cSGreg Roach * 62*852ede8cSGreg Roach * @return string 63*852ede8cSGreg Roach */ 64*852ede8cSGreg Roach abstract public function getTabContent(Individual $individual): string; 65*852ede8cSGreg Roach 66*852ede8cSGreg Roach /** 6739402588SGreg Roach * The text that appears on the tab. 6839402588SGreg Roach * 6939402588SGreg Roach * @return string 7039402588SGreg Roach */ 7139402588SGreg Roach public function tabTitle(): string 7239402588SGreg Roach { 7339402588SGreg Roach return $this->title(); 7439402588SGreg Roach } 7539402588SGreg Roach 7639402588SGreg Roach /** 7749a243cbSGreg Roach * Users change change the order of tabs using the control panel. 7849a243cbSGreg Roach * 7949a243cbSGreg Roach * @param int $tab_order 8049a243cbSGreg Roach * 8149a243cbSGreg Roach * @return void 8249a243cbSGreg Roach */ 8349a243cbSGreg Roach public function setTabOrder(int $tab_order): void 8449a243cbSGreg Roach { 8549a243cbSGreg Roach $this->tab_order = $tab_order; 8649a243cbSGreg Roach } 8749a243cbSGreg Roach 8849a243cbSGreg Roach /** 8949a243cbSGreg Roach * Users change change the order of tabs using the control panel. 9049a243cbSGreg Roach * 9149a243cbSGreg Roach * @return int 9249a243cbSGreg Roach */ 9349a243cbSGreg Roach public function getTabOrder(): int 9449a243cbSGreg Roach { 9524bd2cf5SGreg Roach return $this->tab_order ?? $this->defaultTabOrder(); 9649a243cbSGreg Roach } 9749a243cbSGreg Roach 9849a243cbSGreg Roach /** 9949a243cbSGreg Roach * The default position for this tab. It can be changed in the control panel. 10049a243cbSGreg Roach * 10149a243cbSGreg Roach * @return int 10249a243cbSGreg Roach */ 103cbf4b7faSGreg Roach public function defaultTabOrder(): int 104cbf4b7faSGreg Roach { 10549a243cbSGreg Roach return 9999; 10649a243cbSGreg Roach } 1078eaf8709SGreg Roach 1088eaf8709SGreg Roach /** 1098eaf8709SGreg Roach * This module handles the following facts - so don't show them on the "Facts and events" tab. 1108eaf8709SGreg Roach * 11154c7f8dfSGreg Roach * @return Collection 1128eaf8709SGreg Roach */ 1138eaf8709SGreg Roach public function supportedFacts(): Collection 1148eaf8709SGreg Roach { 1158eaf8709SGreg Roach return new Collection([]); 1168eaf8709SGreg Roach } 117*852ede8cSGreg Roach 118*852ede8cSGreg Roach /** 119*852ede8cSGreg Roach * @param ServerRequestInterface $request 120*852ede8cSGreg Roach * 121*852ede8cSGreg Roach * @return ResponseInterface 122*852ede8cSGreg Roach */ 123*852ede8cSGreg Roach public function getTabAction(ServerRequestInterface $request): ResponseInterface 124*852ede8cSGreg Roach { 125*852ede8cSGreg Roach $tree = $request->getAttribute('tree'); 126*852ede8cSGreg Roach assert($tree instanceof Tree); 127*852ede8cSGreg Roach 128*852ede8cSGreg Roach $xref = $request->getQueryParams()['xref']; 129*852ede8cSGreg Roach 130*852ede8cSGreg Roach $record = Individual::getInstance($xref, $tree); 131*852ede8cSGreg Roach $record = Auth::checkIndividualAccess($record); 132*852ede8cSGreg Roach 133*852ede8cSGreg Roach $user = $request->getAttribute('user'); 134*852ede8cSGreg Roach 135*852ede8cSGreg Roach if ($this->accessLevel($tree, 'tab') < Auth::accessLevel($tree, $user)) { 136*852ede8cSGreg Roach throw new AccessDeniedHttpException('Access denied'); 137*852ede8cSGreg Roach } 138*852ede8cSGreg Roach 139*852ede8cSGreg Roach $layout = view('layouts/ajax', [ 140*852ede8cSGreg Roach 'content' => $this->getTabContent($record), 141*852ede8cSGreg Roach ]); 142*852ede8cSGreg Roach 143*852ede8cSGreg Roach return response($layout); 144*852ede8cSGreg Roach } 14549a243cbSGreg Roach} 146