ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarCategoryAssignments.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 
33 {
34  protected $db;
35 
36  protected $cal_entry_id = 0;
37  protected $assignments = array();
38 
45  public function __construct($a_cal_entry_id)
46  {
47  global $ilDB;
48 
49  $this->db = $ilDB;
50  $this->cal_entry_id = $a_cal_entry_id;
51 
52  $this->read();
53  }
54 
63  public static function _lookupCategories($a_cal_id)
64  {
65  global $ilDB;
66 
67  $query = "SELECT cat_id FROM cal_cat_assignments ".
68  "WHERE cal_id = ".$ilDB->quote($a_cal_id ,'integer')." ";
69  $res = $ilDB->query($query);
70  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
71  {
72  $cat_ids[] = $row->cat_id;
73  }
74  return $cat_ids ? $cat_ids : array();
75  }
76 
85  public static function _lookupCategory($a_cal_id)
86  {
87  if(count($cats = self::_lookupCategories($a_cal_id)))
88  {
89  return $cats[0];
90  }
91  return 0;
92  }
93 
101  public static function _getAppointmentCalendars($a_cal_ids)
102  {
103  global $ilDB;
104 
105  $query = "SELECT * FROM cal_cat_assignments ".
106  "WHERE ".$ilDB->in('cal_id',$a_cal_ids,false,'integer');
107  $res = $ilDB->query($query);
108  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
109  {
110  $map[$row->cal_id] = $row->cat_id;
111  }
112  return $map ? $map : array();
113  }
114 
122  public static function _getAssignedAppointments($a_cat_id)
123  {
124  global $ilDB;
125 
126  $query = "SELECT * FROM cal_cat_assignments ".
127  "WHERE ".$ilDB->in('cat_id',$a_cat_id,false,'integer');
128 
129  $res = $ilDB->query($query);
130  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
131  {
132  $cal_ids[] = $row->cal_id;
133  }
134  return $cal_ids ? $cal_ids : array();
135  }
136 
145  public static function _getAutoGeneratedAppointmentsByObjId($a_obj_id)
146  {
147  global $ilDB;
148 
149  $query = "SELECT ce.cal_id FROM cal_categories cc ".
150  "JOIN cal_cat_assignments cca ON cc.cat_id = cca.cat_id ".
151  "JOIN cal_entries ce ON cca.cal_id = ce.cal_id ".
152  "WHERE auto_generated = 1 ".
153  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
154  $res = $ilDB->query($query);
155  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
156  {
157  $apps[] = $row->cal_id;
158  }
159  return $apps ? $apps : array();
160  }
161 
169  public static function _deleteByAppointmentId($a_app_id)
170  {
171  global $ilDB;
172 
173  $query = "DELETE FROM cal_cat_assignments ".
174  "WHERE cal_id = ".$ilDB->quote($a_app_id ,'integer')." ";
175  $res = $ilDB->manipulate($query);
176 
177  return true;
178  }
179 
188  public static function _deleteByCategoryId($a_cat_id)
189  {
190  global $ilDB;
191 
192  $query = "DELETE FROM cal_cat_assignments ".
193  "WHERE cat_id = ".$ilDB->quote($a_cat_id ,'integer')." ";
194  $res = $ilDB->manipulate($query);
195  return true;
196  }
197 
204  public function getFirstAssignment()
205  {
206  return isset($this->assignments[0]) ? $this->assignments[0] : false;
207  }
208 
215  public function getAssignments()
216  {
217  return $this->assignments ? $this->assignments : array();
218  }
219 
227  public function addAssignment($a_cal_cat_id)
228  {
229  global $ilDB;
230 
231  $query = "INSERT INTO cal_cat_assignments (cal_id,cat_id) ".
232  "VALUES ( ".
233  $this->db->quote($this->cal_entry_id ,'integer').", ".
234  $this->db->quote($a_cal_cat_id ,'integer')." ".
235  ")";
236  $res = $ilDB->manipulate($query);
237  $this->assignments[] = (int) $a_cal_cat_id;
238 
239  return true;
240  }
241 
249  public function deleteAssignment($a_cat_id)
250  {
251  global $ilDB;
252 
253  $query = "DELETE FROM cal_cat_assignments ".
254  "WHERE cal_id = ".$this->db->quote($this->cal_entry_id ,'integer').", ".
255  "AND cat_id = ".$this->db->quote($a_cat_id ,'integer')." ";
256  $res = $ilDB->manipulate($query);
257 
258  if(($key = array_search($a_cat_id,$this->assignments)) !== false)
259  {
260  unset($this->assignments[$key]);
261  }
262  return true;
263  }
264 
270  public function deleteAssignments()
271  {
272  global $ilDB;
273 
274  $query = "DELETE FROM cal_cat_assignments ".
275  "WHERE cal_id = ".$this->db->quote($this->cal_entry_id ,'integer')." ";
276  $res = $ilDB->manipulate($query);
277  return true;
278  }
279 
280 
287  private function read()
288  {
289  global $ilDB;
290 
291  $query = "SELECT * FROM cal_cat_assignments ".
292  "WHERE cal_id = ".$this->db->quote($this->cal_entry_id ,'integer')." ";
293 
294  $res = $this->db->query($query);
295  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
296  {
297  $this->assignments[] = $row->cat_id;
298  }
299  }
300 }
301 ?>