Ejemplo n.º 1
0
 function start()
 {
     $this->__buildHeader();
     $attribs = array("obj_id" => "il_" . IL_INST_ID . "_exc_" . $this->exercise->getId());
     if ($this->exercise->getOwner()) {
         $attribs["owner"] = "il_" . IL_INST_ID . "_usr_" . $this->exercise->getOwner();
     }
     $this->xmlStartTag("Exercise", $attribs);
     //todo: create new dtd for new assignment structure
     $this->xmlElement("Title", null, $this->exercise->getTitle());
     $this->xmlElement("Description", null, $this->exercise->getDescription());
     //$this->xmlElement("Instruction",  null,$this->exercise->getInstruction());
     //$this->xmlElement("DueDate",  null,$this->exercise->getTimestamp());
     //todo: as a workaround use first assignment for compatibility with old exercise dtd
     $assignments = ilExAssignment::getAssignmentDataOfExercise($this->exercise->getId());
     if (count($assignments) > 0) {
         foreach ($assignments as $assignment) {
             $this->xmlStartTag("Assignment");
             $this->xmlElement("Instruction", null, $assignment["instruction"]);
             $this->xmlElement("DueDate", null, $assignment["deadline"]);
             $this->handleAssignmentFiles($this->exercise->getId(), $assignment["id"]);
             if ($this->attachMembers) {
                 $this->handleAssignmentMembers($this->exercise->getId(), $assignment["id"]);
             }
             $this->xmlEndTag("Assignment");
         }
     }
     $this->xmlEndTag("Exercise");
     $this->__buildFooter();
     return true;
 }
 /**
  * Import relevant properties from given exercise
  *
  * @param ilObjExercise $a_test
  * @return object
  */
 public static function createFromExercise(ilObjExercise $a_exercise, $a_user_id)
 {
     global $lng;
     $lng->loadLanguageModule("exercise");
     $newObj = new self();
     $newObj->setTitle($a_exercise->getTitle());
     $newObj->setDescription($a_exercise->getDescription());
     include_once "Services/Tracking/classes/class.ilLPMarks.php";
     $lp_marks = new ilLPMarks($a_exercise->getId(), $a_user_id);
     $newObj->setProperty("issued_on", new ilDate($lp_marks->getStatusChanged(), IL_CAL_DATETIME));
     // create certificate
     include_once "Services/Certificate/classes/class.ilCertificate.php";
     include_once "Modules/Exercise/classes/class.ilExerciseCertificateAdapter.php";
     $certificate = new ilCertificate(new ilExerciseCertificateAdapter($a_exercise));
     $certificate = $certificate->outCertificate(array("user_id" => $a_user_id), false);
     // save pdf file
     if ($certificate) {
         // we need the object id for storing the certificate file
         $newObj->create();
         $path = self::initStorage($newObj->getId(), "certificate");
         $file_name = "exc_" . $a_exercise->getId() . "_" . $a_user_id . ".pdf";
         if (file_put_contents($path . $file_name, $certificate)) {
             $newObj->setProperty("file", $file_name);
             $newObj->update();
             return $newObj;
         }
         // file creation failed, so remove to object, too
         $newObj->delete();
     }
     // remove if certificate works
     $newObj->create();
     return $newObj;
 }