ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilBookingReservation Class Reference

a booking reservation More...

+ Collaboration diagram for ilBookingReservation:

Public Member Functions

 __construct ($a_id=null)
 Constructor. More...
 
 getId ()
 Get id. More...
 
 setObjectId ($a_object_id)
 Set object id. More...
 
 getObjectId ()
 Get object id. More...
 
 setUserId ($a_user_id)
 Set booking user id. More...
 
 getUserId ()
 Get booking user id. More...
 
 setAssignerId ($a_assigner_id)
 Set assigner user id. More...
 
 getAssignerId ()
 Get assigner user id. More...
 
 setFrom ($a_from)
 Set booking from date. More...
 
 getFrom ()
 Get booking from date. More...
 
 setTo ($a_to)
 Set booking to date. More...
 
 getTo ()
 Get booking to date. More...
 
 setStatus ($a_status)
 Set booking status. More...
 
 getStatus ()
 Get booking status. More...
 
 setGroupId ($a_group_id)
 Set group id. More...
 
 getGroupId ()
 Get group id. More...
 
 save ()
 Create new entry in db. More...
 
 update ()
 Update entry in db. More...
 
 delete ()
 Delete single entry. More...
 
 getCalendarEntry ()
 

Static Public Member Functions

static isValidStatus ($a_status)
 Check if given status is valid. More...
 
static getNewGroupId ()
 Get next group id. More...
 
static getAvailableObject (array $a_ids, $a_from, $a_to, $a_return_single=true, $a_return_counter=false)
 Check if any of given objects are bookable. More...
 
static isObjectAvailableInPeriod ($a_obj_id, ilBookingSchedule $a_schedule, $a_from, $a_to)
 
static isBookingPoolLimitReachedByUser (int $a_user_id, int $a_pool_id)
 
static getMembersWithoutReservation (int $a_object_id)
 
static isObjectAvailableNoSchedule ($a_obj_id)
 
static numAvailableFromObjectNoSchedule ($a_obj_id)
 
static getNumAvailablesNoSchedule ($a_obj_id)
 
static getCurrentOrUpcomingReservation ($a_object_id)
 Get details about object reservation. More...
 
static getObjectReservationForUser ($a_object_id, $a_user_id, $a_multi=false)
 
static getList ($a_object_ids, $a_limit=10, $a_offset=0, array $filter)
 List all reservations. More...
 
static getListByDate ( $a_has_schedule, array $a_object_ids=null, array $filter=null, array $a_pool_ids=null)
 List all reservations by date. More...
 
static getUserFilter (array $a_object_ids)
 Get all users who have reservations for object(s) More...
 
static changeStatus (array $a_ids, $a_status)
 List all reservations. More...
 
static getCancelDetails ($a_obj_id, $a_user_id, $a_from, $a_to)
 Get reservation ids from aggregated id for cancellation. More...
 

Data Fields

const STATUS_IN_USE = 2
 
const STATUS_CANCELLED = 5
 

Protected Member Functions

 read ()
 Get dataset from db. More...
 

Protected Attributes

 $db
 
 $id
 
 $object_id
 
 $user_id
 
 $from
 
 $to
 
 $status
 
 $group_id
 
 $assigner_id
 

Detailed Description

a booking reservation

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 12 of file class.ilBookingReservation.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingReservation::__construct (   $a_id = null)

Constructor.

if id is given will read dataset from db

Parameters
int$a_id

Definition at line 38 of file class.ilBookingReservation.php.

39 {
40 global $DIC;
41
42 $this->db = $DIC->database();
43 $this->id = (int) $a_id;
44 $this->read();
45 }
global $DIC
Definition: saml.php:7

References $DIC, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ changeStatus()

static ilBookingReservation::changeStatus ( array  $a_ids,
  $a_status 
)
static

List all reservations.

Parameters
array$a_object_ids
int$a_limit
int$a_offset
array$filter
array$a_group_id
Returns
array Batch update reservation status
Parameters
array$a_ids
int$a_status
Returns
bool

Definition at line 1062 of file class.ilBookingReservation.php.

1063 {
1064 global $DIC;
1065
1066 $ilDB = $DIC->database();
1067
1068 if (self::isValidStatus($a_status)) {
1069 return $ilDB->manipulate('UPDATE booking_reservation' .
1070 ' SET status = ' . $ilDB->quote($a_status, 'integer') .
1071 ' WHERE ' . $ilDB->in('booking_reservation_id', $a_ids, '', 'integer'));
1072 }
1073 }
global $ilDB

References $DIC, and $ilDB.

Referenced by ilObjBookingPoolGUI\changeStatusObject().

+ Here is the caller graph for this function:

◆ delete()

ilBookingReservation::delete ( )

Delete single entry.

Returns
bool

Definition at line 285 of file class.ilBookingReservation.php.

286 {
288
289 if ($this->id) {
290 return $ilDB->manipulate('DELETE FROM booking_reservation' .
291 ' WHERE booking_reservation_id = ' . $ilDB->quote($this->id, 'integer'));
292 }
293 }

References $db, and $ilDB.

◆ getAssignerId()

ilBookingReservation::getAssignerId ( )

Get assigner user id.

Returns
int

Definition at line 105 of file class.ilBookingReservation.php.

References $assigner_id.

◆ getAvailableObject()

static ilBookingReservation::getAvailableObject ( array  $a_ids,
  $a_from,
  $a_to,
  $a_return_single = true,
  $a_return_counter = false 
)
static

Check if any of given objects are bookable.

Parameters
array$a_ids
int$a_from
int$a_to
int$a_return_single
Returns
int

Definition at line 316 of file class.ilBookingReservation.php.

317 {
318 global $DIC;
319
320 $ilDB = $DIC->database();
321
323
324 $from = $ilDB->quote($a_from, 'integer');
325 $to = $ilDB->quote($a_to, 'integer');
326
327 $set = $ilDB->query('SELECT count(*) cnt, object_id' .
328 ' FROM booking_reservation' .
329 ' WHERE ' . $ilDB->in('object_id', $a_ids, '', 'integer') .
330 ' AND (status IS NULL OR status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') . ')' .
331 ' AND ((date_from <= ' . $from . ' AND date_to >= ' . $from . ')' .
332 ' OR (date_from <= ' . $to . ' AND date_to >= ' . $to . ')' .
333 ' OR (date_from >= ' . $from . ' AND date_to <= ' . $to . '))' .
334 ' GROUP BY object_id');
335 $blocked = $counter = array();
336 while ($row = $ilDB->fetchAssoc($set)) {
337 if ($row['cnt'] >= $nr_map[$row['object_id']]) {
338 $blocked[] = $row['object_id'];
339 } elseif ($a_return_counter) {
340 $counter[$row['object_id']] = (int) $nr_map[$row['object_id']] - (int) $row['cnt'];
341 }
342 }
343
344 // #17868 - validate against schedule availability
345 foreach ($a_ids as $obj_id) {
346 $bobj = new ilBookingObject($obj_id);
347 if ($bobj->getScheduleId()) {
348 include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
349 $schedule = new ilBookingSchedule($bobj->getScheduleId());
350
351 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
352 ? $schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
353 : null;
354 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
355 ? strtotime($schedule->getAvailabilityTo()->get(IL_CAL_DATE) . " 23:59:59")
356 : null;
357
358 if (($av_from && $a_from < $av_from) ||
359 ($av_to && $a_to > $av_to)) {
360 $blocked[] = $obj_id;
361 unset($counter[$obj_id]);
362 }
363 }
364 }
365
366 $available = array_diff($a_ids, $blocked);
367 if (sizeof($available)) {
368 if ($a_return_counter) {
369 foreach ($a_ids as $id) {
370 if (!isset($counter[$id])) {
371 $counter[$id] = (int) $nr_map[$id];
372 }
373 }
374 return $counter;
375 } elseif ($a_return_single) {
376 return array_shift($available);
377 } else {
378 return $available;
379 }
380 }
381 }
const IL_CAL_DATE
const IL_CAL_UNIX
a bookable ressource
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items.
schedule for booking ressource
$row

References $DIC, $from, $id, $ilDB, $row, $to, ilBookingObject\getNrOfItemsForObjects(), IL_CAL_DATE, and IL_CAL_UNIX.

Referenced by ilObjBookingPoolGUI\buildDatesBySchedule(), ilObjBookingPoolGUI\confirmedBookingNumbersObject(), and ilObjBookingPoolGUI\confirmedBookingObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCalendarEntry()

ilBookingReservation::getCalendarEntry ( )

Definition at line 1075 of file class.ilBookingReservation.php.

1076 {
1077 $ilDB = $this->db;
1078
1079 include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
1080
1081 $set = $ilDB->query("SELECT ce.cal_id FROM cal_entries ce" .
1082 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id" .
1083 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id" .
1084 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id" .
1085 " WHERE cc.obj_id = " . $ilDB->quote($this->getUserId(), 'integer') .
1086 " AND br.user_id = " . $ilDB->quote($this->getUserId(), 'integer') .
1087 " AND cc.type = " . $ilDB->quote(ilCalendarCategory::TYPE_BOOK, 'integer') .
1088 " AND ce.context_id = " . $ilDB->quote($this->getId(), 'integer'));
1089 $row = $ilDB->fetchAssoc($set);
1090 return $row["cal_id"];
1091 }

References $db, $ilDB, $row, and ilCalendarCategory\TYPE_BOOK.

◆ getCancelDetails()

static ilBookingReservation::getCancelDetails (   $a_obj_id,
  $a_user_id,
  $a_from,
  $a_to 
)
static

Get reservation ids from aggregated id for cancellation.

Parameters
int$a_obj_id
int$a_user_id
int$a_from
int$a_to
Returns
array

Definition at line 1102 of file class.ilBookingReservation.php.

1103 {
1104 global $DIC;
1105
1106 $ilDB = $DIC->database();
1107
1108 $res = array();
1109
1110 $sql = "SELECT booking_reservation_id" .
1111 " FROM booking_reservation" .
1112 " WHERE object_id = " . $ilDB->quote($a_obj_id, "integer") .
1113 " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
1114 " AND date_from = " . $ilDB->quote($a_from, "integer") .
1115 " AND date_to = " . $ilDB->quote($a_to, "integer") .
1116 " AND (status IS NULL" .
1117 " OR status <> " . $ilDB->quote(self::STATUS_CANCELLED, "integer") . ")";
1118 $set = $ilDB->query($sql);
1119 while ($row = $ilDB->fetchAssoc($set)) {
1120 $res[] = $row["booking_reservation_id"];
1121 }
1122
1123 return $res;
1124 }
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $res, and $row.

Referenced by ilObjBookingPoolGUI\rsvConfirmCancelObject(), and ilObjBookingPoolGUI\rsvConfirmDeleteObject().

+ Here is the caller graph for this function:

◆ getCurrentOrUpcomingReservation()

static ilBookingReservation::getCurrentOrUpcomingReservation (   $a_object_id)
static

Get details about object reservation.

Parameters
int$a_object_id
Returns
array

Definition at line 548 of file class.ilBookingReservation.php.

549 {
550 global $DIC;
551
552 $ilDB = $DIC->database();
553
554 $now = $ilDB->quote(time(), 'integer');
555
556 $ilDB->setLimit(1);
557 $set = $ilDB->query('SELECT user_id, status, date_from, date_to' .
558 ' FROM booking_reservation' .
559 ' WHERE ((date_from <= ' . $now . ' AND date_to >= ' . $now . ')' .
560 ' OR date_from > ' . $now . ')' .
561 ' AND (status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') .
562 ' OR STATUS IS NULL) AND object_id = ' . $ilDB->quote($a_object_id, 'integer') .
563 ' ORDER BY date_from');
564 $row = $ilDB->fetchAssoc($set);
565 return $row;
566 }

References $DIC, $ilDB, and $row.

◆ getFrom()

ilBookingReservation::getFrom ( )

Get booking from date.

Returns
int

Definition at line 123 of file class.ilBookingReservation.php.

124 {
125 return $this->from;
126 }

References $from.

◆ getGroupId()

ilBookingReservation::getGroupId ( )

Get group id.

Returns
int

Definition at line 195 of file class.ilBookingReservation.php.

References $group_id.

◆ getId()

ilBookingReservation::getId ( )

Get id.

Returns
int

Definition at line 51 of file class.ilBookingReservation.php.

52 {
53 return $this->id;
54 }

References $id.

◆ getList()

static ilBookingReservation::getList (   $a_object_ids,
  $a_limit = 10,
  $a_offset = 0,
array  $filter 
)
static

List all reservations.

Parameters
array$a_object_ids
int$a_limit
int$a_offset
array$a_offset
Returns
array

Definition at line 599 of file class.ilBookingReservation.php.

600 {
601 global $DIC;
602
603 $ilDB = $DIC->database();
604
605 $sql = 'SELECT r.*,o.title' .
606 ' FROM booking_reservation r' .
607 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
608
609 $count_sql = 'SELECT COUNT(*) AS counter' .
610 ' FROM booking_reservation r' .
611 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
612
613 $where = array($ilDB->in('r.object_id', $a_object_ids, '', 'integer'));
614 if ($filter['status']) {
615 if ($filter['status'] > 0) {
616 $where[] = 'status = ' . $ilDB->quote($filter['status'], 'integer');
617 } else {
618 $where[] = '(status != ' . $ilDB->quote(-$filter['status'], 'integer') .
619 ' OR status IS NULL)';
620 }
621 }
622 if ($filter['from']) {
623 $where[] = 'date_from >= ' . $ilDB->quote($filter['from'], 'integer');
624 }
625 if ($filter['to']) {
626 $where[] = 'date_to <= ' . $ilDB->quote($filter['to'], 'integer');
627 }
628 if (sizeof($where)) {
629 $sql .= ' WHERE ' . implode(' AND ', $where);
630 $count_sql .= ' WHERE ' . implode(' AND ', $where);
631 }
632
633 $set = $ilDB->query($count_sql);
634 $row = $ilDB->fetchAssoc($set);
635 $counter = $row['counter'];
636
637 $sql .= ' ORDER BY date_from DESC, booking_reservation_id DESC';
638
639 $ilDB->setLimit($a_limit, $a_offset);
640 $set = $ilDB->query($sql);
641 $res = array();
642 while ($row = $ilDB->fetchAssoc($set)) {
643 $res[] = $row;
644 }
645
646 return array('data' => $res, 'counter' => $counter);
647 }

References $DIC, $ilDB, $res, and $row.

Referenced by ilBookingObjectsTableGUI\getItems().

+ Here is the caller graph for this function:

◆ getListByDate()

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

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 657 of file class.ilBookingReservation.php.

662 {
663 global $DIC;
664
665 $ilDB = $DIC->database();
666
667 $res = array();
668
669 $sql = 'SELECT r.*, o.title, o.pool_id' .
670 ' FROM booking_reservation r' .
671 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
672
673 if ($a_pool_ids !== null) {
674 $where = array($ilDB->in('pool_id', $a_pool_ids, '', 'integer'));
675 }
676
677 if ($a_object_ids !== null) {
678 $where = array($ilDB->in('object_id', $a_object_ids, '', 'integer'));
679 }
680
681 if ($filter['status']) {
682 if ($filter['status'] > 0) {
683 $where[] = 'status = ' . $ilDB->quote($filter['status'], 'integer');
684 } else {
685 $where[] = '(status != ' . $ilDB->quote(-$filter['status'], 'integer') .
686 ' OR status IS NULL)';
687 }
688 }
689 if ($filter['title']) {
690 $where[] = '(' . $ilDB->like('title', 'text', '%' . $filter['title'] . '%') .
691 ' OR ' . $ilDB->like('description', 'text', '%' . $filter['title'] . '%') . ')';
692 }
693 if ($a_has_schedule) {
694 if ($filter['from']) {
695 $where[] = 'date_from >= ' . $ilDB->quote($filter['from'], 'integer');
696 }
697 if ($filter['to']) {
698 $where[] = 'date_to <= ' . $ilDB->quote($filter['to'], 'integer');
699 }
700 if (!$filter['past']) {
701 $where[] = 'date_to > ' . $ilDB->quote(time(), 'integer');
702 }
703 }
704 if ($filter['user_id']) { // #16584
705 $where[] = 'user_id = ' . $ilDB->quote($filter['user_id'], 'integer');
706 }
707 /*
708 if($a_group_id)
709 {
710 $where[] = 'group_id = '.$ilDB->quote(substr($a_group_id, 1), 'integer');
711 }
712 */
713 if (sizeof($where)) {
714 $sql .= ' WHERE ' . implode(' AND ', $where);
715 }
716
717 if ($a_has_schedule) {
718 $sql .= ' ORDER BY date_from DESC';
719 } else {
720 // #16155 - could be cancelled and re-booked
721 $sql .= ' ORDER BY status';
722 }
723
724 $set = $ilDB->query($sql);
725 while ($row = $ilDB->fetchAssoc($set)) {
726 $obj_id = $row["object_id"];
727 $user_id = $row["user_id"];
728
729 if ($a_has_schedule) {
730 $slot = $row["date_from"] . "_" . $row["date_to"];
731 $idx = $obj_id . "_" . $user_id . "_" . $slot;
732 } else {
733 $idx = $obj_id . "_" . $user_id;
734 }
735
736 if ($a_has_schedule && $filter["slot"]) {
737 $slot_idx = date("w", $row["date_from"]) . "_" . date("H:i", $row["date_from"]) .
738 "-" . date("H:i", $row["date_to"] + 1);
739 if ($filter["slot"] != $slot_idx) {
740 continue;
741 }
742 }
743
744 if (!isset($res[$idx])) {
746
747 $res[$idx] = array(
748 "object_id" => $obj_id
749 ,"title" => $row["title"]
750 ,"pool_id" => $row["pool_id"]
751 ,"user_id" => $user_id
752 ,"counter" => 1
753 ,"user_name" => $uname["lastname"] . ", " . $uname["firstname"] // #17862
754 );
755
756 if ($a_has_schedule) {
757 $res[$idx]["booking_reservation_id"] = $idx;
758 $res[$idx]["date"] = date("Y-m-d", $row["date_from"]);
759 $res[$idx]["slot"] = date("H:i", $row["date_from"]) . " - " .
760 date("H:i", $row["date_to"] + 1);
761 $res[$idx]["week"] = date("W", $row["date_from"]);
762 $res[$idx]["weekday"] = date("w", $row["date_from"]);
763 $res[$idx]["can_be_cancelled"] = ($row["status"] != self::STATUS_CANCELLED &&
764 $row["date_from"] > time());
765 $res[$idx]["_sortdate"] = $row["date_from"];
766 } else {
767 $res[$idx]["booking_reservation_id"] = $row["booking_reservation_id"];
768 $res[$idx]["status"] = $row["status"];
769 $res[$idx]["can_be_cancelled"] = ($row["status"] != self::STATUS_CANCELLED);
770 }
771 } else {
772 $res[$idx]["counter"]++;
773 }
774 }
775
776 return $res;
777 }
static _lookupName($a_user_id)
lookup user name

References $DIC, $ilDB, $res, $row, $user_id, ilObjUser\_lookupName(), and STATUS_CANCELLED.

Referenced by ilBookingReservationsTableGUI\getItems(), and ilBookCronNotification\sendNotifications().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMembersWithoutReservation()

static ilBookingReservation::getMembersWithoutReservation ( int  $a_object_id)
static

Definition at line 486 of file class.ilBookingReservation.php.

486 : array
487 {
488 global $DIC;
489 $ilDB = $DIC->database();
490
491 $pool_id = ilBookingObject::lookupPoolId($a_object_id);
492
493 $res = array();
494 $query = 'SELECT DISTINCT bm.user_id user_id' .
495 ' FROM booking_member bm' .
496 ' WHERE bm.booking_pool_id = ' . $ilDB->quote($pool_id, 'integer') .
497 ' AND bm.user_id NOT IN (' .
498 'SELECT user_id' .
499 ' FROM booking_reservation' .
500 ' WHERE object_id = ' . $ilDB->quote($a_object_id, 'integer') .
501 ' AND (status IS NULL OR status <> ' . ilBookingReservation::STATUS_CANCELLED . '))';
502
503 $set = $ilDB->query($query);
504
505 while ($row = $ilDB->fetchAssoc($set)) {
506 $res[] = $row['user_id'];
507 }
508
509 return $res;
510 }
static lookupPoolId($object_id)
Lookup pool id.
$query

References $DIC, $ilDB, $query, $res, $row, ilBookingObject\lookupPoolId(), and STATUS_CANCELLED.

Referenced by ilBookingParticipant\getAssignableParticipants().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNewGroupId()

static ilBookingReservation::getNewGroupId ( )
static

Get next group id.

Returns
int

Definition at line 299 of file class.ilBookingReservation.php.

300 {
301 global $DIC;
302
303 $ilDB = $DIC->database();
304
305 return $ilDB->nextId('booking_reservation_group');
306 }

References $DIC, and $ilDB.

Referenced by ilObjBookingPoolGUI\confirmedBookingObject().

+ Here is the caller graph for this function:

◆ getNumAvailablesNoSchedule()

static ilBookingReservation::getNumAvailablesNoSchedule (   $a_obj_id)
static

Definition at line 523 of file class.ilBookingReservation.php.

524 {
525 global $DIC;
526
527 $ilDB = $DIC->database();
528
529 $all = ilBookingObject::getNrOfItemsForObjects(array($a_obj_id));
530 $all = (int) $all[$a_obj_id];
531
532 $set = $ilDB->query('SELECT COUNT(*) cnt' .
533 ' FROM booking_reservation r' .
534 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)' .
535 ' WHERE (status IS NULL OR status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') . ')' .
536 ' AND r.object_id = ' . $ilDB->quote($a_obj_id, 'integer'));
537 $cnt = $ilDB->fetchAssoc($set);
538 $cnt = (int) $cnt['cnt'];
539
540 return (int) $all - $cnt; // #11864
541 }

References $DIC, $ilDB, and ilBookingObject\getNrOfItemsForObjects().

Referenced by isObjectAvailableNoSchedule(), and numAvailableFromObjectNoSchedule().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObjectId()

ilBookingReservation::getObjectId ( )

Get object id.

Returns
int

Definition at line 69 of file class.ilBookingReservation.php.

References $object_id.

◆ getObjectReservationForUser()

static ilBookingReservation::getObjectReservationForUser (   $a_object_id,
  $a_user_id,
  $a_multi = false 
)
static

Definition at line 568 of file class.ilBookingReservation.php.

569 {
570 global $DIC;
571
572 $ilDB = $DIC->database();
573
574 $set = $ilDB->query('SELECT booking_reservation_id FROM booking_reservation' .
575 ' WHERE user_id = ' . $ilDB->quote($a_user_id, 'integer') .
576 ' AND object_id = ' . $ilDB->quote($a_object_id, 'integer') .
577 ' AND (status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') .
578 ' OR STATUS IS NULL)');
579 if (!$a_multi) {
580 $row = $ilDB->fetchAssoc($set);
581 return $row['booking_reservation_id'];
582 } else {
583 $res = array();
584 while ($row = $ilDB->fetchAssoc($set)) {
585 $res[] = $row['booking_reservation_id'];
586 }
587 return $res;
588 }
589 }

References $DIC, $ilDB, $res, and $row.

Referenced by ilObjBookingPoolGUI\confirmedBookingObject(), ilBookingObjectGUI\deliverPostFile(), ilBookingObjectGUI\displayPostInfo(), ilBookingAssignObjectsTableGUI\getItems(), ilBookingParticipant\isParticipantAssigned(), and ilBookingObjectGUI\rsvCancelUser().

+ Here is the caller graph for this function:

◆ getStatus()

ilBookingReservation::getStatus ( )

Get booking status.

Returns
int

Definition at line 164 of file class.ilBookingReservation.php.

References $status.

◆ getTo()

ilBookingReservation::getTo ( )

Get booking to date.

Returns
int

Definition at line 141 of file class.ilBookingReservation.php.

142 {
143 return $this->to;
144 }

References $to.

◆ getUserFilter()

static ilBookingReservation::getUserFilter ( array  $a_object_ids)
static

Get all users who have reservations for object(s)

Parameters
array$a_object_ids
Returns
array

Definition at line 785 of file class.ilBookingReservation.php.

786 {
787 global $DIC;
788
789 $ilDB = $DIC->database();
790
791 $res = array();
792
793 $sql = "SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login" .
794 " FROM usr_data ud " .
795 " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)" .
796 " WHERE ud.usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") .
797 " AND " . $ilDB->in("r.object_id", $a_object_ids, "", "integer") .
798 " ORDER BY ud.lastname,ud.firstname";
799 $set = $ilDB->query($sql);
800 while ($row = $ilDB->fetchAssoc($set)) {
801 $res[$row["usr_id"]] = $row["lastname"] . ", " . $row["firstname"] .
802 " (" . $row["login"] . ")";
803 }
804
805 return $res;
806 }

References $DIC, $ilDB, $res, and $row.

Referenced by ilBookingReservationsTableGUI\initFilter().

+ Here is the caller graph for this function:

◆ getUserId()

ilBookingReservation::getUserId ( )

Get booking user id.

Returns
int

Definition at line 87 of file class.ilBookingReservation.php.

88 {
89 return $this->user_id;
90 }

References $user_id.

◆ isBookingPoolLimitReachedByUser()

static ilBookingReservation::isBookingPoolLimitReachedByUser ( int  $a_user_id,
int  $a_pool_id 
)
static

Definition at line 468 of file class.ilBookingReservation.php.

468 : int
469 {
470 global $DIC;
471 $ilDB = $DIC->database();
472
473 $booking_pool_objects = ilBookingObject::getObjectsForPool($a_pool_id);
474
475 $query = "SELECT count(user_id) total" .
476 " FROM booking_reservation" .
477 " WHERE " . $ilDB->in('object_id', $booking_pool_objects, false, 'integer') .
478 " AND user_id = " . $a_user_id .
479 " AND (status IS NULL OR status <> " . ilBookingReservation::STATUS_CANCELLED . ')';
480 $res = $ilDB->query($query);
482
483 return (int) $row['total'];
484 }
static getObjectsForPool(int $a_pool_id)
Get all booking pool object ids from an specific booking pool.

References $DIC, $ilDB, $query, $res, $row, ilDBConstants\FETCHMODE_ASSOC, ilBookingObject\getObjectsForPool(), and STATUS_CANCELLED.

Referenced by ilBookingParticipant\getAssignableParticipants().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isObjectAvailableInPeriod()

static ilBookingReservation::isObjectAvailableInPeriod (   $a_obj_id,
ilBookingSchedule  $a_schedule,
  $a_from,
  $a_to 
)
static

Definition at line 383 of file class.ilBookingReservation.php.

384 {
385 global $DIC;
386
387 $ilDB = $DIC->database();
388
389 if (!$a_from) {
390 $a_from = time();
391 }
392 if (!$a_to) {
393 $a_to = strtotime("+1year", $a_from);
394 }
395
396 if ($a_from > $a_to) {
397 return;
398 }
399
400 $from = $ilDB->quote($a_from, 'integer');
401 $to = $ilDB->quote($a_to, 'integer');
402
403 // all bookings in period
404 $now = time();
405 $set = $ilDB->query('SELECT count(*) cnt' .
406 ' FROM booking_reservation' .
407 ' WHERE object_id = ' . $ilDB->quote($a_obj_id, 'integer') .
408 ' AND (status IS NULL OR status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') . ')' .
409 ' AND date_to > ' . $now .
410 ' AND ((date_from <= ' . $from . ' AND date_to >= ' . $from . ')' .
411 ' OR (date_from <= ' . $to . ' AND date_to >= ' . $to . ')' .
412 ' OR (date_from >= ' . $from . ' AND date_to <= ' . $to . '))');
413 $row = $ilDB->fetchAssoc($set);
414 $booked_in_period = $row["cnt"];
415
416 $per_slot = ilBookingObject::getNrOfItemsForObjects(array($a_obj_id));
417 $per_slot = $per_slot[$a_obj_id];
418
419 // max available nr of items per (week)day
420 $schedule_slots = array();
421 $definition = $a_schedule->getDefinition();
422 $map = array_flip(array("su", "mo", "tu", "we", "th", "fr", "sa"));
423 foreach ($definition as $day => $day_slots) {
424 $schedule_slots[$map[$day]] = $day_slots;
425 }
426
427 $av_from = ($a_schedule->getAvailabilityFrom() && !$a_schedule->getAvailabilityFrom()->isNull())
428 ? $a_schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
429 : null;
430 $av_to = ($a_schedule->getAvailabilityTo() && !$a_schedule->getAvailabilityTo()->isNull())
431 ? strtotime($a_schedule->getAvailabilityTo()->get(IL_CAL_DATE) . " 23:59:59")
432 : null;
433
434 // sum up max available items in period per (week)day
435 $available_in_period = 0;
436 $loop = 0;
437 while ($a_from < $a_to &&
438 ++$loop < 1000) {
439 // any slots for current weekday?
440 $day_slots = $schedule_slots[date("w", $a_from)];
441 if ($day_slots) {
442 foreach ($day_slots as $slot) {
443 // convert slot to current datetime
444 $slot = explode("-", $slot);
445 $slot_from = strtotime(date("Y-m-d", $a_from) . " " . $slot[0]);
446 $slot_to = strtotime(date("Y-m-d", $a_from) . " " . $slot[1]);
447
448 // slot has to be in the future and part of schedule availability
449 if ($slot_to > time() &&
450 $slot_from >= $av_from &&
451 $slot_to <= $av_to) {
452 $available_in_period += $per_slot;
453 }
454 }
455 }
456
457 $a_from += (60 * 60 * 24);
458 }
459
460 if ($available_in_period - $booked_in_period > 0) {
461 return true;
462 }
463
464 return false;
465 }
getAvailabilityTo()
Get availability end.
getAvailabilityFrom()
Get availability start.
getDefinition()
Get definition.

References $DIC, $from, $ilDB, $map, $row, $to, ilBookingSchedule\getAvailabilityFrom(), ilBookingSchedule\getAvailabilityTo(), ilBookingSchedule\getDefinition(), ilBookingObject\getNrOfItemsForObjects(), IL_CAL_DATE, and IL_CAL_UNIX.

Referenced by ilBookingObjectsTableGUI\getItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isObjectAvailableNoSchedule()

static ilBookingReservation::isObjectAvailableNoSchedule (   $a_obj_id)
static

Definition at line 512 of file class.ilBookingReservation.php.

513 {
514 $available = self::getNumAvailablesNoSchedule($a_obj_id);
515 return (bool) $available; // #11864
516 }
static getNumAvailablesNoSchedule($a_obj_id)

References getNumAvailablesNoSchedule().

Referenced by ilObjBookingPoolGUI\confirmedBookingObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidStatus()

static ilBookingReservation::isValidStatus (   $a_status)
static

Check if given status is valid.

Parameters
int$a_status
Returns
bool

Definition at line 174 of file class.ilBookingReservation.php.

175 {
176 if (in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED))) {
177 return true;
178 }
179 return false;
180 }

Referenced by setStatus().

+ Here is the caller graph for this function:

◆ numAvailableFromObjectNoSchedule()

static ilBookingReservation::numAvailableFromObjectNoSchedule (   $a_obj_id)
static

Definition at line 517 of file class.ilBookingReservation.php.

518 {
519 $available = self::getNumAvailablesNoSchedule($a_obj_id);
520 return (int) $available;
521 }

References getNumAvailablesNoSchedule().

Referenced by ilBookingAssignParticipantsTableGUI\__construct(), ilObjBookingPoolGUI\bookMultipleParticipantsObject(), and ilBookingAssignObjectsTableGUI\getItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilBookingReservation::read ( )
protected

Get dataset from db.

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

204 {
206
207 if ($this->id) {
208 $set = $ilDB->query('SELECT *' .
209 ' FROM booking_reservation' .
210 ' WHERE booking_reservation_id = ' . $ilDB->quote($this->id, 'integer'));
211 $row = $ilDB->fetchAssoc($set);
212 $this->setUserId($row['user_id']);
213 $this->setAssignerId($row['assigner_id']);
214 $this->setObjectId($row['object_id']);
215 $this->setFrom($row['date_from']);
216 $this->setTo($row['date_to']);
217 $this->setStatus($row['status']);
218 $this->setGroupId($row['group_id']);
219 }
220 }
setTo($a_to)
Set booking to date.
setObjectId($a_object_id)
Set object id.
setAssignerId($a_assigner_id)
Set assigner user id.
setFrom($a_from)
Set booking from date.
setGroupId($a_group_id)
Set group id.
setStatus($a_status)
Set booking status.
setUserId($a_user_id)
Set booking user id.

References $db, $ilDB, $row, setAssignerId(), setFrom(), setGroupId(), setObjectId(), setStatus(), setTo(), and setUserId().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilBookingReservation::save ( )

Create new entry in db.

Returns
bool

Definition at line 226 of file class.ilBookingReservation.php.

227 {
229
230 if ($this->id) {
231 return false;
232 }
233
234 $this->id = $ilDB->nextId('booking_reservation');
235
236 return $ilDB->manipulate('INSERT INTO booking_reservation' .
237 ' (booking_reservation_id,user_id,assigner_id,object_id,date_from,date_to,status,group_id)' .
238 ' VALUES (' . $ilDB->quote($this->id, 'integer') .
239 ',' . $ilDB->quote($this->getUserId(), 'integer') .
240 ',' . $ilDB->quote($this->getAssignerId(), 'integer') .
241 ',' . $ilDB->quote($this->getObjectId(), 'integer') .
242 ',' . $ilDB->quote($this->getFrom(), 'integer') .
243 ',' . $ilDB->quote($this->getTo(), 'integer') .
244 ',' . $ilDB->quote($this->getStatus(), 'integer') .
245 ',' . $ilDB->quote($this->getGroupId(), 'integer') . ')');
246 }

References $db, and $ilDB.

◆ setAssignerId()

ilBookingReservation::setAssignerId (   $a_assigner_id)

Set assigner user id.

Parameters
$a_assigner_id

Definition at line 96 of file class.ilBookingReservation.php.

97 {
98 $this->assigner_id = (int) $a_assigner_id;
99 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setFrom()

ilBookingReservation::setFrom (   $a_from)

Set booking from date.

Parameters
int$a_from

Definition at line 114 of file class.ilBookingReservation.php.

115 {
116 $this->from = (int) $a_from;
117 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setGroupId()

ilBookingReservation::setGroupId (   $a_group_id)

Set group id.

Parameters
int$a_group_id

Definition at line 186 of file class.ilBookingReservation.php.

187 {
188 $this->group_id = $a_group_id;
189 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setObjectId()

ilBookingReservation::setObjectId (   $a_object_id)

Set object id.

Parameters
int$a_object_id

Definition at line 60 of file class.ilBookingReservation.php.

61 {
62 $this->object_id = $a_object_id;
63 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setStatus()

ilBookingReservation::setStatus (   $a_status)

Set booking status.

Parameters
int$a_status

Definition at line 150 of file class.ilBookingReservation.php.

151 {
152 if ($a_status === null) {
153 $this->status = null;
154 }
155 if ($this->isValidStatus((int) $a_status)) {
156 $this->status = (int) $a_status;
157 }
158 }
static isValidStatus($a_status)
Check if given status is valid.

References isValidStatus().

Referenced by read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTo()

ilBookingReservation::setTo (   $a_to)

Set booking to date.

Parameters
int$a_to

Definition at line 132 of file class.ilBookingReservation.php.

133 {
134 $this->to = (int) $a_to;
135 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setUserId()

ilBookingReservation::setUserId (   $a_user_id)

Set booking user id.

Parameters
int$a_user_id

Definition at line 78 of file class.ilBookingReservation.php.

79 {
80 $this->user_id = (int) $a_user_id;
81 }

Referenced by read().

+ Here is the caller graph for this function:

◆ update()

ilBookingReservation::update ( )

Update entry in db.

Returns
bool

Definition at line 252 of file class.ilBookingReservation.php.

253 {
255
256 if (!$this->id) {
257 return false;
258 }
259
260 /* there can only be 1
261 if($this->getStatus() == self::STATUS_IN_USE)
262 {
263 $ilDB->manipulate('UPDATE booking_reservation'.
264 ' SET status = '.$ilDB->quote(NULL, 'integer').
265 ' WHERE object_id = '.$ilDB->quote($this->getObjectId(), 'integer').
266 ' AND status = '.$ilDB->quote(self::STATUS_IN_USE, 'integer'));
267 }
268 */
269
270 return $ilDB->manipulate('UPDATE booking_reservation' .
271 ' SET object_id = ' . $ilDB->quote($this->getObjectId(), 'text') .
272 ', user_id = ' . $ilDB->quote($this->getUserId(), 'integer') .
273 ', assigner_id = ' . $ilDB->quote($this->getAssignerId(), 'integer') .
274 ', date_from = ' . $ilDB->quote($this->getFrom(), 'integer') .
275 ', date_to = ' . $ilDB->quote($this->getTo(), 'integer') .
276 ', status = ' . $ilDB->quote($this->getStatus(), 'integer') .
277 ', group_id = ' . $ilDB->quote($this->getGroupId(), 'integer') .
278 ' WHERE booking_reservation_id = ' . $ilDB->quote($this->id, 'integer'));
279 }

References $db, and $ilDB.

Field Documentation

◆ $assigner_id

ilBookingReservation::$assigner_id
protected

Definition at line 26 of file class.ilBookingReservation.php.

Referenced by getAssignerId().

◆ $db

ilBookingReservation::$db
protected

Definition at line 17 of file class.ilBookingReservation.php.

Referenced by delete(), getCalendarEntry(), read(), save(), and update().

◆ $from

ilBookingReservation::$from
protected

◆ $group_id

ilBookingReservation::$group_id
protected

Definition at line 25 of file class.ilBookingReservation.php.

Referenced by getGroupId().

◆ $id

ilBookingReservation::$id
protected

Definition at line 19 of file class.ilBookingReservation.php.

Referenced by getAvailableObject(), and getId().

◆ $object_id

ilBookingReservation::$object_id
protected

Definition at line 20 of file class.ilBookingReservation.php.

Referenced by getObjectId().

◆ $status

ilBookingReservation::$status
protected

Definition at line 24 of file class.ilBookingReservation.php.

Referenced by getStatus().

◆ $to

ilBookingReservation::$to
protected

◆ $user_id

ilBookingReservation::$user_id
protected

Definition at line 21 of file class.ilBookingReservation.php.

Referenced by getListByDate(), and getUserId().

◆ STATUS_CANCELLED

◆ STATUS_IN_USE


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