Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessStatusFree
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 buildDaysCondition
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace BO\Zmsdb\Query;
4
5/**
6 *
7 */
8class 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            FROM
35                calendarscope c
36                INNER JOIN slot s
37                    ON c.scopeID = s.scopeID
38                        %s
39                        AND s.status = "free"
40                LEFT JOIN oeffnungszeit a ON s.availabilityID = a.OeffnungszeitID
41                LEFT JOIN slot_hiera h ON h.ancestorID = s.slotID
42                    AND h.ancestorLevel <= IF(a.erlaubemehrfachslots, c.slotsRequired, :forceRequiredSlots)
43                INNER JOIN slot s2 on h.slotID = s2.slotID and s2.status = "free"
44                LEFT JOIN slot_process p ON h.slotID = p.slotID
45            GROUP BY s.slotID, h.slotID
46            ) AS tmp_ancestor
47            GROUP BY slotID
48            HAVING ancestorCount >= slotsRequired
49            ) AS tmp_avail 
50            INNER JOIN slot_sequence sq ON sq.slotsequence <= tmp_avail.free
51    ';
52    const GROUPBY_SELECT_PROCESSLIST_DAY = 'GROUP BY scope__id, appointments__0__date';
53
54    public static function buildDaysCondition($days)
55    {
56        $sql = 'AND (';
57        $sqlPats = [];
58
59        foreach ($days as $day) {
60            $sqlPats[] = '(c.year = ' . $day->format('Y') . '
61                        AND c.month = ' . $day->format('m') . '
62                        AND s.day = ' . $day->format('d') . '
63                        AND c.year = s.year
64                        AND c.month = s.month)';
65        }
66
67        return $sql . implode(' OR ', $sqlPats) . ')';
68    }
69}