ILIAS  release_8 Revision v8.24
class.ilCalendarCategoryAssignments.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
31{
32 protected ilDBInterface $db;
33
34 protected int $cal_entry_id = 0;
35 protected array $assignments = [];
36
37 public function __construct(int $a_cal_entry_id)
38 {
39 global $DIC;
40
41 $this->db = $DIC->database();
42 $this->cal_entry_id = $a_cal_entry_id;
43 $this->read();
44 }
45
46 public static function _lookupCategories(int $a_cal_id): array
47 {
48 global $DIC;
49
50 $ilDB = $DIC['ilDB'];
51 $query = "SELECT cat_id FROM cal_cat_assignments " .
52 "WHERE cal_id = " . $ilDB->quote($a_cal_id, 'integer') . " ";
53 $res = $ilDB->query($query);
54 $cat_ids = [];
55 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
56 $cat_ids[] = (int) $row->cat_id;
57 }
58 return $cat_ids;
59 }
60
61 public static function _lookupCategory(int $a_cal_id): int
62 {
63 if (count($cats = self::_lookupCategories($a_cal_id))) {
64 return $cats[0];
65 }
66 return 0;
67 }
68
73 public static function _getAppointmentCalendars(array $a_cal_ids): array
74 {
75 global $DIC;
76
77 $ilDB = $DIC['ilDB'];
78 $query = "SELECT * FROM cal_cat_assignments " .
79 "WHERE " . $ilDB->in('cal_id', $a_cal_ids, false, 'integer');
80 $res = $ilDB->query($query);
81 $map = [];
82 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
83 $map[(int) $row->cal_id] = (int) $row->cat_id;
84 }
85 return $map;
86 }
87
93 public static function _getAssignedAppointments(array $a_cat_id): array
94 {
95 global $DIC;
96
97 $ilDB = $DIC['ilDB'];
98 $query = "SELECT * FROM cal_cat_assignments " .
99 "WHERE " . $ilDB->in('cat_id', $a_cat_id, false, 'integer');
100
101 $res = $ilDB->query($query);
102 $cal_ids = [];
103 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
104 $cal_ids[] = (int) $row->cal_id;
105 }
106 return $cal_ids;
107 }
108
113 public static function lookupNumberOfAssignedAppointments(array $a_cat_ids): int
114 {
115 global $DIC;
116
117 $ilDB = $DIC['ilDB'];
118 $query = 'SELECT COUNT(*) num FROM cal_cat_assignments ' .
119 'WHERE ' . $ilDB->in('cat_id', $a_cat_ids, false, 'integer');
120 $res = $ilDB->query($query);
121 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
122 return (int) $row->num;
123 }
124 return 0;
125 }
126
131 public static function _getAutoGeneratedAppointmentsByObjId(int $a_obj_id): array
132 {
133 global $DIC;
134
135 $ilDB = $DIC['ilDB'];
136 $query = "SELECT ce.cal_id FROM cal_categories cc " .
137 "JOIN cal_cat_assignments cca ON cc.cat_id = cca.cat_id " .
138 "JOIN cal_entries ce ON cca.cal_id = ce.cal_id " .
139 "WHERE auto_generated = 1 " .
140 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
141 $res = $ilDB->query($query);
142 $apps = [];
143 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
144 $apps[] = (int) $row->cal_id;
145 }
146 return $apps;
147 }
148
152 public static function _deleteByAppointmentId(int $a_app_id): void
153 {
154 global $DIC;
155
156 $ilDB = $DIC['ilDB'];
157 $query = "DELETE FROM cal_cat_assignments " .
158 "WHERE cal_id = " . $ilDB->quote($a_app_id, 'integer') . " ";
159 $res = $ilDB->manipulate($query);
160 }
161
169 public static function _deleteByCategoryId(int $a_cat_id): void
170 {
171 global $DIC;
172
173 $ilDB = $DIC['ilDB'];
174 $query = "DELETE FROM cal_cat_assignments " .
175 "WHERE cat_id = " . $ilDB->quote($a_cat_id, 'integer') . " ";
176 $res = $ilDB->manipulate($query);
177 }
178
182 public function getFirstAssignment(): ?int
183 {
184 return $this->assignments[0] ?? null;
185 }
186
190 public function getAssignments(): array
191 {
192 return $this->assignments;
193 }
194
195 public function addAssignment(int $a_cal_cat_id): void
196 {
197 $query = "INSERT INTO cal_cat_assignments (cal_id,cat_id) " .
198 "VALUES ( " .
199 $this->db->quote($this->cal_entry_id, 'integer') . ", " .
200 $this->db->quote($a_cal_cat_id, 'integer') . " " .
201 ")";
202 $res = $this->db->manipulate($query);
203 $this->assignments[] = $a_cal_cat_id;
204 }
205
206 public function deleteAssignment(int $a_cat_id): void
207 {
208 $query = "DELETE FROM cal_cat_assignments " .
209 "WHERE cal_id = " . $this->db->quote($this->cal_entry_id, 'integer') . ", " .
210 "AND cat_id = " . $this->db->quote($a_cat_id, 'integer') . " ";
211 $res = $this->db->manipulate($query);
212
213 if (($key = array_search($a_cat_id, $this->assignments)) !== false) {
214 unset($this->assignments[$key]);
215 }
216 }
217
218 public function deleteAssignments(): void
219 {
220 $query = "DELETE FROM cal_cat_assignments " .
221 "WHERE cal_id = " . $this->db->quote($this->cal_entry_id, 'integer') . " ";
222 $res = $this->db->manipulate($query);
223 }
224
225 private function read()
226 {
227 $query = "SELECT * FROM cal_cat_assignments " .
228 "WHERE cal_id = " . $this->db->quote($this->cal_entry_id, 'integer') . " ";
229
230 $res = $this->db->query($query);
231 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
232 $this->assignments[] = (int) $row->cat_id;
233 }
234 }
235}
static _getAutoGeneratedAppointmentsByObjId(int $a_obj_id)
get automatic generated appointments of category
static _deleteByCategoryId(int $a_cat_id)
Delete assignments by category id @access public.
static _getAssignedAppointments(array $a_cat_id)
Get assigned apointments.
static _deleteByAppointmentId(int $a_app_id)
Delete appointment assignment.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
string $key
Consumer key/client ID value.
Definition: System.php:193
$query