Lines n/a 0 / 0
Functions and Methods n/a 0 / 0
Classes and Traits n/a 0 / 0
Name Lines Functions and Methods CRAP Classes and Traits
OverviewCalendar n/a 0 / 0 n/a 0 / 0 0 n/a 0 / 0
1<?php
2
3namespace BO\Zmsbackend\Calendar\Repository;
4
5class OverviewCalendar extends \BO\Zmsbackend\Query\Base
6{
7    const string TABLE = 'overview_calendar';
8
9    const string INSERT_ONE = "
10        INSERT INTO overview_calendar
11            (scope_id, process_id, status, starts_at, ends_at)
12        VALUES
13            (:scope_id, :process_id, :status, :starts_at, :ends_at)
14    ";
15
16    const string CANCEL_BY_PROCESS = "
17        UPDATE overview_calendar
18           SET status     = 'cancelled',
19               updated_at = CURRENT_TIMESTAMP
20         WHERE process_id = :process_id
21           AND status    <> 'cancelled'
22";
23
24    // Keep the stored scope when the submitted id is not a standort row.
25    const string UPDATE_BY_PROCESS = "
26        UPDATE overview_calendar
27           SET scope_id   = IFNULL(
28                   (SELECT StandortID FROM standort WHERE StandortID = :scope_id),
29                   scope_id
30               ),
31               starts_at  = :starts_at,
32               ends_at    = :ends_at,
33               updated_at = CURRENT_TIMESTAMP
34         WHERE process_id = :process_id
35           AND status     = 'confirmed'
36    ";
37
38    const string SELECT_MAX_UPDATED = "
39        SELECT MAX(updated_at) AS max_updated
40          FROM overview_calendar
41         WHERE scope_id IN (%s)
42           AND ends_at   > :from
43           AND starts_at < :until
44    ";
45
46    const string SELECT_MAX_UPDATED_GLOBAL = "
47        SELECT MAX(updated_at) AS max_updated
48          FROM overview_calendar
49         WHERE scope_id IN (%s)
50    ";
51
52    const string SELECT_RANGE = "
53        SELECT b.id, b.scope_id, b.process_id, b.status,
54               b.starts_at, b.ends_at, b.updated_at,
55               p.displayNumber AS display_number,
56               s.Bezeichnung   AS scope_name,
57               s.standortkuerzel AS scope_short
58          FROM overview_calendar b
59          JOIN standort s ON b.scope_id = s.StandortID
60          LEFT JOIN buerger p ON b.process_id = p.BuergerID
61         WHERE b.scope_id IN (%s)
62           AND b.ends_at   > :from
63           AND b.starts_at < :until
64           AND b.status = 'confirmed'
65         ORDER BY b.scope_id, b.starts_at, b.ends_at, b.id
66    ";
67
68    const string SELECT_RANGE_UPDATED = "
69        SELECT b.id, b.scope_id, b.process_id, b.status,
70               b.starts_at, b.ends_at, b.updated_at,
71               p.displayNumber AS display_number,
72               s.Bezeichnung   AS scope_name,
73               s.standortkuerzel AS scope_short
74          FROM overview_calendar b
75          JOIN standort s ON b.scope_id = s.StandortID
76          LEFT JOIN buerger p ON b.process_id = p.BuergerID
77         WHERE b.scope_id IN (%s)
78           AND b.ends_at   > :from
79           AND b.starts_at < :until
80           AND b.updated_at > :updatedAfter
81           AND b.status IN ('confirmed','cancelled')
82         ORDER BY b.scope_id, b.starts_at, b.ends_at, b.id
83    ";
84
85    const string SELECT_CHANGED_PIDS_SINCE = "
86        SELECT DISTINCT process_id
87          FROM overview_calendar
88         WHERE scope_id IN (%s)
89           AND updated_at > :updatedAfter
90    ";
91
92    const string DELETE_ALL_BEFORE_END = "
93        DELETE FROM overview_calendar
94         WHERE ends_at < :threshold
95    ";
96}