1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2021 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Http\RequestHandlers; 21 22use Fisharebest\Webtrees\Http\ViewResponseTrait; 23use Fisharebest\Webtrees\I18N; 24use Fisharebest\Webtrees\Registry; 25use Fisharebest\Webtrees\Services\TreeService; 26use Fisharebest\Webtrees\Services\UserService; 27use Fisharebest\Webtrees\Tree; 28use Illuminate\Database\Capsule\Manager as DB; 29use Psr\Http\Message\ResponseInterface; 30use Psr\Http\Message\ServerRequestInterface; 31use Psr\Http\Server\RequestHandlerInterface; 32 33/** 34 * Show pending changes. 35 */ 36class PendingChangesLogPage implements RequestHandlerInterface 37{ 38 use ViewResponseTrait; 39 40 private TreeService $tree_service; 41 42 private UserService $user_service; 43 44 /** 45 * @param TreeService $tree_service 46 * @param UserService $user_service 47 */ 48 public function __construct(TreeService $tree_service, UserService $user_service) 49 { 50 $this->tree_service = $tree_service; 51 $this->user_service = $user_service; 52 } 53 54 /** 55 * @param ServerRequestInterface $request 56 * 57 * @return ResponseInterface 58 */ 59 public function handle(ServerRequestInterface $request): ResponseInterface 60 { 61 $this->layout = 'layouts/administration'; 62 63 $tree = $request->getAttribute('tree'); 64 assert($tree instanceof Tree); 65 66 $trees = $this->tree_service->titles(); 67 68 $users = ['' => '']; 69 foreach ($this->user_service->all() as $user) { 70 $user_name = $user->userName(); 71 $users[$user_name] = $user_name; 72 } 73 74 // First and last change in the database. 75 $earliest = DB::table('change')->min('change_time'); 76 $latest = DB::table('change')->max('change_time'); 77 78 $earliest = Registry::timestampFactory()->fromString($earliest); 79 $latest = Registry::timestampFactory()->fromString($latest); 80 81 $earliest = $earliest->toDateString(); 82 $latest = $latest->toDateString(); 83 84 $from = $request->getQueryParams()['from'] ?? $earliest; 85 $to = $request->getQueryParams()['to'] ?? $latest; 86 $type = $request->getQueryParams()['type'] ?? ''; 87 $oldged = $request->getQueryParams()['oldged'] ?? ''; 88 $newged = $request->getQueryParams()['newged'] ?? ''; 89 $xref = $request->getQueryParams()['xref'] ?? ''; 90 $username = $request->getQueryParams()['username'] ?? ''; 91 92 return $this->viewResponse('admin/changes-log', [ 93 'earliest' => $earliest, 94 'from' => $from, 95 'latest' => $latest, 96 'newged' => $newged, 97 'oldged' => $oldged, 98 'statuses' => $this->changeStatuses(), 99 'title' => I18N::translate('Changes log'), 100 'to' => $to, 101 'tree' => $tree, 102 'trees' => $trees, 103 'type' => $type, 104 'username' => $username, 105 'users' => $users, 106 'xref' => $xref, 107 ]); 108 } 109 110 /** 111 * Labels for the various statuses. 112 * 113 * @return array<string,string> 114 */ 115 private function changeStatuses(): array 116 { 117 return [ 118 '' => '', 119 /* I18N: the status of an edit accepted/rejected/pending */ 120 'accepted' => I18N::translate('accepted'), 121 /* I18N: the status of an edit accepted/rejected/pending */ 122 'rejected' => I18N::translate('rejected'), 123 /* I18N: the status of an edit accepted/rejected/pending */ 124 'pending' => I18N::translate('pending'), 125 ]; 126 } 127} 128