ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assSingleChoice.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 
23 {
31  var $answers;
32 
42 
48  protected $thumb_size;
49 
56  protected $feedback_setting;
57 
72  public function __construct(
73  $title = "",
74  $comment = "",
75  $author = "",
76  $owner = -1,
77  $question = "",
79  )
80  {
82  $this->thumb_size = 150;
83  $this->output_type = $output_type;
84  $this->answers = array();
85  $this->shuffle = 1;
86  $this->feedback_setting = 2;
87  }
88 
95  function isComplete()
96  {
97  if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
98  {
99  foreach ($this->answers as $answer)
100  {
101  if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) return false;
102  }
103  return true;
104  }
105  else
106  {
107  return false;
108  }
109  }
110 
117  public function saveToDb($original_id = "")
118  {
120  global $ilDB;
121 
123 
124  // kann das weg?
125  $oldthumbsize = 0;
126  if ($this->isSingleline && ($this->getThumbSize()))
127  {
128  // get old thumbnail size
129  $result = $ilDB->queryF("SELECT thumb_size FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
130  array("integer"),
131  array($this->getId())
132  );
133  if ($result->numRows() == 1)
134  {
135  $data = $ilDB->fetchAssoc($result);
136  $oldthumbsize = $data['thumb_size'];
137  }
138  }
139 
140 
142 
144 
146  }
147 
148  /*
149  * Rebuild the thumbnail images with a new thumbnail size
150  */
151  protected function rebuildThumbnails()
152  {
153  if ($this->isSingleline && ($this->getThumbSize()))
154  {
155  foreach ($this->getAnswers() as $answer)
156  {
157  if (strlen($answer->getImage()))
158  {
159  $this->generateThumbForFile($this->getImagePath(), $answer->getImage());
160  }
161  }
162  }
163  }
164 
165  public function getThumbPrefix()
166  {
167  return "thumb.";
168  }
169 
170  protected function generateThumbForFile($path, $file)
171  {
172  $filename = $path . $file;
173  if (@file_exists($filename))
174  {
175  $thumbpath = $path . $this->getThumbPrefix() . $file;
176  $path_info = @pathinfo($filename);
177  $ext = "";
178  switch (strtoupper($path_info['extension']))
179  {
180  case 'PNG':
181  $ext = 'PNG';
182  break;
183  case 'GIF':
184  $ext = 'GIF';
185  break;
186  default:
187  $ext = 'JPEG';
188  break;
189  }
190  ilUtil::convertImage($filename, $thumbpath, $ext, $this->getThumbSize());
191  }
192  }
193 
201  function loadFromDb($question_id)
202  {
203  global $ilDB;
204 
205  $hasimages = 0;
206 
207  $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",
208  array("integer"),
209  array($question_id)
210  );
211  if ($result->numRows() == 1)
212  {
213  $data = $ilDB->fetchAssoc($result);
214  $this->setId($question_id);
215  $this->setObjId($data["obj_fi"]);
216  $this->setTitle($data["title"]);
217  $this->setNrOfTries($data['nr_of_tries']);
218  $this->setComment($data["description"]);
219  $this->setOriginalId($data["original_id"]);
220  $this->setAuthor($data["author"]);
221  $this->setPoints($data["points"]);
222  $this->setOwner($data["owner"]);
223  include_once("./Services/RTE/classes/class.ilRTE.php");
224  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
225  $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
226  $this->setShuffle($shuffle);
227  $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
228  $this->setThumbSize($data['thumb_size']);
229  $this->isSingleline = ($data['allow_images']) ? false : true;
230  $this->lastChange = $data['tstamp'];
231  $this->feedback_setting = $data['feedback_setting'];
232 
233  try
234  {
235  $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
236  }
238  {
239  }
240  }
241 
242  $result = $ilDB->queryF("SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
243  array('integer'),
244  array($question_id)
245  );
246  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
247  if ($result->numRows() > 0)
248  {
249  while ($data = $ilDB->fetchAssoc($result))
250  {
251  $imagefilename = $this->getImagePath() . $data["imagefile"];
252  if (!@file_exists($imagefilename))
253  {
254  $data["imagefile"] = "";
255  }
256  include_once("./Services/RTE/classes/class.ilRTE.php");
257  $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"], 1);
258  array_push($this->answers, new ASS_AnswerBinaryStateImage($data["answertext"], $data["points"], $data["aorder"], 1, $data["imagefile"]));
259  }
260  }
261 
262  parent::loadFromDb($question_id);
263  }
264 
270  function duplicate($for_test = true, $title = "", $author = "", $owner = "", $testObjId = null)
271  {
272  if ($this->id <= 0)
273  {
274  // The question has not been saved. It cannot be duplicated
275  return;
276  }
277  // duplicate the question in database
278  $this_id = $this->getId();
279  $thisObjId = $this->getObjId();
280 
281  $clone = $this;
282  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
284  $clone->id = -1;
285 
286  if( (int)$testObjId > 0 )
287  {
288  $clone->setObjId($testObjId);
289  }
290 
291  if ($title)
292  {
293  $clone->setTitle($title);
294  }
295 
296  if ($author)
297  {
298  $clone->setAuthor($author);
299  }
300  if ($owner)
301  {
302  $clone->setOwner($owner);
303  }
304  if ($for_test)
305  {
306  $clone->saveToDb($original_id);
307  }
308  else
309  {
310  $clone->saveToDb();
311  }
312 
313  // copy question page content
314  $clone->copyPageOfQuestion($this_id);
315 
316  // copy XHTML media objects
317  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
318  // duplicate the images
319  $clone->duplicateImages($this_id, $thisObjId);
320 
321  $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
322 
323  return $clone->id;
324  }
325 
331  function copyObject($target_questionpool_id, $title = "")
332  {
333  if ($this->id <= 0)
334  {
335  // The question has not been saved. It cannot be duplicated
336  return;
337  }
338  // duplicate the question in database
339  $clone = $this;
340  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
342  $clone->id = -1;
343  $source_questionpool_id = $this->getObjId();
344  $clone->setObjId($target_questionpool_id);
345  if ($title)
346  {
347  $clone->setTitle($title);
348  }
349  $clone->saveToDb();
350  // copy question page content
351  $clone->copyPageOfQuestion($original_id);
352  // copy XHTML media objects
353  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
354  // duplicate the image
355  $clone->copyImages($original_id, $source_questionpool_id);
356 
357  $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
358 
359  return $clone->id;
360  }
361 
362  public function createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle = "")
363  {
364  if ($this->id <= 0)
365  {
366  // The question has not been saved. It cannot be duplicated
367  return;
368  }
369 
370  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
371 
372  $sourceQuestionId = $this->id;
373  $sourceParentId = $this->getObjId();
374 
375  // duplicate the question in database
376  $clone = $this;
377  $clone->id = -1;
378 
379  $clone->setObjId($targetParentId);
380 
381  if ($targetQuestionTitle)
382  {
383  $clone->setTitle($targetQuestionTitle);
384  }
385 
386  $clone->saveToDb();
387  // copy question page content
388  $clone->copyPageOfQuestion($sourceQuestionId);
389  // copy XHTML media objects
390  $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
391  // duplicate the image
392  $clone->copyImages($sourceQuestionId, $sourceParentId);
393 
394  $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
395 
396  return $clone->id;
397  }
398 
406  function getOutputType()
407  {
408  return $this->output_type;
409  }
410 
419  {
420  $this->output_type = $output_type;
421  }
422 
436  function addAnswer(
437  $answertext = "",
438  $points = 0.0,
439  $order = 0,
440  $answerimage = ""
441  )
442  {
443  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
444  if (array_key_exists($order, $this->answers))
445  {
446  // insert answer
447  $answer = new ASS_AnswerBinaryStateImage($answertext, $points, $order, 1, $answerimage);
448  $newchoices = array();
449  for ($i = 0; $i < $order; $i++)
450  {
451  array_push($newchoices, $this->answers[$i]);
452  }
453  array_push($newchoices, $answer);
454  for ($i = $order; $i < count($this->answers); $i++)
455  {
456  $changed = $this->answers[$i];
457  $changed->setOrder($i+1);
458  array_push($newchoices, $changed);
459  }
460  $this->answers = $newchoices;
461  }
462  else
463  {
464  // add answer
465  $answer = new ASS_AnswerBinaryStateImage($answertext, $points, count($this->answers), 1, $answerimage);
466  array_push($this->answers, $answer);
467  }
468  }
469 
477  function getAnswerCount()
478  {
479  return count($this->answers);
480  }
481 
491  function getAnswer($index = 0)
492  {
493  if ($index < 0) return NULL;
494  if (count($this->answers) < 1) return NULL;
495  if ($index >= count($this->answers)) return NULL;
496 
497  return $this->answers[$index];
498  }
499 
508  function deleteAnswer($index = 0)
509  {
510  if ($index < 0) return;
511  if (count($this->answers) < 1) return;
512  if ($index >= count($this->answers)) return;
513  $answer = $this->answers[$index];
514  if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
515  unset($this->answers[$index]);
516  $this->answers = array_values($this->answers);
517  for ($i = 0; $i < count($this->answers); $i++)
518  {
519  if ($this->answers[$i]->getOrder() > $index)
520  {
521  $this->answers[$i]->setOrder($i);
522  }
523  }
524  }
525 
532  function flushAnswers()
533  {
534  $this->answers = array();
535  }
536 
543  function getMaximumPoints()
544  {
545  $points = 0;
546  foreach ($this->answers as $key => $value)
547  {
548  if ($value->getPoints() > $points)
549  {
550  $points = $value->getPoints();
551  }
552  }
553  return $points;
554  }
555 
566  public function calculateReachedPoints($active_id, $pass = NULL, $returndetails = FALSE)
567  {
568  if( $returndetails )
569  {
570  throw new ilTestException('return details not implemented for '.__METHOD__);
571  }
572 
573  global $ilDB;
574 
575  $found_values = array();
576  if (is_null($pass))
577  {
578  $pass = $this->getSolutionMaxPass($active_id);
579  }
580  $result = $ilDB->queryF("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
581  array('integer','integer','integer'),
582  array($active_id, $this->getId(), $pass)
583  );
584  while ($data = $ilDB->fetchAssoc($result))
585  {
586  if (strcmp($data["value1"], "") != 0)
587  {
588  array_push($found_values, $data["value1"]);
589  }
590  }
591  $points = 0;
592  foreach ($this->answers as $key => $answer)
593  {
594  if (count($found_values) > 0)
595  {
596  if (in_array($key, $found_values))
597  {
598  $points += $answer->getPoints();
599  }
600  }
601  }
602 
603  return $points;
604  }
605 
614  public function saveWorkingData($active_id, $pass = NULL)
615  {
616  global $ilDB;
617  global $ilUser;
618 
619  if (is_null($pass))
620  {
621  include_once "./Modules/Test/classes/class.ilObjTest.php";
622  $pass = ilObjTest::_getPass($active_id);
623  }
624  $entered_values = 0;
625 
626  $this->getProcessLocker()->requestUserSolutionUpdateLock();
627 
628  $result = $ilDB->queryF("SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
629  array('integer','integer','integer'),
630  array($active_id, $this->getId(), $pass)
631  );
632  $row = $ilDB->fetchAssoc($result);
633  $update = $row["solution_id"];
634 
635  if ($update)
636  {
637  if (strlen($_POST["multiple_choice_result"]))
638  {
639  $affectedRows = $ilDB->update("tst_solutions", array(
640  "value1" => array("clob", $_POST["multiple_choice_result"]),
641  "tstamp" => array("integer", time())
642  ), array(
643  "solution_id" => array("integer", $update)
644  ));
645  $entered_values++;
646  }
647  else
648  {
649  $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE solution_id = %s",
650  array('integer'),
651  array($update)
652  );
653  }
654  }
655  else
656  {
657  if (strlen($_POST["multiple_choice_result"]))
658  {
659  $next_id = $ilDB->nextId('tst_solutions');
660  $affectedRows = $ilDB->insert("tst_solutions", array(
661  "solution_id" => array("integer", $next_id),
662  "active_fi" => array("integer", $active_id),
663  "question_fi" => array("integer", $this->getId()),
664  "value1" => array("clob", $_POST['multiple_choice_result']),
665  "value2" => array("clob", null),
666  "pass" => array("integer", $pass),
667  "tstamp" => array("integer", time())
668  ));
669  $entered_values++;
670  }
671  }
672 
673  $this->getProcessLocker()->releaseUserSolutionUpdateLock();
674 
675  if ($entered_values)
676  {
677  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
679  {
680  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
681  }
682  }
683  else
684  {
685  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
687  {
688  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
689  }
690  }
691 
692  return true;
693  }
694 
695  public function saveAdditionalQuestionDataToDb()
696  {
698  global $ilDB;
699 
700  // save additional data
701  $ilDB->manipulateF( "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
702  array( "integer" ),
703  array( $this->getId() )
704  );
705 
706  $ilDB->manipulateF( "INSERT INTO " . $this->getAdditionalTableName(
707  ) . " (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
708  array( "integer", "text", "text", "integer" ),
709  array(
710  $this->getId(),
711  $this->getShuffle(),
712  ($this->isSingleline) ? "0" : "1",
713  (strlen( $this->getThumbSize() ) == 0) ? null : $this->getThumbSize()
714  )
715  );
716  }
717 
718  public function saveAnswerSpecificDataToDb()
719  {
721  global $ilDB;
722  if (!$this->isSingleline)
723  {
724  ilUtil::delDir( $this->getImagePath() );
725  }
726  $ilDB->manipulateF( "DELETE FROM qpl_a_sc WHERE question_fi = %s",
727  array( 'integer' ),
728  array( $this->getId() )
729  );
730 
731  foreach ($this->answers as $key => $value)
732  {
734  $answer_obj = $this->answers[$key];
735  $next_id = $ilDB->nextId( 'qpl_a_sc' );
736  $ilDB->manipulateF( "INSERT INTO qpl_a_sc (answer_id, question_fi, answertext, points, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
737  array( 'integer', 'integer', 'text', 'float', 'integer', 'text', 'integer' ),
738  array(
739  $next_id,
740  $this->getId(),
741  ilRTE::_replaceMediaObjectImageSrc( $answer_obj->getAnswertext(), 0 ),
742  $answer_obj->getPoints(),
743  $answer_obj->getOrder(),
744  $answer_obj->getImage(),
745  time()
746  )
747  );
748  }
749  $this->rebuildThumbnails();
750  }
751 
760  protected function reworkWorkingData($active_id, $pass, $obligationsAnswered)
761  {
762  // nothing to rework!
763  }
764 
765  function syncWithOriginal()
766  {
767  if ($this->getOriginalId())
768  {
769  $this->syncImages();
771  }
772  }
773 
780  function getQuestionType()
781  {
782  return "assSingleChoice";
783  }
784 
792  {
793  return "qpl_qst_sc";
794  }
795 
803  {
804  return "qpl_a_sc";
805  }
806 
815  function setImageFile($image_filename, $image_tempfilename = "")
816  {
817  $result = 0;
818  if (!empty($image_tempfilename))
819  {
820  $image_filename = str_replace(" ", "_", $image_filename);
821  $imagepath = $this->getImagePath();
822  if (!file_exists($imagepath))
823  {
824  ilUtil::makeDirParents($imagepath);
825  }
826  //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
827  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
828  {
829  $result = 2;
830  }
831  else
832  {
833  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
834  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
835  if (!preg_match("/^image/", $mimetype))
836  {
837  unlink($imagepath . $image_filename);
838  $result = 1;
839  }
840  else
841  {
842  // create thumbnail file
843  if ($this->isSingleline && ($this->getThumbSize()))
844  {
845  $this->generateThumbForFile($imagepath, $image_filename);
846  }
847  }
848  }
849  }
850  return $result;
851  }
852 
859  function deleteImage($image_filename)
860  {
861  $imagepath = $this->getImagePath();
862  @unlink($imagepath . $image_filename);
863  $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
864  @unlink($thumbpath);
865  }
866 
867  function duplicateImages($question_id, $objectId = null)
868  {
869  global $ilLog;
870  $imagepath = $this->getImagePath();
871  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
872 
873  if( (int)$objectId > 0 )
874  {
875  $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
876  }
877 
878  foreach ($this->answers as $answer)
879  {
880  $filename = $answer->getImage();
881  if (strlen($filename))
882  {
883  if (!file_exists($imagepath))
884  {
885  ilUtil::makeDirParents($imagepath);
886  }
887  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
888  {
889  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
890  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
891  }
892  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
893  {
894  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
895  {
896  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
897  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
898  }
899  }
900  }
901  }
902  }
903 
904  function copyImages($question_id, $source_questionpool)
905  {
906  global $ilLog;
907  $imagepath = $this->getImagePath();
908  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
909  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
910  foreach ($this->answers as $answer)
911  {
912  $filename = $answer->getImage();
913  if (strlen($filename))
914  {
915  if (!file_exists($imagepath))
916  {
917  ilUtil::makeDirParents($imagepath);
918  }
919  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
920  {
921  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
922  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
923  }
924  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
925  {
926  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
927  {
928  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
929  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
930  }
931  }
932  }
933  }
934  }
935 
939  protected function syncImages()
940  {
941  global $ilLog;
942  $question_id = $this->getOriginalId();
943  $imagepath = $this->getImagePath();
944  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
945  ilUtil::delDir($imagepath_original);
946  foreach ($this->answers as $answer)
947  {
948  $filename = $answer->getImage();
949  if (strlen($filename))
950  {
951  if (@file_exists($imagepath . $filename))
952  {
953  if (!file_exists($imagepath))
954  {
955  ilUtil::makeDirParents($imagepath);
956  }
957  if (!file_exists($imagepath_original))
958  {
959  ilUtil::makeDirParents($imagepath_original);
960  }
961  if (!@copy($imagepath . $filename, $imagepath_original . $filename))
962  {
963  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
964  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
965  }
966  }
967  if (@file_exists($imagepath . $this->getThumbPrefix() . $filename))
968  {
969  if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename))
970  {
971  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
972  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
973  }
974  }
975  }
976  }
977  }
978 
984  {
986  foreach ($this->answers as $index => $answer)
987  {
988  $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), $index);
989  $answer_obj = $this->answers[$index];
990  $text .= $answer_obj->getAnswertext();
991  }
992  return $text;
993  }
994 
998  function &getAnswers()
999  {
1000  return $this->answers;
1001  }
1002 
1015  public function setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
1016  {
1017  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
1018  $solution = $this->getSolutionValues($active_id, $pass);
1019  $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
1020  $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
1021  $i = 1;
1022  foreach ($this->getAnswers() as $id => $answer)
1023  {
1024  $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($answer->getAnswertext()), $format_bold);
1025  if ($id == $solution[0]["value1"])
1026  {
1027  $worksheet->write($startrow + $i, 1, 1);
1028  }
1029  else
1030  {
1031  $worksheet->write($startrow + $i, 1, 0);
1032  }
1033  $i++;
1034  }
1035  return $startrow + $i + 1;
1036  }
1037 
1038  public function getThumbSize()
1039  {
1040  return $this->thumb_size;
1041  }
1042 
1043  public function setThumbSize($a_size)
1044  {
1045  $this->thumb_size = $a_size;
1046  }
1047 
1051  public function toJSON()
1052  {
1053  include_once("./Services/RTE/classes/class.ilRTE.php");
1054  $result = array();
1055  $result['id'] = (int) $this->getId();
1056  $result['type'] = (string) $this->getQuestionType();
1057  $reilUtilsult['title'] = (string) $this->getTitle();
1058  $result['question'] = $this->formatSAQuestion($this->getQuestion());
1059  $result['nr_of_tries'] = (int) $this->getNrOfTries();
1060  $result['shuffle'] = (bool) $this->getShuffle();
1061 
1062  $result['feedback'] = array(
1063  "onenotcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false),
1064  "allcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true)
1065  );
1066 
1067  $answers = array();
1068  $has_image = false;
1069  foreach ($this->getAnswers() as $key => $answer_obj)
1070  {
1071  if((string) $answer_obj->getImage())
1072  {
1073  $has_image = true;
1074  }
1075  array_push($answers, array(
1076  "answertext" => (string) $this->formatSAQuestion($answer_obj->getAnswertext()),
1077  "points" => (float)$answer_obj->getPoints(),
1078  "order" => (int)$answer_obj->getOrder(),
1079  "image" => (string) $answer_obj->getImage(),
1080  "feedback" => ilRTE::_replaceMediaObjectImageSrc(
1081  $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key), 0
1082  )
1083  ));
1084  }
1085  $result['answers'] = $answers;
1086  if($has_image)
1087  {
1088  $result['path'] = $this->getImagePathWeb();
1089  $result['thumb'] = $this->getThumbSize();
1090  }
1091 
1092  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1093  $result['mobs'] = $mobs;
1094 
1095  return json_encode($result);
1096  }
1097 
1098  public function removeAnswerImage($index)
1099  {
1100  $answer = $this->answers[$index];
1101  if (is_object($answer))
1102  {
1103  $this->deleteImage($answer->getImage());
1104  $answer->setImage('');
1105  }
1106  }
1107 
1108  function createRandomSolution($active_id, $pass)
1109  {
1110  $value = rand(0, count($this->answers)-1);
1111  $_POST["multiple_choice_result"] = (strlen($value)) ? (string)$value : '0';
1112  $this->saveWorkingData($active_id, $pass);
1113  }
1114 
1116  {
1117  global $ilUser;
1118 
1119  $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1120  if ($multilineAnswerSetting != 1)
1121  {
1122  $multilineAnswerSetting = 0;
1123  }
1124  return $multilineAnswerSetting;
1125  }
1126 
1127  function setMultilineAnswerSetting($a_setting = 0)
1128  {
1129  global $ilUser;
1130  $ilUser->writePref("tst_multiline_answers", $a_setting);
1131  }
1132 
1142  public function setSpecificFeedbackSetting($a_feedback_setting)
1143  {
1144  $this->feedback_setting = $a_feedback_setting;
1145  }
1146 
1156  public function getSpecificFeedbackSetting()
1157  {
1158  if ($this->feedback_setting)
1159  {
1160  return $this->feedback_setting;
1161  }
1162  else
1163  {
1164  return 1;
1165  }
1166  }
1167 
1178  public function isAnswered($active_id, $pass)
1179  {
1180  $answered = assQuestion::doesSolutionRecordsExist($active_id, $pass, $this->getId());
1181 
1182  return $answered;
1183  }
1184 
1195  public static function isObligationPossible($questionId)
1196  {
1197  return true;
1198  }
1199 }