ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilConsultationHourAppointments.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
5
16{
17
26 public static function getAppointmentIds($a_user_id, $a_context_id = null, $a_start = null, $a_type = null, $a_check_owner = true)
27 {
28 global $DIC;
29
30 $ilDB = $DIC['ilDB'];
31
32 if (!$a_type) {
33 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
35 }
36 $owner = ' ';
37 if ($a_check_owner) {
38 $owner = " AND be.obj_id = " . $ilDB->quote($a_user_id, 'integer');
39 }
40
41 $query = "SELECT ce.cal_id FROM cal_entries ce" .
42 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id" .
43 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id" .
44 " JOIN booking_entry be ON ce.context_id = be.booking_id" .
45 " WHERE cc.obj_id = " . $ilDB->quote($a_user_id, 'integer') .
46 $owner .
47 " AND cc.type = " . $ilDB->quote($a_type, 'integer');
48
49
50 if ($a_context_id) {
51 $query .= " AND ce.context_id = " . $ilDB->quote($a_context_id, 'integer');
52 }
53 if ($a_start) {
54 $query .= " AND ce.starta = " . $ilDB->quote($a_start->get(IL_CAL_DATETIME, '', 'UTC'), 'text');
55 }
56
57 $query .= (' ORDER BY ce.starta ASC');
58
59 $res = $ilDB->query($query);
60 $entries = array();
61 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
62 $entries[] = $row->cal_id;
63 }
64 return $entries;
65 }
66
67
74 public static function getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start = null)
75 {
76 global $DIC;
77
78 $ilDB = $DIC['ilDB'];
79
80 // @todo check start time
81
82 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
84
85 $start_limit = '';
86 if ($start instanceof ilDateTime) {
87 $start_limit = 'AND ce.starta >= ' . $ilDB->quote($start->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp');
88 }
89
90 $query = 'SELECT ce.cal_id FROM cal_entries ce ' .
91 'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id ' .
92 'JOIN cal_categories cc ON ca.cat_id = cc.cat_id ' .
93 'JOIN booking_entry be ON ce.context_id = be.booking_id ' .
94 'WHERE cc.obj_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ' .
95 'AND cc.type = ' . $ilDB->quote($type, 'integer') . ' ' .
96 'AND be.booking_group = ' . $ilDB->quote($a_ch_group_id, 'integer') . ' ' .
97 $start_limit . ' ' .
98 'ORDER BY ce.starta ';
99 $res = $ilDB->query($query);
100 $app_ids = array();
101 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
102 $app_ids[] = $row->cal_id;
103 }
104 return $app_ids;
105 }
106
111 public static function getAppointments($a_user_id)
112 {
113 $entries = array();
114 foreach (self::getAppointmentIds($a_user_id) as $app_id) {
115 $entries[] = new ilCalendarEntry($app_id);
116 }
117 return $entries;
118 }
119
127 public static function getManager($a_as_name = false, $a_full_name = false, $a_user_id = null)
128 {
129 global $DIC;
130
131 $ilDB = $DIC['ilDB'];
132 $ilUser = $DIC['ilUser'];
133
134 if (!$a_user_id) {
135 $user_id = $ilUser->getId();
136 } else {
137 $user_id = $a_user_id;
138 }
139
140 $set = $ilDB->query('SELECT admin_id FROM cal_ch_settings' .
141 ' WHERE user_id = ' . $ilDB->quote($user_id, 'integer'));
142 $row = $ilDB->fetchAssoc($set);
143 if ($row && $row['admin_id']) {
144 if ($a_as_name && $a_full_name) {
145 return ilObjUser::_lookupFullname($row['admin_id']);
146 } elseif ($a_as_name) {
147 return ilObjUser::_lookupLogin($row['admin_id']);
148 }
149 return (int) $row['admin_id'];
150 }
151 }
152
158 public static function setManager($a_user_name)
159 {
160 global $DIC;
161
162 $ilDB = $DIC['ilDB'];
163 $ilUser = $DIC['ilUser'];
164
165 $user_id = false;
166 if ($a_user_name) {
167 $user_id = ilObjUser::_loginExists($a_user_name);
168 if (!$user_id) {
169 return false;
170 }
171 }
172
173 $ilDB->manipulate('DELETE FROM cal_ch_settings' .
174 ' WHERE user_id = ' . $ilDB->quote($ilUser->getId(), 'integer'));
175
176 if ($user_id && $user_id != $ilUser->getId()) {
177 $ilDB->manipulate('INSERT INTO cal_ch_settings (user_id, admin_id)' .
178 ' VALUES (' . $ilDB->quote($ilUser->getId(), 'integer') . ',' .
179 $ilDB->quote($user_id, 'integer') . ')');
180 }
181
182 return true;
183 }
184
189 public static function getManagedUsers()
190 {
191 global $DIC;
192
193 $ilDB = $DIC['ilDB'];
194 $ilUser = $DIC['ilUser'];
195
196 $all = array();
197 $set = $ilDB->query('SELECT user_id FROM cal_ch_settings' .
198 ' WHERE admin_id = ' . $ilDB->quote($ilUser->getId(), 'integer'));
199 while ($row = $ilDB->fetchAssoc($set)) {
200 $all[$row['user_id']] = ilObjUser::_lookupLogin($row['user_id']);
201 }
202 return $all;
203 }
204}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
Model for a calendar entry.
static getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.
static getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start=null)
Get appointment ids by consultation hour group.
static getManager($a_as_name=false, $a_full_name=false, $a_user_id=null)
Get consultation hour manager for current user or specific user.
static getAppointments($a_user_id)
Get all appointments.
static getManagedUsers()
Get all managed consultation hours users for current users.
static setManager($a_user_name)
Set consultation hour manager for current user.
@classDescription Date and time handling
static _lookupLogin($a_user_id)
lookup login
static _lookupFullname($a_user_id)
Lookup Full Name.
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
$query
$type
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_context_id
Definition: workflow.php:97
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46