ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 obj_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 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
50 {
51 $obj_ids[] = $row->obj_id;
52 }
53 return $obj_ids;
54 }
55
59 public static function deleteByObjId($a_obj_id)
60 {
61 global $ilDB;
62
63 $query = 'DELETE FROM ecs_course_assignments '.
64 'WHERE obj_id = '.$ilDB->quote($a_obj_id, 'integer');
65 $ilDB->manipulate($query);
66 return true;
67 }
68
75 public static function deleteByServerId($a_server_id)
76 {
77 global $ilDB;
78
79 $query = 'DELETE FROM ecs_course_assignments '.
80 'WHERE sid = '.$ilDB->quote($a_server_id, 'integer');
81 $ilDB->manipulate($query);
82 return true;
83 }
84
92 public static function lookupUserIds($a_cms_id, $a_cms_sub_id, $a_obj_id)
93 {
94 global $ilDB;
95
96 $query = 'SELECT usr_id FROM ecs_course_assignments '.
97 'WHERE cms_id = '.$ilDB->quote($a_cms_id,'integer').' '.
98 'AND cms_sub_id = '.$ilDB->quote($a_cms_sub_id).' '.
99 'AND obj_id = '.$ilDB->quote($a_obj_id,'integer');
100 $res = $ilDB->query($query);
101
102 $usr_ids = array();
103 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
104 {
105 $usr_ids[] = $row->usr_id;
106 }
107 return $usr_ids;
108 }
109
118 public static function lookupAssignment($a_cms_id,$a_cms_sub_id,$a_obj_id,$a_usr_id)
119 {
120 global $ilDB;
121
122 $query = 'SELECT id FROM ecs_course_assignments '.
123 'WHERE cms_id = '.$ilDB->quote($a_cms_id,'integer').' '.
124 'AND cms_sub_id = '.$ilDB->quote($a_cms_sub_id,'integer').' '.
125 'AND obj_id = '.$ilDB->quote($a_obj_id,'integer').' '.
126 'AND usr_id = '.$ilDB->quote($a_usr_id,'text');
127 $res = $ilDB->query($query);
128 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
129 {
130 return new ilECSCourseMemberAssignment($row->id);
131 }
132 return null;
133 }
134
135
136 public function getId()
137 {
138 return $this->id;
139 }
140
145 public function setServer($a_server)
146 {
147 $this->server = $a_server;
148 }
149
154 public function getServer()
155 {
156 return $this->server;
157 }
158
159 public function setMid($a_mid)
160 {
161 $this->mid = $a_mid;
162 }
163
164 public function getMid()
165 {
166 return $this->mid;
167 }
168
169 public function setCmsId($a_id)
170 {
171 $this->cms_id = $a_id;
172 }
173
174 public function getCmsId()
175 {
176 return $this->cms_id;
177 }
178
179 public function setCmsSubId($a_id)
180 {
181 $this->cms_sub_id = $a_id;
182 }
183
184 public function getCmsSubId()
185 {
186 return $this->cms_sub_id;
187 }
188
189 public function setObjId($a_id)
190 {
191 $this->obj_id = $a_id;
192 }
193
194 public function getObjId()
195 {
196 return $this->obj_id;
197 }
198
199 public function setUid($a_id)
200 {
201 $this->uid = $a_id;
202 }
203
204 public function getUid()
205 {
206 return $this->uid;
207 }
208
209 public function setStatus($a_status)
210 {
211 $this->status = $a_status;
212 }
213
214 public function getStatus()
215 {
216 return $this->status;
217 }
218
223 public function save()
224 {
225 global $ilDB;
226
227 $this->id = $ilDB->nextId('ecs_course_assignments');
228
229
230 $assignment = self::lookupAssignment(
231 $this->getCmsId(),
232 $this->getCmsSubId(),
233 $this->getObjId(),
234 $this->getUid()
235 );
236 if($assignment instanceof ilECSCourseMemberAssignment)
237 {
238 $assignment->update();
239 return TRUE;
240 }
241
242 $query = 'INSERT INTO ecs_course_assignments '.
243 '(id,sid,mid,cms_id,cms_sub_id,obj_id,usr_id,status) '.
244 'VALUES( '.
245 $ilDB->quote($this->getId(),'integer').', '.
246 $ilDB->quote($this->getServer(),'integer').', '.
247 $ilDB->quote($this->getMid(),'integer').', '.
248 $ilDB->quote($this->getCmsId(),'integer').', '.
249 $ilDB->quote($this->getCmsSubId(),'integer').', '.
250 $ilDB->quote($this->getObjId(),'integer').', '.
251 $ilDB->quote($this->getUid(),'text').', '.
252 $ilDB->quote($this->getStatus(),'integer').' '.
253 ')';
254 $ilDB->manipulate($query);
255 }
256
262 public function update()
263 {
264 global $ilDB;
265
266 $query = 'UPDATE ecs_course_assignments '.
267 'SET '.
268 'sid = '.$ilDB->quote($this->getServer(),'integer').', '.
269 'mid = '.$ilDB->quote($this->getMid(),'integer').', '.
270 'cms_id = '.$ilDB->quote($this->getCmsId(),'integer').', '.
271 'cms_sub_id = '.$ilDB->quote($this->getCmsSubId(),'integer').', '.
272 'obj_id = '.$ilDB->quote($this->getObjId(),'integer').', '.
273 'usr_id = '.$ilDB->quote($this->getUid(),'text').', '.
274 'status = '.$ilDB->quote($this->getStatus(),'integer').' '.
275 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
276 $ilDB->manipulate($query);
277 return true;
278 }
279
283 public function delete()
284 {
285 global $ilDB;
286
287 $query = 'DELETE FROM ecs_course_assignments '.
288 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
289 $ilDB->manipulate($query);
290 return true;
291 }
292
293
294
299 protected function read()
300 {
301 global $ilDB;
302
303 if(!$this->getId())
304 {
305 return false;
306 }
307
308 $query = 'SELECT * FROM ecs_course_assignments '.
309 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
310 $res = $ilDB->query($query);
311 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
312 {
313 $this->setServer($row->sid);
314 $this->setMid($row->mid);
315 $this->setCmsId($row->cms_id);
316 $this->setCmsSubId($row->cms_sub_id);
317 $this->setObjId($row->obj_id);
318 $this->setUid($row->usr_id);
319 $this->setStatus($row->status);
320 }
321 }
322}
323?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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