ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilConsultationHourUtils Class Reference
+ 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 (int $a_usr_id, int $a_app_id, string $comment='')
 Book an appointment. More...
 
static cancelBooking (int $a_usr_id, int $a_app_id, bool $a_send_notification=true)
 Cancel a booking. More...
 
static lookupManagedUsers ($a_usr_id)
 Lookup managed users. More...
 

Detailed Description

Member Function Documentation

◆ bookAppointment()

static ilConsultationHourUtils::bookAppointment ( int  $a_usr_id,
int  $a_app_id,
string  $comment = '' 
)
static

Book an appointment.

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

Parameters
int$a_usr_id
int$a_app_id
Returns
bool

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

135 : bool
136 {
137 global $DIC;
138
139 $lng = $DIC->language();
140
141 // Create new default consultation hour calendar
142 $cal_lang = ilLanguageFactory::_getLanguage($lng->getDefaultLanguage());
143 $cal_lang->loadLanguageModule('dateplaner');
144
147 $a_usr_id,
148 $cal_lang->txt('cal_ch_personal_ch'),
149 true
150 );
151
152 // duplicate appointment
153 $app = new ilCalendarEntry($a_app_id);
154 $personal_app = clone $app;
155 $personal_app->save();
156
157 // assign appointment to category
158 $assignment = new ilCalendarCategoryAssignments($personal_app->getEntryId());
159 $assignment->addAssignment($ch->getCategoryID());
160
161 // book appointment
162 $booking = new ilBookingEntry($app->getContextId());
163 $booking->book($app->getEntryId(), $a_usr_id);
165 $app->getEntryId(),
166 $a_usr_id,
168 );
169
170 $mail = new ilCalendarMailNotification();
171 $mail->setAppointmentId($app->getEntryId());
172 $mail->setRecipients([$a_usr_id]);
174 $mail->send();
175
176 $recipients = [$booking->getObjId()];
177 $mail = new ilCalendarMailNotification();
178 $mail->setAppointmentId($app->getEntryId());
179 $mail->setBookerID($a_usr_id);
180 $mail->setRecipients($recipients);
182 $mail->send();
183
185 false,
186 false,
187 $booking->getObjId()
188 );
189 if ($manager > 0) {
190 $recipients = [$manager];
191 $mail = new ilCalendarMailNotification();
192 $mail->setAppointmentId($app->getEntryId());
193 $mail->setBookerID($a_usr_id);
194 $mail->setRecipients($recipients);
196 $mail->send();
197 }
198 return true;
199 }
$comment
Definition: buildRTE.php:72
Booking definition.
static writeBookingMessage(int $a_entry_id, int $a_usr_id, string $a_message)
Write booking message.
Model for a calendar entry.
Distributes calendar mail notifications.
static initDefaultCalendarByType(int $a_type_id, int $a_usr_id, string $a_title, bool $a_create=false)
Init the default calendar for given type and user.
static getManager(bool $a_as_name=false, bool $a_full_name=false, ?int $a_user_id=null)
Get consultation hour manager for current user or specific user.
static _getLanguage(string $a_lang_key='')
Get language object.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26

References $comment, $DIC, $lng, ilLanguageFactory\_getLanguage(), ilBookingEntry\book(), ilConsultationHourAppointments\getManager(), ilBookingEntry\getObjId(), ilCalendarUtil\initDefaultCalendarByType(), ilCalendarMailNotification\TYPE_BOOKING_CONFIRMATION, ilCalendarMailNotification\TYPE_BOOKING_CONFIRMATION_MANAGER, ilCalendarCategory\TYPE_CH, and ilBookingEntry\writeBookingMessage().

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

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

◆ cancelBooking()

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

Cancel a booking.

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

204 : bool
205 {
206 // Delete personal copy of appointment
207 $app = new ilCalendarEntry($a_app_id);
208
210 $a_usr_id,
211 $app->getContextId(),
212 $app->getStart(),
214 false
215 );
216
217 // Delete booking entries
218 // Send notification
219 $booking = new ilBookingEntry($app->getContextId());
220 if ($a_send_notification) {
221 $booking->cancelBooking($a_app_id, $a_usr_id);
222 } else {
223 $booking->deleteBooking($a_app_id, $a_usr_id);
224 }
225
226 foreach ($user_apps as $uapp_id) {
227 $uapp = new ilCalendarEntry($uapp_id);
228 $uapp->delete();
229
231
232 break;
233 }
234
235 return true;
236 }
static _deleteByAppointmentId(int $a_app_id)
Delete appointment assignment.
static getAppointmentIds(int $a_user_id, ?int $a_context_id=null, ?ilDateTime $a_start=null, ?int $a_type=null, bool $a_check_owner=true)

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

Referenced by ilConsultationHoursGUI\cancelBooking(), ilCalendarAppointmentGUI\cancelConfirmed(), and ilConsultationHoursGUI\deleteAppointments().

+ 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
Returns
int[]

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

102 : array {
103 global $DIC;
104
105 $db = $DIC->database();
106
107 $query = 'select ce.cal_id from cal_entries ce ' .
108 'join cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
109 'join cal_categories cc on cca.cat_id = cc.cat_id ' .
110 'where context_id = ' . $db->quote($booking->getId(), 'integer') . ' ' .
111 'and starta = ' . $db->quote(
112 $start->get(IL_CAL_DATETIME, '', \ilTimeZone::UTC),
114 ) . ' ' .
115 'and enda = ' . $db->quote(
118 ) . ' ' .
119 'and type = ' . $db->quote(\ilCalendarCategory::TYPE_CH, 'integer');
120 $res = $db->query($query);
121
122 $calendar_apppointments = [];
123 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
124 $calendar_apppointments[] = (int) $row->cal_id;
125 }
126 return $calendar_apppointments;
127 }
const IL_CAL_DATETIME
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
$res
Definition: ltiservices.php:69

References ILIAS\Repository\int().

Referenced by ilConsultationHoursGUI\rewriteBookingIdsForAppointments().

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

30 : array {
31 global $DIC;
32
33 $ctrl = $DIC->ctrl();
34 $logger = $DIC->logger()->cal();
35 $ctrl->setParameterByClass(end($ctrl_class_structure), 'seed', '');
36 $ctrl->setParameterByClass(end($ctrl_class_structure), 'category_id', '');
37
40 $candidates = array_unique(array_merge(
41 $participants->getAdmins(),
42 $participants->getTutors()
43 ));
44 $users = \ilBookingEntry::lookupBookableUsersForObject([$obj_id], $candidates);
45 $now = new \ilDateTime(time(), IL_CAL_UNIX);
46 $links = [];
47 foreach ($users as $user_id) {
48 $next_entry = null;
50 $category_id = 0;
51 foreach ($appointments as $entry) {
52 // find next entry
53 if (ilDateTime::_before($entry->getStart(), $now, IL_CAL_DAY)) {
54 continue;
55 }
56 $category_id = ilCalendarCategoryAssignments::_lookupCategories($entry->getEntryId())[0] ?? 0;
57 $booking_entry = new ilBookingEntry($entry->getContextId());
58 if (count($booking_entry->getTargetObjIds()) > 0 && !in_array($obj_id, $booking_entry->getTargetObjIds())) {
59 continue;
60 }
61 if (!$booking_entry->isAppointmentBookableForUser($entry->getEntryId(), $current_user_id)) {
62 continue;
63 }
64 $next_entry = $entry;
65 break;
66 }
67
68 $ctrl->setParameterByClass(end($ctrl_class_structure), 'ch_user_id', $user_id);
69 if ($category_id > 0) {
70 $ctrl->setParameterByClass(end($ctrl_class_structure), 'category_id', $category_id);
71 }
72 if ($next_entry instanceof \ilCalendarEntry) {
73 $arr = explode("-", $next_entry->getStart()->get(IL_CAL_DATE));
74 $arr[2] = "01";
75 $seed = implode("-", $arr);
76 $ctrl->setParameterByClass(
77 end($ctrl_class_structure),
78 'seed',
79 $seed
80 );
81 }
82 $current_link = [
83 'link' => $ctrl->getLinkTargetByClass($ctrl_class_structure, 'selectCHCalendarOfUser'),
85 ];
86 $links[] = $current_link;
87 }
88 // Reset control structure links
89 $ctrl->setParameterByClass(end($ctrl_class_structure), 'seed', '');
90 $ctrl->setParameterByClass(end($ctrl_class_structure), 'ch_user_id', '');
91 $ctrl->setParameterByClass(end($ctrl_class_structure), 'category_id', '');
92 return $links;
93 }
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DAY
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 assignme...
static getAppointments(int $a_user_id)
Get all appointments.
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.
static _lookupFullname(int $a_user_id)
static _lookupObjId(int $ref_id)
static getInstance(int $a_ref_id)
$ref_id
Definition: ltiauth.php:66

Referenced by ilConsultationHoursCalendarBlockGUI\getData().

+ Here is the caller graph for this function:

◆ lookupManagedUsers()

static ilConsultationHourUtils::lookupManagedUsers (   $a_usr_id)
static

Lookup managed users.

Returns
int[]

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

242 : array
243 {
244 global $DIC;
245
246 $ilDB = $DIC->database();
247 $query = 'SELECT user_id FROM cal_ch_settings ' .
248 'WHERE admin_id = ' . $ilDB->quote($a_usr_id, 'integer');
249 $res = $ilDB->query($query);
250
251 $users = array();
252 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
253 $users[] = (int) $row->user_id;
254 }
255 return $users;
256 }

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

Referenced by ilBookingEntry\lookupManagedBookingsForObject().

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

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