1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Http\RequestHandlers; 21 22use Fisharebest\Webtrees\Carbon; 23use Fisharebest\Webtrees\Http\ViewResponseTrait; 24use Fisharebest\Webtrees\I18N; 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 /** @var TreeService */ 41 private $tree_service; 42 43 /** @var UserService */ 44 private $user_service; 45 46 /** 47 * @param TreeService $tree_service 48 * @param UserService $user_service 49 */ 50 public function __construct(TreeService $tree_service, UserService $user_service) 51 { 52 $this->tree_service = $tree_service; 53 $this->user_service = $user_service; 54 } 55 56 /** 57 * @param ServerRequestInterface $request 58 * 59 * @return ResponseInterface 60 */ 61 public function handle(ServerRequestInterface $request): ResponseInterface 62 { 63 $this->layout = 'layouts/administration'; 64 65 $tree = $request->getAttribute('tree'); 66 assert($tree instanceof Tree); 67 68 $trees = $this->tree_service->titles(); 69 70 $users = ['' => '']; 71 foreach ($this->user_service->all() as $user) { 72 $user_name = $user->userName(); 73 $users[$user_name] = $user_name; 74 } 75 76 // First and last change in the database. 77 $earliest = DB::table('change')->min('change_time'); 78 $latest = DB::table('change')->max('change_time'); 79 80 $earliest = Carbon::make($earliest) ?? Carbon::now(); 81 $latest = Carbon::make($latest) ?? Carbon::now(); 82 83 $earliest = $earliest->toDateString(); 84 $latest = $latest->toDateString(); 85 86 $from = $request->getQueryParams()['from'] ?? $earliest; 87 $to = $request->getQueryParams()['to'] ?? $latest; 88 $type = $request->getQueryParams()['type'] ?? ''; 89 $oldged = $request->getQueryParams()['oldged'] ?? ''; 90 $newged = $request->getQueryParams()['newged'] ?? ''; 91 $xref = $request->getQueryParams()['xref'] ?? ''; 92 $username = $request->getQueryParams()['username'] ?? ''; 93 94 return $this->viewResponse('admin/changes-log', [ 95 'earliest' => $earliest, 96 'from' => $from, 97 'latest' => $latest, 98 'newged' => $newged, 99 'oldged' => $oldged, 100 'statuses' => $this->changeStatuses(), 101 'title' => I18N::translate('Changes log'), 102 'to' => $to, 103 'tree' => $tree, 104 'trees' => $trees, 105 'type' => $type, 106 'username' => $username, 107 'users' => $users, 108 'xref' => $xref, 109 ]); 110 } 111 112 /** 113 * Labels for the various statuses. 114 * 115 * @return array 116 */ 117 private function changeStatuses(): array 118 { 119 return [ 120 '' => '', 121 /* I18N: the status of an edit accepted/rejected/pending */ 122 'accepted' => I18N::translate('accepted'), 123 /* I18N: the status of an edit accepted/rejected/pending */ 124 'rejected' => I18N::translate('rejected'), 125 /* I18N: the status of an edit accepted/rejected/pending */ 126 'pending' => I18N::translate('pending'), 127 ]; 128 } 129} 130