ILIAS  trunk Revision v11.0_alpha-1831-g8615d53dadb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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.

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

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.
+ 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 57 of file class.ReservationDBRepository.php.

References ILIAS\BookingManager\Reservations\ReservationDBRepository\$db, $id, $ilDB, and $message.

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

◆ delete()

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

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

References ILIAS\BookingManager\Reservations\ReservationDBRepository\$db, $id, and $ilDB.

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

◆ getCachedContextObjBookingInfo()

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

Get context object properties info.

Exceptions

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

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

◆ getForId()

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

Get reservation data for id.

Returns
string[]

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

References ILIAS\BookingManager\Reservations\ReservationDBRepository\$db, and $ilDB.

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

◆ 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 172 of file class.ReservationDBRepository.php.

References ILIAS\BookingManager\Reservations\ReservationDBRepository\$db, $ilDB, $res, $user_id, ilObjUser\_lookupName(), null, and ilBookingReservation\STATUS_CANCELLED.

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

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

◆ getNewGroupId()

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

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

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

◆ 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[]$ids booking object ids

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

References ILIAS\BookingManager\Reservations\ReservationDBRepository\$db, $ilDB, $res, and ilBookingReservation\STATUS_CANCELLED.

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

◆ getReservationIdsByBookingObjectId()

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

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

References ILIAS\Repository\int().

335  : array
336  {
337  $set = $this->db->queryF(
338  "SELECT booking_reservation_id FROM booking_reservation " .
339  " WHERE object_id = %s ",
340  ["integer"],
341  [$booking_object_id]
342  );
343  $ret = [];
344  while ($row = $this->db->fetchAssoc($set)) {
345  $ret[] = (int) $row['booking_reservation_id'];
346  }
347 
348  return $ret;
349  }
+ 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 307 of file class.ReservationDBRepository.php.

References ILIAS\BookingManager\Reservations\ReservationDBRepository\getListByDate(), null, ilArrayUtil\sortArray(), ilArrayUtil\stableSortArray(), and ilBookingReservation\STATUS_CANCELLED.

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

309  : void {
310  $filter = ["context_obj_ids" => ($context_obj_ids)];
311  $filter['past'] = true;
312  $filter['status'] = -\ilBookingReservation::STATUS_CANCELLED;
313  $list = $this->getListByDate(true, null, $filter);
314  $list = \ilArrayUtil::sortArray($list, "slot", "asc", true);
315  $list = \ilArrayUtil::stableSortArray($list, "date", "asc", true);
316  $list = \ilArrayUtil::stableSortArray($list, "object_id", "asc", true);
317  $this->preloaded_by_context_list = \ilArrayUtil::stableSortArray($list, "pool_id", "asc", true);
318  }
getListByDate(bool $a_has_schedule, ?array $a_object_ids=null, ?array $filter=null, ?array $a_pool_ids=null)
List all reservations by date.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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...
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()

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 89 of file class.ReservationDBRepository.php.

References ILIAS\BookingManager\Reservations\ReservationDBRepository\$db, $ilDB, and $message.

100  : int {
101  $ilDB = $this->db;
102  return $ilDB->manipulate('UPDATE booking_reservation' .
103  ' SET object_id = ' . $ilDB->quote($object_id, 'text') .
104  ', user_id = ' . $ilDB->quote($user_id, 'integer') .
105  ', assigner_id = ' . $ilDB->quote($assigner_id, 'integer') .
106  ', date_from = ' . $ilDB->quote($from, 'integer') .
107  ', date_to = ' . $ilDB->quote($to, 'integer') .
108  ', status = ' . $ilDB->quote($status, 'integer') .
109  ', group_id = ' . $ilDB->quote($group_id, 'integer') .
110  ', context_obj_id = ' . $ilDB->quote($context_obj_id, 'integer') .
111  ', message = ' . $ilDB->quote($message, 'text') .
112  ' WHERE booking_reservation_id = ' . $ilDB->quote($id, 'integer'));
113  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$message
Definition: xapiexit.php:31

Field Documentation

◆ $db

◆ $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: