ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
64  protected $location = self::LTYPE_LOCAL;
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(ilDBConstants::FETCHMODE_OBJECT)) {
104  return new ilCalendarCategory($row->cat_id);
105  }
106  return null;
107  }
108 
114  public static function getInstanceByCategoryId($a_cat_id)
115  {
116  if (!self::$instances[$a_cat_id]) {
117  return self::$instances[$a_cat_id] = new ilCalendarCategory($a_cat_id);
118  }
119  return self::$instances[$a_cat_id];
120  }
121 
125  public static function lookupCategorySortIndex($a_type_id)
126  {
127  return array_search($a_type_id, self::$SORTED_TYPES);
128  }
134  public static function lookupAppointments($a_category_id)
135  {
136  global $ilDB;
137 
138  $query = "SELECT * FROM cal_cat_assignments " .
139  'WHERE cat_id = ' . $ilDB->quote($a_category_id, 'integer');
140  $res = $ilDB->query($query);
141  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
142  $apps[] = $row->cal_id;
143  }
144  return $apps ? $apps : array();
145  }
146 
147 
154  public function getCategoryID()
155  {
156  return $this->cat_id;
157  }
158 
166  public function setTitle($a_title)
167  {
168  $this->title = $a_title;
169  }
170 
177  public function getTitle()
178  {
179  return $this->title;
180  }
181 
182 
189  public function setColor($a_color)
190  {
191  $this->color = $a_color;
192  }
193 
200  public function getColor()
201  {
202  return $this->color;
203  }
204 
211  public function setType($a_type)
212  {
213  $this->type = $a_type;
214  }
215 
222  public function getType()
223  {
224  return $this->type;
225  }
226 
233  public function setObjId($a_obj_id)
234  {
235  $this->obj_id = $a_obj_id;
236  }
237 
244  public function getObjId()
245  {
246  return $this->obj_id;
247  }
248 
254  public function getObjType()
255  {
256  return $this->obj_type;
257  }
258 
259  public function getLocationType()
260  {
261  return $this->location;
262  }
263 
264  public function setLocationType($a_type)
265  {
266  $this->location = $a_type;
267  }
268 
269  public function setRemoteUrl($a_url)
270  {
271  $this->remote_url = $a_url;
272  }
273 
274  public function getRemoteUrl()
275  {
276  return $this->remote_url;
277  }
278 
279  public function setRemoteUser($a_user)
280  {
281  $this->remote_user = $a_user;
282  }
283 
284  public function getRemoteUser()
285  {
286  return $this->remote_user;
287  }
288 
289  public function setRemotePass($a_pass)
290  {
291  $this->remote_pass = $a_pass;
292  }
293 
294  public function getRemotePass()
295  {
296  return $this->remote_pass;
297  }
298 
303  public function setRemoteSyncLastExecution(ilDateTime $dt = null)
304  {
305  $this->remote_sync = $dt;
306  }
307 
312  public function getRemoteSyncLastExecution()
313  {
314  if ($this->remote_sync instanceof ilDateTime) {
315  return $this->remote_sync;
316  }
317  return new ilDateTime();
318  }
319 
320 
327  public function add()
328  {
329  global $ilDB;
330 
331  $next_id = $ilDB->nextId('cal_categories');
332 
333  $query = "INSERT INTO cal_categories (cat_id,obj_id,color,type,title,loc_type,remote_url,remote_user,remote_pass,remote_sync) " .
334  "VALUES ( " .
335  $ilDB->quote($next_id, 'integer') . ", " .
336  $this->db->quote($this->getObjId(), 'integer') . ", " .
337  $this->db->quote($this->getColor(), 'text') . ", " .
338  $this->db->quote($this->getType(), 'integer') . ", " .
339  $this->db->quote($this->getTitle(), 'text') . ", " .
340  $this->db->quote($this->getLocationType(), 'integer') . ', ' .
341  $this->db->quote($this->getRemoteUrl(), 'text') . ', ' .
342  $this->db->quote($this->getRemoteUser(), 'text') . ', ' .
343  $this->db->quote($this->getRemotePass(), 'text') . ', ' .
344  $this->db->quote($this->getRemoteSyncLastExecution()->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp') . ' ' .
345  ")";
346 
347  $ilDB->manipulate($query);
348 
349  $this->cat_id = $next_id;
350  return $this->cat_id;
351  }
352 
359  public function update()
360  {
361  global $ilDB;
362 
363  $query = "UPDATE cal_categories " .
364  "SET obj_id = " . $this->db->quote($this->getObjId(), 'integer') . ", " .
365  "color = " . $this->db->quote($this->getColor(), 'text') . ", " .
366  "type = " . $this->db->quote($this->getType(), 'integer') . ", " .
367  "title = " . $this->db->quote($this->getTitle(), 'text') . ", " .
368  "loc_type = " . $this->db->quote($this->getLocationType(), 'integer') . ', ' .
369  "remote_url = " . $this->db->quote($this->getRemoteUrl(), 'text') . ', ' .
370  "remote_user = " . $this->db->quote($this->getRemoteUser(), 'text') . ', ' .
371  "remote_pass = " . $this->db->quote($this->getRemotePass(), 'text') . ', ' .
372  'remote_sync = ' . $this->db->quote($this->getRemoteSyncLastExecution()->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp') . ' ' .
373  "WHERE cat_id = " . $this->db->quote($this->cat_id, 'integer') . " ";
374  $res = $ilDB->manipulate($query);
375  return true;
376  }
377 
384  public function delete()
385  {
386  global $ilDB;
387 
388  $query = "DELETE FROM cal_categories " .
389  "WHERE cat_id = " . $this->db->quote($this->cat_id, 'integer') . " ";
390  $res = $ilDB->manipulate($query);
391 
392  include_once('./Services/Calendar/classes/class.ilCalendarVisibility.php');
394 
395  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
396  foreach (ilCalendarCategoryAssignments::_getAssignedAppointments(array($this->cat_id)) as $app_id) {
397  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
398  ilCalendarEntry::_delete($app_id);
399  }
401  }
402 
409  public function validate()
410  {
411  if ($this->getLocationType() == ilCalendarCategory::LTYPE_REMOTE and !$this->getRemoteUrl()) {
412  return false;
413  }
414  if (strlen($this->getTitle()) and strlen($this->getColor()) and $this->getType()) {
415  return true;
416  }
417  return false;
418  }
419 
425  private function read()
426  {
427  global $ilDB;
428 
429  if (!$this->cat_id) {
430  return true;
431  }
432 
433  $query = "SELECT * FROM cal_categories " .
434  "WHERE cat_id = " . $this->db->quote($this->getCategoryID(), 'integer') . " ";
435  $res = $this->db->query($query);
436  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
437  $this->cat_id = $row->cat_id;
438  $this->obj_id = $row->obj_id;
439  $this->type = $row->type;
440  $this->color = $row->color;
441  $this->title = $row->title;
442  $this->location = $row->loc_type;
443  $this->remote_url = $row->remote_url;
444  $this->remote_user = $row->remote_user;
445  $this->remote_pass = $row->remote_pass;
446 
447  if ($row->remote_sync) {
448  $this->remote_sync = new ilDateTime($row->remote_sync, IL_CAL_DATETIME, 'UTC');
449  } else {
450  $this->remote_sync = new ilDateTime();
451  }
452  }
453  if ($this->getType() == self::TYPE_OBJ) {
454  $this->title = ilObject::_lookupTitle($this->getObjId());
455  $this->obj_type = ilObject::_lookupType($this->getObjId());
456  }
457  }
458 }
static lookupCategorySortIndex($a_type_id)
Lookup sort index of calendar type.
const IL_CAL_DATETIME
static _deleteCategories($a_cat_id)
delete by category
setObjId($a_obj_id)
set obj id
setColor($a_color)
set color
getRemoteSyncLastExecution()
Get last execution date of remote sync.
static _lookupTitle($a_id)
lookup object title
Stores calendar categories.
__construct($a_cat_id=0)
Constructor.
$a_type
Definition: workflow.php:92
static _delete($a_entry_id)
delete entry
Set the worksheet tab color
static lookupAppointments($a_category_id)
get all assigned appointment ids
foreach($_POST as $key=> $value) $res
static _getInstanceByObjId($a_obj_id)
get instance by obj_id
Date and time handling
$query
static getInstanceByCategoryId($a_cat_id)
Get instance by category id.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _deleteByCategoryId($a_cat_id)
Delete assignments by category id.
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
setTitle($a_title)
set title
global $ilDB
getCategoryID()
get category id
setRemoteSyncLastExecution(ilDateTime $dt=null)
Set remote sync last execution.