ILIAS  release_7 Revision v7.30-3-g800a261c036
class.assImagemapQuestion.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
5require_once './Modules/Test/classes/inc.AssessmentConstants.php';
6require_once './Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
7require_once './Modules/TestQuestionPool/interfaces/interface.ilObjAnswerScoringAdjustable.php';
8require_once './Modules/TestQuestionPool/interfaces/interface.iQuestionCondition.php';
9require_once './Modules/TestQuestionPool/classes/class.ilUserQuestionResult.php';
10
25{
26 // hey: prevPassSolutions - wtf is imagemap ^^
27 public $currentSolution = array();
28 // hey.
29
32
33 public const AVAILABLE_SHAPES = [
34 'RECT' => 'rect',
35 'CIRCLE' => 'circle',
36 'POLY' => 'poly'];
37
39 public $answers;
40
43
46
48 public $coords;
49
51 protected $is_multiple_choice = false;
52
67 public function __construct(
68 $title = "",
69 $comment = "",
70 $author = "",
71 $owner = -1,
72 $question = "",
74 ) {
76 $this->image_filename = $image_filename;
77 $this->answers = array();
78 $this->coords = array();
79 }
80
87 {
88 $this->is_multiple_choice = $is_multiple_choice;
89 }
90
96 public function getIsMultipleChoice()
97 {
99 }
100
107 public function isComplete()
108 {
109 if (strlen($this->title)
110 && ($this->author)
111 && ($this->question)
112 && ($this->image_filename)
113 && (count($this->answers))
114 && ($this->getMaximumPoints() > 0)
115 ) {
116 return true;
117 }
118 return false;
119 }
120
130 public function saveToDb($original_id = "")
131 {
135 parent::saveToDb($original_id);
136 }
137
139 {
140 global $DIC;
141 $ilDB = $DIC['ilDB'];
142 $ilDB->manipulateF(
143 "DELETE FROM qpl_a_imagemap WHERE question_fi = %s",
144 array( "integer" ),
145 array( $this->getId() )
146 );
147
148 // Anworten wegschreiben
149 foreach ($this->answers as $key => $value) {
150 $answer_obj = $this->answers[$key];
151 $answer_obj->setOrder($key);
152 $next_id = $ilDB->nextId('qpl_a_imagemap');
153 $ilDB->manipulateF(
154 "INSERT INTO qpl_a_imagemap (answer_id, question_fi, answertext, points, aorder, coords, area, points_unchecked) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
155 array( "integer", "integer", "text", "float", "integer", "text", "text", "float" ),
156 array( $next_id, $this->id, $answer_obj->getAnswertext(
157 ), $answer_obj->getPoints(), $answer_obj->getOrder(
158 ), $answer_obj->getCoords(), $answer_obj->getArea(
159 ), $answer_obj->getPointsUnchecked() )
160 );
161 }
162 }
163
165 {
166 global $DIC;
167 $ilDB = $DIC['ilDB'];
168
169 $ilDB->manipulateF(
170 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
171 array( "integer" ),
172 array( $this->getId() )
173 );
174
175 $ilDB->manipulateF(
176 "INSERT INTO " . $this->getAdditionalTableName(
177 ) . " (question_fi, image_file, is_multiple_choice) VALUES (%s, %s, %s)",
178 array( "integer", "text", 'integer' ),
179 array(
180 $this->getId(),
181 $this->image_filename,
182 (int) $this->is_multiple_choice
183 )
184 );
185 }
186
192 public function duplicate($for_test = true, $title = "", $author = "", $owner = "", $testObjId = null)
193 {
194 if ($this->id <= 0) {
195 // The question has not been saved. It cannot be duplicated
196 return;
197 }
198 // duplicate the question in database
199 $this_id = $this->getId();
200 $thisObjId = $this->getObjId();
201
202 $clone = $this;
203 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
205 $clone->id = -1;
206
207 if ((int) $testObjId > 0) {
208 $clone->setObjId($testObjId);
209 }
210
211 if ($title) {
212 $clone->setTitle($title);
213 }
214 if ($author) {
215 $clone->setAuthor($author);
216 }
217 if ($owner) {
218 $clone->setOwner($owner);
219 }
220 if ($for_test) {
221 $clone->saveToDb($original_id);
222 } else {
223 $clone->saveToDb();
224 }
225
226 // copy question page content
227 $clone->copyPageOfQuestion($this_id);
228 // copy XHTML media objects
229 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
230 // duplicate the image
231 $clone->duplicateImage($this_id, $thisObjId);
232
233 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
234
235 return $clone->id;
236 }
237
245 public function copyObject($target_questionpool_id, $title = "")
246 {
247 if ($this->id <= 0) {
248 // The question has not been saved. It cannot be duplicated
249 return;
250 }
251 // duplicate the question in database
252 $clone = $this;
253 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
255 $clone->id = -1;
256 $source_questionpool_id = $this->getObjId();
257 $clone->setObjId($target_questionpool_id);
258 if ($title) {
259 $clone->setTitle($title);
260 }
261 $clone->saveToDb();
262
263 // copy question page content
264 $clone->copyPageOfQuestion($original_id);
265 // copy XHTML media objects
266 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
267 // duplicate the image
268 $clone->copyImage($original_id, $source_questionpool_id);
269
270 $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
271
272 return $clone->id;
273 }
274
275 public function createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle = "")
276 {
277 if ($this->id <= 0) {
278 // The question has not been saved. It cannot be duplicated
279 return;
280 }
281
282 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
283
284 $sourceQuestionId = $this->id;
285 $sourceParentId = $this->getObjId();
286
287 // duplicate the question in database
288 $clone = $this;
289 $clone->id = -1;
290
291 $clone->setObjId($targetParentId);
292
293 if ($targetQuestionTitle) {
294 $clone->setTitle($targetQuestionTitle);
295 }
296
297 $clone->saveToDb();
298 // copy question page content
299 $clone->copyPageOfQuestion($sourceQuestionId);
300 // copy XHTML media objects
301 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
302 // duplicate the image
303 $clone->copyImage($sourceQuestionId, $sourceParentId);
304
305 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
306
307 return $clone->id;
308 }
309
310 public function duplicateImage($question_id, $objectId = null)
311 {
312 global $DIC;
313 $ilLog = $DIC['ilLog'];
314
315 $imagepath = $this->getImagePath();
316 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
317
318 if ((int) $objectId > 0) {
319 $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
320 }
321
322 if (!file_exists($imagepath)) {
323 ilUtil::makeDirParents($imagepath);
324 }
325 $filename = $this->getImageFilename();
326
327 // #18755
328 if (!file_exists($imagepath_original . $filename)) {
329 $ilLog->write("Could not find an image map file when trying to duplicate image: " . $imagepath_original . $filename);
330 $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
331 $ilLog->write("Using fallback source directory:" . $imagepath_original);
332 }
333
334 if (!file_exists($imagepath_original . $filename) || !copy($imagepath_original . $filename, $imagepath . $filename)) {
335 $ilLog->write("Could not duplicate image for image map question: " . $imagepath_original . $filename);
336 }
337 }
338
339 public function copyImage($question_id, $source_questionpool)
340 {
341 $imagepath = $this->getImagePath();
342 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
343 $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
344 if (!file_exists($imagepath)) {
345 ilUtil::makeDirParents($imagepath);
346 }
347 $filename = $this->getImageFilename();
348 if (!copy($imagepath_original . $filename, $imagepath . $filename)) {
349 print "image could not be copied!!!! ";
350 }
351 }
352
362 public function loadFromDb($question_id)
363 {
364 global $DIC;
365 $ilDB = $DIC['ilDB'];
366
367 $result = $ilDB->queryF(
368 "SELECT qpl_questions.*, " . $this->getAdditionalTableName() . ".* FROM qpl_questions LEFT JOIN " . $this->getAdditionalTableName() . " ON " . $this->getAdditionalTableName() . ".question_fi = qpl_questions.question_id WHERE qpl_questions.question_id = %s",
369 array("integer"),
370 array($question_id)
371 );
372 if ($result->numRows() == 1) {
373 $data = $ilDB->fetchAssoc($result);
374 $this->setId($question_id);
375 $this->setObjId($data["obj_fi"]);
376 $this->setTitle($data["title"]);
377 $this->setComment($data["description"]);
378 $this->setOriginalId($data["original_id"]);
379 $this->setNrOfTries($data['nr_of_tries']);
380 $this->setAuthor($data["author"]);
381 $this->setPoints($data["points"]);
382 $this->setOwner($data["owner"]);
383 $this->setIsMultipleChoice($data["is_multiple_choice"] == self::MODE_MULTIPLE_CHOICE);
384 include_once("./Services/RTE/classes/class.ilRTE.php");
385 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
386 $this->setImageFilename($data["image_file"]);
387 $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
388
389 try {
393 }
394
395 try {
396 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
398 }
399
400 $result = $ilDB->queryF(
401 "SELECT * FROM qpl_a_imagemap WHERE question_fi = %s ORDER BY aorder ASC",
402 array("integer"),
403 array($question_id)
404 );
405 include_once "./Modules/TestQuestionPool/classes/class.assAnswerImagemap.php";
406 if ($result->numRows() > 0) {
407 while ($data = $ilDB->fetchAssoc($result)) {
408 array_push($this->answers, new ASS_AnswerImagemap($data["answertext"], $data["points"], $data["aorder"], $data["coords"], $data["area"], $data['question_fi'], $data['points_unchecked']));
409 }
410 }
411 }
412 parent::loadFromDb($question_id);
413 }
414
421 public function uploadImagemap(array $shapes)
422 {
423 $added = 0;
424
425 if (count($shapes) > 0) {
426 foreach ($shapes as $shape) {
427 $this->addAnswer($shape->getAnswertext(), 0.0, count($this->answers), $shape->getCoords(), $shape->getArea());
428 $added++;
429 }
430 }
431
432 return $added;
433 }
434
435 public function getImageFilename()
436 {
438 }
439
447 public function setImageFilename($image_filename, $image_tempfilename = "")
448 {
449 if (!empty($image_filename)) {
450 $image_filename = str_replace(" ", "_", $image_filename);
451 $this->image_filename = $image_filename;
452 }
453 if (!empty($image_tempfilename)) {
454 $imagepath = $this->getImagePath();
455 if (!file_exists($imagepath)) {
456 ilUtil::makeDirParents($imagepath);
457 }
458 if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) {
459 $this->ilias->raiseError("The image could not be uploaded!", $this->ilias->error_obj->MESSAGE);
460 }
461 global $DIC;
462 $ilLog = $DIC['ilLog'];
463 $ilLog->write("gespeichert: " . $imagepath . $image_filename);
464 }
465 }
466
476 public function get_imagemap_contents($href = "#")
477 {
478 $imagemap_contents = "<map name=\"" . $this->title . "\"> ";
479 for ($i = 0; $i < count($this->answers); $i++) {
480 $imagemap_contents .= "<area alt=\"" . $this->answers[$i]->getAnswertext() . "\" ";
481 $imagemap_contents .= "shape=\"" . $this->answers[$i]->getArea() . "\" ";
482 $imagemap_contents .= "coords=\"" . $this->answers[$i]->getCoords() . "\" ";
483 $imagemap_contents .= "href=\"$href&selimage=" . $this->answers[$i]->getOrder() . "\" /> ";
484 }
485 $imagemap_contents .= "</map>";
486 return $imagemap_contents;
487 }
488
503 public function addAnswer(
504 $answertext = "",
505 $points = 0.0,
506 $order = 0,
507 $coords = "",
508 $area = "",
509 $points_unchecked = 0.0
510 ) {
511 include_once "./Modules/TestQuestionPool/classes/class.assAnswerImagemap.php";
512 if (array_key_exists($order, $this->answers)) {
513 // Insert answer
514 $answer = new ASS_AnswerImagemap($answertext, $points, $order, $coords, $area, -1, $points_unchecked);
515 for ($i = count($this->answers) - 1; $i >= $order; $i--) {
516 $this->answers[$i + 1] = $this->answers[$i];
517 $this->answers[$i + 1]->setOrder($i + 1);
518 }
519 $this->answers[$order] = $answer;
520 } else {
521 // Append answer
522 $answer = new ASS_AnswerImagemap($answertext, $points, count($this->answers), $coords, $area, -1, $points_unchecked);
523 array_push($this->answers, $answer);
524 }
525 }
526
536 public function getAnswerCount()
537 {
538 return count($this->answers);
539 }
540
552 public function getAnswer($index = 0)
553 {
554 if ($index < 0) {
555 return null;
556 }
557 if (count($this->answers) < 1) {
558 return null;
559 }
560 if ($index >= count($this->answers)) {
561 return null;
562 }
563 return $this->answers[$index];
564 }
565
575 public function &getAnswers()
576 {
577 return $this->answers;
578 }
579
590 public function deleteArea($index = 0)
591 {
592 if ($index < 0) {
593 return;
594 }
595 if (count($this->answers) < 1) {
596 return;
597 }
598 if ($index >= count($this->answers)) {
599 return;
600 }
601 unset($this->answers[$index]);
602 $this->answers = array_values($this->answers);
603 for ($i = 0; $i < count($this->answers); $i++) {
604 if ($this->answers[$i]->getOrder() > $index) {
605 $this->answers[$i]->setOrder($i);
606 }
607 }
608 }
609
618 public function flushAnswers()
619 {
620 $this->answers = array();
621 }
622
631 public function getMaximumPoints()
632 {
633 $points = 0;
634 foreach ($this->answers as $key => $value) {
635 if ($this->is_multiple_choice) {
636 if ($value->getPoints() > $value->getPointsUnchecked()) {
637 $points += $value->getPoints();
638 } else {
639 $points += $value->getPointsUnchecked();
640 }
641 } else {
642 if ($value->getPoints() > $points) {
643 $points = $value->getPoints();
644 }
645 }
646 }
647 return $points;
648 }
649
660 public function calculateReachedPoints($active_id, $pass = null, $authorizedSolution = true, $returndetails = false)
661 {
662 if ($returndetails) {
663 throw new ilTestException('return details not implemented for ' . __METHOD__);
664 }
665
666 global $DIC;
667 $ilDB = $DIC['ilDB'];
668
669 $found_values = array();
670 if (is_null($pass)) {
671 $pass = $this->getSolutionMaxPass($active_id);
672 }
673 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorizedSolution);
674 while ($data = $ilDB->fetchAssoc($result)) {
675 if (strcmp($data["value1"], "") != 0) {
676 array_push($found_values, $data["value1"]);
677 }
678 }
679
680 $points = $this->calculateReachedPointsForSolution($found_values);
681
682 return $points;
683 }
684
686 {
687 $solutionData = $previewSession->getParticipantsSolution();
688
689 $reachedPoints = $this->calculateReachedPointsForSolution(is_array($solutionData) ? array_values($solutionData) : array());
690 $reachedPoints = $this->deductHintPointsFromReachedPoints($previewSession, $reachedPoints);
691
692 return $this->ensureNonNegativePoints($reachedPoints);
693 }
694
695 public function isAutosaveable()
696 {
697 return false; // #15217
698 }
699
708 public function saveWorkingData($active_id, $pass = null, $authorized = true)
709 {
710 global $DIC;
711 $ilDB = $DIC['ilDB'];
712
713 if (is_null($pass)) {
714 include_once "./Modules/Test/classes/class.ilObjTest.php";
715 $pass = ilObjTest::_getPass($active_id);
716 }
717
718 $solutionSelectionChanged = false;
719
720 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(function () use (&$solutionSelectionChanged, $ilDB, $active_id, $pass, $authorized) {
721 if ($authorized) {
722 // remove the dummy record of the intermediate solution
723 $this->deleteDummySolutionRecord($active_id, $pass);
724
725 // delete the authorized solution and make the intermediate solution authorized (keeping timestamps)
726 $this->removeCurrentSolution($active_id, $pass, true);
727 $this->updateCurrentSolutionsAuthorization($active_id, $pass, true, true);
728
729 $solutionSelectionChanged = true;
730 } else {
732 $active_id,
733 $pass,
734 $this->is_multiple_choice
735 );
736
737 if ($this->isReuseSolutionSelectionRequest()) {
738 $selection = $this->getReuseSolutionSelectionParameter();
739
740 foreach ($selection as $selectedIndex) {
741 $this->saveCurrentSolution($active_id, $pass, (int) $selectedIndex, null, $authorized);
742 $solutionSelectionChanged = true;
743 }
744 } elseif ($this->isRemoveSolutionSelectionRequest()) {
745 $selection = $this->getRemoveSolutionSelectionParameter();
746
747 $this->deleteSolutionRecordByValues($active_id, $pass, $authorized, array(
748 'value1' => (int) $selection
749 ));
750
751 $solutionSelectionChanged = true;
752 } elseif ($this->isAddSolutionSelectionRequest()) {
753 $selection = $this->getAddSolutionSelectionParameter();
754
755 if ($this->is_multiple_choice) {
756 $this->deleteSolutionRecordByValues($active_id, $pass, $authorized, array(
757 'value1' => (int) $_GET['selImage']
758 ));
759 } else {
760 $this->removeCurrentSolution($active_id, $pass, $authorized);
761 }
762
763 $this->saveCurrentSolution($active_id, $pass, $_GET['selImage'], null, $authorized);
764
765 $solutionSelectionChanged = true;
766 }
767 }
768 });
769
770 require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
772 if ($solutionSelectionChanged) {
773 assQuestion::logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
774 } else {
775 assQuestion::logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
776 }
777 }
778
779 return true;
780 }
781
782 protected function savePreviewData(ilAssQuestionPreviewSession $previewSession)
783 {
784 $solution = $previewSession->getParticipantsSolution();
785
786 if ($this->is_multiple_choice && strlen($_GET['remImage'])) {
787 unset($solution[(int) $_GET['remImage']]);
788 }
789
790 if (strlen($_GET['selImage'])) {
791 if (!$this->is_multiple_choice) {
792 $solution = array();
793 }
794
795 $solution[(int) $_GET['selImage']] = (int) $_GET['selImage'];
796 }
797
798 $previewSession->setParticipantsSolution($solution);
799 }
800
801 public function syncWithOriginal()
802 {
803 if ($this->getOriginalId()) {
804 parent::syncWithOriginal();
805 }
806 }
807
816 public function getQuestionType()
817 {
818 return "assImagemapQuestion";
819 }
820
829 public function getAdditionalTableName()
830 {
831 return "qpl_qst_imagemap";
832 }
833
842 public function getAnswerTableName()
843 {
844 return "qpl_a_imagemap";
845 }
846
852 {
853 $text = parent::getRTETextWithMediaObjects();
854 foreach ($this->answers as $index => $answer) {
855 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), 0, $index);
856 }
857 return $text;
858 }
859
863 public function setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
864 {
865 parent::setExportDetailsXLS($worksheet, $startrow, $active_id, $pass);
866
867 $solution = $this->getSolutionValues($active_id, $pass);
868
869 $i = 1;
870 foreach ($this->getAnswers() as $id => $answer) {
871 $worksheet->setCell($startrow + $i, 0, $answer->getArea() . ": " . $answer->getCoords());
872 $worksheet->setBold($worksheet->getColumnCoord(0) . ($startrow + $i));
873
874 $cellValue = 0;
875 foreach ($solution as $solIndex => $sol) {
876 if ($sol['value1'] == $id) {
877 $cellValue = 1;
878 break;
879 }
880 }
881
882 $worksheet->setCell($startrow + $i, 2, $cellValue);
883
884 $i++;
885 }
886
887 return $startrow + $i + 1;
888 }
889
893 public function deleteImage()
894 {
895 $file = $this->getImagePath() . $this->getImageFilename();
896 @unlink($file);
897 $this->flushAnswers();
898 $this->image_filename = "";
899 }
900
904 public function toJSON()
905 {
906 include_once("./Services/RTE/classes/class.ilRTE.php");
907 $result = array();
908 $result['id'] = (int) $this->getId();
909 $result['type'] = (string) $this->getQuestionType();
910 $result['title'] = (string) $this->getTitle();
911 $result['question'] = $this->formatSAQuestion($this->getQuestion());
912 $result['nr_of_tries'] = (int) $this->getNrOfTries();
913 $result['shuffle'] = (bool) $this->getShuffle();
914 $result['is_multiple'] = (bool) $this->getIsMultipleChoice();
915 $result['feedback'] = array(
916 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
917 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
918 );
919 $result['image'] = (string) $this->getImagePathWeb() . $this->getImageFilename();
920
921 $answers = array();
922 $order = 0;
923 foreach ($this->getAnswers() as $key => $answer_obj) {
924 array_push($answers, array(
925 "answertext" => (string) $answer_obj->getAnswertext(),
926 "points" => (float) $answer_obj->getPoints(),
927 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
928 "order" => (int) $order,
929 "coords" => $answer_obj->getCoords(),
930 "state" => $answer_obj->getState(),
931 "area" => $answer_obj->getArea(),
932 "feedback" => $this->formatSAQuestion(
933 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
934 )
935 ));
936 $order++;
937 }
938 $result['answers'] = $answers;
939
940 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
941 $result['mobs'] = $mobs;
942
943 return json_encode($result);
944 }
945
950 protected function calculateReachedPointsForSolution($found_values)
951 {
952 $points = 0;
953 if (count($found_values) > 0) {
954 foreach ($this->answers as $key => $answer) {
955 if (in_array($key, $found_values)) {
956 $points += $answer->getPoints();
957 } elseif ($this->getIsMultipleChoice()) {
958 $points += $answer->getPointsUnchecked();
959 }
960 }
961 return $points;
962 }
963 return $points;
964 }
965
974 public function getOperators($expression)
975 {
976 require_once "./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
978 }
979
984 public function getExpressionTypes()
985 {
986 return array(
991 );
992 }
993
1002 public function getUserQuestionResult($active_id, $pass)
1003 {
1005 global $DIC;
1006 $ilDB = $DIC['ilDB'];
1007 $result = new ilUserQuestionResult($this, $active_id, $pass);
1008
1009 $maxStep = $this->lookupMaxStep($active_id, $pass);
1010
1011 if ($maxStep !== null) {
1012 $data = $ilDB->queryF(
1013 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1014 array("integer", "integer", "integer", "integer"),
1015 array($active_id, $pass, $this->getId(), $maxStep)
1016 );
1017 } else {
1018 $data = $ilDB->queryF(
1019 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step IS NULL",
1020 array("integer", "integer", "integer"),
1021 array($active_id, $pass, $this->getId())
1022 );
1023 }
1024
1025 while ($row = $ilDB->fetchAssoc($data)) {
1026 $result->addKeyValue($row["value1"], $row["value1"]);
1027 }
1028
1029 $points = $this->calculateReachedPoints($active_id, $pass);
1030 $max_points = $this->getMaximumPoints();
1031
1032 $result->setReachedPercentage(($points / $max_points) * 100);
1033
1034 return $result;
1035 }
1036
1045 public function getAvailableAnswerOptions($index = null)
1046 {
1047 if ($index !== null) {
1048 return $this->getAnswer($index);
1049 } else {
1050 return $this->getAnswers();
1051 }
1052 }
1053
1054 // hey: prevPassSolutions - wtf is imagemap ^^
1055 public function getTestOutputSolutions($activeId, $pass)
1056 {
1057 $solution = parent::getTestOutputSolutions($activeId, $pass);
1058
1059 $this->currentSolution = array();
1060 foreach ($solution as $record) {
1061 $this->currentSolution[] = $record['value1'];
1062 }
1063
1064 return $solution;
1065 }
1067 {
1068 if (!$this->isAddSolutionSelectionRequest()) {
1069 return null;
1070 }
1071
1072 return $_GET["selImage"];
1073 }
1075 {
1076 if (!isset($_GET["selImage"])) {
1077 return false;
1078 }
1079
1080 if (!strlen($_GET["selImage"])) {
1081 return false;
1082 }
1083
1084 return true;
1085 }
1087 {
1088 if (!$this->isRemoveSolutionSelectionRequest()) {
1089 return null;
1090 }
1091
1092 return $_GET["remImage"];
1093 }
1095 {
1096 if (!$this->is_multiple_choice) {
1097 return false;
1098 }
1099
1100 if (!isset($_GET["remImage"])) {
1101 return false;
1102 }
1103
1104 if (!strlen($_GET["remImage"])) {
1105 return false;
1106 }
1107
1108 return true;
1109 }
1111 {
1112 if (!$this->isReuseSolutionSelectionRequest()) {
1113 return null;
1114 }
1115
1116 return assQuestion::explodeKeyValues($_GET["reuseSelection"]);
1117 }
1119 {
1120 if (!$this->getTestPresentationConfig()->isPreviousPassSolutionReuseAllowed()) {
1121 return false;
1122 }
1123
1124 if (!isset($_GET["reuseSelection"])) {
1125 return false;
1126 }
1127
1128 if (!strlen($_GET["reuseSelection"])) {
1129 return false;
1130 }
1131
1132 if (!preg_match('/\d(,\d)*/', $_GET["reuseSelection"])) {
1133 return false;
1134 }
1135
1136 return true;
1137 }
1138 // hey.
1139}
$result
if(! $in) print
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
Class for true/false or yes/no answers.
An exception for terminatinating execution or to throw for unit testing.
Class for image map questions.
getAvailableAnswerOptions($index=null)
If index is null, the function returns an array with all anwser options Else it returns the specific ...
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
getQuestionType()
Returns the question type of the question.
setIsMultipleChoice($is_multiple_choice)
Set true if the Imagemapquestion is a multiplechoice Question.
uploadImagemap(array $shapes)
Uploads an image map and takes over the areas.
flushAnswers()
Deletes all answers.
calculateReachedPointsFromPreviewSession(ilAssQuestionPreviewSession $previewSession)
toJSON()
Returns a JSON representation of the question.
duplicateImage($question_id, $objectId=null)
setImageFilename($image_filename, $image_tempfilename="")
Sets the image file name.
setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
{Creates an Excel worksheet for the detailed cumulated results of this question.object}
getAnswer($index=0)
Returns an answer.
getTestOutputSolutions($activeId, $pass)
getAnswerTableName()
Returns the name of the answer table in the database.
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
Duplicates an assImagemapQuestion.
getExpressionTypes()
Get all available expression types for a specific question.
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
saveWorkingData($active_id, $pass=null, $authorized=true)
Saves the learners input of the question to the database.
copyObject($target_questionpool_id, $title="")
Copies an assImagemapQuestion object.
deleteImage()
Deletes the image file.
calculateReachedPointsForSolution($found_values)
isComplete()
Returns true, if a imagemap question is complete for use.
getOperators($expression)
Get all available operations for a specific question.
deleteArea($index=0)
Deletes an answer.
& getAnswers()
Returns the answer array.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
copyImage($question_id, $source_questionpool)
loadFromDb($question_id)
Loads a assImagemapQuestion object from a database.
__construct( $title="", $comment="", $author="", $owner=-1, $question="", $image_filename="")
assImagemapQuestion constructor
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveToDb($original_id="")
Saves an assImagemapQuestion object to a database.
addAnswer( $answertext="", $points=0.0, $order=0, $coords="", $area="", $points_unchecked=0.0)
Adds a possible answer for a imagemap question.
getAnswerCount()
Returns the number of answers.
get_imagemap_contents($href="#")
Gets the imagemap file contents.
getIsMultipleChoice()
Returns true, if the imagemap question is a multiplechoice question.
savePreviewData(ilAssQuestionPreviewSession $previewSession)
Abstract basic class which is to be extended by the concrete assessment question type classes.
getCurrentSolutionResultSet($active_id, $pass, $authorized=true)
Get a restulset for the current user solution for a this question by active_id and pass.
getSolutionValues($active_id, $pass=null, $authorized=true)
Loads solutions of a given user from the database an returns it.
static _getOriginalId($question_id)
Returns the original id of a question.
formatSAQuestion($a_q)
Format self assessment question.
setId($id=-1)
Sets the id of the assQuestion object.
setOriginalId($original_id)
setObjId($obj_id=0)
Set the object id of the container object.
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
saveQuestionDataToDb($original_id="")
deleteSolutionRecordByValues($activeId, $passIndex, $authorized, $matchValues)
deleteDummySolutionRecord($activeId, $passIndex)
getId()
Gets the id of the assQuestion object.
saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized=true, $tstamp=null)
getObjId()
Get the object id of the container object.
setTitle($title="")
Sets the title string of the assQuestion object.
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.
setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
Sets the estimated working time of a question from given hour, minute and second.
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
static explodeKeyValues($keyValues)
static logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
removeCurrentSolution($active_id, $pass, $authorized=true)
setAuthor($author="")
Sets the authors name of the assQuestion object.
getTestPresentationConfig()
Get the test question configuration (initialised once)
forceExistingIntermediateSolution($activeId, $passIndex, $considerDummyRecordCreation)
getShuffle()
Gets the shuffle flag.
setLifecycle(ilAssQuestionLifecycle $lifecycle)
updateCurrentSolutionsAuthorization($activeId, $pass, $authorized, $keepTime=false)
getTitle()
Gets the title string of the assQuestion object.
setPoints($a_points)
Sets the maximum available points for the question.
setComment($comment="")
Sets the comment string of the assQuestion object.
setNrOfTries($a_nr_of_tries)
getQuestion()
Gets the question string of the question object.
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
setQuestion($question="")
Sets the question string of the question object.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
ensureNonNegativePoints($points)
static _getLogLanguage()
retrieve the log language for assessment logging
static _enabledAssessmentLogging()
check wether assessment logging is enabled or not
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
Base Exception for all Exceptions relating to Modules/Test.
Class ilUserQuestionResult.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static makeDirParents($a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: goto.php:24
$mobs
Definition: imgupload.php:54
Class iQuestionCondition.
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
Interface ilObjAnswerScoringAdjustable.
Interface ilObjQuestionScoringAdjustable.
$index
Definition: metadata.php:128
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)
global $ilDB
$data
Definition: storeScorm.php:23