122e73debSGreg Roach<?php 222e73debSGreg Roach 322e73debSGreg Roach/** 422e73debSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 622e73debSGreg Roach * This program is free software: you can redistribute it and/or modify 722e73debSGreg Roach * it under the terms of the GNU General Public License as published by 822e73debSGreg Roach * the Free Software Foundation, either version 3 of the License, or 922e73debSGreg Roach * (at your option) any later version. 1022e73debSGreg Roach * This program is distributed in the hope that it will be useful, 1122e73debSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1222e73debSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1322e73debSGreg Roach * GNU General Public License for more details. 1422e73debSGreg 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/>. 1622e73debSGreg Roach */ 1722e73debSGreg Roach 1822e73debSGreg Roachdeclare(strict_types=1); 1922e73debSGreg Roach 2022e73debSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 2122e73debSGreg Roach 2222e73debSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 2322e73debSGreg Roachuse Fisharebest\Webtrees\I18N; 2422ad3b5bSGreg Roachuse Fisharebest\Webtrees\Services\PendingChangesService; 25b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 2622e73debSGreg Roachuse Psr\Http\Message\ResponseInterface; 2722e73debSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 2822e73debSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 2922e73debSGreg Roach 3022e73debSGreg Roachuse function route; 3122e73debSGreg Roach 3222e73debSGreg Roach/** 3322e73debSGreg Roach * Show all pending changes. 3422e73debSGreg Roach */ 3522e73debSGreg Roachclass PendingChanges implements RequestHandlerInterface 3622e73debSGreg Roach{ 3722e73debSGreg Roach use ViewResponseTrait; 3822e73debSGreg Roach 3922ad3b5bSGreg Roach // Some servers may not have enough resources to show all the changes. 4022ad3b5bSGreg Roach private const MAX_CHANGES = 1000; 4122ad3b5bSGreg Roach 42c4943cffSGreg Roach private PendingChangesService $pending_changes_service; 4322e73debSGreg Roach 4422e73debSGreg Roach /** 4522ad3b5bSGreg Roach * @param PendingChangesService $pending_changes_service 4622e73debSGreg Roach */ 4722ad3b5bSGreg Roach public function __construct(PendingChangesService $pending_changes_service) 4822e73debSGreg Roach { 4922ad3b5bSGreg Roach $this->pending_changes_service = $pending_changes_service; 5022e73debSGreg Roach } 5122e73debSGreg Roach 5222e73debSGreg Roach /** 5322e73debSGreg Roach * @param ServerRequestInterface $request 5422e73debSGreg Roach * 5522e73debSGreg Roach * @return ResponseInterface 5622e73debSGreg Roach */ 5722e73debSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 5822e73debSGreg Roach { 59b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 609f0bdfcdSGreg Roach $n = Validator::queryParams($request)->integer('n', self::MAX_CHANGES); 619f0bdfcdSGreg Roach $default_url = route(TreePage::class, ['tree' => $tree->name()]); 629f0bdfcdSGreg Roach $url = Validator::queryParams($request)->isLocalUrl()->string('url', $default_url); 6322ad3b5bSGreg Roach $xrefs = $this->pending_changes_service->pendingXrefs($tree); 6422ad3b5bSGreg Roach $changes = $this->pending_changes_service->pendingChanges($tree, $n); 6522e73debSGreg Roach $title = I18N::translate('Pending changes'); 6622e73debSGreg Roach 6722e73debSGreg Roach return $this->viewResponse('pending-changes-page', [ 6822e73debSGreg Roach 'changes' => $changes, 6922ad3b5bSGreg Roach 'count' => $xrefs->count(), 7022e73debSGreg Roach 'title' => $title, 7122e73debSGreg Roach 'tree' => $tree, 7222e73debSGreg Roach 'url' => $url, 7322e73debSGreg Roach ]); 7422e73debSGreg Roach } 7522e73debSGreg Roach} 76