122e73debSGreg Roach<?php 222e73debSGreg Roach 322e73debSGreg Roach/** 422e73debSGreg Roach * webtrees: online genealogy 5a091ac74SGreg Roach * Copyright (C) 2020 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 1522e73debSGreg Roach * along with this program. If not, see <http://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; 24*22ad3b5bSGreg Roachuse Fisharebest\Webtrees\Services\PendingChangesService; 2522e73debSGreg Roachuse Fisharebest\Webtrees\Tree; 2622e73debSGreg Roachuse Psr\Http\Message\ResponseInterface; 2722e73debSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 2822e73debSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 2922e73debSGreg Roach 3022e73debSGreg Roachuse function assert; 3122e73debSGreg Roachuse function route; 3222e73debSGreg Roach 3322e73debSGreg Roach/** 3422e73debSGreg Roach * Show all pending changes. 3522e73debSGreg Roach */ 3622e73debSGreg Roachclass PendingChanges implements RequestHandlerInterface 3722e73debSGreg Roach{ 3822e73debSGreg Roach use ViewResponseTrait; 3922e73debSGreg Roach 40*22ad3b5bSGreg Roach // Some servers may not have enough resources to show all the changes. 41*22ad3b5bSGreg Roach private const MAX_CHANGES = 1000; 42*22ad3b5bSGreg Roach 43*22ad3b5bSGreg Roach /** @var PendingChangesService */ 44*22ad3b5bSGreg Roach private $pending_changes_service; 4522e73debSGreg Roach 4622e73debSGreg Roach /** 47*22ad3b5bSGreg Roach * PendingChanges constructor. 48*22ad3b5bSGreg Roach * 49*22ad3b5bSGreg Roach * @param PendingChangesService $pending_changes_service 5022e73debSGreg Roach */ 51*22ad3b5bSGreg Roach public function __construct(PendingChangesService $pending_changes_service) 5222e73debSGreg Roach { 53*22ad3b5bSGreg Roach $this->pending_changes_service = $pending_changes_service; 5422e73debSGreg Roach } 5522e73debSGreg Roach 5622e73debSGreg Roach /** 5722e73debSGreg Roach * @param ServerRequestInterface $request 5822e73debSGreg Roach * 5922e73debSGreg Roach * @return ResponseInterface 6022e73debSGreg Roach */ 6122e73debSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 6222e73debSGreg Roach { 6322e73debSGreg Roach $tree = $request->getAttribute('tree'); 6475964c75SGreg Roach assert($tree instanceof Tree); 6522e73debSGreg Roach 66*22ad3b5bSGreg Roach $n = (int) ($request->getQueryParams()['n'] ?? self::MAX_CHANGES); 67*22ad3b5bSGreg Roach 688e0e1b25SGreg Roach $url = $request->getQueryParams()['url'] ?? route(TreePage::class, ['tree' => $tree->name()]); 69*22ad3b5bSGreg Roach $xrefs = $this->pending_changes_service->pendingXrefs($tree); 70*22ad3b5bSGreg Roach $changes = $this->pending_changes_service->pendingChanges($tree, $n); 7122e73debSGreg Roach $title = I18N::translate('Pending changes'); 7222e73debSGreg Roach 7322e73debSGreg Roach return $this->viewResponse('pending-changes-page', [ 7422e73debSGreg Roach 'changes' => $changes, 75*22ad3b5bSGreg Roach 'count' => $xrefs->count(), 7622e73debSGreg Roach 'title' => $title, 7722e73debSGreg Roach 'tree' => $tree, 7822e73debSGreg Roach 'url' => $url, 7922e73debSGreg Roach ]); 8022e73debSGreg Roach } 8122e73debSGreg Roach} 82