ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $DIC;
48
49 $ilDB = $DIC['ilDB'];
50
51 $this->db = $ilDB;
52 $this->cal_entry_id = $a_cal_entry_id;
53
54 $this->read();
55 }
56
65 public static function _lookupCategories($a_cal_id)
66 {
67 global $DIC;
68
69 $ilDB = $DIC['ilDB'];
70
71 $query = "SELECT cat_id FROM cal_cat_assignments " .
72 "WHERE cal_id = " . $ilDB->quote($a_cal_id, 'integer') . " ";
73 $res = $ilDB->query($query);
74 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
75 $cat_ids[] = $row->cat_id;
76 }
77 return $cat_ids ? $cat_ids : array();
78 }
79
88 public static function _lookupCategory($a_cal_id)
89 {
90 if (count($cats = self::_lookupCategories($a_cal_id))) {
91 return $cats[0];
92 }
93 return 0;
94 }
95
103 public static function _getAppointmentCalendars($a_cal_ids)
104 {
105 global $DIC;
106
107 $ilDB = $DIC['ilDB'];
108
109 $query = "SELECT * FROM cal_cat_assignments " .
110 "WHERE " . $ilDB->in('cal_id', $a_cal_ids, false, 'integer');
111 $res = $ilDB->query($query);
112 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
113 $map[$row->cal_id] = $row->cat_id;
114 }
115 return $map ? $map : array();
116 }
117
125 public static function _getAssignedAppointments($a_cat_id)
126 {
127 global $DIC;
128
129 $ilDB = $DIC['ilDB'];
130
131 $query = "SELECT * FROM cal_cat_assignments " .
132 "WHERE " . $ilDB->in('cat_id', $a_cat_id, false, 'integer');
133
134 $res = $ilDB->query($query);
135 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
136 $cal_ids[] = $row->cal_id;
137 }
138 return $cal_ids ? $cal_ids : array();
139 }
140
145 public static function lookupNumberOfAssignedAppointments($a_cat_ids)
146 {
147 global $DIC;
148
149 $ilDB = $DIC['ilDB'];
150
151 $query = 'SELECT COUNT(*) num FROM cal_cat_assignments ' .
152 'WHERE ' . $ilDB->in('cat_id', $a_cat_ids, false, 'integer');
153 $res = $ilDB->query($query);
154 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
155 return $row->num;
156 }
157 return 0;
158 }
159
168 public static function _getAutoGeneratedAppointmentsByObjId($a_obj_id)
169 {
170 global $DIC;
171
172 $ilDB = $DIC['ilDB'];
173
174 $query = "SELECT ce.cal_id FROM cal_categories cc " .
175 "JOIN cal_cat_assignments cca ON cc.cat_id = cca.cat_id " .
176 "JOIN cal_entries ce ON cca.cal_id = ce.cal_id " .
177 "WHERE auto_generated = 1 " .
178 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
179 $res = $ilDB->query($query);
180 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
181 $apps[] = $row->cal_id;
182 }
183 return $apps ? $apps : array();
184 }
185
193 public static function _deleteByAppointmentId($a_app_id)
194 {
195 global $DIC;
196
197 $ilDB = $DIC['ilDB'];
198
199 $query = "DELETE FROM cal_cat_assignments " .
200 "WHERE cal_id = " . $ilDB->quote($a_app_id, 'integer') . " ";
201 $res = $ilDB->manipulate($query);
202
203 return true;
204 }
205
214 public static function _deleteByCategoryId($a_cat_id)
215 {
216 global $DIC;
217
218 $ilDB = $DIC['ilDB'];
219
220 $query = "DELETE FROM cal_cat_assignments " .
221 "WHERE cat_id = " . $ilDB->quote($a_cat_id, 'integer') . " ";
222 $res = $ilDB->manipulate($query);
223 return true;
224 }
225
232 public function getFirstAssignment()
233 {
234 return isset($this->assignments[0]) ? $this->assignments[0] : false;
235 }
236
243 public function getAssignments()
244 {
245 return $this->assignments ? $this->assignments : array();
246 }
247
255 public function addAssignment($a_cal_cat_id)
256 {
257 global $DIC;
258
259 $ilDB = $DIC['ilDB'];
260
261 $query = "INSERT INTO cal_cat_assignments (cal_id,cat_id) " .
262 "VALUES ( " .
263 $this->db->quote($this->cal_entry_id, 'integer') . ", " .
264 $this->db->quote($a_cal_cat_id, 'integer') . " " .
265 ")";
266 $res = $ilDB->manipulate($query);
267 $this->assignments[] = (int) $a_cal_cat_id;
268
269 return true;
270 }
271
279 public function deleteAssignment($a_cat_id)
280 {
281 global $DIC;
282
283 $ilDB = $DIC['ilDB'];
284
285 $query = "DELETE FROM cal_cat_assignments " .
286 "WHERE cal_id = " . $this->db->quote($this->cal_entry_id, 'integer') . ", " .
287 "AND cat_id = " . $this->db->quote($a_cat_id, 'integer') . " ";
288 $res = $ilDB->manipulate($query);
289
290 if (($key = array_search($a_cat_id, $this->assignments)) !== false) {
291 unset($this->assignments[$key]);
292 }
293 return true;
294 }
295
301 public function deleteAssignments()
302 {
303 global $DIC;
304
305 $ilDB = $DIC['ilDB'];
306
307 $query = "DELETE FROM cal_cat_assignments " .
308 "WHERE cal_id = " . $this->db->quote($this->cal_entry_id, 'integer') . " ";
309 $res = $ilDB->manipulate($query);
310 return true;
311 }
312
313
320 private function read()
321 {
322 global $DIC;
323
324 $ilDB = $DIC['ilDB'];
325
326 $query = "SELECT * FROM cal_cat_assignments " .
327 "WHERE cal_id = " . $this->db->quote($this->cal_entry_id, 'integer') . " ";
328
329 $res = $this->db->query($query);
330 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
331 $this->assignments[] = $row->cat_id;
332 }
333 }
334}
An exception for terminatinating execution or to throw for unit testing.
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
static _lookupCategory($a_cal_id)
Lookup category id.
static lookupNumberOfAssignedAppointments($a_cat_ids)
Get number of assigned appoitments.
static _deleteByAppointmentId($a_app_id)
Delete appointment assignment.
static _lookupCategories($a_cal_id)
lookup categories
static _getAppointmentCalendars($a_cal_ids)
lookup calendars for appointment ids
static _getAutoGeneratedAppointmentsByObjId($a_obj_id)
get automatic generated appointments of category
static _deleteByCategoryId($a_cat_id)
Delete assignments by category id.
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB