ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
43
44 $query = 'SELECT id FROM ecs_course_assignments ' .
45 'WHERE usr_id = ' . $ilDB->quote($a_usr_id, 'text');
46 $res = $ilDB->query($query);
47
48 $obj_ids = array();
49
50 $assignments = array();
51 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
52 $assignments[] = new self($row->id);
53 }
54 return $assignments;
55 }
56
60 public static function deleteByObjId($a_obj_id)
61 {
62 global $ilDB;
63
64 $query = 'DELETE FROM ecs_course_assignments ' .
65 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
66 $ilDB->manipulate($query);
67 return true;
68 }
69
76 public static function deleteByServerId($a_server_id)
77 {
78 global $ilDB;
79
80 $query = 'DELETE FROM ecs_course_assignments ' .
81 'WHERE sid = ' . $ilDB->quote($a_server_id, 'integer');
82 $ilDB->manipulate($query);
83 return true;
84 }
85
93 public static function lookupUserIds($a_cms_id, $a_cms_sub_id, $a_obj_id)
94 {
95 global $ilDB;
96
97 $cms_sub_id_query = '';
98
99 if (is_null($a_cms_sub_id)) {
100 $cms_sub_id_query = 'AND cms_sub_id IS NULL ';
101 } else {
102 $cms_sub_id_query = 'AND cms_sub_id = ' . $ilDB->quote($a_cms_sub_id, 'integer') . ' ';
103 }
104
105 $query = 'SELECT usr_id FROM ecs_course_assignments ' .
106 'WHERE cms_id = ' . $ilDB->quote($a_cms_id, 'integer') . ' ' .
107 $cms_sub_id_query .
108 'AND obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
109 $res = $ilDB->query($query);
110
111 $usr_ids = array();
112 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
113 $usr_ids[] = $row->usr_id;
114 }
115 return $usr_ids;
116 }
117
126 public static function lookupAssignment($a_cms_id, $a_cms_sub_id, $a_obj_id, $a_usr_id)
127 {
128 global $ilDB;
129
130 $cms_sub_id_query = '';
131 if (is_null($a_cms_sub_id)) {
132 $cms_sub_id_query = 'AND cms_sub_id IS NULL ';
133 } else {
134 $cms_sub_id_query = 'AND cms_sub_id = ' . $ilDB->quote($a_cms_sub_id, 'integer') . ' ';
135 }
136
137 $query = 'SELECT id FROM ecs_course_assignments ' .
138 'WHERE cms_id = ' . $ilDB->quote($a_cms_id, 'integer') . ' ' .
139 $cms_sub_id_query .
140 'AND obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
141 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'text');
142 $res = $ilDB->query($query);
143 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
144 return new ilECSCourseMemberAssignment($row->id);
145 }
146 return null;
147 }
148
149
150 public function getId()
151 {
152 return $this->id;
153 }
154
159 public function setServer($a_server)
160 {
161 $this->server = $a_server;
162 }
163
168 public function getServer()
169 {
170 return $this->server;
171 }
172
173 public function setMid($a_mid)
174 {
175 $this->mid = $a_mid;
176 }
177
178 public function getMid()
179 {
180 return $this->mid;
181 }
182
183 public function setCmsId($a_id)
184 {
185 $this->cms_id = $a_id;
186 }
187
188 public function getCmsId()
189 {
190 return $this->cms_id;
191 }
192
193 public function setCmsSubId($a_id)
194 {
195 $this->cms_sub_id = $a_id;
196 }
197
198 public function getCmsSubId()
199 {
200 return $this->cms_sub_id;
201 }
202
203 public function setObjId($a_id)
204 {
205 $this->obj_id = $a_id;
206 }
207
208 public function getObjId()
209 {
210 return $this->obj_id;
211 }
212
213 public function setUid($a_id)
214 {
215 $this->uid = $a_id;
216 }
217
218 public function getUid()
219 {
220 return $this->uid;
221 }
222
223 public function setStatus($a_status)
224 {
225 $this->status = $a_status;
226 }
227
228 public function getStatus()
229 {
230 return $this->status;
231 }
232
237 public function save()
238 {
239 global $ilDB;
240
241 $this->id = $ilDB->nextId('ecs_course_assignments');
242
243
244 $assignment = self::lookupAssignment(
245 $this->getCmsId(),
246 $this->getCmsSubId(),
247 $this->getObjId(),
248 $this->getUid()
249 );
250 if ($assignment instanceof ilECSCourseMemberAssignment) {
251 $assignment->update();
252 return true;
253 }
254
255 $query = 'INSERT INTO ecs_course_assignments ' .
256 '(id,sid,mid,cms_id,cms_sub_id,obj_id,usr_id,status) ' .
257 'VALUES( ' .
258 $ilDB->quote($this->getId(), 'integer') . ', ' .
259 $ilDB->quote($this->getServer(), 'integer') . ', ' .
260 $ilDB->quote($this->getMid(), 'integer') . ', ' .
261 $ilDB->quote($this->getCmsId(), 'integer') . ', ' .
262 $ilDB->quote($this->getCmsSubId(), 'integer') . ', ' .
263 $ilDB->quote($this->getObjId(), 'integer') . ', ' .
264 $ilDB->quote($this->getUid(), 'text') . ', ' .
265 $ilDB->quote($this->getStatus(), 'integer') . ' ' .
266 ')';
267 $ilDB->manipulate($query);
268 }
269
275 public function update()
276 {
277 global $ilDB;
278
279 $query = 'UPDATE ecs_course_assignments ' .
280 'SET ' .
281 'sid = ' . $ilDB->quote($this->getServer(), 'integer') . ', ' .
282 'mid = ' . $ilDB->quote($this->getMid(), 'integer') . ', ' .
283 'cms_id = ' . $ilDB->quote($this->getCmsId(), 'integer') . ', ' .
284 'cms_sub_id = ' . $ilDB->quote($this->getCmsSubId(), 'integer') . ', ' .
285 'obj_id = ' . $ilDB->quote($this->getObjId(), 'integer') . ', ' .
286 'usr_id = ' . $ilDB->quote($this->getUid(), 'text') . ', ' .
287 'status = ' . $ilDB->quote($this->getStatus(), 'integer') . ' ' .
288 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
289 $ilDB->manipulate($query);
290 return true;
291 }
292
296 public function delete()
297 {
298 global $ilDB;
299
300 $query = 'DELETE FROM ecs_course_assignments ' .
301 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
302 $ilDB->manipulate($query);
303 return true;
304 }
305
306
307
312 protected function read()
313 {
314 global $ilDB;
315
316 if (!$this->getId()) {
317 return false;
318 }
319
320 $query = 'SELECT * FROM ecs_course_assignments ' .
321 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
322 $res = $ilDB->query($query);
323 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
324 $this->setServer($row->sid);
325 $this->setMid($row->mid);
326 $this->setCmsId($row->cms_id);
327 $this->setCmsSubId($row->cms_sub_id);
328 $this->setObjId($row->obj_id);
329 $this->setUid($row->usr_id);
330 $this->setStatus($row->status);
331 }
332 }
333}
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