ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilBookingReservationDBRepository Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilBookingReservationDBRepository:

Public Member Functions

 __construct (ilDBInterface $db, ?array $preload_context_obj_ids=null)
 Do not call this constructor directly, use ilBookingReservationDBRepositoryFactory instead. More...
 
 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)
 
 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)
 
 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

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 24 of file class.ilBookingReservationDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingReservationDBRepository::__construct ( ilDBInterface  $db,
?array  $preload_context_obj_ids = null 
)

Do not call this constructor directly, use ilBookingReservationDBRepositoryFactory instead.

Definition at line 33 of file class.ilBookingReservationDBRepository.php.

References $db, and preloadByContextIds().

36  {
37  if (is_array($preload_context_obj_ids)) {
38  $this->preloadByContextIds($preload_context_obj_ids);
39  }
40  $this->db = $db;
41  }
preloadByContextIds(array $context_obj_ids)
Preload reservation information for context obj ids.
+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilBookingReservationDBRepository::create ( int  $user_id,
int  $assigner_id,
int  $object_id,
int  $context_obj_id,
int  $from,
int  $to,
int  $status,
int  $group_id 
)
Returns
int new reservation id

Definition at line 59 of file class.ilBookingReservationDBRepository.php.

References $db, $id, and $ilDB.

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

◆ delete()

ilBookingReservationDBRepository::delete ( int  $id)

Definition at line 113 of file class.ilBookingReservationDBRepository.php.

References $db, $id, and $ilDB.

113  : void
114  {
115  $ilDB = $this->db;
116 
117  if ($id) {
118  $ilDB->manipulate('DELETE FROM booking_reservation' .
119  ' WHERE booking_reservation_id = ' . $ilDB->quote($id, 'integer'));
120  }
121  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ getCachedContextObjBookingInfo()

ilBookingReservationDBRepository::getCachedContextObjBookingInfo ( int  $context_obj_id)

Get context object properties info.

Exceptions
ilBookingReservationException

Definition at line 321 of file class.ilBookingReservationDBRepository.php.

Referenced by ilBookingInfoListItemPropertiesAdapter\appendProperties().

323  : array {
324  if (!is_array($this->preloaded_by_context_list)) {
325  throw new ilBookingReservationException("Repo not initilialized.");
326  }
327  return array_filter($this->preloaded_by_context_list, static function ($row) use ($context_obj_id) {
328  return ($row["context_obj_id"] == $context_obj_id);
329  });
330  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ getForId()

ilBookingReservationDBRepository::getForId ( int  $id)

Get reservation data for id.

Returns
string[]

Definition at line 47 of file class.ilBookingReservationDBRepository.php.

References $db, and $ilDB.

47  : array
48  {
49  $ilDB = $this->db;
50  $set = $ilDB->query('SELECT *' .
51  ' FROM booking_reservation' .
52  ' WHERE booking_reservation_id = ' . $ilDB->quote($id, 'integer'));
53  return $ilDB->fetchAssoc($set);
54  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ getListByDate()

ilBookingReservationDBRepository::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 170 of file class.ilBookingReservationDBRepository.php.

References $db, $ilDB, $res, ilObjUser\_lookupName(), and ilBookingReservation\STATUS_CANCELLED.

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

◆ getNewGroupId()

ilBookingReservationDBRepository::getNewGroupId ( )
Returns
int group id

Definition at line 126 of file class.ilBookingReservationDBRepository.php.

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

◆ getNumberOfReservations()

ilBookingReservationDBRepository::getNumberOfReservations ( array  $ids,
int  $from,
int  $to,
bool  $only_not_over_yet = false 
)

Get number of uncancelled reservations in time frame.

Parameters
int[]$ids booking object ids

Definition at line 136 of file class.ilBookingReservationDBRepository.php.

References $db, $ilDB, $res, and ilBookingReservation\STATUS_CANCELLED.

Referenced by ilBookingReservation\getAvailableObject(), and ilBookingReservation\isObjectAvailableInPeriod().

141  : array {
142  $ilDB = $this->db;
143 
144  $from = $ilDB->quote($from, 'integer');
145  $to = $ilDB->quote($to, 'integer');
146 
147  $date = $only_not_over_yet
148  ? ' AND date_to > ' . $ilDB->quote(time(), "integer")
149  : "";
150 
151  $set = $ilDB->query('SELECT count(*) cnt, object_id' .
152  ' FROM booking_reservation' .
153  ' WHERE ' . $ilDB->in('object_id', $ids, '', 'integer') . $date .
154  ' AND (status IS NULL OR status <> ' . $ilDB->quote(
156  'integer'
157  ) . ')' .
158  ' AND date_from <= ' . $to . ' AND date_to >= ' . $from .
159  ' GROUP BY object_id');
160  $res = [];
161  while ($row = $ilDB->fetchAssoc($set)) {
162  $res[$row["object_id"]] = $row;
163  }
164  return $res;
165  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getReservationIdsByBookingObjectId()

ilBookingReservationDBRepository::getReservationIdsByBookingObjectId ( int  $booking_object_id)

Definition at line 332 of file class.ilBookingReservationDBRepository.php.

References ILIAS\Repository\int().

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

◆ preloadByContextIds()

ilBookingReservationDBRepository::preloadByContextIds ( array  $context_obj_ids)
protected

Preload reservation information for context obj ids.

Parameters
int[]$context_obj_ids

Definition at line 302 of file class.ilBookingReservationDBRepository.php.

References Vendor\Package\$f, ilArrayUtil\sortArray(), ilArrayUtil\stableSortArray(), and ilBookingReservation\STATUS_CANCELLED.

Referenced by __construct().

304  : void {
305  $filter = ["context_obj_ids" => ($context_obj_ids)];
306  $filter['past'] = true;
307  $filter['status'] = -ilBookingReservation::STATUS_CANCELLED;
309  $repo = $f->getRepo();
310  $list = $repo->getListByDate(true, null, $filter);
311  $list = ilArrayUtil::sortArray($list, "slot", "asc", true);
312  $list = ilArrayUtil::stableSortArray($list, "date", "asc", true);
313  $list = ilArrayUtil::stableSortArray($list, "object_id", "asc", true);
314  $this->preloaded_by_context_list = ilArrayUtil::stableSortArray($list, "pool_id", "asc", true);
315  }
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilBookingReservationDBRepository::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 
)
Returns
int number of affected records

Definition at line 89 of file class.ilBookingReservationDBRepository.php.

References $db, and $ilDB.

99  : int {
100  $ilDB = $this->db;
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  ' WHERE booking_reservation_id = ' . $ilDB->quote($id, 'integer'));
111  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

Field Documentation

◆ $db

ilDBInterface ilBookingReservationDBRepository::$db
protected

◆ $preloaded_by_context_list

array ilBookingReservationDBRepository::$preloaded_by_context_list = null
protected

Definition at line 27 of file class.ilBookingReservationDBRepository.php.


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