ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
5 require_once './Modules/Test/classes/inc.AssessmentConstants.php';
6 require_once './Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
7 require_once './Modules/TestQuestionPool/interfaces/interface.ilObjAnswerScoringAdjustable.php';
8 require_once './Modules/TestQuestionPool/interfaces/interface.iQuestionCondition.php';
9 require_once './Modules/TestQuestionPool/classes/class.ilUserQuestionResult.php';
10 
25 {
26  // hey: prevPassSolutions - wtf is imagemap ^^
27  public $currentSolution = array();
28  // hey.
29 
30  const MODE_SINGLE_CHOICE = 0;
32 
34  public $answers;
35 
38 
41 
43  public $coords;
44 
46  protected $is_multiple_choice = false;
47 
62  public function __construct(
63  $title = "",
64  $comment = "",
65  $author = "",
66  $owner = -1,
67  $question = "",
68  $image_filename = ""
69  ) {
70  parent::__construct($title, $comment, $author, $owner, $question);
71  $this->image_filename = $image_filename;
72  $this->answers = array();
73  $this->coords = array();
74  }
75 
82  {
83  $this->is_multiple_choice = $is_multiple_choice;
84  }
85 
91  public function getIsMultipleChoice()
92  {
94  }
95 
102  public function isComplete()
103  {
104  if (strlen($this->title)
105  && ($this->author)
106  && ($this->question)
107  && ($this->image_filename)
108  && (count($this->answers))
109  && ($this->getMaximumPoints() > 0)
110  ) {
111  return true;
112  }
113  return false;
114  }
115 
125  public function saveToDb($original_id = "")
126  {
130  parent::saveToDb($original_id);
131  }
132 
133  public function saveAnswerSpecificDataToDb()
134  {
135  global $ilDB;
136  $ilDB->manipulateF(
137  "DELETE FROM qpl_a_imagemap WHERE question_fi = %s",
138  array( "integer" ),
139  array( $this->getId() )
140  );
141 
142  // Anworten wegschreiben
143  foreach ($this->answers as $key => $value) {
144  $answer_obj = $this->answers[$key];
145  $next_id = $ilDB->nextId('qpl_a_imagemap');
146  $ilDB->manipulateF(
147  "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)",
148  array( "integer", "integer", "text", "float", "integer", "text", "text", "float" ),
149  array( $next_id, $this->id, $answer_obj->getAnswertext(
150  ), $answer_obj->getPoints(), $answer_obj->getOrder(
151  ), $answer_obj->getCoords(), $answer_obj->getArea(
152  ), $answer_obj->getPointsUnchecked() )
153  );
154  }
155  }
156 
158  {
159  global $ilDB;
160 
161  $ilDB->manipulateF(
162  "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
163  array( "integer" ),
164  array( $this->getId() )
165  );
166 
167  $ilDB->manipulateF(
168  "INSERT INTO " . $this->getAdditionalTableName(
169  ) . " (question_fi, image_file, is_multiple_choice) VALUES (%s, %s, %s)",
170  array( "integer", "text", 'integer' ),
171  array(
172  $this->getId(),
173  $this->image_filename,
174  (int) $this->is_multiple_choice
175  )
176  );
177  }
178 
184  public function duplicate($for_test = true, $title = "", $author = "", $owner = "", $testObjId = null)
185  {
186  if ($this->id <= 0) {
187  // The question has not been saved. It cannot be duplicated
188  return;
189  }
190  // duplicate the question in database
191  $this_id = $this->getId();
192  $thisObjId = $this->getObjId();
193 
194  $clone = $this;
195  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
197  $clone->id = -1;
198 
199  if ((int) $testObjId > 0) {
200  $clone->setObjId($testObjId);
201  }
202 
203  if ($title) {
204  $clone->setTitle($title);
205  }
206  if ($author) {
207  $clone->setAuthor($author);
208  }
209  if ($owner) {
210  $clone->setOwner($owner);
211  }
212  if ($for_test) {
213  $clone->saveToDb($original_id);
214  } else {
215  $clone->saveToDb();
216  }
217 
218  // copy question page content
219  $clone->copyPageOfQuestion($this_id);
220  // copy XHTML media objects
221  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
222  // duplicate the image
223  $clone->duplicateImage($this_id, $thisObjId);
224 
225  $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
226 
227  return $clone->id;
228  }
229 
237  public function copyObject($target_questionpool_id, $title = "")
238  {
239  if ($this->id <= 0) {
240  // The question has not been saved. It cannot be duplicated
241  return;
242  }
243  // duplicate the question in database
244  $clone = $this;
245  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
247  $clone->id = -1;
248  $source_questionpool_id = $this->getObjId();
249  $clone->setObjId($target_questionpool_id);
250  if ($title) {
251  $clone->setTitle($title);
252  }
253  $clone->saveToDb();
254 
255  // copy question page content
256  $clone->copyPageOfQuestion($original_id);
257  // copy XHTML media objects
258  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
259  // duplicate the image
260  $clone->copyImage($original_id, $source_questionpool_id);
261 
262  $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
263 
264  return $clone->id;
265  }
266 
267  public function createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle = "")
268  {
269  if ($this->id <= 0) {
270  // The question has not been saved. It cannot be duplicated
271  return;
272  }
273 
274  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
275 
276  $sourceQuestionId = $this->id;
277  $sourceParentId = $this->getObjId();
278 
279  // duplicate the question in database
280  $clone = $this;
281  $clone->id = -1;
282 
283  $clone->setObjId($targetParentId);
284 
285  if ($targetQuestionTitle) {
286  $clone->setTitle($targetQuestionTitle);
287  }
288 
289  $clone->saveToDb();
290  // copy question page content
291  $clone->copyPageOfQuestion($sourceQuestionId);
292  // copy XHTML media objects
293  $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
294  // duplicate the image
295  $clone->copyImage($sourceQuestionId, $sourceParentId);
296 
297  $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
298 
299  return $clone->id;
300  }
301 
302  public function duplicateImage($question_id, $objectId = null)
303  {
304  global $ilLog;
305 
306  $imagepath = $this->getImagePath();
307  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
308 
309  if ((int) $objectId > 0) {
310  $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
311  }
312 
313  if (!file_exists($imagepath)) {
314  ilUtil::makeDirParents($imagepath);
315  }
316  $filename = $this->getImageFilename();
317 
318  // #18755
319  if (!file_exists($imagepath_original . $filename)) {
320  $ilLog->write("Could not find an image map file when trying to duplicate image: " . $imagepath_original . $filename);
321  $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
322  $ilLog->write("Using fallback source directory:" . $imagepath_original);
323  }
324 
325  if (!file_exists($imagepath_original . $filename) || !copy($imagepath_original . $filename, $imagepath . $filename)) {
326  $ilLog->write("Could not duplicate image for image map question: " . $imagepath_original . $filename);
327  }
328  }
329 
330  public function copyImage($question_id, $source_questionpool)
331  {
332  $imagepath = $this->getImagePath();
333  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
334  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
335  if (!file_exists($imagepath)) {
336  ilUtil::makeDirParents($imagepath);
337  }
338  $filename = $this->getImageFilename();
339  if (!copy($imagepath_original . $filename, $imagepath . $filename)) {
340  print "image could not be copied!!!! ";
341  }
342  }
343 
353  public function loadFromDb($question_id)
354  {
355  global $ilDB;
356 
357  $result = $ilDB->queryF(
358  "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",
359  array("integer"),
360  array($question_id)
361  );
362  if ($result->numRows() == 1) {
363  $data = $ilDB->fetchAssoc($result);
364  $this->setId($question_id);
365  $this->setObjId($data["obj_fi"]);
366  $this->setTitle($data["title"]);
367  $this->setComment($data["description"]);
368  $this->setOriginalId($data["original_id"]);
369  $this->setNrOfTries($data['nr_of_tries']);
370  $this->setAuthor($data["author"]);
371  $this->setPoints($data["points"]);
372  $this->setOwner($data["owner"]);
373  $this->setIsMultipleChoice($data["is_multiple_choice"] == self::MODE_MULTIPLE_CHOICE);
374  include_once("./Services/RTE/classes/class.ilRTE.php");
375  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
376  $this->setImageFilename($data["image_file"]);
377  $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
378 
379  try {
380  $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
381  } catch (ilTestQuestionPoolException $e) {
382  }
383 
384  $result = $ilDB->queryF(
385  "SELECT * FROM qpl_a_imagemap WHERE question_fi = %s ORDER BY aorder ASC",
386  array("integer"),
387  array($question_id)
388  );
389  include_once "./Modules/TestQuestionPool/classes/class.assAnswerImagemap.php";
390  if ($result->numRows() > 0) {
391  while ($data = $ilDB->fetchAssoc($result)) {
392  array_push($this->answers, new ASS_AnswerImagemap($data["answertext"], $data["points"], $data["aorder"], $data["coords"], $data["area"], $data['question_fi'], $data['points_unchecked']));
393  }
394  }
395  }
396  parent::loadFromDb($question_id);
397  }
398 
405  public function uploadImagemap(array $shapes)
406  {
407  $added = 0;
408 
409  if (count($shapes) > 0) {
410  foreach ($shapes as $shape) {
411  $this->addAnswer($shape->getAnswertext(), 0.0, count($this->answers), $shape->getCoords(), $shape->getArea());
412  $added++;
413  }
414  }
415 
416  return $added;
417  }
418 
419  public function getImageFilename()
420  {
421  return $this->image_filename;
422  }
423 
431  public function setImageFilename($image_filename, $image_tempfilename = "")
432  {
433  if (!empty($image_filename)) {
434  $image_filename = str_replace(" ", "_", $image_filename);
435  $this->image_filename = $image_filename;
436  }
437  if (!empty($image_tempfilename)) {
438  $imagepath = $this->getImagePath();
439  if (!file_exists($imagepath)) {
440  ilUtil::makeDirParents($imagepath);
441  }
442  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) {
443  $this->ilias->raiseError("The image could not be uploaded!", $this->ilias->error_obj->MESSAGE);
444  }
445  global $ilLog;
446  $ilLog->write("gespeichert: " . $imagepath . $image_filename);
447  }
448  }
449 
459  public function get_imagemap_contents($href = "#")
460  {
461  $imagemap_contents = "<map name=\"" . $this->title . "\"> ";
462  for ($i = 0; $i < count($this->answers); $i++) {
463  $imagemap_contents .= "<area alt=\"" . $this->answers[$i]->getAnswertext() . "\" ";
464  $imagemap_contents .= "shape=\"" . $this->answers[$i]->getArea() . "\" ";
465  $imagemap_contents .= "coords=\"" . $this->answers[$i]->getCoords() . "\" ";
466  $imagemap_contents .= "href=\"$href&selimage=" . $this->answers[$i]->getOrder() . "\" /> ";
467  }
468  $imagemap_contents .= "</map>";
469  return $imagemap_contents;
470  }
471 
486  public function addAnswer(
487  $answertext = "",
488  $points = 0.0,
489  $order = 0,
490  $coords="",
491  $area="",
492  $points_unchecked = 0.0
493  ) {
494  include_once "./Modules/TestQuestionPool/classes/class.assAnswerImagemap.php";
495  if (array_key_exists($order, $this->answers)) {
496  // Insert answer
497  $answer = new ASS_AnswerImagemap($answertext, $points, $order, $coords, $area, -1, $points_unchecked);
498  for ($i = count($this->answers) - 1; $i >= $order; $i--) {
499  $this->answers[$i+1] = $this->answers[$i];
500  $this->answers[$i+1]->setOrder($i+1);
501  }
502  $this->answers[$order] = $answer;
503  } else {
504  // Append answer
505  $answer = new ASS_AnswerImagemap($answertext, $points, count($this->answers), $coords, $area, -1, $points_unchecked);
506  array_push($this->answers, $answer);
507  }
508  }
509 
519  public function getAnswerCount()
520  {
521  return count($this->answers);
522  }
523 
535  public function getAnswer($index = 0)
536  {
537  if ($index < 0) {
538  return null;
539  }
540  if (count($this->answers) < 1) {
541  return null;
542  }
543  if ($index >= count($this->answers)) {
544  return null;
545  }
546  return $this->answers[$index];
547  }
548 
558  public function &getAnswers()
559  {
560  return $this->answers;
561  }
562 
573  public function deleteArea($index = 0)
574  {
575  if ($index < 0) {
576  return;
577  }
578  if (count($this->answers) < 1) {
579  return;
580  }
581  if ($index >= count($this->answers)) {
582  return;
583  }
584  unset($this->answers[$index]);
585  $this->answers = array_values($this->answers);
586  for ($i = 0; $i < count($this->answers); $i++) {
587  if ($this->answers[$i]->getOrder() > $index) {
588  $this->answers[$i]->setOrder($i);
589  }
590  }
591  }
592 
601  public function flushAnswers()
602  {
603  $this->answers = array();
604  }
605 
614  public function getMaximumPoints()
615  {
616  $points = 0;
617  foreach ($this->answers as $key => $value) {
618  if ($this->is_multiple_choice) {
619  if ($value->getPoints() > $value->getPointsUnchecked()) {
620  $points += $value->getPoints();
621  } else {
622  $points += $value->getPointsUnchecked();
623  }
624  } else {
625  if ($value->getPoints() > $points) {
626  $points = $value->getPoints();
627  }
628  }
629  }
630  return $points;
631  }
632 
643  public function calculateReachedPoints($active_id, $pass = null, $authorizedSolution = true, $returndetails = false)
644  {
645  if ($returndetails) {
646  throw new ilTestException('return details not implemented for ' . __METHOD__);
647  }
648 
649  global $ilDB;
650 
651  $found_values = array();
652  if (is_null($pass)) {
653  $pass = $this->getSolutionMaxPass($active_id);
654  }
655  $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorizedSolution);
656  while ($data = $ilDB->fetchAssoc($result)) {
657  if (strcmp($data["value1"], "") != 0) {
658  array_push($found_values, $data["value1"]);
659  }
660  }
661 
662  $points = $this->calculateReachedPointsForSolution($found_values);
663 
664  return $points;
665  }
666 
668  {
669  $solutionData = $previewSession->getParticipantsSolution();
670 
671  $reachedPoints = $this->calculateReachedPointsForSolution(is_array($solutionData) ? array_values($solutionData) : array());
672  $reachedPoints = $this->deductHintPointsFromReachedPoints($previewSession, $reachedPoints);
673 
674  return $this->ensureNonNegativePoints($reachedPoints);
675  }
676 
677  public function isAutosaveable()
678  {
679  return false; // #15217
680  }
681 
690  public function saveWorkingData($active_id, $pass = null, $authorized = true)
691  {
692  global $ilDB;
693 
694  if (is_null($pass)) {
695  include_once "./Modules/Test/classes/class.ilObjTest.php";
696  $pass = ilObjTest::_getPass($active_id);
697  }
698 
699  $solutionSelectionChanged = false;
700 
701  $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(function () use (&$solutionSelectionChanged, $ilDB, $active_id, $pass, $authorized) {
702  if ($authorized) {
703  // remove the dummy record of the intermediate solution
704  $this->deleteDummySolutionRecord($active_id, $pass);
705 
706  // delete the authorized solution and make the intermediate solution authorized (keeping timestamps)
707  $this->removeCurrentSolution($active_id, $pass, true);
708  $this->updateCurrentSolutionsAuthorization($active_id, $pass, true, true);
709 
710  $solutionSelectionChanged = true;
711  } else {
713  $active_id,
714  $pass,
715  $this->is_multiple_choice
716  );
717 
718  if ($this->isReuseSolutionSelectionRequest()) {
719  $selection = $this->getReuseSolutionSelectionParameter();
720 
721  foreach ($selection as $selectedIndex) {
722  $this->saveCurrentSolution($active_id, $pass, (int) $selectedIndex, null, $authorized);
723  $solutionSelectionChanged = true;
724  }
725  } elseif ($this->isRemoveSolutionSelectionRequest()) {
726  $selection = $this->getRemoveSolutionSelectionParameter();
727 
728  $this->deleteSolutionRecordByValues($active_id, $pass, $authorized, array(
729  'value1' => (int) $selection
730  ));
731 
732  $solutionSelectionChanged = true;
733  } elseif ($this->isAddSolutionSelectionRequest()) {
734  $selection = $this->getAddSolutionSelectionParameter();
735 
736  if ($this->is_multiple_choice) {
737  $this->deleteSolutionRecordByValues($active_id, $pass, $authorized, array(
738  'value1' => (int) $_GET['selImage']
739  ));
740  } else {
741  $this->removeCurrentSolution($active_id, $pass, $authorized);
742  }
743 
744  $this->saveCurrentSolution($active_id, $pass, $_GET['selImage'], null, $authorized);
745 
746  $solutionSelectionChanged = true;
747  }
748  }
749  });
750 
751  require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
753  if ($solutionSelectionChanged) {
754  assQuestion::logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
755  } else {
756  assQuestion::logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
757  }
758  }
759 
760  return true;
761  }
762 
763  protected function savePreviewData(ilAssQuestionPreviewSession $previewSession)
764  {
765  $solution = $previewSession->getParticipantsSolution();
766 
767  if ($this->is_multiple_choice && strlen($_GET['remImage'])) {
768  unset($solution[(int) $_GET['remImage']]);
769  }
770 
771  if (strlen($_GET['selImage'])) {
772  if (!$this->is_multiple_choice) {
773  $solution = array();
774  }
775 
776  $solution[(int) $_GET['selImage']] = (int) $_GET['selImage'];
777  }
778 
779  $previewSession->setParticipantsSolution($solution);
780  }
781 
785  protected function reworkWorkingData($active_id, $pass, $obligationsAnswered, $authorized)
786  {
787  // nothing to rework!
788  }
789 
790  public function syncWithOriginal()
791  {
792  if ($this->getOriginalId()) {
793  parent::syncWithOriginal();
794  }
795  }
796 
805  public function getQuestionType()
806  {
807  return "assImagemapQuestion";
808  }
809 
818  public function getAdditionalTableName()
819  {
820  return "qpl_qst_imagemap";
821  }
822 
831  public function getAnswerTableName()
832  {
833  return "qpl_a_imagemap";
834  }
835 
840  public function getRTETextWithMediaObjects()
841  {
842  $text = parent::getRTETextWithMediaObjects();
843  foreach ($this->answers as $index => $answer) {
844  $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), $index);
845  }
846  return $text;
847  }
848 
852  public function setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
853  {
854  parent::setExportDetailsXLS($worksheet, $startrow, $active_id, $pass);
855 
856  $solution = $this->getSolutionValues($active_id, $pass);
857 
858  $i = 1;
859  foreach ($this->getAnswers() as $id => $answer) {
860  $worksheet->setCell($startrow + $i, 0, $answer->getArea() . ": " . $answer->getCoords());
861  $worksheet->setBold($worksheet->getColumnCoord(0) . ($startrow + $i));
862 
863  $cellValue = 0;
864  foreach ($solution as $solIndex => $sol) {
865  if ($sol['value1'] == $id) {
866  $cellValue = 1;
867  break;
868  }
869  }
870 
871  $worksheet->setCell($startrow + $i, 1, $cellValue);
872 
873  $i++;
874  }
875 
876  return $startrow + $i + 1;
877  }
878 
882  public function deleteImage()
883  {
884  $file = $this->getImagePath() . $this->getImageFilename();
885  @unlink($file);
886  $this->flushAnswers();
887  $this->image_filename = "";
888  }
889 
893  public function toJSON()
894  {
895  include_once("./Services/RTE/classes/class.ilRTE.php");
896  $result = array();
897  $result['id'] = (int) $this->getId();
898  $result['type'] = (string) $this->getQuestionType();
899  $result['title'] = (string) $this->getTitle();
900  $result['question'] = $this->formatSAQuestion($this->getQuestion());
901  $result['nr_of_tries'] = (int) $this->getNrOfTries();
902  $result['shuffle'] = (bool) $this->getShuffle();
903  $result['is_multiple'] = (bool) $this->getIsMultipleChoice();
904  $result['feedback'] = array(
905  'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
906  'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
907  );
908  $result['image'] = (string) $this->getImagePathWeb() . $this->getImageFilename();
909 
910  $answers = array();
911  $order = 0;
912  foreach ($this->getAnswers() as $key => $answer_obj) {
913  array_push($answers, array(
914  "answertext" => (string) $answer_obj->getAnswertext(),
915  "points" => (float) $answer_obj->getPoints(),
916  "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
917  "order" => (int) $order,
918  "coords" => $answer_obj->getCoords(),
919  "state" => $answer_obj->getState(),
920  "area" => $answer_obj->getArea(),
921  "feedback" => $this->formatSAQuestion(
922  $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key)
923  )
924  ));
925  $order++;
926  }
927  $result['answers'] = $answers;
928 
929  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
930  $result['mobs'] = $mobs;
931 
932  return json_encode($result);
933  }
934 
939  protected function calculateReachedPointsForSolution($found_values)
940  {
941  $points = 0;
942  if (count($found_values) > 0) {
943  foreach ($this->answers as $key => $answer) {
944  if (in_array($key, $found_values)) {
945  $points += $answer->getPoints();
946  } elseif ($this->getIsMultipleChoice()) {
947  $points += $answer->getPointsUnchecked();
948  }
949  }
950  return $points;
951  }
952  return $points;
953  }
954 
963  public function getOperators($expression)
964  {
965  require_once "./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
967  }
968 
973  public function getExpressionTypes()
974  {
975  return array(
980  );
981  }
982 
991  public function getUserQuestionResult($active_id, $pass)
992  {
994  global $ilDB;
995  $result = new ilUserQuestionResult($this, $active_id, $pass);
996 
997  $maxStep = $this->lookupMaxStep($active_id, $pass);
998 
999  if ($maxStep !== null) {
1000  $data = $ilDB->queryF(
1001  "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1002  array("integer", "integer", "integer", "integer"),
1003  array($active_id, $pass, $this->getId(), $maxStep)
1004  );
1005  } else {
1006  $data = $ilDB->queryF(
1007  "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step IS NULL",
1008  array("integer", "integer", "integer"),
1009  array($active_id, $pass, $this->getId())
1010  );
1011  }
1012 
1013  while ($row = $ilDB->fetchAssoc($data)) {
1014  $result->addKeyValue($row["value1"], $row["value1"]);
1015  }
1016 
1017  $points = $this->calculateReachedPoints($active_id, $pass);
1018  $max_points = $this->getMaximumPoints();
1019 
1020  $result->setReachedPercentage(($points/$max_points) * 100);
1021 
1022  return $result;
1023  }
1024 
1033  public function getAvailableAnswerOptions($index = null)
1034  {
1035  if ($index !== null) {
1036  return $this->getAnswer($index);
1037  } else {
1038  return $this->getAnswers();
1039  }
1040  }
1041 
1042  // hey: prevPassSolutions - wtf is imagemap ^^
1043  public function getTestOutputSolutions($activeId, $pass)
1044  {
1045  $solution = parent::getTestOutputSolutions($activeId, $pass);
1046 
1047  $this->currentSolution = array();
1048  foreach ($solution as $record) {
1049  $this->currentSolution[] = $record['value1'];
1050  }
1051 
1052  return $solution;
1053  }
1055  {
1056  if (!$this->isAddSolutionSelectionRequest()) {
1057  return null;
1058  }
1059 
1060  return $_GET["selImage"];
1061  }
1062  protected function isAddSolutionSelectionRequest()
1063  {
1064  if (!isset($_GET["selImage"])) {
1065  return false;
1066  }
1067 
1068  if (!strlen($_GET["selImage"])) {
1069  return false;
1070  }
1071 
1072  return true;
1073  }
1075  {
1076  if (!$this->isRemoveSolutionSelectionRequest()) {
1077  return null;
1078  }
1079 
1080  return $_GET["remImage"];
1081  }
1083  {
1084  if (!$this->is_multiple_choice) {
1085  return false;
1086  }
1087 
1088  if (!isset($_GET["remImage"])) {
1089  return false;
1090  }
1091 
1092  if (!strlen($_GET["remImage"])) {
1093  return false;
1094  }
1095 
1096  return true;
1097  }
1099  {
1100  if (!$this->isReuseSolutionSelectionRequest()) {
1101  return null;
1102  }
1103 
1104  return assQuestion::explodeKeyValues($_GET["reuseSelection"]);
1105  }
1106  protected function isReuseSolutionSelectionRequest()
1107  {
1108  if (!$this->getTestPresentationConfig()->isPreviousPassSolutionReuseAllowed()) {
1109  return false;
1110  }
1111 
1112  if (!isset($_GET["reuseSelection"])) {
1113  return false;
1114  }
1115 
1116  if (!strlen($_GET["reuseSelection"])) {
1117  return false;
1118  }
1119 
1120  if (!preg_match('/\d(,\d)*/', $_GET["reuseSelection"])) {
1121  return false;
1122  }
1123 
1124  return true;
1125  }
1126  // hey.
1127 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
getId()
Gets the id of the assQuestion object.
Add rich text string
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _getOriginalId($question_id)
Returns the original id of a question.
formatSAQuestion($a_q)
Format self assessment question.
calculateReachedPointsForSolution($found_values)
$worksheet
Class iQuestionCondition.
forceExistingIntermediateSolution($activeId, $passIndex, $considerDummyRecordCreation)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
$result
savePreviewData(ilAssQuestionPreviewSession $previewSession)
$_GET["client_id"]
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
Duplicates an assImagemapQuestion.
Class for true/false or yes/no answers.
Abstract basic class which is to be extended by the concrete assessment question type classes...
getOperators($expression)
Get all available operations for a specific question.
ensureNonNegativePoints($points)
deleteDummySolutionRecord($activeId, $passIndex)
__construct( $title="", $comment="", $author="", $owner=-1, $question="", $image_filename="")
assImagemapQuestion constructor
getSolutionValues($active_id, $pass=null, $authorized=true)
Loads solutions of a given user from the database an returns it.
setId($id=-1)
Sets the id of the assQuestion object.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
Sets the estimated working time of a question from given hour, minute and second. ...
$index
Definition: metadata.php:60
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
deleteArea($index=0)
Deletes an answer.
setNrOfTries($a_nr_of_tries)
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
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...
getObjId()
Get the object id of the container object.
getShuffle()
Gets the shuffle flag.
Base Exception for all Exceptions relating to Modules/Test.
getIsMultipleChoice()
Returns true, if the imagemap question is a multiplechoice question.
static _getLogLanguage()
retrieve the log language for assessment logging
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
getTestOutputSolutions($activeId, $pass)
setAuthor($author="")
Sets the authors name of the assQuestion object.
static _enabledAssessmentLogging()
check wether assessment logging is enabled or not
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
getAnswer($index=0)
Returns an answer.
saveToDb($original_id="")
Saves an assImagemapQuestion object to a database.
uploadImagemap(array $shapes)
Uploads an image map and takes over the areas.
$mobs
toJSON()
Returns a JSON representation of the question.
Class ilUserQuestionResult.
updateCurrentSolutionsAuthorization($activeId, $pass, $authorized, $keepTime=false)
saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized=true, $tstamp=null)
static explodeKeyValues($keyValues)
$text
Definition: errorreport.php:18
Interface ilObjAnswerScoringAdjustable.
getQuestion()
Gets the question string of the question object.
deleteImage()
Deletes the image file.
redirection script todo: (a better solution should control the processing via a xml file) ...
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 ...
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
isComplete()
Returns true, if a imagemap question is complete for use.
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
copyImage($question_id, $source_questionpool)
Create styles array
The data for the language used.
reworkWorkingData($active_id, $pass, $obligationsAnswered, $authorized)
{}
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
duplicateImage($question_id, $objectId=null)
setIsMultipleChoice($is_multiple_choice)
Set true if the Imagemapquestion is a multiplechoice Question.
getExpressionTypes()
Get all available expression types for a specific question.
saveWorkingData($active_id, $pass=null, $authorized=true)
Saves the learners input of the question to the database.
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
setPoints($a_points)
Sets the maximum available points for the question.
saveQuestionDataToDb($original_id="")
addAnswer( $answertext="", $points=0.0, $order=0, $coords="", $area="", $points_unchecked=0.0)
Adds a possible answer for a imagemap question.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
& getAnswers()
Returns the answer array.
copyObject($target_questionpool_id, $title="")
Copies an assImagemapQuestion object.
getAnswerCount()
Returns the number of answers.
setQuestion($question="")
Sets the question string of the question object.
Interface ilObjQuestionScoringAdjustable.
removeCurrentSolution($active_id, $pass, $authorized=true)
setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
{}
deleteSolutionRecordByValues($activeId, $passIndex, $authorized, $matchValues)
getTestPresentationConfig()
Get the test question configuration (initialised once)
setImageFilename($image_filename, $image_tempfilename="")
Sets the image file name.
global $ilDB
setOriginalId($original_id)
getCurrentSolutionResultSet($active_id, $pass, $authorized=true)
Get a restulset for the current user solution for a this question by active_id and pass...
$i
Definition: disco.tpl.php:19
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
getAnswerTableName()
Returns the name of the answer table in the database.
getTitle()
Gets the title string of the assQuestion object.
getQuestionType()
Returns the question type of the question.
flushAnswers()
Deletes all answers.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
setTitle($title="")
Sets the title string of the assQuestion object.
setObjId($obj_id=0)
Set the object id of the container object.
calculateReachedPointsFromPreviewSession(ilAssQuestionPreviewSession $previewSession)
loadFromDb($question_id)
Loads a assImagemapQuestion object from a database.
$key
Definition: croninfo.php:18
setComment($comment="")
Sets the comment string of the assQuestion object.
get_imagemap_contents($href="#")
Gets the imagemap file contents.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.