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';
38 include_once
"./Modules/TestQuestionPool/classes/class.assMultipleChoice.php";
42 $this->
object->loadFromDb($id);
55 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
58 require_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
80 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
82 $form->setFormAction($this->ctrl->getFormAction($this));
84 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
$_POST)) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
85 if ($checkonly) $isSingleline = (
$_POST[
'types'] == 0) ?
true :
false;
88 $form->setMultipart(TRUE);
92 $form->setMultipart(FALSE);
94 $form->setTableWidth(
"100%");
95 $form->setId(
"assmultiplechoice");
108 $form->setValuesByPost();
109 $errors = !$form->checkInput();
110 $form->setValuesByPost();
111 if (
$errors) $checkonly =
false;
114 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
130 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
140 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
142 $this->
object->removeAnswerImage($position);
152 $position = key(
$_POST[
'cmd'][
'addchoice']);
153 $this->
object->addAnswer(
"", 0, 0, $position+1);
163 $position = key(
$_POST[
'cmd'][
'removechoice']);
164 $this->
object->deleteAnswer($position);
186 $graphicalOutput = FALSE,
187 $result_output = FALSE,
188 $show_question_only = TRUE,
189 $show_feedback = FALSE,
190 $show_correct_solution = FALSE,
191 $show_manual_scoring = FALSE,
192 $show_question_text = TRUE
199 $user_solution = array();
200 if (($active_id > 0) && (!$show_correct_solution))
202 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
203 foreach ($solutions as $idx => $solution_value)
205 array_push($user_solution, $solution_value[
"value1"]);
211 foreach ($this->object->answers as $index => $answer)
213 $points_checked = $answer->getPointsChecked();
214 $points_unchecked = $answer->getPointsUnchecked();
215 if ($points_checked > $points_unchecked)
217 if ($points_checked > 0)
219 array_push($user_solution, $index);
226 include_once
"./Services/UICore/classes/class.ilTemplate.php";
227 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
228 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
229 foreach ($keys as $answer_id)
231 $answer = $this->
object->answers[$answer_id];
232 if (($active_id > 0) && (!$show_correct_solution))
234 if ($graphicalOutput)
239 foreach ($user_solution as $mc_solution)
241 if (strcmp($mc_solution, $answer_id) == 0)
248 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
259 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
270 $template->setCurrentBlock(
"icon_ok");
272 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
273 $template->parseCurrentBlock();
277 $template->setCurrentBlock(
"icon_ok");
279 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
280 $template->parseCurrentBlock();
284 if (strlen($answer->getImage()))
286 $template->setCurrentBlock(
"answer_image");
287 if ($this->object->getThumbSize())
289 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
293 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
295 $alt = $answer->getImage();
296 if (strlen($answer->getAnswertext()))
298 $alt = $answer->getAnswertext();
300 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
303 $template->parseCurrentBlock();
309 if ($this->object->getSpecificFeedbackSetting() == 2)
311 foreach ($user_solution as $mc_solution)
313 if (strcmp($mc_solution, $answer_id) == 0)
315 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
316 $this->object->getId(), $answer_id
320 $template->setCurrentBlock(
"feedback");
321 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput( $fb,
true ));
322 $template->parseCurrentBlock();
328 if ($this->object->getSpecificFeedbackSetting() == 1)
330 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
331 $this->object->getId(), $answer_id
335 $template->setCurrentBlock(
"feedback");
336 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput( $fb,
true ));
337 $template->parseCurrentBlock();
341 if ($this->object->getSpecificFeedbackSetting() == 3)
343 $answer = $this->
object->getAnswer($answer_id);
345 if ($answer->getPoints() > 0)
347 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
348 $this->object->getId(), $answer_id
352 $template->setCurrentBlock(
"feedback");
353 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput( $fb,
true ));
354 $template->parseCurrentBlock();
360 $template->setCurrentBlock(
"answer_row");
361 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
365 $pointschecked = $this->
object->answers[$answer_id]->getPointsChecked();
366 $pointsunchecked = $this->
object->answers[$answer_id]->getPointsUnchecked();
367 $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ?
"%s " . $this->lng->txt(
"point") :
"%s " . $this->lng->txt(
"points");
368 $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ?
"%s " . $this->lng->txt(
"point") :
"%s " . $this->lng->txt(
"points");
369 $template->setVariable(
"RESULT_OUTPUT", sprintf(
"(" . $this->lng->txt(
"checkbox_checked") .
" = $resulttextchecked, " . $this->lng->txt(
"checkbox_unchecked") .
" = $resulttextunchecked)", $pointschecked, $pointsunchecked));
371 foreach ($user_solution as $mc_solution)
373 if (strcmp($mc_solution, $answer_id) == 0)
376 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
383 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
385 $template->parseCurrentBlock();
387 $questiontext = $this->
object->getQuestion();
388 if ($show_question_text==
true)
390 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
392 $questionoutput = $template->get();
395 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput( $feedback ,
true ));
396 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
398 $solutionoutput = $solutiontemplate->get();
399 if (!$show_question_only)
404 return $solutionoutput;
407 function getPreview($show_question_only = FALSE, $showInlineFeedback =
false)
414 include_once
"./Services/UICore/classes/class.ilTemplate.php";
415 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
416 foreach ($keys as $answer_id)
418 $answer = $this->
object->answers[$answer_id];
419 if (strlen($answer->getImage()))
421 if ($this->object->getThumbSize())
423 $template->setCurrentBlock(
"preview");
424 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
425 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
427 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
428 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
429 $alt = $answer->getImage();
430 if (strlen($answer->getAnswertext()))
432 $alt = $answer->getAnswertext();
434 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
437 $template->parseCurrentBlock();
441 $template->setCurrentBlock(
"answer_image");
442 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
443 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
444 $alt = $answer->getImage();
445 if (strlen($answer->getAnswertext()))
447 $alt = $answer->getAnswertext();
449 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
450 $template->setVariable(
"ATTR", $attr);
453 $template->parseCurrentBlock();
457 if( $showInlineFeedback )
462 $template->setCurrentBlock(
"answer_row");
463 $template->setVariable(
"ANSWER_ID", $answer_id);
464 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
465 foreach ($user_solution as $mc_solution)
467 if (strcmp($mc_solution, $answer_id) == 0)
469 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
472 $template->parseCurrentBlock();
474 $questiontext = $this->
object->getQuestion();
475 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
476 $questionoutput = $template->get();
477 if (!$show_question_only)
482 return $questionoutput;
497 $is_postponed = FALSE,
498 $use_post_solutions = FALSE,
499 $show_feedback = FALSE
506 $user_solution = array();
510 include_once
"./Modules/Test/classes/class.ilObjTest.php";
515 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
516 foreach ($solutions as $idx => $solution_value)
518 array_push($user_solution, $solution_value[
"value1"]);
522 include_once
"./Services/UICore/classes/class.ilTemplate.php";
523 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
524 foreach ($keys as $answer_id)
526 $answer = $this->
object->answers[$answer_id];
527 if (strlen($answer->getImage()))
529 if ($this->object->getThumbSize())
531 $template->setCurrentBlock(
"preview");
532 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
533 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
535 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
536 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
537 $alt = $answer->getImage();
538 if (strlen($answer->getAnswertext()))
540 $alt = $answer->getAnswertext();
542 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
545 $template->parseCurrentBlock();
549 $template->setCurrentBlock(
"answer_image");
550 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
551 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
552 $alt = $answer->getImage();
553 if (strlen($answer->getAnswertext()))
555 $alt = $answer->getAnswertext();
557 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
558 $template->setVariable(
"ATTR", $attr);
561 $template->parseCurrentBlock();
570 $template->setCurrentBlock(
"answer_row");
571 $template->setVariable(
"ANSWER_ID", $answer_id);
572 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
573 foreach ($user_solution as $mc_solution)
575 if (strcmp($mc_solution, $answer_id) == 0)
577 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
580 $template->parseCurrentBlock();
582 $questiontext = $this->
object->getQuestion();
583 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
584 $questionoutput = $template->get();
585 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
596 global $rbacsystem, $ilTabs;
598 $ilTabs->clearTargets();
600 $this->ctrl->setParameterByClass(
"ilAssQuestionPageGUI",
"q_id",
$_GET[
"q_id"]);
601 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
602 $q_type = $this->
object->getQuestionType();
606 $classname = $q_type .
"GUI";
607 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
608 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
613 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
616 $ilTabs->addTarget(
"edit_page",
617 $this->ctrl->getLinkTargetByClass(
"ilAssQuestionPageGUI",
"edit"),
618 array(
"edit",
"insert",
"exec_pg"),
619 "",
"", $force_active);
624 $force_active =
false;
625 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
628 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
629 $force_active =
false;
631 $ilTabs->addTarget(
"edit_question",
633 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
634 $classname,
"", $force_active);
649 $ilTabs->addTarget(
"statistics",
650 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
665 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
669 if (!is_array($this->choiceKeys))
671 $this->choiceKeys = array_keys($this->object->answers);
672 if ($this->object->getShuffle())
674 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);
685 return $this->
object->prepareTextareaOutput($output, TRUE);
690 $this->
object->setShuffle(
$_POST[
"shuffle"] );
692 $this->
object->setSpecificFeedbackSetting(
$_POST[
'feedback_setting'] );
694 $this->
object->setMultilineAnswerSetting(
$_POST[
"types"] );
695 if (is_array(
$_POST[
'choice'][
'imagename'] ) &&
$_POST[
"types"] == 1)
697 $this->
object->isSingleline =
true;
702 $this->
object->isSingleline = (
$_POST[
"types"] == 0) ?
true :
false;
704 $this->
object->setThumbSize( (strlen(
$_POST[
"thumb_size"] )) ?
$_POST[
"thumb_size"] :
"" );
710 $this->
object->flushAnswers();
711 if ($this->object->isSingleline)
713 foreach (
$_POST[
'choice'][
'answer'] as $index => $answertext)
717 $picturefile =
$_POST[
'choice'][
'imagename'][$index];
718 $file_org_name = $_FILES[
'choice'][
'name'][
'image'][$index];
719 $file_temp_name = $_FILES[
'choice'][
'tmp_name'][
'image'][$index];
721 if (strlen( $file_temp_name ))
724 $suffix = strtolower( array_pop( explode(
".", $file_org_name ) ) );
725 if (in_array( $suffix, array(
"jpg",
"jpeg",
"png",
"gif" ) ))
728 $filename = $this->
object->createNewImageFileName( $file_org_name );
729 if ($this->object->setImageFile(
$filename, $file_temp_name ) == 0)
735 $this->
object->addAnswer( $answertext,
736 $_POST[
'choice'][
'points'][$index],
737 $_POST[
'choice'][
'points_unchecked'][$index],
745 foreach (
$_POST[
'choice'][
'answer'] as $index => $answer)
747 $answertext = $answer;
748 $this->
object->addAnswer( $answertext,
749 $_POST[
'choice'][
'points'][$index],
750 $_POST[
'choice'][
'points_unchecked'][$index],
762 $shuffle->setChecked( $this->object->getShuffle() );
763 $shuffle->setRequired( FALSE );
766 if ($this->object->getId())
769 $hidden->setValue( $this->object->getId() );
773 if (!$this->object->getSelfAssessmentEditingMode())
775 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
777 )) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
781 $types->setValue( ($isSingleline) ? 0 : 1 );
782 $types->setOptions( array(
783 0 => $this->lng->txt(
'answers_singleline' ),
784 1 => $this->lng->txt(
'answers_multiline' ),
793 $thumb_size =
new ilNumberInputGUI($this->lng->txt(
"thumb_size" ),
"thumb_size");
794 $thumb_size->
setSuffix($this->lng->txt(
"thumb_size_unit_pixel"));
795 $thumb_size->setMinValue( 20 );
796 $thumb_size->setDecimals( 0 );
797 $thumb_size->setSize( 6 );
798 $thumb_size->setInfo( $this->lng->txt(
'thumb_size_info' ) );
799 $thumb_size->setValue( $this->object->getThumbSize() );
800 $thumb_size->setRequired(
false );
802 return $isSingleline;
804 return $isSingleline;
810 include_once
"./Modules/TestQuestionPool/classes/class.ilMultipleChoiceWizardInputGUI.php";
813 $choices->setQuestionObject( $this->
object );
814 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
816 )) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
817 $choices->setSingleline( $isSingleline );
818 $choices->setAllowMove(
false );
819 if ($this->object->getSelfAssessmentEditingMode())
821 $choices->setSize( 40 );
822 $choices->setMaxLength( 800 );
824 if ($this->object->getAnswerCount() == 0)
825 $this->object->addAnswer(
"", 0, 0, 0 );
826 $choices->setValues( $this->object->getAnswers() );
869 $this->
aggregateAnswers( $relevant_answers, $this->object->getAnswers() ) )->get();
874 $aggregate = array();
875 foreach ($answers_defined_on_question as $answer)
877 $aggregated_info_for_answer = array();
878 $aggregated_info_for_answer[
'answertext'] = $answer->getAnswerText();
879 $aggregated_info_for_answer[
'count_checked'] = 0;
881 foreach ($relevant_answers_chosen as $relevant_answer)
883 if ($relevant_answer[
'value1'] == $answer->getOrder())
885 $aggregated_info_for_answer[
'count_checked']++;
888 $aggregated_info_for_answer[
'count_unchecked'] =
889 ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
890 - $aggregated_info_for_answer[
'count_checked'];
892 $aggregate[] = $aggregated_info_for_answer;
904 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_answers_table.html',
true,
true,
"Modules/TestQuestionPool");
906 foreach ($aggregate as $line_data)
908 $tpl->setCurrentBlock(
'aggregaterow' );
909 $tpl->setVariable(
'OPTION', $line_data[
'answertext'] );
910 $tpl->setVariable(
'COUNT', $line_data[
'count_checked'] );
911 $tpl->parseCurrentBlock();
924 if($this->object->getSpecificFeedbackSetting() == 2)
926 foreach($user_solution as $mc_solution)
928 if(strcmp($mc_solution, $answer_id) == 0)
930 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
933 $template->setCurrentBlock(
"feedback");
934 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
935 $template->parseCurrentBlock();
941 if($this->object->getSpecificFeedbackSetting() == 1)
943 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
946 $template->setCurrentBlock(
"feedback");
947 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
948 $template->parseCurrentBlock();
952 if($this->object->getSpecificFeedbackSetting() == 3)
954 $answer = $this->
object->getAnswer($answer_id);
956 if($answer->getPoints() > 0)
958 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
961 $template->setCurrentBlock(
"feedback");
962 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
963 $template->parseCurrentBlock();