xref: /webtrees/app/Http/RequestHandlers/PendingChangesLogPage.php (revision d11be7027e34e3121be11cc025421873364403f9)
122e73debSGreg Roach<?php
222e73debSGreg Roach
322e73debSGreg Roach/**
422e73debSGreg Roach * webtrees: online genealogy
5*d11be702SGreg 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
2222e73debSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait;
2322e73debSGreg Roachuse Fisharebest\Webtrees\I18N;
24d97083feSGreg Roachuse Fisharebest\Webtrees\Registry;
2522e73debSGreg Roachuse Fisharebest\Webtrees\Services\TreeService;
2622e73debSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
27b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator;
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
40c4943cffSGreg Roach    private TreeService $tree_service;
4122e73debSGreg Roach
42c4943cffSGreg Roach    private UserService $user_service;
4322e73debSGreg Roach
4422e73debSGreg Roach    /**
4522e73debSGreg Roach     * @param TreeService $tree_service
4622e73debSGreg Roach     * @param UserService $user_service
4722e73debSGreg Roach     */
4822e73debSGreg Roach    public function __construct(TreeService $tree_service, UserService $user_service)
4922e73debSGreg Roach    {
5022e73debSGreg Roach        $this->tree_service = $tree_service;
5122e73debSGreg Roach        $this->user_service = $user_service;
5222e73debSGreg Roach    }
5322e73debSGreg Roach
5422e73debSGreg Roach    /**
5522e73debSGreg Roach     * @param ServerRequestInterface $request
5622e73debSGreg Roach     *
5722e73debSGreg Roach     * @return ResponseInterface
5822e73debSGreg Roach     */
5922e73debSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
6022e73debSGreg Roach    {
6122e73debSGreg Roach        $this->layout = 'layouts/administration';
6222e73debSGreg Roach
63b55cbc6bSGreg Roach        $tree  = Validator::attributes($request)->tree();
6422e73debSGreg Roach        $trees = $this->tree_service->titles();
6522e73debSGreg Roach        $users = ['' => ''];
66b55cbc6bSGreg Roach
6722e73debSGreg Roach        foreach ($this->user_service->all() as $user) {
6822e73debSGreg Roach            $user_name         = $user->userName();
6922e73debSGreg Roach            $users[$user_name] = $user_name;
7022e73debSGreg Roach        }
7122e73debSGreg Roach
7222e73debSGreg Roach        // First and last change in the database.
7322e73debSGreg Roach        $earliest = DB::table('change')->min('change_time');
7422e73debSGreg Roach        $latest   = DB::table('change')->max('change_time');
7522e73debSGreg Roach
76748dbe15SGreg Roach        $earliest = Registry::timestampFactory()->fromString($earliest)->toDateString();
77748dbe15SGreg Roach        $latest   = Registry::timestampFactory()->fromString($latest)->toDateString();
7822e73debSGreg Roach
79748dbe15SGreg Roach        $from     = Validator::queryParams($request)->string('from', $earliest);
80748dbe15SGreg Roach        $to       = Validator::queryParams($request)->string('to', $latest);
81748dbe15SGreg Roach        $type     = Validator::queryParams($request)->string('type', '');
82748dbe15SGreg Roach        $oldged   = Validator::queryParams($request)->string('oldged', '');
83748dbe15SGreg Roach        $newged   = Validator::queryParams($request)->string('newged', '');
84748dbe15SGreg Roach        $xref     = Validator::queryParams($request)->string('xref', '');
85748dbe15SGreg Roach        $username = Validator::queryParams($request)->string('username', '');
8622e73debSGreg Roach
8722e73debSGreg Roach        return $this->viewResponse('admin/changes-log', [
8822e73debSGreg Roach            'earliest' => $earliest,
8922e73debSGreg Roach            'from'     => $from,
9022e73debSGreg Roach            'latest'   => $latest,
9122e73debSGreg Roach            'newged'   => $newged,
9222e73debSGreg Roach            'oldged'   => $oldged,
9322e73debSGreg Roach            'statuses' => $this->changeStatuses(),
9422e73debSGreg Roach            'title'    => I18N::translate('Changes log'),
9522e73debSGreg Roach            'to'       => $to,
9622e73debSGreg Roach            'tree'     => $tree,
9722e73debSGreg Roach            'trees'    => $trees,
9822e73debSGreg Roach            'type'     => $type,
9922e73debSGreg Roach            'username' => $username,
10022e73debSGreg Roach            'users'    => $users,
10122e73debSGreg Roach            'xref'     => $xref,
10222e73debSGreg Roach        ]);
10322e73debSGreg Roach    }
10422e73debSGreg Roach
10522e73debSGreg Roach    /**
10622e73debSGreg Roach     * Labels for the various statuses.
10722e73debSGreg Roach     *
108ac701fbdSGreg Roach     * @return array<string,string>
10922e73debSGreg Roach     */
11022e73debSGreg Roach    private function changeStatuses(): array
11122e73debSGreg Roach    {
11222e73debSGreg Roach        return [
11322e73debSGreg Roach            ''         => '',
11422e73debSGreg Roach            /* I18N: the status of an edit accepted/rejected/pending */
11522e73debSGreg Roach            'accepted' => I18N::translate('accepted'),
11622e73debSGreg Roach            /* I18N: the status of an edit accepted/rejected/pending */
11722e73debSGreg Roach            'rejected' => I18N::translate('rejected'),
11822e73debSGreg Roach            /* I18N: the status of an edit accepted/rejected/pending */
11922e73debSGreg Roach            'pending'  => I18N::translate('pending'),
12022e73debSGreg Roach        ];
12122e73debSGreg Roach    }
12222e73debSGreg Roach}
123