Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.88% covered (success)
96.88%
31 / 32
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProcessLog
96.88% covered (success)
96.88%
31 / 32
0.00% covered (danger)
0.00%
0 / 1
4
0.00% covered (danger)
0.00%
0 / 1
 readResponse
96.88% covered (success)
96.88%
31 / 32
0.00% covered (danger)
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        $logList = (new Query())->readByProcessData(
49            urldecode((string) $searchQuery),
50            $service,
51            $provider,
52            $date ? new DateTime($date) : null,
53            $userAction,
54            $page,
55            $resultsPerPage,
56            $resolvedScopeIds
57        );
58
59        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
60        $message->data = $logList;
61
62        $response = Render::withLastModified($response, time(), '0');
63        $response = Render::withJson($response, $message, 200);
64        return $response;
65    }
66}