ILIAS  Release_5_0_x_branch Revision 61816
 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  if($this->exc->hasAddToDesktop())
81  {
82  $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
83  $tmp_user->addDesktopItem($this->getRefId(),"exc");
84  }
85 
86  $ilDB->manipulate("DELETE FROM exc_members ".
87  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer")." ".
88  "AND usr_id = ".$ilDB->quote($a_usr_id, "integer")." ");
89 
90 // @todo: some of this fields may not be needed anymore
91  $ilDB->manipulateF("INSERT INTO exc_members (obj_id, usr_id, status, sent, feedback) ".
92  " VALUES (%s,%s,%s,%s,%s)",
93  array("integer", "integer", "text", "integer", "integer"),
94  array($this->getObjId(), $a_usr_id, 'notgraded', 0, 0));
95 
96  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
98 
99  $this->read();
100 
101  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
102  ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
103 
104  return true;
105  }
106 
110  function isAssigned($a_id)
111  {
112  return in_array($a_id,$this->getMembers());
113  }
114 
118  function assignMembers($a_members)
119  {
120  $assigned = 0;
121  if(is_array($a_members))
122  {
123  foreach($a_members as $member)
124  {
125  if(!$this->isAssigned($member))
126  {
127  $this->assignMember($member);
128  }
129  else
130  {
131  ++$assigned;
132  }
133  }
134  }
135  if($assigned == count($a_members))
136  {
137  return false;
138  }
139  else
140  {
141  return true;
142  }
143  }
144 
150  function deassignMember($a_usr_id)
151  {
152  global $ilDB;
153 
154  $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
155  $tmp_user->dropDesktopItem($this->getRefId(),"exc");
156 
157  $query = "DELETE FROM exc_members ".
158  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer")." ".
159  "AND usr_id = ".$ilDB->quote($a_usr_id, "integer")." ";
160 
161  $ilDB->manipulate($query);
162 
163  $this->read();
164 
165  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
166  ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
167 
168  // delete all delivered files of the member
169  $this->exc->deleteAllDeliveredFilesOfUser($a_usr_id);
170 
171 // @todo: delete all assignment associations (and their files)
172 
173  return false;
174  }
175 
179  function deassignMembers($a_members)
180  {
181  if(is_array($a_members))
182  {
183  foreach($a_members as $member)
184  {
185  $this->deassignMember($member);
186  }
187  }
188  else
189  {
190  return false;
191  }
192  }
193 
197  function read()
198  {
199  global $ilDB;
200 
201  $tmp_arr_members = array();
202 
203  $query = "SELECT * FROM exc_members ".
204  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer");
205 
206  $res = $ilDB->query($query);
207  while($row = $ilDB->fetchObject($res))
208  {
209  $tmp_arr_members[] = $row->usr_id;
210  }
211  $this->setMembers($tmp_arr_members);
212 
213  return true;
214  }
215 
216 // @todo: clone also assignments
217  function ilClone($a_new_id)
218  {
219  global $ilDB;
220 
221  $data = array();
222 
223  $query = "SELECT * FROM exc_members ".
224  "WHERE obj_id = ".$ilDB->quote($this->getObjId(), "integer");
225 
226  $res = $ilDB->query($query);
227  while($row = $ilDB->fetchObject($res))
228  {
229  $data[] = array("usr_id" => $row->usr_id,
230  "notice" => $row->notice,
231  "returned" => $row->returned,
232  "status" => $row->status,
233  "sent" => $row->sent,
234  "feedback" => $row->feedback
235  );
236  }
237  foreach($data as $row)
238  {
239  $ilDB->manipulateF("INSERT INTO exc_members ".
240  " (obj_id, usr_id, notice, returned, status, feedback, sent) VALUES ".
241  " (%s,%s,%s,%s,%s,%s,%s)",
242  array ("integer", "integer", "text", "integer", "text", "integer", "integer"),
243  array ($a_new_id, $row["usr_id"], $row["notice"], (int) $row["returned"],
244  $row["status"], (int) $row["feedback"], (int) $row["sent"])
245  );
246 
247  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
248  ilLPStatusWrapper::_updateStatus($a_new_id, $row["usr_id"]);
249  }
250  return true;
251  }
252 
253 // @todo: delete also assignments
254  function delete()
255  {
256  global $ilDB;
257 
258  $query = "DELETE FROM exc_members WHERE obj_id = ".
259  $ilDB->quote($this->getObjId(), "integer");
260  $ilDB->manipulate($query);
261 
262  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
264 
265  return true;
266  }
267 
268  function _getMembers($a_obj_id)
269  {
270  global $ilDB;
271 
272  // #14963 - see ilExAssignment::getMemberListData()
273  $query = "SELECT DISTINCT(excm.usr_id) ud".
274  " FROM exc_members excm".
275  " JOIN object_data od ON (od.obj_id = excm.usr_id)".
276  " WHERE excm.obj_id = ".$ilDB->quote($a_obj_id, "integer").
277  " AND od.type = ".$ilDB->quote("usr", "text");
278 
279  $res = $ilDB->query($query);
280  while($row = $ilDB->fetchObject($res))
281  {
282  $usr_ids[] = $row->ud;
283  }
284 
285  return $usr_ids ? $usr_ids : array();
286  }
287 
288 
293  function _getReturned($a_obj_id)
294  {
295  global $ilDB;
296 
297  $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members ".
298  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
299  "AND returned = 1";
300 
301  $res = $ilDB->query($query);
302  while($row = $ilDB->fetchObject($res))
303  {
304  $usr_ids[] = $row->ud;
305  }
306 
307  return $usr_ids ? $usr_ids : array();
308  }
309 
317  function _hasReturned($a_obj_id, $a_user_id)
318  {
319  global $ilDB;
320 
321  $set = $ilDB->query("SELECT DISTINCT(usr_id) FROM exc_members WHERE ".
322  " obj_id = ".$ilDB->quote($a_obj_id, "integer")." AND ".
323  " returned = ".$ilDB->quote(1, "integer")." AND ".
324  " usr_id = ".$ilDB->quote($a_user_id, "integer")
325  );
326  if ($rec = $ilDB->fetchAssoc($set))
327  {
328  return true;
329  }
330  return false;
331  }
332 
336  function _getPassedUsers($a_obj_id)
337  {
338  global $ilDB;
339 
340  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
341  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
342  "AND status = ".$ilDB->quote("passed", "text");
343  $res = $ilDB->query($query);
344  while($row = $ilDB->fetchObject($res))
345  {
346  $usr_ids[] = $row->usr_id;
347  }
348  return $usr_ids ? $usr_ids : array();
349  }
350 
354  function _getFailedUsers($a_obj_id)
355  {
356  global $ilDB;
357 
358  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
359  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
360  "AND status = ".$ilDB->quote("failed", "text");
361  $res = $ilDB->query($query);
362  while($row = $ilDB->fetchObject($res))
363  {
364  $usr_ids[] = $row->usr_id;
365  }
366  return $usr_ids ? $usr_ids : array();
367  }
368 
379  function _lookupStatus($a_obj_id, $a_user_id)
380  {
381  global $ilDB;
382 
383  $query = "SELECT status FROM exc_members ".
384  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
385  " AND usr_id = ".$ilDB->quote($a_user_id, "integer");
386 
387  $res = $ilDB->query($query);
388  if($row = $ilDB->fetchAssoc($res))
389  {
390  return $row["status"];
391  }
392 
393  return false;
394  }
395 
407  function _writeStatus($a_obj_id, $a_user_id, $a_status)
408  {
409  global $ilDB;
410 
411  $ilDB->manipulate("UPDATE exc_members SET ".
412  " status = ".$ilDB->quote($a_status, "text").
413  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
414  " AND usr_id = ".$ilDB->quote($a_user_id, "integer")
415  );
416 
417  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
418  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
419  }
420 
433  function _writeReturned($a_obj_id, $a_user_id, $a_status)
434  {
435  global $ilDB;
436 
437  $ilDB->manipulate("UPDATE exc_members SET ".
438  " returned = ".$ilDB->quote($a_status, "text").
439  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
440  " AND usr_id = ".$ilDB->quote($a_user_id, "integer")
441  );
442 
443  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
444  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
445  }
446 
447 } //END class.ilObjExercise
448 ?>