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(callcenter) AS freeAppointments__callcenter,
41                    SUM(intern) AS freeAppointments__intern,
42                    SUM(publicall) AS allAppointments__public,
43                    SUM(callcenterall) AS allAppointments__callcenter,
44                    SUM(internall) AS allAppointments__intern,
45                    "sum" AS freeAppointments__type,
46                    "free" AS allAppointments__type,
47                    "bookable" AS status
48        FROM
49        (
50
51        SELECT
52          year,
53          month,
54          day,
55          time,
56          slotsRequired,
57          COUNT(slotID) ancestorCount,
58          MIN(IF(public > confirmed, public - confirmed, 0)) AS public,
59          MIN(IF(callcenter > confirmed, callcenter - confirmed, 0)) AS callcenter,
60          MIN(CAST(intern AS SIGNED) - confirmed) AS intern,
61          MIN(public) AS publicall,
62          MIN(callcenter) AS callcenterall,
63          MIN(intern) AS internall
64        FROM
65        (
66
67            SELECT
68                IFNULL(COUNT(p.slotID), 0) confirmed,
69                IF(a.erlaubemehrfachslots, c.slotsRequired, :forceRequiredSlots) slotsRequired,
70                s.slotID,
71                s.year,
72                s.month,
73                s.day,
74                s.time,
75                s.public,
76                s.callcenter,
77                s.intern
78            FROM
79                calendarscope c
80                INNER JOIN slot s
81                    ON c.scopeID = s.scopeID AND c.year = s.year AND c.month = s.month AND s.status = "free"
82                LEFT JOIN oeffnungszeit a ON s.availabilityID = a.OeffnungszeitID
83                LEFT JOIN slot_hiera h ON h.ancestorID = s.slotID
84                    AND h.ancestorLevel <= IF(a.erlaubemehrfachslots, c.slotsRequired, :forceRequiredSlots)
85                LEFT JOIN slot_process p ON h.slotID = p.slotID
86            GROUP BY s.slotID, h.slotID
87
88        ) AS slotaggregate 
89        GROUP BY slotID
90        HAVING ancestorCount >= slotsRequired
91
92        ) AS dayaggregate
93        GROUP BY year, month, day
94        ORDER BY year, month, day
95';
96}