ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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(ilDBConstants::FETCHMODE_OBJECT)) {
71  $cat_ids[] = $row->cat_id;
72  }
73  return $cat_ids ? $cat_ids : array();
74  }
75 
84  public static function _lookupCategory($a_cal_id)
85  {
86  if (count($cats = self::_lookupCategories($a_cal_id))) {
87  return $cats[0];
88  }
89  return 0;
90  }
91 
99  public static function _getAppointmentCalendars($a_cal_ids)
100  {
101  global $ilDB;
102 
103  $query = "SELECT * FROM cal_cat_assignments " .
104  "WHERE " . $ilDB->in('cal_id', $a_cal_ids, false, 'integer');
105  $res = $ilDB->query($query);
106  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
107  $map[$row->cal_id] = $row->cat_id;
108  }
109  return $map ? $map : array();
110  }
111 
119  public static function _getAssignedAppointments($a_cat_id)
120  {
121  global $ilDB;
122 
123  $query = "SELECT * FROM cal_cat_assignments " .
124  "WHERE " . $ilDB->in('cat_id', $a_cat_id, false, 'integer');
125 
126  $res = $ilDB->query($query);
127  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
128  $cal_ids[] = $row->cal_id;
129  }
130  return $cal_ids ? $cal_ids : array();
131  }
132 
137  public static function lookupNumberOfAssignedAppointments($a_cat_ids)
138  {
139  global $ilDB;
140 
141  $query = 'SELECT COUNT(*) num FROM cal_cat_assignments ' .
142  'WHERE ' . $ilDB->in('cat_id', $a_cat_ids, false, 'integer');
143  $res = $ilDB->query($query);
144  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
145  return $row->num;
146  }
147  return 0;
148  }
149 
158  public static function _getAutoGeneratedAppointmentsByObjId($a_obj_id)
159  {
160  global $ilDB;
161 
162  $query = "SELECT ce.cal_id FROM cal_categories cc " .
163  "JOIN cal_cat_assignments cca ON cc.cat_id = cca.cat_id " .
164  "JOIN cal_entries ce ON cca.cal_id = ce.cal_id " .
165  "WHERE auto_generated = 1 " .
166  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
167  $res = $ilDB->query($query);
168  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
169  $apps[] = $row->cal_id;
170  }
171  return $apps ? $apps : array();
172  }
173 
181  public static function _deleteByAppointmentId($a_app_id)
182  {
183  global $ilDB;
184 
185  $query = "DELETE FROM cal_cat_assignments " .
186  "WHERE cal_id = " . $ilDB->quote($a_app_id, 'integer') . " ";
187  $res = $ilDB->manipulate($query);
188 
189  return true;
190  }
191 
200  public static function _deleteByCategoryId($a_cat_id)
201  {
202  global $ilDB;
203 
204  $query = "DELETE FROM cal_cat_assignments " .
205  "WHERE cat_id = " . $ilDB->quote($a_cat_id, 'integer') . " ";
206  $res = $ilDB->manipulate($query);
207  return true;
208  }
209 
216  public function getFirstAssignment()
217  {
218  return isset($this->assignments[0]) ? $this->assignments[0] : false;
219  }
220 
227  public function getAssignments()
228  {
229  return $this->assignments ? $this->assignments : array();
230  }
231 
239  public function addAssignment($a_cal_cat_id)
240  {
241  global $ilDB;
242 
243  $query = "INSERT INTO cal_cat_assignments (cal_id,cat_id) " .
244  "VALUES ( " .
245  $this->db->quote($this->cal_entry_id, 'integer') . ", " .
246  $this->db->quote($a_cal_cat_id, 'integer') . " " .
247  ")";
248  $res = $ilDB->manipulate($query);
249  $this->assignments[] = (int) $a_cal_cat_id;
250 
251  return true;
252  }
253 
261  public function deleteAssignment($a_cat_id)
262  {
263  global $ilDB;
264 
265  $query = "DELETE FROM cal_cat_assignments " .
266  "WHERE cal_id = " . $this->db->quote($this->cal_entry_id, 'integer') . ", " .
267  "AND cat_id = " . $this->db->quote($a_cat_id, 'integer') . " ";
268  $res = $ilDB->manipulate($query);
269 
270  if (($key = array_search($a_cat_id, $this->assignments)) !== false) {
271  unset($this->assignments[$key]);
272  }
273  return true;
274  }
275 
281  public function deleteAssignments()
282  {
283  global $ilDB;
284 
285  $query = "DELETE FROM cal_cat_assignments " .
286  "WHERE cal_id = " . $this->db->quote($this->cal_entry_id, 'integer') . " ";
287  $res = $ilDB->manipulate($query);
288  return true;
289  }
290 
291 
298  private function read()
299  {
300  global $ilDB;
301 
302  $query = "SELECT * FROM cal_cat_assignments " .
303  "WHERE cal_id = " . $this->db->quote($this->cal_entry_id, 'integer') . " ";
304 
305  $res = $this->db->query($query);
306  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
307  $this->assignments[] = $row->cat_id;
308  }
309  }
310 }
static _lookupCategory($a_cal_id)
Lookup category id.
static lookupNumberOfAssignedAppointments($a_cat_ids)
Get number of assigned appoitments.
static _lookupCategories($a_cal_id)
lookup categories
foreach($_POST as $key=> $value) $res
static _getAutoGeneratedAppointmentsByObjId($a_obj_id)
get automatic generated appointments of category
$query
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
Create styles array
The data for the language used.
static _deleteByCategoryId($a_cat_id)
Delete assignments by category id.
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
global $ilDB
$key
Definition: croninfo.php:18
static _getAppointmentCalendars($a_cal_ids)
lookup calendars for appointment ids