ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilBookingReservationDBRepository Class Reference

Repo class for reservations. More...

+ Collaboration diagram for ilBookingReservationDBRepository:

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

 $db
 
 $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
killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Do not call this constructor directly, use ilBookingReservationDBRepositoryFactory instead

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

References $db, and preloadByContextIds().

32  {
33  if (is_array($preload_context_obj_ids)) {
34  $this->preloadByContextIds($preload_context_obj_ids);
35  }
36  $this->db = $db;
37  }
preloadByContextIds($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,
  $context_obj_id,
int  $from,
int  $to,
  $status,
  $group_id 
)

Insert.

Parameters
int$user_id
int$assigner_id
int$object_id
int$context_obj_id
int$from
int$to
int$status
int$group_id
Returns
int

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

References $db, and $ilDB.

77  {
78  $ilDB = $this->db;
79 
80  $id = $ilDB->nextId('booking_reservation');
81  $ilDB->manipulate('INSERT INTO booking_reservation' .
82  ' (booking_reservation_id,user_id,assigner_id,object_id,context_obj_id,date_from,date_to,status,group_id)' .
83  ' VALUES (' . $ilDB->quote($id, 'integer') .
84  ',' . $ilDB->quote($user_id, 'integer') .
85  ',' . $ilDB->quote($assigner_id, 'integer') .
86  ',' . $ilDB->quote($object_id, 'integer') .
87  ',' . $ilDB->quote($context_obj_id, 'integer') .
88  ',' . $ilDB->quote($from, 'integer') .
89  ',' . $ilDB->quote($to, 'integer') .
90  ',' . $ilDB->quote($status, 'integer') .
91  ',' . $ilDB->quote($group_id, 'integer') . ')');
92  return $id;
93  }
global $ilDB

◆ delete()

ilBookingReservationDBRepository::delete ( int  $id)

Delete.

Parameters
int$id

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

References $db, and $ilDB.

139  {
140  $ilDB = $this->db;
141 
142  if ($id) {
143  $ilDB->manipulate('DELETE FROM booking_reservation' .
144  ' WHERE booking_reservation_id = ' . $ilDB->quote($id, 'integer'));
145  }
146  }
global $ilDB

◆ getCachedContextObjBookingInfo()

ilBookingReservationDBRepository::getCachedContextObjBookingInfo (   $context_obj_id)

Get context object properties info.

Parameters
$context_obj_id
Returns
array|null
Exceptions
ilBookingReservationException

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

363  {
364  if (!is_array($this->preloaded_by_context_list)) {
365  throw new ilBookingReservationException("Repo not initilialized.");
366  }
367  return array_filter($this->preloaded_by_context_list, function ($row) use ($context_obj_id) {
368  return ($row["context_obj_id"] == $context_obj_id);
369  });
370  }

◆ getForId()

ilBookingReservationDBRepository::getForId ( int  $id)

Get reservation data for id.

Parameters
int
Returns
array

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

References $db, and $ilDB.

46  {
47  $ilDB = $this->db;
48  $set = $ilDB->query('SELECT *' .
49  ' FROM booking_reservation' .
50  ' WHERE booking_reservation_id = ' . $ilDB->quote($id, 'integer'));
51  $row = $ilDB->fetchAssoc($set);
52  return $row;
53  }
global $ilDB

◆ getListByDate()

ilBookingReservationDBRepository::getListByDate (   $a_has_schedule,
array  $a_object_ids = null,
array  $filter = null,
array  $a_pool_ids = null 
)

List all reservations by date.

Parameters
bool$a_has_schedulehas schedule
array$a_object_idsobject ids
array$filterfilter
array$a_pool_idspool ids
Returns
array

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

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

208  {
209  $ilDB = $this->db;
210 
211  $res = array();
212 
213  $sql = 'SELECT r.*, o.title, o.pool_id' .
214  ' FROM booking_reservation r' .
215  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
216 
217  if ($a_pool_ids !== null) {
218  $where = array($ilDB->in('pool_id', $a_pool_ids, '', 'integer'));
219  }
220 
221  if ($a_object_ids !== null) {
222  $where = array($ilDB->in('object_id', $a_object_ids, '', 'integer'));
223  }
224 
225  if (is_array($filter['context_obj_ids']) && count($filter['context_obj_ids']) > 0) {
226  $where = array($ilDB->in('context_obj_id', $filter['context_obj_ids'], '', 'integer'));
227  }
228 
229  if ($filter['status']) {
230  if ($filter['status'] > 0) {
231  $where[] = 'status = ' . $ilDB->quote($filter['status'], 'integer');
232  } else {
233  $where[] = '(status != ' . $ilDB->quote(-$filter['status'], 'integer') .
234  ' OR status IS NULL)';
235  }
236  }
237  if ($filter['title']) {
238  $where[] = '(' . $ilDB->like('title', 'text', '%' . $filter['title'] . '%') .
239  ' OR ' . $ilDB->like('description', 'text', '%' . $filter['title'] . '%') . ')';
240  }
241  if ($a_has_schedule) {
242  if ($filter['from']) {
243  $where[] = 'date_from >= ' . $ilDB->quote($filter['from'], 'integer');
244  }
245  if ($filter['to']) {
246  $where[] = 'date_to <= ' . $ilDB->quote($filter['to'], 'integer');
247  }
248  if (!$filter['past']) {
249  $where[] = 'date_to > ' . $ilDB->quote(time(), 'integer');
250  }
251  }
252  if ($filter['user_id']) { // #16584
253  $where[] = 'user_id = ' . $ilDB->quote($filter['user_id'], 'integer');
254  }
255  /*
256  if($a_group_id)
257  {
258  $where[] = 'group_id = '.$ilDB->quote(substr($a_group_id, 1), 'integer');
259  }
260  */
261  if (sizeof($where)) {
262  $sql .= ' WHERE ' . implode(' AND ', $where);
263  }
264 
265  if ($a_has_schedule) {
266  $sql .= ' ORDER BY date_from DESC';
267  } else {
268  // #16155 - could be cancelled and re-booked
269  $sql .= ' ORDER BY status';
270  }
271 
272  $set = $ilDB->query($sql);
273  while ($row = $ilDB->fetchAssoc($set)) {
274  $obj_id = $row["object_id"];
275  $user_id = $row["user_id"];
276 
277  if ($a_has_schedule) {
278  $slot = $row["date_from"] . "_" . $row["date_to"];
279  $idx = $obj_id . "_" . $user_id . "_" . $slot;
280  } else {
281  $idx = $obj_id . "_" . $user_id;
282  }
283  $idx .= "_" . $row["context_obj_id"];
284 
285  if ($a_has_schedule && $filter["slot"]) {
286  $slot_idx = date("w", $row["date_from"]) . "_" . date("H:i", $row["date_from"]) .
287  "-" . date("H:i", $row["date_to"] + 1);
288  if ($filter["slot"] != $slot_idx) {
289  continue;
290  }
291  }
292 
293  if (!isset($res[$idx])) {
294  $uname = ilObjUser::_lookupName($user_id);
295 
296  $res[$idx] = array(
297  "object_id" => $obj_id
298  ,"title" => $row["title"]
299  ,"pool_id" => $row["pool_id"]
300  ,"context_obj_id" => (int) $row["context_obj_id"]
301  ,"user_id" => $user_id
302  ,"counter" => 1
303  ,"user_name" => $uname["lastname"] . ", " . $uname["firstname"] // #17862
304  );
305 
306  if ($a_has_schedule) {
307  $res[$idx]["booking_reservation_id"] = $idx;
308  $res[$idx]["date"] = date("Y-m-d", $row["date_from"]);
309  $res[$idx]["slot"] = date("H:i", $row["date_from"]) . " - " .
310  date("H:i", $row["date_to"] + 1);
311  $res[$idx]["week"] = date("W", $row["date_from"]);
312  $res[$idx]["weekday"] = date("w", $row["date_from"]);
313  $res[$idx]["can_be_cancelled"] = ($row["status"] != ilBookingReservation::STATUS_CANCELLED &&
314  $row["date_from"] > time());
315  $res[$idx]["_sortdate"] = $row["date_from"];
316 
317  // this currently means: has any cancelled reservations (it is not grouped by this info)
318  $res[$idx]["status"] = $row["status"];
319  } else {
320  $res[$idx]["booking_reservation_id"] = $row["booking_reservation_id"];
321  $res[$idx]["status"] = $row["status"];
322  $res[$idx]["can_be_cancelled"] = ($row["status"] != ilBookingReservation::STATUS_CANCELLED);
323  }
324  } else {
325  $res[$idx]["counter"]++;
326  }
327  }
328 
329  return $res;
330  }
static _lookupName($a_user_id)
lookup user name
foreach($_POST as $key=> $value) $res
global $ilDB
+ Here is the call graph for this function:

◆ getNewGroupId()

ilBookingReservationDBRepository::getNewGroupId ( )

Get next group id.

Returns
int

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

References $db, and $ilDB.

153  {
154  $ilDB = $this->db;
155 
156  return $ilDB->nextId('booking_reservation_group');
157  }
global $ilDB

◆ getNumberOfReservations()

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

Get number of uncancelled reservations in time frame.

Parameters
int[]$ids
int$from
int$to
Returns
array

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

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

169  {
170  $ilDB = $this->db;
171 
172  $from = $ilDB->quote($from, 'integer');
173  $to = $ilDB->quote($to, 'integer');
174 
175  $date = $only_not_over_yet
176  ? ' AND date_to > ' . $ilDB->quote(time(), "integer")
177  : "";
178 
179  $set = $ilDB->query('SELECT count(*) cnt, object_id' .
180  ' FROM booking_reservation' .
181  ' WHERE ' . $ilDB->in('object_id', $ids, '', 'integer') . $date .
182  ' AND (status IS NULL OR status <> ' . $ilDB->quote(
184  'integer'
185  ) . ')' .
186  ' AND date_from <= ' . $to . ' AND date_to >= ' . $from .
187  ' GROUP BY object_id');
188  $res = [];
189  while ($row = $ilDB->fetchAssoc($set)) {
190  $res[$row["object_id"]] = $row;
191  }
192  return $res;
193  }
foreach($_POST as $key=> $value) $res
global $ilDB

◆ preloadByContextIds()

ilBookingReservationDBRepository::preloadByContextIds (   $context_obj_ids)
protected

Preload reservation information for context obj ids.

Parameters
int[]$context_obj_ids

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

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

Referenced by __construct().

342  {
343  $filter = ["context_obj_ids" => ($context_obj_ids)];
344  $filter['past'] = true;
345  $filter['status'] = -ilBookingReservation::STATUS_CANCELLED;
347  $repo = $f->getRepo();
348  $list = $repo->getListByDate(true, null, $filter);
349  $list = ilUtil::sortArray($list, "slot", "asc", true);
350  $list = ilUtil::stableSortArray($list, "date", "asc", true);
351  $list = ilUtil::stableSortArray($list, "object_id", "asc", true);
352  $this->preloaded_by_context_list = ilUtil::stableSortArray($list, "pool_id", "asc", true);
353  }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static stableSortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...
+ 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,
  $context_obj_id,
int  $from,
int  $to,
  $status,
  $group_id 
)

Update.

Parameters
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

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

References $db, and $ilDB.

119  {
120  $ilDB = $this->db;
121  return $ilDB->manipulate('UPDATE booking_reservation' .
122  ' SET object_id = ' . $ilDB->quote($object_id, 'text') .
123  ', user_id = ' . $ilDB->quote($user_id, 'integer') .
124  ', assigner_id = ' . $ilDB->quote($assigner_id, 'integer') .
125  ', date_from = ' . $ilDB->quote($from, 'integer') .
126  ', date_to = ' . $ilDB->quote($to, 'integer') .
127  ', status = ' . $ilDB->quote($status, 'integer') .
128  ', group_id = ' . $ilDB->quote($group_id, 'integer') .
129  ', context_obj_id = ' . $ilDB->quote($context_obj_id, 'integer') .
130  ' WHERE booking_reservation_id = ' . $ilDB->quote($id, 'integer'));
131  }
global $ilDB

Field Documentation

◆ $db

ilBookingReservationDBRepository::$db
protected

◆ $preloaded_by_context_list

ilBookingReservationDBRepository::$preloaded_by_context_list = null
protected

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


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