ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilConsultationHourAppointments.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
31  public static function getAppointmentIds(
32  int $a_user_id,
33  ?int $a_context_id = null,
34  ?ilDateTime $a_start = null,
35  ?int $a_type = null,
36  bool $a_check_owner = true
37  ): array {
38  global $DIC;
39 
40  $ilDB = $DIC->database();
41 
42  if (!$a_type) {
44  }
45  $owner = ' ';
46  if ($a_check_owner) {
47  $owner = " AND be.obj_id = " . $ilDB->quote($a_user_id, 'integer');
48  }
49 
50  $query = "SELECT ce.cal_id FROM cal_entries ce" .
51  " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id" .
52  " JOIN cal_categories cc ON cca.cat_id = cc.cat_id" .
53  " JOIN booking_entry be ON ce.context_id = be.booking_id" .
54  " WHERE cc.obj_id = " . $ilDB->quote($a_user_id, 'integer') .
55  $owner .
56  " AND cc.type = " . $ilDB->quote($a_type, 'integer');
57 
58  if ($a_context_id) {
59  $query .= " AND ce.context_id = " . $ilDB->quote($a_context_id, 'integer');
60  }
61  if ($a_start) {
62  $query .= " AND ce.starta = " . $ilDB->quote($a_start->get(IL_CAL_DATETIME, '', 'UTC'), 'text');
63  }
64  $query .= (' ORDER BY ce.starta ASC');
65  $res = $ilDB->query($query);
66  $entries = array();
67  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
68  $entries[] = (int) $row->cal_id;
69  }
70  return $entries;
71  }
72 
78  public static function getAppointmentIdsByGroup(
79  int $a_user_id,
80  int $a_ch_group_id,
81  ?ilDateTime $start = null
82  ): array {
83  global $DIC;
84 
85  $ilDB = $DIC->database();
87  $start_limit = '';
88  if ($start instanceof ilDateTime) {
89  $start_limit = 'AND ce.starta >= ' . $ilDB->quote($start->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp');
90  }
91  $query = 'SELECT ce.cal_id FROM cal_entries ce ' .
92  'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id ' .
93  'JOIN cal_categories cc ON ca.cat_id = cc.cat_id ' .
94  'JOIN booking_entry be ON ce.context_id = be.booking_id ' .
95  'WHERE cc.obj_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ' .
96  'AND cc.type = ' . $ilDB->quote($type, 'integer') . ' ' .
97  'AND be.booking_group = ' . $ilDB->quote($a_ch_group_id, 'integer') . ' ' .
98  $start_limit . ' ' .
99  'ORDER BY ce.starta ';
100  $res = $ilDB->query($query);
101  $app_ids = [];
102  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
103  $app_ids[] = (int) $row->cal_id;
104  }
105  return $app_ids;
106  }
107 
112  public static function getAppointments(int $a_user_id): array
113  {
114  $entries = [];
115  foreach (self::getAppointmentIds($a_user_id) as $app_id) {
116  $entries[] = new ilCalendarEntry($app_id);
117  }
118  return $entries;
119  }
120 
125  public static function getManager(bool $a_as_name = false, bool $a_full_name = false, ?int $a_user_id = null)
126  {
127  global $DIC;
128 
129  $ilDB = $DIC->database();
130  $ilUser = $DIC->user();
131 
132  if (!$a_user_id) {
133  $user_id = $ilUser->getId();
134  } else {
135  $user_id = $a_user_id;
136  }
137 
138  $set = $ilDB->query('SELECT admin_id FROM cal_ch_settings' .
139  ' WHERE user_id = ' . $ilDB->quote($user_id, 'integer'));
140  $row = $ilDB->fetchAssoc($set);
141  if ($row && $row['admin_id']) {
142  if ($a_as_name && $a_full_name) {
143  return ilObjUser::_lookupFullname((int) $row['admin_id']);
144  } elseif ($a_as_name) {
145  return ilObjUser::_lookupLogin((int) $row['admin_id']);
146  }
147  return (int) $row['admin_id'];
148  }
149  return 0;
150  }
151 
157  public static function setManager(string $a_user_name): bool
158  {
159  global $DIC;
160 
161  $ilDB = $DIC->database();
162  $ilUser = $DIC->user();
163 
164  $user_id = false;
165  if ($a_user_name) {
166  $user_id = ilObjUser::_loginExists($a_user_name);
167  if (!$user_id) {
168  return false;
169  }
170  }
171 
172  $ilDB->manipulate('DELETE FROM cal_ch_settings' .
173  ' WHERE user_id = ' . $ilDB->quote($ilUser->getId(), 'integer'));
174 
175  if ($user_id && $user_id != $ilUser->getId()) {
176  $ilDB->manipulate('INSERT INTO cal_ch_settings (user_id, admin_id)' .
177  ' VALUES (' . $ilDB->quote($ilUser->getId(), 'integer') . ',' .
178  $ilDB->quote($user_id, 'integer') . ')');
179  }
180  return true;
181  }
182 
187  public static function getManagedUsers(): array
188  {
189  global $DIC;
190 
191  $ilDB = $DIC->database();
192  $ilUser = $DIC->user();
193 
194  $all = array();
195  $set = $ilDB->query('SELECT user_id FROM cal_ch_settings' .
196  ' WHERE admin_id = ' . $ilDB->quote($ilUser->getId(), 'integer'));
197  while ($row = $ilDB->fetchAssoc($set)) {
198  $all[(int) $row['user_id']] = ilObjUser::_lookupLogin((int) $row['user_id']);
199  }
200  return $all;
201  }
202 }
$res
Definition: ltiservices.php:66
const IL_CAL_DATETIME
static _lookupFullname(int $a_user_id)
static getAppointmentIds(int $a_user_id, ?int $a_context_id=null, ?ilDateTime $a_start=null, ?int $a_type=null, bool $a_check_owner=true)
static getManager(bool $a_as_name=false, bool $a_full_name=false, ?int $a_user_id=null)
Get consultation hour manager for current user or specific user.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getManagedUsers()
Get all managed consultation hours users for current users.
static getAppointmentIdsByGroup(int $a_user_id, int $a_ch_group_id, ?ilDateTime $start=null)
Get appointment ids by consultation hour group.
static _loginExists(string $a_login, int $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...
global $DIC
Definition: shib_login.php:22
static getAppointments(int $a_user_id)
Get all appointments.
static setManager(string $a_user_name)
Set consultation hour manager for current user.
static _lookupLogin(int $a_user_id)