ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assMultipleChoice.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
24 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
25 
36 {
44  var $answers;
45 
55 
61  protected $thumb_size;
62 
77  function __construct(
78  $title = "",
79  $comment = "",
80  $author = "",
81  $owner = -1,
82  $question = "",
84  )
85  {
87  $this->output_type = $output_type;
88  $this->thumb_size = 150;
89  $this->answers = array();
90  $this->shuffle = 1;
91  }
92 
99  function isComplete()
100  {
101  if (($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
102  {
103  return true;
104  }
105  else
106  {
107  return false;
108  }
109  }
110 
117  function saveToDb($original_id = "")
118  {
119  global $ilDB;
120 
122 
123  $oldthumbsize = 0;
124  if ($this->isSingleline && ($this->getThumbSize()))
125  {
126  // get old thumbnail size
127  $result = $ilDB->queryF("SELECT thumb_size FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
128  array("integer"),
129  array($this->getId())
130  );
131  if ($result->numRows() == 1)
132  {
133  $data = $ilDB->fetchAssoc($result);
134  $oldthumbsize = $data['thumb_size'];
135  }
136  }
137  if (!$this->isSingleline)
138  {
139  ilUtil::delDir($this->getImagePath());
140  }
141 
142  // save additional data
143  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
144  array("integer"),
145  array($this->getId())
146  );
147 
148  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
149  array("integer", "text", "text", "integer"),
150  array(
151  $this->getId(),
152  $this->getShuffle(),
153  ($this->isSingleline) ? "0" : "1",
154  (strlen($this->getThumbSize()) == 0) ? null : $this->getThumbSize()
155  )
156  );
157 
158  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_mc WHERE question_fi = %s",
159  array('integer'),
160  array($this->getId())
161  );
162 
163  foreach ($this->answers as $key => $value)
164  {
165  $answer_obj = $this->answers[$key];
166  $next_id = $ilDB->nextId('qpl_a_mc');
167  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_mc (answer_id, question_fi, answertext, points, points_unchecked, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
168  array('integer','integer','text','float','float','integer','text', 'integer'),
169  array(
170  $next_id,
171  $this->getId(),
172  ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0),
173  $answer_obj->getPoints(),
174  $answer_obj->getPointsUnchecked(),
175  $answer_obj->getOrder(),
176  $answer_obj->getImage(),
177  time()
178  )
179  );
180  }
181 
182  $this->rebuildThumbnails();
183 
185  }
186 
187  /*
188  * Rebuild the thumbnail images with a new thumbnail size
189  */
190  protected function rebuildThumbnails()
191  {
192  if ($this->isSingleline && ($this->getThumbSize()))
193  {
194  foreach ($this->getAnswers() as $answer)
195  {
196  if (strlen($answer->getImage()))
197  {
198  $this->generateThumbForFile($this->getImagePath(), $answer->getImage());
199  }
200  }
201  }
202  }
203 
204  public function getThumbPrefix()
205  {
206  return "thumb.";
207  }
208 
209  protected function generateThumbForFile($path, $file)
210  {
211  $filename = $path . $file;
212  if (@file_exists($filename))
213  {
214  $thumbpath = $path . $this->getThumbPrefix() . $file;
215  $path_info = @pathinfo($filename);
216  $ext = "";
217  switch (strtoupper($path_info['extension']))
218  {
219  case 'PNG':
220  $ext = 'PNG';
221  break;
222  case 'GIF':
223  $ext = 'GIF';
224  break;
225  default:
226  $ext = 'JPEG';
227  break;
228  }
229  ilUtil::convertImage($filename, $thumbpath, $ext, $this->getThumbSize());
230  }
231  }
232 
239  function loadFromDb($question_id)
240  {
241  global $ilDB;
242  $hasimages = 0;
243 
244  $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",
245  array("integer"),
246  array($question_id)
247  );
248  if ($result->numRows() == 1)
249  {
250  $data = $ilDB->fetchAssoc($result);
251  $this->setId($question_id);
252  $this->setObjId($data["obj_fi"]);
253  $this->setTitle($data["title"]);
254  $this->setNrOfTries($data['nr_of_tries']);
255  $this->setComment($data["description"]);
256  $this->setOriginalId($data["original_id"]);
257  $this->setAuthor($data["author"]);
258  $this->setPoints($data["points"]);
259  $this->setOwner($data["owner"]);
260  include_once("./Services/RTE/classes/class.ilRTE.php");
261  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
262  $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
263  $this->setShuffle($shuffle);
264  $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
265  $this->setThumbSize($data['thumb_size']);
266  $this->isSingleline = ($data['allow_images']) ? false : true;
267  $this->lastChange = $data['tstamp'];
268  }
269 
270  $result = $ilDB->queryF("SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
271  array('integer'),
272  array($question_id)
273  );
274  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
275  if ($result->numRows() > 0)
276  {
277  while ($data = $ilDB->fetchAssoc($result))
278  {
279  $imagefilename = $this->getImagePath() . $data["imagefile"];
280  if (!@file_exists($imagefilename))
281  {
282  $data["imagefile"] = "";
283  }
284  include_once("./Services/RTE/classes/class.ilRTE.php");
285  $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"], 1);
286  array_push($this->answers, new ASS_AnswerMultipleResponseImage($data["answertext"], $data["points"], $data["aorder"], $data["points_unchecked"], $data["imagefile"]));
287  }
288  }
289 
290  parent::loadFromDb($question_id);
291  }
292 
298  function duplicate($for_test = true, $title = "", $author = "", $owner = "")
299  {
300  if ($this->id <= 0)
301  {
302  // The question has not been saved. It cannot be duplicated
303  return;
304  }
305  // duplicate the question in database
306  $this_id = $this->getId();
307  $clone = $this;
308  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
310  $clone->id = -1;
311  if ($title)
312  {
313  $clone->setTitle($title);
314  }
315 
316  if ($author)
317  {
318  $clone->setAuthor($author);
319  }
320  if ($owner)
321  {
322  $clone->setOwner($owner);
323  }
324 
325  if ($for_test)
326  {
327  $clone->saveToDb($original_id);
328  }
329  else
330  {
331  $clone->saveToDb();
332  }
333 
334  // copy question page content
335  $clone->copyPageOfQuestion($this_id);
336  // copy XHTML media objects
337  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
338  // duplicate the images
339  $clone->duplicateImages($this_id);
340  // duplicate the generic feedback
341  $clone->duplicateFeedbackGeneric($this_id);
342  // duplicate the answer specific feedback
343  $clone->duplicateFeedbackAnswer($this_id);
344 
345  $clone->onDuplicate($this_id);
346 
347  return $clone->id;
348  }
349 
355  function copyObject($target_questionpool, $title = "")
356  {
357  if ($this->id <= 0)
358  {
359  // The question has not been saved. It cannot be duplicated
360  return;
361  }
362  // duplicate the question in database
363  $clone = $this;
364  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
366  $clone->id = -1;
367  $source_questionpool = $this->getObjId();
368  $clone->setObjId($target_questionpool);
369  if ($title)
370  {
371  $clone->setTitle($title);
372  }
373  $clone->saveToDb();
374 
375  // copy question page content
376  $clone->copyPageOfQuestion($original_id);
377  // copy XHTML media objects
378  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
379  // duplicate the image
380  $clone->copyImages($original_id, $source_questionpool);
381  // duplicate the generic feedback
382  $clone->duplicateFeedbackGeneric($original_id);
383  // duplicate the answer specific feedback
384  $clone->duplicateFeedbackAnswer($original_id);
385 
386  $clone->onDuplicate($source_questionpool, $this->getId());
387 
388  $clone->onCopy($this->getObjId(), $this->getId());
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  $points_unchecked = 0.0,
433  $order = 0,
434  $answerimage = ""
435  )
436  {
437  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
438  if (array_key_exists($order, $this->answers))
439  {
440  // insert answer
441  $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, $order, $points_unchecked, $answerimage);
442  $newchoices = array();
443  for ($i = 0; $i < $order; $i++)
444  {
445  array_push($newchoices, $this->answers[$i]);
446  }
447  array_push($newchoices, $answer);
448  for ($i = $order; $i < count($this->answers); $i++)
449  {
450  $changed = $this->answers[$i];
451  $changed->setOrder($i+1);
452  array_push($newchoices, $changed);
453  }
454  $this->answers = $newchoices;
455  }
456  else
457  {
458  // add answer
459  $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, count($this->answers), $points_unchecked, $answerimage);
460  array_push($this->answers, $answer);
461  }
462  }
463 
471  function getAnswerCount()
472  {
473  return count($this->answers);
474  }
475 
485  function getAnswer($index = 0)
486  {
487  if ($index < 0) return NULL;
488  if (count($this->answers) < 1) return NULL;
489  if ($index >= count($this->answers)) return NULL;
490 
491  return $this->answers[$index];
492  }
493 
502  function deleteAnswer($index = 0)
503  {
504  if ($index < 0) return;
505  if (count($this->answers) < 1) return;
506  if ($index >= count($this->answers)) return;
507  $answer = $this->answers[$index];
508  if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
509  unset($this->answers[$index]);
510  $this->answers = array_values($this->answers);
511  for ($i = 0; $i < count($this->answers); $i++)
512  {
513  if ($this->answers[$i]->getOrder() > $index)
514  {
515  $this->answers[$i]->setOrder($i);
516  }
517  }
518  }
519 
526  function flushAnswers()
527  {
528  $this->answers = array();
529  }
530 
537  function getMaximumPoints()
538  {
539  $points = 0;
540  $allpoints = 0;
541  foreach ($this->answers as $key => $value)
542  {
543  if ($value->getPoints() > $value->getPointsUnchecked())
544  {
545  $allpoints += $value->getPoints();
546  }
547  else
548  {
549  $allpoints += $value->getPointsUnchecked();
550  }
551  }
552  return $allpoints;
553  }
554 
564  function calculateReachedPoints($active_id, $pass = NULL)
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 (in_array($key, $found_values))
588  {
589  $points += $answer->getPoints();
590  }
591  else
592  {
593  $points += $answer->getPointsUnchecked();
594  }
595  }
596  include_once "./Modules/Test/classes/class.ilObjTest.php";
597  $mc_scoring = ilObjTest::_getMCScoring($active_id);
598  if (($mc_scoring == 0) && (count($found_values) == 0))
599  {
600  $points = 0;
601  }
602  $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
603  return $points;
604  }
605 
614  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 
625  $entered_values = 0;
626  $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
627  array('integer','integer','integer'),
628  array($active_id, $this->getId(), $pass)
629  );
630  foreach ($_POST as $key => $value)
631  {
632  if (preg_match("/^multiple_choice_result_(\d+)/", $key, $matches))
633  {
634  if (strlen($value))
635  {
636  $next_id = $ilDB->nextId('tst_solutions');
637  $affectedRows = $ilDB->insert("tst_solutions", array(
638  "solution_id" => array("integer", $next_id),
639  "active_fi" => array("integer", $active_id),
640  "question_fi" => array("integer", $this->getId()),
641  "value1" => array("clob", $value),
642  "value2" => array("clob", null),
643  "pass" => array("integer", $pass),
644  "tstamp" => array("integer", time())
645  ));
646  $entered_values++;
647  }
648  }
649  }
650  if ($entered_values)
651  {
652  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
654  {
655  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
656  }
657  }
658  else
659  {
660  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
662  {
663  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
664  }
665  }
666  parent::saveWorkingData($active_id, $pass);
667  return true;
668  }
669 
676  {
677  global $ilDB;
678 
679  $feedback = "";
680 
681  // delete generic feedback of the original
682  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_fb_mc WHERE question_fi = %s",
683  array('integer'),
684  array($this->original_id)
685  );
686 
687  // get generic feedback of the actual question
688  $result = $ilDB->queryF("SELECT * FROM qpl_fb_mc WHERE question_fi = %s",
689  array('integer'),
690  array($this->getId())
691  );
692  // save generic feedback to the original
693  if ($result->numRows())
694  {
695  while ($row = $ilDB->fetchAssoc($result))
696  {
697  $next_id = $ilDB->nextId('qpl_fb_mc');
698  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_fb_mc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
699  array('integer','integer','integer','text','integer'),
700  array(
701  $next_id,
702  $this->original_id,
703  $row["answer"],
704  $row["feedback"],
705  time()
706  )
707  );
708  }
709  }
710  }
711 
712  function syncWithOriginal()
713  {
714  if ($this->getOriginalId())
715  {
716  $this->syncFeedbackSingleAnswers();
717  $this->syncImages();
719  }
720  }
721 
728  function getQuestionType()
729  {
730  return "assMultipleChoice";
731  }
732 
740  {
741  return "qpl_qst_mc";
742  }
743 
751  {
752  return "qpl_a_mc";
753  }
754 
763  function setImageFile($image_filename, $image_tempfilename = "")
764  {
765  $result = 0;
766  if (!empty($image_tempfilename))
767  {
768  $image_filename = str_replace(" ", "_", $image_filename);
769  $imagepath = $this->getImagePath();
770  if (!file_exists($imagepath))
771  {
772  ilUtil::makeDirParents($imagepath);
773  }
774  //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
775  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
776  {
777  $result = 2;
778  }
779  else
780  {
781  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
782  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
783  if (!preg_match("/^image/", $mimetype))
784  {
785  unlink($imagepath . $image_filename);
786  $result = 1;
787  }
788  else
789  {
790  // create thumbnail file
791  if ($this->isSingleline && ($this->getThumbSize()))
792  {
793  $this->generateThumbForFile($imagepath, $image_filename);
794  }
795  }
796  }
797  }
798  return $result;
799  }
800 
807  function deleteImage($image_filename)
808  {
809  $imagepath = $this->getImagePath();
810  @unlink($imagepath . $image_filename);
811  $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
812  @unlink($thumbpath);
813  }
814 
815  function duplicateImages($question_id)
816  {
817  global $ilLog;
818  $imagepath = $this->getImagePath();
819  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
820  foreach ($this->answers as $answer)
821  {
822  $filename = $answer->getImage();
823  if (strlen($filename))
824  {
825  if (!file_exists($imagepath))
826  {
827  ilUtil::makeDirParents($imagepath);
828  }
829  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
830  {
831  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
832  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
833  }
834  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
835  {
836  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
837  {
838  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
839  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
840  }
841  }
842  }
843  }
844  }
845 
846  function copyImages($question_id, $source_questionpool)
847  {
848  global $ilLog;
849  $imagepath = $this->getImagePath();
850  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
851  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
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 
881  protected function syncImages()
882  {
883  global $ilLog;
884  $question_id = $this->getOriginalId();
885  $imagepath = $this->getImagePath();
886  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
887  ilUtil::delDir($imagepath_original);
888  foreach ($this->answers as $answer)
889  {
890  $filename = $answer->getImage();
891  if (strlen($filename))
892  {
893  if (@file_exists($imagepath . $filename))
894  {
895  if (!file_exists($imagepath))
896  {
897  ilUtil::makeDirParents($imagepath);
898  }
899  if (!file_exists($imagepath_original))
900  {
901  ilUtil::makeDirParents($imagepath_original);
902  }
903  if (!@copy($imagepath . $filename, $imagepath_original . $filename))
904  {
905  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
906  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
907  }
908  }
909  if (@file_exists($imagepath . $this->getThumbPrefix() . $filename))
910  {
911  if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename))
912  {
913  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
914  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
915  }
916  }
917  }
918  }
919  }
920 
928  function saveFeedbackSingleAnswer($answer_index, $feedback)
929  {
930  global $ilDB;
931 
932  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_fb_mc WHERE question_fi = %s AND answer = %s",
933  array('integer','integer'),
934  array($this->getId(), $answer_index)
935  );
936  if (strlen($feedback))
937  {
938  include_once("./Services/RTE/classes/class.ilRTE.php");
939  $next_id = $ilDB->nextId('qpl_fb_mc');
940  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_fb_mc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
941  array('integer','integer','integer','text','integer'),
942  array(
943  $next_id,
944  $this->getId(),
945  $answer_index,
947  time()
948  )
949  );
950  }
951  }
952 
960  function getFeedbackSingleAnswer($answer_index)
961  {
962  global $ilDB;
963 
964  $feedback = "";
965  $result = $ilDB->queryF("SELECT * FROM qpl_fb_mc WHERE question_fi = %s AND answer = %s",
966  array('integer','integer'),
967  array($this->getId(), $answer_index)
968  );
969  if ($result->numRows())
970  {
971  $row = $ilDB->fetchAssoc($result);
972  include_once("./Services/RTE/classes/class.ilRTE.php");
973  $feedback = ilRTE::_replaceMediaObjectImageSrc($row["feedback"], 1);
974  }
975  return $feedback;
976  }
977 
985  {
986  global $ilDB;
987 
988  $feedback = "";
989  $result = $ilDB->queryF("SELECT * FROM qpl_fb_mc WHERE question_fi = %s",
990  array('integer'),
991  array($original_id)
992  );
993  if ($result->numRows())
994  {
995  while ($row = $ilDB->fetchAssoc($result))
996  {
997  $next_id = $ilDB->nextId('qpl_fb_mc');
998  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_fb_mc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
999  array('integer','integer','integer','text','integer'),
1000  array(
1001  $next_id,
1002  $this->getId(),
1003  $row["answer"],
1004  $row["feedback"],
1005  time()
1006  )
1007  );
1008  }
1009  }
1010  }
1011 
1017  {
1019  foreach ($this->answers as $index => $answer)
1020  {
1021  $text .= $this->getFeedbackSingleAnswer($index);
1022  $answer_obj = $this->answers[$index];
1023  $text .= $answer_obj->getAnswertext();
1024  }
1025  return $text;
1026  }
1027 
1031  function &getAnswers()
1032  {
1033  return $this->answers;
1034  }
1035 
1045  public function setExportDetailsXLS(&$adapter, $startrow, $active_id, $pass)
1046  {
1047  $solution = $this->getSolutionValues($active_id, $pass);
1048  $adapter->setCellValue($startrow, 0, $this->lng->txt($this->getQuestionType()), CELL_FORMAT_TITLE);
1049  $adapter->setCellValue($startrow, 1, $this->getTitle(), CELL_FORMAT_TITLE);
1050  $i = 1;
1051  foreach ($this->getAnswers() as $id => $answer)
1052  {
1053  $adapter->setCellValue($startrow + $i, 0, $answer->getAnswertext(), CELL_FORMAT_BOLD);
1054  $checked = FALSE;
1055  foreach ($solution as $solutionvalue)
1056  {
1057  if ($id == $solutionvalue["value1"])
1058  {
1059  $checked = TRUE;
1060  }
1061  }
1062  if ($checked)
1063  {
1064  $adapter->setCellValue($startrow + $i, 1, 1);
1065  }
1066  else
1067  {
1068  $adapter->setCellValue($startrow + $i, 1, 0);
1069  }
1070  $i++;
1071  }
1072  return $startrow + $i + 1;
1073  }
1074 
1075  public function getThumbSize()
1076  {
1077  return $this->thumb_size;
1078  }
1079 
1080  public function setThumbSize($a_size)
1081  {
1082  $this->thumb_size = $a_size;
1083  }
1084 
1088  public function toJSON()
1089  {
1090  include_once("./Services/RTE/classes/class.ilRTE.php");
1091  $result = array();
1092  $result['id'] = (int) $this->getId();
1093  $result['type'] = (string) $this->getQuestionType();
1094  $result['title'] = (string) $this->getTitle();
1095  $result['question'] = (string) ilRTE::_replaceMediaObjectImageSrc($this->getQuestion(), 0);
1096  $result['nr_of_tries'] = (int) $this->getNrOfTries();
1097  $result['shuffle'] = (bool) $this->getShuffle();
1098  $result['feedback'] = array(
1099  "onenotcorrect" => nl2br(ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackGeneric(0), 0)),
1100  "allcorrect" => nl2br(ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackGeneric(1), 0))
1101  );
1102  $answers = array();
1103  foreach ($this->getAnswers() as $key => $answer_obj)
1104  {
1105  array_push($answers, array(
1106  "answertext" => (string) $answer_obj->getAnswertext(),
1107  "points_checked" => (float) $answer_obj->getPointsChecked(),
1108  "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1109  "order" => (int) $answer_obj->getOrder(),
1110  "image" => $answer_obj->getImage(),
1111  "feedback" => ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackSingleAnswer($key), 0)
1112  ));
1113  }
1114  $result['answers'] = $answers;
1115  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1116  $result['mobs'] = $mobs;
1117  return json_encode($result);
1118  }
1119 
1120  public function removeAnswerImage($index)
1121  {
1122  $answer = $this->answers[$index];
1123  if (is_object($answer))
1124  {
1125  $this->deleteImage($answer->getImage());
1126  $answer->setImage('');
1127  }
1128  }
1129 
1131  {
1132  global $ilUser;
1133 
1134  $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1135  if ($multilineAnswerSetting != 1)
1136  {
1137  $multilineAnswerSetting = 0;
1138  }
1139  return $multilineAnswerSetting;
1140  }
1141 
1142  function setMultilineAnswerSetting($a_setting = 0)
1143  {
1144  global $ilUser;
1145  $ilUser->writePref("tst_multiline_answers", $a_setting);
1146  }
1147 }
1148 
1149 ?>