ILIAS  Release_4_4_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  $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  // #14963 - see ilExAssignment::getMemberListData()
270  $query = "SELECT DISTINCT(excm.usr_id) ud".
271  " FROM exc_members excm".
272  " JOIN object_data od ON (od.obj_id = excm.usr_id)".
273  " WHERE excm.obj_id = ".$ilDB->quote($a_obj_id, "integer").
274  " AND od.type = ".$ilDB->quote("usr", "text");
275 
276  $res = $ilDB->query($query);
277  while($row = $ilDB->fetchObject($res))
278  {
279  $usr_ids[] = $row->ud;
280  }
281 
282  return $usr_ids ? $usr_ids : array();
283  }
284 
285 
290  function _getReturned($a_obj_id)
291  {
292  global $ilDB;
293 
294  $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members ".
295  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
296  "AND returned = 1";
297 
298  $res = $ilDB->query($query);
299  while($row = $ilDB->fetchObject($res))
300  {
301  $usr_ids[] = $row->ud;
302  }
303 
304  return $usr_ids ? $usr_ids : array();
305  }
306 
314  function _hasReturned($a_obj_id, $a_user_id)
315  {
316  global $ilDB;
317 
318  $set = $ilDB->query("SELECT DISTINCT(usr_id) FROM exc_members WHERE ".
319  " obj_id = ".$ilDB->quote($a_obj_id, "integer")." AND ".
320  " returned = ".$ilDB->quote(1, "integer")." AND ".
321  " usr_id = ".$ilDB->quote($a_user_id, "integer")
322  );
323  if ($rec = $ilDB->fetchAssoc($set))
324  {
325  return true;
326  }
327  return false;
328  }
329 
333  function _getPassedUsers($a_obj_id)
334  {
335  global $ilDB;
336 
337  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
338  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
339  "AND status = ".$ilDB->quote("passed", "text");
340  $res = $ilDB->query($query);
341  while($row = $ilDB->fetchObject($res))
342  {
343  $usr_ids[] = $row->usr_id;
344  }
345  return $usr_ids ? $usr_ids : array();
346  }
347 
351  function _getFailedUsers($a_obj_id)
352  {
353  global $ilDB;
354 
355  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
356  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
357  "AND status = ".$ilDB->quote("failed", "text");
358  $res = $ilDB->query($query);
359  while($row = $ilDB->fetchObject($res))
360  {
361  $usr_ids[] = $row->usr_id;
362  }
363  return $usr_ids ? $usr_ids : array();
364  }
365 
376  function _lookupStatus($a_obj_id, $a_user_id)
377  {
378  global $ilDB;
379 
380  $query = "SELECT status FROM exc_members ".
381  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
382  " AND usr_id = ".$ilDB->quote($a_user_id, "integer");
383 
384  $res = $ilDB->query($query);
385  if($row = $ilDB->fetchAssoc($res))
386  {
387  return $row["status"];
388  }
389 
390  return false;
391  }
392 
404  function _writeStatus($a_obj_id, $a_user_id, $a_status)
405  {
406  global $ilDB;
407 
408  $ilDB->manipulate("UPDATE exc_members SET ".
409  " status = ".$ilDB->quote($a_status, "text").
410  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
411  " AND usr_id = ".$ilDB->quote($a_user_id, "integer")
412  );
413 
414  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
415  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
416  }
417 
430  function _writeReturned($a_obj_id, $a_user_id, $a_status)
431  {
432  global $ilDB;
433 
434  $ilDB->manipulate("UPDATE exc_members SET ".
435  " returned = ".$ilDB->quote($a_status, "text").
436  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
437  " AND usr_id = ".$ilDB->quote($a_user_id, "integer")
438  );
439 
440  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
441  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
442  }
443 
444 } //END class.ilObjExercise
445 ?>