ILIAS  eassessment Revision 61809
 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 /*
167  $delivered_files =& $this->getDeliveredFiles($a_usr_id);
168  $files_to_delete = array();
169  $userfile = "";
170  foreach ($delivered_files as $key => $value)
171  {
172  array_push($files_to_delete, $value["returned_id"]);
173  $userfile = $value["filename"];
174  }
175  $this->deleteDeliveredFiles($files_to_delete, $a_usr_id);
176 
177  // delete the user directory if existing
178  if ($userfile)
179  {
180  $pathinfo = pathinfo($userfile);
181  $dir = $pathinfo["dirname"];
182  }
183  if (is_dir($dir))
184  {
185  rmdir($dir);
186  }
187 */
188 
189 // @todo: delete all assignment associations (and their files)
190 
191  return false;
192  }
193 
197  function deassignMembers($a_members)
198  {
199  if(is_array($a_members))
200  {
201  foreach($a_members as $member)
202  {
203  $this->deassignMember($member);
204  }
205  }
206  else
207  {
208  return false;
209  }
210  }
211 
215  function read()
216  {
217  global $ilDB;
218 
219  $tmp_arr_members = array();
220 
221  $query = "SELECT * FROM exc_members ".
222  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer");
223 
224  $res = $ilDB->query($query);
225  while($row = $ilDB->fetchObject($res))
226  {
227  $tmp_arr_members[] = $row->usr_id;
228  }
229  $this->setMembers($tmp_arr_members);
230 
231  return true;
232  }
233 
234 // @todo: clone also assignments
235  function ilClone($a_new_id)
236  {
237  global $ilDB;
238 
239  $data = array();
240 
241  $query = "SELECT * FROM exc_members ".
242  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer");
243 
244  $res = $ilDB->query($query);
245  while($row = $ilDB->fetchObject($res))
246  {
247  $data[] = array("usr_id" => $row->usr_id,
248  "notice" => $row->notice,
249  "returned" => $row->returned,
250  "status" => $row->status,
251  "sent" => $row->sent,
252  "feedback" => $row->feedback
253  );
254  }
255  foreach($data as $row)
256  {
257  $ilDB->manipulateF("INSERT INTO exc_members ".
258  " (obj_id, usr_id, notice, returned, status, feedback, sent) VALUES ".
259  " (%s,%s,%s,%s,%s,%s,%s)",
260  array ("integer", "integer", "text", "integer", "text", "integer", "integer"),
261  array ($a_new_id, $row["usr_id"], $row["notice"], (int) $row["returned"],
262  $row["status"], (int) $row["feedback"], (int) $row["sent"])
263  );
264 
265  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
266  ilLPStatusWrapper::_updateStatus($a_new_id, $row["usr_id"]);
267  }
268  return true;
269  }
270 
271 // @todo: delete also assignments
272  function delete()
273  {
274  global $ilDB;
275 
276  $query = "DELETE FROM exc_members WHERE obj_id = ".
277  $ilDB->quote($this->getObjId(), "integer");
278  $ilDB->manipulate($query);
279 
280  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
282 
283  return true;
284  }
285 
286  function _getMembers($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 
293  $res = $ilDB->query($query);
294  while($row = $ilDB->fetchObject($res))
295  {
296  $usr_ids[] = $row->ud;
297  }
298 
299  return $usr_ids ? $usr_ids : array();
300  }
301 
302 
307  function _getReturned($a_obj_id)
308  {
309  global $ilDB;
310 
311  $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members ".
312  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
313  "AND returned = 1";
314 
315  $res = $ilDB->query($query);
316  while($row = $ilDB->fetchObject($res))
317  {
318  $usr_ids[] = $row->ud;
319  }
320 
321  return $usr_ids ? $usr_ids : array();
322  }
323 
331  function _hasReturned($a_obj_id, $a_user_id)
332  {
333  global $ilDB;
334 
335  $set = $ilDB->query("SELECT DISTINCT(usr_id) FROM exc_members WHERE ".
336  " obj_id = ".$ilDB->quote($a_obj_id, "integer")." AND ".
337  " returned = ".$ilDB->quote(1, "integer")." AND ".
338  " usr_id = ".$ilDB->quote($a_user_id, "integer")
339  );
340  if ($rec = $ilDB->fetchAssoc($set))
341  {
342  return true;
343  }
344  return false;
345  }
346 
350  function _getPassedUsers($a_obj_id)
351  {
352  global $ilDB;
353 
354  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
355  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
356  "AND status = ".$ilDB->quote("passed", "text");
357  $res = $ilDB->query($query);
358  while($row = $ilDB->fetchObject($res))
359  {
360  $usr_ids[] = $row->usr_id;
361  }
362  return $usr_ids ? $usr_ids : array();
363  }
364 
368  function _getFailedUsers($a_obj_id)
369  {
370  global $ilDB;
371 
372  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
373  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
374  "AND status = ".$ilDB->quote("failed", "text");
375  $res = $ilDB->query($query);
376  while($row = $ilDB->fetchObject($res))
377  {
378  $usr_ids[] = $row->usr_id;
379  }
380  return $usr_ids ? $usr_ids : array();
381  }
382 
393  function _lookupStatus($a_obj_id, $a_user_id)
394  {
395  global $ilDB;
396 
397  $query = "SELECT status FROM exc_members ".
398  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
399  " AND usr_id = ".$ilDB->quote($a_user_id, "integer");
400 
401  $res = $ilDB->query($query);
402  if($row = $ilDB->fetchAssoc($res))
403  {
404  return $row["status"];
405  }
406 
407  return false;
408  }
409 
421  function _writeStatus($a_obj_id, $a_user_id, $a_status)
422  {
423  global $ilDB;
424 
425  $ilDB->manipulate("UPDATE exc_members SET ".
426  " status = ".$ilDB->quote($a_status, "text").
427  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
428  " AND usr_id = ".$ilDB->quote($a_user_id, "integer")
429  );
430 
431  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
432  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
433  }
434 
447  function _writeReturned($a_obj_id, $a_user_id, $a_status)
448  {
449  global $ilDB;
450 
451  $ilDB->manipulate("UPDATE exc_members SET ".
452  " returned = ".$ilDB->quote($a_status, "text").
453  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
454  " AND usr_id = ".$ilDB->quote($a_user_id, "integer")
455  );
456 
457  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
458  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
459  }
460 
461 } //END class.ilObjExercise
462 ?>