ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 103 of file class.ilConsultationHourUtils.php.

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

References $app, $DIC, $lng, ilLanguageFactory\_getLanguage(), 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 (   $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 147 of file class.ilConsultationHourUtils.php.

148 {
149 // Delete personal copy of appointment
150 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
151 $app = new ilCalendarEntry($a_app_id);
152
153 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
155 $a_usr_id,
156 $app->getContextId(),
157 $app->getStart(),
159 false
160 );
161 foreach ($user_apps as $uapp_id) {
162 $uapp = new ilCalendarEntry($uapp_id);
163 $uapp->delete();
164
165 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
167
168 break;
169 }
170
171 // Delete booking entries
172 // Send notification
173 $booking = new ilBookingEntry($app->getContextId());
174 if ($a_send_notification) {
175 $booking->cancelBooking($a_app_id, $a_usr_id);
176 } else {
177 $booking->deleteBooking($a_app_id, $a_usr_id);
178 }
179 return true;
180 }
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
static getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.

References $app, ilCalendarCategoryAssignments\_deleteByAppointmentId(), 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
Parameters
ilBookingEntry$booking
ilDateTime$start
ilDateTime$end
Returns
int[]
Exceptions
ilDatabaseException

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

75 {
76 global $DIC;
77
78 $db = $DIC->database();
79
80 $query = 'select ce.cal_id from cal_entries ce ' .
81 'join cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
82 'join cal_categories cc on cca.cat_id = cc.cat_id '.
83 'where context_id = ' . $db->quote($booking->getId(), 'integer') . ' ' .
84 'and starta = ' . $db->quote($start->get(IL_CAL_DATETIME, '', \ilTimeZone::UTC), \ilDBConstants::T_TIMESTAMP) . ' ' .
85 'and enda = ' . $db->quote($end->get(IL_CAL_DATETIME, '', \ilTimeZone::UTC), \ilDBConstants::T_TIMESTAMP) . ' ' .
86 'and type = ' . $db->quote(\ilCalendarCategory::TYPE_CH, 'integer');
87 $res = $db->query($query);
88
89 $calendar_apppointments = [];
90 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
91 $calendar_apppointments[] = $row->cal_id;
92 }
93 return $calendar_apppointments;
94 }
const IL_CAL_DATETIME
$query
foreach($_POST as $key=> $value) $res

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().

+ 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.

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
31 $next_entry = null;
33 foreach ($appointments as $entry) {
34 // find next entry
35 if (ilDateTime::_before($entry->getStart(), $now, IL_CAL_DAY)) {
36 continue;
37 }
38 $booking_entry = new ilBookingEntry($entry->getContextId());
39 if (!in_array($obj_id, $booking_entry->getTargetObjIds())) {
40 continue;
41 }
42 if (!$booking_entry->isAppointmentBookableForUser($entry->getEntryId(), $current_user_id)) {
43 continue;
44 }
45 $next_entry = $entry;
46 break;
47 }
48
49 $ctrl->setParameterByClass(end($ctrl_class_structure), 'ch_user_id', $user_id);
50 if ($next_entry instanceof \ilCalendarEntry) {
51 $ctrl->setParameterByClass(end($ctrl_class_structure), 'seed', $next_entry->getStart()->get(IL_CAL_DATE));
52 }
53 $current_link = [
54 'link' => $ctrl->getLinkTargetByClass($ctrl_class_structure, 'selectCHCalendarOfUser'),
55 'txt' => str_replace("%1", ilObjUser::_lookupFullname($user_id), $lng->txt("cal_consultation_hours_for_user"))
56 ];
57 $links[] = $current_link;
58 }
59 // Reset control structure links
60 $ctrl->setParameterByClass(end($ctrl_class_structure), 'seed', '');
61 $ctrl->setParameterByClass(end($ctrl_class_structure), 'ch_user_id', '');
62 return $links;
63 }
const IL_CAL_DATE
const IL_CAL_UNIX
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...
static getAppointments($a_user_id)
Get all appointments.
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.
static _lookupFullname($a_user_id)
Lookup Full Name.
static _lookupObjId($a_id)
static getInstance($a_ref_id)
Get instance by ref_id.

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

Referenced by ilCalendarBlockGUI\addConsultationHourButtons().

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

187 {
188 global $DIC;
189
190 $ilDB = $DIC['ilDB'];
191
192 $query = 'SELECT user_id FROM cal_ch_settings ' .
193 'WHERE admin_id = ' . $ilDB->quote($a_usr_id, 'integer');
194 $res = $ilDB->query($query);
195
196 $users = array();
197 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
198 $users[] = $row->user_id;
199 }
200 return $users;
201 }
global $ilDB

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

Referenced by ilBookingEntry\lookupManagedBookingsForObject().

+ Here is the caller graph for this function:

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