167992b6aSRichard Cissee<?php 23976b470SGreg Roach 367992b6aSRichard Cissee/** 467992b6aSRichard Cissee * webtrees: online genealogy 567992b6aSRichard Cissee * Copyright (C) 2019 webtrees development team 667992b6aSRichard Cissee * This program is free software: you can redistribute it and/or modify 767992b6aSRichard Cissee * it under the terms of the GNU General Public License as published by 867992b6aSRichard Cissee * the Free Software Foundation, either version 3 of the License, or 967992b6aSRichard Cissee * (at your option) any later version. 1067992b6aSRichard Cissee * This program is distributed in the hope that it will be useful, 1167992b6aSRichard Cissee * but WITHOUT ANY WARRANTY; without even the implied warranty of 1267992b6aSRichard Cissee * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1367992b6aSRichard Cissee * GNU General Public License for more details. 1467992b6aSRichard Cissee * You should have received a copy of the GNU General Public License 1567992b6aSRichard Cissee * along with this program. If not, see <http://www.gnu.org/licenses/>. 1667992b6aSRichard Cissee */ 17fcfa147eSGreg Roach 1867992b6aSRichard Cisseedeclare(strict_types=1); 1967992b6aSRichard Cissee 2067992b6aSRichard Cisseenamespace Fisharebest\Webtrees\Module; 2167992b6aSRichard Cissee 2267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Http\Controllers\ListController; 2367992b6aSRichard Cisseeuse Fisharebest\Webtrees\I18N; 24*e72c24d6SGreg Roachuse Fisharebest\Webtrees\Repository; 2567992b6aSRichard Cisseeuse Fisharebest\Webtrees\Services\IndividualListService; 2667992b6aSRichard Cisseeuse Fisharebest\Webtrees\Services\LocalizationService; 2767992b6aSRichard Cisseeuse Fisharebest\Webtrees\Tree; 2867992b6aSRichard Cisseeuse Fisharebest\Webtrees\Auth; 2967992b6aSRichard Cisseeuse Illuminate\Database\Capsule\Manager as DB; 306ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 3157ab2231SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 32f3874e19SGreg Roach 335229eadeSGreg Roachuse function assert; 3467992b6aSRichard Cissee 3567992b6aSRichard Cissee/** 3667992b6aSRichard Cissee * Class RepositoryListModule 3767992b6aSRichard Cissee */ 3867992b6aSRichard Cisseeclass RepositoryListModule extends AbstractModule implements ModuleListInterface 3967992b6aSRichard Cissee{ 4067992b6aSRichard Cissee use ModuleListTrait; 4167992b6aSRichard Cissee 42*e72c24d6SGreg Roach /** @var int The default access level for this module. It can be changed in the control panel. */ 43*e72c24d6SGreg Roach protected $access_level = Auth::PRIV_USER; 44*e72c24d6SGreg Roach 4567992b6aSRichard Cissee /** 460cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 4767992b6aSRichard Cissee * 4867992b6aSRichard Cissee * @return string 4967992b6aSRichard Cissee */ 5067992b6aSRichard Cissee public function title(): string 5167992b6aSRichard Cissee { 5267992b6aSRichard Cissee /* I18N: Name of a module/list */ 5367992b6aSRichard Cissee return I18N::translate('Repositories'); 5467992b6aSRichard Cissee } 5567992b6aSRichard Cissee 5667992b6aSRichard Cissee /** 5767992b6aSRichard Cissee * A sentence describing what this module does. 5867992b6aSRichard Cissee * 5967992b6aSRichard Cissee * @return string 6067992b6aSRichard Cissee */ 6167992b6aSRichard Cissee public function description(): string 6267992b6aSRichard Cissee { 63b5e8e56bSGreg Roach /* I18N: Description of the “Repositories” module */ 6467992b6aSRichard Cissee return I18N::translate('A list of repositories.'); 6567992b6aSRichard Cissee } 6667992b6aSRichard Cissee 6767992b6aSRichard Cissee /** 6867992b6aSRichard Cissee * CSS class for the URL. 6967992b6aSRichard Cissee * 7067992b6aSRichard Cissee * @return string 7167992b6aSRichard Cissee */ 7267992b6aSRichard Cissee public function listMenuClass(): string 7367992b6aSRichard Cissee { 7467992b6aSRichard Cissee return 'menu-list-repo'; 7567992b6aSRichard Cissee } 7667992b6aSRichard Cissee 774db4b4a9SGreg Roach /** 7857ab2231SGreg Roach * @param ServerRequestInterface $request 794db4b4a9SGreg Roach * 806ccdf4f0SGreg Roach * @return ResponseInterface 814db4b4a9SGreg Roach */ 8257ab2231SGreg Roach public function getListAction(ServerRequestInterface $request): ResponseInterface 8367992b6aSRichard Cissee { 8457ab2231SGreg Roach $tree = $request->getAttribute('tree'); 8575964c75SGreg Roach assert($tree instanceof Tree); 865229eadeSGreg Roach 8757ab2231SGreg Roach $user = $request->getAttribute('user'); 8857ab2231SGreg Roach 8996d794e7SGreg Roach Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user); 9067992b6aSRichard Cissee 9167992b6aSRichard Cissee $listController = new ListController(app(IndividualListService::class), app(LocalizationService::class)); 9257ab2231SGreg Roach return $listController->repositoryList($request); 9367992b6aSRichard Cissee } 9467992b6aSRichard Cissee 954db4b4a9SGreg Roach /** 964db4b4a9SGreg Roach * @return string[] 974db4b4a9SGreg Roach */ 9867992b6aSRichard Cissee public function listUrlAttributes(): array 9967992b6aSRichard Cissee { 10067992b6aSRichard Cissee return []; 10167992b6aSRichard Cissee } 10267992b6aSRichard Cissee 1034db4b4a9SGreg Roach /** 1044db4b4a9SGreg Roach * @param Tree $tree 1054db4b4a9SGreg Roach * 1064db4b4a9SGreg Roach * @return bool 1074db4b4a9SGreg Roach */ 10867992b6aSRichard Cissee public function listIsEmpty(Tree $tree): bool 10967992b6aSRichard Cissee { 11067992b6aSRichard Cissee return !DB::table('other') 11167992b6aSRichard Cissee ->where('o_file', '=', $tree->id()) 112*e72c24d6SGreg Roach ->where('o_type', '=', Repository::RECORD_TYPE) 11367992b6aSRichard Cissee ->exists(); 11467992b6aSRichard Cissee } 11567992b6aSRichard Cissee} 116