ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExerciseMembers.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
34 {
35  var $ilias;
36 
37  var $ref_id;
38  var $obj_id;
39  var $members;
40  var $status;
44  var $notice;
45 
46  function ilExerciseMembers($a_obj_id,$a_ref_id)
47  {
48  global $ilias;
49 
50  $this->ilias =& $ilias;
51  $this->obj_id = $a_obj_id;
52  $this->ref_id = $a_ref_id;
53  }
54 
55  // GET SET METHODS
56  function getRefId()
57  {
58  return $this->ref_id;
59  }
60  function getObjId()
61  {
62  return $this->obj_id;
63  }
64  function setObjId($a_obj_id)
65  {
66  $this->obj_id = $a_obj_id;
67  }
68  function getMembers()
69  {
70  return $this->members ? $this->members : array();
71  }
72  function setMembers($a_members)
73  {
74  $this->members = $a_members;
75  }
76 
82  function assignMember($a_usr_id)
83  {
84  global $ilDB;
85 
86  $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
87  $tmp_user->addDesktopItem($this->getRefId(),"exc");
88 
89 
90  $query = "REPLACE INTO exc_members ".
91  "SET obj_id = ".$ilDB->quote($this->getObjId()).", ".
92  "usr_id = ".$ilDB->quote($a_usr_id).", ".
93  "status = 'notgraded', sent = '0', feedback='0'";
94 
95  $res = $this->ilias->db->query($query);
96  $this->read();
97 
98  return true;
99  }
100  function isAssigned($a_id)
101  {
102  return in_array($a_id,$this->getMembers());
103  }
104 
105  function assignMembers($a_members)
106  {
107  $assigned = 0;
108  if(is_array($a_members))
109  {
110  foreach($a_members as $member)
111  {
112  if(!$this->isAssigned($member))
113  {
114  $this->assignMember($member);
115  }
116  else
117  {
118  ++$assigned;
119  }
120  }
121  }
122  if($assigned == count($a_members))
123  {
124  return false;
125  }
126  else
127  {
128  return true;
129  }
130  }
131 
137  function deassignMember($a_usr_id)
138  {
139  global $ilDB;
140 
141  $tmp_user = ilObjectFactory::getInstanceByObjId($a_usr_id);
142  $tmp_user->dropDesktopItem($this->getRefId(),"exc");
143 
144  $query = "DELETE FROM exc_members ".
145  "WHERE obj_id = ".$ilDB->quote($this->getObjId())." ".
146  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
147 
148  $this->ilias->db->query($query);
149  $this->read();
150  // delete all delivered files of the member
151  $delivered_files =& $this->getDeliveredFiles($a_usr_id);
152  $files_to_delete = array();
153  $userfile = "";
154  foreach ($delivered_files as $key => $value)
155  {
156  array_push($files_to_delete, $value["returned_id"]);
157  $userfile = $value["filename"];
158  }
159  $this->deleteDeliveredFiles($files_to_delete, $a_usr_id);
160  // delete the user directory if existing
161  if ($userfile)
162  {
163  $pathinfo = pathinfo($userfile);
164  $dir = $pathinfo["dirname"];
165  }
166  if (is_dir($dir))
167  {
168  rmdir($dir);
169  }
170  return false;
171  }
172 
173  function deassignMembers($a_members)
174  {
175  if(is_array($a_members))
176  {
177  foreach($a_members as $member)
178  {
179  $this->deassignMember($member);
180  }
181  }
182  else
183  {
184  return false;
185  }
186  }
187  function setStatus($a_status)
188  {
189  if(is_array($a_status))
190  {
191  $this->status = $a_status;
192  return true;
193  }
194  }
195  function getStatus()
196  {
197  return $this->status ? $this->status : array();
198  }
199  function getStatusByMember($a_member_id)
200  {
201  if(isset($this->status[$a_member_id]))
202  {
203  return $this->status[$a_member_id];
204  }
205  return false;
206  }
207 
214  function setStatusForMember($a_member_id,$a_status)
215  {
216  global $ilDB;
217 
218  $query = "UPDATE exc_members ".
219  "SET status = ".$ilDB->quote($a_status).", ".
220  "status_time= ".$ilDB->quote(date("Y-m-d H:i:s"))." ".
221  " WHERE obj_id = ".$ilDB->quote($this->getObjId())." ".
222  "AND usr_id = ".$ilDB->quote($a_member_id)." ".
223  " AND status <> ".$ilDB->quote($a_status);
224 
225  $this->ilias->db->query($query);
226  $this->read();
227 
228  return true;
229  }
230 
236  function updateStatusTimeForMember($a_member_id)
237  {
238  global $ilDB;
239 
240  $query = "UPDATE exc_members ".
241  "SET status_time= ".$ilDB->quote(date("Y-m-d H:i:s"))." ".
242  " WHERE obj_id = ".$ilDB->quote($this->getObjId())." ".
243  "AND usr_id = ".$ilDB->quote($a_member_id)." ";
244 
245  $this->ilias->db->query($query);
246  $this->read();
247 
248  return true;
249  }
250 
251 
252  function setStatusSent($a_status)
253  {
254  if(is_array($a_status))
255  {
256  $this->status_sent = $a_status;
257  return true;
258  }
259  }
260  function getStatusSent()
261  {
262  return $this->status_sent ? $this->status_sent : array(0 => 0);
263  }
264  function getStatusSentByMember($a_member_id)
265  {
266  if(isset($this->status_sent[$a_member_id]))
267  {
268  return $this->status_sent[$a_member_id];
269  }
270  return false;
271  }
272  function setStatusSentForMember($a_member_id,$a_status)
273  {
274  global $ilDB;
275 
276  $query = "UPDATE exc_members ".
277  "SET sent = ".$ilDB->quote(($a_status ? 1 : 0))." , ".
278  "sent_time=".$ilDB->quote(($a_status ? (date("Y-m-d H:i:s")) : ("0000-00-00 00:00:00"))).
279  " WHERE obj_id = ".$ilDB->quote($this->getObjId())." ".
280  "AND usr_id = ".$ilDB->quote($a_member_id)." ";
281 
282  $this->ilias->db->query($query);
283  $this->read();
284 
285  return true;
286  }
287 
288  function getStatusReturned()
289  {
290  return $this->status_returned ? $this->status_returned : array(0 => 0);
291  }
292  function setStatusReturned($a_status)
293  {
294  if(is_array($a_status))
295  {
296  $this->status_returned = $a_status;
297  return true;
298  }
299  return false;
300  }
301 
302  function getStatusReturnedByMember($a_member_id)
303  {
304  if(isset($this->status_returned[$a_member_id]))
305  {
306  return $this->status_returned[$a_member_id];
307  }
308  return false;
309  }
310  function setStatusReturnedForMember($a_member_id,$a_status)
311  {
312  global $ilDB;
313 
314  $query = "UPDATE exc_members ".
315  "SET returned = ".$ilDB->quote(($a_status ? 1 : 0))." ".
316  "WHERE obj_id = ".$ilDB->quote($this->getObjId())." ".
317  "AND usr_id = ".$ilDB->quote($a_member_id)." ";
318 
319  $this->ilias->db->query($query);
320  $this->read();
321 
322  return true;
323  }
324 
325  // feedback functions
326  function setStatusFeedback($a_status)
327  {
328  if(is_array($a_status))
329  {
330  $this->status_feedback = $a_status;
331  return true;
332  }
333  }
334  function getStatusFeedback()
335  {
336  return $this->status_feedback ? $this->status_feedback : array(0 => 0);
337  }
338  function getStatusFeedbackByMember($a_member_id)
339  {
340  if(isset($this->status_feedback[$a_member_id]))
341  {
342  return $this->status_feedback[$a_member_id];
343  }
344  return false;
345  }
346 
347  function setStatusFeedbackForMember($a_member_id,$a_status)
348  {
349  global $ilDB;
350 
351  $query = "UPDATE exc_members ".
352  "SET feedback = ".$ilDB->quote(($a_status ? 1 : 0)).", ".
353  "feedback_time=".$ilDB->quote(($a_status ? (date("Y-m-d H:i:s")) : ("0000-00-00 00:00:00"))).
354  " WHERE obj_id = ".$ilDB->quote($this->getObjId())." ".
355  "AND usr_id = ".$ilDB->quote($a_member_id);
356 
357  $this->ilias->db->query($query);
358  $this->read();
359 
360  return true;
361  }
362 
363  function getNotice()
364  {
365  return $this->notice ? $this->notice : array(0 => 0);
366  }
367 
368  function setNotice($a_notice)
369  {
370  if(is_array($a_notice))
371  {
372  $this->notice = $a_notice;
373  return true;
374  }
375  return false;
376  }
377 
378  function getNoticeByMember($a_member_id)
379  {
380  if(isset($this->notice[$a_member_id]))
381  {
382  return $this->notice[$a_member_id];
383  }
384  else
385  {
386  return "";
387  }
388  }
389 
390  function hasReturned($a_member_id)
391  {
392  global $ilDB;
393 
394  $query = sprintf("SELECT returned_id FROM exc_returned WHERE obj_id = %s AND user_id = %s",
395  $this->ilias->db->quote($this->getObjId() . ""),
396  $this->ilias->db->quote($a_member_id . "")
397  );
398  $result = $this->ilias->db->query($query);
399  return $result->numRows();
400  }
401 
406  {
407  global $ilDB;
408 
409  $query = "SELECT * FROM exc_returned WHERE obj_id = ".
410  $ilDB->quote($this->getObjId());
411 
412  $res = $this->ilias->db->query($query);
413  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
414  {
415  $delivered[] = $row;
416  }
417 
418  $delivered = ilObjExercise::_fixFilenameArray($delivered);
419 
420  return $delivered ? $delivered : array();
421  }
422 
430  function &getDeliveredFiles($a_member_id)
431  {
432  $query = sprintf("SELECT *, TIMESTAMP + 0 AS timestamp14 FROM exc_returned WHERE obj_id = %s AND user_id = %s ORDER BY timestamp14",
433  $this->ilias->db->quote($this->getObjId() . ""),
434  $this->ilias->db->quote($a_member_id . "")
435  );
436  $result = $this->ilias->db->query($query);
437  $delivered_files = array();
438  if ($result->numRows())
439  {
440  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
441  {
442  array_push($delivered_files, $row);
443  }
444  }
445 
446  $delivered_files = ilObjExercise::_fixFilenameArray($delivered_files);
447 
448  return $delivered_files;
449  }
450 
457  function deleteDeliveredFiles($file_id_array, $a_member_id)
458  {
459  global $ilDB;
460 
461  if (count($file_id_array))
462  {
463  $query = sprintf("SELECT * FROM exc_returned WHERE user_id = %s AND returned_id IN (".
464  implode(ilUtil::quoteArray($file_id_array) ,",").")",
465  $this->ilias->db->quote($a_member_id . "")
466  );
467  $result = $this->ilias->db->query($query);
468  if ($result->numRows())
469  {
470  $result_array = array();
471  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
472  {
473  array_push($result_array, $row);
474  }
475  // delete the entries in the database
476  $query = sprintf("DELETE FROM exc_returned WHERE user_id = %s AND returned_id IN ("
477  .implode(ilUtil::quoteArray($file_id_array) ,",").")",
478  $this->ilias->db->quote($a_member_id . "")
479  );
480  $result = $this->ilias->db->query($query);
481  // delete the files
482  foreach ($result_array as $key => $value)
483  {
484  unlink(ilObjExercise::_fixFilename($value["filename"]));
485  }
486  }
487  }
488  }
489 
495  function deliverReturnedFiles($a_member_id, $a_only_new = false)
496  {
497  global $ilUser, $ilDB;
498 
499  // get last download time
500  $and_str = "";
501  if ($a_only_new)
502  {
503  $q = "SELECT download_time FROM exc_usr_tutor WHERE ".
504  " obj_id = ".$ilDB->quote($this->getObjId())." AND ".
505  " usr_id = ".$ilDB->quote($a_member_id)." AND ".
506  " tutor_id = ".$ilDB->quote($ilUser->getId());
507  $lu_set = $ilDB->query($q);
508  if ($lu_rec = $lu_set->fetchRow(DB_FETCHMODE_ASSOC))
509  {
510  if ($lu_rec["download_time"] > 0)
511  {
512  $and_str = " AND timestamp > ".$ilDB->quote($lu_rec["download_time"]);
513  }
514  }
515  }
516 
517  $this->updateTutorDownloadTime($a_member_id);
518 
519  $query = sprintf("SELECT * FROM exc_returned WHERE obj_id = %s AND user_id = %s".
520  $and_str,
521  $this->ilias->db->quote($this->getObjId() . ""),
522  $this->ilias->db->quote($a_member_id . "")
523  );
524  $result = $this->ilias->db->query($query);
525  $count = $result->numRows();
526  if ($count == 1)
527  {
528  $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
529  $this->downloadSingleFile(ilObjExercise::_fixFilename($row["filename"]), $row["filetitle"]);
530  }
531  else if ($count > 0)
532  {
533  $array_files = array();
534  $filename = "";
535  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
536  {
537  $filename = ilObjExercise::_fixFilename($row["filename"]);
538  $pathinfo = pathinfo($filename);
539  $dir = $pathinfo["dirname"];
540  $file = $pathinfo["basename"];
541  array_push($array_files, $file);
542  }
543  $pathinfo = pathinfo($filename);
544  $dir = $pathinfo["dirname"];
545  $this->downloadMultipleFiles($array_files, $dir, $a_member_id);
546  }
547  else
548  {
549  return false;
550  }
551 
552  return true;
553  }
554 
561  function updateTutorDownloadTime($a_member_id)
562  {
563  global $ilUser, $ilDB;
564 
565  // set download time
566  $q = "REPLACE INTO exc_usr_tutor (obj_id, usr_id, tutor_id, download_time) VALUES ".
567  "(".$ilDB->quote($this->getObjId()).",".$ilDB->quote($a_member_id).
568  ",".$ilDB->quote($ilUser->getId()).",now())";
569  $ilDB->query($q);
570  }
571 
572  function downloadSelectedFiles($array_file_id,$a_user_id)
573  {
574  global $ilDB;
575 
576  if (count($array_file_id))
577  {
578  $query = "SELECT * FROM exc_returned ".
579  "WHERE user_id = ".$ilDB->quote($a_user_id)." ".
580  "AND returned_id IN (".
581  implode(ilUtil::quoteArray($array_file_id) ,",").")";
582  $result = $this->ilias->db->query($query);
583  if ($result->numRows())
584  {
585  $array_found = array();
586  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
587  {
588  array_push($array_found, $row);
589  }
590  if (count($array_found) == 1)
591  {
592  $this->downloadSingleFile(ilObjExercise::_fixFilename($array_found[0]["filename"]), $array_found[0]["filetitle"]);
593  }
594  else
595  {
596  $filenames = array();
597  $dir = "";
598  $file = "";
599  foreach ($array_found as $key => $value)
600  {
601  $pathinfo = pathinfo(ilObjExercise::_fixFilename($value["filename"]));
602  $dir = $pathinfo["dirname"];
603  $file = $pathinfo["basename"];
604  array_push($filenames, $file);
605  }
606  $this->downloadMultipleFiles($filenames, $dir);
607  }
608  }
609  }
610  }
611 
612  function downloadSingleFile($filename, $filetitle)
613  {
614  require_once "./Services/Utilities/classes/class.ilUtil.php";
615  ilUtil::deliverFile($filename, $filetitle);
616  }
617 
618  function downloadMultipleFiles($array_filenames, $pathname, $a_member_id = 0)
619  {
620  global $lng, $ilObjDataCache;
621  require_once "./Services/Utilities/classes/class.ilUtil.php";
622  $cdir = getcwd();
623 
624  $zip = PATH_TO_ZIP;
625  $tmpdir = ilUtil::ilTempnam();
626  $tmpfile = ilUtil::ilTempnam();
627  $tmpzipfile = $tmpfile . ".zip";
628 
629  ilUtil::makeDir($tmpdir);
630  chdir($tmpdir);
631 
632  //copy all files to a temporary directory and remove them afterwards
633  foreach ($array_filenames as $key => $filename)
634  {
635  // remove timestamp
636  $newFilename = trim(basename($array_filenames[$key]));
637  $pos = strpos($newFilename , "_");
638  if ($pos === false)
639  {
640  } else
641  {
642  $newFilename= substr($newFilename, $pos + 1);
643  }
644  $newFilename = $tmpdir.DIRECTORY_SEPARATOR.$newFilename;
645  // copy to temporal directory
646  $oldFilename = $pathname.DIRECTORY_SEPARATOR.$array_filenames[$key];
647  if (!copy ($oldFilename, $newFilename))
648  {
649  echo 'Could not copy '.$oldFilename.' to '.$newFilename;
650  }
651  touch($newFilename, filectime($oldFilename));
652  $array_filenames[$key] = ilUtil::escapeShellArg(basename($newFilename)); //$array_filenames[$key]);
653  }
654  $zipcmd = $zip." ".ilUtil::escapeShellArg($tmpzipfile)." ".join($array_filenames, " ");
655  exec($zipcmd);
656  ilUtil::delDir($tmpdir);
657  $exerciseTitle = $ilObjDataCache->lookupTitle($this->getObjId());
658  $deliverFilename = $exerciseTitle;
659  if ($a_member_id > 0)
660  {
661  $userName = ilObjUser::_lookupName($a_member_id);
662  $deliverFilename .= "_".$userName["lastname"]."_".$userName["firstname"];
663  } else
664  {
665  $deliverFilename .= "_files";
666  }
667  $deliverFilename .= ".zip";
668  ilUtil::deliverFile($tmpzipfile, $deliverFilename);
669  chdir($cdir);
670  unlink($tmpzipfile);
671  }
672 
673  function setNoticeForMember($a_member_id,$a_notice)
674  {
675  global $ilDB;
676 
677  $query = "UPDATE exc_members ".
678  "SET notice = ".$ilDB->quote($a_notice)." ".
679  "WHERE obj_id = ".$ilDB->quote($this->getObjId())." ".
680  "AND usr_id = ".$ilDB->quote($a_member_id);
681 
682  $this->ilias->db->query($query);
683  $this->read();
684 
685  return true;
686  }
687 /*
688  function update()
689  {
690  $save_members = $this->getMembers();
691  $save_notice = $this->getNotice();
692  $saved_st_solved = $this->getStatusSolved();
693  $saved_st_sent = $this->getStatusSent();
694  $saved_st_return = $this->getStatusReturned();
695 
696  $this->read();
697 
698  // UPDATE MEMBERS
699  foreach(array_diff($this->getMembers(),$save_members) as $member)
700  {
701  $query = "DELETE FROM exc_members ".
702  "WHERE obj_id = '".$this->getObjId()."' ".
703  "AND usr_id = '".$member."'";
704  $this->ilias->db->query($query);
705  }
706  foreach(array_diff($save_members,$this->getMembers()) as $member)
707  {
708  $query = "INSERT INTO exc_members ".
709  "SET obj_id = '".$this->getObjId()."', ".
710  "usr_id = '".$member."', ".
711  "sent = '0', ".
712  "solved = '0'";
713  $this->ilias->db->query($query);
714  }
715  $this->setMembers($save_members);
716  $this->setNotice($save_notice);
717  $this->setStatusSent($saved_st_sent);
718  $this->setStatusSolved($saved_st_solved);
719  $this->setStatusReturned($saved_st_return);
720 
721 
722  // UPDATE SOLVED AND SENT
723  foreach($this->getMembers() as $member)
724  {
725  $query = "UPDATE exc_members ".
726  "SET solved = '".$this->getStatusSolvedByMember($member)."', ".
727  "notice = '".addslashes($this->getNoticeByMember($member))."', ".
728  "returned = '".$this->getStatusReturnedByMember($member)."', ".
729  "sent = '".$this->getStatusSentByMember($member)."'";
730  $this->ilias->db->query($query);
731  }
732  return true;
733  }
734 */
735  function read()
736  {
737  global $ilDB;
738 
739  $tmp_arr_members = array();
740  $tmp_arr_status = array();
741  $tmp_arr_sent = array();
742  $tmp_arr_notice = array();
743  $tmp_arr_returned = array();
744  $tmp_arr_feedback = array();
745 
746  $query = "SELECT * FROM exc_members ".
747  "WHERE obj_id = ".$ilDB->quote($this->getObjId());
748 
749  $res = $this->ilias->db->query($query);
750  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
751  {
752  $tmp_arr_members[] = $row->usr_id;
753  $tmp_arr_notice[$row->usr_id] = $row->notice;
754  $tmp_arr_returned[$row->usr_id] = $row->returned;
755  $tmp_arr_status[$row->usr_id] = $row->status;
756  $tmp_arr_sent[$row->usr_id] = $row->sent;
757  $tmp_arr_feedback[$row->usr_id] = $row->feedback;
758  }
759  $this->setMembers($tmp_arr_members);
760  $this->setNotice($tmp_arr_notice);
761  $this->setStatus($tmp_arr_status);
762  $this->setStatusSent($tmp_arr_sent);
763  $this->setStatusReturned($tmp_arr_returned);
764  $this->setStatusFeedback($tmp_arr_feedback);
765 
766  return true;
767  }
768 
769 
770  function ilClone($a_new_id)
771  {
772  global $ilDB;
773 
774  $data = array();
775 
776  $query = "SELECT * FROM exc_members ".
777  "WHERE obj_id = ".$ilDB->quote($this->getObjId());
778 
779  $res = $this->ilias->db->query($query);
780  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
781  {
782  $data[] = array("usr_id" => $row->usr_id,
783  "notice" => $row->notice,
784  "returned" => $row->returned,
785  "status" => $row->status,
786  "sent" => $row->sent,
787  "feedback" => $row->feedback
788  );
789  }
790  foreach($data as $row)
791  {
792  $query = "INSERT INTO exc_members ".
793  "SET obj_id = ".$ilDB->quote($a_new_id).", ".
794  "usr_id = ".$ilDB->quote($row["usr_id"]).", ".
795  "notice = ".$ilDB->quote($row["notice"]).", ".
796  "returned = ".$ilDB->quote($row["returned"]).", ".
797  "status = ".$ilDB->quote($row["status"]).", ".
798  "feedback = ".$ilDB->quote($row["feedback"]).", ".
799  "sent = ".$ilDB->quote($row["sent"]);
800 
801  $res = $this->ilias->db->query($query);
802  }
803  return true;
804  }
805 
806  function delete()
807  {
808  global $ilDB;
809 
810  $query = "DELETE FROM exc_members WHERE obj_id = ".$ilDB->quote($this->getObjId());
811  $this->ilias->db->query($query);
812 
813  return true;
814  }
815 
816  function _getMembers($a_obj_id)
817  {
818  global $ilDB;
819 
820  $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members ".
821  "WHERE obj_id = ".$ilDB->quote($a_obj_id);
822 
823  $res = $ilDB->query($query);
824  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
825  {
826  $usr_ids[] = $row->ud;
827  }
828 
829  return $usr_ids ? $usr_ids : array();
830  }
831 
832  function _getReturned($a_obj_id)
833  {
834  global $ilDB;
835 
836  $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members ".
837  "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ".
838  "AND returned = 1";
839 
840  $res = $ilDB->query($query);
841  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
842  {
843  $usr_ids[] = $row->ud;
844  }
845 
846  return $usr_ids ? $usr_ids : array();
847  }
848 
849  /* deprecated use _lookupStatus instead
850  modified and added this function again.
851  Learning progress needs this function and _getFailedUsers
852  */
853  function _getPassedUsers($a_obj_id)
854  {
855  global $ilDB;
856 
857  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
858  "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ".
859  "AND status = 'passed'";
860  $res = $ilDB->query($query);
861  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
862  {
863  $usr_ids[] = $row->usr_id;
864  }
865  return $usr_ids ? $usr_ids : array();
866  }
867 
868  function _getFailedUsers($a_obj_id)
869  {
870  global $ilDB;
871 
872  $query = "SELECT DISTINCT(usr_id) FROM exc_members ".
873  "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ".
874  "AND status = 'failed'";
875  $res = $ilDB->query($query);
876  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
877  {
878  $usr_ids[] = $row->usr_id;
879  }
880  return $usr_ids ? $usr_ids : array();
881  }
882 
889  function _lookupStatus($a_obj_id, $a_user_id)
890  {
891  global $ilDB;
892 
893  $query = "SELECT status FROM exc_members ".
894  "WHERE obj_id = ".$ilDB->quote($a_obj_id).
895  "AND usr_id = ".$ilDB->quote($a_user_id);
896 
897  $res = $ilDB->query($query);
898  if($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
899  {
900  return $row["status"];
901  }
902 
903  return false;
904  }
905 
906 } //END class.ilObjExercise
907 ?>