Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
Day
n/a
0 / 0
n/a
0 / 0
0
n/a
0 / 0
1<?php
2
3namespace BO\Zmsdb\Query;
4
5/**
6 *
7 * Calculate Slots for available booking times
8 */
9class Day extends Base
10{
11    const QUERY_CREATE_TEMPORARY_SCOPELIST = '
12        CREATE TEMPORARY TABLE calendarscope (
13            scopeID INT,
14            year SMALLINT,
15            month TINYINT,
16            slotsRequired TINYINT,
17            PRIMARY KEY (scopeID, year, month) 
18        );
19    ';
20
21    const QUERY_INSERT_TEMPORARY_SCOPELIST = '
22        INSERT INTO calendarscope SET
23            scopeID = :scopeID,
24            year = :year,
25            month = :month,
26            slotsRequired = :slotsRequired;
27    ';
28
29    const QUERY_DROP_TEMPORARY_SCOPELIST = 'DROP TEMPORARY TABLE IF EXISTS calendarscope;';
30
31    /**
32     * see also ProcessStatusFree::QUERY_SELECT_PROCESSLIST_DAY
33     */
34    const QUERY_DAYLIST_JOIN = '
35        SELECT
36            year,
37            LPAD(month, 2, "0") AS month,
38            LPAD(day, 2, "0") AS day,
39            SUM(public) AS freeAppointments__public,
40            SUM(intern) AS freeAppointments__intern,
41            SUM(publicall) AS allAppointments__public,
42            SUM(internall) AS allAppointments__intern,
43            "sum" AS freeAppointments__type,
44            "free" AS allAppointments__type,
45            "bookable" AS status,
46            IFNULL(GROUP_CONCAT(DISTINCT CASE WHEN public > 0 THEN scopeID END SEPARATOR ","), "") AS scopeIDs
47        FROM
48        (
49            SELECT
50                year,
51                month,
52                day,
53                time,
54                slotsRequired,
55                COUNT(slotID) AS ancestorCount,
56                MIN(IF(public > confirmed, public - confirmed, 0)) AS public,
57                MIN(CAST(intern AS SIGNED) - confirmed) AS intern,
58                MIN(public) AS publicall,
59                MIN(intern) AS internall,
60                scopeID
61            FROM
62            (
63                SELECT
64                    IFNULL(COUNT(p.slotID), 0) AS confirmed,
65                    IF(a.erlaubemehrfachslots, c.slotsRequired, :forceRequiredSlots) AS slotsRequired,
66                    s.slotID,
67                    s.year,
68                    s.month,
69                    s.day,
70                    s.time,
71                    s.public,
72                    s.intern,
73                    cc.id,
74                    s.scopeID
75                FROM
76                    calendarscope c
77                    INNER JOIN slot s
78                        ON c.scopeID = s.scopeID
79                        AND c.year = s.year
80                        AND c.month = s.month
81                        AND s.status = "free"
82                    LEFT JOIN oeffnungszeit a
83                        ON s.availabilityID = a.OeffnungszeitID
84                    LEFT JOIN slot_hiera h
85                        ON h.ancestorID = s.slotID
86                        AND h.ancestorLevel <= IF(a.erlaubemehrfachslots, c.slotsRequired, :forceRequiredSlots)
87                    LEFT JOIN slot_process p
88                        ON h.slotID = p.slotID
89                    LEFT JOIN closures cc
90                        ON s.scopeID = cc.StandortID
91                        AND s.year = cc.year
92                        AND s.month = cc.month
93                        AND s.day = cc.day
94                GROUP BY s.slotID, h.slotID
95                HAVING cc.id IS NULL
96            ) AS slotaggregate
97            GROUP BY slotID, scopeID
98            HAVING ancestorCount >= slotsRequired
99        ) AS dayaggregate
100        GROUP BY year, month, day
101        ORDER BY year, month, day;
102';
103}