122e73debSGreg Roach<?php 222e73debSGreg Roach 322e73debSGreg Roach/** 422e73debSGreg Roach * webtrees: online genealogy 522e73debSGreg Roach * Copyright (C) 2019 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\Carbon; 2322e73debSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 2422e73debSGreg Roachuse Fisharebest\Webtrees\I18N; 2522e73debSGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 2622e73debSGreg Roachuse Fisharebest\Webtrees\Services\UserService; 2722e73debSGreg Roachuse Fisharebest\Webtrees\Tree; 2822e73debSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 2922e73debSGreg Roachuse Psr\Http\Message\ResponseInterface; 3022e73debSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 3122e73debSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 3222e73debSGreg Roach 3322e73debSGreg Roach/** 3422e73debSGreg Roach * Show pending changes. 3522e73debSGreg Roach */ 3622e73debSGreg Roachclass PendingChangesLogPage implements RequestHandlerInterface 3722e73debSGreg Roach{ 3822e73debSGreg Roach use ViewResponseTrait; 3922e73debSGreg Roach 4022e73debSGreg Roach /** @var TreeService */ 4122e73debSGreg Roach private $tree_service; 4222e73debSGreg Roach 4322e73debSGreg Roach /** @var UserService */ 4422e73debSGreg Roach private $user_service; 4522e73debSGreg Roach 4622e73debSGreg Roach /** 4722e73debSGreg Roach * @param TreeService $tree_service 4822e73debSGreg Roach * @param UserService $user_service 4922e73debSGreg Roach */ 5022e73debSGreg Roach public function __construct(TreeService $tree_service, UserService $user_service) 5122e73debSGreg Roach { 5222e73debSGreg Roach $this->tree_service = $tree_service; 5322e73debSGreg Roach $this->user_service = $user_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 $this->layout = 'layouts/administration'; 6422e73debSGreg Roach 6522e73debSGreg Roach $tree = $request->getAttribute('tree'); 6675964c75SGreg Roach assert($tree instanceof Tree); 6722e73debSGreg Roach 6822e73debSGreg Roach $trees = $this->tree_service->titles(); 6922e73debSGreg Roach 7022e73debSGreg Roach $users = ['' => '']; 7122e73debSGreg Roach foreach ($this->user_service->all() as $user) { 7222e73debSGreg Roach $user_name = $user->userName(); 7322e73debSGreg Roach $users[$user_name] = $user_name; 7422e73debSGreg Roach } 7522e73debSGreg Roach 7622e73debSGreg Roach // First and last change in the database. 7722e73debSGreg Roach $earliest = DB::table('change')->min('change_time'); 7822e73debSGreg Roach $latest = DB::table('change')->max('change_time'); 7922e73debSGreg Roach 80*28589336SGreg Roach $earliest = Carbon::make($earliest) ?? Carbon::now(); 81*28589336SGreg Roach $latest = Carbon::make($latest) ?? Carbon::now(); 8222e73debSGreg Roach 8322e73debSGreg Roach $earliest = $earliest->toDateString(); 8422e73debSGreg Roach $latest = $latest->toDateString(); 8522e73debSGreg Roach 8622e73debSGreg Roach $from = $request->getQueryParams()['from'] ?? $earliest; 8722e73debSGreg Roach $to = $request->getQueryParams()['to'] ?? $latest; 8822e73debSGreg Roach $type = $request->getQueryParams()['type'] ?? ''; 8922e73debSGreg Roach $oldged = $request->getQueryParams()['oldged'] ?? ''; 9022e73debSGreg Roach $newged = $request->getQueryParams()['newged'] ?? ''; 9122e73debSGreg Roach $xref = $request->getQueryParams()['xref'] ?? ''; 9222e73debSGreg Roach $username = $request->getQueryParams()['username'] ?? ''; 9322e73debSGreg Roach 9422e73debSGreg Roach return $this->viewResponse('admin/changes-log', [ 9522e73debSGreg Roach 'earliest' => $earliest, 9622e73debSGreg Roach 'from' => $from, 9722e73debSGreg Roach 'latest' => $latest, 9822e73debSGreg Roach 'newged' => $newged, 9922e73debSGreg Roach 'oldged' => $oldged, 10022e73debSGreg Roach 'statuses' => $this->changeStatuses(), 10122e73debSGreg Roach 'title' => I18N::translate('Changes log'), 10222e73debSGreg Roach 'to' => $to, 10322e73debSGreg Roach 'tree' => $tree, 10422e73debSGreg Roach 'trees' => $trees, 10522e73debSGreg Roach 'type' => $type, 10622e73debSGreg Roach 'username' => $username, 10722e73debSGreg Roach 'users' => $users, 10822e73debSGreg Roach 'xref' => $xref, 10922e73debSGreg Roach ]); 11022e73debSGreg Roach } 11122e73debSGreg Roach 11222e73debSGreg Roach /** 11322e73debSGreg Roach * Labels for the various statuses. 11422e73debSGreg Roach * 11522e73debSGreg Roach * @return array 11622e73debSGreg Roach */ 11722e73debSGreg Roach private function changeStatuses(): array 11822e73debSGreg Roach { 11922e73debSGreg Roach return [ 12022e73debSGreg Roach '' => '', 12122e73debSGreg Roach /* I18N: the status of an edit accepted/rejected/pending */ 12222e73debSGreg Roach 'accepted' => I18N::translate('accepted'), 12322e73debSGreg Roach /* I18N: the status of an edit accepted/rejected/pending */ 12422e73debSGreg Roach 'rejected' => I18N::translate('rejected'), 12522e73debSGreg Roach /* I18N: the status of an edit accepted/rejected/pending */ 12622e73debSGreg Roach 'pending' => I18N::translate('pending'), 12722e73debSGreg Roach ]; 12822e73debSGreg Roach } 12922e73debSGreg Roach} 130