ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ILIAS\BookingManager\Reservations\ReservationDBRepository Class Reference

Repo class for reservations Acts on tables booking_reservation (rw), booking_reservation_group (rw) and booking_object (r) More...

+ Collaboration diagram for ILIAS\BookingManager\Reservations\ReservationDBRepository:

Public Member Functions

 __construct (\ilDBInterface $db, ?array $preload_context_obj_ids=null)
 
 getForId (int $id)
 Get reservation data for id. More...
 
 create (int $user_id, int $assigner_id, int $object_id, int $context_obj_id, int $from, int $to, int $status, int $group_id, string $message="")
 
 update (int $id, int $user_id, int $assigner_id, int $object_id, int $context_obj_id, int $from, int $to, int $status, int $group_id, string $message="")
 
 delete (int $id)
 
 getNewGroupId ()
 
 getNumberOfReservations (array $ids, int $from, int $to, bool $only_not_over_yet=false)
 Get number of uncancelled reservations in time frame. More...
 
 getListByDate (bool $a_has_schedule, ?array $a_object_ids=null, ?array $filter=null, ?array $a_pool_ids=null)
 List all reservations by date. More...
 
 getCachedContextObjBookingInfo (int $context_obj_id)
 Get context object properties info. More...
 
 getReservationIdsByBookingObjectId (int $booking_object_id)
 

Protected Member Functions

 preloadByContextIds (array $context_obj_ids)
 Preload reservation information for context obj ids. More...
 

Protected Attributes

ilDBInterface $db
 
array $preloaded_by_context_list = null
 

Detailed Description

Repo class for reservations Acts on tables booking_reservation (rw), booking_reservation_group (rw) and booking_object (r)

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 26 of file class.ReservationDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\BookingManager\Reservations\ReservationDBRepository::__construct ( \ilDBInterface  $db,
?array  $preload_context_obj_ids = null 
)

Definition at line 31 of file class.ReservationDBRepository.php.

34 {
35 $this->db = $db;
36 if (is_array($preload_context_obj_ids)) {
37 $this->preloadByContextIds($preload_context_obj_ids);
38 }
39 }
preloadByContextIds(array $context_obj_ids)
Preload reservation information for context obj ids.

References ILIAS\BookingManager\Reservations\ReservationDBRepository\$db, and ILIAS\BookingManager\Reservations\ReservationDBRepository\preloadByContextIds().

+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ILIAS\BookingManager\Reservations\ReservationDBRepository::create ( int  $user_id,
int  $assigner_id,
int  $object_id,
int  $context_obj_id,
int  $from,
int  $to,
int  $status,
int  $group_id,
string  $message = "" 
)
Returns
int new reservation id

Definition at line 56 of file class.ReservationDBRepository.php.

66 : int {
68
69 $id = $ilDB->nextId('booking_reservation');
70 $ilDB->manipulate('INSERT INTO booking_reservation' .
71 ' (booking_reservation_id,user_id,assigner_id,object_id,context_obj_id,date_from,date_to,status,group_id,message)' .
72 ' VALUES (' . $ilDB->quote($id, 'integer') .
73 ',' . $ilDB->quote($user_id, 'integer') .
74 ',' . $ilDB->quote($assigner_id, 'integer') .
75 ',' . $ilDB->quote($object_id, 'integer') .
76 ',' . $ilDB->quote($context_obj_id, 'integer') .
77 ',' . $ilDB->quote($from, 'integer') .
78 ',' . $ilDB->quote($to, 'integer') .
79 ',' . $ilDB->quote($status, 'integer') .
80 ',' . $ilDB->quote($group_id, 'integer') .
81 ',' . $ilDB->quote($message, 'text') . ')');
82 return $id;
83 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ delete()

ILIAS\BookingManager\Reservations\ReservationDBRepository::delete ( int  $id)

Definition at line 114 of file class.ReservationDBRepository.php.

114 : void
115 {
117
118 if ($id) {
119 $ilDB->manipulate('DELETE FROM booking_reservation' .
120 ' WHERE booking_reservation_id = ' . $ilDB->quote($id, 'integer'));
121 }
122 }

References $id, and $ilDB.

◆ getCachedContextObjBookingInfo()

ILIAS\BookingManager\Reservations\ReservationDBRepository::getCachedContextObjBookingInfo ( int  $context_obj_id)

Get context object properties info.

Exceptions

ilBookingReservationException

Definition at line 323 of file class.ReservationDBRepository.php.

325 : array {
326 if (!is_array($this->preloaded_by_context_list)) {
327 throw new \ilBookingReservationException("Repo not initilialized.");
328 }
329 return array_filter($this->preloaded_by_context_list, static function ($row) use ($context_obj_id) {
330 return ($row["context_obj_id"] == $context_obj_id);
331 });
332 }

◆ getForId()

ILIAS\BookingManager\Reservations\ReservationDBRepository::getForId ( int  $id)

Get reservation data for id.

Returns
string[]

Definition at line 45 of file class.ReservationDBRepository.php.

45 : array
46 {
47 $il_db_statement = $this->db->query(
48 "SELECT * FROM booking_reservation WHERE booking_reservation_id = {$this->db->quote($id, \ilDBConstants::T_INTEGER)}"
49 );
50 return $this->db->fetchAssoc($il_db_statement) ?? [];
51 }

◆ getListByDate()

ILIAS\BookingManager\Reservations\ReservationDBRepository::getListByDate ( bool  $a_has_schedule,
?array  $a_object_ids = null,
?array  $filter = null,
?array  $a_pool_ids = null 
)

List all reservations by date.

Definition at line 171 of file class.ReservationDBRepository.php.

176 : array {
178
179 $res = array();
180
181 $sql = 'SELECT r.*, o.title, o.pool_id, o.post_text, o.post_file' .
182 ' FROM booking_reservation r' .
183 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
184
185 $where = [];
186 if ($a_pool_ids !== null) {
187 $where = array($ilDB->in('pool_id', $a_pool_ids, '', 'integer'));
188 }
189
190 if ($a_object_ids !== null) {
191 $where = array($ilDB->in('object_id', $a_object_ids, '', 'integer'));
192 }
193
194 if (isset($filter['context_obj_ids']) && count($filter['context_obj_ids']) > 0) {
195 $where = array($ilDB->in('context_obj_id', $filter['context_obj_ids'], '', 'integer'));
196 }
197
198 if ($filter['status'] ?? false) {
199 if ($filter['status'] > 0) {
200 $where[] = 'status = ' . $ilDB->quote($filter['status'], 'integer');
201 } else {
202 $where[] = '(status != ' . $ilDB->quote(-$filter['status'], 'integer') .
203 ' OR status IS NULL)';
204 }
205 }
206 if (isset($filter['title']) && is_string($filter['title'])) {
207 $where[] = '(' . $ilDB->like('title', 'text', '%' . $filter['title'] . '%') .
208 ' OR ' . $ilDB->like('description', 'text', '%' . $filter['title'] . '%') . ')';
209 }
210 if ($a_has_schedule) {
211 if (isset($filter['from']) && (int) $filter['from'] > 0) {
212 $where[] = 'date_from >= ' . $ilDB->quote($filter['from'], 'integer');
213 }
214 if (isset($filter['to']) && (int) $filter['to'] > 0) {
215 $where[] = 'date_to <= ' . $ilDB->quote($filter['to'], 'integer');
216 }
217 if (!isset($filter['past']) || !$filter['past']) {
218 $where[] = 'date_to > ' . $ilDB->quote(time(), 'integer');
219 }
220 }
221 if (isset($filter['user_id']) && is_numeric($filter['user_id'])) { // #16584
222 $where[] = 'user_id = ' . $ilDB->quote($filter['user_id'], 'integer');
223 }
224 if (count($where) > 0) {
225 $sql .= ' WHERE ' . implode(' AND ', $where);
226 }
227
228 if ($a_has_schedule) {
229 $sql .= ' ORDER BY date_from DESC';
230 } else {
231 // #16155 - could be cancelled and re-booked
232 $sql .= ' ORDER BY status';
233 }
234 $set = $ilDB->query($sql);
235 while ($row = $ilDB->fetchAssoc($set)) {
236 $obj_id = $row["object_id"];
237 $user_id = $row["user_id"];
238
239 if ($a_has_schedule) {
240 $slot = $row["date_from"] . "_" . $row["date_to"];
241 $idx = $obj_id . "_" . $user_id . "_" . $slot;
242 } else {
243 $idx = $obj_id . "_" . $user_id;
244 }
245 $idx .= "_" . $row["context_obj_id"];
246
247 if ($a_has_schedule && ($filter["slot"] ?? false)) {
248 $slot_idx = date("w", $row["date_from"]) . "_" . date("H:i", $row["date_from"]) .
249 "-" . date("H:i", $row["date_to"] + 1);
250 if ($filter["slot"] != $slot_idx) {
251 continue;
252 }
253 }
254
255 if (!isset($res[$idx])) {
257
258 $res[$idx] = array(
259 "object_id" => $obj_id
260 ,"title" => $row["title"]
261 ,"post_text" => $row["post_text"]
262 ,"post_file" => $row["post_file"]
263 ,"pool_id" => $row["pool_id"]
264 ,"context_obj_id" => (int) $row["context_obj_id"]
265 ,"user_id" => $user_id
266 ,"message" => (string) $row["message"]
267 ,"counter" => 1
268 ,"user_name" => $uname["lastname"] . ", " . $uname["firstname"] // #17862
269 ,"login" => $uname["login"]
270 );
271
272 if ($a_has_schedule) {
273 $res[$idx]["booking_reservation_id"] = $idx;
274 $res[$idx]["date"] = date("Y-m-d", $row["date_from"]);
275 $res[$idx]["slot"] = date("H:i", $row["date_from"]) . " - " .
276 date("H:i", $row["date_to"] + 1);
277 $res[$idx]["week"] = date("W", $row["date_from"]);
278 $res[$idx]["weekday"] = date("w", $row["date_from"]);
279 $res[$idx]["can_be_cancelled"] = ($row["status"] != \ilBookingReservation::STATUS_CANCELLED &&
280 $row["date_from"] > time());
281 $res[$idx]["_sortdate"] = $row["date_from"];
282
283 // this currently means: has any cancelled reservations (it is not grouped by this info)
284 $res[$idx]["status"] = $row["status"];
285 } else {
286 $res[$idx]["booking_reservation_id"] = $row["booking_reservation_id"];
287 $res[$idx]["status"] = $row["status"];
288 $res[$idx]["can_be_cancelled"] = ($row["status"] != \ilBookingReservation::STATUS_CANCELLED);
289 }
290 } else {
291 $res[$idx]["counter"]++;
292 }
293 }
294
295 return $res;
296 }
static _lookupName(int $a_user_id)
$res
Definition: ltiservices.php:69

◆ getNewGroupId()

ILIAS\BookingManager\Reservations\ReservationDBRepository::getNewGroupId ( )
Returns
int group id

Definition at line 127 of file class.ReservationDBRepository.php.

127 : int
128 {
129 return $this->db->nextId('booking_reservation_group');
130 }

◆ getNumberOfReservations()

ILIAS\BookingManager\Reservations\ReservationDBRepository::getNumberOfReservations ( array  $ids,
int  $from,
int  $to,
bool  $only_not_over_yet = false 
)

Get number of uncancelled reservations in time frame.

Parameters
int[]$idsbooking object ids

Definition at line 137 of file class.ReservationDBRepository.php.

142 : array {
144
145 $from = $ilDB->quote($from, 'integer');
146 $to = $ilDB->quote($to, 'integer');
147
148 $date = $only_not_over_yet
149 ? ' AND date_to > ' . $ilDB->quote(time(), "integer")
150 : "";
151
152 $set = $ilDB->query('SELECT count(*) cnt, object_id' .
153 ' FROM booking_reservation' .
154 ' WHERE ' . $ilDB->in('object_id', $ids, '', 'integer') . $date .
155 ' AND (status IS NULL OR status <> ' . $ilDB->quote(
157 'integer'
158 ) . ')' .
159 ' AND date_from <= ' . $to . ' AND date_to >= ' . $from .
160 ' GROUP BY object_id');
161 $res = [];
162 while ($row = $ilDB->fetchAssoc($set)) {
163 $res[$row["object_id"]] = $row;
164 }
165 return $res;
166 }

References $res.

◆ getReservationIdsByBookingObjectId()

ILIAS\BookingManager\Reservations\ReservationDBRepository::getReservationIdsByBookingObjectId ( int  $booking_object_id)

Definition at line 334 of file class.ReservationDBRepository.php.

334 : array
335 {
336 $set = $this->db->queryF(
337 "SELECT booking_reservation_id FROM booking_reservation " .
338 " WHERE object_id = %s ",
339 ["integer"],
340 [$booking_object_id]
341 );
342 $ret = [];
343 while ($row = $this->db->fetchAssoc($set)) {
344 $ret[] = (int) $row['booking_reservation_id'];
345 }
346
347 return $ret;
348 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ preloadByContextIds()

ILIAS\BookingManager\Reservations\ReservationDBRepository::preloadByContextIds ( array  $context_obj_ids)
protected

Preload reservation information for context obj ids.

Parameters
int[]$context_obj_ids

Definition at line 306 of file class.ReservationDBRepository.php.

308 : void {
309 $filter = ["context_obj_ids" => ($context_obj_ids)];
310 $filter['past'] = true;
311 $filter['status'] = -\ilBookingReservation::STATUS_CANCELLED;
312 $list = $this->getListByDate(true, null, $filter);
313 $list = \ilArrayUtil::sortArray($list, "slot", "asc", true);
314 $list = \ilArrayUtil::stableSortArray($list, "date", "asc", true);
315 $list = \ilArrayUtil::stableSortArray($list, "object_id", "asc", true);
316 $this->preloaded_by_context_list = \ilArrayUtil::stableSortArray($list, "pool_id", "asc", true);
317 }
getListByDate(bool $a_has_schedule, ?array $a_object_ids=null, ?array $filter=null, ?array $a_pool_ids=null)
List all reservations by date.
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static stableSortArray(array $array, string $a_array_sortby, string $a_array_sortorder="asc", bool $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...

Referenced by ILIAS\BookingManager\Reservations\ReservationDBRepository\__construct().

+ Here is the caller graph for this function:

◆ update()

ILIAS\BookingManager\Reservations\ReservationDBRepository::update ( int  $id,
int  $user_id,
int  $assigner_id,
int  $object_id,
int  $context_obj_id,
int  $from,
int  $to,
int  $status,
int  $group_id,
string  $message = "" 
)
Returns
int number of affected records

Definition at line 88 of file class.ReservationDBRepository.php.

99 : int {
101 return $ilDB->manipulate('UPDATE booking_reservation' .
102 ' SET object_id = ' . $ilDB->quote($object_id, 'text') .
103 ', user_id = ' . $ilDB->quote($user_id, 'integer') .
104 ', assigner_id = ' . $ilDB->quote($assigner_id, 'integer') .
105 ', date_from = ' . $ilDB->quote($from, 'integer') .
106 ', date_to = ' . $ilDB->quote($to, 'integer') .
107 ', status = ' . $ilDB->quote($status, 'integer') .
108 ', group_id = ' . $ilDB->quote($group_id, 'integer') .
109 ', context_obj_id = ' . $ilDB->quote($context_obj_id, 'integer') .
110 ', message = ' . $ilDB->quote($message, 'text') .
111 ' WHERE booking_reservation_id = ' . $ilDB->quote($id, 'integer'));
112 }

Field Documentation

◆ $db

ilDBInterface ILIAS\BookingManager\Reservations\ReservationDBRepository::$db
protected

◆ $preloaded_by_context_list

array ILIAS\BookingManager\Reservations\ReservationDBRepository::$preloaded_by_context_list = null
protected

Definition at line 29 of file class.ReservationDBRepository.php.


The documentation for this class was generated from the following file: