ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjExercise.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "classes/class.ilObject.php";
5 require_once "./Modules/Exercise/classes/class.ilFileDataExercise.php";
6 require_once "./Modules/Exercise/classes/class.ilExerciseMembers.php";
7 
20 class ilObjExercise extends ilObject
21 {
22  var $file_obj;
24  var $files;
25 
27  var $hour;
28  var $minutes;
29  var $day;
30  var $month;
31  var $year;
34 
43  protected $completion_by_submission = false;
44 
51  function ilObjExercise($a_id = 0,$a_call_by_reference = true)
52  {
53  $this->setPassMode("all");
54  $this->type = "exc";
55  $this->ilObject($a_id,$a_call_by_reference);
56  }
57 
58  // SET, GET METHODS
59  function setDate($a_hour,$a_minutes,$a_day,$a_month,$a_year)
60  {
61  $this->hour = (int) $a_hour;
62  $this->minutes = (int) $a_minutes;
63  $this->day = (int) $a_day;
64  $this->month = (int) $a_month;
65  $this->year = (int) $a_year;
66  $this->timestamp = mktime($this->hour,$this->minutes,0,$this->month,$this->day,$this->year);
67  return true;
68  }
69  function getTimestamp()
70  {
71  return $this->timestamp;
72  }
73  function setTimestamp($a_timestamp)
74  {
75  $this->timestamp = $a_timestamp;
76  }
77  function setInstruction($a_instruction)
78  {
79  $this->instruction = $a_instruction;
80  }
81  function getInstruction()
82  {
83  return $this->instruction;
84  }
85 
91  function setPassMode($a_val)
92  {
93  $this->pass_mode = $a_val;
94  }
95 
101  function getPassMode()
102  {
103  return $this->pass_mode;
104  }
105 
111  function setPassNr($a_val)
112  {
113  $this->pass_nr = $a_val;
114  }
115 
121  function getPassNr()
122  {
123  return $this->pass_nr;
124  }
125 
131  function setShowSubmissions($a_val)
132  {
133  $this->show_submissions = $a_val;
134  }
135 
142  {
143  return $this->show_submissions;
144  }
145 
146 
147 /* function getFiles()
148  {
149  return $this->files;
150  }*/
151 
152  function checkDate()
153  {
154  return $this->hour == (int) date("H",$this->timestamp) and
155  $this->minutes == (int) date("i",$this->timestamp) and
156  $this->day == (int) date("d",$this->timestamp) and
157  $this->month == (int) date("m",$this->timestamp) and
158  $this->year == (int) date("Y",$this->timestamp);
159 
160  }
161 
165  function deliverFile($a_http_post_files, $a_ass_id, $user_id, $unzip = false)
166  {
167  global $ilDB;
168 
169  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
170  $storage = new ilFSStorageExercise($this->getId(), $a_ass_id);
171  $deliver_result = $storage->deliverFile($a_http_post_files, $user_id, $unzip);
172 //var_dump($deliver_result);
173  if ($deliver_result)
174  {
175  $next_id = $ilDB->nextId("exc_returned");
176  $query = sprintf("INSERT INTO exc_returned ".
177  "(returned_id, obj_id, user_id, filename, filetitle, mimetype, ts, ass_id) ".
178  "VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
179  $ilDB->quote($next_id, "integer"),
180  $ilDB->quote($this->getId(), "integer"),
181  $ilDB->quote($user_id, "integer"),
182  $ilDB->quote($deliver_result["fullname"], "text"),
183  $ilDB->quote($a_http_post_files["name"], "text"),
184  $ilDB->quote($deliver_result["mimetype"], "text"),
185  $ilDB->quote(ilUtil::now(), "timestamp"),
186  $ilDB->quote($a_ass_id, "integer")
187  );
188  $ilDB->manipulate($query);
189  if (!$this->members_obj->isAssigned($user_id))
190  {
191  $this->members_obj->assignMember($user_id);
192  }
193  ilExAssignment::updateStatusReturnedForUser($a_ass_id, $user_id, 1);
194  ilExerciseMembers::_writeReturned($this->getId(), $user_id, 1);
195  }
196  return true;
197  }
198 
202  function addUploadedFile($a_http_post_files, $unzipUploadedFile = false)
203  {
204  global $lng;
205  if ($unzipUploadedFile && preg_match("/zip/", $a_http_post_files["type"]) == 1)
206  {
207 
208  $this->processUploadedFile($a_http_post_files["tmp_name"], "storeUploadedFile", true);
209  return true;
210 
211 
212  }
213  else
214  {
215  $this->file_obj->storeUploadedFile($a_http_post_files, true);
216  return true;
217  }
218  }
219  function deleteFiles($a_files)
220  {
221  $this->file_obj->unlinkFiles($a_files);
222  }
223 
224  function saveData()
225  {
226  global $ilDB;
227 
228  // SAVE ONLY EXERCISE SPECIFIC DATA
229  /*$query = "INSERT INTO exc_data SET ".
230  "obj_id = ".$ilDB->quote($this->getId()).", ".
231  "instruction = ".$ilDB->quote($this->getInstruction()).", ".
232  "time_stamp = ".$ilDB->quote($this->getTimestamp());
233  $this->ilias->db->query($query);*/
234 
235  $ilDB->insert("exc_data", array(
236  "obj_id" => array("integer", $this->getId()),
237  "instruction" => array("clob", $this->getInstruction()),
238  "time_stamp" => array("integer", $this->getTimestamp()),
239  "pass_mode" => array("text", $this->getPassMode()),
240  "pass_nr" => array("text", $this->getPassNr()),
241  "show_submissions" => array("integer", (int) $this->getShowSubmissions()),
242  'compl_by_submission' => array('integer', (int)$this->isCompletionBySubmissionEnabled()),
243  "certificate_visibility" => array("integer", (int)$this->getCertificateVisibility())
244  ));
245  return true;
246  }
247 
255  public function cloneObject($a_target_id,$a_copy_id = 0)
256  {
257  global $ilDB;
258 
259  // Copy settings
260  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
261  $new_obj->setInstruction($this->getInstruction());
262  $new_obj->setTimestamp($this->getTimestamp());
263  $new_obj->setPassMode($this->getPassMode());
264  $new_obj->saveData();
265  $new_obj->setPassNr($this->getPassNr());
266  $new_obj->setShowSubmissions($this->getShowSubmissions());
267  $new_obj->setCompletionBySubmission($this->isCompletionBySubmissionEnabled());
268 
269 
270  $new_obj->update();
271 
272  // Copy assignments
273  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
274  ilExAssignment::cloneAssignmentsOfExercise($this->getId(), $new_obj->getId());
275  //$tmp_file_obj =& new ilFileDataExercise($this->getId());
276  //$tmp_file_obj->ilClone($new_obj->getId());
277  //unset($tmp_file_obj);
278 
279  // Copy learning progress settings
280  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
281  $obj_settings = new ilLPObjSettings($this->getId());
282  $obj_settings->cloneSettings($new_obj->getId());
283  unset($obj_settings);
284 
285  return $new_obj;
286  }
287 
294  function deleteDeliveredFiles($a_exc_id, $a_ass_id, $file_id_array, $user_id)
295  {
296  ilExAssignment::deleteDeliveredFiles($a_exc_id, $a_ass_id, $file_id_array, $user_id);
297 
298  // Finally update status 'returned' of member if no file exists
299  if(!count(ilExAssignment::getDeliveredFiles($a_exc_id, $a_ass_id, $user_id)))
300  {
301  ilExAssignment::updateStatusReturnedForUser($a_ass_id, $user_id, 0);
302  }
303  }
304 
310  function deliverReturnedFiles($user_id)
311  {
312  require_once "./Services/Utilities/classes/class.ilUtil.php";
313  }
314 
321  function delete()
322  {
323  global $ilDB;
324 
325  // always call parent delete function first!!
326  if (!parent::delete())
327  {
328  return false;
329  }
330  // put here course specific stuff
331  $ilDB->manipulate("DELETE FROM exc_data ".
332  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer"));
333 
334  //$this->ilias->db->query($query);
335 
336  //$this->file_obj->delete();
337  //$this->members_obj->delete();
338 
339  // remove all notifications
340  include_once "./Services/Notification/classes/class.ilNotification.php";
342 
343  return true;
344  }
345 
356  function notify($a_event,$a_ref_id,$a_node_id,$a_params = 0)
357  {
358  // object specific event handling
359 
360  parent::notify($a_event,$a_ref_id,$a_node_id,$a_params);
361  }
362 
363  function read()
364  {
365  global $ilDB;
366 
367  parent::read();
368 
369  $query = "SELECT * FROM exc_data ".
370  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
371 
372  $res = $ilDB->query($query);
373  while($row = $ilDB->fetchObject($res))
374  {
375  $this->setInstruction($row->instruction);
376  $this->setTimestamp($row->time_stamp);
377  $pm = ($row->pass_mode == "")
378  ? "all"
379  : $row->pass_mode;
380  $this->setPassMode($pm);
381  $this->setShowSubmissions($row->show_submissions);
382  if ($row->pass_mode == "nr")
383  {
384  $this->setPassNr($row->pass_nr);
385  }
386  $this->setCompletionBySubmission($row->compl_by_submission == 1 ? true : false);
387  $this->setCertificateVisibility($row->certificate_visibility);
388  }
389 
390  $this->members_obj = new ilExerciseMembers($this);
391 
392  // GET FILE ASSIGNED TO EXERCISE
393 // $this->file_obj = new ilFileDataExercise($this->getId());
394 // $this->files = $this->file_obj->getFiles();
395 
396  return true;
397  }
398 
399  function update()
400  {
401  global $ilDB;
402 
403  parent::update();
404 
405  /*$query = "UPDATE exc_data SET ".
406  "instruction = ".$ilDB->quote($this->getInstruction()).", ".
407  "time_stamp = ".$ilDB->quote($this->getTimestamp())." ".
408  "WHERE obj_id = ".$ilDB->quote($this->getId());
409  */
410 
411  if ($this->getPassMode() == "all")
412  {
413  $pass_nr = null;
414  }
415  else
416  {
417  $pass_nr = $this->getPassNr();
418  }
419 
420  $ilDB->update("exc_data", array(
421  "instruction" => array("clob", $this->getInstruction()),
422  "time_stamp" => array("integer", $this->getTimestamp()),
423  "pass_mode" => array("text", $this->getPassMode()),
424  "pass_nr" => array("integer", $this->getPassNr()),
425  "show_submissions" => array("integer", (int) $this->getShowSubmissions()),
426  'compl_by_submission' => array('integer', (int)$this->isCompletionBySubmissionEnabled())
427  ), array(
428  "obj_id" => array("integer", $this->getId())
429  ));
430 
431  $this->updateAllUsersStatus();
432 
433  //$res = $this->ilias->db->query($query);
434 
435  #$this->members_obj->update();
436  return true;
437  }
438 
442  function sendAssignment($a_exc_id, $a_ass_id, $a_members)
443  {
444  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
445  $ass_title = ilExAssignment::lookupTitle($a_ass_id);
446 
447  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
448  $storage = new ilFSStorageExercise($a_exc_id, $a_ass_id);
449  $files = $storage->getFiles();
450 
451  if(count($files))
452  {
453  include_once "./classes/class.ilFileDataMail.php";
454 
455  $mfile_obj = new ilFileDataMail($_SESSION["AccountId"]);
456  foreach($files as $file)
457  {
458  $mfile_obj->copyAttachmentFile($file["fullpath"], $file["name"]);
459  $file_names[] = $file["name"];
460  }
461  }
462 
463  include_once "Services/Mail/classes/class.ilMail.php";
464 
465  $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
466  $message = $tmp_mail_obj->sendMail(
467  $this->__formatRecipients($a_members),"","",
468  $this->__formatSubject($ass_title), $this->__formatBody($a_ass_id),
469  count($file_names) ? $file_names : array(),array("normal"));
470 
471  unset($tmp_mail_obj);
472 
473  if(count($file_names))
474  {
475  $mfile_obj->unlinkFiles($file_names);
476  unset($mfile_obj);
477  }
478 
479 
480  // SET STATUS SENT FOR ALL RECIPIENTS
481  foreach($a_members as $member_id => $value)
482  {
483  ilExAssignment::updateStatusSentForUser($a_ass_id, $member_id, 1);
484  }
485 
486  return true;
487  }
488 
492  function _lookupStatusTime($exc_id, $member_id)
493  {
494 
495  global $ilDB, $lng;
496 
497  $q = "SELECT * ".
498  "FROM exc_members ".
499  "WHERE obj_id= ".$ilDB->quote($exc_id, "integer").
500  " AND usr_id= ".$ilDB->quote($member_id, "integer");
501 
502  $set = $ilDB->query($q);
503  if ($rec = $ilDB->fetchAssoc($set))
504  {
505  return ilUtil::getMySQLTimestamp($rec["status_time"]);
506  }
507  }
508 
509  // PRIVATE METHODS
510  function __formatBody($a_ass_id)
511  {
512  global $lng;
513 
514  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
515  $ass = new ilExAssignment($a_ass_id);
516 
517  $body = $ass->getInstruction();
518  $body .= "\n\n";
519  $body .= $lng->txt("exc_edit_until") . ": ".
520  ilFormat::formatDate(date("Y-m-d H:i:s",$ass->getDeadline()), "datetime", true);
521  $body .= "\n\n";
522  $body .= ILIAS_HTTP_PATH.
523  "/goto.php?target=".
524  $this->getType().
525  "_".$this->getRefId()."&client_id=".CLIENT_ID;
526 
527  return $body;
528  }
529 
530  function __formatSubject($a_ass_title = "")
531  {
532  $subject = $this->getTitle();
533 
534  if ($a_ass_title != "")
535  {
536  $subject.= ": ".$a_ass_title;
537  }
538 
539  return $subject;
540  }
541 
542  function __formatRecipients($a_members)
543  {
544  foreach($a_members as $member_id => $value)
545  {
546  $tmp_obj = ilObjectFactory::getInstanceByObjId($member_id);
547  $tmp_members[] = $tmp_obj->getLogin();
548 
549  unset($tmp_obj);
550  }
551 
552  return implode(',',$tmp_members ? $tmp_members : array());
553  }
554 
555  function _checkCondition($a_exc_id,$a_operator,$a_value,$a_usr_id = 0)
556  {
557  global $ilUser;
558 
559  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
560 
561  switch($a_operator)
562  {
563  case 'passed':
564  if (ilExerciseMembers::_lookupStatus($a_exc_id, $a_usr_id) == "passed")
565  {
566  return true;
567  }
568  else
569  {
570  return false;
571  }
572  break;
573 
574  default:
575  return true;
576  }
577  return true;
578  }
579 
586  function processUploadedFile ($fileTmp, $storageMethod, $persistentErrorMessage,
587  $a_ass_id)
588  {
589  global $lng, $ilUser;
590 
591  // Create unzip-directory
592  $newDir = ilUtil::ilTempnam();
593  ilUtil::makeDir($newDir);
594 
595  include_once ("Services/Utilities/classes/class.ilFileUtils.php");
596 
597  try
598  {
599  $processDone = ilFileUtils::processZipFile($newDir,$fileTmp, false);
600  ilFileUtils::recursive_dirscan($newDir, $filearray);
601 
602  foreach ($filearray["file"] as $key => $filename)
603  {
604  $a_http_post_files["name"] = ilFileUtils::utf8_encode($filename);
605  $a_http_post_files["type"] = "other";
606  $a_http_post_files["tmp_name"] = $filearray["path"][$key]."/".$filename;
607  $a_http_post_files["error"] = 0;
608  $a_http_post_files["size"] = filesize($filearray["path"][$key]."/".$filename);
609 
610  if ($storageMethod == "deliverFile")
611  {
612  $this->$storageMethod($a_http_post_files, $a_ass_id, $ilUser->id, true);
613  }
614  else if ($storageMethod == "storeUploadedFile")
615  {
616  $this->file_obj->$storageMethod($a_http_post_files, true, true);
617  }
618  }
619  ilExerciseMembers::_writeReturned($this->getId(), $ilUser->id, 1);
620  ilUtil::sendSuccess($this->lng->txt("file_added"),$persistentErrorMessage);
621 
622  }
623  catch (ilFileUtilsException $e)
624  {
625  ilUtil::sendFailure($e->getMessage(), $persistentErrorMessage);
626  }
627 
628 
629  ilUtil::delDir($newDir);
630  return $processDone;
631 
632  }
633 
644  static function _fixFilename($a_filename)
645  {
646  $ex_pos = strrpos($a_filename, "/exercise/");
647  if ($ex_pos > 0)
648  {
649  $a_filename = CLIENT_DATA_DIR.substr($a_filename, $ex_pos);
650  }
651  return $a_filename;
652  }
653 
658  static function _fixFilenameArray($a_array)
659  {
660  if (is_array($a_array))
661  {
662  foreach ($a_array as $k => $v)
663  {
664  if ($v["filename"] != "")
665  {
666  $a_array[$k]["filename"] = ilObjExercise::_fixFilename($a_array[$k]["filename"]);
667  }
668  }
669  }
670 
671  return $a_array;
672  }
673 
677  function determinStatusOfUser($a_user_id = 0)
678  {
679  global $ilUser;
680 
681  if ($a_user_id == 0)
682  {
683  $a_user_id = $ilUser->getId();
684  }
685 
686  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
688 
689  $passed_all_mandatory = true;
690  $failed_a_mandatory = false;
691  $cnt_passed = 0;
692  $cnt_notgraded = 0;
693  $passed_at_least_one = false;
694 
695  foreach ($ass as $a)
696  {
697  $stat = ilExAssignment::lookupStatusOfUser($a["id"], $a_user_id);
698  if ($a["mandatory"] && ($stat == "failed" || $stat == "notgraded"))
699  {
700  $passed_all_mandatory = false;
701  }
702  if ($a["mandatory"] && ($stat == "failed"))
703  {
704  $failed_a_mandatory = true;
705  }
706  if ($stat == "passed")
707  {
708  $cnt_passed++;
709  }
710  if ($stat == "notgraded")
711  {
712  $cnt_notgraded++;
713  }
714  }
715 
716  if (count($ass) == 0)
717  {
718  $passed_all_mandatory = false;
719  }
720 
721  if ($this->getPassMode() != "nr")
722  {
723 //echo "5";
724  $overall_stat = "notgraded";
725  if ($failed_a_mandatory)
726  {
727 //echo "6";
728  $overall_stat = "failed";
729  }
730  else if ($passed_all_mandatory && $cnt_passed > 0)
731  {
732 //echo "7";
733  $overall_stat = "passed";
734  }
735  }
736  else
737  {
738 //echo "8";
739  $min_nr = $this->getPassNr();
740  $overall_stat = "notgraded";
741 //echo "*".$cnt_passed."*".$cnt_notgraded."*".$min_nr."*";
742  if ($failed_a_mandatory || ($cnt_passed + $cnt_notgraded < $min_nr))
743  {
744 //echo "9";
745  $overall_stat = "failed";
746  }
747  else if ($passed_all_mandatory && $cnt_passed >= $min_nr)
748  {
749 //echo "A";
750  $overall_stat = "passed";
751  }
752  }
753 
754  $ret = array(
755  "overall_status" => $overall_stat,
756  "failed_a_mandatory" => $failed_a_mandatory);
757 //echo "<br>p:".$cnt_passed.":ng:".$cnt_notgraded;
758 //var_dump($ret);
759  return $ret;
760  }
761 
765  function updateUserStatus($a_user_id = 0)
766  {
767  global $ilUser;
768 
769  if ($a_user_id == 0)
770  {
771  $a_user_id = $ilUser->getId();
772  }
773 
774  $st = $this->determinStatusOfUser($a_user_id);
775 
776  include_once("./Modules/Exercise/classes/class.ilExerciseMembers.php");
777  ilExerciseMembers::_writeStatus($this->getId(), $a_user_id,
778  $st["overall_status"]);
779  }
780 
785  {
786  if (!is_object($this->members_obj));
787  {
788  $this->members_obj = new ilExerciseMembers($this);
789  }
790 
791  $mems = $this->members_obj->getMembers();
792  foreach ($mems as $mem)
793  {
794  $this->updateUserStatus($mem);
795  }
796  }
797 
801  function exportGradesExcel()
802  {
803  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
805 
806  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
807  $excelfile = ilUtil::ilTempnam();
808  $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
809  $workbook = $adapter->getWorkbook();
810  $workbook->setVersion(8); // Use Excel97/2000 Format
811  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
812 
813  //
814  // status
815  //
816  $mainworksheet = $workbook->addWorksheet();
817 
818  // header row
819  $mainworksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("name")));
820  $cnt = 1;
821  foreach ($ass_data as $ass)
822  {
823  $mainworksheet->writeString(0, $cnt, $cnt);
824  $cnt++;
825  }
826  $mainworksheet->writeString(0, $cnt, ilExcelUtils::_convert_text($this->lng->txt("exc_total_exc")));
827 
828  // data rows
829  $this->mem_obj = new ilExerciseMembers($this);
830  $getmems = $this->mem_obj->getMembers();
831  $mems = array();
832  foreach ($getmems as $user_id)
833  {
834  $mems[$user_id] = ilObjUser::_lookupName($user_id);
835  }
836  $mems = ilUtil::sortArray($mems, "lastname", "asc", false, true);
837 
838  $data = array();
839  $row_cnt = 1;
840  foreach ($mems as $user_id => $d)
841  {
842  $col_cnt = 1;
843 
844  // name
845  $mainworksheet->writeString($row_cnt, 0,
846  ilExcelUtils::_convert_text($d["lastname"].", ".$d["firstname"]." [".$d["login"]."]"));
847 
848  reset($ass_data);
849 
850  foreach ($ass_data as $ass)
851  {
852  $status = ilExAssignment::lookupStatusOfUser($ass["id"], $user_id);
853  $mainworksheet->writeString($row_cnt, $col_cnt, ilExcelUtils::_convert_text($this->lng->txt("exc_".$status)));
854  $col_cnt++;
855  }
856 
857  // total status
858  $status = ilExerciseMembers::_lookupStatus($this->getId(), $user_id);
859  $mainworksheet->writeString($row_cnt, $col_cnt, ilExcelUtils::_convert_text($this->lng->txt("exc_".$status)));
860 
861  $row_cnt++;
862  }
863 
864  //
865  // mark
866  //
867  $worksheet2 = $workbook->addWorksheet();
868 
869  // header row
870  $worksheet2->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("name")));
871  $cnt = 1;
872  foreach ($ass_data as $ass)
873  {
874  $worksheet2->writeString(0, $cnt, $cnt);
875  $cnt++;
876  }
877  $worksheet2->writeString(0, $cnt, ilExcelUtils::_convert_text($this->lng->txt("exc_total_exc")));
878 
879  // data rows
880  $data = array();
881  $row_cnt = 1;
882  reset($mems);
883  foreach ($mems as $user_id => $d)
884  {
885  $col_cnt = 1;
886  $d = ilObjUser::_lookupName($user_id);
887 
888  // name
889  $worksheet2->writeString($row_cnt, 0,
890  ilExcelUtils::_convert_text($d["lastname"].", ".$d["firstname"]." [".$d["login"]."]"));
891 
892  reset($ass_data);
893 
894  foreach ($ass_data as $ass)
895  {
896  $worksheet2->writeString($row_cnt, $col_cnt,
898  $col_cnt++;
899  }
900 
901  // total mark
902  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
903  $worksheet2->writeString($row_cnt, $col_cnt,
905 
906  $row_cnt++;
907  }
908 
909 
910  $workbook->close();
911  $exc_name = ilUtil::getASCIIFilename(preg_replace("/\s/", "_", $this->getTitle()));
912  ilUtil::deliverFile($excelfile, $exc_name.".xls", "application/vnd.ms-excel");
913  }
914 
918  function sendFeedbackFileNotification($a_feedback_file, $a_user_id, $a_ass_id)
919  {
920  include_once("./Modules/Exercise/classes/class.ilExerciseMailNotification.php");
921  $not = new ilExerciseMailNotification();
923  $not->setAssignmentId($a_ass_id);
924  $not->setRefId($this->getRefId());
925  $not->setRecipients(array($a_user_id));
926  $not->send();
927  }
928 
938  {
940  }
941 
951  public function setCompletionBySubmission($bool)
952  {
953  $this->completion_by_submission = (bool)$bool;
954 
955  return $this;
956  }
957 
968  public function handleSubmission($ass_id)
969  {
970  global $ilUser, $ilDB;
971 
973  {
974  include_once 'Modules/Exercise/classes/class.ilExAssignment.php';
975 
976  $res = $ilDB->queryF(
977  'SELECT returned_id FROM exc_returned WHERE obj_id = %s AND user_id = %s AND ass_id = %s',
978  array('integer', 'integer', 'integer'),
979  array($this->getId(), $ilUser->getId(), (int)$ass_id)
980  );
981 
982  if($num = $ilDB->numRows($res))
983  {
984  ilExAssignment::updateStatusOfUser($ass_id, $ilUser->getId(), 'passed');
985  }
986  else
987  {
988  ilExAssignment::updateStatusOfUser($ass_id, $ilUser->getId(), 'notgraded');
989  }
990  }
991  }
992 
999  public static function _lookupFinishedUserExercises($a_user_id)
1000  {
1001  global $ilDB;
1002 
1003  $set = $ilDB->query("SELECT obj_id, status FROM exc_members".
1004  " WHERE usr_id = ".$ilDB->quote($a_user_id, "integer").
1005  " AND (status = ".$ilDB->quote("passed", "text").
1006  " OR status = ".$ilDB->quote("failed", "text").")");
1007 
1008  $all = array();
1009  while($row = $ilDB->fetchAssoc($set))
1010  {
1011  $all[$row["obj_id"]] = ($row["status"] == "passed");
1012  }
1013  return $all;
1014  }
1015 
1023  function addResourceObject($a_wsp_id, $a_ass_id, $user_id)
1024  {
1025  global $ilDB;
1026 
1027  $next_id = $ilDB->nextId("exc_returned");
1028  $query = sprintf("INSERT INTO exc_returned ".
1029  "(returned_id, obj_id, user_id, filetitle, ass_id) ".
1030  "VALUES (%s, %s, %s, %s, %s)",
1031  $ilDB->quote($next_id, "integer"),
1032  $ilDB->quote($this->getId(), "integer"),
1033  $ilDB->quote($user_id, "integer"),
1034  $ilDB->quote($a_wsp_id, "text"),
1035  $ilDB->quote($a_ass_id, "integer")
1036  );
1037  $ilDB->manipulate($query);
1038  if (!$this->members_obj->isAssigned($user_id))
1039  {
1040  $this->members_obj->assignMember($user_id);
1041  }
1042  // no submission yet
1043  ilExAssignment::updateStatusReturnedForUser($a_ass_id, $user_id, 0);
1044  ilExerciseMembers::_writeReturned($this->getId(), $user_id, 0);
1045  }
1046 
1052  function deleteAllDeliveredFilesOfUser($a_user_id)
1053  {
1054  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
1056  }
1057 
1064  public static function findUserFiles($a_user_id, $a_filetitle)
1065  {
1066  global $ilDB;
1067 
1068  $set = $ilDB->query("SELECT obj_id, ass_id".
1069  " FROM exc_returned".
1070  " WHERE user_id = ".$ilDB->quote($a_user_id, "integer").
1071  " AND filetitle = ".$ilDB->quote($a_filetitle, "text"));
1072  $res = array();
1073  while($row = $ilDB->fetchAssoc($set))
1074  {
1075  $res[$row["ass_id"]] = $row;
1076  }
1077  return $res;
1078  }
1079 
1087  {
1088  return (strlen($this->certificate_visibility)) ? $this->certificate_visibility : 0;
1089  }
1090 
1097  function setCertificateVisibility($a_value)
1098  {
1099  $this->certificate_visibility = $a_value;
1100  }
1101 
1108  function saveCertificateVisibility($a_value)
1109  {
1110  global $ilDB;
1111 
1112  $affectedRows = $ilDB->manipulateF("UPDATE exc_data SET certificate_visibility = %s WHERE obj_id = %s",
1113  array('integer', 'integer'),
1114  array($a_value, $this->getId())
1115  );
1116  }
1117 
1124  function hasUserCertificate($a_user_id)
1125  {
1126  // show certificate?
1127  include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
1128  if(ilRPCServerSettings::getInstance()->isEnabled())
1129  {
1130  $certificate_visible = $this->getCertificateVisibility();
1131  // if not never
1132  if($certificate_visible != 2)
1133  {
1134  // if passed only
1135  include_once 'Modules/Exercise/classes/class.ilExerciseMembers.php';
1136  $status = ilExerciseMembers::_lookupStatus($this->getId(), $a_user_id);
1137  if($certificate_visible == 1 && $status == "passed")
1138  {
1139  return true;
1140  }
1141  // always (excluding notgraded)
1142  else if($certificate_visible == 0 && $status != "notgraded")
1143  {
1144  return true;
1145  }
1146  }
1147  }
1148  return false;
1149  }
1150 }
1151 
1152 ?>