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 include_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
39 include_once
'./Modules/TestQuestionPool/classes/class.assImagemapQuestion.php';
43 $this->
object->loadFromDb($id);
45 $assessmentSetting =
new ilSetting(
"assessment");
46 $this->linecolor = (strlen($assessmentSetting->get(
"imap_line_color"))) ?
"#" . $assessmentSetting->get(
"imap_line_color") :
"#FF0000";
51 if (isset(
$_POST[
"imagemap"]) ||
52 isset(
$_POST[
"imagemap_x"]) ||
53 isset(
$_POST[
"imagemap_y"]))
55 $this->ctrl->setCmd(
"getCoords");
65 $this->
object->saveToDb();
66 $this->ctrl->redirect($this,
'editQuestion');
78 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
81 require_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
93 if ($this->ctrl->getCmd() !=
'deleteImage')
95 $this->
object->flushAnswers();
96 if (is_array(
$_POST[
'image'][
'coords'][
'name'] ))
98 foreach (
$_POST[
'image'][
'coords'][
'name'] as $idx => $name)
100 if( $this->object->getIsMultipleChoice() && isset(
$_POST[
'image'][
'coords'][
'points_unchecked']) )
102 $pointsUnchecked =
$_POST[
'image'][
'coords'][
'points_unchecked'][$idx];
106 $pointsUnchecked = 0.0;
109 $this->
object->addAnswer(
111 $_POST[
'image'][
'coords'][
'points'][$idx],
113 $_POST[
'image'][
'coords'][
'coords'][$idx],
114 $_POST[
'image'][
'coords'][
'shape'][$idx],
119 if (strlen( $_FILES[
'imagemapfile'][
'tmp_name'] ))
121 if ($this->object->getSelfAssessmentEditingMode() && $this->
object->getId() < 1)
122 $this->object->createNewQuestion();
123 $this->
object->uploadImagemap( $_FILES[
'imagemapfile'][
'tmp_name'] );
130 if ($this->ctrl->getCmd() ==
'deleteImage')
132 $this->
object->deleteImage();
136 if (strlen( $_FILES[
'image'][
'tmp_name'] ) == 0)
138 $this->
object->setImageFilename(
$_POST[
"image_name"] );
141 if (strlen( $_FILES[
'image'][
'tmp_name'] ))
143 if ($this->object->getSelfAssessmentEditingMode() && $this->
object->getId() < 1)
144 $this->object->createNewQuestion();
145 $this->
object->setImageFilename( $_FILES[
'image'][
'name'], $_FILES[
'image'][
'tmp_name'] );
156 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
158 $form->setFormAction($this->ctrl->getFormAction($this));
160 $form->setMultipart(TRUE);
161 $form->setTableWidth(
"100%");
162 $form->setId(
"assimagemap");
174 $form->setValuesByPost();
175 $errors = !$form->checkInput();
176 $form->setValuesByPost();
178 if (
$errors) $checkonly =
false;
181 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
195 $radioGroup =
new ilRadioGroupInputGUI($this->lng->txt(
'tst_imap_qst_mode' ),
'is_multiple_choice');
196 $radioGroup->
setValue( $this->object->getIsMultipleChoice() );
197 $modeSingleChoice =
new ilRadioOption($this->lng->txt(
'tst_imap_qst_mode_sc'),
199 $modeMultipleChoice =
new ilRadioOption($this->lng->txt(
'tst_imap_qst_mode_mc'),
201 $radioGroup->addOption( $modeSingleChoice );
202 $radioGroup->addOption( $modeMultipleChoice );
206 include_once
"./Modules/TestQuestionPool/classes/class.ilImagemapFileInputGUI.php";
209 $image->setRequired(
true );
211 if (strlen( $this->object->getImageFilename() ))
213 $image->setImage( $this->object->getImagePathWeb() . $this->
object->getImageFilename() );
214 $image->setValue( $this->object->getImageFilename() );
215 $image->setAreas( $this->object->getAnswers() );
216 $assessmentSetting =
new ilSetting(
"assessment");
217 $linecolor = (strlen( $assessmentSetting->get(
"imap_line_color" )
218 )) ?
"\"#" . $assessmentSetting->get(
"imap_line_color" ) .
"\"" :
"\"#FF0000\"";
220 $image->setImagePath( $this->object->getImagePath() );
221 $image->setImagePathWeb( $this->object->getImagePathWeb() );
226 $imagemapfile =
new ilFileInputGUI($this->lng->txt(
'add_imagemap' ),
'imagemapfile');
228 $form->
addItem( $imagemapfile );
256 $coords = join(
$_POST[
'image'][
'mapcoords'],
",");
260 if (preg_match(
"/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/",
$_POST[
'image'][
'mapcoords'][0] .
" " .
$_POST[
'image'][
'mapcoords'][1], $matches))
262 $coords =
"$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
267 $coords = join($_POST[
'image'][
'mapcoords'],
",");
271 $this->
object->addAnswer(
$_POST[
"shapetitle"], 0, count($this->object->getAnswers()), $coords,
$_POST[
"shape"]);
272 $this->
object->saveToDb();
273 $this->ctrl->redirect($this,
'editQuestion');
278 $shape = (strlen($shape)) ? $shape :
$_POST[
'shape'];
279 include_once
"./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
281 $this->tpl->addBlockFile(
"QUESTION_DATA",
"question_data",
"tpl.il_as_qpl_imagemap_question.html",
"Modules/TestQuestionPool");
283 if (is_array(
$_POST[
'image'][
'mapcoords']))
285 foreach (
$_POST[
'image'][
'mapcoords'] as $value)
287 array_push($coords, $value);
290 if (is_array(
$_POST[
'cmd'][
'areaEditor'][
'image']))
292 array_push($coords,
$_POST[
'cmd'][
'areaEditor'][
'image'][0] .
"," .
$_POST[
'cmd'][
'areaEditor'][
'image'][1]);
294 foreach ($coords as $value)
296 $this->tpl->setCurrentBlock(
"hidden");
297 $this->tpl->setVariable(
"HIDDEN_NAME",
'image[mapcoords][]');
298 $this->tpl->setVariable(
"HIDDEN_VALUE", $value);
299 $this->tpl->parseCurrentBlock();
302 $this->tpl->setCurrentBlock(
"hidden");
303 $this->tpl->setVariable(
"HIDDEN_NAME",
'shape');
304 $this->tpl->setVariable(
"HIDDEN_VALUE", $shape);
305 $this->tpl->parseCurrentBlock();
308 foreach ($this->object->answers as $index => $answer)
310 $preview->addArea($index, $answer->getArea(), $answer->getCoords(), $answer->getAnswertext(),
"",
"",
true,
$this->linecolor);
313 $disabled_save =
" disabled=\"disabled\"";
318 if (count($coords) == 0)
322 else if (count($coords) == 1)
325 $preview->addPoint(
$preview->getAreaCount(), join($coords,
","), TRUE,
"blue");
327 else if (count($coords) == 2)
329 $c = join($coords,
",");
335 if (count($coords) == 0)
339 else if (count($coords) == 1)
342 $preview->addPoint(
$preview->getAreaCount(), join($coords,
","), TRUE,
"blue");
344 else if (count($coords) == 2)
346 if (preg_match(
"/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $coords[0] .
" " . $coords[1], $matches))
348 $c =
"$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
355 if (count($coords) == 0)
359 else if (count($coords) == 1)
362 $preview->addPoint(
$preview->getAreaCount(), join($coords,
","), TRUE,
"blue");
364 else if (count($coords) > 1)
368 $c = join($coords,
",");
377 $imagepath = $this->
object->getImagePathWeb() .
$preview->getPreviewFilename($this->object->getImagePath(), $this->
object->getImageFilename()) .
"?img=" . time();
380 $this->tpl->setCurrentBlock(
"maparea");
381 $this->tpl->setVariable(
"IMAGE_SOURCE",
"$imagepath");
382 $this->tpl->setVariable(
"IMAGEMAP_NAME",
"image");
383 $this->tpl->parseCurrentBlock();
387 $this->tpl->setCurrentBlock(
"imagearea");
388 $this->tpl->setVariable(
"IMAGE_SOURCE",
"$imagepath");
389 $this->tpl->setVariable(
"ALT_IMAGE", $this->lng->txt(
"imagemap"));
390 $this->tpl->parseCurrentBlock();
393 if (strlen(
$_POST[
'shapetitle']))
395 $this->tpl->setCurrentBlock(
"shapetitle");
396 $this->tpl->setVariable(
"VALUE_SHAPETITLE",
$_POST[
"shapetitle"]);
397 $this->tpl->parseCurrentBlock();
400 $this->tpl->setVariable(
"TEXT_IMAGEMAP", $this->lng->txt(
"imagemap"));
401 $this->tpl->setVariable(
"TEXT_SHAPETITLE", $this->lng->txt(
"name"));
402 $this->tpl->setVariable(
"CANCEL", $this->lng->txt(
"cancel"));
403 $this->tpl->setVariable(
"SAVE", $this->lng->txt(
"save"));
404 $this->tpl->setVariable(
"DISABLED_SAVE", $disabled_save);
408 $this->tpl->setVariable(
"FORMACTION", $this->ctrl->getFormaction($this,
'addRect'));
411 $this->tpl->setVariable(
"FORMACTION", $this->ctrl->getFormaction($this,
'addCircle'));
414 $this->tpl->setVariable(
"FORMACTION", $this->ctrl->getFormaction($this,
'addPoly'));
422 $position = key(
$_POST[
'cmd'][
'removeArea'][
'image']);
423 $this->
object->deleteArea($position);
430 $this->ctrl->redirect($this,
'editQuestion');
433 function outQuestionForTest($formaction, $active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
437 require_once
'./Modules/Test/classes/class.ilObjTest.php';
441 $info =& $this->
object->getSolutionValues($active_id,
$pass);
445 $info =& $this->
object->getSolutionValues($active_id, NULL);
450 if (strcmp($info[0][
"value1"],
"") != 0)
452 $formaction .=
"&selImage=" . $info[0][
"value1"];
456 $test_output = $this->
getTestOutput($active_id,
$pass, $is_postponed, $use_post_solutions, $show_feedback);
457 $this->tpl->setVariable(
"QUESTION_OUTPUT", $test_output);
458 $this->tpl->setVariable(
"FORMACTION", $formaction);
479 $graphicalOutput = FALSE,
480 $result_output = FALSE,
481 $show_question_only = TRUE,
482 $show_feedback = FALSE,
483 $show_correct_solution = FALSE,
484 $show_manual_scoring = FALSE,
485 $show_question_text = TRUE
488 $imagepath = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
489 $solutions = array();
490 if (($active_id > 0) && (!$show_correct_solution))
492 include_once
"./Modules/Test/classes/class.ilObjTest.php";
497 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
501 if(!$this->object->getIsMultipleChoice())
505 foreach ($this->object->answers as $index => $answer)
507 if ($answer->getPoints() > $max_points)
509 $max_points = $answer->getPoints();
510 $found_index = $index;
513 array_push($solutions, array(
"value1" => $found_index));
518 foreach($this->object->answers as $index => $answer)
520 $points_checked = $answer->getPoints();
521 $points_unchecked = $answer->getPointsUnchecked();
522 if($points_checked > $points_unchecked)
524 if($points_checked > 0)
526 array_push($solutions, array(
"value1" => $index));
533 if (is_array($solutions))
535 include_once
"./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
537 foreach ($solutions as $idx => $solution_value)
539 if (strcmp($solution_value[
"value1"],
"") != 0)
541 $preview->addArea($solution_value[
"value1"], $this->object->answers[$solution_value[
"value1"]]->getArea(), $this->
object->answers[$solution_value[
"value1"]]->getCoords(), $this->
object->answers[$solution_value[
"value1"]]->getAnswertext(),
"",
"",
true,
$this->linecolor);
542 $solution_id = $solution_value[
"value1"];
546 $imagepath = $this->
object->getImagePathWeb() .
$preview->getPreviewFilename($this->object->getImagePath(), $this->
object->getImageFilename());
550 include_once
"./Services/UICore/classes/class.ilTemplate.php";
551 $template =
new ilTemplate(
"tpl.il_as_qpl_imagemap_question_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
552 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
553 $questiontext = $this->
object->getQuestion();
554 if ($show_question_text==
true)
556 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
558 $template->setVariable(
"IMG_SRC",
"$imagepath");
559 $template->setVariable(
"IMG_ALT", $this->lng->txt(
"imagemap"));
560 $template->setVariable(
"IMG_TITLE", $this->lng->txt(
"imagemap"));
561 if (($active_id > 0) && (!$show_correct_solution))
563 if ($graphicalOutput)
566 $reached_points = $this->
object->getReachedPoints($active_id,
$pass);
567 if ($reached_points == $this->object->getMaximumPoints())
569 $template->setCurrentBlock(
"icon_ok");
571 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
572 $template->parseCurrentBlock();
576 $template->setCurrentBlock(
"icon_ok");
577 if ($reached_points > 0)
580 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
585 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
587 $template->parseCurrentBlock();
594 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
595 $this->object->getId(), $solution_id
600 $template->setCurrentBlock(
"feedback");
601 $template->setVariable(
"FEEDBACK", $fb);
602 $template->parseCurrentBlock();
606 $questionoutput = $template->get();
608 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
609 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
611 $solutionoutput = $solutiontemplate->get();
612 if (!$show_question_only)
617 return $solutionoutput;
620 function getPreview($show_question_only = FALSE, $showInlineFeedback =
false)
624 $user_solution = array();
628 $user_solution = array_values($this->
getPreviewSession()->getParticipantsSolution());
631 include_once
"./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
633 foreach ($user_solution as $idx => $solution_value)
635 if (strcmp($solution_value,
"") != 0)
637 $preview->addArea($solution_value, $this->object->answers[$solution_value]->getArea(), $this->
object->answers[$solution_value]->getCoords(), $this->
object->answers[$solution_value]->getAnswertext(),
"",
"",
true,
$this->linecolor);
641 $imagepath = $this->
object->getImagePathWeb() .
$preview->getPreviewFilename($this->object->getImagePath(), $this->
object->getImageFilename());
645 $user_solution = array();
646 $imagepath = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
650 include_once
"./Services/UICore/classes/class.ilTemplate.php";
651 $template =
new ilTemplate(
"tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
662 foreach ($this->object->answers as $answer_id => $answer)
664 $parameter =
"&selImage=$answer_id";
665 if(is_array($user_solution) && in_array($answer_id, $user_solution))
667 $parameter =
"&remImage=$answer_id";
672 $template->setCurrentBlock(
"imagemap_area_href");
673 $template->setVariable(
"HREF_AREA", $hrefArea . $parameter);
674 $template->parseCurrentBlock();
677 $template->setCurrentBlock(
"imagemap_area");
678 $template->setVariable(
"SHAPE", $answer->getArea());
679 $template->setVariable(
"COORDS", $answer->getCoords());
682 $template->parseCurrentBlock();
684 $questiontext = $this->
object->getQuestion();
685 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
686 $template->setVariable(
"IMG_SRC",
"$imagepath");
687 $template->setVariable(
"IMG_ALT", $this->lng->txt(
"imagemap"));
688 $template->setVariable(
"IMG_TITLE", $this->lng->txt(
"imagemap"));
689 $questionoutput = $template->get();
690 if (!$show_question_only)
695 return $questionoutput;
698 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
702 if($this->object->getIsMultipleChoice())
704 $user_solution = array();
709 include_once
"./Modules/Test/classes/class.ilObjTest.php";
714 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
715 foreach ($solutions as $idx => $solution_value)
717 if($this->object->getIsMultipleChoice())
719 $user_solution[] = $solution_value[
"value1"];
723 $user_solution = $solution_value[
"value1"];
728 $imagepath = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
732 include_once
"./Modules/Test/classes/class.ilObjTest.php";
737 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
738 include_once
"./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
740 foreach ($solutions as $idx => $solution_value)
742 if (strcmp($solution_value[
"value1"],
"") != 0)
744 $preview->addArea($solution_value[
"value1"], $this->object->answers[$solution_value[
"value1"]]->getArea(), $this->
object->answers[$solution_value[
"value1"]]->getCoords(), $this->
object->answers[$solution_value[
"value1"]]->getAnswertext(),
"",
"",
true,
$this->linecolor);
748 $imagepath = $this->
object->getImagePathWeb() .
$preview->getPreviewFilename($this->object->getImagePath(), $this->
object->getImageFilename());
752 include_once
"./Services/UICore/classes/class.ilTemplate.php";
753 $template =
new ilTemplate(
"tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
754 $this->ctrl->setParameterByClass($this->
getTargetGuiClass(),
"formtimestamp", time());
756 foreach ($this->object->answers as $answer_id => $answer)
758 $template->setCurrentBlock(
"imagemap_area");
759 $parameter =
"&selImage=$answer_id";
760 if(is_array($user_solution) && in_array($answer_id, $user_solution))
762 $parameter =
"&remImage=$answer_id";
764 $template->setVariable(
"HREF_AREA", $hrefArea . $parameter);
765 $template->setVariable(
"SHAPE", $answer->getArea());
766 $template->setVariable(
"COORDS", $answer->getCoords());
769 $template->parseCurrentBlock();
772 if(!$this->object->getIsMultipleChoice() && strlen($user_solution) && $user_solution == $answer_id)
774 $feedback = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
775 $this->object->getId(), $answer_id
777 if (strlen($feedback))
779 $template->setCurrentBlock(
"feedback");
780 $template->setVariable(
"FEEDBACK", $feedback);
781 $template->parseCurrentBlock();
786 $questiontext = $this->
object->getQuestion();
787 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
788 $template->setVariable(
"IMG_SRC",
"$imagepath");
789 $template->setVariable(
"IMG_ALT", $this->lng->txt(
"imagemap"));
790 $template->setVariable(
"IMG_TITLE", $this->lng->txt(
"imagemap"));
791 $questionoutput = $template->get();
792 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
805 global $rbacsystem, $ilTabs;
807 $ilTabs->clearTargets();
809 $this->ctrl->setParameterByClass(
"ilAssQuestionPageGUI",
"q_id",
$_GET[
"q_id"]);
810 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
811 $q_type = $this->
object->getQuestionType();
815 $classname = $q_type .
"GUI";
816 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
817 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
822 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
825 $ilTabs->addTarget(
"edit_page",
826 $this->ctrl->getLinkTargetByClass(
"ilAssQuestionPageGUI",
"edit"),
827 array(
"edit",
"insert",
"exec_pg"),
828 "",
"", $force_active);
834 $force_active =
false;
835 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
838 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
839 if (array_key_exists(
"imagemap_x",
$_POST))
841 $force_active =
true;
844 $ilTabs->addTarget(
"edit_question",
846 array(
"editQuestion",
"save",
"addArea",
"addRect",
"addCircle",
"addPoly",
847 "uploadingImage",
"uploadingImagemap",
"areaEditor",
848 "removeArea",
"saveShape",
"saveEdit",
"originalSyncForm"),
849 $classname,
"", $force_active);
864 $ilTabs->addTarget(
"statistics",
865 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
875 if( !$this->object->feedbackOBJ->specificAnswerFeedbackExists(array_values($this->object->getAnswers())) )
880 $output =
'<table class="test_specific_feedback"><tbody>';
882 foreach($this->object->getAnswers() as $idx => $answer)
884 $feedback = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
885 $this->object->getId(), $idx
888 $output .=
"<tr><td>{$answer->getAnswerText()}</td><td>{$feedback}</td></tr>";
891 $output .=
'</tbody></table>';
893 return $this->
object->prepareTextareaOutput($output, TRUE);