ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilBookingEntry Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilBookingEntry:

Public Member Functions

 __construct (int $a_booking_id=0)
 Constructor. More...
 
 getId ()
 
 setBookingGroup (int $a_id)
 
 getBookingGroup ()
 
 setObjId (int $a_id)
 
 getObjId ()
 
 setDeadlineHours (int $a_hours)
 
 getDeadlineHours ()
 
 setNumberOfBookings (int $a_num)
 
 getNumberOfBookings ()
 
 setTargetObjIds (?array $a_obj_id)
 
 getTargetObjIds ()
 
 isTargetObjectVisible (int $a_ref_id)
 Check if target ref id is visible. More...
 
 save ()
 
 update ()
 
 delete ()
 
 isOwner (?int $a_user_id=null)
 check if current (or given) user is entry owner More...
 
 getCurrentNumberOfBookings (int $a_entry_id)
 get current number of bookings More...
 
 getCurrentBookings (int $a_entry_id)
 get current bookings More...
 
 hasBooked (int $a_entry_id, ?int $a_user_id=null)
 get current number of bookings More...
 
 isBookedOut (int $a_entry_id, bool $a_check_current_user=false)
 get current number of bookings More...
 
 isAppointmentBookableForUser (int $a_app_id, int $a_user_id)
 Check if a calendar appointment is bookable for a specific user. More...
 
 book (int $a_entry_id, ?int $a_user_id=null)
 book calendar entry for user More...
 
 cancelBooking (int $a_entry_id, ?int $a_user_id=null)
 cancel calendar booking for user More...
 
 deleteBooking (int $a_entry_id, int $a_user_id)
 Delete booking. More...
 

Static Public Member Functions

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

Protected Member Functions

 setId (int $a_id)
 
 read ()
 

Protected Attributes

ilDBInterface $db
 
ilObjUser $user
 

Private Attributes

int $id = 0
 
int $obj_id = 0
 
int $deadline = 0
 
int $num_bookings = 1
 
array $target_obj_ids = []
 
int $booking_group = 0
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Booking definition

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

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

Constructor & Destructor Documentation

◆ __construct()

ilBookingEntry::__construct ( int  $a_booking_id = 0)

Constructor.

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

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

44  {
45  global $DIC;
46 
47  $this->db = $DIC->database();
48  $this->user = $DIC->user();
49  $this->setId($a_booking_id);
50  if ($this->getId()) {
51  $this->read();
52  }
53  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ book()

ilBookingEntry::book ( int  $a_entry_id,
?int  $a_user_id = null 
)

book calendar entry for user

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

References hasBooked(), ilCalendarMailNotification\TYPE_BOOKING_CONFIRMATION, and ILIAS\Repository\user().

Referenced by ilConsultationHourUtils\bookAppointment().

654  : bool
655  {
656  if (!$a_user_id) {
657  $a_user_id = $this->user->getId();
658  }
659 
660  if (!$this->hasBooked($a_entry_id, $a_user_id)) {
661  $this->db->manipulate('INSERT INTO booking_user (entry_id, user_id, tstamp)' .
662  ' VALUES (' . $this->db->quote($a_entry_id, 'integer') . ',' .
663  $this->db->quote($a_user_id, 'integer') . ',' . $this->db->quote(time(), 'integer') . ')');
664 
665  $mail = new ilCalendarMailNotification();
666  $mail->setAppointmentId($a_entry_id);
667  $mail->setRecipients(array($a_user_id));
669  $mail->send();
670  }
671  return true;
672  }
Distributes calendar mail notifications.
hasBooked(int $a_entry_id, ?int $a_user_id=null)
get current number of bookings
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cancelBooking()

ilBookingEntry::cancelBooking ( int  $a_entry_id,
?int  $a_user_id = null 
)

cancel calendar booking for user

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

References ilDateTime\_before(), deleteBooking(), hasBooked(), IL_CAL_UNIX, ilCalendarMailNotification\TYPE_BOOKING_CANCELLATION, and ILIAS\Repository\user().

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

677  : bool
678  {
679  if (!$a_user_id) {
680  $a_user_id = $this->user->getId();
681  }
682 
683  // @todo do not send mails about past consultation hours
684  $entry = new ilCalendarEntry($a_entry_id);
685 
686  $past = ilDateTime::_before($entry->getStart(), new ilDateTime(time(), IL_CAL_UNIX));
687  if ($this->hasBooked($a_entry_id, $a_user_id) && !$past) {
688  $mail = new ilCalendarMailNotification();
689  $mail->setAppointmentId($a_entry_id);
690  $mail->setRecipients(array($a_user_id));
692  $mail->send();
693  }
694  $this->deleteBooking($a_entry_id, $a_user_id);
695  return true;
696  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Distributes calendar mail notifications.
deleteBooking(int $a_entry_id, int $a_user_id)
Delete booking.
hasBooked(int $a_entry_id, ?int $a_user_id=null)
get current number of bookings
const IL_CAL_UNIX
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilBookingEntry::delete ( )

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

References $query, and getId().

227  : void
228  {
229  $query = "DELETE FROM booking_entry " .
230  "WHERE booking_id = " . $this->db->quote($this->getId(), 'integer');
231  $this->db->manipulate($query);
232  $query = 'DELETE FROM booking_obj_assignment ' .
233  'WHERE booking_id = ' . $this->db->quote($this->getId(), 'integer');
234  $this->db->manipulate($query);
235  }
$query
+ Here is the call graph for this function:

◆ deleteBooking()

ilBookingEntry::deleteBooking ( int  $a_entry_id,
int  $a_user_id 
)

Delete booking.

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

References $query.

Referenced by cancelBooking().

701  : bool
702  {
703  $query = 'DELETE FROM booking_user ' .
704  'WHERE entry_id = ' . $this->db->quote($a_entry_id, 'integer') . ' ' .
705  'AND user_id = ' . $this->db->quote($a_user_id, 'integer');
706  $this->db->manipulate($query);
707  return true;
708  }
$query
+ Here is the caller graph for this function:

◆ getBookingGroup()

ilBookingEntry::getBookingGroup ( )

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

References $booking_group.

Referenced by ilConsultationHoursGUI\edit(), isAppointmentBookableForUser(), save(), and update().

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

◆ getCurrentBookings()

ilBookingEntry::getCurrentBookings ( int  $a_entry_id)

get current bookings

Parameters
int$a_entry_id
Returns
int[]

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

References $res, and ILIAS\Repository\int().

Referenced by ilConsultationHoursGUI\delete(), and ilConsultationHoursTableGUI\parse().

479  : array
480  {
481  $set = $this->db->query('SELECT user_id FROM booking_user' .
482  ' WHERE entry_id = ' . $this->db->quote($a_entry_id, 'integer'));
483  $res = array();
484  while ($row = $this->db->fetchAssoc($set)) {
485  $res[] = (int) $row['user_id'];
486  }
487  return $res;
488  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCurrentNumberOfBookings()

ilBookingEntry::getCurrentNumberOfBookings ( int  $a_entry_id)

get current number of bookings

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

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

463  : int
464  {
465  $set = $this->db->query('SELECT COUNT(*) AS counter FROM booking_user' .
466  ' WHERE entry_id = ' . $this->db->quote($a_entry_id, 'integer'));
467  $row = $this->db->fetchAssoc($set);
468  if (is_array($row)) {
469  return (int) $row['counter'];
470  }
471  return 0;
472  }
+ Here is the caller graph for this function:

◆ getDeadlineHours()

ilBookingEntry::getDeadlineHours ( )

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

References $deadline.

Referenced by ilConsultationHoursGUI\edit(), isAppointmentBookableForUser(), isBookedOut(), save(), and update().

130  : int
131  {
132  return $this->deadline;
133  }
+ Here is the caller graph for this function:

◆ getId()

ilBookingEntry::getId ( )

◆ getInstanceByCalendarEntryId()

static ilBookingEntry::getInstanceByCalendarEntryId ( int  $a_id)
static

Get instance by calendar entry.

Parameters
int$id
Returns
ilBookingEntry|null

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

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

311  : ?ilBookingEntry
312  {
313  $cal_entry = new ilCalendarEntry($a_id);
314  $booking_id = $cal_entry->getContextId();
315  if ($booking_id) {
316  return new self($booking_id);
317  }
318  return null;
319  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ getNumberOfBookings()

ilBookingEntry::getNumberOfBookings ( )

◆ getObjId()

ilBookingEntry::getObjId ( )

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

References $obj_id.

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

120  : int
121  {
122  return $this->obj_id;
123  }
+ Here is the caller graph for this function:

◆ getTargetObjIds()

ilBookingEntry::getTargetObjIds ( )
Returns
int[] | null

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

References $target_obj_ids.

Referenced by ilConsultationHoursGUI\edit(), and isTargetObjectVisible().

156  : ?array
157  {
158  return $this->target_obj_ids;
159  }
+ Here is the caller graph for this function:

◆ hasBooked()

ilBookingEntry::hasBooked ( int  $a_entry_id,
?int  $a_user_id = null 
)

get current number of bookings

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

References $query, and ILIAS\Repository\user().

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

565  : bool
566  {
567  if (!$a_user_id) {
568  $a_user_id = $this->user->getId();
569  }
570 
571  $query = 'SELECT COUNT(*) AS counter FROM booking_user' .
572  ' WHERE entry_id = ' . $this->db->quote($a_entry_id, 'integer') .
573  ' AND user_id = ' . $this->db->quote($a_user_id, 'integer');
574  $set = $this->db->query($query);
575  $row = $this->db->fetchAssoc($set);
576  if (is_array($row)) {
577  return (bool) $row['counter'];
578  }
579  return false;
580  }
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasObjectBookingEntries()

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

Check if object has assigned consultation hour appointments.

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

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

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

405  : bool
406  {
407  global $DIC;
408 
409  $ilDB = $DIC->database();
410 
411  $user_restriction = '';
412  if ($a_usr_id) {
413  $user_restriction = 'AND obj_id = ' . $ilDB->quote($a_usr_id, ilDBConstants::T_INTEGER) . ' ';
414  }
415 
416  $query = 'SELECT be.booking_id FROM booking_entry be ' .
417  'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
418  'WHERE bo.target_obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
419  $user_restriction;
420 
421  $res = $ilDB->query($query);
422  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
423  return true;
424  }
425  return false;
426  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ isAppointmentBookableForUser()

ilBookingEntry::isAppointmentBookableForUser ( int  $a_app_id,
int  $a_user_id 
)

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

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

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

613  : bool
614  {
615  // #12025
616  if ($a_user_id == ANONYMOUS_USER_ID) {
617  return false;
618  }
619  // Check max bookings
620  if ($this->getNumberOfBookings() <= $this->getCurrentNumberOfBookings($a_app_id)) {
621  return false;
622  }
623 
624  // Check deadline
625  $dead_limit = new ilDateTime(time(), IL_CAL_UNIX);
626  $dead_limit->increment(IL_CAL_HOUR, $this->getDeadlineHours());
627 
628  $entry = new ilCalendarEntry($a_app_id);
629  if (ilDateTime::_after($dead_limit, $entry->getStart())) {
630  return false;
631  }
632 
633  // Check group restrictions
634  if (!$this->getBookingGroup()) {
635  return true;
636  }
638  $this->getObjId(),
639  $this->getBookingGroup()
640  );
641 
642  // Number of bookings in group
643  $bookings = self::lookupBookingsOfUser($group_apps, $a_user_id);
644 
645  if (count($bookings) >= ilConsultationHourGroups::lookupMaxBookings($this->getBookingGroup())) {
646  return false;
647  }
648  return true;
649  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ANONYMOUS_USER_ID
Definition: constants.php:27
const IL_CAL_HOUR
getCurrentNumberOfBookings(int $a_entry_id)
get current number of bookings
const IL_CAL_UNIX
static getAppointmentIdsByGroup(int $a_user_id, int $a_ch_group_id, ?ilDateTime $start=null)
Get appointment ids by consultation hour group.
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static lookupMaxBookings(int $a_group_id)
Lookup max number of bookings for group.
+ Here is the call graph for this function:

◆ isBookable()

static ilBookingEntry::isBookable ( array  $a_obj_ids,
?int  $a_target_obj_id = null 
)
static

Which objects are bookable?

Parameters
int[]$a_obj_ids
int | null$a_target_obj_id
Returns
int[]

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

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

327  : array
328  {
329  global $DIC;
330 
331  $ilDB = $DIC->database();
332  if ($a_target_obj_id) {
333  $query = 'SELECT DISTINCT(obj_id) FROM booking_entry be ' .
334  'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
335  'WHERE ' . $ilDB->in('obj_id', $a_obj_ids, false, 'integer') . ' ' .
336  'AND bo.target_obj_id = ' . $ilDB->quote($a_target_obj_id, 'integer');
337  } else {
338  $query = 'SELECT DISTINCT(obj_id) FROM booking_entry be ' .
339  'WHERE ' . $ilDB->in('obj_id', $a_obj_ids, false, 'integer') . ' ';
340  }
341 
342  $res = $ilDB->query($query);
343  $all = [];
344  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
345  $all[] = (int) $row->obj_id;
346  }
347  return $all;
348  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the call graph for this function:

◆ isBookedOut()

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

get current number of bookings

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

References getCurrentNumberOfBookings(), getDeadlineHours(), getNumberOfBookings(), getObjId(), hasBooked(), IL_CAL_UNIX, and ILIAS\Repository\user().

585  : bool
586  {
587  if ($this->getNumberOfBookings() == $this->getCurrentNumberOfBookings($a_entry_id)) {
588  // check against current user
589  if ($a_check_current_user) {
590  if ($this->hasBooked($a_entry_id)) {
591  return false;
592  }
593  if ($this->user->getId() == $this->getObjId()) {
594  return false;
595  }
596  }
597  return true;
598  }
599 
600  $deadline = $this->getDeadlineHours();
601  if ($deadline) {
602  $entry = new ilCalendarEntry($a_entry_id);
603  if (time() + ($deadline * 60 * 60) > $entry->getStart()->get(IL_CAL_UNIX)) {
604  return true;
605  }
606  }
607  return false;
608  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCurrentNumberOfBookings(int $a_entry_id)
get current number of bookings
hasBooked(int $a_entry_id, ?int $a_user_id=null)
get current number of bookings
const IL_CAL_UNIX
+ Here is the call graph for this function:

◆ isOwner()

ilBookingEntry::isOwner ( ?int  $a_user_id = null)

check if current (or given) user is entry owner

Parameters
int | null$a_user_id
Returns
bool

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

References getObjId(), and ILIAS\Repository\user().

267  : bool
268  {
269  if (!$a_user_id) {
270  $a_user_id = $this->user->getId();
271  }
272  if ($this->getObjId() == $a_user_id) {
273  return true;
274  }
275  return false;
276  }
+ Here is the call graph for this function:

◆ isTargetObjectVisible()

ilBookingEntry::isTargetObjectVisible ( int  $a_ref_id)

Check if target ref id is visible.

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

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

164  : bool
165  {
166  // no course/group filter
167  if (!$this->getTargetObjIds()) {
168  return true;
169  }
170 
171  $obj_id = ilObject::_lookupObjId($a_ref_id);
172  return in_array($obj_id, $this->getTargetObjIds());
173  }
static _lookupObjId(int $ref_id)
+ Here is the call graph for this function:

◆ lookupBookableUsersForObject()

static ilBookingEntry::lookupBookableUsersForObject ( array  $a_obj_id,
array  $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
int[]$a_obj_ids
int[]$a_user_ids
Returns
int[] user ids

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

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, ILIAS\Repository\int(), and ilCalendarCategory\TYPE_CH.

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

358  : array
359  {
360  global $DIC;
361 
362  $ilDB = $DIC->database();
363  $query = 'SELECT be.obj_id bobj FROM booking_entry be ' .
364  'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
365  'JOIN cal_entries ce on be.booking_id = ce.context_id ' .
366  'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
367  'JOIN cal_categories cc on cca.cat_id = cc.cat_id ' .
368  'WHERE ' . $ilDB->in('be.obj_id', $a_user_ids, false, 'integer') . ' ' .
369  'AND ' . $ilDB->in('bo.target_obj_id', $a_obj_id, false, 'integer') . ' ' .
370  'AND cc.obj_id = be.obj_id ' .
371  'AND cc.type = ' . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ';
372 
373  $res = $ilDB->query($query);
374 
375  $objs = [];
376  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
377  if (!in_array($row->bobj, $objs)) {
378  $objs[] = (int) $row->bobj;
379  }
380  }
381 
382  // non filtered booking entries
383  $query = 'SELECT be.obj_id bobj FROM booking_entry be ' .
384  'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
385  'JOIN cal_entries ce on be.booking_id = ce.context_id ' .
386  'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
387  'JOIN cal_categories cc on cca.cat_id = cc.cat_id ' .
388  'WHERE bo.booking_id IS NULL ' .
389  'AND ' . $ilDB->in('be.obj_id', $a_user_ids, false, 'integer') . ' ' .
390  'AND cc.obj_id = be.obj_id ' .
391  'AND cc.type = ' . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ';
392 
393  $res = $ilDB->query($query);
394  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
395  if (!in_array($row->bobj, $objs)) {
396  $objs[] = (int) $row->bobj;
397  }
398  }
399  return $objs;
400  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupBookingMessage()

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

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

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

Referenced by ilConsultationHourBookingTableGUI\parse().

428  : string
429  {
430  global $DIC;
431 
432  $ilDB = $DIC->database();
433 
434  $query = 'SELECT * from booking_user ' .
435  'WHERE entry_id = ' . $ilDB->quote($a_entry_id, 'integer') . ' ' .
436  'AND user_id = ' . $ilDB->quote($a_usr_id, 'integer');
437  $res = $ilDB->query($query);
438  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
439  return (string) $row->booking_message;
440  }
441  return '';
442  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ lookupBookingsForAppointment()

static ilBookingEntry::lookupBookingsForAppointment ( int  $a_app_id)
static

Lookup booked users for appointment.

Parameters
int$a_app_id
Returns
int[]

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

References $DIC, $ilDB, $query, $res, and ILIAS\Repository\int().

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

495  : array
496  {
497  global $DIC;
498 
499  $ilDB = $DIC->database();
500  $query = 'SELECT user_id FROM booking_user ' .
501  'WHERE entry_id = ' . $ilDB->quote($a_app_id, 'integer');
502  $res = $ilDB->query($query);
503  $users = [];
504  while ($row = $ilDB->fetchObject($res)) {
505  $users[] = (int) $row->user_id;
506  }
507  return $users;
508  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupBookingsForObject()

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

Lookup booking for an object and user.

Parameters
int$a_obj_id
int$a_usr_id
Returns
array<int, array<{dt: int, dtend: int, owner: int}>>

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

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, IL_CAL_DATETIME, IL_CAL_UNIX, ILIAS\Repository\int(), ilDBConstants\T_INTEGER, and ilTimeZone\UTC.

516  : array
517  {
518  global $DIC;
519 
520  $ilDB = $DIC->database();
521  $query = 'SELECT bu.user_id, starta, enda FROM booking_user bu ' .
522  'JOIN cal_entries ca ON entry_id = ca.cal_id ' .
523  'JOIN booking_entry be ON context_id = booking_id ' .
524  'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
525  'WHERE bo.target_obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
526  'AND be.obj_id = ' . $ilDB->quote($a_usr_id, ilDBConstants::T_INTEGER) . ' ' .
527  'ORDER BY starta';
528  $res = $ilDB->query($query);
529 
530  $bookings = array();
531  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
532  $dt = new ilDateTime($row->starta, IL_CAL_DATETIME, ilTimeZone::UTC);
533  $dt_end = new ilDateTime($row->enda, IL_CAL_DATETIME, ilTimeZone::UTC);
534  $bookings[(int) $row->user_id][] = [
535  'dt' => $dt->get(IL_CAL_UNIX),
536  'dtend' => $dt_end->get(IL_CAL_UNIX),
537  'owner' => $a_usr_id
538  ];
539  }
540  return $bookings;
541  }
$res
Definition: ltiservices.php:69
const IL_CAL_DATETIME
const IL_CAL_UNIX
global $DIC
Definition: feed.php:28
$query
+ Here is the call graph for this function:

◆ lookupBookingsOfUser()

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

Lookup bookings of user.

Parameters
int[]
int
?ilDateTime
Returns
int[]

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

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

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

77  : array
78  {
79  global $DIC;
80 
81  $ilDB = $DIC->database();
82  $query = 'SELECT entry_id FROM booking_user ' .
83  'WHERE ' . $ilDB->in('entry_id', $a_app_ids, false, 'integer') . ' ' .
84  'AND user_id = ' . $ilDB->quote($a_usr_id, 'integer');
85 
86  $res = $ilDB->query($query);
87 
88  $booked_entries = array();
89  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
90  $booked_entries[] = (int) $row->entry_id;
91  }
92  return $booked_entries;
93  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupManagedBookingsForObject()

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

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

Returns
array<string, array<{dt: int, dtend: int, owner: int, explanation: string}>>

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

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

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

547  : array
548  {
549  $bookings = self::lookupBookingsForObject($a_obj_id, $a_usr_id);
550  foreach (ilConsultationHourUtils::lookupManagedUsers($a_usr_id) as $managed_user_id) {
551  foreach (self::lookupBookingsForObject($a_obj_id, $managed_user_id) as $booked_user => $booking) {
552  $fullname = ilObjUser::_lookupFullname($managed_user_id);
553  foreach ($booking as $booking_entry) {
554  $booking_entry['explanation'] = '(' . $fullname . ')';
555  $bookings[$booked_user][] = $booking_entry;
556  }
557  }
558  }
559  return $bookings;
560  }
static _lookupFullname(int $a_user_id)
static lookupManagedUsers($a_usr_id)
Lookup managed users.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilBookingEntry::read ( )
protected

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

References $query, $res, ilDBConstants\FETCHMODE_ASSOC, ilDBConstants\FETCHMODE_OBJECT, getId(), ILIAS\Repository\int(), setBookingGroup(), setDeadlineHours(), setNumberOfBookings(), and setObjId().

Referenced by __construct().

237  : void
238  {
239  if (!$this->getId()) {
240  return;
241  }
242 
243  $query = "SELECT * FROM booking_entry " .
244  "WHERE booking_id = " . $this->db->quote($this->getId(), 'integer');
245  $res = $this->db->query($query);
246  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
247  $this->setObjId((int) $row['obj_id']);
248  $this->setDeadlineHours((int) $row['deadline']);
249  $this->setNumberOfBookings((int) $row['num_bookings']);
250  $this->setBookingGroup((int) $row['booking_group']);
251  }
252 
253  $query = 'SELECT * FROM booking_obj_assignment ' .
254  'WHERE booking_id = ' . $this->db->quote($this->getId(), 'integer');
255  $res = $this->db->query($query);
256  $this->target_obj_ids = array();
257  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
258  $this->target_obj_ids[] = (int) $row->target_obj_id;
259  }
260  }
$res
Definition: ltiservices.php:69
setDeadlineHours(int $a_hours)
$query
setNumberOfBookings(int $a_num)
+ 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 281 of file class.ilBookingEntry.php.

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

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

281  : void
282  {
283  global $DIC;
284 
285  $ilDB = $DIC->database();
286  $set = $ilDB->query('SELECT DISTINCT(context_id) FROM cal_entries e' .
287  ' JOIN cal_cat_assignments a ON (e.cal_id = a.cal_id)' .
288  ' JOIN cal_categories c ON (a.cat_id = c.cat_id) WHERE c.type = ' . $ilDB->quote(
290  'integer'
291  ));
292 
293  $used = array();
294  while ($row = $ilDB->fetchAssoc($set)) {
295  $used[] = $row['context_id'];
296  }
297  $ilDB->query($q = 'DELETE FROM booking_entry WHERE ' . $ilDB->in('booking_id', $used, true, 'integer'));
298  $ilDB->query($q = 'DELETE FROM booking_obj_assignment WHERE ' . $ilDB->in(
299  'booking_id',
300  $used,
301  true,
302  'integer'
303  ));
304  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ resetGroup()

static ilBookingEntry::resetGroup ( int  $a_group_id)
static

Reset booking group (in case of deletion)

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

References $DIC, $ilDB, and $query.

Referenced by ilConsultationHourGroup\delete().

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

◆ save()

ilBookingEntry::save ( )

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

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

Referenced by ilConsultationHoursGUI\createNewBookingEntry(), and ilConsultationHoursGUI\saveSequence().

175  : void
176  {
177  $this->setId($this->db->nextId('booking_entry'));
178  $query = 'INSERT INTO booking_entry (booking_id,obj_id,deadline,num_bookings,booking_group) ' .
179  "VALUES ( " .
180  $this->db->quote($this->getId(), 'integer') . ', ' .
181  $this->db->quote($this->getObjId(), 'integer') . ', ' .
182  $this->db->quote($this->getDeadlineHours(), 'integer') . ', ' .
183  $this->db->quote($this->getNumberOfBookings(), 'integer') . ',' .
184  $this->db->quote($this->getBookingGroup(), 'integer') . ' ' .
185  ") ";
186  $this->db->manipulate($query);
187 
188  foreach ((array) $this->target_obj_ids as $obj_id) {
189  $query = 'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
190  'VALUES( ' .
191  $this->db->quote($this->getId(), 'integer') . ', ' .
192  $this->db->quote($obj_id, 'integer') . ' ' .
193  ')';
194  $this->db->manipulate($query);
195  }
196  }
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setBookingGroup()

ilBookingEntry::setBookingGroup ( int  $a_id)

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

Referenced by ilConsultationHoursGUI\createNewBookingEntry(), read(), and ilConsultationHoursGUI\saveSequence().

105  : void
106  {
107  $this->booking_group = $a_id;
108  }
+ Here is the caller graph for this function:

◆ setDeadlineHours()

ilBookingEntry::setDeadlineHours ( int  $a_hours)

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

Referenced by ilConsultationHoursGUI\createNewBookingEntry(), read(), and ilConsultationHoursGUI\saveSequence().

125  : void
126  {
127  $this->deadline = $a_hours;
128  }
+ Here is the caller graph for this function:

◆ setId()

ilBookingEntry::setId ( int  $a_id)
protected

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

Referenced by __construct(), and save().

95  : void
96  {
97  $this->id = $a_id;
98  }
+ Here is the caller graph for this function:

◆ setNumberOfBookings()

ilBookingEntry::setNumberOfBookings ( int  $a_num)

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

Referenced by ilConsultationHoursGUI\createNewBookingEntry(), read(), and ilConsultationHoursGUI\saveSequence().

135  : void
136  {
137  $this->num_bookings = $a_num;
138  }
+ Here is the caller graph for this function:

◆ setObjId()

ilBookingEntry::setObjId ( int  $a_id)

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

Referenced by ilConsultationHoursGUI\createNewBookingEntry(), read(), and ilConsultationHoursGUI\saveSequence().

115  : void
116  {
117  $this->obj_id = $a_id;
118  }
+ Here is the caller graph for this function:

◆ setTargetObjIds()

ilBookingEntry::setTargetObjIds ( ?array  $a_obj_id)
Parameters
int[]|null$a_obj_id

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

Referenced by ilConsultationHoursGUI\createNewBookingEntry(), ilCalendarScheduleFilterBookings\modifyEvent(), and ilConsultationHoursGUI\saveSequence().

148  : void
149  {
150  $this->target_obj_ids = $a_obj_id;
151  }
+ Here is the caller graph for this function:

◆ update()

ilBookingEntry::update ( )

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

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

198  : void
199  {
200  if (!$this->getId()) {
201  return;
202  }
203 
204  $query = "UPDATE booking_entry SET " .
205  " obj_id = " . $this->db->quote($this->getObjId(), 'integer') . ", " .
206  " deadline = " . $this->db->quote($this->getDeadlineHours(), 'integer') . ", " .
207  " num_bookings = " . $this->db->quote($this->getNumberOfBookings(), 'integer') . ', ' .
208  'booking_group = ' . $this->db->quote($this->getBookingGroup(), 'integer') . ' ' .
209  'WHERE booking_id = ' . $this->db->quote($this->getId(), 'integer');
210  $this->db->manipulate($query);
211 
212  // obj assignments
213  $query = 'DELETE FROM booking_obj_assignment ' .
214  'WHERE booking_id = ' . $this->db->quote($this->getId(), 'integer');
215  $this->db->manipulate($query);
216 
217  foreach ((array) $this->target_obj_ids as $obj_id) {
218  $query = 'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
219  'VALUES( ' .
220  $this->db->quote($this->getId(), 'integer') . ', ' .
221  $this->db->quote($obj_id, 'integer') . ' ' .
222  ')';
223  $this->db->manipulate($query);
224  }
225  }
$query
+ Here is the call graph for this function:

◆ writeBookingMessage()

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

Write booking message.

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

References $DIC, $ilDB, and $query.

Referenced by ilCalendarAppointmentGUI\bookconfirmed().

447  : void
448  {
449  global $DIC;
450 
451  $ilDB = $DIC->database();
452  $query = 'UPDATE booking_user SET ' .
453  'booking_message = ' . $ilDB->quote($a_message, 'text') . ' ' .
454  'WHERE entry_id = ' . $ilDB->quote($a_entry_id, 'integer') . ' ' .
455  'AND user_id = ' . $ilDB->quote($a_usr_id, 'integer');
456 
457  $ilDB->manipulate($query);
458  }
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

Field Documentation

◆ $booking_group

int ilBookingEntry::$booking_group = 0
private

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

Referenced by getBookingGroup().

◆ $db

ilDBInterface ilBookingEntry::$db
protected

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

◆ $deadline

int ilBookingEntry::$deadline = 0
private

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

Referenced by getDeadlineHours().

◆ $id

int ilBookingEntry::$id = 0
private

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

Referenced by getId().

◆ $num_bookings

int ilBookingEntry::$num_bookings = 1
private

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

Referenced by getNumberOfBookings().

◆ $obj_id

int ilBookingEntry::$obj_id = 0
private

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

Referenced by getObjId().

◆ $target_obj_ids

array ilBookingEntry::$target_obj_ids = []
private

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

Referenced by getTargetObjIds().

◆ $user

ilObjUser ilBookingEntry::$user
protected

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


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