/**
  * add an exercise with id.
  *
  * @param string $session_id    current session
  * @param int $target_id refid of parent in repository
  * @param string $exercise_xml   qti xml description of test
  *
  * @return int reference id in the tree, 0 if not successful
  */
 function addExercise($sid, $target_id, $exercise_xml)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     global $rbacsystem, $tree, $ilLog;
     if (!($target_obj =& ilObjectFactory::getInstanceByRefId($target_id, false))) {
         return $this->__raiseError('No valid target given.', 'Client');
     }
     if (ilObject::_isInTrash($target_id)) {
         return $this->__raiseError("Parent with ID {$target_id} has been deleted.", 'CLIENT_OBJECT_DELETED');
     }
     // Check access
     $allowed_types = array('cat', 'grp', 'crs', 'fold', 'root');
     if (!in_array($target_obj->getType(), $allowed_types)) {
         return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
     }
     if (!$rbacsystem->checkAccess('create', $target_id, "exc")) {
         return $this->__raiseError('No permission to create exercises in target  ' . $target_id . '!', 'Client');
     }
     // create object, put it into the tree and use the parser to update the settings
     include_once './Modules/Exercise/classes/class.ilObjExercise.php';
     include_once './Modules/Exercise/classes/class.ilExerciseXMLParser.php';
     include_once './Modules/Exercise/classes/class.ilExerciseException.php';
     $exercise = new ilObjExercise();
     $exercise->create();
     $exercise->createReference();
     $exercise->putInTree($target_id);
     $exercise->setPermissions($target_id);
     $exercise->saveData();
     // we need this as workaround because file and member objects need to be initialised
     $exercise->read();
     $exerciseXMLParser = new ilExerciseXMLParser($exercise, $exercise_xml);
     try {
         if ($exerciseXMLParser->start()) {
             $exerciseXMLParser->getAssignment()->update();
             return $exercise->update() ? $exercise->getRefId() : -1;
         }
         throw new ilExerciseException("Could not parse XML");
     } catch (ilExerciseException $exception) {
         return $this->__raiseError($exception->getMessage(), $exception->getCode() == ilExerciseException::$ID_MISMATCH ? "Client" : "Server");
     }
 }
Ejemplo n.º 2
0
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     //echo $a_entity;
     //var_dump($a_rec);
     switch ($a_entity) {
         case "exc":
             include_once "./Modules/Exercise/classes/class.ilObjExercise.php";
             if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
                 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
             } else {
                 $newObj = new ilObjExercise();
                 $newObj->setType("exc");
                 $newObj->create(true);
             }
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setDescription($a_rec["Description"]);
             $newObj->setPassMode($a_rec["PassMode"]);
             $newObj->setPassNr($a_rec["PassNr"]);
             $newObj->setShowSubmissions($a_rec["ShowSubmissions"]);
             $newObj->update();
             $newObj->saveData();
             //var_dump($a_rec);
             $this->current_exc = $newObj;
             $a_mapping->addMapping("Modules/Exercise", "exc", $a_rec["Id"], $newObj->getId());
             //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
             break;
         case "exc_assignment":
             $exc_id = $a_mapping->getMapping("Modules/Exercise", "exc", $a_rec["ExerciseId"]);
             if ($exc_id > 0) {
                 if (is_object($this->current_exc) && $this->current_exc->getId() == $exc_id) {
                     $exc = $this->current_exc;
                 } else {
                     include_once "./Modules/Exercise/classes/class.ilObjExercise.php";
                     $exc = new ilObjExercise($exc_id, false);
                 }
                 include_once "./Modules/Exercise/classes/class.ilExAssignment.php";
                 $ass = new ilExAssignment();
                 $ass->setExerciseId($exc_id);
                 if ($a_rec["StartTime"] != "") {
                     $start = new ilDateTime($a_rec["StartTime"], IL_CAL_DATETIME, "UTC");
                     $ass->setStartTime($start->get(IL_CAL_UNIX));
                 }
                 if ($a_rec["Deadline"] != "") {
                     $deadline = new ilDateTime($a_rec["Deadline"], IL_CAL_DATETIME, "UTC");
                     $ass->setDeadline($deadline->get(IL_CAL_UNIX));
                 }
                 //var_dump($a_rec);
                 $ass->setInstruction($a_rec["Instruction"]);
                 $ass->setTitle($a_rec["Title"]);
                 $ass->setMandatory($a_rec["Mandatory"]);
                 $ass->setOrderNr($a_rec["OrderNr"]);
                 // 4.2
                 $ass->setType($a_rec["Type"]);
                 // 4.4
                 $ass->setPeerReview($a_rec["Peer"]);
                 $ass->setPeerReviewMin($a_rec["PeerMin"]);
                 $ass->setPeerReviewDeadline($a_rec["PeerDeadline"]);
                 $ass->setFeedbackFile($a_rec["FeedbackFile"]);
                 $ass->setFeedbackCron($a_rec["FeedbackCron"]);
                 $ass->setFeedbackDate($a_rec["FeedbackDate"]);
                 // 5.0
                 $ass->setPeerReviewFileUpload($a_rec["PeerFile"]);
                 $ass->setPeerReviewPersonalized($a_rec["PeerPersonal"]);
                 $ass->save();
                 include_once "./Modules/Exercise/classes/class.ilFSStorageExercise.php";
                 $fstorage = new ilFSStorageExercise($exc_id, $ass->getId());
                 $fstorage->create();
                 // assignment files
                 $dir = str_replace("..", "", $a_rec["Dir"]);
                 if ($dir != "" && $this->getImportDirectory() != "") {
                     $source_dir = $this->getImportDirectory() . "/" . $dir;
                     $target_dir = $fstorage->getPath();
                     ilUtil::rCopy($source_dir, $target_dir);
                 }
                 // (4.4) global feedback file
                 $dir = str_replace("..", "", $a_rec["FeedbackDir"]);
                 if ($dir != "" && $this->getImportDirectory() != "") {
                     $source_dir = $this->getImportDirectory() . "/" . $dir;
                     $target_dir = $fstorage->getGlobalFeedbackPath();
                     ilUtil::rCopy($source_dir, $target_dir);
                 }
                 $a_mapping->addMapping("Modules/Exercise", "exc_assignment", $a_rec["Id"], $ass->getId());
             }
             break;
     }
 }