ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_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 }
static _lookupLogin($a_user_id)
lookup login
Model for a calendar entry.
const IL_CAL_DATETIME
$type
global $DIC
Definition: saml.php:7
static _lookupFullname($a_user_id)
Lookup Full Name.
$a_context_id
Definition: workflow.php:97
static getAppointmentIds($a_user_id, $a_context_id=null, $a_start=null, $a_type=null, $a_check_owner=true)
Get all appointment ids.
static setManager($a_user_name)
Set consultation hour manager for current user.
$start
Definition: bench.php:8
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...
$a_type
Definition: workflow.php:92
foreach($_POST as $key=> $value) $res
static getManagedUsers()
Get all managed consultation hours users for current users.
static getAppointments($a_user_id)
Get all appointments.
Date and time handling
$ilUser
Definition: imgupload.php:18
$query
static getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start=null)
Get appointment ids by consultation hour group.
$row
global $ilDB
static getManager($a_as_name=false, $a_full_name=false, $a_user_id=null)
Get consultation hour manager for current user or specific user.