ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 ()
 
 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 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 = []
 

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

Constructor & Destructor Documentation

◆ __construct()

ilBookingEntry::__construct ( int  $a_booking_id = 0)

Constructor.

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

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

42  {
43  global $DIC;
44 
45  $this->db = $DIC->database();
46  $this->user = $DIC->user();
47  $this->setId($a_booking_id);
48  if ($this->getId()) {
49  $this->read();
50  }
51  }
global $DIC
Definition: shib_login.php:25
+ 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 609 of file class.ilBookingEntry.php.

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

609  : bool
610  {
611  if (!$a_user_id) {
612  $a_user_id = $this->user->getId();
613  }
614 
615  if (!$this->hasBooked($a_entry_id, $a_user_id)) {
616  $this->db->manipulate('INSERT INTO booking_user (entry_id, user_id, tstamp)' .
617  ' VALUES (' . $this->db->quote($a_entry_id, 'integer') . ',' .
618  $this->db->quote($a_user_id, 'integer') . ',' . $this->db->quote(time(), 'integer') . ')');
619  }
620  return true;
621  }
hasBooked(int $a_entry_id, ?int $a_user_id=null)
get current number of bookings
+ Here is the call graph for this function:

◆ cancelBooking()

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

cancel calendar booking for user

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

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

626  : bool
627  {
628  if (!$a_user_id) {
629  $a_user_id = $this->user->getId();
630  }
631 
632  // @todo do not send mails about past consultation hours
633  $entry = new ilCalendarEntry($a_entry_id);
634 
635  $past = ilDateTime::_before($entry->getStart(), new ilDateTime(time(), IL_CAL_UNIX));
636  if ($this->hasBooked($a_entry_id, $a_user_id) && !$past) {
637  $mail = new ilCalendarMailNotification();
638  $mail->setAppointmentId($a_entry_id);
639  $mail->setRecipients(array($a_user_id));
641  $mail->send();
642  }
643  $this->deleteBooking($a_entry_id, $a_user_id);
644  return true;
645  }
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:

◆ delete()

ilBookingEntry::delete ( )

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

References getId().

199  : void
200  {
201  $query = "DELETE FROM booking_entry " .
202  "WHERE booking_id = " . $this->db->quote($this->getId(), 'integer');
203  $this->db->manipulate($query);
204  $query = 'DELETE FROM booking_obj_assignment ' .
205  'WHERE booking_id = ' . $this->db->quote($this->getId(), 'integer');
206  $this->db->manipulate($query);
207  }
+ Here is the call graph for this function:

◆ deleteBooking()

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

Delete booking.

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

Referenced by cancelBooking().

650  : bool
651  {
652  $query = 'DELETE FROM booking_user ' .
653  'WHERE entry_id = ' . $this->db->quote($a_entry_id, 'integer') . ' ' .
654  'AND user_id = ' . $this->db->quote($a_user_id, 'integer');
655  $this->db->manipulate($query);
656  return true;
657  }
+ 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 450 of file class.ilBookingEntry.php.

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

Referenced by ilConsultationHoursGUI\deleteAppointments(), and ilConsultationHoursGUI\sendMailToSelectedUsers().

450  : array
451  {
452  $set = $this->db->query('SELECT user_id FROM booking_user' .
453  ' WHERE entry_id = ' . $this->db->quote($a_entry_id, 'integer'));
454  $res = array();
455  while ($row = $this->db->fetchAssoc($set)) {
456  $res[] = (int) $row['user_id'];
457  }
458  return $res;
459  }
$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 434 of file class.ilBookingEntry.php.

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

434  : int
435  {
436  $set = $this->db->query('SELECT COUNT(*) AS counter FROM booking_user' .
437  ' WHERE entry_id = ' . $this->db->quote($a_entry_id, 'integer'));
438  $row = $this->db->fetchAssoc($set);
439  if (is_array($row)) {
440  return (int) $row['counter'];
441  }
442  return 0;
443  }
+ Here is the caller graph for this function:

◆ getDeadlineHours()

ilBookingEntry::getDeadlineHours ( )

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

References $deadline.

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

104  : int
105  {
106  return $this->deadline;
107  }
+ 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 282 of file class.ilBookingEntry.php.

Referenced by ilConsultationHoursGUI\assignUsersToAppointment(), ilConsultationHoursGUI\deleteAppointments(), and ilConsultationHoursGUI\rewriteBookingIdsForAppointments().

282  : ?ilBookingEntry
283  {
284  $cal_entry = new ilCalendarEntry($a_id);
285  $booking_id = $cal_entry->getContextId();
286  if ($booking_id) {
287  return new self($booking_id);
288  }
289  return null;
290  }
+ Here is the caller graph for this function:

◆ getNumberOfBookings()

ilBookingEntry::getNumberOfBookings ( )

◆ getObjId()

ilBookingEntry::getObjId ( )

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

References $obj_id.

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

94  : int
95  {
96  return $this->obj_id;
97  }
+ Here is the caller graph for this function:

◆ getTargetObjIds()

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

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

References $target_obj_ids.

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

130  : ?array
131  {
132  return $this->target_obj_ids;
133  }
+ 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 536 of file class.ilBookingEntry.php.

References ILIAS\Repository\user().

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

536  : bool
537  {
538  if (!$a_user_id) {
539  $a_user_id = $this->user->getId();
540  }
541 
542  $query = 'SELECT COUNT(*) AS counter FROM booking_user' .
543  ' WHERE entry_id = ' . $this->db->quote($a_entry_id, 'integer') .
544  ' AND user_id = ' . $this->db->quote($a_user_id, 'integer');
545  $set = $this->db->query($query);
546  $row = $this->db->fetchAssoc($set);
547  if (is_array($row)) {
548  return (bool) $row['counter'];
549  }
550  return false;
551  }
+ 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 376 of file class.ilBookingEntry.php.

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

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

376  : bool
377  {
378  global $DIC;
379 
380  $ilDB = $DIC->database();
381 
382  $user_restriction = '';
383  if ($a_usr_id) {
384  $user_restriction = 'AND obj_id = ' . $ilDB->quote($a_usr_id, ilDBConstants::T_INTEGER) . ' ';
385  }
386 
387  $query = 'SELECT be.booking_id FROM booking_entry be ' .
388  'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
389  'WHERE bo.target_obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
390  $user_restriction;
391 
392  $res = $ilDB->query($query);
393  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
394  return true;
395  }
396  return false;
397  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:25
+ 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 584 of file class.ilBookingEntry.php.

References ilDateTime\_after(), ANONYMOUS_USER_ID, getCurrentNumberOfBookings(), getDeadlineHours(), getNumberOfBookings(), IL_CAL_HOUR, and IL_CAL_UNIX.

584  : bool
585  {
586  // #12025
587  if ($a_user_id == ANONYMOUS_USER_ID) {
588  return false;
589  }
590  // Check max bookings
591  if ($this->getNumberOfBookings() <= $this->getCurrentNumberOfBookings($a_app_id)) {
592  return false;
593  }
594 
595  // Check deadline
596  $dead_limit = new ilDateTime(time(), IL_CAL_UNIX);
597  $dead_limit->increment(IL_CAL_HOUR, $this->getDeadlineHours());
598 
599  $entry = new ilCalendarEntry($a_app_id);
600  if (ilDateTime::_after($dead_limit, $entry->getStart())) {
601  return false;
602  }
603  return true;
604  }
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 _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.
+ 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 298 of file class.ilBookingEntry.php.

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

298  : array
299  {
300  global $DIC;
301 
302  $ilDB = $DIC->database();
303  if ($a_target_obj_id) {
304  $query = 'SELECT DISTINCT(obj_id) FROM booking_entry be ' .
305  'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
306  'WHERE ' . $ilDB->in('obj_id', $a_obj_ids, false, 'integer') . ' ' .
307  'AND bo.target_obj_id = ' . $ilDB->quote($a_target_obj_id, 'integer');
308  } else {
309  $query = 'SELECT DISTINCT(obj_id) FROM booking_entry be ' .
310  'WHERE ' . $ilDB->in('obj_id', $a_obj_ids, false, 'integer') . ' ';
311  }
312 
313  $res = $ilDB->query($query);
314  $all = [];
315  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
316  $all[] = (int) $row->obj_id;
317  }
318  return $all;
319  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:25
+ 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 556 of file class.ilBookingEntry.php.

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

556  : bool
557  {
558  if ($this->getNumberOfBookings() == $this->getCurrentNumberOfBookings($a_entry_id)) {
559  // check against current user
560  if ($a_check_current_user) {
561  if ($this->hasBooked($a_entry_id)) {
562  return false;
563  }
564  if ($this->user->getId() == $this->getObjId()) {
565  return false;
566  }
567  }
568  return true;
569  }
570 
571  $deadline = $this->getDeadlineHours();
572  if ($deadline) {
573  $entry = new ilCalendarEntry($a_entry_id);
574  if (time() + ($deadline * 60 * 60) > $entry->getStart()->get(IL_CAL_UNIX)) {
575  return true;
576  }
577  }
578  return false;
579  }
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 238 of file class.ilBookingEntry.php.

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

238  : bool
239  {
240  if (!$a_user_id) {
241  $a_user_id = $this->user->getId();
242  }
243  if ($this->getObjId() == $a_user_id) {
244  return true;
245  }
246  return false;
247  }
+ 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 138 of file class.ilBookingEntry.php.

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

138  : bool
139  {
140  // no course/group filter
141  if (!$this->getTargetObjIds()) {
142  return true;
143  }
144 
145  $obj_id = ilObject::_lookupObjId($a_ref_id);
146  return in_array($obj_id, $this->getTargetObjIds());
147  }
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 329 of file class.ilBookingEntry.php.

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

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

329  : array
330  {
331  global $DIC;
332 
333  $ilDB = $DIC->database();
334  $query = 'SELECT be.obj_id bobj FROM booking_entry be ' .
335  'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
336  'JOIN cal_entries ce on be.booking_id = ce.context_id ' .
337  'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
338  'JOIN cal_categories cc on cca.cat_id = cc.cat_id ' .
339  'WHERE ' . $ilDB->in('be.obj_id', $a_user_ids, false, 'integer') . ' ' .
340  'AND ' . $ilDB->in('bo.target_obj_id', $a_obj_id, false, 'integer') . ' ' .
341  'AND cc.obj_id = be.obj_id ' .
342  'AND cc.type = ' . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ';
343 
344  $res = $ilDB->query($query);
345 
346  $objs = [];
347  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
348  if (!in_array($row->bobj, $objs)) {
349  $objs[] = (int) $row->bobj;
350  }
351  }
352 
353  // non filtered booking entries
354  $query = 'SELECT be.obj_id bobj FROM booking_entry be ' .
355  'LEFT JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
356  'JOIN cal_entries ce on be.booking_id = ce.context_id ' .
357  'JOIN cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
358  'JOIN cal_categories cc on cca.cat_id = cc.cat_id ' .
359  'WHERE bo.booking_id IS NULL ' .
360  'AND ' . $ilDB->in('be.obj_id', $a_user_ids, false, 'integer') . ' ' .
361  'AND cc.obj_id = be.obj_id ' .
362  'AND cc.type = ' . $ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer') . ' ';
363 
364  $res = $ilDB->query($query);
365  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
366  if (!in_array($row->bobj, $objs)) {
367  $objs[] = (int) $row->bobj;
368  }
369  }
370  return $objs;
371  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:25
+ 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 399 of file class.ilBookingEntry.php.

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

Referenced by ilAppointmentPresentationConsultationHoursGUI\collectPropertiesAndActions(), ilConsultationHourBookingTableGUI\parse(), ILIAS\Calendar\ConsultationHours\BookingDataProvider\read(), and ilCalendarMailNotification\send().

399  : string
400  {
401  global $DIC;
402 
403  $ilDB = $DIC->database();
404 
405  $query = 'SELECT * from booking_user ' .
406  'WHERE entry_id = ' . $ilDB->quote($a_entry_id, 'integer') . ' ' .
407  'AND user_id = ' . $ilDB->quote($a_usr_id, 'integer');
408  $res = $ilDB->query($query);
409  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
410  return (string) $row->booking_message;
411  }
412  return '';
413  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:25
+ 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 466 of file class.ilBookingEntry.php.

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

Referenced by ilConsultationHourBookingTableGUI\parse().

466  : array
467  {
468  global $DIC;
469 
470  $ilDB = $DIC->database();
471  $query = 'SELECT user_id FROM booking_user ' .
472  'WHERE entry_id = ' . $ilDB->quote($a_app_id, 'integer');
473  $res = $ilDB->query($query);
474  $users = [];
475  while ($row = $ilDB->fetchObject($res)) {
476  $users[] = (int) $row->user_id;
477  }
478  return $users;
479  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:25
+ 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 487 of file class.ilBookingEntry.php.

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

487  : array
488  {
489  global $DIC;
490 
491  $ilDB = $DIC->database();
492  $query = 'SELECT bu.user_id, starta, enda FROM booking_user bu ' .
493  'JOIN cal_entries ca ON entry_id = ca.cal_id ' .
494  'JOIN booking_entry be ON context_id = booking_id ' .
495  'JOIN booking_obj_assignment bo ON be.booking_id = bo.booking_id ' .
496  'WHERE bo.target_obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
497  'AND be.obj_id = ' . $ilDB->quote($a_usr_id, ilDBConstants::T_INTEGER) . ' ' .
498  'ORDER BY starta';
499  $res = $ilDB->query($query);
500 
501  $bookings = array();
502  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
503  $dt = new ilDateTime($row->starta, IL_CAL_DATETIME, ilTimeZone::UTC);
504  $dt_end = new ilDateTime($row->enda, IL_CAL_DATETIME, ilTimeZone::UTC);
505  $bookings[(int) $row->user_id][] = [
506  'dt' => $dt->get(IL_CAL_UNIX),
507  'dtend' => $dt_end->get(IL_CAL_UNIX),
508  'owner' => $a_usr_id
509  ];
510  }
511  return $bookings;
512  }
$res
Definition: ltiservices.php:69
const IL_CAL_DATETIME
const IL_CAL_UNIX
global $DIC
Definition: shib_login.php:25
+ 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 60 of file class.ilBookingEntry.php.

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

Referenced by ilConsultationHoursGUI\assignUsersToAppointment().

60  : array
61  {
62  global $DIC;
63 
64  $ilDB = $DIC->database();
65  $query = 'SELECT entry_id FROM booking_user ' .
66  'WHERE ' . $ilDB->in('entry_id', $a_app_ids, false, 'integer') . ' ' .
67  'AND user_id = ' . $ilDB->quote($a_usr_id, 'integer');
68 
69  $res = $ilDB->query($query);
70 
71  $booked_entries = array();
72  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
73  $booked_entries[] = (int) $row->entry_id;
74  }
75  return $booked_entries;
76  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:25
+ 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 518 of file class.ilBookingEntry.php.

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

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

518  : array
519  {
520  $bookings = self::lookupBookingsForObject($a_obj_id, $a_usr_id);
521  foreach (ilConsultationHourUtils::lookupManagedUsers($a_usr_id) as $managed_user_id) {
522  foreach (self::lookupBookingsForObject($a_obj_id, $managed_user_id) as $booked_user => $booking) {
523  $fullname = ilObjUser::_lookupFullname($managed_user_id);
524  foreach ($booking as $booking_entry) {
525  $booking_entry['explanation'] = '(' . $fullname . ')';
526  $bookings[$booked_user][] = $booking_entry;
527  }
528  }
529  }
530  return $bookings;
531  }
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 209 of file class.ilBookingEntry.php.

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

Referenced by __construct().

209  : void
210  {
211  if (!$this->getId()) {
212  return;
213  }
214 
215  $query = "SELECT * FROM booking_entry " .
216  "WHERE booking_id = " . $this->db->quote($this->getId(), 'integer');
217  $res = $this->db->query($query);
218  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
219  $this->setObjId((int) $row['obj_id']);
220  $this->setDeadlineHours((int) $row['deadline']);
221  $this->setNumberOfBookings((int) $row['num_bookings']);
222  }
223 
224  $query = 'SELECT * FROM booking_obj_assignment ' .
225  'WHERE booking_id = ' . $this->db->quote($this->getId(), 'integer');
226  $res = $this->db->query($query);
227  $this->target_obj_ids = array();
228  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
229  $this->target_obj_ids[] = (int) $row->target_obj_id;
230  }
231  }
$res
Definition: ltiservices.php:69
setDeadlineHours(int $a_hours)
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 252 of file class.ilBookingEntry.php.

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

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

252  : void
253  {
254  global $DIC;
255 
256  $ilDB = $DIC->database();
257  $set = $ilDB->query('SELECT DISTINCT(context_id) FROM cal_entries e' .
258  ' JOIN cal_cat_assignments a ON (e.cal_id = a.cal_id)' .
259  ' JOIN cal_categories c ON (a.cat_id = c.cat_id) WHERE c.type = ' . $ilDB->quote(
261  'integer'
262  ));
263 
264  $used = array();
265  while ($row = $ilDB->fetchAssoc($set)) {
266  $used[] = $row['context_id'];
267  }
268  $ilDB->query($q = 'DELETE FROM booking_entry WHERE ' . $ilDB->in('booking_id', $used, true, 'integer'));
269  $ilDB->query($q = 'DELETE FROM booking_obj_assignment WHERE ' . $ilDB->in(
270  'booking_id',
271  $used,
272  true,
273  'integer'
274  ));
275  }
global $DIC
Definition: shib_login.php:25
$q
Definition: shib_logout.php:18
+ Here is the caller graph for this function:

◆ save()

ilBookingEntry::save ( )

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

References getDeadlineHours(), getId(), getNumberOfBookings(), getObjId(), and setId().

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

149  : void
150  {
151  $this->setId($this->db->nextId('booking_entry'));
152  $query = 'INSERT INTO booking_entry (booking_id,obj_id,deadline,num_bookings) ' .
153  "VALUES ( " .
154  $this->db->quote($this->getId(), 'integer') . ', ' .
155  $this->db->quote($this->getObjId(), 'integer') . ', ' .
156  $this->db->quote($this->getDeadlineHours(), 'integer') . ', ' .
157  $this->db->quote($this->getNumberOfBookings(), 'integer') . ' ' .
158  ") ";
159  $this->db->manipulate($query);
160 
161  foreach ((array) $this->target_obj_ids as $obj_id) {
162  $query = 'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
163  'VALUES( ' .
164  $this->db->quote($this->getId(), 'integer') . ', ' .
165  $this->db->quote($obj_id, 'integer') . ' ' .
166  ')';
167  $this->db->manipulate($query);
168  }
169  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDeadlineHours()

ilBookingEntry::setDeadlineHours ( int  $a_hours)

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

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

99  : void
100  {
101  $this->deadline = $a_hours;
102  }
+ Here is the caller graph for this function:

◆ setId()

ilBookingEntry::setId ( int  $a_id)
protected

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

Referenced by __construct(), and save().

78  : void
79  {
80  $this->id = $a_id;
81  }
+ Here is the caller graph for this function:

◆ setNumberOfBookings()

ilBookingEntry::setNumberOfBookings ( int  $a_num)

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

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

109  : void
110  {
111  $this->num_bookings = $a_num;
112  }
+ Here is the caller graph for this function:

◆ setObjId()

ilBookingEntry::setObjId ( int  $a_id)

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

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

89  : void
90  {
91  $this->obj_id = $a_id;
92  }
+ Here is the caller graph for this function:

◆ setTargetObjIds()

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

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

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

122  : void
123  {
124  $this->target_obj_ids = $a_obj_id;
125  }
+ Here is the caller graph for this function:

◆ update()

ilBookingEntry::update ( )

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

References getDeadlineHours(), getId(), getNumberOfBookings(), and getObjId().

171  : void
172  {
173  if (!$this->getId()) {
174  return;
175  }
176 
177  $query = "UPDATE booking_entry SET " .
178  " obj_id = " . $this->db->quote($this->getObjId(), 'integer') . ", " .
179  " deadline = " . $this->db->quote($this->getDeadlineHours(), 'integer') . ", " .
180  " num_bookings = " . $this->db->quote($this->getNumberOfBookings(), 'integer') . ' ' .
181  'WHERE booking_id = ' . $this->db->quote($this->getId(), 'integer');
182  $this->db->manipulate($query);
183 
184  // obj assignments
185  $query = 'DELETE FROM booking_obj_assignment ' .
186  'WHERE booking_id = ' . $this->db->quote($this->getId(), 'integer');
187  $this->db->manipulate($query);
188 
189  foreach ((array) $this->target_obj_ids as $obj_id) {
190  $query = 'INSERT INTO booking_obj_assignment (booking_id, target_obj_id) ' .
191  'VALUES( ' .
192  $this->db->quote($this->getId(), 'integer') . ', ' .
193  $this->db->quote($obj_id, 'integer') . ' ' .
194  ')';
195  $this->db->manipulate($query);
196  }
197  }
+ 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 418 of file class.ilBookingEntry.php.

References $DIC, and $ilDB.

Referenced by ilConsultationHourUtils\bookAppointment().

418  : void
419  {
420  global $DIC;
421 
422  $ilDB = $DIC->database();
423  $query = 'UPDATE booking_user SET ' .
424  'booking_message = ' . $ilDB->quote($a_message, 'text') . ' ' .
425  'WHERE entry_id = ' . $ilDB->quote($a_entry_id, 'integer') . ' ' .
426  'AND user_id = ' . $ilDB->quote($a_usr_id, 'integer');
427 
428  $ilDB->manipulate($query);
429  }
global $DIC
Definition: shib_login.php:25
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ilBookingEntry::$db
protected

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

◆ $deadline

int ilBookingEntry::$deadline = 0
private

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

Referenced by getDeadlineHours().

◆ $id

int ilBookingEntry::$id = 0
private

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

Referenced by getId().

◆ $num_bookings

int ilBookingEntry::$num_bookings = 1
private

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

Referenced by getNumberOfBookings().

◆ $obj_id

int ilBookingEntry::$obj_id = 0
private

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

Referenced by getObjId().

◆ $target_obj_ids

array ilBookingEntry::$target_obj_ids = []
private

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

Referenced by getTargetObjIds().

◆ $user

ilObjUser ilBookingEntry::$user
protected

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


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