29 protected int $id = 0;
33 protected int $to = 0;
39 protected \ILIAS\BookingManager\Reservations\ReservationDBRepository
$repo;
46 $this->db = $DIC->database();
47 $this->
id = (
int) $a_id;
49 $this->repo = $DIC->bookingManager()
63 $this->object_id = $a_object_id;
73 $this->user_id = $a_user_id;
96 $this->assigner_id = $a_assigner_id;
109 $this->
from = $a_from;
120 public function setTo(
int $a_to): void
135 if ($a_status ===
null) {
138 if (self::isValidStatus((
int) $a_status)) {
139 $this->status = (
int) $a_status;
153 return in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED));
158 $this->group_id = $a_group_id;
171 $this->context_obj_id = $a_val;
182 protected function read(): void
185 $row = $this->repo->getForId($this->
id);
189 $this->
setFrom($row[
'date_from']);
190 $this->
setTo($row[
'date_to']);
204 $this->
id = $this->repo->create(
215 return ($this->
id > 0);
239 public function delete():
void 241 $this->repo->delete($this->
id);
252 bool $a_return_single =
true,
253 bool $a_return_counter =
false 259 $repo = $DIC->bookingManager()->internal()->repo()->reservation();
261 $blocked = $counter = array();
262 foreach ($repo->getNumberOfReservations($a_ids, $a_from, $a_to) as $row) {
263 if ($row[
'cnt'] >= $nr_map[$row[
'object_id']]) {
264 $blocked[] = $row[
'object_id'];
265 } elseif ($a_return_counter) {
266 $counter[$row[
'object_id']] = $nr_map[$row[
'object_id']] - (
int) $row[
'cnt'];
271 foreach ($a_ids as $obj_id) {
273 if ($bobj->getScheduleId()) {
276 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
279 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
283 if (($av_from && $a_from < $av_from) ||
284 ($av_to && $a_to > $av_to)) {
285 $blocked[] = $obj_id;
286 unset($counter[$obj_id]);
291 $available = array_diff($a_ids, $blocked);
292 if (count($available)) {
293 if ($a_return_counter) {
294 foreach ($a_ids as $id) {
295 if (!isset($counter[$id])) {
296 $counter[
$id] = $nr_map[
$id];
301 if ($a_return_single) {
302 return array_shift($available);
321 $a_to = strtotime(
"+1year", $a_from);
324 if ($a_from > $a_to) {
329 $repo = $DIC->bookingManager()->internal()->repo()->reservation();
330 $res = $repo->getNumberOfReservations([$a_obj_id], $a_from, $a_to,
true);
331 $booked_in_period = (
int) (
$res[$a_obj_id][
"cnt"] ?? 0);
334 $per_slot = $per_slot[$a_obj_id];
337 $schedule_slots = array();
339 $map = array_flip(array(
"su",
"mo",
"tu",
"we",
"th",
"fr",
"sa"));
340 foreach ($definition as $day => $day_slots) {
341 $schedule_slots[$map[$day]] = $day_slots;
352 $available_in_period = 0;
354 while ($a_from < $a_to &&
357 $day_slots = $schedule_slots[date(
"w", $a_from)] ??
false;
359 foreach ($day_slots as $slot) {
361 $slot = explode(
"-", $slot);
362 $slot_from = strtotime(date(
"Y-m-d", $a_from) .
" " . $slot[0]);
363 $slot_to = strtotime(date(
"Y-m-d", $a_from) .
" " . $slot[1]);
365 if ($slot_from >= $av_from &&
366 ($slot_to <= $av_to || is_null($av_to)) &&
368 $available_in_period += $per_slot;
373 $a_from += (60 * 60 * 24);
375 return $available_in_period - $booked_in_period > 0;
384 $ilDB = $DIC->database();
385 $object_manager = $DIC->bookingManager()->internal()->domain()
386 ->objects($a_pool_id);
388 $booking_pool_objects = $object_manager->getObjectIds();
390 $query =
"SELECT count(user_id) total" .
391 " FROM booking_reservation" .
392 " WHERE " .
$ilDB->in(
'object_id', $booking_pool_objects,
false,
'integer') .
393 " AND user_id = " . $a_user_id .
394 " AND (status IS NULL OR status <> " . self::STATUS_CANCELLED .
')';
398 return (
int) $row[
'total'];
408 $ilDB = $DIC->database();
413 $query =
'SELECT DISTINCT bm.user_id user_id' .
414 ' FROM booking_member bm' .
415 ' WHERE bm.booking_pool_id = ' .
$ilDB->quote($pool_id,
'integer') .
416 ' AND bm.user_id NOT IN (' .
418 ' FROM booking_reservation' .
419 ' WHERE object_id = ' .
$ilDB->quote($a_object_id,
'integer') .
420 ' AND (status IS NULL OR status <> ' . self::STATUS_CANCELLED .
'))';
422 $set =
$ilDB->query($query);
424 while ($row =
$ilDB->fetchAssoc($set)) {
425 $res[] = (
int) $row[
'user_id'];
433 $available = self::getNumAvailablesNoSchedule($a_obj_id);
434 return (
bool) $available;
439 return self::getNumAvailablesNoSchedule($a_obj_id);
446 $ilDB = $DIC->database();
449 $all = $all[$a_obj_id];
451 $set =
$ilDB->query(
'SELECT COUNT(*) cnt' .
452 ' FROM booking_reservation r' .
453 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)' .
454 ' WHERE (status IS NULL OR status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
')' .
455 ' AND r.object_id = ' .
$ilDB->quote($a_obj_id,
'integer'));
456 $cnt =
$ilDB->fetchAssoc($set);
457 $cnt = (
int) $cnt[
'cnt'];
470 $ilDB = $DIC->database();
472 $now =
$ilDB->quote(time(),
'integer');
475 $set =
$ilDB->query(
'SELECT user_id, status, date_from, date_to' .
476 ' FROM booking_reservation' .
477 ' WHERE ((date_from <= ' . $now .
' AND date_to >= ' . $now .
')' .
478 ' OR date_from > ' . $now .
')' .
479 ' AND (status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
480 ' OR STATUS IS NULL) AND object_id = ' .
$ilDB->quote($a_object_id,
'integer') .
481 ' ORDER BY date_from');
482 return $ilDB->fetchAssoc($set);
494 $ilDB = $DIC->database();
496 $set =
$ilDB->query(
'SELECT booking_reservation_id FROM booking_reservation' .
497 ' WHERE user_id = ' .
$ilDB->quote($a_user_id,
'integer') .
498 ' AND object_id = ' .
$ilDB->quote($a_object_id,
'integer') .
499 ' AND (status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
500 ' OR STATUS IS NULL)');
502 while ($row =
$ilDB->fetchAssoc($set)) {
503 $res[] = (
int) $row[
'booking_reservation_id'];
520 $ilDB = $DIC->database();
522 $sql =
'SELECT r.*,o.title' .
523 ' FROM booking_reservation r' .
524 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
526 $count_sql =
'SELECT COUNT(*) AS counter' .
527 ' FROM booking_reservation r' .
528 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
530 $where = array(
$ilDB->in(
'r.object_id', $a_object_ids,
'',
'integer'));
531 if (isset($filter[
'status'])) {
532 if ($filter[
'status'] > 0) {
533 $where[] =
'status = ' .
$ilDB->quote($filter[
'status'],
'integer');
535 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
536 ' OR status IS NULL)';
539 if (isset($filter[
'from'])) {
540 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
542 if (isset($filter[
'to'])) {
543 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
546 $sql .=
' WHERE ' . implode(
' AND ', $where);
547 $count_sql .=
' WHERE ' . implode(
' AND ', $where);
550 $set =
$ilDB->query($count_sql);
551 $row =
$ilDB->fetchAssoc($set);
552 $counter = $row[
'counter'];
554 $sql .=
' ORDER BY date_from DESC, booking_reservation_id DESC';
556 $ilDB->setLimit($a_limit, $a_offset);
557 $set =
$ilDB->query($sql);
559 while ($row =
$ilDB->fetchAssoc($set)) {
563 return array(
'data' =>
$res,
'counter' => $counter);
578 $ilDB = $DIC->database();
582 $sql =
"SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login" .
583 " FROM usr_data ud " .
584 " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)" .
586 " AND " .
$ilDB->in(
"r.object_id", $a_object_ids,
"",
"integer") .
587 " ORDER BY ud.lastname,ud.firstname";
588 $set =
$ilDB->query($sql);
589 while ($row =
$ilDB->fetchAssoc($set)) {
590 $res[$row[
"usr_id"]] = $row[
"lastname"] .
", " . $row[
"firstname"] .
591 " (" . $row[
"login"] .
")";
610 $ilDB = $DIC->database();
612 if (self::isValidStatus($a_status)) {
613 return $ilDB->manipulate(
'UPDATE booking_reservation' .
614 ' SET status = ' .
$ilDB->quote($a_status,
'integer') .
615 ' WHERE ' .
$ilDB->in(
'booking_reservation_id', $a_ids,
'',
'integer'));
625 $set =
$ilDB->query(
"SELECT ce.cal_id FROM cal_entries ce" .
626 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id" .
627 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id" .
628 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id" .
629 " WHERE cc.obj_id = " .
$ilDB->quote($this->getUserId(),
'integer') .
630 " AND br.user_id = " .
$ilDB->quote($this->getUserId(),
'integer') .
632 " AND ce.context_id = " .
$ilDB->quote($this->
getId(),
'integer'));
633 $row =
$ilDB->fetchAssoc($set);
634 return (
int) ($row[
"cal_id"] ?? 0);
649 $ilDB = $DIC->database();
653 $sql =
"SELECT booking_reservation_id" .
654 " FROM booking_reservation" .
655 " WHERE object_id = " .
$ilDB->quote($a_obj_id,
"integer") .
656 " AND user_id = " .
$ilDB->quote($a_user_id,
"integer") .
657 " AND date_from = " .
$ilDB->quote($a_from,
"integer") .
658 " AND date_to = " .
$ilDB->quote($a_to,
"integer") .
659 " AND (status IS NULL" .
660 " OR status <> " .
$ilDB->quote(self::STATUS_CANCELLED,
"integer") .
")";
661 $set =
$ilDB->query($sql);
662 while ($row =
$ilDB->fetchAssoc($set)) {
663 $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...
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.
setMessage(string $message)
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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items for a set of object ids.
setUserId(int $a_user_id)
setObjectId(int $a_object_id)
setContextObjId(int $a_val)
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.
__construct(?int $a_id=null)
static isBookingPoolLimitReachedByUser(int $a_user_id, int $a_pool_id)
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)
to(\GdImage $image, ?int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.
static isValidStatus(int $a_status)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS BookingManager Reservations ReservationDBRepository $repo