ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilConsultationHourUtils.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
12
20 public static function findCalendarAppointmentsForBooking(\ilBookingEntry $booking, \ilDateTime $start, \ilDateTime $end)
21 {
22 global $DIC;
23
24 $db = $DIC->database();
25
26 $query = 'select ce.cal_id from cal_entries ce ' .
27 'join cal_cat_assignments cca on ce.cal_id = cca.cal_id ' .
28 'join cal_categories cc on cca.cat_id = cc.cat_id '.
29 'where context_id = ' . $db->quote($booking->getId(), 'integer') . ' ' .
30 'and starta = ' . $db->quote($start->get(IL_CAL_DATETIME, '', \ilTimeZone::UTC), \ilDBConstants::T_TIMESTAMP) . ' ' .
31 'and enda = ' . $db->quote($end->get(IL_CAL_DATETIME, '', \ilTimeZone::UTC), \ilDBConstants::T_TIMESTAMP) . ' ' .
32 'and type = ' . $db->quote(\ilCalendarCategory::TYPE_CH, 'integer');
33 $res = $db->query($query);
34
35 $calendar_apppointments = [];
36 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
37 $calendar_apppointments[] = $row->cal_id;
38 }
39 return $calendar_apppointments;
40 }
41
42
49 public static function bookAppointment($a_usr_id, $a_app_id)
50 {
51 global $lng;
52
53 // Create new default consultation hour calendar
54 include_once './Services/Language/classes/class.ilLanguageFactory.php';
55 $cal_lang = ilLanguageFactory::_getLanguage($lng->getDefaultLanguage());
56 $cal_lang->loadLanguageModule('dateplaner');
57
58 include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
59 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
62 $a_usr_id,
63 $cal_lang->txt('cal_ch_personal_ch'),
64 true
65 );
66
67 // duplicate appointment
68 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
69 $app = new ilCalendarEntry($a_app_id);
70 $personal_app = clone $app;
71 $personal_app->save();
72
73 // assign appointment to category
74 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
75 $assignment = new ilCalendarCategoryAssignments($personal_app->getEntryId());
76 $assignment->addAssignment($ch->getCategoryID());
77
78 // book appointment
79 include_once './Services/Booking/classes/class.ilBookingEntry.php';
80 $booking = new ilBookingEntry($app->getContextId());
81 $booking->book($app->getEntryId(), $a_usr_id);
82 return true;
83 }
84
91 public static function cancelBooking($a_usr_id, $a_app_id, $a_send_notification = true)
92 {
93 // Delete personal copy of appointment
94 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
95 $app = new ilCalendarEntry($a_app_id);
96
97 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
99 $a_usr_id,
100 $app->getContextId(),
101 $app->getStart(),
103 false
104 );
105 foreach ($user_apps as $uapp_id) {
106 $uapp = new ilCalendarEntry($uapp_id);
107 $uapp->delete();
108
109 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
111
112 break;
113 }
114
115 // Delete booking entries
116 // Send notification
117 $booking = new ilBookingEntry($app->getContextId());
118 if ($a_send_notification) {
119 $booking->cancelBooking($a_app_id, $a_usr_id);
120 } else {
121 $booking->deleteBooking($a_app_id, $a_usr_id);
122 }
123 return true;
124 }
125
130 public static function lookupManagedUsers($a_usr_id)
131 {
132 global $ilDB;
133
134 $query = 'SELECT user_id FROM cal_ch_settings ' .
135 'WHERE admin_id = ' . $ilDB->quote($a_usr_id, 'integer');
136 $res = $ilDB->query($query);
137
138 $users = array();
139 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
140 $users[] = $row->user_id;
141 }
142 return $users;
143 }
144}
$users
Definition: authpage.php:44
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
Booking definition.
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
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 getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.
static lookupManagedUsers($a_usr_id)
Lookup managed users.
static findCalendarAppointmentsForBooking(\ilBookingEntry $booking, \ilDateTime $start, \ilDateTime $end)
static cancelBooking($a_usr_id, $a_app_id, $a_send_notification=true)
Cancel a booking.
static bookAppointment($a_usr_id, $a_app_id)
Book an appointment.
@classDescription Date and time handling
get($a_format, $a_format_str='', $a_tz='')
get formatted date
static _getLanguage($a_lang_key='')
Get langauge object.
$end
Definition: saml1-acs.php:18
global $lng
Definition: privfeed.php:17
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB