Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
EventLog
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
7 / 7
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getEntityMapping
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 reverseEntityMapping
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
2
 postProcess
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 addNameComparison
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addReferenceComparison
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addExpirationCondition
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
5 **/
6
7namespace BO\Zmsbackend\EventLog\Repository;
8
9use BO\Zmsentities\EventLog as EventLogEntity;
10
11class EventLog extends \BO\Zmsbackend\Query\Base
12{
13    public const string TABLE = 'eventlog';
14    public const string ALIAS = 'eventLog';
15
16    protected $resolveLevel = 0;
17
18    public function __construct($queryType, $prefix = '', $name = false, $resolveLevel = null)
19    {
20        parent::__construct($queryType, $prefix, $name, $resolveLevel);
21
22        if ($queryType === self::SELECT) {
23            $this->query->orderBy(self::ALIAS . '.creationDateTime', 'ASC');
24        }
25    }
26    /** @psalm-api */
27    public function getEntityMapping(): array
28    {
29        return [
30            'id'                  => self::ALIAS . '.eventId',
31            'name'                => self::ALIAS . '.eventName',
32            'origin'              => self::ALIAS . '.origin',
33            'referenceType'       => self::ALIAS . '.referenceType',
34            'reference'           => self::ALIAS . '.reference',
35            'sessionid'           => self::ALIAS . '.sessionid',
36            'context'             => self::ALIAS . '.contextjson',
37            'creationDateTime'    => self::ALIAS . '.creationDateTime',
38            'expirationDateTime'  => self::ALIAS . '.expirationDateTime',
39        ];
40    }
41
42    public function reverseEntityMapping(EventLogEntity $entity): array
43    {
44        $data = [
45            'eventName' => $entity->name,
46            'origin' => $entity->origin,
47            'referenceType' => $entity->referenceType,
48            'reference' => $entity->reference,
49            'sessionid' => $entity->sessionid,
50            'contextjson' => json_encode($entity->context, JSON_FORCE_OBJECT),
51            'creationDateTime' => $entity->creationDateTime->format('Y-m-d H:i:s'),
52            'expirationDateTime' => $entity->expirationDateTime->format('Y-m-d H:i:s'),
53        ];
54
55        return array_filter($data, function ($value) {
56            return ($value !== null && $value !== false);
57        });
58    }
59
60    /**
61     * @param array $data
62     * @return array
63     */
64    #[\Override]
65    public function postProcess($data): array
66    {
67        $data['id'] = (int) $data['id'];
68        $data['context'] = json_decode($data['context'], true);
69        $data['creationDateTime'] = new \DateTime($data['creationDateTime']);
70        $data['expirationDateTime'] = new \DateTime($data['expirationDateTime']);
71        return $data;
72    }
73
74    public function addNameComparison(string $name): EventLog
75    {
76        $this->query->where(self::ALIAS . '.eventName', '=', $name);
77
78        return $this;
79    }
80
81    public function addReferenceComparison(string $reference): EventLog
82    {
83        $this->query->where(self::ALIAS . '.reference', '=', $reference);
84
85        return $this;
86    }
87
88    public function addExpirationCondition(): EventLog
89    {
90        $this->query->where(self::ALIAS . '.creationDateTime', '<', (new \DateTime())->format('Y-m-d H:i:s'));
91
92        return $this;
93    }
94}