ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assSingleChoice.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
6 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
7 
22 {
30  var $answers;
31 
41 
47  protected $thumb_size;
48 
63  function __construct(
64  $title = "",
65  $comment = "",
66  $author = "",
67  $owner = -1,
68  $question = "",
70  )
71  {
73  $this->thumb_size = 150;
74  $this->output_type = $output_type;
75  $this->answers = array();
76  $this->shuffle = 1;
77  }
78 
85  function isComplete()
86  {
87  if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
88  {
89  foreach ($this->answers as $answer)
90  {
91  if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) return false;
92  }
93  return true;
94  }
95  else
96  {
97  return false;
98  }
99  }
100 
107  function saveToDb($original_id = "")
108  {
109  global $ilDB;
110 
112 
113  $oldthumbsize = 0;
114  if ($this->isSingleline && ($this->getThumbSize()))
115  {
116  // get old thumbnail size
117  $result = $ilDB->queryF("SELECT thumb_size FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
118  array("integer"),
119  array($this->getId())
120  );
121  if ($result->numRows() == 1)
122  {
123  $data = $ilDB->fetchAssoc($result);
124  $oldthumbsize = $data['thumb_size'];
125  }
126  }
127  if (!$this->isSingleline)
128  {
129  ilUtil::delDir($this->getImagePath());
130  }
131 
132  // save additional data
133  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
134  array("integer"),
135  array($this->getId())
136  );
137 
138  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
139  array("integer", "text", "text", "integer"),
140  array(
141  $this->getId(),
142  $this->getShuffle(),
143  ($this->isSingleline) ? "0" : "1",
144  (strlen($this->getThumbSize()) == 0) ? null : $this->getThumbSize()
145  )
146  );
147 
148  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_sc WHERE question_fi = %s",
149  array('integer'),
150  array($this->getId())
151  );
152 
153  foreach ($this->answers as $key => $value)
154  {
155  $answer_obj = $this->answers[$key];
156  $next_id = $ilDB->nextId('qpl_a_sc');
157  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_sc (answer_id, question_fi, answertext, points, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
158  array('integer','integer','text','float','integer','text','integer'),
159  array(
160  $next_id,
161  $this->getId(),
162  ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0),
163  $answer_obj->getPoints(),
164  $answer_obj->getOrder(),
165  $answer_obj->getImage(),
166  time()
167  )
168  );
169  }
170 
171  $this->rebuildThumbnails();
172 
174  }
175 
176  /*
177  * Rebuild the thumbnail images with a new thumbnail size
178  */
179  protected function rebuildThumbnails()
180  {
181  if ($this->isSingleline && ($this->getThumbSize()))
182  {
183  foreach ($this->getAnswers() as $answer)
184  {
185  if (strlen($answer->getImage()))
186  {
187  $this->generateThumbForFile($this->getImagePath(), $answer->getImage());
188  }
189  }
190  }
191  }
192 
193  public function getThumbPrefix()
194  {
195  return "thumb.";
196  }
197 
198  protected function generateThumbForFile($path, $file)
199  {
200  $filename = $path . $file;
201  if (@file_exists($filename))
202  {
203  $thumbpath = $path . $this->getThumbPrefix() . $file;
204  $path_info = @pathinfo($filename);
205  $ext = "";
206  switch (strtoupper($path_info['extension']))
207  {
208  case 'PNG':
209  $ext = 'PNG';
210  break;
211  case 'GIF':
212  $ext = 'GIF';
213  break;
214  default:
215  $ext = 'JPEG';
216  break;
217  }
218  ilUtil::convertImage($filename, $thumbpath, $ext, $this->getThumbSize());
219  }
220  }
221 
229  function loadFromDb($question_id)
230  {
231  global $ilDB;
232 
233  $hasimages = 0;
234 
235  $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",
236  array("integer"),
237  array($question_id)
238  );
239  if ($result->numRows() == 1)
240  {
241  $data = $ilDB->fetchAssoc($result);
242  $this->setId($question_id);
243  $this->setObjId($data["obj_fi"]);
244  $this->setTitle($data["title"]);
245  $this->setNrOfTries($data['nr_of_tries']);
246  $this->setComment($data["description"]);
247  $this->setOriginalId($data["original_id"]);
248  $this->setAuthor($data["author"]);
249  $this->setPoints($data["points"]);
250  $this->setOwner($data["owner"]);
251  include_once("./Services/RTE/classes/class.ilRTE.php");
252  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
253  $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
254  $this->setShuffle($shuffle);
255  $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
256  $this->setThumbSize($data['thumb_size']);
257  $this->isSingleline = ($data['allow_images']) ? false : true;
258  $this->lastChange = $data['tstamp'];
259  }
260 
261  $result = $ilDB->queryF("SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
262  array('integer'),
263  array($question_id)
264  );
265  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
266  if ($result->numRows() > 0)
267  {
268  while ($data = $ilDB->fetchAssoc($result))
269  {
270  $imagefilename = $this->getImagePath() . $data["imagefile"];
271  if (!@file_exists($imagefilename))
272  {
273  $data["imagefile"] = "";
274  }
275  include_once("./Services/RTE/classes/class.ilRTE.php");
276  $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"], 1);
277  array_push($this->answers, new ASS_AnswerBinaryStateImage($data["answertext"], $data["points"], $data["aorder"], 1, $data["imagefile"]));
278  }
279  }
280 
281  parent::loadFromDb($question_id);
282  }
283 
289  function duplicate($for_test = true, $title = "", $author = "", $owner = "", $testObjId = null)
290  {
291  if ($this->id <= 0)
292  {
293  // The question has not been saved. It cannot be duplicated
294  return;
295  }
296  // duplicate the question in database
297  $this_id = $this->getId();
298 
299  if( (int)$testObjId > 0 )
300  {
301  $thisObjId = $this->getObjId();
302  }
303 
304  $clone = $this;
305  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
307  $clone->id = -1;
308 
309  if( (int)$testObjId > 0 )
310  {
311  $clone->setObjId($testObjId);
312  }
313 
314  if ($title)
315  {
316  $clone->setTitle($title);
317  }
318 
319  if ($author)
320  {
321  $clone->setAuthor($author);
322  }
323  if ($owner)
324  {
325  $clone->setOwner($owner);
326  }
327  if ($for_test)
328  {
329  $clone->saveToDb($original_id);
330  }
331  else
332  {
333  $clone->saveToDb();
334  }
335 
336  // copy question page content
337  $clone->copyPageOfQuestion($this_id);
338 
339  // copy XHTML media objects
340  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
341  // duplicate the images
342  $clone->duplicateImages($this_id, $thisObjId);
343  // duplicate the generic feedback
344  $clone->duplicateGenericFeedback($this_id);
345  // duplicate the answer specific feedback
346  $clone->duplicateFeedbackAnswer($this_id);
347 
348  $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
349 
350  return $clone->id;
351  }
352 
358  function copyObject($target_questionpool, $title = "")
359  {
360  if ($this->id <= 0)
361  {
362  // The question has not been saved. It cannot be duplicated
363  return;
364  }
365  // duplicate the question in database
366  $clone = $this;
367  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
369  $clone->id = -1;
370  $source_questionpool = $this->getObjId();
371  $clone->setObjId($target_questionpool);
372  if ($title)
373  {
374  $clone->setTitle($title);
375  }
376  $clone->saveToDb();
377  // copy question page content
378  $clone->copyPageOfQuestion($original_id);
379  // copy XHTML media objects
380  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
381  // duplicate the image
382  $clone->copyImages($original_id, $source_questionpool);
383  // duplicate the generic feedback
384  $clone->duplicateGenericFeedback($original_id);
385  // duplicate the answer specific feedback
386  $clone->duplicateFeedbackAnswer($original_id);
387  $clone->onCopy($this->getObjId(), $this->getId());
388 
389  return $clone->id;
390  }
391 
399  function getOutputType()
400  {
401  return $this->output_type;
402  }
403 
412  {
413  $this->output_type = $output_type;
414  }
415 
429  function addAnswer(
430  $answertext = "",
431  $points = 0.0,
432  $order = 0,
433  $answerimage = ""
434  )
435  {
436  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
437  if (array_key_exists($order, $this->answers))
438  {
439  // insert answer
440  $answer = new ASS_AnswerBinaryStateImage($answertext, $points, $order, 1, $answerimage);
441  $newchoices = array();
442  for ($i = 0; $i < $order; $i++)
443  {
444  array_push($newchoices, $this->answers[$i]);
445  }
446  array_push($newchoices, $answer);
447  for ($i = $order; $i < count($this->answers); $i++)
448  {
449  $changed = $this->answers[$i];
450  $changed->setOrder($i+1);
451  array_push($newchoices, $changed);
452  }
453  $this->answers = $newchoices;
454  }
455  else
456  {
457  // add answer
458  $answer = new ASS_AnswerBinaryStateImage($answertext, $points, count($this->answers), 1, $answerimage);
459  array_push($this->answers, $answer);
460  }
461  }
462 
470  function getAnswerCount()
471  {
472  return count($this->answers);
473  }
474 
484  function getAnswer($index = 0)
485  {
486  if ($index < 0) return NULL;
487  if (count($this->answers) < 1) return NULL;
488  if ($index >= count($this->answers)) return NULL;
489 
490  return $this->answers[$index];
491  }
492 
501  function deleteAnswer($index = 0)
502  {
503  if ($index < 0) return;
504  if (count($this->answers) < 1) return;
505  if ($index >= count($this->answers)) return;
506  $answer = $this->answers[$index];
507  if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
508  unset($this->answers[$index]);
509  $this->answers = array_values($this->answers);
510  for ($i = 0; $i < count($this->answers); $i++)
511  {
512  if ($this->answers[$i]->getOrder() > $index)
513  {
514  $this->answers[$i]->setOrder($i);
515  }
516  }
517  }
518 
525  function flushAnswers()
526  {
527  $this->answers = array();
528  }
529 
536  function getMaximumPoints()
537  {
538  $points = 0;
539  foreach ($this->answers as $key => $value)
540  {
541  if ($value->getPoints() > $points)
542  {
543  $points = $value->getPoints();
544  }
545  }
546  return $points;
547  }
548 
559  public function calculateReachedPoints($active_id, $pass = NULL, $returndetails = FALSE)
560  {
561  if( $returndetails )
562  {
563  throw new ilTestException('return details not implemented for '.__METHOD__);
564  }
565 
566  global $ilDB;
567 
568  $found_values = array();
569  if (is_null($pass))
570  {
571  $pass = $this->getSolutionMaxPass($active_id);
572  }
573  $result = $ilDB->queryF("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
574  array('integer','integer','integer'),
575  array($active_id, $this->getId(), $pass)
576  );
577  while ($data = $ilDB->fetchAssoc($result))
578  {
579  if (strcmp($data["value1"], "") != 0)
580  {
581  array_push($found_values, $data["value1"]);
582  }
583  }
584  $points = 0;
585  foreach ($this->answers as $key => $answer)
586  {
587  if (count($found_values) > 0)
588  {
589  if (in_array($key, $found_values))
590  {
591  $points += $answer->getPoints();
592  }
593  }
594  }
595 
596  return $points;
597  }
598 
607  public function saveWorkingData($active_id, $pass = NULL)
608  {
609  global $ilDB;
610  global $ilUser;
611 
612  if (is_null($pass))
613  {
614  include_once "./Modules/Test/classes/class.ilObjTest.php";
615  $pass = ilObjTest::_getPass($active_id);
616  }
617  $entered_values = 0;
618 
619  $result = $ilDB->queryF("SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
620  array('integer','integer','integer'),
621  array($active_id, $this->getId(), $pass)
622  );
623  $row = $ilDB->fetchAssoc($result);
624  $update = $row["solution_id"];
625 
626  if ($update)
627  {
628  if (strlen($_POST["multiple_choice_result"]))
629  {
630  $affectedRows = $ilDB->update("tst_solutions", array(
631  "value1" => array("clob", $_POST["multiple_choice_result"]),
632  "tstamp" => array("integer", time())
633  ), array(
634  "solution_id" => array("integer", $update)
635  ));
636  $entered_values++;
637  }
638  else
639  {
640  $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE solution_id = %s",
641  array('integer'),
642  array($update)
643  );
644  }
645  }
646  else
647  {
648  if (strlen($_POST["multiple_choice_result"]))
649  {
650  $next_id = $ilDB->nextId('tst_solutions');
651  $affectedRows = $ilDB->insert("tst_solutions", array(
652  "solution_id" => array("integer", $next_id),
653  "active_fi" => array("integer", $active_id),
654  "question_fi" => array("integer", $this->getId()),
655  "value1" => array("clob", $_POST['multiple_choice_result']),
656  "value2" => array("clob", null),
657  "pass" => array("integer", $pass),
658  "tstamp" => array("integer", time())
659  ));
660  $entered_values++;
661  }
662  }
663  if ($entered_values)
664  {
665  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
667  {
668  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
669  }
670  }
671  else
672  {
673  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
675  {
676  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
677  }
678  }
679 
680  return true;
681  }
682 
691  protected function reworkWorkingData($active_id, $pass, $obligationsAnswered)
692  {
693  // nothing to rework!
694  }
695 
701  function syncFeedbackSingleAnswers()
702  {
703  global $ilDB;
704 
705  $feedback = "";
706 
707  // delete generic feedback of the original
708  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_fb_sc WHERE question_fi = %s",
709  array('integer'),
710  array($this->original_id)
711  );
712 
713  // get generic feedback of the actual question
714  $result = $ilDB->queryF("SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
715  array('integer'),
716  array($this->getId())
717  );
718 
719  // save generic feedback to the original
720  if ($result->numRows())
721  {
722  while ($row = $ilDB->fetchAssoc($result))
723  {
724  $next_id = $ilDB->nextId('qpl_fb_sc');
726  $ilDB->insert('qpl_fb_sc', array(
727  'feedback_id' => array( 'integer', $next_id ),
728  'question_fi' => array( 'integer', $this->original_id ),
729  'answer' => array( 'integer', $row["answer"] ),
730  'feedback' => array( 'clob', $row["feedback"] ),
731  'tstamp' => array( 'integer', time() ),
732  )
733  );
734  }
735  }
736  }
737 
738  function syncWithOriginal()
739  {
740  if ($this->getOriginalId())
741  {
742  $this->syncFeedbackSingleAnswers();
743  $this->syncImages();
745  }
746  }
747 
754  function getQuestionType()
755  {
756  return "assSingleChoice";
757  }
758 
766  {
767  return "qpl_qst_sc";
768  }
769 
777  {
778  return "qpl_a_sc";
779  }
780 
789  function setImageFile($image_filename, $image_tempfilename = "")
790  {
791  $result = 0;
792  if (!empty($image_tempfilename))
793  {
794  $image_filename = str_replace(" ", "_", $image_filename);
795  $imagepath = $this->getImagePath();
796  if (!file_exists($imagepath))
797  {
798  ilUtil::makeDirParents($imagepath);
799  }
800  //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
801  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
802  {
803  $result = 2;
804  }
805  else
806  {
807  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
808  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
809  if (!preg_match("/^image/", $mimetype))
810  {
811  unlink($imagepath . $image_filename);
812  $result = 1;
813  }
814  else
815  {
816  // create thumbnail file
817  if ($this->isSingleline && ($this->getThumbSize()))
818  {
819  $this->generateThumbForFile($imagepath, $image_filename);
820  }
821  }
822  }
823  }
824  return $result;
825  }
826 
833  function deleteImage($image_filename)
834  {
835  $imagepath = $this->getImagePath();
836  @unlink($imagepath . $image_filename);
837  $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
838  @unlink($thumbpath);
839  }
840 
841  function duplicateImages($question_id, $objectId = null)
842  {
843  global $ilLog;
844  $imagepath = $this->getImagePath();
845  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
846 
847  if( (int)$objectId > 0 )
848  {
849  $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
850  }
851 
852  foreach ($this->answers as $answer)
853  {
854  $filename = $answer->getImage();
855  if (strlen($filename))
856  {
857  if (!file_exists($imagepath))
858  {
859  ilUtil::makeDirParents($imagepath);
860  }
861  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
862  {
863  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
864  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
865  }
866  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
867  {
868  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
869  {
870  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
871  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
872  }
873  }
874  }
875  }
876  }
877 
878  function copyImages($question_id, $source_questionpool)
879  {
880  global $ilLog;
881  $imagepath = $this->getImagePath();
882  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
883  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
884  foreach ($this->answers as $answer)
885  {
886  $filename = $answer->getImage();
887  if (strlen($filename))
888  {
889  if (!file_exists($imagepath))
890  {
891  ilUtil::makeDirParents($imagepath);
892  }
893  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
894  {
895  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
896  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
897  }
898  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
899  {
900  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
901  {
902  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
903  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
904  }
905  }
906  }
907  }
908  }
909 
913  protected function syncImages()
914  {
915  global $ilLog;
916  $question_id = $this->getOriginalId();
917  $imagepath = $this->getImagePath();
918  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
919  ilUtil::delDir($imagepath_original);
920  foreach ($this->answers as $answer)
921  {
922  $filename = $answer->getImage();
923  if (strlen($filename))
924  {
925  if (@file_exists($imagepath . $filename))
926  {
927  if (!file_exists($imagepath))
928  {
929  ilUtil::makeDirParents($imagepath);
930  }
931  if (!file_exists($imagepath_original))
932  {
933  ilUtil::makeDirParents($imagepath_original);
934  }
935  if (!@copy($imagepath . $filename, $imagepath_original . $filename))
936  {
937  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
938  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
939  }
940  }
941  if (@file_exists($imagepath . $this->getThumbPrefix() . $filename))
942  {
943  if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename))
944  {
945  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
946  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
947  }
948  }
949  }
950  }
951  }
952 
960  function saveFeedbackSingleAnswer($answer_index, $feedback)
961  {
962  global $ilDB;
963 
964  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
965  array('integer','integer'),
966  array($this->getId(), $answer_index)
967  );
968  if (strlen($feedback))
969  {
970  include_once("./Services/RTE/classes/class.ilRTE.php");
971  $next_id = $ilDB->nextId('qpl_fb_sc');
973  $ilDB->insert('qpl_fb_sc', array(
974  'feedback_id' => array( 'integer', $next_id ),
975  'question_fi' => array( 'integer', $this->getId() ),
976  'answer' => array( 'integer', $answer_index ),
977  'feedback' => array( 'clob', ilRTE::_replaceMediaObjectImageSrc($feedback, 0) ),
978  'tstamp' => array( 'integer', time() ),
979  )
980  );
981  }
982  }
983 
991  function getFeedbackSingleAnswer($answer_index)
992  {
993  global $ilDB;
994 
995  $feedback = "";
996  $result = $ilDB->queryF("SELECT * FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
997  array('integer','integer'),
998  array($this->getId(), $answer_index)
999  );
1000  if ($result->numRows())
1001  {
1002  $row = $ilDB->fetchAssoc($result);
1003  include_once("./Services/RTE/classes/class.ilRTE.php");
1004  $feedback = ilRTE::_replaceMediaObjectImageSrc($row["feedback"], 1);
1005  }
1006  return $feedback;
1007  }
1008 
1015  function duplicateFeedbackAnswer($original_id)
1016  {
1017  global $ilDB;
1018 
1019  $feedback = "";
1020  $result = $ilDB->queryF("SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
1021  array('integer'),
1022  array($original_id)
1023  );
1024  if ($result->numRows())
1025  {
1026  while ($row = $ilDB->fetchAssoc($result))
1027  {
1028  $next_id = $ilDB->nextId('qpl_fb_sc');
1030  $ilDB->insert('qpl_fb_sc', array(
1031  'feedback_id' => array( 'integer', $next_id ),
1032  'question_fi' => array( 'integer', $this->getId() ),
1033  'answer' => array( 'integer', $row["answer"] ),
1034  'feedback' => array( 'clob', $row["feedback"] ),
1035  'tstamp' => array( 'integer', time() ),
1036  )
1037  );
1038  }
1039  }
1040  }
1041 
1047  {
1049  foreach ($this->answers as $index => $answer)
1050  {
1051  $text .= $this->getFeedbackSingleAnswer($index);
1052  $answer_obj = $this->answers[$index];
1053  $text .= $answer_obj->getAnswertext();
1054  }
1055  return $text;
1056  }
1057 
1061  function &getAnswers()
1062  {
1063  return $this->answers;
1064  }
1065 
1078  public function setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
1079  {
1080  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
1081  $solution = $this->getSolutionValues($active_id, $pass);
1082  $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
1083  $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
1084  $i = 1;
1085  foreach ($this->getAnswers() as $id => $answer)
1086  {
1087  $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($answer->getAnswertext()), $format_bold);
1088  if ($id == $solution[0]["value1"])
1089  {
1090  $worksheet->write($startrow + $i, 1, 1);
1091  }
1092  else
1093  {
1094  $worksheet->write($startrow + $i, 1, 0);
1095  }
1096  $i++;
1097  }
1098  return $startrow + $i + 1;
1099  }
1100 
1101  public function getThumbSize()
1102  {
1103  return $this->thumb_size;
1104  }
1105 
1106  public function setThumbSize($a_size)
1107  {
1108  $this->thumb_size = $a_size;
1109  }
1110 
1114  public function toJSON()
1115  {
1116  include_once("./Services/RTE/classes/class.ilRTE.php");
1117  $result = array();
1118  $result['id'] = (int) $this->getId();
1119  $result['type'] = (string) $this->getQuestionType();
1120  $result['title'] = (string) $this->getTitle();
1121  $result['question'] = $this->formatSAQuestion($this->getQuestion());
1122  $result['nr_of_tries'] = (int) $this->getNrOfTries();
1123  $result['shuffle'] = (bool) $this->getShuffle();
1124  $result['feedback'] = array(
1125  "onenotcorrect" => ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackGeneric(0), 0),
1126  "allcorrect" => ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackGeneric(1), 0)
1127  );
1128 
1129  $answers = array();
1130  $has_image = false;
1131  foreach ($this->getAnswers() as $key => $answer_obj)
1132  {
1133  if((string) $answer_obj->getImage())
1134  {
1135  $has_image = true;
1136  }
1137  array_push($answers, array(
1138  "answertext" => (string) $this->formatSAQuestion($answer_obj->getAnswertext()),
1139  "points" => (float)$answer_obj->getPoints(),
1140  "order" => (int)$answer_obj->getOrder(),
1141  "image" => (string) $answer_obj->getImage(),
1142  "feedback" => ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackSingleAnswer($key), 0)
1143  ));
1144  }
1145  $result['answers'] = $answers;
1146  if($has_image)
1147  {
1148  $result['path'] = $this->getImagePathWeb();
1149  $result['thumb'] = $this->getThumbSize();
1150  }
1151 
1152  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1153  $result['mobs'] = $mobs;
1154 
1155  return json_encode($result);
1156  }
1157 
1158  public function removeAnswerImage($index)
1159  {
1160  $answer = $this->answers[$index];
1161  if (is_object($answer))
1162  {
1163  $this->deleteImage($answer->getImage());
1164  $answer->setImage('');
1165  }
1166  }
1167 
1168  function createRandomSolution($active_id, $pass)
1169  {
1170  $value = rand(0, count($this->answers)-1);
1171  $_POST["multiple_choice_result"] = (strlen($value)) ? (string)$value : '0';
1172  $this->saveWorkingData($active_id, $pass);
1173  }
1174 
1176  {
1177  global $ilUser;
1178 
1179  $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1180  if ($multilineAnswerSetting != 1)
1181  {
1182  $multilineAnswerSetting = 0;
1183  }
1184  return $multilineAnswerSetting;
1185  }
1186 
1187  function setMultilineAnswerSetting($a_setting = 0)
1188  {
1189  global $ilUser;
1190  $ilUser->writePref("tst_multiline_answers", $a_setting);
1191  }
1192 
1203  public function isAnswered($active_id, $pass)
1204  {
1205  $answered = assQuestion::doesSolutionRecordsExist($active_id, $pass, $this->getId());
1206 
1207  return $answered;
1208  }
1209 
1220  public static function isObligationPossible($questionId)
1221  {
1222  return true;
1223  }
1224 }
1225 
1226 ?>