Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
89.47% |
17 / 19 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
TicketprinterAccess | |
89.47% |
17 / 19 |
|
80.00% |
4 / 5 |
18.38 | |
0.00% |
0 / 1 |
testTicketprinter | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
testMatchingClusterAndScopes | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
6 | |||
testTicketprinterNotFound | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
testTicketprinterIsProtectedEnabled | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
12 | |||
testTicketprinterValidHash | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | namespace BO\Zmsapi\Helper; |
4 | |
5 | use BO\Slim\Render; |
6 | use BO\Zmsdb\Useraccount; |
7 | |
8 | class TicketprinterAccess |
9 | { |
10 | /** |
11 | * Test if ticketprinter found and if protection is enabled |
12 | * |
13 | * @return array $useraccount |
14 | */ |
15 | public static function testTicketprinter($entity) |
16 | { |
17 | if ($entity->hasId()) { |
18 | $organisation = (new \BO\Zmsdb\Organisation())->readByHash($entity->hash); |
19 | } |
20 | self::testTicketprinterNotFound($entity); |
21 | self::testTicketprinterValidHash($entity); |
22 | self::testMatchingClusterAndScopes($entity, $organisation->getId()); |
23 | } |
24 | |
25 | public static function testMatchingClusterAndScopes($entity, $organisationId) |
26 | { |
27 | if (isset($entity->buttons) && $entity->buttons) { |
28 | $departmentList = (new \BO\Zmsdb\Department())->readByOrganisationId($organisationId, 1); |
29 | $scopeList = $departmentList->getUniqueScopeList(); |
30 | //$clusterList = $departmentList->getUniqueClusterList(); |
31 | foreach ($entity->buttons as $button) { |
32 | if ('scope' == $button['type'] && ! $scopeList->hasEntity($button['scope']['id'])) { |
33 | throw new \BO\Zmsapi\Exception\Ticketprinter\UnvalidButtonList(); |
34 | } /*elseif ('cluster' == $button['type'] && ! $clusterList->hasEntity($button['cluster']['id'])) { |
35 | throw new \BO\Zmsapi\Exception\Ticketprinter\UnvalidButtonList(); |
36 | }*/ |
37 | } |
38 | } |
39 | } |
40 | |
41 | public static function testTicketprinterNotFound($entity) |
42 | { |
43 | if (! $entity->hasId() || ! (new \BO\Zmsdb\Ticketprinter())->readByHash($entity->getId())->hasId()) { |
44 | throw new \BO\Zmsapi\Exception\Ticketprinter\TicketprinterNotFound(); |
45 | } |
46 | } |
47 | |
48 | public static function testTicketprinterIsProtectedEnabled($entity, $isProtectionEnabled) |
49 | { |
50 | if ($isProtectionEnabled && ! $entity->isEnabled()) { |
51 | throw new \BO\Zmsapi\Exception\Ticketprinter\TicketprinterNotEnabled(); |
52 | } |
53 | } |
54 | |
55 | public static function testTicketprinterValidHash($entity) |
56 | { |
57 | if ( |
58 | isset($entity->id) && |
59 | $entity->id && |
60 | (new \BO\Zmsdb\Ticketprinter())->readByHash($entity->hash)->id != $entity->id |
61 | ) { |
62 | throw new \BO\Zmsapi\Exception\Ticketprinter\TicketprinterHashNotValid(); |
63 | } |
64 | } |
65 | } |