ILIAS  release_8 Revision v8.24
class.ilCalendarCategory.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
32{
33 public const LTYPE_LOCAL = 1;
34 public const LTYPE_REMOTE = 2;
35
36 private static ?array $instances = [];
37
38 public const DEFAULT_COLOR = '#04427e';
39
40 public const TYPE_UNDEFINED = 0;
41 public const TYPE_USR = 1; // user
42 public const TYPE_OBJ = 2; // object
43 public const TYPE_GLOBAL = 3; // global
44 public const TYPE_CH = 4; // consultation hours
45 public const TYPE_BOOK = 5; // booking manager
46
47 protected static array $SORTED_TYPES = array(
48 0 => self::TYPE_GLOBAL,
49 1 => self::TYPE_USR,
50 2 => self::TYPE_CH,
51 3 => self::TYPE_BOOK,
52 4 => self::TYPE_OBJ
53 );
54
55 protected int $cat_id = 0;
56 protected string $color = '';
57 protected int $type = self::TYPE_USR;
58 protected int $obj_id = 0;
59 protected string $obj_type = '';
60 protected string $title = '';
61
63 protected string $remote_url = '';
64 protected string $remote_user = '';
65 protected string $remote_pass = '';
66 protected ?ilDateTime $remote_sync = null;
67
68 protected ilDBInterface $db;
69
70 public function __construct(int $a_cat_id = 0)
71 {
72 global $DIC;
73
74 $this->db = $DIC->database();
75 $this->cat_id = $a_cat_id;
76
77 $this->read();
78 }
79
83 public static function _getInstanceByObjId(int $a_obj_id): ?ilCalendarCategory
84 {
85 global $DIC;
86
87 $ilDB = $DIC['ilDB'];
88 $query = "SELECT cat_id FROM cal_categories " .
89 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
90 "AND type = " . $ilDB->quote(self::TYPE_OBJ, 'integer');
91 $res = $ilDB->query($query);
92 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
93 return new ilCalendarCategory((int) $row->cat_id);
94 }
95 return null;
96 }
97
98 public static function getInstanceByCategoryId(int $a_cat_id): ilCalendarCategory
99 {
100 if (!isset(self::$instances[$a_cat_id])) {
101 return self::$instances[$a_cat_id] = new ilCalendarCategory($a_cat_id);
102 }
103 return self::$instances[$a_cat_id];
104 }
105
109 public static function lookupCategorySortIndex(int $a_type_id): int
110 {
111 return (int) array_search($a_type_id, self::$SORTED_TYPES);
112 }
113
118 public static function lookupAppointments(int $a_category_id): array
119 {
120 global $DIC;
121
122 $ilDB = $DIC['ilDB'];
123 $query = "SELECT * FROM cal_cat_assignments " .
124 'WHERE cat_id = ' . $ilDB->quote($a_category_id, 'integer');
125 $res = $ilDB->query($query);
126 $apps = [];
127 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
128 $apps[] = (int) $row->cal_id;
129 }
130 return $apps;
131 }
132
133 public function getCategoryID(): int
134 {
135 return $this->cat_id;
136 }
137
138 public function setTitle(string $a_title): void
139 {
140 $this->title = $a_title;
141 }
142
143 public function getTitle(): string
144 {
145 return $this->title;
146 }
147
148 public function setColor(string $a_color): void
149 {
150 $this->color = $a_color;
151 }
152
153 public function getColor(): string
154 {
155 return $this->color;
156 }
157
158 public function setType(int $a_type): void
159 {
160 $this->type = $a_type;
161 }
162
163 public function getType(): int
164 {
165 return $this->type;
166 }
167
168 public function setObjId(int $a_obj_id): void
169 {
170 $this->obj_id = $a_obj_id;
171 }
172
173 public function getObjId(): int
174 {
175 return $this->obj_id;
176 }
177
178 public function getObjType(): string
179 {
180 return $this->obj_type;
181 }
182
183 public function getLocationType(): int
184 {
185 return $this->location;
186 }
187
188 public function setLocationType(int $a_type): void
189 {
190 $this->location = $a_type;
191 }
192
193 public function setRemoteUrl(string $a_url): void
194 {
195 $this->remote_url = $a_url;
196 }
197
198 public function getRemoteUrl(): string
199 {
200 return $this->remote_url;
201 }
202
203 public function setRemoteUser(string $a_user): void
204 {
205 $this->remote_user = $a_user;
206 }
207
208 public function getRemoteUser(): string
209 {
210 return $this->remote_user;
211 }
212
213 public function setRemotePass(string $a_pass): void
214 {
215 $this->remote_pass = $a_pass;
216 }
217
218 public function getRemotePass(): string
219 {
220 return $this->remote_pass;
221 }
222
226 public function setRemoteSyncLastExecution(ilDateTime $dt): void
227 {
228 $this->remote_sync = $dt;
229 }
230
235 {
236 if ($this->remote_sync instanceof ilDateTime) {
237 return $this->remote_sync;
238 }
239 return new ilDateTime();
240 }
241
242 public function add(): int
243 {
244 $next_id = $this->db->nextId('cal_categories');
245 $query = "INSERT INTO cal_categories (cat_id,obj_id,color,type,title,loc_type,remote_url,remote_user,remote_pass,remote_sync) " .
246 "VALUES ( " .
247 $this->db->quote($next_id, 'integer') . ", " .
248 $this->db->quote($this->getObjId(), 'integer') . ", " .
249 $this->db->quote($this->getColor(), 'text') . ", " .
250 $this->db->quote($this->getType(), 'integer') . ", " .
251 $this->db->quote($this->getTitle(), 'text') . ", " .
252 $this->db->quote($this->getLocationType(), 'integer') . ', ' .
253 $this->db->quote($this->getRemoteUrl(), 'text') . ', ' .
254 $this->db->quote($this->getRemoteUser(), 'text') . ', ' .
255 $this->db->quote($this->getRemotePass(), 'text') . ', ' .
256 $this->db->quote(
258 'timestamp'
259 ) . ' ' .
260 ")";
261
262 $this->db->manipulate($query);
263
264 $this->cat_id = $next_id;
265 return $this->cat_id;
266 }
267
268 public function update(): void
269 {
270 $query = "UPDATE cal_categories " .
271 "SET obj_id = " . $this->db->quote($this->getObjId(), 'integer') . ", " .
272 "color = " . $this->db->quote($this->getColor(), 'text') . ", " .
273 "type = " . $this->db->quote($this->getType(), 'integer') . ", " .
274 "title = " . $this->db->quote($this->getTitle(), 'text') . ", " .
275 "loc_type = " . $this->db->quote($this->getLocationType(), 'integer') . ', ' .
276 "remote_url = " . $this->db->quote($this->getRemoteUrl(), 'text') . ', ' .
277 "remote_user = " . $this->db->quote($this->getRemoteUser(), 'text') . ', ' .
278 "remote_pass = " . $this->db->quote($this->getRemotePass(), 'text') . ', ' .
279 'remote_sync = ' . $this->db->quote($this->getRemoteSyncLastExecution()->get(
281 '',
283 ), 'timestamp') . ' ' .
284 "WHERE cat_id = " . $this->db->quote($this->cat_id, 'integer') . " ";
285 $res = $this->db->manipulate($query);
286 }
287
288 public function delete(): void
289 {
290 $query = "DELETE FROM cal_categories " .
291 "WHERE cat_id = " . $this->db->quote($this->cat_id, 'integer') . " ";
292 $res = $this->db->manipulate($query);
293
295
296 foreach (ilCalendarCategoryAssignments::_getAssignedAppointments(array($this->cat_id)) as $app_id) {
298 }
300 }
301
302 public function validate(): bool
303 {
305 return false;
306 }
307 if (strlen($this->getTitle()) && strlen($this->getColor()) && $this->getType()) {
308 return true;
309 }
310 return false;
311 }
312
313 private function read(): void
314 {
315 if (!$this->cat_id) {
316 return;
317 }
318
319 $query = "SELECT * FROM cal_categories " .
320 "WHERE cat_id = " . $this->db->quote($this->getCategoryID(), 'integer') . " ";
321 $res = $this->db->query($query);
322 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
323 $this->cat_id = (int) $row->cat_id;
324 $this->obj_id = (int) $row->obj_id;
325 $this->type = (int) $row->type;
326 $this->color = (string) $row->color;
327 $this->title = (string) $row->title;
328 $this->location = (int) $row->loc_type;
329 $this->remote_url = (string) $row->remote_url;
330 $this->remote_user = (string) $row->remote_user;
331 $this->remote_pass = (string) $row->remote_pass;
332
333 if ($row->remote_sync) {
334 $this->remote_sync = new ilDateTime((string) $row->remote_sync, IL_CAL_DATETIME, 'UTC');
335 } else {
336 $this->remote_sync = new ilDateTime();
337 }
338 }
339 if ($this->getType() == self::TYPE_OBJ) {
340 $this->title = ilObject::_lookupTitle($this->getObjId());
341 $this->obj_type = ilObject::_lookupType($this->getObjId());
342 }
343 }
344}
const IL_CAL_DATETIME
static _deleteByCategoryId(int $a_cat_id)
Delete assignments by category id @access public.
static _getAssignedAppointments(array $a_cat_id)
Get assigned apointments.
Stores calendar categories.
setRemoteSyncLastExecution(ilDateTime $dt)
Set remote sync last execution.
static lookupCategorySortIndex(int $a_type_id)
Lookup sort index of calendar type.
static lookupAppointments(int $a_category_id)
get all assigned appointment ids
static _getInstanceByObjId(int $a_obj_id)
get instance by obj_id
getRemoteSyncLastExecution()
Get last execution date of remote sync.
static getInstanceByCategoryId(int $a_cat_id)
static _delete(int $a_entry_id)
static _deleteCategories(int $a_cat_id)
@classDescription Date and time handling
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query