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';
7 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
36 include_once
"./Modules/TestQuestionPool/classes/class.assSingleChoice.php";
40 $this->
object->loadFromDb($id);
53 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
56 require_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
75 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
77 $form->setFormAction($this->ctrl->getFormAction($this));
79 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
$_POST)) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
80 if ($checkonly) $isSingleline = (
$_POST[
'types'] == 0) ?
true :
false;
83 $form->setMultipart(TRUE);
87 $form->setMultipart(FALSE);
89 $form->setTableWidth(
"100%");
90 $form->setId(
"asssinglechoice");
105 $form->setValuesByPost();
106 $errors = !$form->checkInput();
107 $form->setValuesByPost();
108 if (
$errors) $checkonly =
false;
111 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
121 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
131 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
133 $this->
object->removeAnswerImage($position);
143 $position = key(
$_POST[
'cmd'][
'addchoice']);
144 $this->
object->addAnswer(
"", 0, $position+1);
154 $position = key(
$_POST[
'cmd'][
'removechoice']);
155 $this->
object->deleteAnswer($position);
175 $graphicalOutput = FALSE,
176 $result_output = FALSE,
177 $show_question_only = TRUE,
178 $show_feedback = FALSE,
179 $show_correct_solution = FALSE,
180 $show_manual_scoring = FALSE,
181 $show_question_text = TRUE
189 if (($active_id > 0) && (!$show_correct_solution))
191 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
192 foreach ($solutions as $idx => $solution_value)
194 $user_solution = $solution_value[
"value1"];
201 foreach ($this->object->answers as $index => $answer)
203 if ($answer->getPoints() > $max_points)
205 $max_points = $answer->getPoints();
206 $found_index = $index;
209 $user_solution = $found_index;
212 include_once
"./Services/UICore/classes/class.ilTemplate.php";
213 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
214 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
215 foreach ($keys as $answer_id)
217 $answer = $this->
object->answers[$answer_id];
218 if (($active_id > 0) && (!$show_correct_solution))
220 if ($graphicalOutput)
224 if (strcmp($user_solution, $answer_id) == 0)
226 if ($answer->getPoints() == $this->
object->getMaximumPoints())
236 $template->setCurrentBlock(
"icon_ok");
238 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
239 $template->parseCurrentBlock();
243 $template->setCurrentBlock(
"icon_not_ok");
244 if ($answer->getPoints() > 0)
247 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
252 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
254 $template->parseCurrentBlock();
257 if (strlen($user_solution) == 0)
259 $template->setCurrentBlock(
"icon_not_ok");
261 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
262 $template->parseCurrentBlock();
266 if (strlen($answer->getImage()))
268 $template->setCurrentBlock(
"answer_image");
269 if ($this->object->getThumbSize())
271 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
275 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
277 $alt = $answer->getImage();
278 if (strlen($answer->getAnswertext()))
280 $alt = $answer->getAnswertext();
282 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
285 $template->parseCurrentBlock();
291 $template->setCurrentBlock(
"answer_row");
292 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
293 if (strcmp($user_solution, $answer_id) == 0)
296 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
301 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
305 $points = $this->
object->answers[$answer_id]->getPoints();
306 $resulttext = ($points == 1) ?
"(%s " . $this->lng->txt(
"point") .
")" :
"(%s " . $this->lng->txt(
"points") .
")";
307 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext, $points));
309 $template->parseCurrentBlock();
311 $questiontext = $this->
object->getQuestion();
312 if ($show_question_text==
true)
314 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
316 $questionoutput = $template->get();
318 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput( $feedback,
true ));
319 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
321 $solutionoutput = $solutiontemplate->get();
322 if (!$show_question_only)
327 return $solutionoutput;
330 public function getPreview($show_question_only = FALSE, $showInlineFeedback =
false)
335 include_once
"./Services/UICore/classes/class.ilTemplate.php";
336 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
337 foreach ($keys as $answer_id)
339 $answer = $this->
object->answers[$answer_id];
340 if (strlen($answer->getImage()))
342 if ($this->object->getThumbSize())
344 $template->setCurrentBlock(
"preview");
345 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
346 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
348 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
349 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
350 $alt = $answer->getImage();
351 if (strlen($answer->getAnswertext()))
353 $alt = $answer->getAnswertext();
355 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
358 $template->parseCurrentBlock();
362 $template->setCurrentBlock(
"answer_image");
363 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
364 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
365 $alt = $answer->getImage();
366 if (strlen($answer->getAnswertext()))
368 $alt = $answer->getAnswertext();
370 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
371 $template->setVariable(
"ATTR", $attr);
374 $template->parseCurrentBlock();
381 $template->setCurrentBlock(
"answer_row");
382 $template->setVariable(
"QID", $this->object->getId().
'ID');
383 $template->setVariable(
"ANSWER_ID", $answer_id);
384 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
389 if (strcmp($user_solution, $answer_id) == 0)
391 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
395 $template->parseCurrentBlock();
397 $questiontext = $this->
object->getQuestion();
398 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
399 $questionoutput = $template->get();
400 if (!$show_question_only)
405 return $questionoutput;
408 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
417 include_once
"./Modules/Test/classes/class.ilObjTest.php";
422 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
423 foreach ($solutions as $idx => $solution_value)
425 $user_solution = $solution_value[
"value1"];
430 include_once
"./Services/UICore/classes/class.ilTemplate.php";
431 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
432 foreach ($keys as $answer_id)
434 $answer = $this->
object->answers[$answer_id];
435 if (strlen($answer->getImage()))
437 if ($this->object->getThumbSize())
439 $template->setCurrentBlock(
"preview");
440 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
441 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
443 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
444 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
445 $alt = $answer->getImage();
446 if (strlen($answer->getAnswertext()))
448 $alt = $answer->getAnswertext();
450 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
453 $template->parseCurrentBlock();
457 $template->setCurrentBlock(
"answer_image");
458 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
459 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
460 $alt = $answer->getImage();
461 if (strlen($answer->getAnswertext()))
463 $alt = $answer->getAnswertext();
465 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
466 $template->setVariable(
"ATTR", $attr);
469 $template->parseCurrentBlock();
474 $feedbackOutputRequired =
false;
476 switch( $this->object->getSpecificFeedbackSetting() )
479 $feedbackOutputRequired =
true;
483 if (strcmp($user_solution, $answer_id) == 0)
485 $feedbackOutputRequired =
true;
490 if ($this->object->getAnswer($answer_id)->getPoints() > 0)
492 $feedbackOutputRequired =
true;
497 if($feedbackOutputRequired)
499 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
500 $this->object->getId(), $answer_id
504 $template->setCurrentBlock(
"feedback");
505 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput( $fb,
true ));
506 $template->parseCurrentBlock();
510 $template->setCurrentBlock(
"answer_row");
511 $template->setVariable(
"ANSWER_ID", $answer_id);
512 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
513 if (strcmp($user_solution, $answer_id) == 0)
515 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
517 $template->parseCurrentBlock();
519 $questiontext = $this->
object->getQuestion();
520 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
521 $questionoutput = $template->get();
522 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
535 global $rbacsystem, $ilTabs;
537 $ilTabs->clearTargets();
539 $this->ctrl->setParameterByClass(
"ilAssQuestionPageGUI",
"q_id",
$_GET[
"q_id"]);
540 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
541 $q_type = $this->
object->getQuestionType();
545 $classname = $q_type .
"GUI";
546 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
547 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
552 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
555 $ilTabs->addTarget(
"edit_page",
556 $this->ctrl->getLinkTargetByClass(
"ilAssQuestionPageGUI",
"edit"),
557 array(
"edit",
"insert",
"exec_pg"),
558 "",
"", $force_active);
564 $force_active =
false;
565 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
568 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
570 $ilTabs->addTarget(
"edit_question",
572 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
573 $classname,
"", $force_active);
588 $ilTabs->addTarget(
"statistics",
589 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
604 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
608 if (!is_array($this->choiceKeys))
610 $this->choiceKeys = array_keys($this->object->answers);
611 if ($this->object->getShuffle())
613 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);
624 return $this->
object->prepareTextareaOutput($output, TRUE);
629 $this->
object->setShuffle(
$_POST[
"shuffle"] );
630 $this->
object->setMultilineAnswerSetting(
$_POST[
"types"] );
631 if (is_array(
$_POST[
'choice'][
'imagename'] ) &&
$_POST[
"types"] == 1)
633 $this->
object->isSingleline =
true;
638 $this->
object->isSingleline = (
$_POST[
"types"] == 0) ?
true :
false;
640 $this->
object->setThumbSize( (strlen(
$_POST[
"thumb_size"] )) ?
$_POST[
"thumb_size"] :
"" );
645 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
$_POST)) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
649 $shuffle->setChecked( $this->object->getShuffle() );
650 $shuffle->setRequired( FALSE );
653 if ($this->object->getId())
656 $hidden->setValue( $this->object->getId() );
660 if (!$this->object->getSelfAssessmentEditingMode())
665 $types->setValue( ($isSingleline) ? 0 : 1 );
666 $types->setOptions( array(
667 0 => $this->lng->txt(
'answers_singleline' ),
668 1 => $this->lng->txt(
'answers_multiline' ),
677 $thumb_size =
new ilNumberInputGUI($this->lng->txt(
"thumb_size" ),
"thumb_size");
678 $thumb_size->
setSuffix($this->lng->txt(
"thumb_size_unit_pixel"));
679 $thumb_size->setMinValue( 20 );
680 $thumb_size->setDecimals( 0 );
681 $thumb_size->setSize( 6 );
682 $thumb_size->setInfo( $this->lng->txt(
'thumb_size_info' ) );
683 $thumb_size->setValue( $this->object->getThumbSize() );
684 $thumb_size->setRequired(
false );
707 $this->
object->flushAnswers();
708 if ($this->object->isSingleline)
710 foreach (
$_POST[
'choice'][
'answer'] as $index => $answertext)
714 $picturefile =
$_POST[
'choice'][
'imagename'][$index];
715 $file_org_name = $_FILES[
'choice'][
'name'][
'image'][$index];
716 $file_temp_name = $_FILES[
'choice'][
'tmp_name'][
'image'][$index];
718 if (strlen( $file_temp_name ))
721 $suffix = strtolower( array_pop( explode(
".", $file_org_name ) ) );
722 if (in_array( $suffix, array(
"jpg",
"jpeg",
"png",
"gif" ) ))
725 $filename = $this->
object->createNewImageFileName( $file_org_name );
726 if ($this->object->setImageFile(
$filename, $file_temp_name ) == 0)
733 $this->
object->addAnswer( $answertext,
$_POST[
'choice'][
'points'][$index], $index, $picturefile );
738 foreach (
$_POST[
'choice'][
'answer'] as $index => $answer)
740 $answertext = $answer;
741 $this->
object->addAnswer( $answertext,
$_POST[
'choice'][
'points'][$index], $index );
748 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
$_POST)) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
751 include_once
"./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
754 $choices->setQuestionObject( $this->
object );
755 $choices->setSingleline( $isSingleline );
756 $choices->setAllowMove(
false );
757 if ($this->object->getSelfAssessmentEditingMode())
759 $choices->setSize( 40 );
760 $choices->setMaxLength( 800 );
762 if ($this->object->getAnswerCount() == 0)
763 $this->object->addAnswer(
"", 0, 0 );
764 $choices->setValues( $this->object->getAnswers() );
793 $this->
aggregateAnswers( $relevant_answers, $this->object->getAnswers() ) )->get();
798 $aggregate = array();
799 foreach ($answers_defined_on_question as $answer)
801 $aggregated_info_for_answer = array();
802 $aggregated_info_for_answer[
'answertext'] = $answer->getAnswerText();
803 $aggregated_info_for_answer[
'count_checked'] = 0;
805 foreach ($relevant_answers_chosen as $relevant_answer)
807 if ($relevant_answer[
'value1'] == $answer->getOrder())
809 $aggregated_info_for_answer[
'count_checked']++;
812 $aggregated_info_for_answer[
'count_unchecked'] =
813 ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
814 - $aggregated_info_for_answer[
'count_checked'];
816 $aggregate[] = $aggregated_info_for_answer;
828 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_answers_table.html',
true,
true,
"Modules/TestQuestionPool");
830 foreach ($aggregate as $line_data)
832 $tpl->setCurrentBlock(
'aggregaterow' );
833 $tpl->setVariable(
'OPTION', $line_data[
'answertext'] );
834 $tpl->setVariable(
'COUNT', $line_data[
'count_checked'] );
835 $tpl->parseCurrentBlock();
842 $feedbackOutputRequired =
false;
844 switch($this->object->getSpecificFeedbackSetting())
847 $feedbackOutputRequired =
true;
851 if(strcmp($user_solution, $answer_id) == 0)
853 $feedbackOutputRequired =
true;
858 if($this->object->getAnswer($answer_id)->getPoints() > 0)
860 $feedbackOutputRequired =
true;
865 if($feedbackOutputRequired)
867 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
870 $template->setCurrentBlock(
"feedback");
871 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
872 $template->parseCurrentBlock();