29 $this->
setId($a_booking_id);
46 $query =
'UPDATE booking_entry SET booking_group = '.$ilDB->quote(0,
'integer').
' '.
47 'WHERE booking_group = '.$ilDB->quote($a_group_id,
'integer');
61 $query =
'SELECT entry_id FROM booking_user '.
62 'WHERE '.$ilDB->in(
'entry_id',$a_app_ids,
false,
'integer').
' '.
63 'AND user_id = '.$ilDB->quote($a_usr_id,
'integer');
67 $booked_entries = array();
70 $booked_entries[] =
$row->entry_id;
72 return $booked_entries;
82 $this->
id = (int)$a_id;
96 $this->booking_group = $a_id;
111 $this->obj_id = (int)$a_id;
130 $this->deadline = (int)$a_hours;
149 $this->num_bookings = (int)$a_num;
168 $this->target_obj_ids = $a_obj_id;
204 $this->
setId($ilDB->nextId(
'booking_entry'));
205 $query =
'INSERT INTO booking_entry (booking_id,obj_id,deadline,num_bookings,booking_group) '.
207 $ilDB->quote($this->
getId(),
'integer').
', '.
208 $ilDB->quote($this->
getObjId(),
'integer').
', '.
213 $ilDB->manipulate($query);
215 foreach((array) $this->target_obj_ids as
$obj_id)
217 $query =
'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) '.
219 $ilDB->quote($this->
getId(),
'integer').
', '.
220 $ilDB->quote($obj_id,
'integer').
' '.
222 $ilDB->manipulate($query);
240 $query =
"UPDATE booking_entry SET ".
241 "SET obj_id = ".$ilDB->quote($this->
getObjId(),
'integer').
", ".
245 $ilDB->manipulate(
$query);
248 $query =
'DELETE FROM booking_obj_assignment '.
249 'WHERE booking_id = '.$ilDB->quote($this->
getId(),
'integer');
250 $ilDB->manipulate(
$query);
252 foreach((array) $this->target_obj_ids as
$obj_id)
254 $query =
'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) '.
256 $ilDB->quote($this->
getId(),
'integer').
', '.
257 $ilDB->quote($obj_id,
'integer').
' '.
259 $ilDB->manipulate(
$query);
268 public function delete()
272 $query =
"DELETE FROM booking_entry ".
273 "WHERE booking_id = ".$ilDB->quote($this->
getId(),
'integer');
274 $ilDB->manipulate(
$query);
276 $query =
'DELETE FROM booking_obj_assignment '.
277 'WHERE booking_id = '.$ilDB->quote($this->
getId(),
'integer');
278 $ilDB->manipulate(
$query);
296 $query =
"SELECT * FROM booking_entry ".
297 "WHERE booking_id = ".$ilDB->quote($this->
getId(),
'integer');
307 $query =
'SELECT * FROM booking_obj_assignment '.
308 'WHERE booking_id = '.$ilDB->quote($this->
getId(),
'integer');
311 $this->target_obj_ids = array();
314 $this->target_obj_ids[] =
$row->target_obj_id;
331 $a_user_id = $ilUser->getId();
348 $set = $ilDB->query(
'SELECT DISTINCT(context_id) FROM cal_entries e'.
349 ' JOIN cal_cat_assignments a ON (e.cal_id = a.cal_id)'.
353 while(
$row = $ilDB->fetchAssoc($set))
355 $used[] =
$row[
'context_id'];
358 $ilDB->query($q =
'DELETE FROM booking_entry WHERE '.$ilDB->in(
'booking_id', $used,
true,
'integer'));
359 $ilDB->query($q =
'DELETE FROM booking_obj_assignment WHERE '.$ilDB->in(
'booking_id',$used,
true,
'integer'));
369 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
371 $booking_id = $cal_entry->getContextId();
374 return new self($booking_id);
385 public static function isBookable(array $a_obj_ids, $a_target_obj_id = NULL)
391 $query =
'SELECT DISTINCT(obj_id) FROM booking_entry be '.
392 'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id '.
393 'WHERE '.$ilDB->in(
'obj_id', $a_obj_ids,
false,
'integer').
' '.
394 'AND bo.target_obj_id = '.$ilDB->quote($a_target_obj_id,
'integer');
398 $query =
'SELECT DISTINCT(obj_id) FROM booking_entry be '.
399 'WHERE '.$ilDB->in(
'obj_id', $a_obj_ids,
false,
'integer').
' ';
406 $all[] =
$row->obj_id;
423 $query =
'SELECT be.obj_id bobj FROM booking_entry be '.
424 'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id '.
425 'JOIN cal_entries ce on be.booking_id = ce.context_id '.
426 'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id '.
427 'JOIN cal_categories cc on cca.cat_id = cc.cat_id '.
428 'WHERE '.$ilDB->in(
'be.obj_id', (array) $a_user_ids,
false,
'integer').
' '.
429 'AND '.$ilDB->in(
'bo.target_obj_id', (array) $a_obj_id,
false,
'integer').
' '.
430 'AND cc.obj_id = be.obj_id '.
438 if(!in_array(
$row->bobj,$objs))
440 $objs[] =
$row->bobj;
445 $query =
'SELECT be.obj_id bobj FROM booking_entry be '.
446 'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id '.
447 'JOIN cal_entries ce on be.booking_id = ce.context_id '.
448 'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id '.
449 'JOIN cal_categories cc on cca.cat_id = cc.cat_id '.
450 'WHERE bo.booking_id IS NULL '.
451 'AND '.$ilDB->in(
'be.obj_id', (array) $a_user_ids,
false,
'integer').
' '.
452 'AND cc.obj_id = be.obj_id '.
459 if(!in_array(
$row->bobj,$objs))
461 $objs[] =
$row->bobj;
477 $user_restriction =
'';
480 $user_restriction =
'AND obj_id = '.$ilDB->quote($a_usr_id).
' ';
484 $query =
'SELECT be.booking_id FROM booking_entry be '.
485 'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id '.
486 'WHERE bo.target_obj_id = '.$ilDB->quote($a_obj_id,
'integer').
' '.
501 $query =
'SELECT * from booking_user '.
502 'WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer').
' '.
503 'AND user_id = '.$ilDB->quote($a_usr_id,
'integer');
507 return $row->booking_message;
522 $query =
'UPDATE booking_user SET '.
523 'booking_message = '.$ilDB->quote($a_message,
'text').
' '.
524 'WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer').
' '.
525 'AND user_id = '.$ilDB->quote($a_usr_id,
'integer');
529 $ilDB->manipulate(
$query);
542 $set = $ilDB->query(
'SELECT COUNT(*) AS counter FROM booking_user'.
543 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer'));
544 $row = $ilDB->fetchAssoc($set);
545 return (
int)
$row[
'counter'];
557 $set = $ilDB->query(
'SELECT user_id FROM booking_user'.
558 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer'));
560 while(
$row = $ilDB->fetchAssoc($set))
577 $query =
'SELECT user_id FROM booking_user '.
578 'WHERE entry_id = '.$ilDB->quote($a_app_id,
'integer');
582 while(
$row = $ilDB->fetchObject(
$res))
584 $users[] =
$row->user_id;
600 $query =
'SELECT bu.user_id, starta, enda FROM booking_user bu '.
601 'JOIN cal_entries ca ON entry_id = ca.cal_id '.
602 'JOIN booking_entry be ON context_id = booking_id '.
603 'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id '.
604 'WHERE bo.target_obj_id = '.$ilDB->quote($a_obj_id,
'integer').
' '.
605 'AND be.obj_id = '.$ilDB->quote($a_usr_id).
' '.
614 $bookings[
$row->user_id][] = array(
617 'owner' => $a_usr_id);
632 include_once
'./Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
635 foreach(self::lookupBookingsForObject($a_obj_id, $managed_user_id) as $booked_user => $booking)
638 foreach($booking as $booking_entry)
640 $booking_entry[
'explanation'] =
'('.$fullname.
')';
641 $bookings[$booked_user][] = $booking_entry;
655 public function hasBooked($a_entry_id, $a_user_id = NULL)
661 $a_user_id = $ilUser->getId();
664 $query =
'SELECT COUNT(*) AS counter FROM booking_user'.
665 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer').
666 ' AND user_id = '.$ilDB->quote($a_user_id,
'integer');
667 $set = $ilDB->query(
$query);
668 $row = $ilDB->fetchAssoc($set);
670 return (
bool)
$row[
'counter'];
679 public function isBookedOut($a_entry_id, $a_check_current_user =
false)
686 if($a_check_current_user)
692 if($ilUser->getId() == $this->
getObjId())
703 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
722 if($a_user_id == ANONYMOUS_USER_ID)
730 #$GLOBALS['ilLog']->write(__METHOD__.': Number of bookings exceeded');
738 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
742 #$GLOBALS['ilLog']->write(__METHOD__.': Deadline reached');
749 #$GLOBALS['ilLog']->write(__METHOD__.': No booking group');
752 include_once
'./Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
761 include_once
'./Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
762 #$GLOBALS['ilLog']->write(__METHOD__.': '.ilConsultationHourGroups::lookupMaxBookings($this->getBookingGroup()));
766 #$GLOBALS['ilLog']->write(__METHOD__.': Personal booking limit reached');
769 #$GLOBALS['ilLog']->write(__METHOD__.': Is bookable!');
778 public function book($a_entry_id, $a_user_id =
false)
784 $a_user_id = $ilUser->getId();
787 if(!$this->
hasBooked($a_entry_id, $a_user_id))
789 $ilDB->manipulate(
'INSERT INTO booking_user (entry_id, user_id, tstamp)'.
790 ' VALUES ('.$ilDB->quote($a_entry_id,
'integer').
','.
791 $ilDB->quote($a_user_id,
'integer').
','.$ilDB->quote(time(),
'integer').
')');
793 include_once
'Services/Calendar/classes/class.ilCalendarMailNotification.php';
795 $mail->setAppointmentId($a_entry_id);
796 $mail->setRecipients(array($a_user_id));
814 $a_user_id = $ilUser->getId();
821 if($this->
hasBooked($a_entry_id, $a_user_id) && !$past)
823 include_once
'Services/Calendar/classes/class.ilCalendarMailNotification.php';
825 $mail->setAppointmentId($a_entry_id);
826 $mail->setRecipients(array($a_user_id));
845 $query =
'DELETE FROM booking_user ' .
846 'WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer').
' '.
847 'AND user_id = '.$ilDB->quote($a_user_id,
'integer');
848 $ilDB->manipulate(
$query);