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