ILIAS  release_8 Revision v8.24
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)
 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 
)
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);
164 return true;
165 }
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...
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 _getLanguage(string $a_lang_key='')
Get language object.
$app
Definition: cli.php:39
global $DIC
Definition: feed.php:28
$lng

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

Referenced by ilConsultationHoursGUI\assignUsersToAppointment(), ilConsultationHoursGUI\assignUsersToGroup(), 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 170 of file class.ilConsultationHourUtils.php.

170 : bool
171 {
172 // Delete personal copy of appointment
173 $app = new ilCalendarEntry($a_app_id);
174
176 $a_usr_id,
177 $app->getContextId(),
178 $app->getStart(),
180 false
181 );
182 foreach ($user_apps as $uapp_id) {
183 $uapp = new ilCalendarEntry($uapp_id);
184 $uapp->delete();
185
187
188 break;
189 }
190
191 // Delete booking entries
192 // Send notification
193 $booking = new ilBookingEntry($app->getContextId());
194 if ($a_send_notification) {
195 $booking->cancelBooking($a_app_id, $a_usr_id);
196 } else {
197 $booking->deleteBooking($a_app_id, $a_usr_id);
198 }
199 return true;
200 }
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 $app, ilCalendarCategoryAssignments\_deleteByAppointmentId(), ilBookingEntry\cancelBooking(), ilBookingEntry\deleteBooking(), ilConsultationHourAppointments\getAppointmentIds(), and ilCalendarCategory\TYPE_CH.

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

+ 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
$query

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'),
84 'txt' => ilObjUser::_lookupFullname($user_id)
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:67

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

206 : array
207 {
208 global $DIC;
209
210 $ilDB = $DIC->database();
211 $query = 'SELECT user_id FROM cal_ch_settings ' .
212 'WHERE admin_id = ' . $ilDB->quote($a_usr_id, 'integer');
213 $res = $ilDB->query($query);
214
215 $users = array();
216 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
217 $users[] = (int) $row->user_id;
218 }
219 return $users;
220 }

References $DIC, $ilDB, $query, $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: