3 declare(strict_types=1);
    47         $this->db = $DIC->database();
    48         $this->
user = $DIC->user();
    49         $this->
setId($a_booking_id);
    62         $ilDB = $DIC->database();
    64         $query = 
'UPDATE booking_entry SET booking_group = ' . 
$ilDB->quote(0, 
'integer') . 
' ' .
    65             'WHERE booking_group = ' . 
$ilDB->quote($a_group_id, 
'integer');
    66         $ilDB->manipulate($query);
    81         $ilDB = $DIC->database();
    82         $query = 
'SELECT entry_id FROM booking_user ' .
    83             'WHERE ' . 
$ilDB->in(
'entry_id', $a_app_ids, 
false, 
'integer') . 
' ' .
    84             'AND user_id = ' . 
$ilDB->quote($a_usr_id, 
'integer');
    88         $booked_entries = array();
    90             $booked_entries[] = (
int) $row->entry_id;
    92         return $booked_entries;
    95     protected function setId(
int $a_id): void
   107         $this->booking_group = $a_id;
   117         $this->obj_id = $a_id;
   127         $this->deadline = $a_hours;
   137         $this->num_bookings = $a_num;
   150         $this->target_obj_ids = $a_obj_id;
   177         $this->
setId($this->db->nextId(
'booking_entry'));
   178         $query = 
'INSERT INTO booking_entry (booking_id,obj_id,deadline,num_bookings,booking_group) ' .
   180             $this->db->quote($this->
getId(), 
'integer') . 
', ' .
   181             $this->db->quote($this->
getObjId(), 
'integer') . 
', ' .
   186         $this->db->manipulate($query);
   188         foreach ((array) $this->target_obj_ids as $obj_id) {
   189             $query = 
'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
   191                 $this->db->quote($this->
getId(), 
'integer') . 
', ' .
   192                 $this->db->quote($obj_id, 
'integer') . 
' ' .
   194             $this->db->manipulate($query);
   200         if (!$this->
getId()) {
   204         $query = 
"UPDATE booking_entry SET " .
   205             " obj_id = " . $this->db->quote($this->
getObjId(), 
'integer') . 
", " .
   206             " deadline = " . $this->db->quote($this->
getDeadlineHours(), 
'integer') . 
", " .
   208             'booking_group = ' . $this->db->quote($this->
getBookingGroup(), 
'integer') . 
' ' .
   209             'WHERE booking_id = ' . $this->db->quote($this->
getId(), 
'integer');
   210         $this->db->manipulate($query);
   213         $query = 
'DELETE FROM booking_obj_assignment ' .
   214             'WHERE booking_id = ' . $this->db->quote($this->
getId(), 
'integer');
   215         $this->db->manipulate($query);
   217         foreach ((array) $this->target_obj_ids as $obj_id) {
   218             $query = 
'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
   220                 $this->db->quote($this->
getId(), 
'integer') . 
', ' .
   221                 $this->db->quote($obj_id, 
'integer') . 
' ' .
   223             $this->db->manipulate($query);
   227     public function delete(): 
void   229         $query = 
"DELETE FROM booking_entry " .
   230             "WHERE booking_id = " . $this->db->quote($this->
getId(), 
'integer');
   231         $this->db->manipulate($query);
   232         $query = 
'DELETE FROM booking_obj_assignment ' .
   233             'WHERE booking_id = ' . $this->db->quote($this->
getId(), 
'integer');
   234         $this->db->manipulate($query);
   237     protected function read(): void
   239         if (!$this->
getId()) {
   243         $query = 
"SELECT * FROM booking_entry " .
   244             "WHERE booking_id = " . $this->db->quote($this->
getId(), 
'integer');
   245         $res = $this->db->query($query);
   247             $this->
setObjId((
int) $row[
'obj_id']);
   253         $query = 
'SELECT * FROM booking_obj_assignment ' .
   254             'WHERE booking_id = ' . $this->db->quote($this->
getId(), 
'integer');
   255         $res = $this->db->query($query);
   256         $this->target_obj_ids = array();
   258             $this->target_obj_ids[] = (
int) $row->target_obj_id;
   267     public function isOwner(?
int $a_user_id = null): bool
   270             $a_user_id = $this->
user->getId();
   272         if ($this->
getObjId() == $a_user_id) {
   285         $ilDB = $DIC->database();
   286         $set = 
$ilDB->query(
'SELECT DISTINCT(context_id) FROM cal_entries e' .
   287             ' JOIN cal_cat_assignments a ON (e.cal_id = a.cal_id)' .
   288             ' JOIN cal_categories c ON (a.cat_id = c.cat_id) WHERE c.type = ' . 
$ilDB->quote(
   294         while ($row = 
$ilDB->fetchAssoc($set)) {
   295             $used[] = $row[
'context_id'];
   297         $ilDB->query(
$q = 
'DELETE FROM booking_entry WHERE ' . 
$ilDB->in(
'booking_id', $used, 
true, 
'integer'));
   298         $ilDB->query(
$q = 
'DELETE FROM booking_obj_assignment WHERE ' . 
$ilDB->in(
   314         $booking_id = $cal_entry->getContextId();
   316             return new self($booking_id);
   327     public static function isBookable(array $a_obj_ids, ?
int $a_target_obj_id = null): array
   331         $ilDB = $DIC->database();
   332         if ($a_target_obj_id) {
   333             $query = 
'SELECT DISTINCT(obj_id) FROM booking_entry be ' .
   334                 'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
   335                 'WHERE ' . 
$ilDB->in(
'obj_id', $a_obj_ids, 
false, 
'integer') . 
' ' .
   336                 'AND bo.target_obj_id = ' . 
$ilDB->quote($a_target_obj_id, 
'integer');
   338             $query = 
'SELECT DISTINCT(obj_id) FROM booking_entry be ' .
   339                 'WHERE ' . 
$ilDB->in(
'obj_id', $a_obj_ids, 
false, 
'integer') . 
' ';
   345             $all[] = (
int) $row->obj_id;
   362         $ilDB = $DIC->database();
   363         $query = 
'SELECT be.obj_id bobj FROM booking_entry be ' .
   364             'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
   365             'JOIN cal_entries ce on be.booking_id = ce.context_id ' .
   366             'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
   367             'JOIN cal_categories cc on cca.cat_id = cc.cat_id ' .
   368             'WHERE ' . 
$ilDB->in(
'be.obj_id', $a_user_ids, 
false, 
'integer') . 
' ' .
   369             'AND ' . 
$ilDB->in(
'bo.target_obj_id', $a_obj_id, 
false, 
'integer') . 
' ' .
   370             'AND cc.obj_id = be.obj_id ' .
   377             if (!in_array($row->bobj, $objs)) {
   378                 $objs[] = (
int) $row->bobj;
   383         $query = 
'SELECT be.obj_id bobj FROM booking_entry be ' .
   384             'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
   385             'JOIN cal_entries ce on be.booking_id = ce.context_id ' .
   386             'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
   387             'JOIN cal_categories cc on cca.cat_id = cc.cat_id ' .
   388             'WHERE bo.booking_id IS NULL ' .
   389             'AND ' . 
$ilDB->in(
'be.obj_id', $a_user_ids, 
false, 
'integer') . 
' ' .
   390             'AND cc.obj_id = be.obj_id ' .
   395             if (!in_array($row->bobj, $objs)) {
   396                 $objs[] = (
int) $row->bobj;
   409         $ilDB = $DIC->database();
   411         $user_restriction = 
'';
   416         $query = 
'SELECT be.booking_id FROM booking_entry be ' .
   417             'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
   418             'WHERE bo.target_obj_id = ' . 
$ilDB->quote($a_obj_id, 
'integer') . 
' ' .
   432         $ilDB = $DIC->database();
   434         $query = 
'SELECT * from booking_user ' .
   435             'WHERE entry_id = ' . 
$ilDB->quote($a_entry_id, 
'integer') . 
' ' .
   436             'AND user_id = ' . 
$ilDB->quote($a_usr_id, 
'integer');
   439             return (
string) $row->booking_message;
   451         $ilDB = $DIC->database();
   452         $query = 
'UPDATE booking_user SET ' .
   453             'booking_message = ' . 
$ilDB->quote($a_message, 
'text') . 
' ' .
   454             'WHERE entry_id = ' . 
$ilDB->quote($a_entry_id, 
'integer') . 
' ' .
   455             'AND user_id = ' . 
$ilDB->quote($a_usr_id, 
'integer');
   457         $ilDB->manipulate($query);
   465         $set = $this->db->query(
'SELECT COUNT(*) AS counter FROM booking_user' .
   466             ' WHERE entry_id = ' . $this->db->quote($a_entry_id, 
'integer'));
   467         $row = $this->db->fetchAssoc($set);
   468         if (is_array($row)) {
   469             return (
int) $row[
'counter'];
   481         $set = $this->db->query(
'SELECT user_id FROM booking_user' .
   482             ' WHERE entry_id = ' . $this->db->quote($a_entry_id, 
'integer'));
   484         while ($row = $this->db->fetchAssoc($set)) {
   485             $res[] = (
int) $row[
'user_id'];
   499         $ilDB = $DIC->database();
   500         $query = 
'SELECT user_id FROM booking_user ' .
   501             'WHERE entry_id = ' . 
$ilDB->quote($a_app_id, 
'integer');
   504         while ($row = 
$ilDB->fetchObject(
$res)) {
   505             $users[] = (
int) $row->user_id;
   520         $ilDB = $DIC->database();
   521         $query = 
'SELECT bu.user_id, starta, enda FROM booking_user bu ' .
   522             'JOIN cal_entries ca ON entry_id = ca.cal_id ' .
   523             'JOIN booking_entry be ON context_id = booking_id ' .
   524             'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
   525             'WHERE bo.target_obj_id = ' . 
$ilDB->quote($a_obj_id, 
'integer') . 
' ' .
   534             $bookings[(
int) $row->user_id][] = [
   549         $bookings = self::lookupBookingsForObject($a_obj_id, $a_usr_id);
   551             foreach (self::lookupBookingsForObject($a_obj_id, $managed_user_id) as $booked_user => $booking) {
   553                 foreach ($booking as $booking_entry) {
   554                     $booking_entry[
'explanation'] = 
'(' . $fullname . 
')';
   555                     $bookings[$booked_user][] = $booking_entry;
   565     public function hasBooked(
int $a_entry_id, ?
int $a_user_id = null): bool
   568             $a_user_id = $this->
user->getId();
   571         $query = 
'SELECT COUNT(*) AS counter FROM booking_user' .
   572             ' WHERE entry_id = ' . $this->db->quote($a_entry_id, 
'integer') .
   573             ' AND user_id = ' . $this->db->quote($a_user_id, 
'integer');
   574         $set = $this->db->query($query);
   575         $row = $this->db->fetchAssoc($set);
   576         if (is_array($row)) {
   577             return (
bool) $row[
'counter'];
   585     public function isBookedOut(
int $a_entry_id, 
bool $a_check_current_user = 
false): bool
   589             if ($a_check_current_user) {
   603             if (time() + ($deadline * 60 * 60) > $entry->getStart()->get(
IL_CAL_UNIX)) {
   643         $bookings = self::lookupBookingsOfUser($group_apps, $a_user_id);
   654     public function book(
int $a_entry_id, ?
int $a_user_id = null): bool
   657             $a_user_id = $this->
user->getId();
   660         if (!$this->
hasBooked($a_entry_id, $a_user_id)) {
   661             $this->db->manipulate(
'INSERT INTO booking_user (entry_id, user_id, tstamp)' .
   662                 ' VALUES (' . $this->db->quote($a_entry_id, 
'integer') . 
',' .
   663                 $this->db->quote($a_user_id, 
'integer') . 
',' . $this->db->quote(time(), 
'integer') . 
')');
   666             $mail->setAppointmentId($a_entry_id);
   667             $mail->setRecipients(array($a_user_id));
   677     public function cancelBooking(
int $a_entry_id, ?
int $a_user_id = null): bool
   680             $a_user_id = $this->
user->getId();
   687         if ($this->
hasBooked($a_entry_id, $a_user_id) && !$past) {
   689             $mail->setAppointmentId($a_entry_id);
   690             $mail->setRecipients(array($a_user_id));
   703         $query = 
'DELETE FROM booking_user ' .
   704             'WHERE entry_id = ' . $this->db->quote($a_entry_id, 
'integer') . 
' ' .
   705             'AND user_id = ' . $this->db->quote($a_user_id, 
'integer');
   706         $this->db->manipulate($query);
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static isBookable(array $a_obj_ids, ?int $a_target_obj_id=null)
Which objects are bookable? 
 
const TYPE_BOOKING_CONFIRMATION
 
static hasObjectBookingEntries(int $a_obj_id, int $a_usr_id)
Check if object has assigned consultation hour appointments. 
 
getCurrentBookings(int $a_entry_id)
get current bookings 
 
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets. 
 
static _lookupFullname(int $a_user_id)
 
static lookupManagedUsers($a_usr_id)
Lookup managed users. 
 
getCurrentNumberOfBookings(int $a_entry_id)
get current number of bookings 
 
isAppointmentBookableForUser(int $a_app_id, int $a_user_id)
Check if a calendar appointment is bookable for a specific user. 
 
Distributes calendar mail notifications. 
 
deleteBooking(int $a_entry_id, int $a_user_id)
Delete booking. 
 
static removeObsoleteEntries()
Remove unused booking entries. 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
hasBooked(int $a_entry_id, ?int $a_user_id=null)
get current number of bookings 
 
static writeBookingMessage(int $a_entry_id, int $a_usr_id, string $a_message)
Write booking message. 
 
static lookupBookingsOfUser(array $a_app_ids, int $a_usr_id, ?ilDateTime $start=null)
Lookup bookings of user. 
 
static _lookupObjId(int $ref_id)
 
static getInstanceByCalendarEntryId(int $a_id)
Get instance by calendar entry. 
 
__construct(int $a_booking_id=0)
Constructor. 
 
static lookupBookingsForObject(int $a_obj_id, int $a_usr_id)
Lookup booking for an object and user. 
 
setDeadlineHours(int $a_hours)
 
static getAppointmentIdsByGroup(int $a_user_id, int $a_ch_group_id, ?ilDateTime $start=null)
Get appointment ids by consultation hour group. 
 
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets. 
 
cancelBooking(int $a_entry_id, ?int $a_user_id=null)
cancel calendar booking for user 
 
isTargetObjectVisible(int $a_ref_id)
Check if target ref id is visible. 
 
static lookupMaxBookings(int $a_group_id)
Lookup max number of bookings for group. 
 
static lookupManagedBookingsForObject(int $a_obj_id, int $a_usr_id)
Lookup bookings for own and managed consultation hours of an object. 
 
const TYPE_BOOKING_CANCELLATION
 
isBookedOut(int $a_entry_id, bool $a_check_current_user=false)
get current number of bookings 
 
static lookupBookableUsersForObject(array $a_obj_id, array $a_user_ids)
Consultation hours are offered if 1) consultation hour owner is admin or tutor and no object assignme...
 
setNumberOfBookings(int $a_num)
 
static lookupBookingMessage(int $a_entry_id, int $a_usr_id)
 
static resetGroup(int $a_group_id)
Reset booking group (in case of deletion) 
 
isOwner(?int $a_user_id=null)
check if current (or given) user is entry owner 
 
setTargetObjIds(?array $a_obj_id)
 
setBookingGroup(int $a_id)
 
static lookupBookingsForAppointment(int $a_app_id)
Lookup booked users for appointment. 
 
book(int $a_entry_id, ?int $a_user_id=null)
book calendar entry for user