xref: /webtrees/app/Http/RequestHandlers/SiteLogsData.php (revision d11be7027e34e3121be11cc025421873364403f9)
157bfa969SGreg Roach<?php
257bfa969SGreg Roach
357bfa969SGreg Roach/**
457bfa969SGreg Roach * webtrees: online genealogy
5*d11be702SGreg 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
22d97083feSGreg Roachuse Fisharebest\Webtrees\Registry;
2357bfa969SGreg Roachuse Fisharebest\Webtrees\Services\DatatablesService;
2457bfa969SGreg Roachuse Fisharebest\Webtrees\Services\SiteLogsService;
2557bfa969SGreg Roachuse Psr\Http\Message\ResponseInterface;
2657bfa969SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
2757bfa969SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
2857bfa969SGreg Roach
2957bfa969SGreg Roachuse function e;
3057bfa969SGreg Roach
3157bfa969SGreg Roach/**
3257bfa969SGreg Roach * Find logs.
3357bfa969SGreg Roach */
3457bfa969SGreg Roachclass SiteLogsData implements RequestHandlerInterface
3557bfa969SGreg Roach{
36c4943cffSGreg Roach    private DatatablesService $datatables_service;
3757bfa969SGreg Roach
38c4943cffSGreg Roach    private SiteLogsService $site_logs_service;
3957bfa969SGreg Roach
4057bfa969SGreg Roach    /**
4157bfa969SGreg Roach     * @param DatatablesService $datatables_service
4257bfa969SGreg Roach     * @param SiteLogsService   $site_logs_service
4357bfa969SGreg Roach     */
4457bfa969SGreg Roach    public function __construct(
4557bfa969SGreg Roach        DatatablesService $datatables_service,
4657bfa969SGreg Roach        SiteLogsService $site_logs_service
4757bfa969SGreg Roach    ) {
4857bfa969SGreg Roach        $this->datatables_service = $datatables_service;
4957bfa969SGreg Roach        $this->site_logs_service  = $site_logs_service;
5057bfa969SGreg Roach    }
5157bfa969SGreg Roach
5257bfa969SGreg Roach    /**
5357bfa969SGreg Roach     * @param ServerRequestInterface $request
5457bfa969SGreg Roach     *
5557bfa969SGreg Roach     * @return ResponseInterface
5657bfa969SGreg Roach     */
5757bfa969SGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
5857bfa969SGreg Roach    {
596c21f8beSGreg Roach        $query = $this->site_logs_service->logsQuery($request);
6057bfa969SGreg Roach
61f70bcff5SGreg Roach        return $this->datatables_service->handleQuery($request, $query, [], [], static function (object $row): array {
6257bfa969SGreg Roach            return [
6357bfa969SGreg Roach                $row->log_id,
64d97083feSGreg Roach                Registry::timestampFactory()->fromString($row->log_time)->toDateTimeString(),
6557bfa969SGreg Roach                $row->log_type,
66533502eaSGreg Roach                '<span class="ut">' . e($row->log_message) . '</span>',
67533502eaSGreg Roach                e($row->ip_address),
68533502eaSGreg Roach                '<span class="ut">' . e($row->user_name) . '</span>',
69533502eaSGreg Roach                '<span class="ut">' . e($row->gedcom_name) . '</span>',
7057bfa969SGreg Roach            ];
7157bfa969SGreg Roach        });
7257bfa969SGreg Roach    }
7357bfa969SGreg Roach}
74