ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules 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 
12 {
16  protected $db;
17 
18  public $ref_id;
19  public $obj_id;
20  public $members;
21  public $status;
22  // var $status_feedback;
23  // var $status_sent;
24  // var $status_returned;
25  // var $notice;
26 
31 
32  public function __construct($a_exc)
33  {
34  global $DIC;
35 
36  $this->db = $DIC->database();
37  $this->exc = $a_exc;
38  $this->obj_id = $a_exc->getId();
39  $this->ref_id = $a_exc->getRefId();
40  $this->read();
41 
42  $this->recommended_content_manager = new ilRecommendedContentManager();
43  }
44 
48  public function getRefId()
49  {
50  return $this->ref_id;
51  }
52 
56  public function getObjId()
57  {
58  return $this->obj_id;
59  }
60 
64  public function setObjId($a_obj_id)
65  {
66  $this->obj_id = $a_obj_id;
67  }
68 
72  public function getMembers()
73  {
74  return $this->members ? $this->members : array();
75  }
76 
80  public function setMembers($a_members)
81  {
82  $this->members = $a_members;
83  }
84 
90  public function assignMember($a_usr_id)
91  {
92  $ilDB = $this->db;
93 
94  /*if($this->exc->hasAddToDesktop())
95  {
96  }*/
97 
98  $ilDB->manipulate("DELETE FROM exc_members " .
99  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
100  "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ");
101 
102  // @todo: some of this fields may not be needed anymore
103  $ilDB->manipulateF(
104  "INSERT INTO exc_members (obj_id, usr_id, status, sent, feedback) " .
105  " VALUES (%s,%s,%s,%s,%s)",
106  array("integer", "integer", "text", "integer", "integer"),
107  array($this->getObjId(), $a_usr_id, 'notgraded', 0, 0)
108  );
109 
110  ilExAssignment::createNewUserRecords($a_usr_id, $this->getObjId());
111 
112  $this->read();
113 
114  ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
115 
116  return true;
117  }
118 
122  public function isAssigned($a_id)
123  {
124  return in_array($a_id, $this->getMembers());
125  }
126 
130  public function assignMembers($a_members)
131  {
132  $assigned = 0;
133  if (is_array($a_members)) {
134  foreach ($a_members as $member) {
135  if (!$this->isAssigned($member)) {
136  $this->assignMember($member);
137  } else {
138  ++$assigned;
139  }
140  }
141  }
142  if ($assigned == count($a_members)) {
143  return false;
144  } else {
145  return true;
146  }
147  }
148 
154  public function deassignMember($a_usr_id)
155  {
156  $ilDB = $this->db;
157 
158  $this->recommended_content_manager->removeObjectRecommendation($a_usr_id, $this->getRefId());
159 
160  $query = "DELETE FROM exc_members " .
161  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
162  "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ";
163 
164  $ilDB->manipulate($query);
165 
166  $this->read();
167 
168  ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
169 
170  // delete all delivered files of the member
171  ilExSubmission::deleteUser($this->exc->getId(), $a_usr_id);
172 
173  // delete individual deadline/starting time entries
174  foreach (ilExAssignment::getInstancesByExercise($this->exc->getId()) as $ass) {
175  $idl = ilExcIndividualDeadline::getInstance($ass->getId(), $a_usr_id, false);
176  $idl->delete();
177  }
178 
179  // @todo: delete all assignment associations (and their files)
180 
181  return false;
182  }
183 
187  public function deassignMembers($a_members)
188  {
189  if (is_array($a_members)) {
190  foreach ($a_members as $member) {
191  $this->deassignMember($member);
192  }
193  } else {
194  return false;
195  }
196  }
197 
201  public function read()
202  {
203  $ilDB = $this->db;
204 
205  $tmp_arr_members = array();
206 
207  $query = "SELECT * FROM exc_members " .
208  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
209 
210  $res = $ilDB->query($query);
211  while ($row = $ilDB->fetchObject($res)) {
212  if (ilObject::_lookupType($row->usr_id) == "usr") {
213  $tmp_arr_members[] = $row->usr_id;
214  }
215  }
216  $this->setMembers($tmp_arr_members);
217 
218  return true;
219  }
220 
221  // @todo: clone also assignments
222  public function ilClone($a_new_id)
223  {
224  $ilDB = $this->db;
225 
226  $data = array();
227 
228  $query = "SELECT * FROM exc_members " .
229  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
230 
231  $res = $ilDB->query($query);
232  while ($row = $ilDB->fetchObject($res)) {
233  $data[] = array("usr_id" => $row->usr_id,
234  "notice" => $row->notice,
235  "returned" => $row->returned,
236  "status" => $row->status,
237  "sent" => $row->sent,
238  "feedback" => $row->feedback
239  );
240  }
241  foreach ($data as $row) {
242  $ilDB->manipulateF(
243  "INSERT INTO exc_members " .
244  " (obj_id, usr_id, notice, returned, status, feedback, sent) VALUES " .
245  " (%s,%s,%s,%s,%s,%s,%s)",
246  array("integer", "integer", "text", "integer", "text", "integer", "integer"),
247  array($a_new_id, $row["usr_id"], $row["notice"], (int) $row["returned"],
248  $row["status"], (int) $row["feedback"], (int) $row["sent"])
249  );
250 
251  ilLPStatusWrapper::_updateStatus($a_new_id, $row["usr_id"]);
252  }
253  return true;
254  }
255 
256  // @todo: delete also assignments
257  public function delete()
258  {
259  $ilDB = $this->db;
260 
261  $query = "DELETE FROM exc_members WHERE obj_id = " .
262  $ilDB->quote($this->getObjId(), "integer");
263  $ilDB->manipulate($query);
264 
266 
267  return true;
268  }
269 
270  public static function _getMembers($a_obj_id)
271  {
272  global $DIC;
273 
274  $ilDB = $DIC->database();
275 
276  // #14963 - see ilExAssignment::getMemberListData()
277  $query = "SELECT DISTINCT(excm.usr_id) ud" .
278  " FROM exc_members excm" .
279  " JOIN object_data od ON (od.obj_id = excm.usr_id)" .
280  " WHERE excm.obj_id = " . $ilDB->quote($a_obj_id, "integer") .
281  " AND od.type = " . $ilDB->quote("usr", "text");
282 
283  $res = $ilDB->query($query);
284  while ($row = $ilDB->fetchObject($res)) {
285  $usr_ids[] = $row->ud;
286  }
287 
288  return $usr_ids ? $usr_ids : array();
289  }
290 
301  public static function _lookupStatus($a_obj_id, $a_user_id)
302  {
303  global $DIC;
304 
305  $ilDB = $DIC->database();
306 
307  $query = "SELECT status FROM exc_members " .
308  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
309  " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
310 
311  $res = $ilDB->query($query);
312  if ($row = $ilDB->fetchAssoc($res)) {
313  return $row["status"];
314  }
315 
316  return false;
317  }
318 
330  public static function _writeStatus($a_obj_id, $a_user_id, $a_status)
331  {
332  global $DIC;
333 
334  $ilDB = $DIC->database();
335 
336  $ilDB->manipulate(
337  "UPDATE exc_members SET " .
338  " status = " . $ilDB->quote($a_status, "text") .
339  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
340  " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
341  );
342 
343  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
344  }
345 
358  public static function _writeReturned($a_obj_id, $a_user_id, $a_status)
359  {
360  global $DIC;
361 
362  $ilDB = $DIC->database();
363 
364  $ilDB->manipulate(
365  "UPDATE exc_members SET " .
366  " returned = " . $ilDB->quote($a_status, "integer") .
367  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
368  " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
369  );
370 
371  ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
372  }
373 
374 
375  //
376  // LP
377  //
378 
383  public static function _getReturned($a_obj_id)
384  {
385  global $DIC;
386 
387  $ilDB = $DIC->database();
388 
389  $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members " .
390  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
391  "AND returned = 1";
392 
393  $res = $ilDB->query($query);
394  while ($row = $ilDB->fetchObject($res)) {
395  $usr_ids[] = $row->ud;
396  }
397 
398  return $usr_ids ? $usr_ids : array();
399  }
400 
408  public static function _hasReturned($a_obj_id, $a_user_id)
409  {
410  global $DIC;
411 
412  $ilDB = $DIC->database();
413 
414  $set = $ilDB->query(
415  "SELECT DISTINCT(usr_id) FROM exc_members WHERE " .
416  " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
417  " returned = " . $ilDB->quote(1, "integer") . " AND " .
418  " usr_id = " . $ilDB->quote($a_user_id, "integer")
419  );
420  if ($rec = $ilDB->fetchAssoc($set)) {
421  return true;
422  }
423  return false;
424  }
425 
429  public static function _getPassedUsers($a_obj_id)
430  {
431  global $DIC;
432 
433  $ilDB = $DIC->database();
434 
435  $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
436  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
437  "AND status = " . $ilDB->quote("passed", "text");
438  $res = $ilDB->query($query);
439  while ($row = $ilDB->fetchObject($res)) {
440  $usr_ids[] = $row->usr_id;
441  }
442  return $usr_ids ? $usr_ids : array();
443  }
444 
448  public static function _getFailedUsers($a_obj_id)
449  {
450  global $DIC;
451 
452  $ilDB = $DIC->database();
453 
454  $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
455  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
456  "AND status = " . $ilDB->quote("failed", "text");
457  $res = $ilDB->query($query);
458  while ($row = $ilDB->fetchObject($res)) {
459  $usr_ids[] = $row->usr_id;
460  }
461  return $usr_ids ? $usr_ids : array();
462  }
463 } //END class.ilObjExercise
static deleteUser($a_exc_id, $a_user_id)
Delete all delivered files of user.
$data
Definition: storeScorm.php:23
Class ilExerciseMembers.
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.
static getInstance($a_ass_id, $a_participant_id, $a_is_team=false)
Get instance.
static getInstancesByExercise($a_exc_id)
global $DIC
Definition: goto.php:24
setObjId($a_obj_id)
Set exercise id.
deassignMember($a_usr_id)
Detaches a user from an exercise.
$query
static _lookupType($a_id, $a_reference=false)
lookup object type
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.
Recommended content manager (business logic)
static _getMembers($a_obj_id)
isAssigned($a_id)
Is user assigned to exercise?
assignMember($a_usr_id)
Assign a user to the exercise.