ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExerciseMembers.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  var $ref_id;
15  var $obj_id;
16  var $members;
17  var $status;
18 // var $status_feedback;
19 // var $status_sent;
20 // var $status_returned;
21 // var $notice;
22 
23  function ilExerciseMembers($a_exc)
24  {
25  $this->exc = $a_exc;
26  $this->obj_id = $a_exc->getId();
27  $this->ref_id = $a_exc->getRefId();
28  $this->read();
29  }
30 
34  function getRefId()
35  {
36  return $this->ref_id;
37  }
38 
42  function getObjId()
43  {
44  return $this->obj_id;
45  }
46 
50  function setObjId($a_obj_id)
51  {
52  $this->obj_id = $a_obj_id;
53  }
54 
58  function getMembers()
59  {
60  return $this->members ? $this->members : array();
61  }
62 
66  function setMembers($a_members)
67  {
68  $this->members = $a_members;
69  }
70 
76  function assignMember($a_usr_id)
77  {
78  global $ilDB;
79 
80  $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
81  $tmp_user->addDesktopItem($this->getRefId(),"exc");
82 
83  $ilDB->manipulate("DELETE FROM exc_members ".
84  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer")." ".
85  "AND usr_id = ".$ilDB->quote($a_usr_id, "integer")." ");
86 
87 // @todo: some of this fields may not be needed anymore
88  $ilDB->manipulateF("INSERT INTO exc_members (obj_id, usr_id, status, sent, feedback) ".
89  " VALUES (%s,%s,%s,%s,%s)",
90  array("integer", "integer", "text", "integer", "integer"),
91  array($this->getObjId(), $a_usr_id, 'notgraded', 0, 0));
92 
93  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
95 
96  $this->read();
97 
98  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
99  ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
100 
101  return true;
102  }
103 
107  function isAssigned($a_id)
108  {
109  return in_array($a_id,$this->getMembers());
110  }
111 
115  function assignMembers($a_members)
116  {
117  $assigned = 0;
118  if(is_array($a_members))
119  {
120  foreach($a_members as $member)
121  {
122  if(!$this->isAssigned($member))
123  {
124  $this->assignMember($member);
125  }
126  else
127  {
128  ++$assigned;
129  }
130  }
131  }
132  if($assigned == count($a_members))
133  {
134  return false;
135  }
136  else
137  {
138  return true;
139  }
140  }
141 
147  function deassignMember($a_usr_id)
148  {
149  global $ilDB;
150 
151  $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
152  $tmp_user->dropDesktopItem($this->getRefId(),"exc");
153 
154  $query = "DELETE FROM exc_members ".
155  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer")." ".
156  "AND usr_id = ".$ilDB->quote($a_usr_id, "integer")." ";
157 
158  $ilDB->manipulate($query);
159 
160  $this->read();
161 
162  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
163  ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
164 
165  // delete all delivered files of the member
166  $this->exc->deleteAllDeliveredFilesOfUser($a_usr_id);
167 
168 // @todo: delete all assignment associations (and their files)
169 
170  return false;
171  }
172 
176  function deassignMembers($a_members)
177  {
178  if(is_array($a_members))
179  {
180  foreach($a_members as $member)
181  {
182  $this->deassignMember($member);
183  }
184  }
185  else
186  {
187  return false;
188  }
189  }
190 
194  function read()
195  {
196  global $ilDB;
197 
198  $tmp_arr_members = array();
199 
200  $query = "SELECT * FROM exc_members ".
201  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer");
202 
203  $res = $ilDB->query($query);
204  while($row = $ilDB->fetchObject($res))
205  {
206  $tmp_arr_members[] = $row->usr_id;
207  }
208  $this->setMembers($tmp_arr_members);
209 
210  return true;
211  }
212 
213 // @todo: clone also assignments
214  function ilClone($a_new_id)
215  {
216  global $ilDB;
217 
218  $data = array();
219 
220  $query = "SELECT * FROM exc_members ".
221  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer");
222 
223  $res = $ilDB->query($query);
224  while($row = $ilDB->fetchObject($res))
225  {
226  $data[] = array("usr_id" => $row->usr_id,
227  "notice" => $row->notice,
228  "returned" => $row->returned,
229  "status" => $row->status,
230  "sent" => $row->sent,
231  "feedback" => $row->feedback
232  );
233  }
234  foreach($data as $row)
235  {
236  $ilDB->manipulateF("INSERT INTO exc_members ".
237  " (obj_id, usr_id, notice, returned, status, feedback, sent) VALUES ".
238  " (%s,%s,%s,%s,%s,%s,%s)",
239  array ("integer", "integer", "text", "integer", "text", "integer", "integer"),
240  array ($a_new_id, $row["usr_id"], $row["notice"], (int) $row["returned"],
241  $row["status"], (int) $row["feedback"], (int) $row["sent"])
242  );
243 
244  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
245  ilLPStatusWrapper::_updateStatus($a_new_id, $row["usr_id"]);
246  }
247  return true;
248  }
249 
250 // @todo: delete also assignments
251  function delete()
252  {
253  global $ilDB;
254 
255  $query = "DELETE FROM exc_members WHERE obj_id = ".
256  $ilDB->quote($this->getObjId(), "integer");
257  $ilDB->manipulate($query);
258 
259  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
261 
262  return true;
263  }
264 
265  function _getMembers($a_obj_id)
266  {
267  global $ilDB;
268 
269  $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members ".
270  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
271 
272  $res = $ilDB->query($query);
273  while($row = $ilDB->fetchObject($res))
274  {
275  $usr_ids[] = $row->ud;
276  }
277 
278  return $usr_ids ? $usr_ids : array();
279  }
280 
281 
286  function _getReturned($a_obj_id)
287  {
288  global $ilDB;
289 
290  $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members ".
291  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
292  "AND returned = 1";
293 
294  $res = $ilDB->query($query);
295  while($row = $ilDB->fetchObject($res))
296  {
297  $usr_ids[] = $row->ud;
298  }
299 
300  return $usr_ids ? $usr_ids : array();
301  }
302 
310  function _hasReturned($a_obj_id, $a_user_id)
311  {
312  global $ilDB;
313 
314  $set = $ilDB->query("SELECT DISTINCT(usr_id) FROM exc_members WHERE ".
315  " obj_id = ".$ilDB->quote($a_obj_id, "integer")." AND ".
316  " returned = ".$ilDB->quote(1, "integer")." AND ".
317  " usr_id = ".$ilDB->quote($a_user_id, "integer")
318  );
319  if ($rec = $ilDB->fetchAssoc($set))
320  {
321  return true;
322  }
323  return false;
324  }
325 
329  function _getPassedUsers($a_obj_id)
330  {
331  global $ilDB;
332 
333  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
334  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
335  "AND status = ".$ilDB->quote("passed", "text");
336  $res = $ilDB->query($query);
337  while($row = $ilDB->fetchObject($res))
338  {
339  $usr_ids[] = $row->usr_id;
340  }
341  return $usr_ids ? $usr_ids : array();
342  }
343 
347  function _getFailedUsers($a_obj_id)
348  {
349  global $ilDB;
350 
351  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
352  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
353  "AND status = ".$ilDB->quote("failed", "text");
354  $res = $ilDB->query($query);
355  while($row = $ilDB->fetchObject($res))
356  {
357  $usr_ids[] = $row->usr_id;
358  }
359  return $usr_ids ? $usr_ids : array();
360  }
361 
372  function _lookupStatus($a_obj_id, $a_user_id)
373  {
374  global $ilDB;
375 
376  $query = "SELECT status FROM exc_members ".
377  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
378  " AND usr_id = ".$ilDB->quote($a_user_id, "integer");
379 
380  $res = $ilDB->query($query);
381  if($row = $ilDB->fetchAssoc($res))
382  {
383  return $row["status"];
384  }
385 
386  return false;
387  }
388 
400  function _writeStatus($a_obj_id, $a_user_id, $a_status)
401  {
402  global $ilDB;
403 
404  $ilDB->manipulate("UPDATE exc_members SET ".
405  " status = ".$ilDB->quote($a_status, "text").
406  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
407  " AND usr_id = ".$ilDB->quote($a_user_id, "integer")
408  );
409 
410  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
411  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
412  }
413 
426  function _writeReturned($a_obj_id, $a_user_id, $a_status)
427  {
428  global $ilDB;
429 
430  $ilDB->manipulate("UPDATE exc_members SET ".
431  " returned = ".$ilDB->quote($a_status, "text").
432  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
433  " AND usr_id = ".$ilDB->quote($a_user_id, "integer")
434  );
435 
436  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
437  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
438  }
439 
440 } //END class.ilObjExercise
441 ?>