Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
78.95% |
15 / 19 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Slot | |
78.95% |
15 / 19 |
|
33.33% |
1 / 3 |
6.34 | |
0.00% |
0 / 1 |
| getEntityMapping | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| reverseEntityMapping | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
4 | |||
| addConditionSlotId | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb\Query; |
| 4 | |
| 5 | class Slot extends Base implements MappingInterface |
| 6 | { |
| 7 | /** |
| 8 | * |
| 9 | * @var String TABLE mysql table reference |
| 10 | */ |
| 11 | const TABLE = 'slot'; |
| 12 | |
| 13 | const QUERY_OPTIMIZE_SLOT = 'OPTIMIZE TABLE slot;'; |
| 14 | const QUERY_OPTIMIZE_SLOT_HIERA = 'OPTIMIZE TABLE slot_hiera;'; |
| 15 | const QUERY_OPTIMIZE_SLOT_PROCESS = 'OPTIMIZE TABLE slot_proces;'; |
| 16 | const QUERY_OPTIMIZE_PROCESS = 'OPTIMIZE TABLE buerger;'; |
| 17 | |
| 18 | const QUERY_LAST_CHANGED = 'SELECT MAX(updateTimestamp) AS dateString FROM slot;'; |
| 19 | |
| 20 | const QUERY_LAST_CHANGED_AVAILABILITY = ' |
| 21 | SELECT MAX(updateTimestamp) AS dateString FROM slot WHERE availabilityID = :availabilityID AND status="free";'; |
| 22 | |
| 23 | const QUERY_LAST_IN_AVAILABILITY = ' |
| 24 | SELECT CONCAT(year, "-", LPAD(month, 2, "0"), "-", LPAD(day, 2, "0")) AS dateString |
| 25 | FROM slot |
| 26 | WHERE availabilityID = :availabilityID AND status="free" |
| 27 | ORDER BY year DESC, month DESC, day DESC |
| 28 | LIMIT 1;'; |
| 29 | |
| 30 | const QUERY_OLDEST_VERSION_IN_AVAILABILITY = ' |
| 31 | SELECT `version` |
| 32 | FROM slot |
| 33 | WHERE availabilityID = :availabilityID AND status="free" |
| 34 | ORDER BY `version` ASC |
| 35 | LIMIT 1;'; |
| 36 | |
| 37 | const QUERY_LAST_CHANGED_SCOPE = ' |
| 38 | SELECT MAX(updateTimestamp) AS dateString FROM slot WHERE scopeID = :scopeID;'; |
| 39 | |
| 40 | const QUERY_INSERT_SLOT_PROCESS = ' |
| 41 | INSERT INTO slot_process |
| 42 | VALUES(?,?,?) |
| 43 | '; |
| 44 | |
| 45 | const QUERY_SELECT_BY_SCOPE_AND_DAY = ' |
| 46 | SELECT |
| 47 | s.* |
| 48 | FROM slot s |
| 49 | WHERE |
| 50 | s.scopeID = :scopeID |
| 51 | AND s.year = :year |
| 52 | AND s.month = :month |
| 53 | AND s.day = :day |
| 54 | '; |
| 55 | |
| 56 | const QUERY_SELECT_MISSING_PROCESS = ' |
| 57 | SELECT |
| 58 | s.slotID, |
| 59 | b.BuergerID, |
| 60 | NOW() updateTimestamp |
| 61 | FROM slot s |
| 62 | INNER JOIN buerger b ON |
| 63 | s.year = YEAR(b.Datum) |
| 64 | AND s.month = MONTH(b.Datum) |
| 65 | AND s.day = DAY(b.Datum) |
| 66 | AND s.scopeID = b.StandortID |
| 67 | AND b.Uhrzeit BETWEEN s.time AND SEC_TO_TIME(TIME_TO_SEC(s.time) + (s.slotTimeInMinutes * 60) - 1) |
| 68 | AND s.status = "free" |
| 69 | LEFT JOIN slot_process sp ON b.BuergerID = sp.processID |
| 70 | WHERE |
| 71 | sp.processID IS NULL |
| 72 | '; |
| 73 | const QUERY_SELECT_MISSING_PROCESS_BY_SCOPE = ' |
| 74 | AND s.scopeID = :scopeID |
| 75 | '; |
| 76 | |
| 77 | |
| 78 | const QUERY_INSERT_SLOT_PROCESS_ID = ' |
| 79 | REPLACE INTO slot_process |
| 80 | SELECT |
| 81 | s.slotID, |
| 82 | b.BuergerID, |
| 83 | NOW() |
| 84 | FROM slot s |
| 85 | INNER JOIN buerger b ON |
| 86 | s.year = YEAR(b.Datum) |
| 87 | AND s.month = MONTH(b.Datum) |
| 88 | AND s.day = DAY(b.Datum) |
| 89 | AND s.scopeID = b.StandortID |
| 90 | AND s.status = "free" |
| 91 | AND b.Uhrzeit BETWEEN s.time AND SEC_TO_TIME(TIME_TO_SEC(s.time) + (s.slotTimeInMinutes * 60) - 1) |
| 92 | WHERE |
| 93 | b.BuergerID = :processId |
| 94 | '; |
| 95 | const QUERY_DELETE_SLOT_PROCESS_CANCELLED = ' |
| 96 | DELETE sp |
| 97 | FROM slot_process sp LEFT JOIN slot s USING (slotID) |
| 98 | WHERE (s.status = "cancelled" OR s.status IS NULL) |
| 99 | '; |
| 100 | const QUERY_DELETE_SLOT_PROCESS_CANCELLED_BY_SCOPE = ' |
| 101 | AND s.scopeID = :scopeID |
| 102 | '; |
| 103 | |
| 104 | |
| 105 | const QUERY_UPDATE_SLOT_MISSING_AVAILABILITY_BY_SCOPE = ' |
| 106 | UPDATE |
| 107 | slot s |
| 108 | LEFT JOIN oeffnungszeit a ON s.availabilityID = a.OeffnungszeitID |
| 109 | SET s.status = "cancelled" |
| 110 | WHERE |
| 111 | ( |
| 112 | a.OeffnungszeitID IS NULL |
| 113 | OR a.Endedatum < :dateString |
| 114 | ) |
| 115 | AND s.scopeID = :scopeID |
| 116 | '; |
| 117 | |
| 118 | const QUERY_UPDATE_SLOT_MISSING_AVAILABILITY = ' |
| 119 | UPDATE |
| 120 | slot s |
| 121 | LEFT JOIN oeffnungszeit a ON s.availabilityID = a.OeffnungszeitID |
| 122 | SET s.status = "cancelled" |
| 123 | WHERE |
| 124 | a.OeffnungszeitID IS NULL |
| 125 | OR a.Endedatum < :dateString |
| 126 | '; |
| 127 | |
| 128 | const QUERY_SELECT_DELETABLE_SLOT_PROCESS = ' |
| 129 | SELECT sp.processID AS processId |
| 130 | FROM slot_process sp |
| 131 | LEFT JOIN buerger b ON sp.processID = b.BuergerID |
| 132 | LEFT JOIN slot s ON sp.slotID = s.slotID |
| 133 | WHERE ( |
| 134 | b.BuergerID IS NULL |
| 135 | OR ( |
| 136 | b.updateTimestamp > sp.updateTimestamp |
| 137 | AND ( |
| 138 | b.Uhrzeit NOT BETWEEN s.time AND SEC_TO_TIME(TIME_TO_SEC(s.time) + (s.slotTimeInMinutes * 60) - 1) |
| 139 | OR s.month != MONTH(b.Datum) |
| 140 | OR s.day != DAY(b.Datum) |
| 141 | OR s.scopeID != b.StandortID |
| 142 | ) |
| 143 | ) |
| 144 | ) |
| 145 | '; |
| 146 | const QUERY_SELECT_DELETABLE_SLOT_PROCESS_BY_SCOPE = ' |
| 147 | AND b.StandortID = :scopeID |
| 148 | '; |
| 149 | |
| 150 | const QUERY_DELETE_SLOT_PROCESS_ID = ' |
| 151 | DELETE sp |
| 152 | FROM slot_process sp |
| 153 | WHERE sp.processID = :processId |
| 154 | '; |
| 155 | |
| 156 | const QUERY_UPDATE_SLOT_STATUS = " |
| 157 | UPDATE slot |
| 158 | LEFT JOIN ( |
| 159 | SELECT s.slotID, |
| 160 | IF(s.status IN ('free', 'full'), IF(IFNULL(COUNT(p.slotID), 0) < intern, 'free', 'full'), s.status) newstatus |
| 161 | FROM slot s |
| 162 | LEFT JOIN slot_process p ON s.slotID = p.slotID |
| 163 | GROUP BY s.slotID |
| 164 | ) calc ON slot.slotID = calc.slotID |
| 165 | SET |
| 166 | slot.status = calc.newstatus |
| 167 | WHERE slot.status != calc.newstatus |
| 168 | "; |
| 169 | |
| 170 | const QUERY_SELECT_SLOT = ' |
| 171 | SELECT slotID FROM slot WHERE |
| 172 | scopeID = :scopeID |
| 173 | AND year = :year |
| 174 | AND month = :month |
| 175 | AND day = :day |
| 176 | AND time = :time |
| 177 | AND availabilityID = :availabilityID |
| 178 | LIMIT 1 |
| 179 | '; |
| 180 | |
| 181 | const QUERY_INSERT_ANCESTOR = ' |
| 182 | INSERT INTO slot_hiera SET slotID = :slotID, ancestorID = :ancestorID, ancestorLevel = :ancestorLevel |
| 183 | '; |
| 184 | |
| 185 | const QUERY_DELETE_ANCESTOR = ' |
| 186 | DELETE FROM slot_hiera WHERE slotID = :slotID |
| 187 | '; |
| 188 | |
| 189 | const QUERY_CANCEL_AVAILABILITY = ' |
| 190 | UPDATE slot SET status = "cancelled" WHERE availabilityID = :availabilityID |
| 191 | '; |
| 192 | |
| 193 | const QUERY_CANCEL_AVAILABILITY_BEFORE_BOOKABLE = ' |
| 194 | UPDATE slot SET status = "cancelled" WHERE availabilityID = :availabilityID |
| 195 | AND CONCAT(year, "-", LPAD(month, 2, "0"), "-", LPAD(day, 2, "0")) < :providedDate |
| 196 | '; |
| 197 | |
| 198 | const QUERY_CANCEL_AVAILABILITY_AFTER_BOOKABLE = ' |
| 199 | UPDATE slot SET status = "cancelled" WHERE availabilityID = :availabilityID |
| 200 | AND CONCAT(year, "-", LPAD(month, 2, "0"), "-", LPAD(day, 2, "0")) > :providedDate |
| 201 | '; |
| 202 | |
| 203 | const QUERY_CANCEL_SLOT_OLD_BY_SCOPE = ' |
| 204 | UPDATE slot SET status = "cancelled" |
| 205 | WHERE scopeID = :scopeID AND ( |
| 206 | (year < :year) |
| 207 | OR (year = :year AND month < :month) |
| 208 | OR (year = :year AND month = :month AND day <= :day AND time < :time) |
| 209 | ) |
| 210 | '; |
| 211 | |
| 212 | const QUERY_CANCEL_SLOT_OLD = ' |
| 213 | UPDATE slot SET status = "cancelled" |
| 214 | WHERE (year < :year) |
| 215 | OR (year = :year AND month < :month) |
| 216 | OR (year = :year AND month = :month AND day <= :day AND time < :time) |
| 217 | '; |
| 218 | |
| 219 | const QUERY_DELETE_SLOT_OLD = ' |
| 220 | DELETE FROM slot |
| 221 | WHERE (year < :year) |
| 222 | OR (year = :year AND month < :month) |
| 223 | OR (year = :year AND month = :month AND day < :day) |
| 224 | '; |
| 225 | |
| 226 | const QUERY_DELETE_SLOT_HIERA = ' |
| 227 | DELETE sh |
| 228 | FROM slot_hiera sh LEFT JOIN slot s USING(slotID) |
| 229 | WHERE s.slotID IS NULL |
| 230 | '; |
| 231 | |
| 232 | |
| 233 | public function getEntityMapping() |
| 234 | { |
| 235 | return [ |
| 236 | ]; |
| 237 | } |
| 238 | |
| 239 | public function reverseEntityMapping( |
| 240 | \BO\Zmsentities\Slot $slot, |
| 241 | \BO\Zmsentities\Availability $availability, |
| 242 | \DateTimeInterface $date |
| 243 | ) { |
| 244 | $data = array(); |
| 245 | $data['scopeID'] = $availability->scope->id; |
| 246 | $data['availabilityID'] = $availability->id; |
| 247 | $data['version'] = $availability->version; |
| 248 | $data['year'] = $date->format('Y'); |
| 249 | $data['month'] = $date->format('m'); |
| 250 | $data['day'] = $date->format('d'); |
| 251 | $data['time'] = $slot->getTimeString(); |
| 252 | $data['public'] = isset($slot['public']) ? $slot['public'] : $availability->workstationCount['public']; |
| 253 | $data['callcenter'] = isset($slot['callcenter']) ? |
| 254 | $slot['callcenter'] : $availability->workstationCount['callcenter']; |
| 255 | $data['intern'] = isset($slot['intern']) ? $slot['intern'] : $availability->workstationCount['intern']; |
| 256 | $data['status'] = $slot->status; |
| 257 | $data['slotTimeInMinutes'] = $availability->slotTimeInMinutes; |
| 258 | return $data; |
| 259 | } |
| 260 | |
| 261 | public function addConditionSlotId($slotID) |
| 262 | { |
| 263 | $this->query->where('slot.slotID', '=', $slotID); |
| 264 | return $this; |
| 265 | } |
| 266 | } |