xref: /webtrees/app/Http/RequestHandlers/SiteLogsData.php (revision 5cac87ae725131e0533df3938e6bed4a6eda5c1b)
157bfa969SGreg Roach<?php
257bfa969SGreg Roach
357bfa969SGreg Roach/**
457bfa969SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
657bfa969SGreg Roach * This program is free software: you can redistribute it and/or modify
757bfa969SGreg Roach * it under the terms of the GNU General Public License as published by
857bfa969SGreg Roach * the Free Software Foundation, either version 3 of the License, or
957bfa969SGreg Roach * (at your option) any later version.
1057bfa969SGreg Roach * This program is distributed in the hope that it will be useful,
1157bfa969SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1257bfa969SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1357bfa969SGreg Roach * GNU General Public License for more details.
1457bfa969SGreg 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/>.
1657bfa969SGreg Roach */
1757bfa969SGreg Roach
1857bfa969SGreg Roachdeclare(strict_types=1);
1957bfa969SGreg Roach
2057bfa969SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
2157bfa969SGreg Roach
22*5cac87aeSGreg Roachuse DateTimeImmutable;
23*5cac87aeSGreg Roachuse DateTimeZone;
24*5cac87aeSGreg Roachuse Fisharebest\Webtrees\Auth;
25*5cac87aeSGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
2657bfa969SGreg Roachuse Fisharebest\Webtrees\Services\DatatablesService;
2757bfa969SGreg Roachuse Fisharebest\Webtrees\Services\SiteLogsService;
2857bfa969SGreg Roachuse Psr\Http\Message\ResponseInterface;
2957bfa969SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
3057bfa969SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
3157bfa969SGreg Roach
3257bfa969SGreg Roachuse function e;
3357bfa969SGreg Roach
3457bfa969SGreg Roach/**
3557bfa969SGreg Roach * Find logs.
3657bfa969SGreg Roach */
3757bfa969SGreg Roachclass SiteLogsData implements RequestHandlerInterface
3857bfa969SGreg Roach{
39c4943cffSGreg Roach    private DatatablesService $datatables_service;
4057bfa969SGreg Roach
41c4943cffSGreg Roach    private SiteLogsService $site_logs_service;
4257bfa969SGreg Roach
4357bfa969SGreg Roach    public function __construct(
4457bfa969SGreg Roach        DatatablesService $datatables_service,
4557bfa969SGreg Roach        SiteLogsService $site_logs_service
4657bfa969SGreg Roach    ) {
4757bfa969SGreg Roach        $this->datatables_service = $datatables_service;
4857bfa969SGreg Roach        $this->site_logs_service  = $site_logs_service;
4957bfa969SGreg Roach    }
5057bfa969SGreg Roach
5157bfa969SGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
5257bfa969SGreg Roach    {
536c21f8beSGreg Roach        $query = $this->site_logs_service->logsQuery($request);
5457bfa969SGreg Roach
55f70bcff5SGreg Roach        return $this->datatables_service->handleQuery($request, $query, [], [], static function (object $row): array {
56*5cac87aeSGreg Roach            $log_time = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $row->log_time, new DateTimeZone('UTC'))
57*5cac87aeSGreg Roach                ->setTimezone(new DateTimeZone(Auth::user()->getPreference(UserInterface::PREF_TIME_ZONE, 'UTC')))
58*5cac87aeSGreg Roach                ->format('Y-m-d H:i:s T');
59*5cac87aeSGreg Roach
6057bfa969SGreg Roach            return [
6157bfa969SGreg Roach                $row->log_id,
62*5cac87aeSGreg Roach                $log_time,
6357bfa969SGreg Roach                $row->log_type,
64533502eaSGreg Roach                '<span class="ut">' . e($row->log_message) . '</span>',
65533502eaSGreg Roach                e($row->ip_address),
66533502eaSGreg Roach                '<span class="ut">' . e($row->user_name) . '</span>',
67533502eaSGreg Roach                '<span class="ut">' . e($row->gedcom_name) . '</span>',
6857bfa969SGreg Roach            ];
6957bfa969SGreg Roach        });
7057bfa969SGreg Roach    }
7157bfa969SGreg Roach}
72