41 $this->db = $DIC->database();
42 $this->
user = $DIC->user();
43 $this->
setId($a_booking_id);
59 $ilDB = $DIC->database();
61 $query =
'UPDATE booking_entry SET booking_group = ' .
$ilDB->quote(0,
'integer') .
' ' .
62 'WHERE booking_group = ' .
$ilDB->quote($a_group_id,
'integer');
76 $ilDB = $DIC->database();
78 $query =
'SELECT entry_id FROM booking_user ' .
79 'WHERE ' .
$ilDB->in(
'entry_id', $a_app_ids,
false,
'integer') .
' ' .
80 'AND user_id = ' .
$ilDB->quote($a_usr_id,
'integer');
84 $booked_entries = array();
86 $booked_entries[] =
$row->entry_id;
88 return $booked_entries;
98 $this->
id = (int) $a_id;
112 $this->booking_group = $a_id;
127 $this->obj_id = (int) $a_id;
146 $this->deadline = (int) $a_hours;
165 $this->num_bookings = (int) $a_num;
184 $this->target_obj_ids = $a_obj_id;
220 $query =
'INSERT INTO booking_entry (booking_id,obj_id,deadline,num_bookings,booking_group) ' .
222 $ilDB->quote($this->
getId(),
'integer') .
', ' .
228 $ilDB->manipulate($query);
230 foreach ((array) $this->target_obj_ids as
$obj_id) {
231 $query =
'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
233 $ilDB->quote($this->
getId(),
'integer') .
', ' .
234 $ilDB->quote($obj_id,
'integer') .
' ' .
236 $ilDB->manipulate($query);
249 if (!$this->
getId()) {
253 $query =
"UPDATE booking_entry SET " .
254 " obj_id = " .
$ilDB->quote($this->
getObjId(),
'integer') .
", " .
258 'WHERE booking_id = ' .
$ilDB->quote($this->
getId(),
'integer');
262 $query =
'DELETE FROM booking_obj_assignment ' .
263 'WHERE booking_id = ' .
$ilDB->quote($this->
getId(),
'integer');
266 foreach ((array) $this->target_obj_ids as
$obj_id) {
267 $query =
'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
269 $ilDB->quote($this->
getId(),
'integer') .
', ' .
270 $ilDB->quote($obj_id,
'integer') .
' ' .
281 public function delete()
285 $query =
"DELETE FROM booking_entry " .
286 "WHERE booking_id = " .
$ilDB->quote($this->
getId(),
'integer');
289 $query =
'DELETE FROM booking_obj_assignment ' .
290 'WHERE booking_id = ' .
$ilDB->quote($this->
getId(),
'integer');
304 if (!$this->
getId()) {
308 $query =
"SELECT * FROM booking_entry " .
309 "WHERE booking_id = " .
$ilDB->quote($this->
getId(),
'integer');
318 $query =
'SELECT * FROM booking_obj_assignment ' .
319 'WHERE booking_id = ' .
$ilDB->quote($this->
getId(),
'integer');
322 $this->target_obj_ids = array();
324 $this->target_obj_ids[] =
$row->target_obj_id;
343 if ($this->
getObjId() == $a_user_id) {
356 $ilDB = $DIC->database();
358 $set =
$ilDB->query(
'SELECT DISTINCT(context_id) FROM cal_entries e' .
359 ' JOIN cal_cat_assignments a ON (e.cal_id = a.cal_id)' .
364 $used[] =
$row[
'context_id'];
367 $ilDB->query($q =
'DELETE FROM booking_entry WHERE ' .
$ilDB->in(
'booking_id', $used,
true,
'integer'));
368 $ilDB->query($q =
'DELETE FROM booking_obj_assignment WHERE ' .
$ilDB->in(
'booking_id', $used,
true,
'integer'));
378 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
380 $booking_id = $cal_entry->getContextId();
382 return new self($booking_id);
393 public static function isBookable(array $a_obj_ids, $a_target_obj_id = null)
397 $ilDB = $DIC->database();
399 if ($a_target_obj_id) {
400 $query =
'SELECT DISTINCT(obj_id) FROM booking_entry be ' .
401 'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
402 'WHERE ' .
$ilDB->in(
'obj_id', $a_obj_ids,
false,
'integer') .
' ' .
403 'AND bo.target_obj_id = ' .
$ilDB->quote($a_target_obj_id,
'integer');
405 $query =
'SELECT DISTINCT(obj_id) FROM booking_entry be ' .
406 'WHERE ' .
$ilDB->in(
'obj_id', $a_obj_ids,
false,
'integer') .
' ';
412 $all[] =
$row->obj_id;
429 $ilDB = $DIC->database();
431 $query =
'SELECT be.obj_id bobj FROM booking_entry be ' .
432 'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
433 'JOIN cal_entries ce on be.booking_id = ce.context_id ' .
434 'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
435 'JOIN cal_categories cc on cca.cat_id = cc.cat_id ' .
436 'WHERE ' .
$ilDB->in(
'be.obj_id', (array) $a_user_ids,
false,
'integer') .
' ' .
437 'AND ' .
$ilDB->in(
'bo.target_obj_id', (array) $a_obj_id,
false,
'integer') .
' ' .
438 'AND cc.obj_id = be.obj_id ' .
445 if (!in_array(
$row->bobj, $objs)) {
446 $objs[] =
$row->bobj;
451 $query =
'SELECT be.obj_id bobj FROM booking_entry be ' .
452 'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
453 'JOIN cal_entries ce on be.booking_id = ce.context_id ' .
454 'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
455 'JOIN cal_categories cc on cca.cat_id = cc.cat_id ' .
456 'WHERE bo.booking_id IS NULL ' .
457 'AND ' .
$ilDB->in(
'be.obj_id', (array) $a_user_ids,
false,
'integer') .
' ' .
458 'AND cc.obj_id = be.obj_id ' .
464 if (!in_array(
$row->bobj, $objs)) {
465 $objs[] =
$row->bobj;
481 $ilDB = $DIC->database();
483 $user_restriction =
'';
485 $user_restriction =
'AND obj_id = ' .
$ilDB->quote($a_usr_id) .
' ';
489 $query =
'SELECT be.booking_id FROM booking_entry be ' .
490 'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
491 'WHERE bo.target_obj_id = ' .
$ilDB->quote($a_obj_id,
'integer') .
' ' .
505 $ilDB = $DIC->database();
507 $query =
'SELECT * from booking_user ' .
508 'WHERE entry_id = ' .
$ilDB->quote($a_entry_id,
'integer') .
' ' .
509 'AND user_id = ' .
$ilDB->quote($a_usr_id,
'integer');
512 return $row->booking_message;
527 $ilDB = $DIC->database();
529 $query =
'UPDATE booking_user SET ' .
530 'booking_message = ' .
$ilDB->quote($a_message,
'text') .
' ' .
531 'WHERE entry_id = ' .
$ilDB->quote($a_entry_id,
'integer') .
' ' .
532 'AND user_id = ' .
$ilDB->quote($a_usr_id,
'integer');
536 $ilDB->manipulate($query);
549 $set =
$ilDB->query(
'SELECT COUNT(*) AS counter FROM booking_user' .
550 ' WHERE entry_id = ' .
$ilDB->quote($a_entry_id,
'integer'));
552 return (
int)
$row[
'counter'];
564 $set =
$ilDB->query(
'SELECT user_id FROM booking_user' .
565 ' WHERE entry_id = ' .
$ilDB->quote($a_entry_id,
'integer'));
583 $ilDB = $DIC->database();
585 $query =
'SELECT user_id FROM booking_user ' .
586 'WHERE entry_id = ' .
$ilDB->quote($a_app_id,
'integer');
606 $ilDB = $DIC->database();
609 $query =
'SELECT bu.user_id, starta, enda FROM booking_user bu ' .
610 'JOIN cal_entries ca ON entry_id = ca.cal_id ' .
611 'JOIN booking_entry be ON context_id = booking_id ' .
612 'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
613 'WHERE bo.target_obj_id = ' .
$ilDB->quote($a_obj_id,
'integer') .
' ' .
614 'AND be.obj_id = ' .
$ilDB->quote($a_usr_id) .
' ' .
622 $bookings[
$row->user_id][] = array(
625 'owner' => $a_usr_id);
638 $bookings = self::lookupBookingsForObject($a_obj_id, $a_usr_id);
639 include_once
'./Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
641 foreach (self::lookupBookingsForObject($a_obj_id, $managed_user_id) as $booked_user => $booking) {
643 foreach ($booking as $booking_entry) {
644 $booking_entry[
'explanation'] =
'(' . $fullname .
')';
645 $bookings[$booked_user][] = $booking_entry;
659 public function hasBooked($a_entry_id, $a_user_id = null)
668 $query =
'SELECT COUNT(*) AS counter FROM booking_user' .
669 ' WHERE entry_id = ' .
$ilDB->quote($a_entry_id,
'integer') .
670 ' AND user_id = ' .
$ilDB->quote($a_user_id,
'integer');
674 return (
bool)
$row[
'counter'];
683 public function isBookedOut($a_entry_id, $a_check_current_user =
false)
689 if ($a_check_current_user) {
702 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
720 if ($a_user_id == ANONYMOUS_USER_ID) {
726 #$GLOBALS['ilLog']->write(__METHOD__.': Number of bookings exceeded'); 734 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
737 #$GLOBALS['ilLog']->write(__METHOD__.': Deadline reached'); 743 #$GLOBALS['ilLog']->write(__METHOD__.': No booking group'); 746 include_once
'./Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
753 $bookings = self::lookupBookingsOfUser($group_apps, $a_user_id);
755 include_once
'./Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
756 #$GLOBALS['ilLog']->write(__METHOD__.': '.ilConsultationHourGroups::lookupMaxBookings($this->getBookingGroup())); 759 #$GLOBALS['ilLog']->write(__METHOD__.': Personal booking limit reached'); 762 #$GLOBALS['ilLog']->write(__METHOD__.': Is bookable!'); 771 public function book($a_entry_id, $a_user_id =
false)
780 if (!$this->
hasBooked($a_entry_id, $a_user_id)) {
781 $ilDB->manipulate(
'INSERT INTO booking_user (entry_id, user_id, tstamp)' .
782 ' VALUES (' .
$ilDB->quote($a_entry_id,
'integer') .
',' .
783 $ilDB->quote($a_user_id,
'integer') .
',' .
$ilDB->quote(time(),
'integer') .
')');
785 include_once
'Services/Calendar/classes/class.ilCalendarMailNotification.php';
787 $mail->setAppointmentId($a_entry_id);
788 $mail->setRecipients(array($a_user_id));
813 if ($this->
hasBooked($a_entry_id, $a_user_id) && !$past) {
814 include_once
'Services/Calendar/classes/class.ilCalendarMailNotification.php';
816 $mail->setAppointmentId($a_entry_id);
817 $mail->setRecipients(array($a_user_id));
836 $query =
'DELETE FROM booking_user ' .
837 'WHERE entry_id = ' .
$ilDB->quote($a_entry_id,
'integer') .
' ' .
838 'AND user_id = ' .
$ilDB->quote($a_user_id,
'integer');
static lookupBookingsForObject($a_obj_id, $a_usr_id)
Lookup booking for an object and user.
Model for a calendar entry.
getNumberOfBookings()
get number of bookings
static hasObjectBookingEntries($a_obj_id, $a_usr_id)
Check if object has assigned consultation hour appointments.
const TYPE_BOOKING_CONFIRMATION
setObjId($a_id)
Set obj id.
deleteBooking($a_entry_id, $a_user_id)
Delete booking type $ilDB.
static lookupManagedUsers($a_usr_id)
Lookup managed users.
static _lookupFullname($a_user_id)
Lookup Full Name.
static lookupManagedBookingsForObject($a_obj_id, $a_usr_id)
Lookup bookings for own and managed consultation hours of an object.
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
setTargetObjIds($a_obj_id)
set target object id
Distributes calendar mail notifications.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
static removeObsoleteEntries()
Remove unused booking entries.
static getInstanceByCalendarEntryId($a_id)
Get instance by calendar entry.
read()
Read settings from db.
getTargetObjIds()
get target object id
__construct($a_booking_id=0)
Constructor.
isAppointmentBookableForUser($a_app_id, $a_user_id)
Check if a calendar appointment is bookable for a specific user.
static lookupBookingMessage($a_entry_id, $a_usr_id)
getCurrentNumberOfBookings($a_entry_id)
get current number of bookings
static writeBookingMessage($a_entry_id, $a_usr_id, $a_message)
Write booking message.
isBookedOut($a_entry_id, $a_check_current_user=false)
get current number of bookings
hasBooked($a_entry_id, $a_user_id=null)
get current number of bookings
static lookupBookableUsersForObject($a_obj_id, $a_user_ids)
Consultation hours are offered if 1) consultation hour owner is admin or tutor and no object assignme...
static lookupBookingsForAppointment($a_app_id)
Lookup booked users for appointment type $ilDB.
foreach($_POST as $key=> $value) $res
isTargetObjectVisible($a_ref_id)
Check if target ref id is visible.
static _lookupObjId($a_id)
getDeadlineHours()
get deadline hours
cancelBooking($a_entry_id, $a_user_id=false)
cancel calendar booking for user
static isBookable(array $a_obj_ids, $a_target_obj_id=null)
Which objects are bookable?
static getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start=null)
Get appointment ids by consultation hour group.
static lookupBookingsOfUser($a_app_ids, $a_usr_id, ilDateTime $start=null)
Lookup bookings if user.
setDeadlineHours($a_hours)
set deadline hours
static lookupMaxBookings($a_group_id)
Lookup max number of bookings for group type $ilDB.
const TYPE_BOOKING_CANCELLATION
getCurrentBookings($a_entry_id)
get current bookings
save()
Save a new booking entry.
book($a_entry_id, $a_user_id=false)
book calendar entry for user
static resetGroup($a_group_id)
Reset booking group (in case of deletion) type $ilDB.
setNumberOfBookings($a_num)
set number of bookings
isOwner($a_user_id=null)
check if current (or given) user is entry owner
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
update()
Update an existing booking entry.