ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
17  protected $db;
18 
19  public $ref_id;
20  public $obj_id;
21  public $members;
22  public $status;
23  // var $status_feedback;
24  // var $status_sent;
25  // var $status_returned;
26  // var $notice;
27 
28  public function __construct($a_exc)
29  {
30  global $DIC;
31 
32  $this->db = $DIC->database();
33  $this->exc = $a_exc;
34  $this->obj_id = $a_exc->getId();
35  $this->ref_id = $a_exc->getRefId();
36  $this->read();
37  }
38 
42  public function getRefId()
43  {
44  return $this->ref_id;
45  }
46 
50  public function getObjId()
51  {
52  return $this->obj_id;
53  }
54 
58  public function setObjId($a_obj_id)
59  {
60  $this->obj_id = $a_obj_id;
61  }
62 
66  public function getMembers()
67  {
68  return $this->members ? $this->members : array();
69  }
70 
74  public function setMembers($a_members)
75  {
76  $this->members = $a_members;
77  }
78 
84  public function assignMember($a_usr_id)
85  {
86  $ilDB = $this->db;
87 
88  if ($this->exc->hasAddToDesktop()) {
89  $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
90  $tmp_user->addDesktopItem($this->getRefId(), "exc");
91  }
92 
93  $ilDB->manipulate("DELETE FROM exc_members " .
94  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
95  "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ");
96 
97  // @todo: some of this fields may not be needed anymore
98  $ilDB->manipulateF(
99  "INSERT INTO exc_members (obj_id, usr_id, status, sent, feedback) " .
100  " VALUES (%s,%s,%s,%s,%s)",
101  array("integer", "integer", "text", "integer", "integer"),
102  array($this->getObjId(), $a_usr_id, 'notgraded', 0, 0)
103  );
104 
105  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
106  ilExAssignment::createNewUserRecords($a_usr_id, $this->getObjId());
107 
108  $this->read();
109 
110  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
111  ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
112 
113  return true;
114  }
115 
119  public function isAssigned($a_id)
120  {
121  return in_array($a_id, $this->getMembers());
122  }
123 
127  public function assignMembers($a_members)
128  {
129  $assigned = 0;
130  if (is_array($a_members)) {
131  foreach ($a_members as $member) {
132  if (!$this->isAssigned($member)) {
133  $this->assignMember($member);
134  } else {
135  ++$assigned;
136  }
137  }
138  }
139  if ($assigned == count($a_members)) {
140  return false;
141  } else {
142  return true;
143  }
144  }
145 
151  public function deassignMember($a_usr_id)
152  {
153  $ilDB = $this->db;
154 
155  $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
156  $tmp_user->dropDesktopItem($this->getRefId(), "exc");
157 
158  $query = "DELETE FROM exc_members " .
159  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
160  "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ";
161 
162  $ilDB->manipulate($query);
163 
164  $this->read();
165 
166  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
167  ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
168 
169  // delete all delivered files of the member
170  include_once("./Modules/Exercise/classes/class.ilExSubmission.php");
171  ilExSubmission::deleteUser($this->exc->getId(), $a_usr_id);
172 
173  // @todo: delete all assignment associations (and their files)
174 
175  return false;
176  }
177 
181  public function deassignMembers($a_members)
182  {
183  if (is_array($a_members)) {
184  foreach ($a_members as $member) {
185  $this->deassignMember($member);
186  }
187  } else {
188  return false;
189  }
190  }
191 
195  public function read()
196  {
197  $ilDB = $this->db;
198 
199  $tmp_arr_members = array();
200 
201  $query = "SELECT * FROM exc_members " .
202  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
203 
204  $res = $ilDB->query($query);
205  while ($row = $ilDB->fetchObject($res)) {
206  if (ilObject::_lookupType($row->usr_id) == "usr") {
207  $tmp_arr_members[] = $row->usr_id;
208  }
209  }
210  $this->setMembers($tmp_arr_members);
211 
212  return true;
213  }
214 
215  // @todo: clone also assignments
216  public function ilClone($a_new_id)
217  {
218  $ilDB = $this->db;
219 
220  $data = array();
221 
222  $query = "SELECT * FROM exc_members " .
223  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
224 
225  $res = $ilDB->query($query);
226  while ($row = $ilDB->fetchObject($res)) {
227  $data[] = array("usr_id" => $row->usr_id,
228  "notice" => $row->notice,
229  "returned" => $row->returned,
230  "status" => $row->status,
231  "sent" => $row->sent,
232  "feedback" => $row->feedback
233  );
234  }
235  foreach ($data as $row) {
236  $ilDB->manipulateF(
237  "INSERT INTO exc_members " .
238  " (obj_id, usr_id, notice, returned, status, feedback, sent) VALUES " .
239  " (%s,%s,%s,%s,%s,%s,%s)",
240  array("integer", "integer", "text", "integer", "text", "integer", "integer"),
241  array($a_new_id, $row["usr_id"], $row["notice"], (int) $row["returned"],
242  $row["status"], (int) $row["feedback"], (int) $row["sent"])
243  );
244 
245  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
246  ilLPStatusWrapper::_updateStatus($a_new_id, $row["usr_id"]);
247  }
248  return true;
249  }
250 
251  // @todo: delete also assignments
252  public function delete()
253  {
254  $ilDB = $this->db;
255 
256  $query = "DELETE FROM exc_members WHERE obj_id = " .
257  $ilDB->quote($this->getObjId(), "integer");
258  $ilDB->manipulate($query);
259 
260  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
262 
263  return true;
264  }
265 
266  public static function _getMembers($a_obj_id)
267  {
268  global $DIC;
269 
270  $ilDB = $DIC->database();
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  $usr_ids[] = $row->ud;
282  }
283 
284  return $usr_ids ? $usr_ids : array();
285  }
286 
297  public static function _lookupStatus($a_obj_id, $a_user_id)
298  {
299  global $DIC;
300 
301  $ilDB = $DIC->database();
302 
303  $query = "SELECT status FROM exc_members " .
304  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
305  " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
306 
307  $res = $ilDB->query($query);
308  if ($row = $ilDB->fetchAssoc($res)) {
309  return $row["status"];
310  }
311 
312  return false;
313  }
314 
326  public static function _writeStatus($a_obj_id, $a_user_id, $a_status)
327  {
328  global $DIC;
329 
330  $ilDB = $DIC->database();
331 
332  $ilDB->manipulate(
333  "UPDATE exc_members SET " .
334  " status = " . $ilDB->quote($a_status, "text") .
335  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
336  " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
337  );
338 
339  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
340  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
341  }
342 
355  public static function _writeReturned($a_obj_id, $a_user_id, $a_status)
356  {
357  global $DIC;
358 
359  $ilDB = $DIC->database();
360 
361  $ilDB->manipulate(
362  "UPDATE exc_members SET " .
363  " returned = " . $ilDB->quote($a_status, "integer") .
364  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
365  " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
366  );
367 
368  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
369  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
370  }
371 
372 
373  //
374  // LP
375  //
376 
381  public static function _getReturned($a_obj_id)
382  {
383  global $DIC;
384 
385  $ilDB = $DIC->database();
386 
387  $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members " .
388  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
389  "AND returned = 1";
390 
391  $res = $ilDB->query($query);
392  while ($row = $ilDB->fetchObject($res)) {
393  $usr_ids[] = $row->ud;
394  }
395 
396  return $usr_ids ? $usr_ids : array();
397  }
398 
406  public static function _hasReturned($a_obj_id, $a_user_id)
407  {
408  global $DIC;
409 
410  $ilDB = $DIC->database();
411 
412  $set = $ilDB->query(
413  "SELECT DISTINCT(usr_id) FROM exc_members WHERE " .
414  " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
415  " returned = " . $ilDB->quote(1, "integer") . " AND " .
416  " usr_id = " . $ilDB->quote($a_user_id, "integer")
417  );
418  if ($rec = $ilDB->fetchAssoc($set)) {
419  return true;
420  }
421  return false;
422  }
423 
427  public static function _getPassedUsers($a_obj_id)
428  {
429  global $DIC;
430 
431  $ilDB = $DIC->database();
432 
433  $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
434  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
435  "AND status = " . $ilDB->quote("passed", "text");
436  $res = $ilDB->query($query);
437  while ($row = $ilDB->fetchObject($res)) {
438  $usr_ids[] = $row->usr_id;
439  }
440  return $usr_ids ? $usr_ids : array();
441  }
442 
446  public static function _getFailedUsers($a_obj_id)
447  {
448  global $DIC;
449 
450  $ilDB = $DIC->database();
451 
452  $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
453  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
454  "AND status = " . $ilDB->quote("failed", "text");
455  $res = $ilDB->query($query);
456  while ($row = $ilDB->fetchObject($res)) {
457  $usr_ids[] = $row->usr_id;
458  }
459  return $usr_ids ? $usr_ids : array();
460  }
461 } //END class.ilObjExercise
static deleteUser($a_exc_id, $a_user_id)
Delete all delivered files of user.
Class ilExerciseMembers.
global $DIC
Definition: saml.php:7
getMembers()
Get members array.
getRefId()
Get exercise ref id.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static _getReturned($a_obj_id)
Get returned status for all members (if they have anything returned for any assignment) ...
getObjId()
Get exercise id.
static _refreshStatus($a_obj_id, $a_users=null)
Set dirty.
static _writeStatus($a_obj_id, $a_user_id, $a_status)
Write user status.
static _writeReturned($a_obj_id, $a_user_id, $a_status)
Write returned status.
static _hasReturned($a_obj_id, $a_user_id)
Has user returned anything in any assignment?
foreach($_POST as $key=> $value) $res
static _lookupStatus($a_obj_id, $a_user_id)
Lookup current status (notgraded|passed|failed)
static _getFailedUsers($a_obj_id)
Get all users that failed the exercise.
setObjId($a_obj_id)
Set exercise id.
deassignMember($a_usr_id)
Detaches a user from an exercise.
$query
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType($a_id, $a_reference=false)
lookup object type
$row
deassignMembers($a_members)
Deassign members.
assignMembers($a_members)
Assign members to exercise.
read()
Read all members.
static _getPassedUsers($a_obj_id)
Get all users that passed the exercise.
global $ilDB
static createNewUserRecords($a_user_id, $a_exc_id)
Create member status record for a new participant for all assignments.
setMembers($a_members)
Set members array.
static _getMembers($a_obj_id)
isAssigned($a_id)
Is user assigned to exercise?
assignMember($a_usr_id)
Assign a user to the exercise.
$data
Definition: bench.php:6