ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SchedulesDBRepository.php
Go to the documentation of this file.
1<?php
2
20
26{
27 protected \ilDBInterface $db;
28 protected static array $pool_loaded = [];
29 protected static array $pool_schedules = [];
30 protected static array $raw_data = [];
31
32 public function __construct(
34 ) {
35 $this->db = $db;
36 }
37
38 public function loadDataOfPool(int $pool_id): void
39 {
40 $db = $this->db;
41
42 if (isset(self::$pool_loaded[$pool_id]) && self::$pool_loaded[$pool_id]) {
43 return;
44 }
45
46 $set = $db->query(
47 'SELECT s.booking_schedule_id,s.title,' .
48 'MAX(o.schedule_id) AS object_has_schedule' .
49 ' FROM booking_schedule s' .
50 ' LEFT JOIN booking_object o ON (s.booking_schedule_id = o.schedule_id)' .
51 ' WHERE s.pool_id = ' . $db->quote($pool_id, 'integer') .
52 ' GROUP BY s.booking_schedule_id,s.title' .
53 ' ORDER BY s.title'
54 );
55
56 self::$pool_schedules[$pool_id] = [];
57
58 while ($row = $db->fetchAssoc($set)) {
59 if (!$row['object_has_schedule']) {
60 $row['is_used'] = false;
61 } else {
62 $row['is_used'] = true;
63 }
64 self::$raw_data[$row["booking_schedule_id"]] = $row;
65 self::$pool_schedules[$pool_id][] = $row;
66 }
67
68 self::$pool_loaded[$pool_id] = true;
69 }
70
71 protected function getScheduleDataForPool(
72 int $pool_id
73 ): array {
74 $this->loadDataOfPool($pool_id);
75 return self::$pool_schedules[$pool_id] ?? [];
76 }
77
78 public function hasSchedules(
79 int $pool_id
80 ): bool {
81 $this->loadDataOfPool($pool_id);
82 return count(self::$pool_schedules[$pool_id] ?? []) > 0;
83 }
84
85 public function getScheduleList(int $pool_id): array
86 {
87 $list = [];
88 foreach ($this->getScheduleDataForPool($pool_id) as $data) {
89 $list[$data["booking_schedule_id"]] = $data["title"];
90 }
91 return $list;
92 }
93
94 public function getScheduleData(int $pool_id): array
95 {
96 $schedules = [];
97 foreach ($this->getScheduleDataForPool($pool_id) as $data) {
98 $schedules[$data["booking_schedule_id"]] = $data;
99 }
100 return $schedules;
101 }
102
103 public function getPoolIdForSchedule(int $schedule_id): int
104 {
105 $set = $this->db->query("SELECT pool_id " .
106 " FROM booking_schedule" .
107 " WHERE booking_schedule_id = " . $this->db->quote($schedule_id, 'integer'));
108 if ($rec = $this->db->fetchAssoc($set)) {
109 return (int) $rec['pool_id'];
110 }
111 return 0;
112 }
113
114}
Interface ilDBInterface.
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...