Beispiel #1
0
 /**
  * Clone poll
  *
  * @param ilObjPoll new object
  * @param int target ref_id
  * @param int copy id
  * @return ilObjPoll
  */
 public function doCloneObject(ilObjPoll $new_obj, $a_target_id, $a_copy_id = 0)
 {
     // question/image
     $new_obj->setQuestion($this->getQuestion());
     $image = $this->getImageFullPath();
     if ($image) {
         $image = array("tmp_name" => $image, "name" => $this->getImage());
         $new_obj->uploadImage($image, true);
     }
     //copy online status if object is not the root copy object
     $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
     if (!$cp_options->isRootNode($this->getRefId())) {
         $new_obj->setOnline($this->isOnline());
     }
     $new_obj->setViewResults($this->getViewResults());
     $new_obj->setShowComments($this->getShowComments());
     $new_obj->setShowResultsAs($this->getShowResultsAs());
     $new_obj->update();
     // answers
     $answers = $this->getAnswers();
     if ($answers) {
         foreach ($answers as $item) {
             $new_obj->saveAnswer($item["answer"]);
         }
     }
     return $new_obj;
 }
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     switch ($a_entity) {
         case "poll":
             include_once "./Modules/Poll/classes/class.ilObjPoll.php";
             $newObj = new ilObjPoll();
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setDescription($a_rec["Description"]);
             $newObj->create();
             $newObj->setQuestion($a_rec["Question"]);
             $newObj->setImage($a_rec["Image"]);
             $newObj->setViewResults($a_rec["ViewResults"]);
             $newObj->update();
             // handle image(s)
             if ($a_rec["Image"]) {
                 $dir = str_replace("..", "", $a_rec["Dir"]);
                 if ($dir != "" && $this->getImportDirectory() != "") {
                     $source_dir = $this->getImportDirectory() . "/" . $dir;
                     $target_dir = ilObjPoll::initStorage($newObj->getId());
                     ilUtil::rCopy($source_dir, $target_dir);
                 }
             }
             $a_mapping->addMapping("Modules/Poll", "poll", $a_rec["Id"], $newObj->getId());
             break;
         case "poll_answer":
             $poll_id = (int) $a_mapping->getMapping("Modules/Poll", "poll", $a_rec["PollId"]);
             if ($poll_id) {
                 $poll = new ilObjPoll($poll_id, false);
                 $poll->saveAnswer($a_rec["Answer"], $a_rec["pos"]);
             }
             break;
     }
 }
Beispiel #3
0
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     switch ($a_entity) {
         case "poll":
             include_once "./Modules/Poll/classes/class.ilObjPoll.php";
             // container copy
             if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"])) {
                 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
             } else {
                 $newObj = new ilObjPoll();
                 $newObj->create();
             }
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setDescription($a_rec["Description"]);
             if ((int) $a_rec["MaxAnswers"]) {
                 $newObj->setMaxNumberOfAnswers($a_rec["MaxAnswers"]);
             }
             $newObj->setSortResultByVotes((bool) $a_rec["ResultSort"]);
             $newObj->setNonAnonymous((bool) $a_rec["NonAnon"]);
             if ((int) $a_rec["ShowResultsAs"]) {
                 $newObj->setShowResultsAs($a_rec["ShowResultsAs"]);
             }
             $newObj->setShowComments($a_rec["ShowComments"]);
             $newObj->setQuestion($a_rec["Question"]);
             $newObj->setImage($a_rec["Image"]);
             $newObj->setViewResults($a_rec["ViewResults"]);
             $newObj->update();
             // handle image(s)
             if ($a_rec["Image"]) {
                 $dir = str_replace("..", "", $a_rec["Dir"]);
                 if ($dir != "" && $this->getImportDirectory() != "") {
                     $source_dir = $this->getImportDirectory() . "/" . $dir;
                     $target_dir = ilObjPoll::initStorage($newObj->getId());
                     ilUtil::rCopy($source_dir, $target_dir);
                 }
             }
             $a_mapping->addMapping("Modules/Poll", "poll", $a_rec["Id"], $newObj->getId());
             break;
         case "poll_answer":
             $poll_id = (int) $a_mapping->getMapping("Modules/Poll", "poll", $a_rec["PollId"]);
             if ($poll_id) {
                 $poll = new ilObjPoll($poll_id, false);
                 $poll->saveAnswer($a_rec["Answer"], $a_rec["pos"]);
             }
             break;
     }
 }
 /**
  * Clone poll
  *
  * @param ilObjPoll new object
  * @param int target ref_id
  * @param int copy id
  * @return ilObjPoll
  */
 public function doCloneObject(ilObjPoll $new_obj, $a_target_id, $a_copy_id = 0)
 {
     // question/image
     $new_obj->setQuestion($this->getQuestion());
     $image = $this->getImageFullPath();
     if ($image) {
         $image = array("tmp_name" => $image, "name" => $this->getImage());
         $new_obj->uploadImage($image, true);
     }
     $new_obj->setViewResults($this->getViewResults());
     $new_obj->update();
     // answers
     $answers = $this->getAnswers();
     if ($answers) {
         foreach ($answers as $item) {
             $new_obj->saveAnswer($item["answer"]);
         }
     }
     return $new_obj;
 }