122e73debSGreg Roach<?php 222e73debSGreg Roach 322e73debSGreg Roach/** 422e73debSGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 1622e73debSGreg Roach */ 1722e73debSGreg Roach 1822e73debSGreg Roachdeclare(strict_types=1); 1922e73debSGreg Roach 2022e73debSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 2122e73debSGreg Roach 22*5cac87aeSGreg Roachuse DateTimeImmutable; 23*5cac87aeSGreg Roachuse DateTimeZone; 24*5cac87aeSGreg Roachuse Fisharebest\Webtrees\Auth; 25*5cac87aeSGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 266f4ec3caSGreg Roachuse Fisharebest\Webtrees\DB; 2722e73debSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 2822e73debSGreg Roachuse Fisharebest\Webtrees\I18N; 2922e73debSGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 3022e73debSGreg Roachuse Fisharebest\Webtrees\Services\UserService; 31b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 3222e73debSGreg Roachuse Psr\Http\Message\ResponseInterface; 3322e73debSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 3422e73debSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 3522e73debSGreg Roach 36*5cac87aeSGreg Roachuse function date; 37*5cac87aeSGreg Roach 3822e73debSGreg Roach/** 3922e73debSGreg Roach * Show pending changes. 4022e73debSGreg Roach */ 4122e73debSGreg Roachclass PendingChangesLogPage implements RequestHandlerInterface 4222e73debSGreg Roach{ 4322e73debSGreg Roach use ViewResponseTrait; 4422e73debSGreg Roach 45c4943cffSGreg Roach private TreeService $tree_service; 4622e73debSGreg Roach 47c4943cffSGreg Roach private UserService $user_service; 4822e73debSGreg Roach 4922e73debSGreg Roach public function __construct(TreeService $tree_service, UserService $user_service) 5022e73debSGreg Roach { 5122e73debSGreg Roach $this->tree_service = $tree_service; 5222e73debSGreg Roach $this->user_service = $user_service; 5322e73debSGreg Roach } 5422e73debSGreg Roach 5522e73debSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 5622e73debSGreg Roach { 5722e73debSGreg Roach $this->layout = 'layouts/administration'; 5822e73debSGreg Roach 59b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 6022e73debSGreg Roach $trees = $this->tree_service->titles(); 6122e73debSGreg Roach $users = ['' => '']; 62b55cbc6bSGreg Roach 6322e73debSGreg Roach foreach ($this->user_service->all() as $user) { 6422e73debSGreg Roach $user_name = $user->userName(); 6522e73debSGreg Roach $users[$user_name] = $user_name; 6622e73debSGreg Roach } 6722e73debSGreg Roach 68*5cac87aeSGreg Roach // First and last change in the database 69*5cac87aeSGreg Roach $earliest = DB::table('change')->min('change_time') ?? date('Y-m-d H:i:s'); 70*5cac87aeSGreg Roach $latest = DB::table('change')->max('change_time') ?? date('Y-m-d H:i:s'); 7122e73debSGreg Roach 72*5cac87aeSGreg Roach $earliest = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $earliest, new DateTimeZone('UTC')) 73*5cac87aeSGreg Roach ->setTimezone(new DateTimeZone(Auth::user()->getPreference(UserInterface::PREF_TIME_ZONE, 'UTC'))) 74*5cac87aeSGreg Roach ->format('Y-m-d'); 75*5cac87aeSGreg Roach 76*5cac87aeSGreg Roach $latest = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $latest, new DateTimeZone('UTC')) 77*5cac87aeSGreg Roach ->setTimezone(new DateTimeZone(Auth::user()->getPreference(UserInterface::PREF_TIME_ZONE, 'UTC'))) 78*5cac87aeSGreg Roach ->format('Y-m-d'); 7922e73debSGreg Roach 80748dbe15SGreg Roach $from = Validator::queryParams($request)->string('from', $earliest); 81748dbe15SGreg Roach $to = Validator::queryParams($request)->string('to', $latest); 82748dbe15SGreg Roach $type = Validator::queryParams($request)->string('type', ''); 83748dbe15SGreg Roach $oldged = Validator::queryParams($request)->string('oldged', ''); 84748dbe15SGreg Roach $newged = Validator::queryParams($request)->string('newged', ''); 85748dbe15SGreg Roach $xref = Validator::queryParams($request)->string('xref', ''); 86748dbe15SGreg Roach $username = Validator::queryParams($request)->string('username', ''); 8722e73debSGreg Roach 8822e73debSGreg Roach return $this->viewResponse('admin/changes-log', [ 8922e73debSGreg Roach 'earliest' => $earliest, 9022e73debSGreg Roach 'from' => $from, 9122e73debSGreg Roach 'latest' => $latest, 9222e73debSGreg Roach 'newged' => $newged, 9322e73debSGreg Roach 'oldged' => $oldged, 9422e73debSGreg Roach 'statuses' => $this->changeStatuses(), 9522e73debSGreg Roach 'title' => I18N::translate('Changes log'), 9622e73debSGreg Roach 'to' => $to, 9722e73debSGreg Roach 'tree' => $tree, 9822e73debSGreg Roach 'trees' => $trees, 9922e73debSGreg Roach 'type' => $type, 10022e73debSGreg Roach 'username' => $username, 10122e73debSGreg Roach 'users' => $users, 10222e73debSGreg Roach 'xref' => $xref, 10322e73debSGreg Roach ]); 10422e73debSGreg Roach } 10522e73debSGreg Roach 10622e73debSGreg Roach /** 10722e73debSGreg Roach * Labels for the various statuses. 10822e73debSGreg Roach * 109ac701fbdSGreg Roach * @return array<string,string> 11022e73debSGreg Roach */ 11122e73debSGreg Roach private function changeStatuses(): array 11222e73debSGreg Roach { 11322e73debSGreg Roach return [ 11422e73debSGreg Roach '' => '', 11522e73debSGreg Roach /* I18N: the status of an edit accepted/rejected/pending */ 11622e73debSGreg Roach 'accepted' => I18N::translate('accepted'), 11722e73debSGreg Roach /* I18N: the status of an edit accepted/rejected/pending */ 11822e73debSGreg Roach 'rejected' => I18N::translate('rejected'), 11922e73debSGreg Roach /* I18N: the status of an edit accepted/rejected/pending */ 12022e73debSGreg Roach 'pending' => I18N::translate('pending'), 12122e73debSGreg Roach ]; 12222e73debSGreg Roach } 12322e73debSGreg Roach} 124