ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
53 $assignments[] = new self($row->id);
54 }
55 return $assignments;
56 }
57
61 public static function deleteByObjId($a_obj_id)
62 {
63 global $ilDB;
64
65 $query = 'DELETE FROM ecs_course_assignments '.
66 'WHERE obj_id = '.$ilDB->quote($a_obj_id, 'integer');
67 $ilDB->manipulate($query);
68 return true;
69 }
70
77 public static function deleteByServerId($a_server_id)
78 {
79 global $ilDB;
80
81 $query = 'DELETE FROM ecs_course_assignments '.
82 'WHERE sid = '.$ilDB->quote($a_server_id, 'integer');
83 $ilDB->manipulate($query);
84 return true;
85 }
86
94 public static function lookupUserIds($a_cms_id, $a_cms_sub_id, $a_obj_id)
95 {
96 global $ilDB;
97
98 $cms_sub_id_query = '';
99
100 if(is_null($a_cms_sub_id))
101 {
102 $cms_sub_id_query = 'AND cms_sub_id IS NULL ';
103 }
104 else
105 {
106 $cms_sub_id_query = 'AND cms_sub_id = '.$ilDB->quote($a_cms_sub_id,'integer').' ';
107 }
108
109 $query = 'SELECT usr_id FROM ecs_course_assignments '.
110 'WHERE cms_id = '.$ilDB->quote($a_cms_id,'integer').' '.
111 $cms_sub_id_query.
112 'AND obj_id = '.$ilDB->quote($a_obj_id,'integer');
113 $res = $ilDB->query($query);
114
115 $usr_ids = array();
116 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
117 {
118 $usr_ids[] = $row->usr_id;
119 }
120 return $usr_ids;
121 }
122
131 public static function lookupAssignment($a_cms_id,$a_cms_sub_id,$a_obj_id,$a_usr_id)
132 {
133 global $ilDB;
134
135 $cms_sub_id_query = '';
136 if(is_null($a_cms_sub_id))
137 {
138 $cms_sub_id_query = 'AND cms_sub_id IS NULL ';
139 }
140 else
141 {
142 $cms_sub_id_query = 'AND cms_sub_id = '.$ilDB->quote($a_cms_sub_id,'integer').' ';
143 }
144
145 $query = 'SELECT id FROM ecs_course_assignments '.
146 'WHERE cms_id = '.$ilDB->quote($a_cms_id,'integer').' '.
147 $cms_sub_id_query.
148 'AND obj_id = '.$ilDB->quote($a_obj_id,'integer').' '.
149 'AND usr_id = '.$ilDB->quote($a_usr_id,'text');
150 $res = $ilDB->query($query);
151 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
152 {
153 return new ilECSCourseMemberAssignment($row->id);
154 }
155 return null;
156 }
157
158
159 public function getId()
160 {
161 return $this->id;
162 }
163
168 public function setServer($a_server)
169 {
170 $this->server = $a_server;
171 }
172
177 public function getServer()
178 {
179 return $this->server;
180 }
181
182 public function setMid($a_mid)
183 {
184 $this->mid = $a_mid;
185 }
186
187 public function getMid()
188 {
189 return $this->mid;
190 }
191
192 public function setCmsId($a_id)
193 {
194 $this->cms_id = $a_id;
195 }
196
197 public function getCmsId()
198 {
199 return $this->cms_id;
200 }
201
202 public function setCmsSubId($a_id)
203 {
204 $this->cms_sub_id = $a_id;
205 }
206
207 public function getCmsSubId()
208 {
209 return $this->cms_sub_id;
210 }
211
212 public function setObjId($a_id)
213 {
214 $this->obj_id = $a_id;
215 }
216
217 public function getObjId()
218 {
219 return $this->obj_id;
220 }
221
222 public function setUid($a_id)
223 {
224 $this->uid = $a_id;
225 }
226
227 public function getUid()
228 {
229 return $this->uid;
230 }
231
232 public function setStatus($a_status)
233 {
234 $this->status = $a_status;
235 }
236
237 public function getStatus()
238 {
239 return $this->status;
240 }
241
246 public function save()
247 {
248 global $ilDB;
249
250 $this->id = $ilDB->nextId('ecs_course_assignments');
251
252
253 $assignment = self::lookupAssignment(
254 $this->getCmsId(),
255 $this->getCmsSubId(),
256 $this->getObjId(),
257 $this->getUid()
258 );
259 if($assignment instanceof ilECSCourseMemberAssignment)
260 {
261 $assignment->update();
262 return TRUE;
263 }
264
265 $query = 'INSERT INTO ecs_course_assignments '.
266 '(id,sid,mid,cms_id,cms_sub_id,obj_id,usr_id,status) '.
267 'VALUES( '.
268 $ilDB->quote($this->getId(),'integer').', '.
269 $ilDB->quote($this->getServer(),'integer').', '.
270 $ilDB->quote($this->getMid(),'integer').', '.
271 $ilDB->quote($this->getCmsId(),'integer').', '.
272 $ilDB->quote($this->getCmsSubId(),'integer').', '.
273 $ilDB->quote($this->getObjId(),'integer').', '.
274 $ilDB->quote($this->getUid(),'text').', '.
275 $ilDB->quote($this->getStatus(),'integer').' '.
276 ')';
277 $ilDB->manipulate($query);
278 }
279
285 public function update()
286 {
287 global $ilDB;
288
289 $query = 'UPDATE ecs_course_assignments '.
290 'SET '.
291 'sid = '.$ilDB->quote($this->getServer(),'integer').', '.
292 'mid = '.$ilDB->quote($this->getMid(),'integer').', '.
293 'cms_id = '.$ilDB->quote($this->getCmsId(),'integer').', '.
294 'cms_sub_id = '.$ilDB->quote($this->getCmsSubId(),'integer').', '.
295 'obj_id = '.$ilDB->quote($this->getObjId(),'integer').', '.
296 'usr_id = '.$ilDB->quote($this->getUid(),'text').', '.
297 'status = '.$ilDB->quote($this->getStatus(),'integer').' '.
298 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
299 $ilDB->manipulate($query);
300 return true;
301 }
302
306 public function delete()
307 {
308 global $ilDB;
309
310 $query = 'DELETE FROM ecs_course_assignments '.
311 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
312 $ilDB->manipulate($query);
313 return true;
314 }
315
316
317
322 protected function read()
323 {
324 global $ilDB;
325
326 if(!$this->getId())
327 {
328 return false;
329 }
330
331 $query = 'SELECT * FROM ecs_course_assignments '.
332 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
333 $res = $ilDB->query($query);
334 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
335 {
336 $this->setServer($row->sid);
337 $this->setMid($row->mid);
338 $this->setCmsId($row->cms_id);
339 $this->setCmsSubId($row->cms_sub_id);
340 $this->setObjId($row->obj_id);
341 $this->setUid($row->usr_id);
342 $this->setStatus($row->status);
343 }
344 }
345}
346?>
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.
global $ilDB