ILIAS  release_7 Revision v7.30-3-g800a261c036
ilConsultationHourUtils Class Reference

Description of class. More...

+ Collaboration diagram for ilConsultationHourUtils:

Static Public Member Functions

static getConsultationHourLinksForRepositoryObject (int $ref_id, int $current_user_id, array $ctrl_class_structure)
 
static findCalendarAppointmentsForBooking (\ilBookingEntry $booking, \ilDateTime $start, \ilDateTime $end)
 
static bookAppointment ($a_usr_id, $a_app_id)
 Book an appointment. More...
 
static cancelBooking ($a_usr_id, $a_app_id, $a_send_notification=true)
 Cancel a booking. More...
 
static lookupManagedUsers ($a_usr_id)
 Lookup managed users. More...
 

Detailed Description

Description of class.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 10 of file class.ilConsultationHourUtils.php.

Member Function Documentation

◆ bookAppointment()

static ilConsultationHourUtils::bookAppointment (   $a_usr_id,
  $a_app_id 
)
static

Book an appointment.

All checks (assignment possible, max booking) must be done before

Parameters
type$a_usr_id
type$a_app_id
Returns
bool

Definition at line 108 of file class.ilConsultationHourUtils.php.

References $app, $DIC, $lng, ilLanguageFactory\_getLanguage(), ilCalendarCategoryAssignments\addAssignment(), ilBookingEntry\book(), ilCalendarUtil\initDefaultCalendarByType(), and ilCalendarCategory\TYPE_CH.

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

109  {
110  global $DIC;
111 
112  $lng = $DIC['lng'];
113 
114  // Create new default consultation hour calendar
115  include_once './Services/Language/classes/class.ilLanguageFactory.php';
116  $cal_lang = ilLanguageFactory::_getLanguage($lng->getDefaultLanguage());
117  $cal_lang->loadLanguageModule('dateplaner');
118 
119  include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
120  include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
123  $a_usr_id,
124  $cal_lang->txt('cal_ch_personal_ch'),
125  true
126  );
127 
128  // duplicate appointment
129  include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
130  $app = new ilCalendarEntry($a_app_id);
131  $personal_app = clone $app;
132  $personal_app->save();
133 
134  // assign appointment to category
135  include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
136  $assignment = new ilCalendarCategoryAssignments($personal_app->getEntryId());
137  $assignment->addAssignment($ch->getCategoryID());
138 
139  // book appointment
140  include_once './Services/Booking/classes/class.ilBookingEntry.php';
141  $booking = new ilBookingEntry($app->getContextId());
142  $booking->book($app->getEntryId(), $a_usr_id);
143  return true;
144  }
$app
Definition: cli.php:38
Model for a calendar entry.
Booking definition.
static _getLanguage($a_lang_key='')
Get langauge object.
$lng
global $DIC
Definition: goto.php:24
book($a_entry_id, $a_user_id=false)
book calendar entry for user
static initDefaultCalendarByType($a_type_id, $a_usr_id, $a_title, $a_create=false)
Init the default calendar for given type and user.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cancelBooking()

static ilConsultationHourUtils::cancelBooking (   $a_usr_id,
  $a_app_id,
  $a_send_notification = true 
)
static

Cancel a booking.

Parameters
type$a_usr_id
type$a_app_id
Returns
bool

Definition at line 152 of file class.ilConsultationHourUtils.php.

References $app, ilCalendarCategoryAssignments\_deleteByAppointmentId(), ilBookingEntry\cancelBooking(), ilConsultationHourAppointments\getAppointmentIds(), and ilCalendarCategory\TYPE_CH.

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

153  {
154  // Delete personal copy of appointment
155  include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
156  $app = new ilCalendarEntry($a_app_id);
157 
158  include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
160  $a_usr_id,
161  $app->getContextId(),
162  $app->getStart(),
164  false
165  );
166  foreach ($user_apps as $uapp_id) {
167  $uapp = new ilCalendarEntry($uapp_id);
168  $uapp->delete();
169 
170  include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
172 
173  break;
174  }
175 
176  // Delete booking entries
177  // Send notification
178  $booking = new ilBookingEntry($app->getContextId());
179  if ($a_send_notification) {
180  $booking->cancelBooking($a_app_id, $a_usr_id);
181  } else {
182  $booking->deleteBooking($a_app_id, $a_usr_id);
183  }
184  return true;
185  }
$app
Definition: cli.php:38
Model for a calendar entry.
static getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.
Booking definition.
cancelBooking($a_entry_id, $a_user_id=false)
cancel calendar booking for user
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findCalendarAppointmentsForBooking()

static ilConsultationHourUtils::findCalendarAppointmentsForBooking ( \ilBookingEntry  $booking,
\ilDateTime  $start,
\ilDateTime  $end 
)
static
Parameters
ilBookingEntry$booking
ilDateTime$start
ilDateTime$end
Returns
int[]
Exceptions
ilDatabaseException

Definition at line 79 of file class.ilConsultationHourUtils.php.

References $DIC, $query, $res, ilDBConstants\FETCHMODE_OBJECT, ilDateTime\get(), ilBookingEntry\getId(), IL_CAL_DATETIME, ilDBConstants\T_TIMESTAMP, ilCalendarCategory\TYPE_CH, and ilTimeZone\UTC.

Referenced by ilConsultationHoursGUI\rewriteBookingIdsForAppointments().

80  {
81  global $DIC;
82 
83  $db = $DIC->database();
84 
85  $query = 'select ce.cal_id from cal_entries ce ' .
86  'join cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
87  'join cal_categories cc on cca.cat_id = cc.cat_id ' .
88  'where context_id = ' . $db->quote($booking->getId(), 'integer') . ' ' .
89  'and starta = ' . $db->quote($start->get(IL_CAL_DATETIME, '', \ilTimeZone::UTC), \ilDBConstants::T_TIMESTAMP) . ' ' .
90  'and enda = ' . $db->quote($end->get(IL_CAL_DATETIME, '', \ilTimeZone::UTC), \ilDBConstants::T_TIMESTAMP) . ' ' .
91  'and type = ' . $db->quote(\ilCalendarCategory::TYPE_CH, 'integer');
92  $res = $db->query($query);
93 
94  $calendar_apppointments = [];
95  while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
96  $calendar_apppointments[] = $row->cal_id;
97  }
98  return $calendar_apppointments;
99  }
const IL_CAL_DATETIME
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getConsultationHourLinksForRepositoryObject()

static ilConsultationHourUtils::getConsultationHourLinksForRepositoryObject ( int  $ref_id,
int  $current_user_id,
array  $ctrl_class_structure 
)
static

Definition at line 12 of file class.ilConsultationHourUtils.php.

References $DIC, $lng, ilDateTime\_before(), ilCalendarCategoryAssignments\_lookupCategories(), ilObjUser\_lookupFullname(), ilObject\_lookupObjId(), ilConsultationHourAppointments\getAppointments(), ilParticipants\getInstance(), IL_CAL_DATE, IL_CAL_DAY, IL_CAL_UNIX, and ilBookingEntry\lookupBookableUsersForObject().

Referenced by ilConsultationHoursCalendarBlockGUI\getData().

13  {
14  global $DIC;
15 
16  $ctrl = $DIC->ctrl();
17  $lng = $DIC->language();
18  $logger = $DIC->logger()->cal();
19 
20  $obj_id = \ilObject::_lookupObjId($ref_id);
21  $participants = \ilParticipants::getInstance($ref_id);
22  $candidates = array_unique(array_merge(
23  $participants->getAdmins(),
24  $participants->getTutors()
25  ));
26  $users = \ilBookingEntry::lookupBookableUsersForObject($obj_id, $candidates);
27  $now = new \ilDateTime(time(), IL_CAL_UNIX);
28  $links = [];
29  foreach ($users as $user_id) {
30  $next_entry = null;
31  $appointments = \ilConsultationHourAppointments::getAppointments($user_id);
32  $category_id = 0;
33  foreach ($appointments as $entry) {
34  // find next entry
35  if (ilDateTime::_before($entry->getStart(), $now, IL_CAL_DAY)) {
36  continue;
37  }
38  $category_id = ilCalendarCategoryAssignments::_lookupCategories($entry->getEntryId())[0] ?? 0;
39  $booking_entry = new ilBookingEntry($entry->getContextId());
40  if (!in_array($obj_id, $booking_entry->getTargetObjIds())) {
41  continue;
42  }
43  if (!$booking_entry->isAppointmentBookableForUser($entry->getEntryId(), $current_user_id)) {
44  continue;
45  }
46  $next_entry = $entry;
47  break;
48  }
49 
50  $ctrl->setParameterByClass(end($ctrl_class_structure), 'ch_user_id', $user_id);
51  if ( $category_id > 0) {
52  $ctrl->setParameterByClass(end($ctrl_class_structure), 'category_id', $category_id);
53  }
54  if ($next_entry instanceof \ilCalendarEntry) {
55  $ctrl->setParameterByClass(end($ctrl_class_structure), 'seed', $next_entry->getStart()->get(IL_CAL_DATE));
56  }
57  $current_link = [
58  'link' => $ctrl->getLinkTargetByClass($ctrl_class_structure, 'selectCHCalendarOfUser'),
59  'txt' => ilObjUser::_lookupFullname($user_id)
60  ];
61  $links[] = $current_link;
62  }
63  // Reset control structure links
64  $ctrl->setParameterByClass(end($ctrl_class_structure), 'seed', '');
65  $ctrl->setParameterByClass(end($ctrl_class_structure), 'ch_user_id', '');
66  $ctrl->setParameterByClass(end($ctrl_class_structure), 'category_id', '');
67  return $links;
68  }
Model for a calendar entry.
static _lookupFullname($a_user_id)
Lookup Full Name.
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.
Booking definition.
static _lookupCategories($a_cal_id)
lookup categories
const IL_CAL_UNIX
static getInstance($a_ref_id)
Get instance by ref_id.
const IL_CAL_DAY
static lookupBookableUsersForObject($a_obj_id, $a_user_ids)
Consultation hours are offered if 1) consultation hour owner is admin or tutor and no object assignme...
$lng
static getAppointments($a_user_id)
Get all appointments.
static _lookupObjId($a_id)
global $DIC
Definition: goto.php:24
const IL_CAL_DATE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupManagedUsers()

static ilConsultationHourUtils::lookupManagedUsers (   $a_usr_id)
static

Lookup managed users.

Parameters
type$a_usr_id

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

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

Referenced by ilBookingEntry\lookupManagedBookingsForObject().

192  {
193  global $DIC;
194 
195  $ilDB = $DIC['ilDB'];
196 
197  $query = 'SELECT user_id FROM cal_ch_settings ' .
198  'WHERE admin_id = ' . $ilDB->quote($a_usr_id, 'integer');
199  $res = $ilDB->query($query);
200 
201  $users = array();
202  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
203  $users[] = $row->user_id;
204  }
205  return $users;
206  }
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
$query
global $ilDB
+ Here is the caller graph for this function:

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