public function renderAggregateView($aggregate)
 {
     $trueOptionLabel = $this->object->getTrueOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
     $falseOptionLabel = $this->object->getFalseOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
     $tpl = new ilTemplate('tpl.il_as_aggregated_kprim_answers_table.html', true, true, "Modules/TestQuestionPool");
     foreach ($aggregate as $lineData) {
         $tpl->setCurrentBlock('aggregaterow');
         $tpl->setVariable('OPTION', $lineData['answertext']);
         $tpl->setVariable('COUNT_TRUE', $lineData['count_true']);
         $tpl->setVariable('COUNT_FALSE', $lineData['count_false']);
         $tpl->parseCurrentBlock();
     }
     $tpl->setVariable('OPTION_HEAD', $this->lng->txt('answers'));
     $tpl->setVariable('COUNT_TRUE_HEAD', $trueOptionLabel);
     $tpl->setVariable('COUNT_FALSE_HEAD', $falseOptionLabel);
     return $tpl;
 }
 private function getMaxPoints()
 {
     return $this->object->getPoints();
 }
 public function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     unset($_SESSION["import_mob_xhtml"]);
     $duration = $item->getDuration();
     $shuffle = 0;
     $answers = array();
     $presentation = $item->getPresentation();
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 switch (strtolower(get_class($response->getRenderType()))) {
                     case "ilqtirenderchoice":
                         $shuffle = $rendertype->getShuffle();
                         $answerorder = 0;
                         $foundimage = FALSE;
                         foreach ($rendertype->response_labels as $response_label) {
                             $ident = $response_label->getIdent();
                             $answertext = "";
                             $answerimage = array();
                             foreach ($response_label->material as $mat) {
                                 $embedded = false;
                                 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
                                     $foundmat = $mat->getMaterial($m);
                                     if (strcmp($foundmat["type"], "mattext") == 0) {
                                     }
                                     if (strcmp($foundmat["type"], "matimage") == 0) {
                                         if (strlen($foundmat["material"]->getEmbedded())) {
                                             $embedded = true;
                                         }
                                     }
                                 }
                                 if ($embedded) {
                                     for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
                                         $foundmat = $mat->getMaterial($m);
                                         if (strcmp($foundmat["type"], "mattext") == 0) {
                                             $answertext .= $foundmat["material"]->getContent();
                                         }
                                         if (strcmp($foundmat["type"], "matimage") == 0) {
                                             $foundimage = TRUE;
                                             $answerimage = array("imagetype" => $foundmat["material"]->getImageType(), "label" => $foundmat["material"]->getLabel(), "content" => $foundmat["material"]->getContent());
                                         }
                                     }
                                 } else {
                                     $answertext = $this->object->QTIMaterialToString($mat);
                                 }
                             }
                             $answers[$ident] = array("answertext" => $answertext, "imagefile" => $answerimage, "answerorder" => $ident);
                         }
                         break;
                 }
                 break;
         }
     }
     $feedbacks = array();
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->outcomes->decvar as $decvar) {
             if ($decvar->getVarname() == 'SCORE') {
                 $this->object->setPoints($decvar->getMaxvalue());
                 if ($decvar->getMinvalue() > 0) {
                     $this->object->setScorePartialSolutionEnabled(true);
                 }
             }
         }
         foreach ($resprocessing->respcondition as $respcondition) {
             if (!count($respcondition->setvar)) {
                 foreach ($respcondition->getConditionvar()->varequal as $varequal) {
                     $ident = $varequal->respident;
                     $answers[$ident]['correctness'] = (bool) $varequal->getContent();
                     break;
                 }
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacks[$ident] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacks[$ident] = $material;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if ($ifb->getIdent() == "response_allcorrect") {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[1] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[1] = $material;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if ($ifb->getIdent() == "response_onenotcorrect") {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacksgeneric[0] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacksgeneric[0] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setShuffleAnswersEnabled($shuffle);
     $this->object->setAnswerType($item->getMetadataEntry("answer_type"));
     $this->object->setOptionLabel($item->getMetadataEntry("option_label_setting"));
     $this->object->setCustomTrueOptionLabel($item->getMetadataEntry("custom_true_option_label"));
     $this->object->setCustomFalseOptionLabel($item->getMetadataEntry("custom_false_option_label"));
     $this->object->setThumbSize($item->getMetadataEntry("thumb_size"));
     $this->object->saveToDb();
     foreach ($answers as $answerData) {
         $answer = new ilAssKprimChoiceAnswer();
         $answer->setImageFsDir($this->object->getImagePath());
         $answer->setImageWebDir($this->object->getImagePathWeb());
         $answer->setPosition($answerData['answerorder']);
         $answer->setAnswertext($answerData['answertext']);
         $answer->setCorrectness($answerData['correctness']);
         if (isset($answerData['imagefile']['label'])) {
             $answer->setImageFile($answerData['imagefile']['label']);
         }
         $this->object->addAnswer($answer);
     }
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     foreach ($answers as $answer) {
         if (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0) {
             $image =& base64_decode($answer["imagefile"]["content"]);
             $imagepath = $this->object->getImagePath();
             include_once "./Services/Utilities/classes/class.ilUtil.php";
             if (!file_exists($imagepath)) {
                 ilUtil::makeDirParents($imagepath);
             }
             $imagepath .= $answer["imagefile"]["label"];
             if ($fh = fopen($imagepath, "wb")) {
                 $imagefile = fwrite($fh, $image);
                 fclose($fh);
             }
         }
     }
     $feedbackSetting = $item->getMetadataEntry('feedback_setting');
     if (!is_null($feedbackSetting)) {
         $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
     }
     // handle the import of media objects in XHTML code
     foreach ($feedbacks as $ident => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacks[$ident] = $m;
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     $questiontext = $this->object->getQuestion();
     $answers =& $this->object->getAnswers();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($answers as $key => $value) {
                 $answer_obj =& $answers[$key];
                 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
             }
             foreach ($feedbacks as $ident => $material) {
                 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($answers as $key => $value) {
         $answer_obj =& $answers[$key];
         $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1));
     }
     foreach ($feedbacks as $ident => $material) {
         $this->object->feedbackOBJ->importSpecificAnswerFeedback($this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
     //$ilLog->write(strftime("%D %T") . ": finished import multiple choice question (single response)");
 }
 public function insert(&$a_tpl)
 {
     $tpl = new ilTemplate("tpl.prop_kprimchoicewizardinput.html", true, true, "Modules/TestQuestionPool");
     foreach ($this->values as $value) {
         /**
          * @var ilAssKprimChoiceAnswer $value
          */
         if ($this->getSingleline()) {
             if (!$this->hideImages) {
                 if (strlen($value->getImageFile())) {
                     $imagename = $value->getImageWebPath();
                     if ($this->getSingleline() && $this->qstObject->getThumbSize()) {
                         if (@file_exists($value->getThumbFsPath())) {
                             $imagename = $value->getThumbWebPath();
                         }
                     }
                     $tpl->setCurrentBlock('image');
                     $tpl->setVariable('SRC_IMAGE', $imagename);
                     $tpl->setVariable('IMAGE_NAME', $value->getImageFile());
                     $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->getAnswertext()));
                     $tpl->setVariable("TXT_DELETE_EXISTING", $this->lng->txt("delete_existing_file"));
                     $tpl->setVariable("IMAGE_ROW_NUMBER", $value->getPosition());
                     $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
                     $tpl->parseCurrentBlock();
                 }
                 $tpl->setCurrentBlock('addimage');
                 $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][{$value->getPosition()}]");
                 $tpl->setVariable("IMAGE_SUBMIT", $this->lng->txt("upload"));
                 $tpl->setVariable("IMAGE_ROW_NUMBER", $value->getPosition());
                 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
                 $tpl->parseCurrentBlock();
             }
             $tpl->setCurrentBlock("prop_text_propval");
             $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
             $tpl->parseCurrentBlock();
             $tpl->setCurrentBlock('singleline');
             $tpl->setVariable("SIZE", $this->getSize());
             $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][{$value->getPosition()}]");
             $tpl->setVariable("SINGLELINE_ROW_NUMBER", $value->getPosition());
             $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
             $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
             if ($this->getDisabled()) {
                 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
             }
             $tpl->parseCurrentBlock();
         } else {
             if (!$this->getSingleline()) {
                 $tpl->setCurrentBlock('multiline');
                 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
                 $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][{$value->getPosition()}]");
                 $tpl->setVariable("MULTILINE_ROW_NUMBER", $value->getPosition());
                 $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
                 if ($this->getDisabled()) {
                     $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
                 }
                 $tpl->parseCurrentBlock();
             }
         }
         if ($this->getAllowMove()) {
             $tpl->setCurrentBlock("move");
             $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][{$value->getPosition()}]");
             $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][{$value->getPosition()}]");
             $tpl->setVariable("UP_ID", "up_{$this->getPostVar()}[{$value->getPosition()}]");
             $tpl->setVariable("DOWN_ID", "down_{$this->getPostVar()}[{$value->getPosition()}]");
             $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
             $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
             $tpl->parseCurrentBlock();
         }
         $tpl->setCurrentBlock("row");
         $tpl->setVariable("POST_VAR", $this->getPostVar());
         $tpl->setVariable("ROW_NUMBER", $value->getPosition());
         $tpl->setVariable("ID", $this->getPostVar() . "[answer][{$value->getPosition()}]");
         $tpl->setVariable("CORRECTNESS_TRUE_ID", $this->getPostVar() . "[correctness][{$value->getPosition()}][true]");
         $tpl->setVariable("CORRECTNESS_FALSE_ID", $this->getPostVar() . "[correctness][{$value->getPosition()}][false]");
         $tpl->setVariable("CORRECTNESS_TRUE_VALUE", 1);
         $tpl->setVariable("CORRECTNESS_FALSE_VALUE", 0);
         if ($value->getCorrectness() !== null) {
             if ($value->getCorrectness()) {
                 $tpl->setVariable('CORRECTNESS_TRUE_SELECTED', ' checked="checked"');
             } else {
                 $tpl->setVariable('CORRECTNESS_FALSE_SELECTED', ' checked="checked"');
             }
         }
         if ($this->getDisabled()) {
             $tpl->setVariable("DISABLED_CORRECTNESS", " disabled=\"disabled\"");
         }
         $tpl->parseCurrentBlock();
     }
     if ($this->getSingleline()) {
         if (!$this->hideImages) {
             if (is_array($this->getSuffixes())) {
                 $suff_str = $delim = "";
                 foreach ($this->getSuffixes() as $suffix) {
                     $suff_str .= $delim . "." . $suffix;
                     $delim = ", ";
                 }
                 $tpl->setCurrentBlock('allowed_image_suffixes');
                 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $this->lng->txt("file_allowed_suffixes") . " " . $suff_str);
                 $tpl->parseCurrentBlock();
             }
             $tpl->setCurrentBlock("image_heading");
             $tpl->setVariable("ANSWER_IMAGE", $this->lng->txt('answer_image'));
             $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
             $tpl->parseCurrentBlock();
         }
     }
     foreach ($this->qstObject->getValidOptionLabels() as $optionLabel) {
         if ($this->qstObject->isCustomOptionLabel($optionLabel)) {
             continue;
         }
         $tpl->setCurrentBlock('option_label_translations');
         $tpl->setVariable('OPTION_LABEL', $optionLabel);
         $tpl->setVariable('TRANSLATION_TRUE', $this->qstObject->getTrueOptionLabelTranslation($this->lng, $optionLabel));
         $tpl->setVariable('TRANSLATION_FALSE', $this->qstObject->getFalseOptionLabelTranslation($this->lng, $optionLabel));
         $tpl->parseCurrentBlock();
     }
     $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
     $tpl->setVariable("DELETE_IMAGE_HEADER", $this->lng->txt('delete_image_header'));
     $tpl->setVariable("DELETE_IMAGE_QUESTION", $this->lng->txt('delete_image_question'));
     $tpl->setVariable("ANSWER_TEXT", $this->lng->txt('answer_text'));
     $tpl->setVariable("OPTIONS_TEXT", $this->lng->txt('options'));
     // winzards input column label values will be updated on document ready js
     //$tpl->setVariable("TRUE_TEXT", $this->qstObject->getTrueOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
     //$tpl->setVariable("FALSE_TEXT", $this->qstObject->getFalseOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
     $a_tpl->setCurrentBlock("prop_generic");
     $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
     $a_tpl->parseCurrentBlock();
     include_once "./Services/YUI/classes/class.ilYuiUtil.php";
     $this->tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
     $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/kprimchoicewizard.js");
     $this->tpl->addJavascript('Modules/TestQuestionPool/js/ilAssKprimChoice.js');
 }