4 require_once
'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5 require_once
'Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6 require_once
'Modules/TestQuestionPool/interfaces/interface.ilGuiAnswerScoringAdjustable.php';
30 require_once
'Modules/TestQuestionPool/classes/class.assKprimChoice.php';
35 $this->
object->loadFromDb($qId);
41 return array(
'uploadImage',
'removeImage');
52 $this->tpl->addCss(
'Modules/Test/templates/default/ta.css');
54 $this->tpl->setVariable(
"QUESTION_DATA", $this->ctrl->getHTML($form));
63 $this->
object->saveToDb();
70 $position = key(
$_POST[
'cmd'][
'removeImage']);
71 $this->
object->removeAnswerImage($position);
73 $this->
object->saveToDb();
79 if( isset(
$_POST[
'cmd'][__FUNCTION__]) && count(
$_POST[
'cmd'][__FUNCTION__]) )
81 $this->
object->moveAnswerDown( key(
$_POST[
'cmd'][__FUNCTION__]) );
82 $this->
object->saveToDb();
90 if( isset(
$_POST[
'cmd'][__FUNCTION__]) && count(
$_POST[
'cmd'][__FUNCTION__]) )
92 $this->
object->moveAnswerUp( key(
$_POST[
'cmd'][__FUNCTION__]) );
93 $this->
object->saveToDb();
102 $form->setValuesByPost();
106 $answersInput = $form->getItemByPostVar(
'kprim_answers');
107 $answersInput->setIgnoreMissingUploadsEnabled(
true);
109 if( !$answersInput->checkUploads(
$_POST[$answersInput->getPostVar()]) )
116 $answersInput->collectValidFiles();
118 elseif( !$form->checkInput() )
160 $shuffleAnswers =
new ilCheckboxInputGUI($this->lng->txt(
"shuffle_answers" ),
"shuffle_answers_enabled");
161 $shuffleAnswers->
setChecked( $this->object->isShuffleAnswersEnabled() );
162 $form->
addItem($shuffleAnswers);
164 if( !$this->object->getSelfAssessmentEditingMode() )
167 $answerType =
new ilSelectInputGUI($this->lng->txt(
'answer_types'),
'answer_type');
168 $answerType->
setOptions($this->object->getAnswerTypeSelectOptions($this->lng));
169 $answerType->setValue( $this->object->getAnswerType() );
173 if( !$this->object->getSelfAssessmentEditingMode() && $this->
object->isSingleLineAnswerType($this->object->getAnswerType()) )
176 $thumbSize =
new ilNumberInputGUI($this->lng->txt(
'thumb_size'),
'thumb_size');
177 $thumbSize->
setSuffix($this->lng->txt(
"thumb_size_unit_pixel"));
178 $thumbSize->setInfo( $this->lng->txt(
'thumb_size_info') );
179 $thumbSize->setDecimals(
false);
180 $thumbSize->setMinValue(20);
181 $thumbSize->setSize(6);
182 $thumbSize->setValue( $this->object->getThumbSize() );
188 $optionLabel->
setInfo($this->lng->txt(
'option_label_info'));
189 $optionLabel->setRequired(
true);
190 $optionLabel->setValue($this->object->getOptionLabel());
191 foreach($this->object->getValidOptionLabelsTranslated($this->lng) as $labelValue => $labelText)
194 $optionLabel->addOption($option);
196 if( $this->object->isCustomOptionLabel($labelValue) )
199 $this->lng->txt(
'option_label_custom_true'),
'option_label_custom_true'
201 $customLabelTrue->
setValue($this->object->getCustomTrueOptionLabel());
202 $option->addSubItem($customLabelTrue);
205 $this->lng->txt(
'option_label_custom_false'),
'option_label_custom_false'
207 $customLabelFalse->
setValue($this->object->getCustomFalseOptionLabel());
208 $option->addSubItem($customLabelFalse);
217 $points->allowDecimals(
true);
218 $points->setMinValue(0);
219 $points->setMinvalueShouldBeGreater(
true);
220 $points->setValue($this->object->getPoints());
224 $scorePartialSolution =
new ilCheckboxInputGUI($this->lng->txt(
'score_partsol_enabled'),
'score_partsol_enabled');
225 $scorePartialSolution->
setInfo($this->lng->txt(
'score_partsol_enabled_info'));
226 $scorePartialSolution->setChecked( $this->object->isScorePartialSolutionEnabled() );
227 $form->
addItem($scorePartialSolution);
237 $oldAnswerType = $this->
object->getAnswerType();
239 $this->
object->setShuffleAnswersEnabled($form->
getItemByPostVar(
'shuffle_answers_enabled')->getChecked());
241 if( !$this->object->getSelfAssessmentEditingMode() )
243 $this->
object->setAnswerType($form->
getItemByPostVar(
'answer_type')->getValue());
250 if( !$this->object->getSelfAssessmentEditingMode() && $this->
object->isSingleLineAnswerType($oldAnswerType) )
252 $this->
object->setThumbSize($form->
getItemByPostVar(
'thumb_size')->getValue());
255 $this->
object->setOptionLabel($form->
getItemByPostVar(
'option_label')->getValue());
257 if( $this->object->isCustomOptionLabel($this->object->getOptionLabel()) )
259 $this->
object->setCustomTrueOptionLabel( strip_tags(
262 $this->
object->setCustomFalseOptionLabel( strip_tags(
269 $this->
object->setScorePartialSolutionEnabled($form->
getItemByPostVar(
'score_partsol_enabled')->getChecked());
278 require_once
'Modules/TestQuestionPool/classes/class.ilKprimChoiceWizardInputGUI.php';
280 $kprimAnswers->
setInfo($this->lng->txt(
'kprim_answers_info'));
281 $kprimAnswers->setSize(64);
282 $kprimAnswers->setMaxLength(1000);
283 $kprimAnswers->setRequired(
true);
284 $kprimAnswers->setAllowMove(
true);
285 $kprimAnswers->setQuestionObject($this->
object);
286 if( !$this->object->getSelfAssessmentEditingMode() )
288 $kprimAnswers->setSingleline($this->object->isSingleLineAnswerType($this->object->getAnswerType()));
292 $kprimAnswers->setSingleline(
false);
294 $kprimAnswers->setValues($this->object->getAnswers());
309 $this->
object->handleFileUploads($answers, $files);
310 $this->
object->setAnswers($answers);
320 foreach($answers as $key => $answer)
350 $is_postponed = FALSE,
351 $use_post_solutions = FALSE,
352 $showInlineFeedback = FALSE
359 $user_solution = array();
363 include_once
"./Modules/Test/classes/class.ilObjTest.php";
368 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
369 foreach ($solutions as $idx => $solution_value)
371 $user_solution[$solution_value[
"value1"]] = $solution_value[
"value2"];
376 include_once
"./Services/UICore/classes/class.ilTemplate.php";
377 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_kprim_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
379 foreach ($keys as $answer_id)
381 $answer = $this->
object->getAnswer($answer_id);
382 if (strlen($answer->getImageFile()))
384 if ($this->object->getThumbSize())
386 $template->setCurrentBlock(
"preview");
387 $template->setVariable(
"URL_PREVIEW", $answer->getImageWebPath());
388 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
390 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getThumbWebPath());
391 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
392 $alt = $answer->getImageFile();
393 if (strlen($answer->getAnswertext()))
395 $alt = $answer->getAnswertext();
397 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
400 $template->parseCurrentBlock();
404 $template->setCurrentBlock(
"answer_image");
405 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getImageWebPath());
406 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
407 $alt = $answer->getImageFile();
408 if (strlen($answer->getAnswertext()))
410 $alt = $answer->getAnswertext();
412 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
413 $template->setVariable(
"ATTR", $attr);
416 $template->parseCurrentBlock();
420 if( $showInlineFeedback )
425 $template->setCurrentBlock(
"answer_row");
426 $template->setVariable(
"ANSWER_ID", $answer_id);
427 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
428 $template->setVariable(
'VALUE_TRUE', 1);
429 $template->setVariable(
'VALUE_FALSE', 0);
431 if( isset($user_solution[$answer->getPosition()]) )
433 $tplVar = $user_solution[$answer->getPosition()] ?
'CHECKED_ANSWER_TRUE' :
'CHECKED_ANSWER_FALSE';
434 $template->setVariable($tplVar,
" checked=\"checked\"");
437 $template->parseCurrentBlock();
440 $questiontext = $this->
object->getQuestion();
441 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
443 $template->setVariable(
"INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
444 $this->lng, $this->object->getOptionLabel()
447 $template->setVariable(
"OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
448 $this->lng, $this->object->getOptionLabel()
451 $template->setVariable(
"OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
452 $this->lng, $this->object->getOptionLabel()
455 $questionoutput = $template->get();
456 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
464 public function getPreview($show_question_only = FALSE, $showInlineFeedback =
false)
471 include_once
"./Services/UICore/classes/class.ilTemplate.php";
472 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_kprim_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
474 foreach ($keys as $answer_id)
476 $answer = $this->
object->getAnswer($answer_id);
477 if (strlen($answer->getImageFile()))
479 if ($this->object->getThumbSize())
481 $template->setCurrentBlock(
"preview");
482 $template->setVariable(
"URL_PREVIEW", $answer->getImageWebPath());
483 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
485 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getThumbWebPath());
486 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
487 $alt = $answer->getImageFile();
488 if (strlen($answer->getAnswertext()))
490 $alt = $answer->getAnswertext();
492 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
495 $template->parseCurrentBlock();
499 $template->setCurrentBlock(
"answer_image");
500 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getImageWebPath());
501 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
502 $alt = $answer->getImageFile();
503 if (strlen($answer->getAnswertext()))
505 $alt = $answer->getAnswertext();
507 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
508 $template->setVariable(
"ATTR", $attr);
511 $template->parseCurrentBlock();
515 if( $showInlineFeedback )
520 $template->setCurrentBlock(
"answer_row");
521 $template->setVariable(
"ANSWER_ID", $answer_id);
522 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
523 $template->setVariable(
'VALUE_TRUE', 1);
524 $template->setVariable(
'VALUE_FALSE', 0);
526 if( isset($user_solution[$answer->getPosition()]) )
528 $tplVar = $user_solution[$answer->getPosition()] ?
'CHECKED_ANSWER_TRUE' :
'CHECKED_ANSWER_FALSE';
529 $template->setVariable($tplVar,
" checked=\"checked\"");
532 $template->parseCurrentBlock();
534 $questiontext = $this->
object->getQuestion();
535 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
537 $template->setVariable(
"INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
538 $this->lng, $this->object->getOptionLabel()
541 $template->setVariable(
"OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
542 $this->lng, $this->object->getOptionLabel()
545 $template->setVariable(
"OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
546 $this->lng, $this->object->getOptionLabel()
549 $questionoutput = $template->get();
550 if (!$show_question_only)
555 return $questionoutput;
572 $graphicalOutput = FALSE,
573 $result_output = FALSE,
574 $show_question_only = TRUE,
575 $show_feedback = FALSE,
576 $show_correct_solution = FALSE,
577 $show_manual_scoring = FALSE,
578 $show_question_text = TRUE
585 $user_solution = array();
586 if (($active_id > 0) && (!$show_correct_solution))
588 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
589 foreach ($solutions as $idx => $solution_value)
591 $user_solution[$solution_value[
'value1']] = $solution_value[
'value2'];
597 foreach ($this->object->getAnswers() as $answer)
599 $user_solution[$answer->getPosition()] = $answer->getCorrectness();
604 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_kprim_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
606 foreach ($keys as $answer_id)
608 $answer = $this->
object->getAnswer($answer_id);
610 if (($active_id > 0) && (!$show_correct_solution))
612 if ($graphicalOutput)
616 if( $user_solution[$answer->getPosition()] == $answer->getCorrectness() )
618 $template->setCurrentBlock(
"icon_ok");
620 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
621 $template->parseCurrentBlock();
625 $template->setCurrentBlock(
"icon_ok");
627 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
628 $template->parseCurrentBlock();
632 if (strlen($answer->getImageFile()))
634 $template->setCurrentBlock(
"answer_image");
635 if ($this->object->getThumbSize())
637 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getThumbWebPath());
641 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getImageWebPath());
646 $template->parseCurrentBlock();
654 $template->setCurrentBlock(
"answer_row");
655 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
657 if( isset($user_solution[$answer->getPosition()]) )
659 if( $user_solution[$answer->getPosition()] )
662 $template->setVariable(
"SOLUTION_ALT_TRUE", $this->lng->txt(
"checked"));
664 $template->setVariable(
"SOLUTION_ALT_FALSE", $this->lng->txt(
"unchecked"));
669 $template->setVariable(
"SOLUTION_ALT_TRUE", $this->lng->txt(
"unchecked"));
671 $template->setVariable(
"SOLUTION_ALT_FALSE", $this->lng->txt(
"checked"));
677 $template->setVariable(
"SOLUTION_ALT_TRUE", $this->lng->txt(
"unchecked"));
679 $template->setVariable(
"SOLUTION_ALT_FALSE", $this->lng->txt(
"unchecked"));
682 $template->parseCurrentBlock();
685 if ($show_question_text==
true)
687 $questiontext = $this->
object->getQuestion();
688 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
690 $template->setVariable(
"INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
691 $this->lng, $this->object->getOptionLabel()
695 $template->setVariable(
"OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
696 $this->lng, $this->object->getOptionLabel()
699 $template->setVariable(
"OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
700 $this->lng, $this->object->getOptionLabel()
704 $questionoutput = $template->get();
707 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
709 if( strlen($feedback) )
711 $solutiontemplate->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput( $feedback ,
true ));
714 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
716 $solutionoutput = $solutiontemplate->get();
718 if (!$show_question_only)
723 return $solutionoutput;
728 if( !$this->object->isShuffleAnswersEnabled() )
730 return array_keys($this->object->getAnswers());
733 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
737 if (!is_array($this->choiceKeys))
739 $this->choiceKeys = array_keys($this->object->getAnswers());
740 if ($this->object->getShuffle())
742 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);
745 $_SESSION[
"choicekeys"] = $this->choiceKeys;
746 return $this->choiceKeys;
751 require_once
'Modules/TestQuestionPool/classes/feedback/class.ilAssConfigurableMultiOptionQuestionFeedback.php';
755 foreach($user_solution as $mc_solution)
757 if(strcmp($mc_solution, $answer_id) == 0)
759 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
762 $template->setCurrentBlock(
"feedback");
763 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
764 $template->parseCurrentBlock();
772 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
775 $template->setCurrentBlock(
"feedback");
776 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
777 $template->parseCurrentBlock();
783 $answer = $this->
object->getAnswer($answer_id);
785 if($answer->getCorrectness())
787 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
790 $template->setCurrentBlock(
"feedback");
791 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
792 $template->parseCurrentBlock();
837 $this->
aggregateAnswers( $relevant_answers, $this->object->getAnswers() ) )->get();
839 return '<pre>'.print_r($relevant_answers, 1).
'</pre>';
844 $trueOptionLabel = $this->
object->getTrueOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
845 $falseOptionLabel = $this->
object->getFalseOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
847 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_kprim_answers_table.html',
true,
true,
"Modules/TestQuestionPool");
849 foreach( $aggregate as $lineData )
851 $tpl->setCurrentBlock(
'aggregaterow');
852 $tpl->setVariable(
'OPTION', $lineData[
'answertext']);
853 $tpl->setVariable(
'COUNT_TRUE', $lineData[
'count_true']);
854 $tpl->setVariable(
'COUNT_FALSE', $lineData[
'count_false']);
855 $tpl->parseCurrentBlock();
858 $tpl->setVariable(
'OPTION_HEAD', $this->lng->txt(
'answers'));
859 $tpl->setVariable(
'COUNT_TRUE_HEAD', $trueOptionLabel);
860 $tpl->setVariable(
'COUNT_FALSE_HEAD', $falseOptionLabel);
867 $aggregate = array();
869 foreach( $answers as $answer )
872 'answertext' => $answer->getAnswerText(),
'count_true' => 0,
'count_false' => 0
875 foreach( $rawSolutionData as $solutionRecord )
877 if( $solutionRecord[
'value1'] == $answer->getPosition() )
879 if( $solutionRecord[
'value2'] )
881 $answerAgg[
'count_true']++;
885 $answerAgg[
'count_false']++;
891 $aggregate[] = $answerAgg;