Lines 97.82% 45 / 46
Functions and Methods 0.00% 0 / 1
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ProcessLog 97.82% 45 / 46 0.00% 0 / 1 4 0.00% 0 / 1
 readResponse 97.82% 45 / 46 0.00% 0 / 1 4
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsbackend\Process\Api;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsbackend\Helper\SearchPagination;
13use BO\Zmsbackend\Log\Service\Log as Query;
14use DateTime;
15
16class ProcessLog extends \BO\Zmsbackend\Api\BaseController
17{
18    /**
19     * @SuppressWarnings(Param)
20     * @return \Psr\Http\Message\ResponseInterface
21     */
22    #[\Override]
23    public function readResponse(
24        \Psr\Http\Message\RequestInterface $request,
25        \Psr\Http\Message\ResponseInterface $response,
26        array $args
27    ) {
28        (new \BO\Zmsbackend\Helper\User($request))->checkPermissions('logs');
29        $searchQuery = Validator::param('searchQuery')->isString()->setDefault(null)->getValue();
30        $service = Validator::param('service')->isString()->setDefault(null)->getValue();
31        $provider = Validator::param('provider')->isString()->setDefault(null)->getValue();
32        $date = Validator::param('date')->isString()->setDefault(null)->getValue();
33        $userAction = Validator::param('userAction')->isNumber()->setDefault(0)->getValue();
34        $requestedPage = (int) Validator::param('page')->isNumber()->setDefault(1)->getValue();
35        $requestedResultsPerPage = (int) Validator::param('perPage')
36            ->isNumber()
37            ->setDefault(SearchPagination::DEFAULT_RESULTS_PER_PAGE)
38            ->getValue();
39        $page = SearchPagination::normalizePage($requestedPage);
40        $resultsPerPage = SearchPagination::normalizeResultsPerPage($requestedResultsPerPage);
41        $scopeIds = Validator::param('scopeIds')->isString()->setDefault(null)->getValue();
42
43        $resolvedScopeIds = null;
44        if ($scopeIds !== null && $scopeIds !== '') {
45            $resolvedScopeIds = array_values(array_filter(array_map('intval', explode(',', $scopeIds))));
46        }
47
48        $query = new Query();
49        $dateTime = $date ? new DateTime($date) : null;
50        $generalSearch = urldecode((string) $searchQuery);
51
52        $logList = $query->readByProcessData(
53            $generalSearch,
54            $service,
55            $provider,
56            $dateTime,
57            $userAction,
58            $page,
59            $resultsPerPage,
60            $resolvedScopeIds
61        );
62        $totalCount = $query->countByProcessData(
63            $generalSearch,
64            $service,
65            $provider,
66            $dateTime,
67            $userAction,
68            $resolvedScopeIds
69        );
70
71        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
72        $message->data = $logList;
73        $message->meta->totalCount = $totalCount;
74        $message->meta->page = $page;
75        $message->meta->limit = $resultsPerPage;
76
77        $response = Render::withLastModified($response, time(), '0');
78        $response = Render::withJson($response, $message, 200);
79        return $response;
80    }
81}