1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2023 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\DB; 23use Fisharebest\Webtrees\Http\ViewResponseTrait; 24use Fisharebest\Webtrees\I18N; 25use Fisharebest\Webtrees\Registry; 26use Fisharebest\Webtrees\Services\TreeService; 27use Fisharebest\Webtrees\Services\UserService; 28use Fisharebest\Webtrees\Validator; 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 = Validator::attributes($request)->tree(); 64 $trees = $this->tree_service->titles(); 65 $users = ['' => '']; 66 67 foreach ($this->user_service->all() as $user) { 68 $user_name = $user->userName(); 69 $users[$user_name] = $user_name; 70 } 71 72 // First and last change in the database. 73 $earliest = DB::table('change')->min('change_time'); 74 $latest = DB::table('change')->max('change_time'); 75 76 $earliest = Registry::timestampFactory()->fromString($earliest)->toDateString(); 77 $latest = Registry::timestampFactory()->fromString($latest)->toDateString(); 78 79 $from = Validator::queryParams($request)->string('from', $earliest); 80 $to = Validator::queryParams($request)->string('to', $latest); 81 $type = Validator::queryParams($request)->string('type', ''); 82 $oldged = Validator::queryParams($request)->string('oldged', ''); 83 $newged = Validator::queryParams($request)->string('newged', ''); 84 $xref = Validator::queryParams($request)->string('xref', ''); 85 $username = Validator::queryParams($request)->string('username', ''); 86 87 return $this->viewResponse('admin/changes-log', [ 88 'earliest' => $earliest, 89 'from' => $from, 90 'latest' => $latest, 91 'newged' => $newged, 92 'oldged' => $oldged, 93 'statuses' => $this->changeStatuses(), 94 'title' => I18N::translate('Changes log'), 95 'to' => $to, 96 'tree' => $tree, 97 'trees' => $trees, 98 'type' => $type, 99 'username' => $username, 100 'users' => $users, 101 'xref' => $xref, 102 ]); 103 } 104 105 /** 106 * Labels for the various statuses. 107 * 108 * @return array<string,string> 109 */ 110 private function changeStatuses(): array 111 { 112 return [ 113 '' => '', 114 /* I18N: the status of an edit accepted/rejected/pending */ 115 'accepted' => I18N::translate('accepted'), 116 /* I18N: the status of an edit accepted/rejected/pending */ 117 'rejected' => I18N::translate('rejected'), 118 /* I18N: the status of an edit accepted/rejected/pending */ 119 'pending' => I18N::translate('pending'), 120 ]; 121 } 122} 123