ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCalendarCategory.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
34{
35 const LTYPE_LOCAL = 1;
36 const LTYPE_REMOTE = 2;
37
38 private static $instances = null;
39
40 const DEFAULT_COLOR = '#04427e';
41
42 const TYPE_USR = 1; // user
43 const TYPE_OBJ = 2; // object
44 const TYPE_GLOBAL = 3; // global
45 const TYPE_CH = 4; // consultation hours
46 const TYPE_BOOK = 5; // booking manager
47
48 protected static $SORTED_TYPES = array(
49 0 => self::TYPE_GLOBAL,
50 1 => self::TYPE_USR,
51 2 => self::TYPE_CH,
52 3 => self::TYPE_BOOK,
53 4 => self::TYPE_OBJ
54 );
55
56
57 protected $cat_id;
58 protected $color;
59 protected $type = self::TYPE_USR;
60 protected $obj_id;
61 protected $obj_type = null;
62 protected $title;
63
65 protected $remote_url;
66 protected $remote_user;
67 protected $remote_pass;
68 protected $remote_sync = null;
69
70 protected $db;
71
72
78 public function __construct($a_cat_id = 0)
79 {
80 global $ilDB;
81
82 $this->db = $ilDB;
83 $this->cat_id = $a_cat_id;
84
85 $this->read();
86 }
87
95 public static function _getInstanceByObjId($a_obj_id)
96 {
97 global $ilDB;
98
99 $query = "SELECT cat_id FROM cal_categories ".
100 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
101 "AND type = ".$ilDB->quote(self::TYPE_OBJ ,'integer');
102 $res = $ilDB->query($query);
103 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
104 {
105 return new ilCalendarCategory($row->cat_id);
106 }
107 return null;
108 }
109
115 public static function getInstanceByCategoryId($a_cat_id)
116 {
117 if(!self::$instances[$a_cat_id])
118 {
119 return self::$instances[$a_cat_id] = new ilCalendarCategory($a_cat_id);
120 }
121 return self::$instances[$a_cat_id];
122 }
123
127 public static function lookupCategorySortIndex($a_type_id)
128 {
129 return array_search($a_type_id, self::$SORTED_TYPES);
130 }
136 public static function lookupAppointments($a_category_id)
137 {
138 global $ilDB;
139
140 $query = "SELECT * FROM cal_cat_assignments ".
141 'WHERE cat_id = '.$ilDB->quote($a_category_id,'integer');
142 $res = $ilDB->query($query);
143 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
144 {
145 $apps[] = $row->cal_id;
146 }
147 return $apps ? $apps : array();
148 }
149
150
157 public function getCategoryID()
158 {
159 return $this->cat_id;
160 }
161
169 public function setTitle($a_title)
170 {
171 $this->title = $a_title;
172 }
173
180 public function getTitle()
181 {
182 return $this->title;
183 }
184
185
192 public function setColor($a_color)
193 {
194 $this->color = $a_color;
195 }
196
203 public function getColor()
204 {
205 return $this->color;
206 }
207
214 public function setType($a_type)
215 {
216 $this->type = $a_type;
217 }
218
225 public function getType()
226 {
227 return $this->type;
228 }
229
236 public function setObjId($a_obj_id)
237 {
238 $this->obj_id = $a_obj_id;
239 }
240
247 public function getObjId()
248 {
249 return $this->obj_id;
250 }
251
257 public function getObjType()
258 {
259 return $this->obj_type;
260 }
261
262 public function getLocationType()
263 {
264 return $this->location;
265 }
266
267 public function setLocationType($a_type)
268 {
269 $this->location = $a_type;
270 }
271
272 public function setRemoteUrl($a_url)
273 {
274 $this->remote_url = $a_url;
275 }
276
277 public function getRemoteUrl()
278 {
279 return $this->remote_url;
280 }
281
282 public function setRemoteUser($a_user)
283 {
284 $this->remote_user = $a_user;
285 }
286
287 public function getRemoteUser()
288 {
289 return $this->remote_user;
290 }
291
292 public function setRemotePass($a_pass)
293 {
294 $this->remote_pass = $a_pass;
295 }
296
297 public function getRemotePass()
298 {
299 return $this->remote_pass;
300 }
301
306 public function setRemoteSyncLastExecution(ilDateTime $dt = null)
307 {
308 $this->remote_sync = $dt;
309 }
310
316 {
317 if($this->remote_sync instanceof ilDateTime)
318 {
319 return $this->remote_sync;
320 }
321 return new ilDateTime();
322 }
323
324
331 public function add()
332 {
333 global $ilDB;
334
335 $next_id = $ilDB->nextId('cal_categories');
336
337 $query = "INSERT INTO cal_categories (cat_id,obj_id,color,type,title,loc_type,remote_url,remote_user,remote_pass,remote_sync) ".
338 "VALUES ( ".
339 $ilDB->quote($next_id,'integer').", ".
340 $this->db->quote($this->getObjId() ,'integer').", ".
341 $this->db->quote($this->getColor() ,'text').", ".
342 $this->db->quote($this->getType() ,'integer').", ".
343 $this->db->quote($this->getTitle() ,'text').", ".
344 $this->db->quote($this->getLocationType(),'integer').', '.
345 $this->db->quote($this->getRemoteUrl(),'text').', '.
346 $this->db->quote($this->getRemoteUser(),'text').', '.
347 $this->db->quote($this->getRemotePass(),'text').', '.
348 $this->db->quote($this->getRemoteSyncLastExecution()->get(IL_CAL_DATETIME,'', ilTimeZone::UTC),'timestamp').' '.
349 ")";
350
351 $ilDB->manipulate($query);
352
353 $this->cat_id = $next_id;
354 return $this->cat_id;
355 }
356
363 public function update()
364 {
365 global $ilDB;
366
367 $query = "UPDATE cal_categories ".
368 "SET obj_id = ".$this->db->quote($this->getObjId() ,'integer').", ".
369 "color = ".$this->db->quote($this->getColor() ,'text').", ".
370 "type = ".$this->db->quote($this->getType() ,'integer').", ".
371 "title = ".$this->db->quote($this->getTitle() ,'text').", ".
372 "loc_type = ".$this->db->quote($this->getLocationType(),'integer').', '.
373 "remote_url = ".$this->db->quote($this->getRemoteUrl(),'text').', '.
374 "remote_user = ".$this->db->quote($this->getRemoteUser(),'text').', '.
375 "remote_pass = ".$this->db->quote($this->getRemotePass(),'text').', '.
376 'remote_sync = '.$this->db->quote($this->getRemoteSyncLastExecution()->get(IL_CAL_DATETIME,'', ilTimeZone::UTC),'timestamp').' '.
377 "WHERE cat_id = ".$this->db->quote($this->cat_id ,'integer')." ";
378 $res = $ilDB->manipulate($query);
379 return true;
380 }
381
388 public function delete()
389 {
390 global $ilDB;
391
392 $query = "DELETE FROM cal_categories ".
393 "WHERE cat_id = ".$this->db->quote($this->cat_id ,'integer')." ";
394 $res = $ilDB->manipulate($query);
395
396 include_once('./Services/Calendar/classes/class.ilCalendarHidden.php');
398
399 include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
400 foreach(ilCalendarCategoryAssignments::_getAssignedAppointments(array($this->cat_id)) as $app_id)
401 {
402 include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
404 }
406 }
407
414 public function validate()
415 {
417 {
418 return false;
419 }
420 if(strlen($this->getTitle()) and strlen($this->getColor()) and $this->getType())
421 {
422 return true;
423 }
424 return false;
425 }
426
432 private function read()
433 {
434 global $ilDB;
435
436 if(!$this->cat_id)
437 {
438 return true;
439 }
440
441 $query = "SELECT * FROM cal_categories ".
442 "WHERE cat_id = ".$this->db->quote($this->getCategoryID() ,'integer')." ";
443 $res = $this->db->query($query);
444 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
445 {
446 $this->cat_id = $row->cat_id;
447 $this->obj_id = $row->obj_id;
448 $this->type = $row->type;
449 $this->color = $row->color;
450 $this->title = $row->title;
451 $this->location = $row->loc_type;
452 $this->remote_url = $row->remote_url;
453 $this->remote_user = $row->remote_user;
454 $this->remote_pass = $row->remote_pass;
455
456 if($row->remote_sync)
457 {
458 $this->remote_sync = new ilDateTime($row->remote_sync,IL_CAL_DATETIME,'UTC');
459 }
460 else
461 {
462 $this->remote_sync = new ilDateTime();
463 }
464 }
465 if($this->getType() == self::TYPE_OBJ)
466 {
467 $this->title = ilObject::_lookupTitle($this->getObjId());
468 $this->obj_type = ilObject::_lookupType($this->getObjId());
469 }
470 }
471}
472?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
const IL_CAL_DATETIME
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
static _deleteByCategoryId($a_cat_id)
Delete assignments by category id.
Stores calendar categories.
static getInstanceByCategoryId($a_cat_id)
Get instance by category id.
__construct($a_cat_id=0)
Constructor.
static _getInstanceByObjId($a_obj_id)
get instance by obj_id
setObjId($a_obj_id)
set obj id
setRemoteSyncLastExecution(ilDateTime $dt=null)
Set remote sync last execution.
static lookupAppointments($a_category_id)
get all assigned appointment ids
static lookupCategorySortIndex($a_type_id)
Lookup sort index of calendar type.
getRemoteSyncLastExecution()
Get last execution date of remote sync.
static _delete($a_entry_id)
delete entry
static _deleteCategories($a_cat_id)
delete by category
@classDescription Date and time handling
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilDB