ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  private static $instances = null;
36 
37  const DEFAULT_COLOR = '#04427e';
38 
39  const TYPE_USR = 1; // user
40  const TYPE_OBJ = 2; // object
41  const TYPE_GLOBAL = 3; // global
42  const TYPE_CH = 4; // consultation hours
43  const TYPE_BOOK = 5; // booking manager
44 
45  protected $cat_id;
46  protected $color;
47  protected $type = self::TYPE_USR;
48  protected $obj_id;
49  protected $obj_type = null;
50  protected $title;
51 
52  protected $db;
53 
54 
60  public function __construct($a_cat_id = 0)
61  {
62  global $ilDB;
63 
64  $this->db = $ilDB;
65  $this->cat_id = $a_cat_id;
66 
67  $this->read();
68  }
69 
77  public static function _getInstanceByObjId($a_obj_id)
78  {
79  global $ilDB;
80 
81  $query = "SELECT cat_id FROM cal_categories ".
82  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
83  "AND type = ".$ilDB->quote(self::TYPE_OBJ ,'integer');
84  $res = $ilDB->query($query);
85  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
86  {
87  return new ilCalendarCategory($row->cat_id);
88  }
89  return null;
90  }
91 
97  public static function getInstanceByCategoryId($a_cat_id)
98  {
99  if(!self::$instances[$a_cat_id])
100  {
101  return self::$instances[$a_cat_id] = new ilCalendarCategory($a_cat_id);
102  }
103  return self::$instances[$a_cat_id];
104  }
105 
106 
112  public static function lookupAppointments($a_category_id)
113  {
114  global $ilDB;
115 
116  $query = "SELECT * FROM cal_cat_assignments ".
117  'WHERE cat_id = '.$ilDB->quote($a_category_id,'integer');
118  $res = $ilDB->query($query);
119  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
120  {
121  $apps[] = $row->cal_id;
122  }
123  return $apps ? $apps : array();
124  }
125 
126 
133  public function getCategoryID()
134  {
135  return $this->cat_id;
136  }
137 
145  public function setTitle($a_title)
146  {
147  $this->title = $a_title;
148  }
149 
156  public function getTitle()
157  {
158  return $this->title;
159  }
160 
161 
168  public function setColor($a_color)
169  {
170  $this->color = $a_color;
171  }
172 
179  public function getColor()
180  {
181  return $this->color;
182  }
183 
190  public function setType($a_type)
191  {
192  $this->type = $a_type;
193  }
194 
201  public function getType()
202  {
203  return $this->type;
204  }
205 
212  public function setObjId($a_obj_id)
213  {
214  $this->obj_id = $a_obj_id;
215  }
216 
223  public function getObjId()
224  {
225  return $this->obj_id;
226  }
227 
233  public function getObjType()
234  {
235  return $this->obj_type;
236  }
237 
238 
245  public function add()
246  {
247  global $ilDB;
248 
249  $next_id = $ilDB->nextId('cal_categories');
250 
251  $query = "INSERT INTO cal_categories (cat_id,obj_id,color,type,title) ".
252  "VALUES ( ".
253  $ilDB->quote($next_id,'integer').", ".
254  $this->db->quote($this->getObjId() ,'integer').", ".
255  $this->db->quote($this->getColor() ,'text').", ".
256  $this->db->quote($this->getType() ,'integer').", ".
257  $this->db->quote($this->getTitle() ,'text')." ".
258  ")";
259  $res = $ilDB->manipulate($query);
260 
261  $this->cat_id = $next_id;
262  return $this->cat_id;
263  }
264 
271  public function update()
272  {
273  global $ilDB;
274 
275  $query = "UPDATE cal_categories ".
276  "SET obj_id = ".$this->db->quote($this->getObjId() ,'integer').", ".
277  "color = ".$this->db->quote($this->getColor() ,'text').", ".
278  "type = ".$this->db->quote($this->getType() ,'integer').", ".
279  "title = ".$this->db->quote($this->getTitle() ,'text')." ".
280  "WHERE cat_id = ".$this->db->quote($this->cat_id ,'integer')." ";
281  $res = $ilDB->manipulate($query);
282  return true;
283  }
284 
291  public function delete()
292  {
293  global $ilDB;
294 
295  $query = "DELETE FROM cal_categories ".
296  "WHERE cat_id = ".$this->db->quote($this->cat_id ,'integer')." ";
297  $res = $ilDB->manipulate($query);
298 
299  include_once('./Services/Calendar/classes/class.ilCalendarHidden.php');
301 
302  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
303  foreach(ilCalendarCategoryAssignments::_getAssignedAppointments(array($this->cat_id)) as $app_id)
304  {
305  include_once('./Services/Calendar/classes/class.ilCalendarEntry.php');
306  ilCalendarEntry::_delete($app_id);
307  }
309  }
310 
317  public function validate()
318  {
319  return strlen($this->getTitle()) and strlen($this->getColor()) and $this->getType();
320  }
321 
327  private function read()
328  {
329  global $ilDB;
330 
331  if(!$this->cat_id)
332  {
333  return true;
334  }
335 
336  $query = "SELECT * FROM cal_categories ".
337  "WHERE cat_id = ".$this->db->quote($this->getCategoryID() ,'integer')." ";
338  $res = $this->db->query($query);
339  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
340  {
341  $this->cat_id = $row->cat_id;
342  $this->obj_id = $row->obj_id;
343  $this->type = $row->type;
344  $this->color = $row->color;
345  $this->title = $row->title;
346  }
347  if($this->getType() == self::TYPE_OBJ)
348  {
349  $this->title = ilObject::_lookupTitle($this->getObjId());
350  $this->obj_type = ilObject::_lookupType($this->getObjId());
351  }
352  }
353 }
354 ?>