ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilBookingEntry Class Reference

Booking definition. More...

+ Collaboration diagram for ilBookingEntry:

Public Member Functions

 __construct ($a_booking_id=0)
 Constructor. More...
 
 getId ()
 Get id. More...
 
 setBookingGroup ($a_id)
 
 getBookingGroup ()
 
 setObjId ($a_id)
 Set obj id. More...
 
 getObjId ()
 get obj id More...
 
 setDeadlineHours ($a_hours)
 set deadline hours More...
 
 getDeadlineHours ()
 get deadline hours More...
 
 setNumberOfBookings ($a_num)
 set number of bookings More...
 
 getNumberOfBookings ()
 get number of bookings More...
 
 setTargetObjIds ($a_obj_id)
 set target object id More...
 
 getTargetObjIds ()
 get target object id More...
 
 isTargetObjectVisible ($a_ref_id)
 Check if target ref id is visible. More...
 
 save ()
 Save a new booking entry. More...
 
 update ()
 Update an existing booking entry. More...
 
 delete ()
 Delete. More...
 
 isOwner ($a_user_id=NULL)
 check if current (or given) user is entry owner More...
 
 getCurrentNumberOfBookings ($a_entry_id)
 get current number of bookings More...
 
 getCurrentBookings ($a_entry_id)
 get current bookings More...
 
 hasBooked ($a_entry_id, $a_user_id=NULL)
 get current number of bookings More...
 
 isBookedOut ($a_entry_id, $a_check_current_user=false)
 get current number of bookings More...
 
 isAppointmentBookableForUser ($a_app_id, $a_user_id)
 Check if a calendar appointment is bookable for a specific user. More...
 
 book ($a_entry_id, $a_user_id=false)
 book calendar entry for user More...
 
 cancelBooking ($a_entry_id, $a_user_id=false)
 cancel calendar booking for user More...
 
 deleteBooking ($a_entry_id, $a_user_id)
 Delete booking @global type $ilDB. More...
 

Static Public Member Functions

static resetGroup ($a_group_id)
 Reset booking group (in case of deletion) @global type $ilDB. More...
 
static lookupBookingsOfUser ($a_app_ids, $a_usr_id, ilDateTime $start=null)
 Lookup bookings if user. More...
 
static removeObsoleteEntries ()
 Remove unused booking entries. More...
 
static getInstanceByCalendarEntryId ($a_id)
 Get instance by calendar entry. More...
 
static isBookable (array $a_obj_ids, $a_target_obj_id=NULL)
 Which objects are bookable? More...
 
static lookupBookableUsersForObject ($a_obj_id, $a_user_ids)
 Consultation hours are offered if 1) consultation hour owner is admin or tutor and no object assignment 2) object is assigned to consultation hour. More...
 
static hasObjectBookingEntries ($a_obj_id, $a_usr_id)
 Check if object has assigned consultation hour appointments. More...
 
static lookupBookingMessage ($a_entry_id, $a_usr_id)
 
static writeBookingMessage ($a_entry_id, $a_usr_id, $a_message)
 Write booking message. More...
 
static lookupBookingsForAppointment ($a_app_id)
 Lookup booked users for appointment @global type $ilDB. More...
 
static lookupBookingsForObject ($a_obj_id, $a_usr_id)
 Lookup booking for an object and user. More...
 
static lookupManagedBookingsForObject ($a_obj_id, $a_usr_id)
 Lookup bookings for own and managed consultation hours of an object. More...
 

Protected Member Functions

 setId ($a_id)
 Set id. More...
 
 read ()
 Read settings from db. More...
 

Private Attributes

 $id = 0
 
 $obj_id = 0
 
 $deadline = 0
 
 $num_bookings = 1
 
 $target_obj_ids = array()
 
 $booking_group = 0
 

Detailed Description

Booking definition.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 13 of file class.ilBookingEntry.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingEntry::__construct (   $a_booking_id = 0)

Constructor.

Definition at line 27 of file class.ilBookingEntry.php.

28 {
29 $this->setId($a_booking_id);
30 if($this->getId())
31 {
32 $this->read();
33 }
34 }
read()
Read settings from db.

References getId(), read(), and setId().

+ Here is the call graph for this function:

Member Function Documentation

◆ book()

ilBookingEntry::book (   $a_entry_id,
  $a_user_id = false 
)

book calendar entry for user

Parameters
int$a_entry_id
int$a_user_id

Definition at line 778 of file class.ilBookingEntry.php.

779 {
780 global $ilUser, $ilDB;
781
782 if(!$a_user_id)
783 {
784 $a_user_id = $ilUser->getId();
785 }
786
787 if(!$this->hasBooked($a_entry_id, $a_user_id))
788 {
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').')');
792
793 include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
794 $mail = new ilCalendarMailNotification();
795 $mail->setAppointmentId($a_entry_id);
796 $mail->setRecipients(array($a_user_id));
798 $mail->send();
799 }
800 return true;
801 }
hasBooked($a_entry_id, $a_user_id=NULL)
get current number of bookings
Distributes calendar mail notifications.
global $ilDB
global $ilUser
Definition: imgupload.php:15

References $ilDB, $ilUser, hasBooked(), and ilCalendarMailNotification\TYPE_BOOKING_CONFIRMATION.

+ Here is the call graph for this function:

◆ cancelBooking()

ilBookingEntry::cancelBooking (   $a_entry_id,
  $a_user_id = false 
)

cancel calendar booking for user

Parameters
int$a_entry_id
int$a_user_id

Definition at line 808 of file class.ilBookingEntry.php.

809 {
810 global $ilUser, $ilDB;
811
812 if(!$a_user_id)
813 {
814 $a_user_id = $ilUser->getId();
815 }
816
817 // @todo do not send mails about past consultation hours
818 $entry = new ilCalendarEntry($a_entry_id);
819
820 $past = ilDateTime::_before($entry->getStart(), new ilDateTime(time(),IL_CAL_UNIX));
821 if($this->hasBooked($a_entry_id, $a_user_id) && !$past)
822 {
823 include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
824 $mail = new ilCalendarMailNotification();
825 $mail->setAppointmentId($a_entry_id);
826 $mail->setRecipients(array($a_user_id));
828 $mail->send();
829 }
830 $this->deleteBooking($a_entry_id,$a_user_id);
831 return true;
832 }
const IL_CAL_UNIX
deleteBooking($a_entry_id, $a_user_id)
Delete booking @global type $ilDB.
Model for a calendar entry.
@classDescription Date and time handling
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.

References $ilDB, $ilUser, ilDateTime\_before(), deleteBooking(), hasBooked(), IL_CAL_UNIX, and ilCalendarMailNotification\TYPE_BOOKING_CANCELLATION.

+ Here is the call graph for this function:

◆ delete()

ilBookingEntry::delete ( )

Delete.

Returns

Definition at line 268 of file class.ilBookingEntry.php.

269 {
270 global $ilDB;
271
272 $query = "DELETE FROM booking_entry ".
273 "WHERE booking_id = ".$ilDB->quote($this->getId(),'integer');
274 $ilDB->manipulate($query);
275
276 $query = 'DELETE FROM booking_obj_assignment '.
277 'WHERE booking_id = '.$ilDB->quote($this->getId(),'integer');
278 $ilDB->manipulate($query);
279
280 return true;
281 }

References $ilDB, $query, and getId().

+ Here is the call graph for this function:

◆ deleteBooking()

ilBookingEntry::deleteBooking (   $a_entry_id,
  $a_user_id 
)

Delete booking @global type $ilDB.

Parameters
type$a_entry_id
type$a_user_id
Returns
boolean

Definition at line 841 of file class.ilBookingEntry.php.

842 {
843 global $ilDB;
844
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);
849 return true;
850 }

References $ilDB, and $query.

Referenced by cancelBooking().

+ Here is the caller graph for this function:

◆ getBookingGroup()

ilBookingEntry::getBookingGroup ( )

Definition at line 99 of file class.ilBookingEntry.php.

100 {
102 }

References $booking_group.

Referenced by isAppointmentBookableForUser(), save(), and update().

+ Here is the caller graph for this function:

◆ getCurrentBookings()

ilBookingEntry::getCurrentBookings (   $a_entry_id)

get current bookings

Parameters
int$a_entry_id
Returns
array

Definition at line 553 of file class.ilBookingEntry.php.

554 {
555 global $ilDB;
556
557 $set = $ilDB->query('SELECT user_id FROM booking_user'.
558 ' WHERE entry_id = '.$ilDB->quote($a_entry_id, 'integer'));
559 $res = array();
560 while($row = $ilDB->fetchAssoc($set))
561 {
562 $res[] = $row['user_id'];
563 }
564 return $res;
565 }

References $ilDB, $res, and $row.

◆ getCurrentNumberOfBookings()

ilBookingEntry::getCurrentNumberOfBookings (   $a_entry_id)

get current number of bookings

Parameters
int$a_entry_id
Returns
int

Definition at line 538 of file class.ilBookingEntry.php.

539 {
540 global $ilDB;
541
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'];
546 }

References $ilDB, and $row.

Referenced by isAppointmentBookableForUser(), and isBookedOut().

+ Here is the caller graph for this function:

◆ getDeadlineHours()

ilBookingEntry::getDeadlineHours ( )

get deadline hours

Returns

Definition at line 137 of file class.ilBookingEntry.php.

138 {
139 return $this->deadline;
140 }

References $deadline.

Referenced by isAppointmentBookableForUser(), isBookedOut(), save(), and update().

+ Here is the caller graph for this function:

◆ getId()

ilBookingEntry::getId ( )

Get id.

Returns

Definition at line 89 of file class.ilBookingEntry.php.

90 {
91 return $this->id;
92 }

References $id.

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

+ Here is the caller graph for this function:

◆ getInstanceByCalendarEntryId()

static ilBookingEntry::getInstanceByCalendarEntryId (   $a_id)
static

Get instance by calendar entry.

Parameters
int$id
Returns
ilBookingEntry

Definition at line 367 of file class.ilBookingEntry.php.

368 {
369 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
370 $cal_entry = new ilCalendarEntry($a_id);
371 $booking_id = $cal_entry->getContextId();
372 if($booking_id)
373 {
374 return new self($booking_id);
375 }
376 }

Referenced by ilConsultationHoursGUI\assignUsersToAppointment(), ilConsultationHoursGUI\assignUsersToGroup(), ilConsultationHoursGUI\delete(), and ilConsultationHoursGUI\updateMulti().

+ Here is the caller graph for this function:

◆ getNumberOfBookings()

ilBookingEntry::getNumberOfBookings ( )

get number of bookings

Returns

Definition at line 156 of file class.ilBookingEntry.php.

157 {
158 return $this->num_bookings;
159 }

References $num_bookings.

Referenced by isAppointmentBookableForUser(), isBookedOut(), save(), and update().

+ Here is the caller graph for this function:

◆ getObjId()

ilBookingEntry::getObjId ( )

get obj id

Returns

Definition at line 118 of file class.ilBookingEntry.php.

119 {
120 return $this->obj_id;
121 }

References $obj_id.

Referenced by isAppointmentBookableForUser(), isOwner(), save(), and update().

+ Here is the caller graph for this function:

◆ getTargetObjIds()

ilBookingEntry::getTargetObjIds ( )

get target object id

Returns
int

Definition at line 175 of file class.ilBookingEntry.php.

176 {
178 }

References $target_obj_ids.

Referenced by isTargetObjectVisible().

+ Here is the caller graph for this function:

◆ hasBooked()

ilBookingEntry::hasBooked (   $a_entry_id,
  $a_user_id = NULL 
)

get current number of bookings

Parameters
int$a_entry_id
int$a_user_id
Returns
bool

Definition at line 655 of file class.ilBookingEntry.php.

656 {
657 global $ilUser, $ilDB;
658
659 if(!$a_user_id)
660 {
661 $a_user_id = $ilUser->getId();
662 }
663
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);
669
670 return (bool) $row['counter'];
671 }

References $ilDB, $ilUser, $query, and $row.

Referenced by book(), cancelBooking(), and isBookedOut().

+ Here is the caller graph for this function:

◆ hasObjectBookingEntries()

static ilBookingEntry::hasObjectBookingEntries (   $a_obj_id,
  $a_usr_id 
)
static

Check if object has assigned consultation hour appointments.

Parameters
type$a_obj_id
type$a_usr_id

Definition at line 473 of file class.ilBookingEntry.php.

474 {
475 global $ilDB;
476
477 $user_restriction = '';
478 if($a_usr_id)
479 {
480 $user_restriction = 'AND obj_id = '.$ilDB->quote($a_usr_id). ' ';
481 }
482
483
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').' '.
487 $user_restriction;
488
489 $res = $ilDB->query($query);
490 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
491 {
492 return true;
493 }
494 return false;
495 }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11

References $ilDB, $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by ilExportFieldsInfo\getSelectableFieldsInfo(), and ilMemberExportGUI\initSettingsForm().

+ Here is the caller graph for this function:

◆ isAppointmentBookableForUser()

ilBookingEntry::isAppointmentBookableForUser (   $a_app_id,
  $a_user_id 
)

Check if a calendar appointment is bookable for a specific user.

Parameters
type$a_cal_entry_id
type$a_user_id
Returns
bool

Definition at line 719 of file class.ilBookingEntry.php.

720 {
721 // #12025
722 if($a_user_id == ANONYMOUS_USER_ID)
723 {
724 return false;
725 }
726
727 // Check max bookings
728 if($this->getNumberOfBookings() <= $this->getCurrentNumberOfBookings($a_app_id))
729 {
730 #$GLOBALS['ilLog']->write(__METHOD__.': Number of bookings exceeded');
731 return false;
732 }
733
734 // Check deadline
735 $dead_limit = new ilDateTime(time(),IL_CAL_UNIX);
736 $dead_limit->increment(IL_CAL_HOUR,$this->getDeadlineHours());
737
738 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
739 $entry = new ilCalendarEntry($a_app_id);
740 if(ilDateTime::_after($dead_limit, $entry->getStart()))
741 {
742 #$GLOBALS['ilLog']->write(__METHOD__.': Deadline reached');
743 return false;
744 }
745
746 // Check group restrictions
747 if(!$this->getBookingGroup())
748 {
749 #$GLOBALS['ilLog']->write(__METHOD__.': No booking group');
750 return true;
751 }
752 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
754 $this->getObjId(),
755 $this->getBookingGroup()
756 );
757
758 // Number of bookings in group
759 $bookings = self::lookupBookingsOfUser($group_apps, $a_user_id);
760
761 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
762 #$GLOBALS['ilLog']->write(__METHOD__.': '.ilConsultationHourGroups::lookupMaxBookings($this->getBookingGroup()));
763
764 if(count($bookings) >= ilConsultationHourGroups::lookupMaxBookings($this->getBookingGroup()))
765 {
766 #$GLOBALS['ilLog']->write(__METHOD__.': Personal booking limit reached');
767 return false;
768 }
769 #$GLOBALS['ilLog']->write(__METHOD__.': Is bookable!');
770 return true;
771 }
const IL_CAL_HOUR
static lookupBookingsOfUser($a_app_ids, $a_usr_id, ilDateTime $start=null)
Lookup bookings if user.
getDeadlineHours()
get deadline hours
getCurrentNumberOfBookings($a_entry_id)
get current number of bookings
getNumberOfBookings()
get number of bookings
static getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start=null)
Get appointment ids by consultation hour group.
static lookupMaxBookings($a_group_id)
Lookup max number of bookings for group @global type $ilDB.
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.

References ilDateTime\_after(), ilConsultationHourAppointments\getAppointmentIdsByGroup(), getBookingGroup(), getCurrentNumberOfBookings(), getDeadlineHours(), getNumberOfBookings(), getObjId(), IL_CAL_HOUR, IL_CAL_UNIX, lookupBookingsOfUser(), and ilConsultationHourGroups\lookupMaxBookings().

+ Here is the call graph for this function:

◆ isBookable()

static ilBookingEntry::isBookable ( array  $a_obj_ids,
  $a_target_obj_id = NULL 
)
static

Which objects are bookable?

Parameters
array$a_obj_ids
int$a_target_obj_id
Returns
array

Definition at line 385 of file class.ilBookingEntry.php.

386 {
387 global $ilDB;
388
389 if($a_target_obj_id)
390 {
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');
395 }
396 else
397 {
398 $query = 'SELECT DISTINCT(obj_id) FROM booking_entry be '.
399 'WHERE '.$ilDB->in('obj_id', $a_obj_ids, false, 'integer').' ';
400 }
401
402 $res = $ilDB->query($query);
403 $all = array();
404 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
405 {
406 $all[] = $row->obj_id;
407 }
408 return $all;
409 }

References $ilDB, $query, $res, $row, and DB_FETCHMODE_OBJECT.

◆ isBookedOut()

ilBookingEntry::isBookedOut (   $a_entry_id,
  $a_check_current_user = false 
)

get current number of bookings

Parameters
int$a_entry_id(calendar entry)
bool$a_check_current_user
Returns
bool

Definition at line 679 of file class.ilBookingEntry.php.

680 {
681 global $ilUser;
682
683 if($this->getNumberOfBookings() == $this->getCurrentNumberOfBookings($a_entry_id))
684 {
685 // check against current user
686 if($a_check_current_user)
687 {
688 if($this->hasBooked($a_entry_id))
689 {
690 return false;
691 }
692 if($ilUser->getId() == $this->getObjId())
693 {
694 return false;
695 }
696 }
697 return true;
698 }
699
700 $deadline = $this->getDeadlineHours();
701 if($deadline)
702 {
703 include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
704 $entry = new ilCalendarEntry($a_entry_id);
705 if(time()+($deadline*60*60) > $entry->getStart()->get(IL_CAL_UNIX))
706 {
707 return true;
708 }
709 }
710 return false;
711 }

References $deadline, $ilUser, getCurrentNumberOfBookings(), getDeadlineHours(), getNumberOfBookings(), hasBooked(), and IL_CAL_UNIX.

+ Here is the call graph for this function:

◆ isOwner()

ilBookingEntry::isOwner (   $a_user_id = NULL)

check if current (or given) user is entry owner

Parameters
int$a_user_id
Returns
bool

Definition at line 325 of file class.ilBookingEntry.php.

326 {
327 global $ilUser;
328
329 if(!$a_user_id)
330 {
331 $a_user_id = $ilUser->getId();
332 }
333
334 if($this->getObjId() == $a_user_id)
335 {
336 return true;
337 }
338 return false;
339 }

References $ilUser, and getObjId().

+ Here is the call graph for this function:

◆ isTargetObjectVisible()

ilBookingEntry::isTargetObjectVisible (   $a_ref_id)

Check if target ref id is visible.

Parameters
type$a_ref_id

Definition at line 184 of file class.ilBookingEntry.php.

185 {
186 // no course/group filter
187 if(!$this->getTargetObjIds())
188 {
189 return true;
190 }
191
192 $obj_id = ilObject::_lookupObjId($a_ref_id);
193 return in_array($obj_id, $this->getTargetObjIds());
194 }
getTargetObjIds()
get target object id
static _lookupObjId($a_id)

References $obj_id, ilObject\_lookupObjId(), and getTargetObjIds().

+ Here is the call graph for this function:

◆ lookupBookableUsersForObject()

static ilBookingEntry::lookupBookableUsersForObject (   $a_obj_id,
  $a_user_ids 
)
static

Consultation hours are offered if 1) consultation hour owner is admin or tutor and no object assignment 2) object is assigned to consultation hour.

Parameters
type$a_obj_ids
type$a_user_ids
Returns
array user ids

Definition at line 419 of file class.ilBookingEntry.php.

420 {
421 global $ilDB;
422
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 '.
431 'AND cc.type = '. $ilDB->quote(ilCalendarCategory::TYPE_CH,'integer').' ';
432
433 $res = $ilDB->query($query);
434
435 $objs = array();
436 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
437 {
438 if(!in_array($row->bobj,$objs))
439 {
440 $objs[] = $row->bobj;
441 }
442 }
443
444 // non filtered booking entries
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 '.
453 'AND cc.type = '. $ilDB->quote(ilCalendarCategory::TYPE_CH,'integer').' ';
454
455
456 $res = $ilDB->query($query);
457 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
458 {
459 if(!in_array($row->bobj,$objs))
460 {
461 $objs[] = $row->bobj;
462 }
463 }
464
465 return $objs;
466 }

References $ilDB, $query, $res, $row, DB_FETCHMODE_OBJECT, and ilCalendarCategory\TYPE_CH.

Referenced by ilCalendarBlockGUI\getHTML().

+ Here is the caller graph for this function:

◆ lookupBookingMessage()

static ilBookingEntry::lookupBookingMessage (   $a_entry_id,
  $a_usr_id 
)
static

Definition at line 497 of file class.ilBookingEntry.php.

498 {
499 global $ilDB;
500
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');
504 $res = $ilDB->query($query);
505 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
506 {
507 return $row->booking_message;
508 }
509 return '';
510 }

References $ilDB, $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by ilConsultationHourBookingTableGUI\parse().

+ Here is the caller graph for this function:

◆ lookupBookingsForAppointment()

static ilBookingEntry::lookupBookingsForAppointment (   $a_app_id)
static

Lookup booked users for appointment @global type $ilDB.

Parameters
type$a_app_id
Returns
type

Definition at line 573 of file class.ilBookingEntry.php.

574 {
575 global $ilDB;
576
577 $query = 'SELECT user_id FROM booking_user '.
578 'WHERE entry_id = '.$ilDB->quote($a_app_id, 'integer');
579 $res = $ilDB->query($query);
580
581 $users = array();
582 while($row = $ilDB->fetchObject($res))
583 {
584 $users[] = $row->user_id;
585 }
586 return $users;
587 }

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

Referenced by ilConsultationHoursGUI\confirmDelete(), and ilConsultationHourBookingTableGUI\parse().

+ Here is the caller graph for this function:

◆ lookupBookingsForObject()

static ilBookingEntry::lookupBookingsForObject (   $a_obj_id,
  $a_usr_id 
)
static

Lookup booking for an object and user.

Parameters
type$a_obj_id
type$a_usr_id
Returns
array

Definition at line 595 of file class.ilBookingEntry.php.

596 {
597 global $ilDB;
598
599
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).' '.
606 'ORDER BY starta';
607 $res = $ilDB->query($query);
608
609 $bookings = array();
610 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
611 {
613 $dt_end = new ilDateTime($row->enda,IL_CAL_DATETIME, ilTimeZone::UTC);
614 $bookings[$row->user_id][] = array(
615 'dt' => $dt->get(IL_CAL_UNIX),
616 'dtend' => $dt_end->get(IL_CAL_UNIX),
617 'owner' => $a_usr_id);
618
619 }
620 return $bookings;
621 }
const IL_CAL_DATETIME

References $ilDB, $query, $res, $row, DB_FETCHMODE_OBJECT, IL_CAL_DATETIME, IL_CAL_UNIX, and ilTimeZone\UTC.

Referenced by lookupManagedBookingsForObject().

+ Here is the caller graph for this function:

◆ lookupBookingsOfUser()

static ilBookingEntry::lookupBookingsOfUser (   $a_app_ids,
  $a_usr_id,
ilDateTime  $start = null 
)
static

Lookup bookings if user.

Parameters
type$a_app_ids
type$a_usr_id

Definition at line 57 of file class.ilBookingEntry.php.

58 {
59 global $ilDB;
60
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');
64
65 $res = $ilDB->query($query);
66
67 $booked_entries = array();
68 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
69 {
70 $booked_entries[] = $row->entry_id;
71 }
72 return $booked_entries;
73 }

References $ilDB, $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by ilConsultationHoursGUI\assignUsersToAppointment(), ilConsultationHoursGUI\assignUsersToGroup(), and isAppointmentBookableForUser().

+ Here is the caller graph for this function:

◆ lookupManagedBookingsForObject()

static ilBookingEntry::lookupManagedBookingsForObject (   $a_obj_id,
  $a_usr_id 
)
static

Lookup bookings for own and managed consultation hours of an object.

Parameters
type$a_obj_id
type$a_usr_id
Returns
array

Definition at line 629 of file class.ilBookingEntry.php.

630 {
631 $bookings = self::lookupBookingsForObject($a_obj_id, $a_usr_id);
632 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
633 foreach(ilConsultationHourUtils::lookupManagedUsers($a_usr_id) as $managed_user_id)
634 {
635 foreach(self::lookupBookingsForObject($a_obj_id, $managed_user_id) as $booked_user => $booking)
636 {
637 $fullname = ilObjUser::_lookupFullname($managed_user_id);
638 foreach($booking as $booking_entry)
639 {
640 $booking_entry['explanation'] = '('.$fullname.')';
641 $bookings[$booked_user][] = $booking_entry;
642 }
643 }
644 }
645 return $bookings;
646 }
static lookupBookingsForObject($a_obj_id, $a_usr_id)
Lookup booking for an object and user.
static lookupManagedUsers($a_usr_id)
Lookup managed users.
_lookupFullname($a_user_id)
Lookup Full Name.

References ilObjUser\_lookupFullname(), lookupBookingsForObject(), and ilConsultationHourUtils\lookupManagedUsers().

Referenced by ilGroupParticipantsTableGUI\parse(), ilCourseParticipantsTableGUI\parse(), and ilMemberExport\write().

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

◆ read()

ilBookingEntry::read ( )
protected

Read settings from db.

Returns

Definition at line 287 of file class.ilBookingEntry.php.

288 {
289 global $ilDB;
290
291 if(!$this->getId())
292 {
293 return false;
294 }
295
296 $query = "SELECT * FROM booking_entry ".
297 "WHERE booking_id = ".$ilDB->quote($this->getId(),'integer');
298 $res = $ilDB->query($query);
299 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
300 {
301 $this->setObjId($row['obj_id']);
302 $this->setDeadlineHours($row['deadline']);
303 $this->setNumberOfBookings($row['num_bookings']);
304 $this->setBookingGroup($row['booking_group']);
305 }
306
307 $query = 'SELECT * FROM booking_obj_assignment '.
308 'WHERE booking_id = '.$ilDB->quote($this->getId(),'integer');
309 $res = $ilDB->query($query);
310
311 $this->target_obj_ids = array();
312 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
313 {
314 $this->target_obj_ids[] = $row->target_obj_id;
315 }
316
317 return true;
318 }
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
setDeadlineHours($a_hours)
set deadline hours
setNumberOfBookings($a_num)
set number of bookings
setObjId($a_id)
Set obj id.

References $ilDB, $query, $res, $row, DB_FETCHMODE_ASSOC, DB_FETCHMODE_OBJECT, getId(), setBookingGroup(), setDeadlineHours(), setNumberOfBookings(), and setObjId().

Referenced by __construct().

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

◆ removeObsoleteEntries()

static ilBookingEntry::removeObsoleteEntries ( )
static

Remove unused booking entries.

Definition at line 344 of file class.ilBookingEntry.php.

345 {
346 global $ilDB;
347
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)'.
350 ' JOIN cal_categories c ON (a.cat_id = c.cat_id) WHERE c.type = '.$ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer'));
351
352 $used = array();
353 while($row = $ilDB->fetchAssoc($set))
354 {
355 $used[] = $row['context_id'];
356 }
357
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'));
360 }

References $ilDB, $row, and ilCalendarCategory\TYPE_CH.

Referenced by ilConsultationHoursGUI\delete(), and ilConsultationHoursGUI\updateMulti().

+ Here is the caller graph for this function:

◆ resetGroup()

static ilBookingEntry::resetGroup (   $a_group_id)
static

Reset booking group (in case of deletion) @global type $ilDB.

Parameters
type$a_group_id
Returns
boolean

Definition at line 42 of file class.ilBookingEntry.php.

43 {
44 global $ilDB;
45
46 $query = 'UPDATE booking_entry SET booking_group = '.$ilDB->quote(0,'integer').' '.
47 'WHERE booking_group = '.$ilDB->quote($a_group_id,'integer');
48 $ilDB->manipulate($query);
49 return true;
50 }

References $ilDB, and $query.

Referenced by ilConsultationHourGroup\delete().

+ Here is the caller graph for this function:

◆ save()

ilBookingEntry::save ( )

Save a new booking entry.

Returns

Definition at line 200 of file class.ilBookingEntry.php.

201 {
202 global $ilDB;
203
204 $this->setId($ilDB->nextId('booking_entry'));
205 $query = 'INSERT INTO booking_entry (booking_id,obj_id,deadline,num_bookings,booking_group) '.
206 "VALUES ( ".
207 $ilDB->quote($this->getId(),'integer').', '.
208 $ilDB->quote($this->getObjId(),'integer').', '.
209 $ilDB->quote($this->getDeadlineHours(),'integer').', '.
210 $ilDB->quote($this->getNumberOfBookings(),'integer').','.
211 $ilDB->quote($this->getBookingGroup(),'integer').' '.
212 ") ";
213 $ilDB->manipulate($query);
214
215 foreach((array) $this->target_obj_ids as $obj_id)
216 {
217 $query = 'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) '.
218 'VALUES( '.
219 $ilDB->quote($this->getId(),'integer').', '.
220 $ilDB->quote($obj_id,'integer').' '.
221 ')';
222 $ilDB->manipulate($query);
223 }
224 return true;
225 }

References $ilDB, $obj_id, $query, getBookingGroup(), getDeadlineHours(), getId(), getNumberOfBookings(), getObjId(), and setId().

+ Here is the call graph for this function:

◆ setBookingGroup()

ilBookingEntry::setBookingGroup (   $a_id)

Definition at line 94 of file class.ilBookingEntry.php.

95 {
96 $this->booking_group = $a_id;
97 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setDeadlineHours()

ilBookingEntry::setDeadlineHours (   $a_hours)

set deadline hours

Parameters
int$a_hours
Returns

Definition at line 128 of file class.ilBookingEntry.php.

129 {
130 $this->deadline = (int)$a_hours;
131 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setId()

ilBookingEntry::setId (   $a_id)
protected

Set id.

Parameters
int$a_id
Returns

Definition at line 80 of file class.ilBookingEntry.php.

81 {
82 $this->id = (int)$a_id;
83 }

Referenced by __construct(), and save().

+ Here is the caller graph for this function:

◆ setNumberOfBookings()

ilBookingEntry::setNumberOfBookings (   $a_num)

set number of bookings

Parameters
int$a_num
Returns

Definition at line 147 of file class.ilBookingEntry.php.

148 {
149 $this->num_bookings = (int)$a_num;
150 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setObjId()

ilBookingEntry::setObjId (   $a_id)

Set obj id.

Parameters
int$a_id
Returns

Definition at line 109 of file class.ilBookingEntry.php.

110 {
111 $this->obj_id = (int)$a_id;
112 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setTargetObjIds()

ilBookingEntry::setTargetObjIds (   $a_obj_id)

set target object id

Parameters
int$a_obj_id
Returns

Definition at line 166 of file class.ilBookingEntry.php.

167 {
168 $this->target_obj_ids = $a_obj_id;
169 }

◆ update()

ilBookingEntry::update ( )

Update an existing booking entry.

Returns

Definition at line 231 of file class.ilBookingEntry.php.

232 {
233 global $ilDB;
234
235 if(!$this->getId())
236 {
237 return false;
238 }
239
240 $query = "UPDATE booking_entry SET ".
241 "SET obj_id = ".$ilDB->quote($this->getObjId(),'integer').", ".
242 " deadline = ".$ilDB->quote($this->getDeadlineHours(),'integer').", ".
243 " num_bookings = ".$ilDB->quote($this->getNumberOfBookings(),'integer').', '.
244 'booking_group = '.$ilDB->quote($this->getBookingGroup(),'integer');
245 $ilDB->manipulate($query);
246
247 // obj assignments
248 $query = 'DELETE FROM booking_obj_assignment '.
249 'WHERE booking_id = '.$ilDB->quote($this->getId(),'integer');
250 $ilDB->manipulate($query);
251
252 foreach((array) $this->target_obj_ids as $obj_id)
253 {
254 $query = 'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) '.
255 'VALUES( '.
256 $ilDB->quote($this->getId(),'integer').', '.
257 $ilDB->quote($obj_id,'integer').' '.
258 ')';
259 $ilDB->manipulate($query);
260 }
261 return true;
262 }

References $ilDB, $obj_id, $query, getBookingGroup(), getDeadlineHours(), getId(), getNumberOfBookings(), and getObjId().

+ Here is the call graph for this function:

◆ writeBookingMessage()

static ilBookingEntry::writeBookingMessage (   $a_entry_id,
  $a_usr_id,
  $a_message 
)
static

Write booking message.

Parameters
type$a_entry_id
type$a_usr_id
type$a_message

Definition at line 518 of file class.ilBookingEntry.php.

519 {
520 global $ilDB;
521
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');
526
527 $GLOBALS['ilLog']->write(__METHOD__.': '.$query);
528
529 $ilDB->manipulate($query);
530 return true;
531 }
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

References $GLOBALS, $ilDB, and $query.

Referenced by ilCalendarAppointmentGUI\bookconfirmed().

+ Here is the caller graph for this function:

Field Documentation

◆ $booking_group

ilBookingEntry::$booking_group = 0
private

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

Referenced by getBookingGroup().

◆ $deadline

ilBookingEntry::$deadline = 0
private

Definition at line 18 of file class.ilBookingEntry.php.

Referenced by getDeadlineHours(), and isBookedOut().

◆ $id

ilBookingEntry::$id = 0
private

Definition at line 15 of file class.ilBookingEntry.php.

Referenced by getId().

◆ $num_bookings

ilBookingEntry::$num_bookings = 1
private

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

Referenced by getNumberOfBookings().

◆ $obj_id

ilBookingEntry::$obj_id = 0
private

Definition at line 16 of file class.ilBookingEntry.php.

Referenced by getObjId(), isTargetObjectVisible(), save(), and update().

◆ $target_obj_ids

ilBookingEntry::$target_obj_ids = array()
private

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

Referenced by getTargetObjIds().


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