ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
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 $DIC;
52
53 $lng = $DIC['lng'];
54
55 // Create new default consultation hour calendar
56 include_once './Services/Language/classes/class.ilLanguageFactory.php';
57 $cal_lang = ilLanguageFactory::_getLanguage($lng->getDefaultLanguage());
58 $cal_lang->loadLanguageModule('dateplaner');
59
60 include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
61 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
64 $a_usr_id,
65 $cal_lang->txt('cal_ch_personal_ch'),
66 true
67 );
68
69 // duplicate appointment
70 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
71 $app = new ilCalendarEntry($a_app_id);
72 $personal_app = clone $app;
73 $personal_app->save();
74
75 // assign appointment to category
76 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
77 $assignment = new ilCalendarCategoryAssignments($personal_app->getEntryId());
78 $assignment->addAssignment($ch->getCategoryID());
79
80 // book appointment
81 include_once './Services/Booking/classes/class.ilBookingEntry.php';
82 $booking = new ilBookingEntry($app->getContextId());
83 $booking->book($app->getEntryId(), $a_usr_id);
84 return true;
85 }
86
93 public static function cancelBooking($a_usr_id, $a_app_id, $a_send_notification = true)
94 {
95 // Delete personal copy of appointment
96 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
97 $app = new ilCalendarEntry($a_app_id);
98
99 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
101 $a_usr_id,
102 $app->getContextId(),
103 $app->getStart(),
105 false
106 );
107 foreach ($user_apps as $uapp_id) {
108 $uapp = new ilCalendarEntry($uapp_id);
109 $uapp->delete();
110
111 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
113
114 break;
115 }
116
117 // Delete booking entries
118 // Send notification
119 $booking = new ilBookingEntry($app->getContextId());
120 if ($a_send_notification) {
121 $booking->cancelBooking($a_app_id, $a_usr_id);
122 } else {
123 $booking->deleteBooking($a_app_id, $a_usr_id);
124 }
125 return true;
126 }
127
132 public static function lookupManagedUsers($a_usr_id)
133 {
134 global $DIC;
135
136 $ilDB = $DIC['ilDB'];
137
138 $query = 'SELECT user_id FROM cal_ch_settings ' .
139 'WHERE admin_id = ' . $ilDB->quote($a_usr_id, 'integer');
140 $res = $ilDB->query($query);
141
142 $users = array();
143 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
144 $users[] = $row->user_id;
145 }
146 return $users;
147 }
148}
$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
static _getLanguage($a_lang_key='')
Get langauge object.
$row
$query
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res
global $ilDB
$start
Definition: bench.php:8