ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
28
31
34
37
40
42 protected $is_multiple_choice = false;
43
58 public function __construct(
59 $title = "",
60 $comment = "",
61 $author = "",
62 $owner = -1,
63 $question = "",
65 )
66 {
67 parent::__construct($title, $comment, $author, $owner, $question);
68 $this->image_filename = $image_filename;
69 $this->answers = array();
70 $this->coords = array();
71 }
72
79 {
80 $this->is_multiple_choice = $is_multiple_choice;
81 }
82
88 public function getIsMultipleChoice()
89 {
91 }
92
99 function isComplete()
100 {
101 if (strlen($this->title)
102 && ($this->author)
103 && ($this->question)
104 && ($this->image_filename)
105 && (count($this->answers))
106 && ($this->getMaximumPoints() > 0)
107 )
108 {
109 return true;
110 }
111 return false;
112 }
113
123 public function saveToDb($original_id = "")
124 {
128 parent::saveToDb($original_id);
129 }
130
132 {
133 global $ilDB;
134 $ilDB->manipulateF( "DELETE FROM qpl_a_imagemap WHERE question_fi = %s",
135 array( "integer" ),
136 array( $this->getId() )
137 );
138
139 // Anworten wegschreiben
140 foreach ($this->answers as $key => $value)
141 {
142 $answer_obj = $this->answers[$key];
143 $next_id = $ilDB->nextId( 'qpl_a_imagemap' );
144 $ilDB->manipulateF( "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)",
145 array( "integer", "integer", "text", "float", "integer", "text", "text", "float" ),
146 array( $next_id, $this->id, $answer_obj->getAnswertext(
147 ), $answer_obj->getPoints(), $answer_obj->getOrder(
148 ), $answer_obj->getCoords(), $answer_obj->getArea(
149 ), $answer_obj->getPointsUnchecked() )
150 );
151 }
152 }
153
155 {
156 global $ilDB;
157
158 $ilDB->manipulateF( "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
159 array( "integer" ),
160 array( $this->getId() )
161 );
162
163 $ilDB->manipulateF( "INSERT INTO " . $this->getAdditionalTableName(
164 ) . " (question_fi, image_file, is_multiple_choice) VALUES (%s, %s, %s)",
165 array( "integer", "text", 'integer' ),
166 array(
167 $this->getId(),
168 $this->image_filename,
169 (int)$this->is_multiple_choice
170 )
171 );
172 }
173
179 function duplicate($for_test = true, $title = "", $author = "", $owner = "", $testObjId = null)
180 {
181 if ($this->id <= 0)
182 {
183 // The question has not been saved. It cannot be duplicated
184 return;
185 }
186 // duplicate the question in database
187 $this_id = $this->getId();
188 $thisObjId = $this->getObjId();
189
190 $clone = $this;
191 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
193 $clone->id = -1;
194
195 if( (int)$testObjId > 0 )
196 {
197 $clone->setObjId($testObjId);
198 }
199
200 if ($title)
201 {
202 $clone->setTitle($title);
203 }
204 if ($author)
205 {
206 $clone->setAuthor($author);
207 }
208 if ($owner)
209 {
210 $clone->setOwner($owner);
211 }
212 if ($for_test)
213 {
214 $clone->saveToDb($original_id);
215 }
216 else
217 {
218 $clone->saveToDb();
219 }
220
221 // copy question page content
222 $clone->copyPageOfQuestion($this_id);
223 // copy XHTML media objects
224 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
225 // duplicate the image
226 $clone->duplicateImage($this_id, $thisObjId);
227
228 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
229
230 return $clone->id;
231 }
232
240 function copyObject($target_questionpool_id, $title = "")
241 {
242 if ($this->id <= 0)
243 {
244 // The question has not been saved. It cannot be duplicated
245 return;
246 }
247 // duplicate the question in database
248 $clone = $this;
249 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
251 $clone->id = -1;
252 $source_questionpool_id = $this->getObjId();
253 $clone->setObjId($target_questionpool_id);
254 if ($title)
255 {
256 $clone->setTitle($title);
257 }
258 $clone->saveToDb();
259
260 // copy question page content
261 $clone->copyPageOfQuestion($original_id);
262 // copy XHTML media objects
263 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
264 // duplicate the image
265 $clone->copyImage($original_id, $source_questionpool_id);
266
267 $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
268
269 return $clone->id;
270 }
271
272 public function createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle = "")
273 {
274 if ($this->id <= 0)
275 {
276 // The question has not been saved. It cannot be duplicated
277 return;
278 }
279
280 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
281
282 $sourceQuestionId = $this->id;
283 $sourceParentId = $this->getObjId();
284
285 // duplicate the question in database
286 $clone = $this;
287 $clone->id = -1;
288
289 $clone->setObjId($targetParentId);
290
291 if ($targetQuestionTitle)
292 {
293 $clone->setTitle($targetQuestionTitle);
294 }
295
296 $clone->saveToDb();
297 // copy question page content
298 $clone->copyPageOfQuestion($sourceQuestionId);
299 // copy XHTML media objects
300 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
301 // duplicate the image
302 $clone->copyImage($sourceQuestionId, $sourceParentId);
303
304 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
305
306 return $clone->id;
307 }
308
309 function duplicateImage($question_id, $objectId = null)
310 {
311 global $ilLog;
312
313 $imagepath = $this->getImagePath();
314 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
315
316 if( (int)$objectId > 0 )
317 {
318 $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
319 }
320
321 if(!file_exists($imagepath))
322 {
323 ilUtil::makeDirParents($imagepath);
324 }
325 $filename = $this->getImageFilename();
326
327 // #18755
328 if(!file_exists($imagepath_original . $filename))
329 {
330 $ilLog->write("Could not find an image map file when trying to duplicate image: " . $imagepath_original . $filename);
331 $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
332 $ilLog->write("Using fallback source directory:" . $imagepath_original);
333 }
334
335 if(!file_exists($imagepath_original . $filename) || !copy($imagepath_original . $filename, $imagepath . $filename))
336 {
337 $ilLog->write("Could not duplicate image for image map question: " . $imagepath_original . $filename);
338 }
339 }
340
341 function copyImage($question_id, $source_questionpool)
342 {
343 $imagepath = $this->getImagePath();
344 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
345 $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
346 if (!file_exists($imagepath))
347 {
348 ilUtil::makeDirParents($imagepath);
349 }
350 $filename = $this->getImageFilename();
351 if (!copy($imagepath_original . $filename, $imagepath . $filename))
352 {
353 print "image could not be copied!!!! ";
354 }
355 }
356
366 function loadFromDb($question_id)
367 {
368 global $ilDB;
369
370 $result = $ilDB->queryF("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",
371 array("integer"),
372 array($question_id)
373 );
374 if ($result->numRows() == 1)
375 {
376 $data = $ilDB->fetchAssoc($result);
377 $this->setId($question_id);
378 $this->setObjId($data["obj_fi"]);
379 $this->setTitle($data["title"]);
380 $this->setComment($data["description"]);
381 $this->setOriginalId($data["original_id"]);
382 $this->setNrOfTries($data['nr_of_tries']);
383 $this->setAuthor($data["author"]);
384 $this->setPoints($data["points"]);
385 $this->setOwner($data["owner"]);
386 $this->setIsMultipleChoice($data["is_multiple_choice"] == self::MODE_MULTIPLE_CHOICE);
387 include_once("./Services/RTE/classes/class.ilRTE.php");
388 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
389 $this->setImageFilename($data["image_file"]);
390 $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
391
392 try
393 {
394 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
395 }
397 {
398 }
399
400 $result = $ilDB->queryF("SELECT * FROM qpl_a_imagemap WHERE question_fi = %s ORDER BY aorder ASC",
401 array("integer"),
402 array($question_id)
403 );
404 include_once "./Modules/TestQuestionPool/classes/class.assAnswerImagemap.php";
405 if ($result->numRows() > 0)
406 {
407 while ($data = $ilDB->fetchAssoc($result))
408 {
409 array_push($this->answers, new ASS_AnswerImagemap($data["answertext"], $data["points"], $data["aorder"], $data["coords"], $data["area"], $data['question_fi'], $data['points_unchecked']));
410 }
411 }
412 }
413 parent::loadFromDb($question_id);
414 }
415
422 function uploadImagemap($imagemap_filename = "")
423 {
424 $added = 0;
425 if (!empty($imagemap_filename))
426 {
427 $fp = fopen($imagemap_filename, "r");
428 $contents = fread($fp, filesize($imagemap_filename));
429 fclose($fp);
430 if (preg_match_all("/<area(.+)>/siU", $contents, $matches))
431 {
432 for ($i=0; $i< count($matches[1]); $i++)
433 {
434 preg_match("/alt\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $alt);
435 preg_match("/coords\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $coords);
436 preg_match("/shape\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $shape);
437 $this->addAnswer($alt[1], 0.0, count($this->answers), $coords[1], $shape[1]);
438 $added++;
439 }
440 }
441 }
442 return $added;
443 }
444
446 {
448 }
449
457 function setImageFilename($image_filename, $image_tempfilename = "")
458 {
459 if (!empty($image_filename))
460 {
461 $image_filename = str_replace(" ", "_", $image_filename);
462 $this->image_filename = $image_filename;
463 }
464 if (!empty($image_tempfilename))
465 {
466 $imagepath = $this->getImagePath();
467 if (!file_exists($imagepath))
468 {
469 ilUtil::makeDirParents($imagepath);
470 }
471 if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
472 {
473 $this->ilias->raiseError("The image could not be uploaded!", $this->ilias->error_obj->MESSAGE);
474 }
475 global $ilLog; $ilLog->write("gespeichert: " . $imagepath.$image_filename);
476 }
477 }
478
488 function get_imagemap_contents($href = "#") {
489 $imagemap_contents = "<map name=\"".$this->title."\"> ";
490 for ($i = 0; $i < count($this->answers); $i++) {
491 $imagemap_contents .= "<area alt=\"".$this->answers[$i]->getAnswertext()."\" ";
492 $imagemap_contents .= "shape=\"".$this->answers[$i]->getArea()."\" ";
493 $imagemap_contents .= "coords=\"".$this->answers[$i]->getCoords()."\" ";
494 $imagemap_contents .= "href=\"$href&selimage=" . $this->answers[$i]->getOrder() . "\" /> ";
495 }
496 $imagemap_contents .= "</map>";
497 return $imagemap_contents;
498 }
499
514 function addAnswer(
515 $answertext = "",
516 $points = 0.0,
517 $order = 0,
518 $coords="",
519 $area="",
520 $points_unchecked = 0.0
521 )
522 {
523 include_once "./Modules/TestQuestionPool/classes/class.assAnswerImagemap.php";
524 if (array_key_exists($order, $this->answers))
525 {
526 // Insert answer
527 $answer = new ASS_AnswerImagemap($answertext, $points, $order, $coords, $area, -1, $points_unchecked);
528 for ($i = count($this->answers) - 1; $i >= $order; $i--)
529 {
530 $this->answers[$i+1] = $this->answers[$i];
531 $this->answers[$i+1]->setOrder($i+1);
532 }
533 $this->answers[$order] = $answer;
534 }
535 else
536 {
537 // Append answer
538 $answer = new ASS_AnswerImagemap($answertext, $points, count($this->answers), $coords, $area, -1, $points_unchecked);
539 array_push($this->answers, $answer);
540 }
541 }
542
552 function getAnswerCount() {
553 return count($this->answers);
554 }
555
567 function getAnswer($index = 0) {
568 if ($index < 0) return NULL;
569 if (count($this->answers) < 1) return NULL;
570 if ($index >= count($this->answers)) return NULL;
571 return $this->answers[$index];
572 }
573
583 function &getAnswers()
584 {
585 return $this->answers;
586 }
587
598 function deleteArea($index = 0)
599 {
600 if ($index < 0) return;
601 if (count($this->answers) < 1) return;
602 if ($index >= count($this->answers)) return;
603 unset($this->answers[$index]);
604 $this->answers = array_values($this->answers);
605 for ($i = 0; $i < count($this->answers); $i++) {
606 if ($this->answers[$i]->getOrder() > $index) {
607 $this->answers[$i]->setOrder($i);
608 }
609 }
610 }
611
620 function flushAnswers() {
621 $this->answers = array();
622 }
623
632 function getMaximumPoints() {
633 $points = 0;
634 foreach ($this->answers as $key => $value) {
635 if($this->is_multiple_choice)
636 {
637 if($value->getPoints() > $value->getPointsUnchecked())
638 {
639 $points += $value->getPoints();
640 }
641 else
642 {
643 $points += $value->getPointsUnchecked();
644 }
645 }
646 else
647 {
648 if($value->getPoints() > $points)
649 {
650 $points = $value->getPoints();
651 }
652 }
653 }
654 return $points;
655 }
656
667 public function calculateReachedPoints($active_id, $pass = NULL, $authorizedSolution = true, $returndetails = FALSE)
668 {
669 if( $returndetails )
670 {
671 throw new ilTestException('return details not implemented for '.__METHOD__);
672 }
673
674 global $ilDB;
675
676 $found_values = array();
677 if (is_null($pass))
678 {
679 $pass = $this->getSolutionMaxPass($active_id);
680 }
681 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorizedSolution);
682 while ($data = $ilDB->fetchAssoc($result))
683 {
684 if (strcmp($data["value1"], "") != 0)
685 {
686 array_push($found_values, $data["value1"]);
687 }
688 }
689
690 $points = $this->calculateReachedPointsForSolution($found_values);
691
692 return $points;
693 }
694
696 {
697 $solutionData = $previewSession->getParticipantsSolution();
698 return $this->calculateReachedPointsForSolution(is_array($solutionData) ? array_values($solutionData) : array());
699 }
700
701 public function isAutosaveable()
702 {
703 return false; // #15217
704 }
705
714 public function saveWorkingData($active_id, $pass = NULL, $authorized = true)
715 {
716 global $ilDB;
717
718 if (is_null($pass))
719 {
720 include_once "./Modules/Test/classes/class.ilObjTest.php";
721 $pass = ilObjTest::_getPass($active_id);
722 }
723
724 $this->getProcessLocker()->requestUserSolutionUpdateLock();
725
726 if(!$authorized)
727 {
728
729 $solutions = $this->getSolutionValues($active_id, $pass, false);
730 if(0 == count($solutions))
731 {
732 $solutions = $this->getSolutionValues($active_id, $pass, true);
733 $this->removeCurrentSolution($active_id, $pass, true);
734 $this->removeCurrentSolution($active_id, $pass, false);
735 foreach($solutions as $solution)
736 {
737 $this->saveCurrentSolution($active_id, $pass, $solution['value1'], null, false);
738 }
739 }
740
741 if($this->is_multiple_choice && strlen($_GET['remImage']))
742 {
743 $query = "DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s AND value1 = %s AND authorized = %s";
744 $types = array("integer", "integer", "integer", "integer", 'integer');
745 $values = array($active_id, $this->getId(), $pass, $_GET['remImage'], (int)$authorized);
746
747 if($this->getStep() !== NULL)
748 {
749 $query .= " AND step = %s ";
750 $types[] = 'integer';
751 $values[] = $this->getStep();
752 }
753 $ilDB->manipulateF($query, $types, $values);
754 }
755 elseif(!$this->is_multiple_choice)
756 {
757 $this->removeCurrentSolution($active_id, $pass, $authorized);
758 }
759
760 if(!$authorized && strlen($_GET["selImage"]))
761 {
762 $imageWasSelected = true;
763
764 $types = array('integer', 'integer', 'integer', 'integer', 'integer');
765 $values = array($active_id, $this->getId(), $pass, (int)$_GET['selImage'], (int)$authorized);
766 $query = 'DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s AND value1 = %s AND authorized = %s';
767 if($this->getStep() != null)
768 {
769 $types[] = 'integer';
770 $values[] = $this->getStep();
771 $query .= ' AND step = %s';
772 }
773
774 $ilDB->manipulateF($query, $types, $values);
775
776 $this->saveCurrentSolution($active_id, $pass, $_GET['selImage'], null, $authorized);
777 }
778 else
779 {
780 $imageWasSelected = false;
781 }
782 }
783 else
784 {
785 $solutions = $this->getUserSolutionPreferingIntermediate($active_id, $pass);
786 $this->removeCurrentSolution($active_id, $pass, true);
787 $this->removeCurrentSolution($active_id, $pass, false);
788 foreach($solutions as $solution)
789 {
790 $this->saveCurrentSolution($active_id, $pass, $solution['value1'], null, true);
791 }
792 }
793
794 $this->getProcessLocker()->releaseUserSolutionUpdateLock();
795
796 require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
798 {
799 if( $imageWasSelected )
800 {
801 $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
802 }
803 else
804 {
805 $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
806 }
807 }
808
809 return true;
810 }
811
812 protected function savePreviewData(ilAssQuestionPreviewSession $previewSession)
813 {
814 $solution = $previewSession->getParticipantsSolution();
815
816 if( $this->is_multiple_choice && strlen($_GET['remImage']) )
817 {
818 unset($solution[(int)$_GET['remImage']]);
819 }
820
821 if( strlen($_GET['selImage']) )
822 {
823 if( !$this->is_multiple_choice )
824 {
825 $solution = array();
826 }
827
828 $solution[(int)$_GET['selImage']] = (int)$_GET['selImage'];
829 }
830
831 $previewSession->setParticipantsSolution($solution);
832 }
833
842 protected function reworkWorkingData($active_id, $pass, $obligationsAnswered)
843 {
844 // nothing to rework!
845 }
846
848 {
849 if ($this->getOriginalId())
850 {
851 parent::syncWithOriginal();
852 }
853 }
854
864 {
865 return "assImagemapQuestion";
866 }
867
877 {
878 return "qpl_qst_imagemap";
879 }
880
890 {
891 return "qpl_a_imagemap";
892 }
893
899 {
900 $text = parent::getRTETextWithMediaObjects();
901 foreach ($this->answers as $index => $answer)
902 {
903 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), $index);
904 }
905 return $text;
906 }
907
920 public function setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
921 {
922 include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
923 $solution = $this->getSolutionValues($active_id, $pass);
924 $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
925 $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
926 $i = 1;
927 foreach ($this->getAnswers() as $id => $answer)
928 {
929 $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($answer->getArea() . ": " . $answer->getCoords()), $format_bold);
930 if ($id == $solution[0]["value1"])
931 {
932 $worksheet->write($startrow + $i, 1, 1);
933 }
934 else
935 {
936 $worksheet->write($startrow + $i, 1, 0);
937 }
938 $i++;
939 }
940 return $startrow + $i + 1;
941 }
942
946 public function deleteImage()
947 {
948 $file = $this->getImagePath() . $this->getImageFilename();
949 @unlink($file);
950 $this->flushAnswers();
951 $this->image_filename = "";
952 }
953
957 public function toJSON()
958 {
959 include_once("./Services/RTE/classes/class.ilRTE.php");
960 $result = array();
961 $result['id'] = (int) $this->getId();
962 $result['type'] = (string) $this->getQuestionType();
963 $result['title'] = (string) $this->getTitle();
964 $result['question'] = $this->formatSAQuestion($this->getQuestion());
965 $result['nr_of_tries'] = (int) $this->getNrOfTries();
966 $result['shuffle'] = (bool) $this->getShuffle();
967 $result['is_multiple'] = (bool) $this->getIsMultipleChoice();
968 $result['feedback'] = array(
969 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
970 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
971 );
972 $result['image'] = (string) $this->getImagePathWeb() . $this->getImageFilename();
973
974 $answers = array();
975 $order = 0;
976 foreach ($this->getAnswers() as $key => $answer_obj)
977 {
978 array_push($answers, array(
979 "answertext" => (string)$answer_obj->getAnswertext(),
980 "points" => (float)$answer_obj->getPoints(),
981 "points_unchecked" => (float)$answer_obj->getPointsUnchecked(),
982 "order" => (int)$order,
983 "coords" => $answer_obj->getCoords(),
984 "state" => $answer_obj->getState(),
985 "area" => $answer_obj->getArea(),
986 "feedback" => $this->formatSAQuestion(
987 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key)
988 )
989 ));
990 $order++;
991 }
992 $result['answers'] = $answers;
993
994 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
995 $result['mobs'] = $mobs;
996
997 return json_encode($result);
998 }
999
1004 protected function calculateReachedPointsForSolution($found_values)
1005 {
1006 $points = 0;
1007 if(count($found_values) > 0)
1008 {
1009 foreach($this->answers as $key => $answer)
1010 {
1011 if(in_array($key, $found_values))
1012 {
1013 $points += $answer->getPoints();
1014 } elseif($this->getIsMultipleChoice())
1015 {
1016 $points += $answer->getPointsUnchecked();
1017 }
1018 }
1019 return $points;
1020 }
1021 return $points;
1022 }
1023
1032 public function getOperators($expression)
1033 {
1034 require_once "./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
1036 }
1037
1042 public function getExpressionTypes()
1043 {
1044 return array(
1049 );
1050 }
1051
1060 public function getUserQuestionResult($active_id, $pass)
1061 {
1063 global $ilDB;
1064 $result = new ilUserQuestionResult($this, $active_id, $pass);
1065
1066 $maxStep = $this->lookupMaxStep($active_id, $pass);
1067
1068 if( $maxStep !== null )
1069 {
1070 $data = $ilDB->queryF("SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1071 array("integer", "integer", "integer", "integer"),
1072 array($active_id, $pass, $this->getId(), $maxStep)
1073 );
1074 }
1075 else
1076 {
1077 $data = $ilDB->queryF("SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step IS NULL",
1078 array("integer", "integer", "integer"),
1079 array($active_id, $pass, $this->getId())
1080 );
1081 }
1082
1083 while($row = $ilDB->fetchAssoc($data))
1084 {
1085 $result->addKeyValue($row["value1"], $row["value1"]);
1086 }
1087
1088 $points = $this->calculateReachedPoints($active_id, $pass);
1089 $max_points = $this->getMaximumPoints();
1090
1091 $result->setReachedPercentage(($points/$max_points) * 100);
1092
1093 return $result;
1094 }
1095
1104 public function getAvailableAnswerOptions($index = null)
1105 {
1106 if($index !== null)
1107 {
1108 return $this->getAnswer($index);
1109 }
1110 else
1111 {
1112 return $this->getAnswers();
1113 }
1114 }
1115}
$result
print $file
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
Class for true/false or yes/no answers.
Class for image map questions.
uploadImagemap($imagemap_filename="")
Uploads an image map and takes over the areas.
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.
flushAnswers()
Deletes all answers.
calculateReachedPointsFromPreviewSession(ilAssQuestionPreviewSession $previewSession)
toJSON()
Returns a JSON representation of the question.
setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
Creates an Excel worksheet for the detailed cumulated results of this question.
duplicateImage($question_id, $objectId=null)
setImageFilename($image_filename, $image_tempfilename="")
Sets the image file name.
getAnswer($index=0)
Returns an answer.
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.
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.
saveWorkingData($active_id, $pass=NULL, $authorized=true)
Saves the learners input of the question to the database.
calculateReachedPoints($active_id, $pass=NULL, $authorizedSolution=true, $returndetails=FALSE)
Returns the points, a learner has reached answering the question.
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.
reworkWorkingData($active_id, $pass, $obligationsAnswered)
Reworks the allready saved working data if neccessary.
getIsMultipleChoice()
Returns true, if the imagemap question is a multiplechoice question.
savePreviewData(ilAssQuestionPreviewSession $previewSession)
Reworks the allready saved working data if neccessary.
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.
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="")
getUserSolutionPreferingIntermediate($active_id, $pass=NULL)
getId()
Gets the id of the assQuestion object.
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.
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
setAuthor($author="")
Sets the authors name of the assQuestion object.
getSolutionValues($active_id, $pass=NULL, $authorized=true)
Loads solutions of a given user from the database an returns it.
getShuffle()
Gets the shuffle flag.
logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
removeCurrentSolution($active_id, $pass, $authorized=true, $ignoredSolutionIds=array())
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
saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized=true)
setQuestion($question="")
Sets the question string of the question object.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
_convert_text($a_text, $a_target="has been removed")
_getLogLanguage()
retrieve the log language for assessment logging
_enabledAssessmentLogging()
check wether assessment logging is enabled or not
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
_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.
$data
$text
if(! $in) print
Class iQuestionCondition.
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
Interface ilObjAnswerScoringAdjustable.
Interface ilObjQuestionScoringAdjustable.
redirection script todo: (a better solution should control the processing via a xml file)
global $ilDB
$mobs