ILIAS  release_4-3 Revision
 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 
141  public static function lookupNumberOfAssignedAppointments($a_cat_ids)
142  {
143  global $ilDB;
144 
145  $query = 'SELECT COUNT(*) num FROM cal_cat_assignments '.
146  'WHERE '.$ilDB->in('cat_id', $a_cat_ids, false, 'integer');
147  $res = $ilDB->query($query);
148  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
149  {
150  return $row->num;
151  }
152  return 0;
153  }
154 
163  public static function _getAutoGeneratedAppointmentsByObjId($a_obj_id)
164  {
165  global $ilDB;
166 
167  $query = "SELECT ce.cal_id FROM cal_categories cc ".
168  "JOIN cal_cat_assignments cca ON cc.cat_id = cca.cat_id ".
169  "JOIN cal_entries ce ON cca.cal_id = ce.cal_id ".
170  "WHERE auto_generated = 1 ".
171  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
172  $res = $ilDB->query($query);
173  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
174  {
175  $apps[] = $row->cal_id;
176  }
177  return $apps ? $apps : array();
178  }
179 
187  public static function _deleteByAppointmentId($a_app_id)
188  {
189  global $ilDB;
190 
191  $query = "DELETE FROM cal_cat_assignments ".
192  "WHERE cal_id = ".$ilDB->quote($a_app_id ,'integer')." ";
193  $res = $ilDB->manipulate($query);
194 
195  return true;
196  }
197 
206  public static function _deleteByCategoryId($a_cat_id)
207  {
208  global $ilDB;
209 
210  $query = "DELETE FROM cal_cat_assignments ".
211  "WHERE cat_id = ".$ilDB->quote($a_cat_id ,'integer')." ";
212  $res = $ilDB->manipulate($query);
213  return true;
214  }
215 
222  public function getFirstAssignment()
223  {
224  return isset($this->assignments[0]) ? $this->assignments[0] : false;
225  }
226 
233  public function getAssignments()
234  {
235  return $this->assignments ? $this->assignments : array();
236  }
237 
245  public function addAssignment($a_cal_cat_id)
246  {
247  global $ilDB;
248 
249  $query = "INSERT INTO cal_cat_assignments (cal_id,cat_id) ".
250  "VALUES ( ".
251  $this->db->quote($this->cal_entry_id ,'integer').", ".
252  $this->db->quote($a_cal_cat_id ,'integer')." ".
253  ")";
254  $res = $ilDB->manipulate($query);
255  $this->assignments[] = (int) $a_cal_cat_id;
256 
257  return true;
258  }
259 
267  public function deleteAssignment($a_cat_id)
268  {
269  global $ilDB;
270 
271  $query = "DELETE FROM cal_cat_assignments ".
272  "WHERE cal_id = ".$this->db->quote($this->cal_entry_id ,'integer').", ".
273  "AND cat_id = ".$this->db->quote($a_cat_id ,'integer')." ";
274  $res = $ilDB->manipulate($query);
275 
276  if(($key = array_search($a_cat_id,$this->assignments)) !== false)
277  {
278  unset($this->assignments[$key]);
279  }
280  return true;
281  }
282 
288  public function deleteAssignments()
289  {
290  global $ilDB;
291 
292  $query = "DELETE FROM cal_cat_assignments ".
293  "WHERE cal_id = ".$this->db->quote($this->cal_entry_id ,'integer')." ";
294  $res = $ilDB->manipulate($query);
295  return true;
296  }
297 
298 
305  private function read()
306  {
307  global $ilDB;
308 
309  $query = "SELECT * FROM cal_cat_assignments ".
310  "WHERE cal_id = ".$this->db->quote($this->cal_entry_id ,'integer')." ";
311 
312  $res = $this->db->query($query);
313  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
314  {
315  $this->assignments[] = $row->cat_id;
316  }
317  }
318 }
319 ?>