29 protected int $id = 0;
33 protected int $to = 0;
45 $this->db = $DIC->database();
46 $this->
id = (
int) $a_id;
49 $this->repo =
$f->getRepo();
61 $this->object_id = $a_object_id;
71 $this->user_id = $a_user_id;
84 $this->assigner_id = $a_assigner_id;
95 public function setFrom(
int $a_from): void
97 $this->from = $a_from;
108 public function setTo(
int $a_to): void
123 if ($a_status === null) {
126 if (self::isValidStatus((
int) $a_status)) {
127 $this->status = (
int) $a_status;
141 return in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED));
146 $this->group_id = $a_group_id;
159 $this->context_obj_id = $a_val;
170 protected function read(): void
173 $row = $this->repo->getForId($this->
id);
177 $this->
setFrom($row[
'date_from']);
178 $this->
setTo($row[
'date_to']);
191 $this->
id = $this->repo->create(
201 return ($this->
id > 0);
224 public function delete():
void 226 $this->repo->delete($this->
id);
237 bool $a_return_single =
true,
238 bool $a_return_counter =
false 243 $repo =
$f->getRepo();
245 $blocked = $counter = array();
247 if ($row[
'cnt'] >= $nr_map[$row[
'object_id']]) {
248 $blocked[] = $row[
'object_id'];
249 } elseif ($a_return_counter) {
250 $counter[$row[
'object_id']] = $nr_map[$row[
'object_id']] - (
int) $row[
'cnt'];
255 foreach ($a_ids as $obj_id) {
257 if ($bobj->getScheduleId()) {
260 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
263 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
267 if (($av_from && $a_from < $av_from) ||
268 ($av_to && $a_to > $av_to)) {
269 $blocked[] = $obj_id;
270 unset($counter[$obj_id]);
275 $available = array_diff($a_ids, $blocked);
276 if (count($available)) {
277 if ($a_return_counter) {
278 foreach ($a_ids as $id) {
279 if (!isset($counter[$id])) {
280 $counter[
$id] = $nr_map[
$id];
285 if ($a_return_single) {
286 return array_shift($available);
303 $a_to = strtotime(
"+1year", $a_from);
306 if ($a_from > $a_to) {
312 $repo =
$f->getRepo();
314 $booked_in_period = (
int) (
$res[$a_obj_id][
"cnt"] ?? 0);
317 $per_slot = $per_slot[$a_obj_id];
320 $schedule_slots = array();
322 $map = array_flip(array(
"su",
"mo",
"tu",
"we",
"th",
"fr",
"sa"));
323 foreach ($definition as $day => $day_slots) {
324 $schedule_slots[$map[$day]] = $day_slots;
335 $available_in_period = 0;
337 while ($a_from < $a_to &&
340 $day_slots = $schedule_slots[date(
"w", $a_from)] ??
false;
342 foreach ($day_slots as $slot) {
344 $slot = explode(
"-", $slot);
345 $slot_from = strtotime(date(
"Y-m-d", $a_from) .
" " . $slot[0]);
346 $slot_to = strtotime(date(
"Y-m-d", $a_from) .
" " . $slot[1]);
348 if ($slot_from >= $av_from &&
349 ($slot_to <= $av_to || is_null($av_to)) &&
351 $available_in_period += $per_slot;
356 $a_from += (60 * 60 * 24);
358 return $available_in_period - $booked_in_period > 0;
367 $ilDB = $DIC->database();
371 $query =
"SELECT count(user_id) total" .
372 " FROM booking_reservation" .
373 " WHERE " .
$ilDB->in(
'object_id', $booking_pool_objects,
false,
'integer') .
374 " AND user_id = " . $a_user_id .
375 " AND (status IS NULL OR status <> " . self::STATUS_CANCELLED .
')';
379 return (
int) $row[
'total'];
389 $ilDB = $DIC->database();
394 $query =
'SELECT DISTINCT bm.user_id user_id' .
395 ' FROM booking_member bm' .
396 ' WHERE bm.booking_pool_id = ' .
$ilDB->quote($pool_id,
'integer') .
397 ' AND bm.user_id NOT IN (' .
399 ' FROM booking_reservation' .
400 ' WHERE object_id = ' .
$ilDB->quote($a_object_id,
'integer') .
401 ' AND (status IS NULL OR status <> ' . self::STATUS_CANCELLED .
'))';
405 while ($row =
$ilDB->fetchAssoc($set)) {
406 $res[] = (
int) $row[
'user_id'];
414 $available = self::getNumAvailablesNoSchedule($a_obj_id);
415 return (
bool) $available;
420 return self::getNumAvailablesNoSchedule($a_obj_id);
427 $ilDB = $DIC->database();
430 $all = $all[$a_obj_id];
432 $set =
$ilDB->query(
'SELECT COUNT(*) cnt' .
433 ' FROM booking_reservation r' .
434 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)' .
435 ' WHERE (status IS NULL OR status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
')' .
436 ' AND r.object_id = ' .
$ilDB->quote($a_obj_id,
'integer'));
437 $cnt =
$ilDB->fetchAssoc($set);
438 $cnt = (
int) $cnt[
'cnt'];
451 $ilDB = $DIC->database();
453 $now =
$ilDB->quote(time(),
'integer');
456 $set =
$ilDB->query(
'SELECT user_id, status, date_from, date_to' .
457 ' FROM booking_reservation' .
458 ' WHERE ((date_from <= ' . $now .
' AND date_to >= ' . $now .
')' .
459 ' OR date_from > ' . $now .
')' .
460 ' AND (status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
461 ' OR STATUS IS NULL) AND object_id = ' .
$ilDB->quote($a_object_id,
'integer') .
462 ' ORDER BY date_from');
463 return $ilDB->fetchAssoc($set);
475 $ilDB = $DIC->database();
477 $set =
$ilDB->query(
'SELECT booking_reservation_id FROM booking_reservation' .
478 ' WHERE user_id = ' .
$ilDB->quote($a_user_id,
'integer') .
479 ' AND object_id = ' .
$ilDB->quote($a_object_id,
'integer') .
480 ' AND (status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
481 ' OR STATUS IS NULL)');
483 while ($row =
$ilDB->fetchAssoc($set)) {
484 $res[] = (
int) $row[
'booking_reservation_id'];
501 $ilDB = $DIC->database();
503 $sql =
'SELECT r.*,o.title' .
504 ' FROM booking_reservation r' .
505 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
507 $count_sql =
'SELECT COUNT(*) AS counter' .
508 ' FROM booking_reservation r' .
509 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
511 $where = array(
$ilDB->in(
'r.object_id', $a_object_ids,
'',
'integer'));
512 if (isset($filter[
'status'])) {
513 if ($filter[
'status'] > 0) {
514 $where[] =
'status = ' .
$ilDB->quote($filter[
'status'],
'integer');
516 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
517 ' OR status IS NULL)';
520 if (isset($filter[
'from'])) {
521 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
523 if (isset($filter[
'to'])) {
524 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
527 $sql .=
' WHERE ' . implode(
' AND ', $where);
528 $count_sql .=
' WHERE ' . implode(
' AND ', $where);
531 $set =
$ilDB->query($count_sql);
532 $row =
$ilDB->fetchAssoc($set);
533 $counter = $row[
'counter'];
535 $sql .=
' ORDER BY date_from DESC, booking_reservation_id DESC';
537 $ilDB->setLimit($a_limit, $a_offset);
538 $set =
$ilDB->query($sql);
540 while ($row =
$ilDB->fetchAssoc($set)) {
544 return array(
'data' =>
$res,
'counter' => $counter);
559 $ilDB = $DIC->database();
563 $sql =
"SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login" .
564 " FROM usr_data ud " .
565 " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)" .
567 " AND " .
$ilDB->in(
"r.object_id", $a_object_ids,
"",
"integer") .
568 " ORDER BY ud.lastname,ud.firstname";
569 $set =
$ilDB->query($sql);
570 while ($row =
$ilDB->fetchAssoc($set)) {
571 $res[$row[
"usr_id"]] = $row[
"lastname"] .
", " . $row[
"firstname"] .
572 " (" . $row[
"login"] .
")";
591 $ilDB = $DIC->database();
593 if (self::isValidStatus($a_status)) {
594 return $ilDB->manipulate(
'UPDATE booking_reservation' .
595 ' SET status = ' .
$ilDB->quote($a_status,
'integer') .
596 ' WHERE ' .
$ilDB->in(
'booking_reservation_id', $a_ids,
'',
'integer'));
606 $set =
$ilDB->query(
"SELECT ce.cal_id FROM cal_entries ce" .
607 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id" .
608 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id" .
609 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id" .
610 " WHERE cc.obj_id = " .
$ilDB->quote($this->getUserId(),
'integer') .
611 " AND br.user_id = " .
$ilDB->quote($this->getUserId(),
'integer') .
613 " AND ce.context_id = " .
$ilDB->quote($this->
getId(),
'integer'));
614 $row =
$ilDB->fetchAssoc($set);
615 return (
int) ($row[
"cal_id"] ?? 0);
630 $ilDB = $DIC->database();
634 $sql =
"SELECT booking_reservation_id" .
635 " FROM booking_reservation" .
636 " WHERE object_id = " .
$ilDB->quote($a_obj_id,
"integer") .
637 " AND user_id = " .
$ilDB->quote($a_user_id,
"integer") .
638 " AND date_from = " .
$ilDB->quote($a_from,
"integer") .
639 " AND date_to = " .
$ilDB->quote($a_to,
"integer") .
640 " AND (status IS NULL" .
641 " OR status <> " .
$ilDB->quote(self::STATUS_CANCELLED,
"integer") .
")";
642 $set =
$ilDB->query($sql);
643 while ($row =
$ilDB->fetchAssoc($set)) {
644 $res[] = (
int) $row[
"booking_reservation_id"];
static getCurrentOrUpcomingReservation(int $a_object_id)
Get details about object reservation.
setFrom(int $a_from)
Set booking from date.
setTo(int $a_to)
Set booking to date.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNumAvailablesNoSchedule(int $a_obj_id)
static changeStatus(array $a_ids, int $a_status)
Batch update reservation status.
static getUserFilter(array $a_object_ids)
Get all users who have reservations for object(s)
static getObjectReservationForUser(int $a_object_id, int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(int $a_id=null)
static getAvailableObject(array $a_ids, int $a_from, int $a_to, bool $a_return_single=true, bool $a_return_counter=false)
Check if any of given objects are bookable.
getNumberOfReservations(array $ids, int $from, int $to, bool $only_not_over_yet=false)
Get number of uncancelled reservations in time frame.
getStatus()
Get booking status.
static getList(array $a_object_ids, int $a_limit=10, int $a_offset=0, array $filter=[])
List all reservations.
setAssignerId(int $a_assigner_id)
Set assigner user id.
static getObjectsForPool(int $a_pool_id)
Get all booking pool object ids from an specific booking pool.
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items for a set of object ids.
ilBookingReservationDBRepository $repo
setUserId(int $a_user_id)
setObjectId(int $a_object_id)
setContextObjId(int $a_val)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getMembersWithoutReservation(int $a_object_id)
static getCancelDetails(int $a_obj_id, int $a_user_id, int $a_from, int $a_to)
Get reservation ids from aggregated id for cancellation.
setGroupId(int $a_group_id)
setStatus(?int $a_status)
Set booking status.
static isBookingPoolLimitReachedByUser(int $a_user_id, int $a_pool_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static numAvailableFromObjectNoSchedule(int $a_obj_id)
static isObjectAvailableNoSchedule(int $a_obj_id)
static lookupPoolId(int $object_id)
static isObjectAvailableInPeriod(int $a_obj_id, ilBookingSchedule $a_schedule, ?int $a_from, ?int $a_to)
static isValidStatus(int $a_status)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...