ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 type $ilDB. More...
 

Static Public Member Functions

static resetGroup ($a_group_id)
 Reset booking group (in case of deletion) 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 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...
 

Protected Attributes

 $db
 
 $user
 

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 37 of file class.ilBookingEntry.php.

References $DIC, getId(), read(), setId(), and user().

38  {
39  global $DIC;
40 
41  $this->db = $DIC->database();
42  $this->user = $DIC->user();
43  $this->setId($a_booking_id);
44  if ($this->getId()) {
45  $this->read();
46  }
47  }
global $DIC
Definition: saml.php:7
read()
Read settings from db.
user()
Definition: user.php:4
setId($a_id)
Set id.
+ 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 771 of file class.ilBookingEntry.php.

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

Referenced by ilConsultationHourUtils\bookAppointment().

772  {
774  $ilDB = $this->db;
775 
776  if (!$a_user_id) {
777  $a_user_id = $ilUser->getId();
778  }
779 
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') . ')');
784 
785  include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
786  $mail = new ilCalendarMailNotification();
787  $mail->setAppointmentId($a_entry_id);
788  $mail->setRecipients(array($a_user_id));
790  $mail->send();
791  }
792  return true;
793  }
Distributes calendar mail notifications.
hasBooked($a_entry_id, $a_user_id=null)
get current number of bookings
$ilUser
Definition: imgupload.php:18
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller 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 800 of file class.ilBookingEntry.php.

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

Referenced by ilConsultationHourUtils\cancelBooking(), and ilCalendarAppointmentGUI\cancelConfirmed().

801  {
803  $ilDB = $this->db;
804 
805  if (!$a_user_id) {
806  $a_user_id = $ilUser->getId();
807  }
808 
809  // @todo do not send mails about past consultation hours
810  $entry = new ilCalendarEntry($a_entry_id);
811 
812  $past = ilDateTime::_before($entry->getStart(), new ilDateTime(time(), IL_CAL_UNIX));
813  if ($this->hasBooked($a_entry_id, $a_user_id) && !$past) {
814  include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
815  $mail = new ilCalendarMailNotification();
816  $mail->setAppointmentId($a_entry_id);
817  $mail->setRecipients(array($a_user_id));
819  $mail->send();
820  }
821  $this->deleteBooking($a_entry_id, $a_user_id);
822  return true;
823  }
Model for a calendar entry.
deleteBooking($a_entry_id, $a_user_id)
Delete booking type $ilDB.
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.
const IL_CAL_UNIX
hasBooked($a_entry_id, $a_user_id=null)
get current number of bookings
Date and time handling
$ilUser
Definition: imgupload.php:18
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilBookingEntry::delete ( )

Delete.

Returns

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

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

282  {
283  $ilDB = $this->db;
284 
285  $query = "DELETE FROM booking_entry " .
286  "WHERE booking_id = " . $ilDB->quote($this->getId(), 'integer');
287  $ilDB->manipulate($query);
288 
289  $query = 'DELETE FROM booking_obj_assignment ' .
290  'WHERE booking_id = ' . $ilDB->quote($this->getId(), 'integer');
291  $ilDB->manipulate($query);
292 
293  return true;
294  }
$query
global $ilDB
+ Here is the call graph for this function:

◆ deleteBooking()

ilBookingEntry::deleteBooking (   $a_entry_id,
  $a_user_id 
)

Delete booking type $ilDB.

Parameters
type$a_entry_id
type$a_user_id
Returns
boolean

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

References $db, $ilDB, and $query.

Referenced by cancelBooking().

833  {
834  $ilDB = $this->db;
835 
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');
839  $ilDB->manipulate($query);
840  return true;
841  }
$query
global $ilDB
+ Here is the caller graph for this function:

◆ getBookingGroup()

ilBookingEntry::getBookingGroup ( )

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

References $booking_group.

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

116  {
117  return $this->booking_group;
118  }
+ 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 560 of file class.ilBookingEntry.php.

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

Referenced by ilConsultationHoursTableGUI\parse().

561  {
562  $ilDB = $this->db;
563 
564  $set = $ilDB->query('SELECT user_id FROM booking_user' .
565  ' WHERE entry_id = ' . $ilDB->quote($a_entry_id, 'integer'));
566  $res = array();
567  while ($row = $ilDB->fetchAssoc($set)) {
568  $res[] = $row['user_id'];
569  }
570  return $res;
571  }
foreach($_POST as $key=> $value) $res
$row
global $ilDB
+ Here is the caller graph for this function:

◆ getCurrentNumberOfBookings()

ilBookingEntry::getCurrentNumberOfBookings (   $a_entry_id)

get current number of bookings

Parameters
int$a_entry_id
Returns
int

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

References $db, $ilDB, and $row.

Referenced by isAppointmentBookableForUser(), and isBookedOut().

546  {
547  $ilDB = $this->db;
548 
549  $set = $ilDB->query('SELECT COUNT(*) AS counter FROM booking_user' .
550  ' WHERE entry_id = ' . $ilDB->quote($a_entry_id, 'integer'));
551  $row = $ilDB->fetchAssoc($set);
552  return (int) $row['counter'];
553  }
$row
global $ilDB
+ Here is the caller graph for this function:

◆ getDeadlineHours()

ilBookingEntry::getDeadlineHours ( )

get deadline hours

Returns

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

References $deadline.

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

154  {
155  return $this->deadline;
156  }
+ Here is the caller graph for this function:

◆ getId()

ilBookingEntry::getId ( )

◆ getInstanceByCalendarEntryId()

static ilBookingEntry::getInstanceByCalendarEntryId (   $a_id)
static

Get instance by calendar entry.

Parameters
int$id
Returns
ilBookingEntry

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

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

377  {
378  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
379  $cal_entry = new ilCalendarEntry($a_id);
380  $booking_id = $cal_entry->getContextId();
381  if ($booking_id) {
382  return new self($booking_id);
383  }
384  }
Model for a calendar entry.
+ Here is the caller graph for this function:

◆ getNumberOfBookings()

ilBookingEntry::getNumberOfBookings ( )

get number of bookings

Returns

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

References $num_bookings.

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

173  {
174  return $this->num_bookings;
175  }
+ Here is the caller graph for this function:

◆ getObjId()

ilBookingEntry::getObjId ( )

get obj id

Returns

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

References $obj_id.

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

135  {
136  return $this->obj_id;
137  }
+ Here is the caller graph for this function:

◆ getTargetObjIds()

ilBookingEntry::getTargetObjIds ( )

get target object id

Returns
int

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

References $target_obj_ids.

Referenced by isTargetObjectVisible().

192  {
193  return $this->target_obj_ids;
194  }
+ 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 659 of file class.ilBookingEntry.php.

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

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

660  {
662  $ilDB = $this->db;
663 
664  if (!$a_user_id) {
665  $a_user_id = $ilUser->getId();
666  }
667 
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');
671  $set = $ilDB->query($query);
672  $row = $ilDB->fetchAssoc($set);
673 
674  return (bool) $row['counter'];
675  }
$ilUser
Definition: imgupload.php:18
$query
$row
global $ilDB
+ 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 477 of file class.ilBookingEntry.php.

References $DIC, $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

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

478  {
479  global $DIC;
480 
481  $ilDB = $DIC->database();
482 
483  $user_restriction = '';
484  if ($a_usr_id) {
485  $user_restriction = 'AND obj_id = ' . $ilDB->quote($a_usr_id) . ' ';
486  }
487 
488 
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') . ' ' .
492  $user_restriction;
493 
494  $res = $ilDB->query($query);
495  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
496  return true;
497  }
498  return false;
499  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$query
$row
global $ilDB
+ 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 717 of file class.ilBookingEntry.php.

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

718  {
719  // #12025
720  if ($a_user_id == ANONYMOUS_USER_ID) {
721  return false;
722  }
723 
724  // Check max bookings
725  if ($this->getNumberOfBookings() <= $this->getCurrentNumberOfBookings($a_app_id)) {
726  #$GLOBALS['ilLog']->write(__METHOD__.': Number of bookings exceeded');
727  return false;
728  }
729 
730  // Check deadline
731  $dead_limit = new ilDateTime(time(), IL_CAL_UNIX);
732  $dead_limit->increment(IL_CAL_HOUR, $this->getDeadlineHours());
733 
734  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
735  $entry = new ilCalendarEntry($a_app_id);
736  if (ilDateTime::_after($dead_limit, $entry->getStart())) {
737  #$GLOBALS['ilLog']->write(__METHOD__.': Deadline reached');
738  return false;
739  }
740 
741  // Check group restrictions
742  if (!$this->getBookingGroup()) {
743  #$GLOBALS['ilLog']->write(__METHOD__.': No booking group');
744  return true;
745  }
746  include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
748  $this->getObjId(),
749  $this->getBookingGroup()
750  );
751 
752  // Number of bookings in group
753  $bookings = self::lookupBookingsOfUser($group_apps, $a_user_id);
754 
755  include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
756  #$GLOBALS['ilLog']->write(__METHOD__.': '.ilConsultationHourGroups::lookupMaxBookings($this->getBookingGroup()));
757 
758  if (count($bookings) >= ilConsultationHourGroups::lookupMaxBookings($this->getBookingGroup())) {
759  #$GLOBALS['ilLog']->write(__METHOD__.': Personal booking limit reached');
760  return false;
761  }
762  #$GLOBALS['ilLog']->write(__METHOD__.': Is bookable!');
763  return true;
764  }
Model for a calendar entry.
getNumberOfBookings()
get number of bookings
const IL_CAL_HOUR
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.
const IL_CAL_UNIX
getCurrentNumberOfBookings($a_entry_id)
get current number of bookings
getDeadlineHours()
get deadline hours
Date and time handling
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 type $ilDB.
+ 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 393 of file class.ilBookingEntry.php.

References $DIC, $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

394  {
395  global $DIC;
396 
397  $ilDB = $DIC->database();
398 
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');
404  } else {
405  $query = 'SELECT DISTINCT(obj_id) FROM booking_entry be ' .
406  'WHERE ' . $ilDB->in('obj_id', $a_obj_ids, false, 'integer') . ' ';
407  }
408 
409  $res = $ilDB->query($query);
410  $all = array();
411  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
412  $all[] = $row->obj_id;
413  }
414  return $all;
415  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$query
$row
global $ilDB

◆ 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 683 of file class.ilBookingEntry.php.

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

684  {
686 
687  if ($this->getNumberOfBookings() == $this->getCurrentNumberOfBookings($a_entry_id)) {
688  // check against current user
689  if ($a_check_current_user) {
690  if ($this->hasBooked($a_entry_id)) {
691  return false;
692  }
693  if ($ilUser->getId() == $this->getObjId()) {
694  return false;
695  }
696  }
697  return true;
698  }
699 
700  $deadline = $this->getDeadlineHours();
701  if ($deadline) {
702  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
703  $entry = new ilCalendarEntry($a_entry_id);
704  if (time() + ($deadline * 60 * 60) > $entry->getStart()->get(IL_CAL_UNIX)) {
705  return true;
706  }
707  }
708  return false;
709  }
Model for a calendar entry.
getNumberOfBookings()
get number of bookings
const IL_CAL_UNIX
getCurrentNumberOfBookings($a_entry_id)
get current number of bookings
hasBooked($a_entry_id, $a_user_id=null)
get current number of bookings
getDeadlineHours()
get deadline hours
$ilUser
Definition: imgupload.php:18
+ 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 335 of file class.ilBookingEntry.php.

References $ilUser, $user, and getObjId().

336  {
338 
339  if (!$a_user_id) {
340  $a_user_id = $ilUser->getId();
341  }
342 
343  if ($this->getObjId() == $a_user_id) {
344  return true;
345  }
346  return false;
347  }
$ilUser
Definition: imgupload.php:18
+ 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 200 of file class.ilBookingEntry.php.

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

201  {
202  // no course/group filter
203  if (!$this->getTargetObjIds()) {
204  return true;
205  }
206 
207  $obj_id = ilObject::_lookupObjId($a_ref_id);
208  return in_array($obj_id, $this->getTargetObjIds());
209  }
getTargetObjIds()
get target object id
static _lookupObjId($a_id)
+ 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 425 of file class.ilBookingEntry.php.

References $DIC, $ilDB, $query, $res, $row, ilDBConstants\FETCHMODE_OBJECT, and ilCalendarCategory\TYPE_CH.

Referenced by ilCalendarBlockGUI\getHTML(), and ilCalendarCategories\readAllConsultationHoursCalendarOfContainer().

426  {
427  global $DIC;
428 
429  $ilDB = $DIC->database();
430 
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 ' .
439  'AND cc.type = ' . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ';
440 
441  $res = $ilDB->query($query);
442 
443  $objs = array();
444  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
445  if (!in_array($row->bobj, $objs)) {
446  $objs[] = $row->bobj;
447  }
448  }
449 
450  // non filtered booking entries
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 ' .
459  'AND cc.type = ' . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ';
460 
461 
462  $res = $ilDB->query($query);
463  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
464  if (!in_array($row->bobj, $objs)) {
465  $objs[] = $row->bobj;
466  }
467  }
468 
469  return $objs;
470  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$query
$row
global $ilDB
+ Here is the caller graph for this function:

◆ lookupBookingMessage()

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

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

References $DIC, $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilConsultationHourBookingTableGUI\parse().

502  {
503  global $DIC;
504 
505  $ilDB = $DIC->database();
506 
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');
510  $res = $ilDB->query($query);
511  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
512  return $row->booking_message;
513  }
514  return '';
515  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$query
$row
global $ilDB
+ Here is the caller graph for this function:

◆ lookupBookingsForAppointment()

static ilBookingEntry::lookupBookingsForAppointment (   $a_app_id)
static

Lookup booked users for appointment type $ilDB.

Parameters
type$a_app_id
Returns
type

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

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

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

580  {
581  global $DIC;
582 
583  $ilDB = $DIC->database();
584 
585  $query = 'SELECT user_id FROM booking_user ' .
586  'WHERE entry_id = ' . $ilDB->quote($a_app_id, 'integer');
587  $res = $ilDB->query($query);
588 
589  $users = array();
590  while ($row = $ilDB->fetchObject($res)) {
591  $users[] = $row->user_id;
592  }
593  return $users;
594  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$query
$users
Definition: authpage.php:44
$row
global $ilDB
+ 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 602 of file class.ilBookingEntry.php.

References $DIC, $ilDB, $query, $res, $row, ilDBConstants\FETCHMODE_OBJECT, IL_CAL_DATETIME, IL_CAL_UNIX, and ilTimeZone\UTC.

603  {
604  global $DIC;
605 
606  $ilDB = $DIC->database();
607 
608 
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) . ' ' .
615  'ORDER BY starta';
616  $res = $ilDB->query($query);
617 
618  $bookings = array();
619  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
620  $dt = new ilDateTime($row->starta, IL_CAL_DATETIME, ilTimeZone::UTC);
621  $dt_end = new ilDateTime($row->enda, IL_CAL_DATETIME, ilTimeZone::UTC);
622  $bookings[$row->user_id][] = array(
623  'dt' => $dt->get(IL_CAL_UNIX),
624  'dtend' => $dt_end->get(IL_CAL_UNIX),
625  'owner' => $a_usr_id);
626  }
627  return $bookings;
628  }
const IL_CAL_DATETIME
global $DIC
Definition: saml.php:7
const IL_CAL_UNIX
foreach($_POST as $key=> $value) $res
Date and time handling
$query
$row
global $ilDB

◆ 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 72 of file class.ilBookingEntry.php.

References $DIC, $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

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

73  {
74  global $DIC;
75 
76  $ilDB = $DIC->database();
77 
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');
81 
82  $res = $ilDB->query($query);
83 
84  $booked_entries = array();
85  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
86  $booked_entries[] = $row->entry_id;
87  }
88  return $booked_entries;
89  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$query
$row
global $ilDB
+ 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 636 of file class.ilBookingEntry.php.

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

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

637  {
638  $bookings = self::lookupBookingsForObject($a_obj_id, $a_usr_id);
639  include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
640  foreach (ilConsultationHourUtils::lookupManagedUsers($a_usr_id) as $managed_user_id) {
641  foreach (self::lookupBookingsForObject($a_obj_id, $managed_user_id) as $booked_user => $booking) {
642  $fullname = ilObjUser::_lookupFullname($managed_user_id);
643  foreach ($booking as $booking_entry) {
644  $booking_entry['explanation'] = '(' . $fullname . ')';
645  $bookings[$booked_user][] = $booking_entry;
646  }
647  }
648  }
649  return $bookings;
650  }
static lookupManagedUsers($a_usr_id)
Lookup managed users.
static _lookupFullname($a_user_id)
Lookup Full Name.
+ 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 300 of file class.ilBookingEntry.php.

References $db, $ilDB, $query, $res, $row, ilDBConstants\FETCHMODE_ASSOC, ilDBConstants\FETCHMODE_OBJECT, getId(), setBookingGroup(), setDeadlineHours(), setNumberOfBookings(), and setObjId().

Referenced by __construct().

301  {
302  $ilDB = $this->db;
303 
304  if (!$this->getId()) {
305  return false;
306  }
307 
308  $query = "SELECT * FROM booking_entry " .
309  "WHERE booking_id = " . $ilDB->quote($this->getId(), 'integer');
310  $res = $ilDB->query($query);
311  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
312  $this->setObjId($row['obj_id']);
313  $this->setDeadlineHours($row['deadline']);
314  $this->setNumberOfBookings($row['num_bookings']);
315  $this->setBookingGroup($row['booking_group']);
316  }
317 
318  $query = 'SELECT * FROM booking_obj_assignment ' .
319  'WHERE booking_id = ' . $ilDB->quote($this->getId(), 'integer');
320  $res = $ilDB->query($query);
321 
322  $this->target_obj_ids = array();
323  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
324  $this->target_obj_ids[] = $row->target_obj_id;
325  }
326 
327  return true;
328  }
setObjId($a_id)
Set obj id.
foreach($_POST as $key=> $value) $res
$query
setDeadlineHours($a_hours)
set deadline hours
$row
global $ilDB
setNumberOfBookings($a_num)
set number of bookings
+ 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 352 of file class.ilBookingEntry.php.

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

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

353  {
354  global $DIC;
355 
356  $ilDB = $DIC->database();
357 
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)' .
360  ' JOIN cal_categories c ON (a.cat_id = c.cat_id) WHERE c.type = ' . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer'));
361 
362  $used = array();
363  while ($row = $ilDB->fetchAssoc($set)) {
364  $used[] = $row['context_id'];
365  }
366 
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'));
369  }
global $DIC
Definition: saml.php:7
$row
global $ilDB
+ Here is the caller graph for this function:

◆ resetGroup()

static ilBookingEntry::resetGroup (   $a_group_id)
static

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

Parameters
type$a_group_id
Returns
boolean

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

References $DIC, $ilDB, and $query.

Referenced by ilConsultationHourGroup\delete().

56  {
57  global $DIC;
58 
59  $ilDB = $DIC->database();
60 
61  $query = 'UPDATE booking_entry SET booking_group = ' . $ilDB->quote(0, 'integer') . ' ' .
62  'WHERE booking_group = ' . $ilDB->quote($a_group_id, 'integer');
63  $ilDB->manipulate($query);
64  return true;
65  }
global $DIC
Definition: saml.php:7
$query
global $ilDB
+ Here is the caller graph for this function:

◆ save()

ilBookingEntry::save ( )

Save a new booking entry.

Returns

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

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

216  {
217  $ilDB = $this->db;
218 
219  $this->setId($ilDB->nextId('booking_entry'));
220  $query = 'INSERT INTO booking_entry (booking_id,obj_id,deadline,num_bookings,booking_group) ' .
221  "VALUES ( " .
222  $ilDB->quote($this->getId(), 'integer') . ', ' .
223  $ilDB->quote($this->getObjId(), 'integer') . ', ' .
224  $ilDB->quote($this->getDeadlineHours(), 'integer') . ', ' .
225  $ilDB->quote($this->getNumberOfBookings(), 'integer') . ',' .
226  $ilDB->quote($this->getBookingGroup(), 'integer') . ' ' .
227  ") ";
228  $ilDB->manipulate($query);
229 
230  foreach ((array) $this->target_obj_ids as $obj_id) {
231  $query = 'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
232  'VALUES( ' .
233  $ilDB->quote($this->getId(), 'integer') . ', ' .
234  $ilDB->quote($obj_id, 'integer') . ' ' .
235  ')';
236  $ilDB->manipulate($query);
237  }
238  return true;
239  }
getNumberOfBookings()
get number of bookings
getDeadlineHours()
get deadline hours
$query
global $ilDB
setId($a_id)
Set id.
+ Here is the call graph for this function:

◆ setBookingGroup()

ilBookingEntry::setBookingGroup (   $a_id)

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

Referenced by read().

111  {
112  $this->booking_group = $a_id;
113  }
+ Here is the caller graph for this function:

◆ setDeadlineHours()

ilBookingEntry::setDeadlineHours (   $a_hours)

set deadline hours

Parameters
int$a_hours
Returns

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

Referenced by read().

145  {
146  $this->deadline = (int) $a_hours;
147  }
+ Here is the caller graph for this function:

◆ setId()

ilBookingEntry::setId (   $a_id)
protected

Set id.

Parameters
int$a_id
Returns

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

Referenced by __construct(), and save().

97  {
98  $this->id = (int) $a_id;
99  }
+ 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 163 of file class.ilBookingEntry.php.

Referenced by read().

164  {
165  $this->num_bookings = (int) $a_num;
166  }
+ Here is the caller graph for this function:

◆ setObjId()

ilBookingEntry::setObjId (   $a_id)

Set obj id.

Parameters
int$a_id
Returns

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

Referenced by read().

126  {
127  $this->obj_id = (int) $a_id;
128  }
+ 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 182 of file class.ilBookingEntry.php.

Referenced by ilCalendarScheduleFilterBookings\modifyEvent().

183  {
184  $this->target_obj_ids = $a_obj_id;
185  }
+ Here is the caller graph for this function:

◆ update()

ilBookingEntry::update ( )

Update an existing booking entry.

Returns

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

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

246  {
247  $ilDB = $this->db;
248 
249  if (!$this->getId()) {
250  return false;
251  }
252 
253  $query = "UPDATE booking_entry SET " .
254  " obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . ", " .
255  " deadline = " . $ilDB->quote($this->getDeadlineHours(), 'integer') . ", " .
256  " num_bookings = " . $ilDB->quote($this->getNumberOfBookings(), 'integer') . ', ' .
257  'booking_group = ' . $ilDB->quote($this->getBookingGroup(), 'integer') . ' ' .
258  'WHERE booking_id = ' . $ilDB->quote($this->getId(), 'integer');
259  $ilDB->manipulate($query);
260 
261  // obj assignments
262  $query = 'DELETE FROM booking_obj_assignment ' .
263  'WHERE booking_id = ' . $ilDB->quote($this->getId(), 'integer');
264  $ilDB->manipulate($query);
265 
266  foreach ((array) $this->target_obj_ids as $obj_id) {
267  $query = 'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
268  'VALUES( ' .
269  $ilDB->quote($this->getId(), 'integer') . ', ' .
270  $ilDB->quote($obj_id, 'integer') . ' ' .
271  ')';
272  $ilDB->manipulate($query);
273  }
274  return true;
275  }
getNumberOfBookings()
get number of bookings
getDeadlineHours()
get deadline hours
$query
global $ilDB
+ 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 523 of file class.ilBookingEntry.php.

References $DIC, $GLOBALS, $ilDB, and $query.

Referenced by ilCalendarAppointmentGUI\bookconfirmed().

524  {
525  global $DIC;
526 
527  $ilDB = $DIC->database();
528 
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');
533 
534  $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $query);
535 
536  $ilDB->manipulate($query);
537  return true;
538  }
global $DIC
Definition: saml.php:7
$query
global $ilDB
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the caller graph for this function:

Field Documentation

◆ $booking_group

ilBookingEntry::$booking_group = 0
private

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

Referenced by getBookingGroup().

◆ $db

◆ $deadline

ilBookingEntry::$deadline = 0
private

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

Referenced by getDeadlineHours(), and isBookedOut().

◆ $id

ilBookingEntry::$id = 0
private

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

Referenced by getId().

◆ $num_bookings

ilBookingEntry::$num_bookings = 1
private

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

Referenced by getNumberOfBookings().

◆ $obj_id

ilBookingEntry::$obj_id = 0
private

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

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

◆ $target_obj_ids

ilBookingEntry::$target_obj_ids = array()
private

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

Referenced by getTargetObjIds().

◆ $user

ilBookingEntry::$user
protected

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

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


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