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