Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ProcessStatusFree | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| buildDaysCondition | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb\Query; |
| 4 | |
| 5 | /** |
| 6 | * |
| 7 | */ |
| 8 | class ProcessStatusFree extends Base |
| 9 | { |
| 10 | /** |
| 11 | * see also Day::QUERY_DAYLIST_JOIN |
| 12 | */ |
| 13 | const QUERY_SELECT_PROCESSLIST_DAYS = ' |
| 14 | SELECT |
| 15 | -- tmp_avail.*, |
| 16 | "free" AS status, |
| 17 | CONCAT(year, "-", month, "-", day, " ", time) AS appointments__0__date, |
| 18 | slotsRequired AS appointments__0__slotCount, |
| 19 | scopeID AS scope__id |
| 20 | FROM |
| 21 | (SELECT |
| 22 | COUNT(slotID) as ancestorCount, |
| 23 | IF(MIN(available - confirmed) > 0, MIN(available - confirmed), 0) as free, |
| 24 | tmp_ancestor.* |
| 25 | FROM (SELECT |
| 26 | IFNULL(COUNT(p.slotID), 0) confirmed, |
| 27 | IF(:slotType = "intern", s.intern, |
| 28 | IF(:slotType = "callcenter", s.callcenter, |
| 29 | IF (:slotType = "public", s.`public`, 0 ) |
| 30 | ) |
| 31 | ) available, |
| 32 | IF(a.erlaubemehrfachslots, c.slotsRequired, :forceRequiredSlots) slotsRequired, |
| 33 | s.*, |
| 34 | cc.id |
| 35 | FROM |
| 36 | calendarscope c |
| 37 | INNER JOIN slot s |
| 38 | ON c.scopeID = s.scopeID |
| 39 | %s |
| 40 | AND s.status = "free" |
| 41 | LEFT JOIN oeffnungszeit a ON s.availabilityID = a.OeffnungszeitID |
| 42 | LEFT JOIN slot_hiera h ON h.ancestorID = s.slotID |
| 43 | AND h.ancestorLevel <= IF(a.erlaubemehrfachslots, c.slotsRequired, :forceRequiredSlots) |
| 44 | INNER JOIN slot s2 on h.slotID = s2.slotID and s2.status = "free" |
| 45 | LEFT JOIN slot_process p ON h.slotID = p.slotID |
| 46 | LEFT JOIN closures cc ON (s.scopeID = cc.StandortID AND s.year = cc.year AND s.month = cc.month and s.day = cc.day) |
| 47 | GROUP BY s.slotID, h.slotID |
| 48 | HAVING cc.id IS NULL |
| 49 | ) AS tmp_ancestor |
| 50 | GROUP BY slotID |
| 51 | HAVING ancestorCount >= slotsRequired |
| 52 | ) AS tmp_avail |
| 53 | INNER JOIN slot_sequence sq ON sq.slotsequence <= tmp_avail.free |
| 54 | '; |
| 55 | const GROUPBY_SELECT_PROCESSLIST_DAY = 'GROUP BY scope__id, appointments__0__date'; |
| 56 | |
| 57 | public static function buildDaysCondition($days) |
| 58 | { |
| 59 | $sql = 'AND ('; |
| 60 | $sqlPats = []; |
| 61 | |
| 62 | foreach ($days as $day) { |
| 63 | $sqlPats[] = '(c.year = ' . $day->format('Y') . ' |
| 64 | AND c.month = ' . $day->format('m') . ' |
| 65 | AND s.day = ' . $day->format('d') . ' |
| 66 | AND c.year = s.year |
| 67 | AND c.month = s.month)'; |
| 68 | } |
| 69 | |
| 70 | return $sql . implode(' OR ', $sqlPats) . ')'; |
| 71 | } |
| 72 | } |