Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
73.91% covered (warning)
73.91%
17 / 23
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
EventLog
73.91% covered (warning)
73.91%
17 / 23
75.00% covered (warning)
75.00%
3 / 4
14.56
0.00% covered (danger)
0.00%
0 / 1
 getDefaults
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 addData
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
5
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
 setSecondsToLive
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
5 **/
6
7declare(strict_types=1);
8
9namespace BO\Zmsentities;
10
11use BO\Zmsentities\Helper\DateTime;
12use DateTimeInterface;
13
14/**
15 * @property int id
16 * @property string name
17 * @property string origin
18 * @property string referenceType
19 * @property string|null reference
20 * @property string|null sessionid
21 * @property array context
22 * @property DateTimeInterface creationDateTime
23 * @property DateTimeInterface expirationDateTime
24 */
25class EventLog extends Schema\Entity
26{
27    public const PRIMARY = 'id';
28
29    public static $schema = "eventlog.json";
30
31    public const LIVETIME_LONGER  = 315360000; // 10 years
32    public const LIVETIME_LONG    = 94608000; // 3 years
33    public const LIVETIME_YEAR    = 31536000; // one year (365 days)
34    public const LIVETIME_DEFAULT = 15552000; // half a year (180 days)
35    public const LIVETIME_MONTH   = 2592000; // one month (30 days)
36    public const LIVETIME_WEEK    = 604800; // one week
37    public const LIVETIME_DAY     = 86400; // one day
38    public const LIVETIME_HOUR    = 3600; // one hour
39
40    /***************  Event Names ****************/
41    public const CLIENT_PROCESSLIST_REQUEST = 'CLIENT_PROCESSLIST_REQUEST';
42    public const CLIENT_PROCESSLIST_SEND = 'CLIENT_PROCESSLIST_REQUEST';
43    // examples for future use below
44    public const QUEUE_PROCESS_SCHEDULE = 'CLIENT_PROCESSLIST_REQUEST';
45    public const QUEUE_PROCESS_DELETE = 'CLIENT_PROCESSLIST_REQUEST';
46    public const WORKSTATION_PROCESS_CALL = 'CLIENT_PROCESSLIST_REQUEST';
47    public const WORKSTATION_PROCESS_START = 'CLIENT_PROCESSLIST_REQUEST';
48    public const WORKSTATION_PROCESS_FINISH = 'CLIENT_PROCESSLIST_REQUEST';
49
50    public function getDefaults(): array
51    {
52        return [
53            'id' => 0,
54            'name' => '',
55            'origin' => '',
56            'referenceType' => 'none',
57            'reference' => null,
58            'sessionid' => null,
59            'context' => [],
60            'creationDateTime' => new DateTime(),
61            'expirationDateTime' => new DateTime('9999-12-31 00:00:00'),
62        ];
63    }
64
65    /**
66     * {@inheritDoc}
67     */
68    public function addData($mergeData): Schema\Entity
69    {
70        if (isset($mergeData['creationDateTime']) && is_string($mergeData['creationDateTime'])) {
71            $mergeData['creationDateTime'] = new DateTime($mergeData['creationDateTime']);
72        }
73        if (isset($mergeData['expirationDateTime']) && is_string($mergeData['expirationDateTime'])) {
74            $mergeData['expirationDateTime'] = new DateTime($mergeData['expirationDateTime']);
75        }
76
77        return parent::addData($mergeData);
78    }
79
80    public function jsonSerialize()
81    {
82        $clone = clone $this;
83        if (isset($clone['creationDateTime']) && $clone['creationDateTime'] instanceof DateTimeInterface) {
84            $clone['creationDateTime'] = $clone['creationDateTime']->format(DATE_ATOM);
85        }
86        if (isset($clone['expirationDateTime']) && $clone['expirationDateTime'] instanceof DateTimeInterface) {
87            $clone['expirationDateTime'] = $clone['expirationDateTime']->format(DATE_ATOM);
88        }
89
90        return $clone->jsonSerialize();
91    }
92
93    /**
94     * sets the expiration time by adding the desired seconds to live to the current time
95     *
96     * @param int $secondsToLive
97     * @return void
98     */
99    public function setSecondsToLive(int $secondsToLive): void
100    {
101        $this['expirationDateTime'] = new DateTime('+' . $secondsToLive . ' seconds');
102    }
103}