Lines 100.00% 27 / 27
Functions and Methods 100.00% 7 / 7
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Ticketprinter 100.00% 27 / 27 100.00% 7 / 7 9 100.00% 1 / 1
 getOrganisationIdByHash 100.00% 2 / 2 100.00% 1 / 1 1
 getEntityMapping 100.00% 7 / 7 100.00% 1 / 1 1
 addConditionTicketprinterId 100.00% 2 / 2 100.00% 1 / 1 1
 addConditionOrganisationId 100.00% 2 / 2 100.00% 1 / 1 1
 addConditionHash 100.00% 2 / 2 100.00% 1 / 1 1
 addConditionDeleteInterval 100.00% 2 / 2 100.00% 1 / 1 1
 reverseEntityMapping 100.00% 10 / 10 100.00% 1 / 1 3
1<?php
2
3namespace BO\Zmsbackend\Ticketprinter\Repository;
4
5class Ticketprinter extends \BO\Zmsbackend\Query\Base implements \BO\Zmsbackend\Query\MappingInterface
6{
7    /**
8     * @var String TABLE mysql table reference
9     */
10    const string TABLE = 'kiosk';
11
12    const string PRIMARY = 'hash';
13
14    /**
15     * No resolving required here
16     */
17    protected $resolveLevel = 0;
18
19    public function getOrganisationIdByHash(): string
20    {
21        return '
22            SELECT organisationsid
23            FROM `kiosk` ticketprinter
24            WHERE ticketprinter.`cookiecode` = :hash';
25    }
26
27    /**
28     * @return (\BO\Zmsbackend\Query\Builder\Expression|string)[]
29     *
30     */
31    #[\Override]
32    public function getEntityMapping()
33    {
34        return [
35            'enabled' => self::expression('CAST(`ticketprinter`.`zugelassen` AS SIGNED)'),
36            'hash' => 'ticketprinter.cookiecode',
37            'id' => 'ticketprinter.kioskid',
38            'lastUpdate' => 'ticketprinter.timestamp',
39            'name' => 'ticketprinter.name'
40        ];
41    }
42
43    public function addConditionTicketprinterId(int|string $ticketprinterId): static
44    {
45        $this->query->where('ticketprinter.kioskid', '=', $ticketprinterId);
46        return $this;
47    }
48
49    public function addConditionOrganisationId(int $organisationId): static
50    {
51        $this->query->where('ticketprinter.organisationsid', '=', $organisationId);
52        return $this;
53    }
54
55    public function addConditionHash(string $hash): static
56    {
57        $this->query->where('ticketprinter.cookiecode', '=', $hash);
58        return $this;
59    }
60
61    public function addConditionDeleteInterval($expirationDate): static
62    {
63        $this->query->where('ticketprinter.timestamp', '<=', $expirationDate->getTimestamp());
64        return $this;
65    }
66
67    /**
68     * @return (int|mixed)[]
69     *
70     */
71    public function reverseEntityMapping(\BO\Zmsentities\Ticketprinter $entity, int $organisationId): array
72    {
73        $data = array();
74        $data['organisationsid'] = $organisationId;
75        $data['zugelassen'] = ($entity->isEnabled()) ? 1 : 0;
76        $data['cookiecode'] = $entity->getId();
77        $data['timestamp'] = time();
78        $data['name'] = $entity->toProperty()->name->get();
79        $data = array_filter($data, function ($value) {
80            return ($value !== null && $value !== false);
81        });
82        return $data;
83    }
84}