Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.44% |
51 / 54 |
|
90.91% |
10 / 11 |
CRAP | |
0.00% |
0 / 1 |
Ticketprinter | |
94.44% |
51 / 54 |
|
90.91% |
10 / 11 |
26.12 | |
0.00% |
0 / 1 |
getDefaults | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getHashWith | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
isEnabled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toStructuredButtonList | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
getScopeList | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
getClusterList | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
getValidButtonWithType | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
getButtonData | |
70.00% |
7 / 10 |
|
0.00% |
0 / 1 |
3.24 | |||
getButtonValue | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getButtonType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getExternalLinkData | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | namespace BO\Zmsentities; |
4 | |
5 | use BO\Mellon\Validator; |
6 | use BO\Zmsentities\Helper\Property; |
7 | |
8 | class Ticketprinter extends Schema\Entity |
9 | { |
10 | const PRIMARY = 'hash'; |
11 | |
12 | public static $schema = "ticketprinter.json"; |
13 | |
14 | protected $allowedButtonTypes = [ |
15 | 's' => 'scope', |
16 | /*'c' => 'cluster',*/ |
17 | 'l' => 'link', |
18 | 'r' => 'request' |
19 | ]; |
20 | |
21 | public function getDefaults() |
22 | { |
23 | return [ |
24 | 'enabled' => false, |
25 | 'reload' => 30 |
26 | ]; |
27 | } |
28 | |
29 | public function getHashWith($organisiationId) |
30 | { |
31 | $this->hash = $organisiationId . "abcdefghijklmnopqrstuvwxyz"; |
32 | //$this->hash = $organisiationId . bin2hex(openssl_random_pseudo_bytes(16)); |
33 | return $this; |
34 | } |
35 | |
36 | public function isEnabled() |
37 | { |
38 | return $this->enabled; |
39 | } |
40 | |
41 | public function toStructuredButtonList() |
42 | { |
43 | $ticketprinter = clone $this; |
44 | $ticketprinter->buttons = array(); |
45 | $buttonList = explode(',', $ticketprinter->buttonlist); |
46 | foreach ($buttonList as $string) { |
47 | $button = array(); |
48 | $button = $ticketprinter->getValidButtonWithType($string); |
49 | $ticketprinter->buttons[] = $ticketprinter->getButtonData($string, $button); |
50 | } |
51 | return $ticketprinter; |
52 | } |
53 | |
54 | public function getScopeList() |
55 | { |
56 | $scopeList = new Collection\ScopeList(); |
57 | if ($this->toProperty()->buttons->isAvailable()) { |
58 | foreach ($this->buttons as $button) { |
59 | if (in_array($button['type'], ['scope', 'request'])) { |
60 | $scopeList->addEntity(new Scope($button['scope'])); |
61 | } |
62 | } |
63 | } |
64 | return $scopeList; |
65 | } |
66 | |
67 | public function getClusterList() |
68 | { |
69 | $clusterList = new Collection\ClusterList(); |
70 | if ($this->toProperty()->buttons->isAvailable()) { |
71 | foreach ($this->buttons as $button) { |
72 | if ('cluster' == $button['type']) { |
73 | $clusterList->addEntity(new Cluster($button['cluster'])); |
74 | } |
75 | } |
76 | } |
77 | return $clusterList; |
78 | } |
79 | |
80 | protected function getValidButtonWithType($string) |
81 | { |
82 | $type = $this->getButtonType($string); |
83 | $value = $this->getButtonValue($string, $type); |
84 | if (! Property::__keyExists($type, $this->allowedButtonTypes) || ! $value) { |
85 | throw new Exception\TicketprinterUnvalidButton(); |
86 | } |
87 | return array( |
88 | 'type' => $this->allowedButtonTypes[$type] |
89 | ); |
90 | } |
91 | |
92 | protected function getButtonData($string, $button) |
93 | { |
94 | $value = $this->getButtonValue($string, $this->getButtonType($string)); |
95 | if ('link' == $button['type']) { |
96 | $button = $this->getExternalLinkData($value, $button); |
97 | } else { |
98 | $button['url'] = '/' . $button['type'] . '/' . $value . '/'; |
99 | $button[$button['type']]['id'] = $value; |
100 | } |
101 | |
102 | if ('request' == $button['type']) { |
103 | $button['scope'] = [ |
104 | 'id' => explode('-', $value)[0] |
105 | ]; |
106 | } |
107 | |
108 | return $button; |
109 | } |
110 | |
111 | protected function getButtonValue($string, $type) |
112 | { |
113 | $value = (in_array($type, ['l', 'r'])) ? |
114 | Validator::value(substr($string, 1))->isString() : |
115 | Validator::value(substr($string, 1))->isNumber(); |
116 | return $value->getValue(); |
117 | } |
118 | |
119 | protected function getButtonType($string) |
120 | { |
121 | return substr($string, 0, 1); |
122 | } |
123 | |
124 | protected function getExternalLinkData($value, $button) |
125 | { |
126 | if (preg_match("/\[([^\]]*)\]/", $value, $matches)) { |
127 | $data = explode('|', $matches[1]); |
128 | $button['url'] = (isset($data[0])) ? $data[0] : ''; |
129 | $button['name'] = (isset($data[1])) ? $data[1] : "Information"; |
130 | } |
131 | return $button; |
132 | } |
133 | } |