ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ilDB;
29 
30  if(!$a_type)
31  {
32  include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
34  }
35  $owner = ' ';
36  if($a_check_owner)
37  {
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  {
52  $query .= " AND ce.context_id = ".$ilDB->quote($a_context_id, 'integer');
53  }
54  if($a_start)
55  {
56  $query .= " AND ce.starta = ".$ilDB->quote($a_start->get(IL_CAL_DATETIME, '', 'UTC'), 'text');
57  }
58 
59  $query .= (' ORDER BY ce.starta ASC');
60 
61  $res = $ilDB->query($query);
62  $entries = array();
63  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
64  {
65  $entries[] = $row->cal_id;
66  }
67  return $entries;
68  }
69 
70 
77  public static function getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start = null)
78  {
79  global $ilDB;
80 
81  // @todo check start time
82 
83  include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
85 
86  $start_limit = '';
87  if($start instanceof ilDateTime)
88  {
89  $start_limit = 'AND ce.starta >= '.$ilDB->quote($start->get(IL_CAL_DATETIME,'','UTC'),'timestamp');
90  }
91 
92  $query = 'SELECT ce.cal_id FROM cal_entries ce '.
93  'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id '.
94  'JOIN cal_categories cc ON ca.cat_id = cc.cat_id '.
95  'JOIN booking_entry be ON ce.context_id = be.booking_id '.
96  'WHERE cc.obj_id = '.$ilDB->quote($a_user_id,'integer').' '.
97  'AND cc.type = '.$ilDB->quote($type,'integer').' '.
98  'AND be.booking_group = '.$ilDB->quote($a_ch_group_id,'integer').' '.
99  $start_limit.' '.
100  'ORDER BY ce.starta ';
101  $res = $ilDB->query($query);
102  $app_ids = array();
103  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
104  {
105  $app_ids[] = $row->cal_id;
106  }
107  return $app_ids;
108  }
109 
114  public static function getAppointments($a_user_id)
115  {
116  $entries = array();
117  foreach(self::getAppointmentIds($a_user_id) as $app_id)
118  {
119  $entries[] = new ilCalendarEntry($app_id);
120  }
121  return $entries;
122  }
123 
129  public static function getManager($a_as_name = false)
130  {
131  global $ilDB, $ilUser;
132 
133  $set = $ilDB->query('SELECT admin_id FROM cal_ch_settings'.
134  ' WHERE user_id = '.$ilDB->quote($ilUser->getId(), 'integer'));
135  $row = $ilDB->fetchAssoc($set);
136  if($row && $row['admin_id'])
137  {
138  if($a_as_name)
139  {
140  return ilObjUser::_lookupLogin($row['admin_id']);
141  }
142  return (int)$row['admin_id'];
143  }
144  }
145 
151  public static function setManager($a_user_name)
152  {
153  global $ilDB, $ilUser;
154 
155  $user_id = false;
156  if($a_user_name)
157  {
158  $user_id = ilObjUser::_loginExists($a_user_name);
159  if(!$user_id)
160  {
161  return false;
162  }
163  }
164 
165  $ilDB->manipulate('DELETE FROM cal_ch_settings'.
166  ' WHERE user_id = '.$ilDB->quote($ilUser->getId(), 'integer'));
167 
168  if($user_id && $user_id != $ilUser->getId())
169  {
170  $ilDB->manipulate('INSERT INTO cal_ch_settings (user_id, admin_id)'.
171  ' VALUES ('.$ilDB->quote($ilUser->getId(), 'integer').','.
172  $ilDB->quote($user_id, 'integer').')');
173  }
174 
175  return true;
176  }
177 
182  public static function getManagedUsers()
183  {
184  global $ilDB, $ilUser;
185 
186  $all = array();
187  $set = $ilDB->query('SELECT user_id FROM cal_ch_settings'.
188  ' WHERE admin_id = '.$ilDB->quote($ilUser->getId(), 'integer'));
189  while($row = $ilDB->fetchAssoc($set))
190  {
191  $all[$row['user_id']] = ilObjUser::_lookupLogin($row['user_id']);
192  }
193  return $all;
194  }
195 }
196 ?>
static _lookupLogin($a_user_id)
lookup login
Model for a calendar entry.
const IL_CAL_DATETIME
static getManager($a_as_name=false)
Get consultation hour manager for current user.
static getAppointmentIds($a_user_id, $a_context_id=NULL, $a_start=NULL, $a_type=NULL, $a_check_owner=true)
Get all appointment ids.
$a_context_id
Definition: workflow.php:98
static setManager($a_user_name)
Set consultation hour manager for current user.
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:93
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
static getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start=null)
Get appointment ids by consultation hour group.
Create styles array
The data for the language used.
global $ilDB