Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
31 / 31 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
Slot | |
100.00% |
31 / 31 |
|
100.00% |
8 / 8 |
16 | |
100.00% |
1 / 1 |
getDefaults | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
setTime | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
hasTime | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
getTimeString | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
removeAppointment | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
withAddedSlot | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
__toString | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
__clone | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace BO\Zmsentities; |
4 | |
5 | class Slot extends Schema\Entity |
6 | { |
7 | public static $schema = "slot.json"; |
8 | |
9 | /** |
10 | * the values represent possible free appointments without confirmed |
11 | * appointments |
12 | * |
13 | */ |
14 | const FREE = 'free'; |
15 | |
16 | /** |
17 | * the values represent free appointments for a given day. Confirmed and |
18 | * reserved appointments on processes are substracted. |
19 | */ |
20 | const TIMESLICE = 'timeslice'; |
21 | |
22 | /** |
23 | * like timeslice, but for more than one scope |
24 | */ |
25 | const SUM = 'sum'; |
26 | |
27 | /** |
28 | * like timeslice, but numbers were reduced due to required slots on a |
29 | * given request |
30 | * |
31 | */ |
32 | const REDUCED = 'reduced'; |
33 | |
34 | /** |
35 | * the values represent a unix timestamp to when there are free processes |
36 | * |
37 | */ |
38 | const TIMESTAMP = 'timestamp'; |
39 | |
40 | public function getDefaults() |
41 | { |
42 | return [ |
43 | 'public' => 0, |
44 | 'intern' => 0, |
45 | 'callcenter' => 0, |
46 | 'type' => self::FREE, |
47 | ]; |
48 | } |
49 | |
50 | public function setTime(Helper\DateTime $slotTime) |
51 | { |
52 | $this->time = $slotTime->format('H:i'); |
53 | } |
54 | |
55 | public function hasTime() |
56 | { |
57 | return ($this->toProperty()->time->get()) ? true : false; |
58 | } |
59 | |
60 | public function getTimeString() |
61 | { |
62 | if (null === $this->toProperty()->time->get()) { |
63 | return '0:00'; |
64 | } |
65 | if ($this->toProperty()->time->get() instanceof \DateTimeInterface) { |
66 | return $this['time']->format('H:i'); |
67 | } |
68 | return $this->toProperty()->time->get(); |
69 | } |
70 | |
71 | public function removeAppointment() |
72 | { |
73 | if ($this->intern <= 0) { |
74 | throw new Exception\SlotFull("Could not remove another appointment from $this"); |
75 | } |
76 | $this->intern = $this->intern - 1; |
77 | if ($this->callcenter > 0) { |
78 | $this->callcenter = $this->callcenter - 1; |
79 | } |
80 | if ($this->public > 0) { |
81 | $this->public = $this->public - 1; |
82 | } |
83 | return $this; |
84 | } |
85 | |
86 | public function withAddedSlot(Slot $slot) |
87 | { |
88 | $slot = clone $slot; |
89 | $slot->type = 'sum'; |
90 | $slot->intern = (($slot->intern > 0) ? $slot->intern : 0) + (($this->intern > 0) ? $this->intern : 0); |
91 | $slot->callcenter = $slot->callcenter + $this->callcenter; |
92 | $slot->public = $slot->public + $this->public; |
93 | return $slot; |
94 | } |
95 | |
96 | public function __toString() |
97 | { |
98 | return "slot#{$this->type}@" |
99 | . "{$this->getTimeString()}" |
100 | . " p/c/i={$this->public}/{$this->callcenter}/{$this->intern}"; |
101 | } |
102 | |
103 | /** |
104 | * Keep empty, no sub-instances |
105 | * ATTENTION: Keep highly optimized, time critical function |
106 | */ |
107 | public function __clone() |
108 | { |
109 | } |
110 | } |