protected function initQuestionForm($a_read_only = false) { global $lng, $ilCtrl; include_once "Services/Form/classes/class.ilPropertyFormGUI.php"; $form = new ilPropertyFormGUI(); $form->setFormAction($ilCtrl->getFormAction($this, "saveQuestion")); $form->setTitle($lng->txt("obj_poll")); $question = new ilTextAreaInputGUI($lng->txt("poll_question"), "question"); $question->setRequired(true); $question->setCols(40); $question->setRows(2); $question->setValue($this->object->getQuestion()); $question->setDisabled($a_read_only); $form->addItem($question); $dimensions = " (" . ilObjPoll::getImageSize() . "px)"; $img = new ilImageFileInputGUI($lng->txt("poll_image") . $dimensions, "image"); $img->setDisabled($a_read_only); $form->addItem($img); // show existing file $file = $this->object->getImageFullPath(true); if ($file) { $img->setImage($file); } $anonymous = new ilRadioGroupInputGUI($lng->txt("poll_mode"), "mode"); $anonymous->setRequired(true); $option = new ilRadioOption($lng->txt("poll_mode_anonymous"), 0); $option->setInfo($lng->txt("poll_mode_anonymous_info")); $anonymous->addOption($option); $option = new ilRadioOption($lng->txt("poll_mode_personal"), 1); $option->setInfo($lng->txt("poll_mode_personal_info")); $anonymous->addOption($option); $anonymous->setValue($this->object->getNonAnonymous()); $anonymous->setDisabled($a_read_only); $form->addItem($anonymous); $nanswers = new ilNumberInputGUI($lng->txt("poll_max_number_of_answers"), "nanswers"); $nanswers->setRequired(true); $nanswers->setMinValue(1); $nanswers->setSize(3); $nanswers->setValue($this->object->getMaxNumberOfAnswers()); $nanswers->setDisabled($a_read_only); $form->addItem($nanswers); $answers = new ilTextInputGUI($lng->txt("poll_answers"), "answers"); $answers->setRequired(true); $answers->setMulti(true, true); $answers->setDisabled($a_read_only); $form->addItem($answers); $multi_answers = array(); foreach ($this->object->getAnswers() as $idx => $item) { if (!$idx) { $answers->setValue($item["answer"]); } $multi_answers[] = $item["answer"]; } $answers->setMultiValues($multi_answers); if (!$a_read_only) { $form->addCommandButton("saveQuestion", $lng->txt("save")); } return $form; }
/** * 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; } }
/** * 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; }