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 = "public", s.`public`, 0)
29                    ) available,
30                IF(a.erlaubemehrfachslots, c.slotsRequired, :forceRequiredSlots) slotsRequired,
31                s.*,
32                cc.id
33            FROM
34                calendarscope c
35                INNER JOIN slot s
36                    ON c.scopeID = s.scopeID
37                        %s
38                        AND s.status = "free"
39                LEFT JOIN oeffnungszeit a ON s.availabilityID = a.OeffnungszeitID
40                LEFT JOIN slot_hiera h ON h.ancestorID = s.slotID
41                    AND h.ancestorLevel <= IF(a.erlaubemehrfachslots, c.slotsRequired, :forceRequiredSlots)
42                INNER JOIN slot s2 on h.slotID = s2.slotID and s2.status = "free"
43                LEFT JOIN slot_process p ON h.slotID = p.slotID
44                LEFT JOIN closures cc ON (s.scopeID = cc.StandortID AND s.year = cc.year AND s.month = cc.month and s.day = cc.day)
45            GROUP BY s.slotID, h.slotID
46            HAVING cc.id IS NULL
47            ) AS tmp_ancestor
48            GROUP BY slotID
49            HAVING ancestorCount >= slotsRequired
50            ) AS tmp_avail 
51            INNER JOIN slot_sequence sq ON sq.slotsequence <= tmp_avail.free
52    ';
53    const GROUPBY_SELECT_PROCESSLIST_DAY = 'GROUP BY scope__id, appointments__0__date';
54
55    public static function buildDaysCondition($days)
56    {
57        $sql = 'AND (';
58        $sqlPats = [];
59
60        foreach ($days as $day) {
61            $sqlPats[] = '(c.year = ' . $day->format('Y') . '
62                        AND c.month = ' . $day->format('m') . '
63                        AND s.day = ' . $day->format('d') . '
64                        AND c.year = s.year
65                        AND c.month = s.month)';
66        }
67
68        return $sql . implode(' OR ', $sqlPats) . ')';
69    }
70}