ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilECSCourseMemberAssignment.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
10{
11 const STATUS_ASSIGNED = 0;
13
14 private $id;
15 private $server;
16 private $mid;
17 private $cms_id;
18 private $cms_sub_id = 0;
19 private $obj_id;
20 private $uid;
21 private $status = 0;
22
23
27 public function __construct($a_id = 0)
28 {
29 $this->id = $a_id;
30
31 $this->read();
32 }
33
40 public static function lookupMissingAssignmentsOfUser($a_usr_id)
41 {
42 global $DIC;
43
44 $ilDB = $DIC['ilDB'];
45
46 $query = 'SELECT id FROM ecs_course_assignments ' .
47 'WHERE usr_id = ' . $ilDB->quote($a_usr_id, 'text');
48 $res = $ilDB->query($query);
49
50 $obj_ids = array();
51
52 $assignments = array();
53 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
54 $assignments[] = new self($row->id);
55 }
56 return $assignments;
57 }
58
62 public static function deleteByObjId($a_obj_id)
63 {
64 global $DIC;
65
66 $ilDB = $DIC['ilDB'];
67
68 $query = 'DELETE FROM ecs_course_assignments ' .
69 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
70 $ilDB->manipulate($query);
71 return true;
72 }
73
80 public static function deleteByServerId($a_server_id)
81 {
82 global $DIC;
83
84 $ilDB = $DIC['ilDB'];
85
86 $query = 'DELETE FROM ecs_course_assignments ' .
87 'WHERE sid = ' . $ilDB->quote($a_server_id, 'integer');
88 $ilDB->manipulate($query);
89 return true;
90 }
91
99 public static function lookupUserIds($a_cms_id, $a_cms_sub_id, $a_obj_id)
100 {
101 global $DIC;
102
103 $ilDB = $DIC['ilDB'];
104
105 $cms_sub_id_query = '';
106
107 if (is_null($a_cms_sub_id)) {
108 $cms_sub_id_query = 'AND cms_sub_id IS NULL ';
109 } else {
110 $cms_sub_id_query = 'AND cms_sub_id = ' . $ilDB->quote($a_cms_sub_id, 'integer') . ' ';
111 }
112
113 $query = 'SELECT usr_id FROM ecs_course_assignments ' .
114 'WHERE cms_id = ' . $ilDB->quote($a_cms_id, 'integer') . ' ' .
115 $cms_sub_id_query .
116 'AND obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
117 $res = $ilDB->query($query);
118
119 $usr_ids = array();
120 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
121 $usr_ids[] = $row->usr_id;
122 }
123 return $usr_ids;
124 }
125
134 public static function lookupAssignment($a_cms_id, $a_cms_sub_id, $a_obj_id, $a_usr_id)
135 {
136 global $DIC;
137
138 $ilDB = $DIC['ilDB'];
139
140 $cms_sub_id_query = '';
141 if (is_null($a_cms_sub_id)) {
142 $cms_sub_id_query = 'AND cms_sub_id IS NULL ';
143 } else {
144 $cms_sub_id_query = 'AND cms_sub_id = ' . $ilDB->quote($a_cms_sub_id, 'integer') . ' ';
145 }
146
147 $query = 'SELECT id FROM ecs_course_assignments ' .
148 'WHERE cms_id = ' . $ilDB->quote($a_cms_id, 'integer') . ' ' .
149 $cms_sub_id_query .
150 'AND obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
151 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'text');
152 $res = $ilDB->query($query);
153 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
154 return new ilECSCourseMemberAssignment($row->id);
155 }
156 return null;
157 }
158
159
160 public function getId()
161 {
162 return $this->id;
163 }
164
169 public function setServer($a_server)
170 {
171 $this->server = $a_server;
172 }
173
178 public function getServer()
179 {
180 return $this->server;
181 }
182
183 public function setMid($a_mid)
184 {
185 $this->mid = $a_mid;
186 }
187
188 public function getMid()
189 {
190 return $this->mid;
191 }
192
193 public function setCmsId($a_id)
194 {
195 $this->cms_id = $a_id;
196 }
197
198 public function getCmsId()
199 {
200 return $this->cms_id;
201 }
202
203 public function setCmsSubId($a_id)
204 {
205 $this->cms_sub_id = $a_id;
206 }
207
208 public function getCmsSubId()
209 {
210 return $this->cms_sub_id;
211 }
212
213 public function setObjId($a_id)
214 {
215 $this->obj_id = $a_id;
216 }
217
218 public function getObjId()
219 {
220 return $this->obj_id;
221 }
222
223 public function setUid($a_id)
224 {
225 $this->uid = $a_id;
226 }
227
228 public function getUid()
229 {
230 return $this->uid;
231 }
232
233 public function setStatus($a_status)
234 {
235 $this->status = $a_status;
236 }
237
238 public function getStatus()
239 {
240 return $this->status;
241 }
242
247 public function save()
248 {
249 global $DIC;
250
251 $ilDB = $DIC['ilDB'];
252
253 $this->id = $ilDB->nextId('ecs_course_assignments');
254
255
256 $assignment = self::lookupAssignment(
257 $this->getCmsId(),
258 $this->getCmsSubId(),
259 $this->getObjId(),
260 $this->getUid()
261 );
262 if ($assignment instanceof ilECSCourseMemberAssignment) {
263 $assignment->update();
264 return true;
265 }
266
267 $query = 'INSERT INTO ecs_course_assignments ' .
268 '(id,sid,mid,cms_id,cms_sub_id,obj_id,usr_id,status) ' .
269 'VALUES( ' .
270 $ilDB->quote($this->getId(), 'integer') . ', ' .
271 $ilDB->quote($this->getServer(), 'integer') . ', ' .
272 $ilDB->quote($this->getMid(), 'integer') . ', ' .
273 $ilDB->quote($this->getCmsId(), 'integer') . ', ' .
274 $ilDB->quote($this->getCmsSubId(), 'integer') . ', ' .
275 $ilDB->quote($this->getObjId(), 'integer') . ', ' .
276 $ilDB->quote($this->getUid(), 'text') . ', ' .
277 $ilDB->quote($this->getStatus(), 'integer') . ' ' .
278 ')';
279 $ilDB->manipulate($query);
280 }
281
287 public function update()
288 {
289 global $DIC;
290
291 $ilDB = $DIC['ilDB'];
292
293 $query = 'UPDATE ecs_course_assignments ' .
294 'SET ' .
295 'sid = ' . $ilDB->quote($this->getServer(), 'integer') . ', ' .
296 'mid = ' . $ilDB->quote($this->getMid(), 'integer') . ', ' .
297 'cms_id = ' . $ilDB->quote($this->getCmsId(), 'integer') . ', ' .
298 'cms_sub_id = ' . $ilDB->quote($this->getCmsSubId(), 'integer') . ', ' .
299 'obj_id = ' . $ilDB->quote($this->getObjId(), 'integer') . ', ' .
300 'usr_id = ' . $ilDB->quote($this->getUid(), 'text') . ', ' .
301 'status = ' . $ilDB->quote($this->getStatus(), 'integer') . ' ' .
302 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
303 $ilDB->manipulate($query);
304 return true;
305 }
306
310 public function delete()
311 {
312 global $DIC;
313
314 $ilDB = $DIC['ilDB'];
315
316 $query = 'DELETE FROM ecs_course_assignments ' .
317 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
318 $ilDB->manipulate($query);
319 return true;
320 }
321
322
323
328 protected function read()
329 {
330 global $DIC;
331
332 $ilDB = $DIC['ilDB'];
333
334 if (!$this->getId()) {
335 return false;
336 }
337
338 $query = 'SELECT * FROM ecs_course_assignments ' .
339 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
340 $res = $ilDB->query($query);
341 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
342 $this->setServer($row->sid);
343 $this->setMid($row->mid);
344 $this->setCmsId($row->cms_id);
345 $this->setCmsSubId($row->cms_sub_id);
346 $this->setObjId($row->obj_id);
347 $this->setUid($row->usr_id);
348 $this->setStatus($row->status);
349 }
350 }
351}
An exception for terminatinating execution or to throw for unit testing.
Storage of ecs course assignments.
static lookupAssignment($a_cms_id, $a_cms_sub_id, $a_obj_id, $a_usr_id)
Lookup assignment of user @global type $ilDB.
save()
Save new entry @global type $ilDB.
static deleteByServerId($a_server_id)
Delete by server id @global type $ilDB.
static lookupMissingAssignmentsOfUser($a_usr_id)
Lookup missing assignments; @global type $ilDB.
static deleteByObjId($a_obj_id)
Delete by obj_id.
static lookupUserIds($a_cms_id, $a_cms_sub_id, $a_obj_id)
Lookup user ids @global type $ilDB.
update()
Update assignemt @global type $ilDB.
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46