ILIAS  Release_3_10_x_branch Revision 61812
 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 
71  $title = "",
72  $comment = "",
73  $author = "",
74  $owner = -1,
75  $question = "",
77  )
78  {
80  $this->output_type = $output_type;
81  $this->answers = array();
82  }
83 
92  function isComplete()
93  {
94  if (($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
95  {
96  return true;
97  }
98  else
99  {
100  return false;
101  }
102  }
103 
112  function saveToDb($original_id = "")
113  {
114  global $ilDB;
115 
116  $complete = 0;
117  if ($this->isComplete())
118  {
119  $complete = 1;
120  }
121 
122  $estw_time = $this->getEstimatedWorkingTime();
123  $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
124 
125  if ($original_id)
126  {
127  $original_id = $ilDB->quote($original_id);
128  }
129  else
130  {
131  $original_id = "NULL";
132  }
133 
134  include_once("./Services/RTE/classes/class.ilRTE.php");
135 
136  if ($this->id == -1)
137  {
138  // Neuen Datensatz schreiben
139  $now = getdate();
140  $question_type = $this->getQuestionTypeID();
141  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
142  $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, points, working_time, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
143  $ilDB->quote($question_type),
144  $ilDB->quote($this->obj_id),
145  $ilDB->quote($this->title),
146  $ilDB->quote($this->comment),
147  $ilDB->quote($this->author),
148  $ilDB->quote($this->owner),
149  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
150  $ilDB->quote($this->getMaximumPoints() . ""),
151  $ilDB->quote($estw_time),
152  $ilDB->quote("$complete"),
153  $ilDB->quote($created),
155  );
156  $result = $ilDB->query($query);
157 
158  if (PEAR::isError($result))
159  {
160  global $ilias;
161  $ilias->raiseError($result->getMessage());
162  }
163  else
164  {
165  $this->id = $ilDB->getLastInsertId();
166  $query = sprintf("INSERT INTO qpl_question_multiplechoice (question_fi, shuffle) VALUES (%s, %s)",
167  $ilDB->quote($this->id . ""),
168  $ilDB->quote("$this->shuffle")
169  );
170  $ilDB->query($query);
171 
172  // create page object of question
173  $this->createPageObject();
174 
175  // Falls die Frage in einen Test eingefügt werden soll, auch diese Verbindung erstellen
176  if ($this->getTestId() > 0)
177  {
178  $this->insertIntoTest($this->getTestId());
179  }
180  }
181  }
182  else
183  {
184  // Vorhandenen Datensatz aktualisieren
185  $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s",
186  $ilDB->quote($this->obj_id. ""),
187  $ilDB->quote($this->title),
188  $ilDB->quote($this->comment),
189  $ilDB->quote($this->author),
190  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
191  $ilDB->quote($this->getMaximumPoints() . ""),
192  $ilDB->quote($estw_time),
193  $ilDB->quote("$complete"),
194  $ilDB->quote($this->id)
195  );
196  $result = $ilDB->query($query);
197  $query = sprintf("UPDATE qpl_question_multiplechoice SET shuffle = %s WHERE question_fi = %s",
198  $ilDB->quote("$this->shuffle"),
199  $ilDB->quote($this->id . "")
200  );
201  $result = $ilDB->query($query);
202  }
203 
204  if (PEAR::isError($result))
205  {
206  global $ilias;
207  $ilias->raiseError($result->getMessage());
208  }
209  else
210  {
211  // Antworten schreiben
212  // alte Antworten löschen
213  $query = sprintf("DELETE FROM qpl_answer_multiplechoice WHERE question_fi = %s",
214  $ilDB->quote($this->id)
215  );
216  $result = $ilDB->query($query);
217 
218  // Anworten wegschreiben
219  foreach ($this->answers as $key => $value)
220  {
221  $answer_obj = $this->answers[$key];
222 
223  $query = sprintf("INSERT INTO qpl_answer_multiplechoice (answer_id, question_fi, answertext, points, points_unchecked, aorder, imagefile) VALUES (NULL, %s, %s, %s, %s, %s, %s)",
224  $ilDB->quote($this->id),
225  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0)),
226  $ilDB->quote($answer_obj->getPoints() . ""),
227  $ilDB->quote($answer_obj->getPointsUnchecked() . ""),
228  $ilDB->quote($answer_obj->getOrder() . ""),
229  $ilDB->quote($answer_obj->getImage() . "")
230  );
231  $answer_result = $ilDB->query($query);
232  }
233  }
234 
236  }
237 
247  function loadFromDb($question_id)
248  {
249  global $ilDB;
250 
251  $hasimages = 0;
252  $query = sprintf("SELECT qpl_questions.*, qpl_question_multiplechoice.* FROM qpl_questions, qpl_question_multiplechoice WHERE question_id = %s AND qpl_questions.question_id = qpl_question_multiplechoice.question_fi",
253  $ilDB->quote($question_id));
254  $result = $ilDB->query($query);
255  if ($result->numRows() == 1)
256  {
257  $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
258  $this->id = $question_id;
259  $this->title = $data->title;
260  $this->comment = $data->comment;
261  $this->solution_hint = $data->solution_hint;
262  $this->original_id = $data->original_id;
263  $this->obj_id = $data->obj_fi;
264  $this->author = $data->author;
265  $this->owner = $data->owner;
266  $this->points = $data->points;
267  include_once("./Services/RTE/classes/class.ilRTE.php");
268  $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
269  $this->setShuffle($data->shuffle);
270  $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
271 
272  $query = sprintf("SELECT * FROM qpl_answer_multiplechoice WHERE question_fi = %s ORDER BY aorder ASC",
273  $ilDB->quote($question_id));
274 
275  $result = $ilDB->query($query);
276 
277  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
278  if ($result->numRows() > 0)
279  {
280  while ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
281  {
282  $imagefilename = $this->getImagePath() . $data->imagefile;
283  if (!@file_exists($imagefilename))
284  {
285  $data->imagefile = "";
286  }
287  include_once("./Services/RTE/classes/class.ilRTE.php");
288  $data->answertext = ilRTE::_replaceMediaObjectImageSrc($data->answertext, 1);
289  if (strlen($data->imagefile)) $hasimages = 1;
290  array_push($this->answers, new ASS_AnswerMultipleResponseImage($data->answertext, $data->points, $data->aorder, $data->points_unchecked, $data->imagefile));
291  }
292  }
293  }
294  $this->setGraphicalAnswerSetting($hasimages);
295  parent::loadFromDb($question_id);
296  }
297 
305  /*function addAnswer($answertext, $points, $answerorder, $correctness)
306  {
307  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryState.php";
308  array_push($this->answers, new ASS_AnswerBinaryState($answertext, $points, $answerorder, $correctness));
309  }*/
310 
318  function duplicate($for_test = true, $title = "", $author = "", $owner = "")
319  {
320  if ($this->id <= 0)
321  {
322  // The question has not been saved. It cannot be duplicated
323  return;
324  }
325  // duplicate the question in database
326  $this_id = $this->getId();
327  $clone = $this;
328  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
330  $clone->id = -1;
331  if ($title)
332  {
333  $clone->setTitle($title);
334  }
335 
336  if ($author)
337  {
338  $clone->setAuthor($author);
339  }
340  if ($owner)
341  {
342  $clone->setOwner($owner);
343  }
344 
345  if ($for_test)
346  {
347  $clone->saveToDb($original_id);
348  }
349  else
350  {
351  $clone->saveToDb();
352  }
353 
354  // copy question page content
355  $clone->copyPageOfQuestion($this_id);
356  // copy XHTML media objects
357  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
358  // duplicate the images
359  $clone->duplicateImages($this_id);
360  // duplicate the generic feedback
361  $clone->duplicateFeedbackGeneric($this_id);
362  // duplicate the answer specific feedback
363  $clone->duplicateFeedbackAnswer($this_id);
364 
365  return $clone->id;
366  }
367 
375  function copyObject($target_questionpool, $title = "")
376  {
377  if ($this->id <= 0)
378  {
379  // The question has not been saved. It cannot be duplicated
380  return;
381  }
382  // duplicate the question in database
383  $clone = $this;
384  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
386  $clone->id = -1;
387  $source_questionpool = $this->getObjId();
388  $clone->setObjId($target_questionpool);
389  if ($title)
390  {
391  $clone->setTitle($title);
392  }
393  $clone->saveToDb();
394 
395  // copy question page content
396  $clone->copyPageOfQuestion($original_id);
397  // copy XHTML media objects
398  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
399  // duplicate the image
400  $clone->copyImages($original_id, $source_questionpool);
401  // duplicate the generic feedback
402  $clone->duplicateFeedbackGeneric($original_id);
403  // duplicate the answer specific feedback
404  $clone->duplicateFeedbackAnswer($original_id);
405 
406  return $clone->id;
407  }
408 
418  function getOutputType()
419  {
420  return $this->output_type;
421  }
422 
433  {
434  $this->output_type = $output_type;
435  }
436 
452  function addAnswer(
453  $answertext = "",
454  $points = 0.0,
455  $points_unchecked = 0.0,
456  $order = 0,
457  $answerimage = ""
458  )
459  {
460  $found = -1;
461  foreach ($this->answers as $key => $value)
462  {
463  if ($value->getOrder() == $order)
464  {
465  $found = $order;
466  }
467  }
468  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
469  if ($found >= 0)
470  {
471  // Antwort einfügen
472  $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, $found, $points_unchecked, $answerimage);
473  array_push($this->answers, $answer);
474  for ($i = $found + 1; $i < count($this->answers); $i++)
475  {
476  $this->answers[$i] = $this->answers[$i-1];
477  }
478  $this->answers[$found] = $answer;
479  }
480  else
481  {
482  // Anwort anhängen
483  $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, count($this->answers), $points_unchecked, $answerimage);
484  array_push($this->answers, $answer);
485  }
486  }
487 
497  function getAnswerCount()
498  {
499  return count($this->answers);
500  }
501 
513  function getAnswer($index = 0)
514  {
515  if ($index < 0) return NULL;
516  if (count($this->answers) < 1) return NULL;
517  if ($index >= count($this->answers)) return NULL;
518 
519  return $this->answers[$index];
520  }
521 
532  function deleteAnswer($index = 0)
533  {
534  if ($index < 0) return;
535  if (count($this->answers) < 1) return;
536  if ($index >= count($this->answers)) return;
537  $answer = $this->answers[$index];
538  if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
539  unset($this->answers[$index]);
540  $this->answers = array_values($this->answers);
541  for ($i = 0; $i < count($this->answers); $i++)
542  {
543  if ($this->answers[$i]->getOrder() > $index)
544  {
545  $this->answers[$i]->setOrder($i);
546  }
547  }
548  }
549 
558  function flushAnswers()
559  {
560  $this->answers = array();
561  }
562 
571  function getMaximumPoints()
572  {
573  $points = 0;
574  $allpoints = 0;
575  foreach ($this->answers as $key => $value)
576  {
577  if ($value->getPoints() > $value->getPointsUnchecked())
578  {
579  $allpoints += $value->getPoints();
580  }
581  else
582  {
583  $allpoints += $value->getPointsUnchecked();
584  }
585  }
586  return $allpoints;
587  }
588 
600  function calculateReachedPoints($active_id, $pass = NULL)
601  {
602  global $ilDB;
603 
604  $found_values = array();
605  if (is_null($pass))
606  {
607  $pass = $this->getSolutionMaxPass($active_id);
608  }
609  $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
610  $ilDB->quote($active_id . ""),
611  $ilDB->quote($this->getId() . ""),
612  $ilDB->quote($pass . "")
613  );
614  $result = $ilDB->query($query);
615  while ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
616  {
617  if (strcmp($data->value1, "") != 0)
618  {
619  array_push($found_values, $data->value1);
620  }
621  }
622  $points = 0;
623  foreach ($this->answers as $key => $answer)
624  {
625  if (in_array($key, $found_values))
626  {
627  $points += $answer->getPoints();
628  }
629  else
630  {
631  $points += $answer->getPointsUnchecked();
632  }
633  }
634  include_once "./Modules/Test/classes/class.ilObjTest.php";
635  $mc_scoring = ilObjTest::_getMCScoring($active_id);
636  if (($mc_scoring == 0) && (count($found_values) == 0))
637  {
638  $points = 0;
639  }
640  $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
641  return $points;
642  }
643 
654  function saveWorkingData($active_id, $pass = NULL)
655  {
656  global $ilDB;
657  global $ilUser;
658 
659  if (is_null($pass))
660  {
661  include_once "./Modules/Test/classes/class.ilObjTest.php";
662  $pass = ilObjTest::_getPass($active_id);
663  }
664 
665  $entered_values = 0;
666  $query = sprintf("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
667  $ilDB->quote($active_id . ""),
668  $ilDB->quote($this->getId() . ""),
669  $ilDB->quote($pass . "")
670  );
671  $result = $ilDB->query($query);
672  foreach ($_POST as $key => $value)
673  {
674  if (preg_match("/^multiple_choice_result_(\d+)/", $key, $matches))
675  {
676  if (strlen($value))
677  {
678  $query = sprintf("INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
679  $ilDB->quote($active_id),
680  $ilDB->quote($this->getId()),
681  $ilDB->quote($value),
682  $ilDB->quote($pass . "")
683  );
684  $result = $ilDB->query($query);
685  $entered_values++;
686  }
687  }
688  }
689  if ($entered_values)
690  {
691  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
693  {
694  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
695  }
696  }
697  else
698  {
699  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
701  {
702  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
703  }
704  }
705  parent::saveWorkingData($active_id, $pass);
706  return true;
707  }
708 
717  {
718  global $ilDB;
719 
720  $feedback = "";
721 
722  // delete generic feedback of the original
723  $deletequery = sprintf("DELETE FROM qpl_feedback_multiplechoice WHERE question_fi = %s",
724  $ilDB->quote($this->original_id . "")
725  );
726  $result = $ilDB->query($deletequery);
727 
728  // get generic feedback of the actual question
729  $query = sprintf("SELECT * FROM qpl_feedback_multiplechoice WHERE question_fi = %s",
730  $ilDB->quote($this->getId() . "")
731  );
732  $result = $ilDB->query($query);
733 
734  // save generic feedback to the original
735  if ($result->numRows())
736  {
737  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
738  {
739  $duplicatequery = sprintf("INSERT INTO qpl_feedback_multiplechoice VALUES (NULL, %s, %s, %s, NULL)",
740  $ilDB->quote($this->original_id . ""),
741  $ilDB->quote($row["answer"] . ""),
742  $ilDB->quote($row["feedback"] . "")
743  );
744  $duplicateresult = $ilDB->query($duplicatequery);
745  }
746  }
747  }
748 
749  function syncWithOriginal()
750  {
751  if ($this->getOriginalId())
752  {
753  $this->syncFeedbackSingleAnswers();
754  $this->syncImages();
756  }
757  }
758 
767  function getQuestionType()
768  {
769  return "assMultipleChoice";
770  }
771 
781  {
782  return "qpl_question_multiplechoice";
783  }
784 
794  {
795  return "qpl_answer_multiplechoice";
796  }
797 
799  {
800  global $ilUser;
801 
802  $graphicalAnswerSetting = $ilUser->getPref("graphicalAnswerSetting");
803  if ($graphicalAnswerSetting != 1)
804  {
805  $graphicalAnswerSetting = 0;
806  }
807  return $graphicalAnswerSetting;
808  }
809 
810  function setGraphicalAnswerSetting($a_setting = 0)
811  {
812  global $ilUser;
813  $ilUser->writePref("graphicalAnswerSetting", $a_setting);
814  }
815 
826  function setImageFile($image_filename, $image_tempfilename = "")
827  {
828  $result = 0;
829  if (!empty($image_tempfilename))
830  {
831  $image_filename = str_replace(" ", "_", $image_filename);
832  $imagepath = $this->getImagePath();
833  if (!file_exists($imagepath))
834  {
835  ilUtil::makeDirParents($imagepath);
836  }
837  //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
838  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
839  {
840  $result = 2;
841  }
842  else
843  {
844  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
845  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
846  if (!preg_match("/^image/", $mimetype))
847  {
848  unlink($imagepath . $image_filename);
849  $result = 1;
850  }
851  else
852  {
853  // create thumbnail file
854  $thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
855  ilUtil::convertImage($imagepath.$image_filename, $thumbpath, "JPEG", 100);
856  }
857  }
858  }
859  return $result;
860  }
861 
870  function deleteImage($image_filename)
871  {
872  $imagepath = $this->getImagePath();
873  unlink($imagepath . $image_filename);
874  $thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
875  unlink($thumbpath);
876  }
877 
878  function duplicateImages($question_id)
879  {
880  global $ilLog;
881  $imagepath = $this->getImagePath();
882  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
883  foreach ($this->answers as $answer)
884  {
885  $filename = $answer->getImage();
886  if (strlen($filename))
887  {
888  if (!file_exists($imagepath))
889  {
890  ilUtil::makeDirParents($imagepath);
891  }
892  if (!copy($imagepath_original . $filename, $imagepath . $filename))
893  {
894  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
895  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
896  }
897  if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg"))
898  {
899  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
900  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
901  }
902  }
903  }
904  }
905 
906  function copyImages($question_id, $source_questionpool)
907  {
908  global $ilLog;
909  $imagepath = $this->getImagePath();
910  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
911  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
912  foreach ($this->answers as $answer)
913  {
914  $filename = $answer->getImage();
915  if (strlen($filename))
916  {
917  if (!file_exists($imagepath))
918  {
919  ilUtil::makeDirParents($imagepath);
920  }
921  if (!copy($imagepath_original . $filename, $imagepath . $filename))
922  {
923  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
924  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
925  }
926  if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg"))
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 
938  protected function syncImages()
939  {
940  global $ilLog;
941  $question_id = $this->getOriginalId();
942  $imagepath = $this->getImagePath();
943  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
944  ilUtil::delDir($imagepath_original);
945  foreach ($this->answers as $answer)
946  {
947  $filename = $answer->getImage();
948  if (strlen($filename))
949  {
950  if (!file_exists($imagepath))
951  {
952  ilUtil::makeDirParents($imagepath);
953  }
954  if (!file_exists($imagepath_original))
955  {
956  ilUtil::makeDirParents($imagepath_original);
957  }
958  if (@file_exists($imagepath . $filename))
959  {
960  if (!@copy($imagepath . $filename, $imagepath_original . $filename))
961  {
962  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
963  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
964  }
965  }
966  if (@file_exists($imagepath . $filename . ".thumb.jpg"))
967  {
968  if (!@copy($imagepath . $filename . ".thumb.jpg", $imagepath_original . $filename . ".thumb.jpg"))
969  {
970  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
971  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
972  }
973  }
974  }
975  }
976  }
977 
987  function saveFeedbackSingleAnswer($answer_index, $feedback)
988  {
989  global $ilDB;
990 
991  $query = sprintf("DELETE FROM qpl_feedback_multiplechoice WHERE question_fi = %s AND answer = %s",
992  $ilDB->quote($this->getId() . ""),
993  $ilDB->quote($answer_index . "")
994  );
995  $result = $ilDB->query($query);
996  if (strlen($feedback))
997  {
998  include_once("./Services/RTE/classes/class.ilRTE.php");
999  $query = sprintf("INSERT INTO qpl_feedback_multiplechoice VALUES (NULL, %s, %s, %s, NULL)",
1000  $ilDB->quote($this->getId() . ""),
1001  $ilDB->quote($answer_index . ""),
1002  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($feedback, 0))
1003  );
1004  $result = $ilDB->query($query);
1005  }
1006  }
1007 
1017  function getFeedbackSingleAnswer($answer_index)
1018  {
1019  global $ilDB;
1020 
1021  $feedback = "";
1022  $query = sprintf("SELECT * FROM qpl_feedback_multiplechoice WHERE question_fi = %s AND answer = %s",
1023  $ilDB->quote($this->getId() . ""),
1024  $ilDB->quote($answer_index . "")
1025  );
1026  $result = $ilDB->query($query);
1027  if ($result->numRows())
1028  {
1029  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
1030  include_once("./Services/RTE/classes/class.ilRTE.php");
1031  $feedback = ilRTE::_replaceMediaObjectImageSrc($row["feedback"], 1);
1032  }
1033  return $feedback;
1034  }
1035 
1045  {
1046  global $ilDB;
1047 
1048  $feedback = "";
1049  $query = sprintf("SELECT * FROM qpl_feedback_multiplechoice WHERE question_fi = %s",
1050  $ilDB->quote($original_id . "")
1051  );
1052  $result = $ilDB->query($query);
1053  if ($result->numRows())
1054  {
1055  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1056  {
1057  $duplicatequery = sprintf("INSERT INTO qpl_feedback_multiplechoice VALUES (NULL, %s, %s, %s, NULL)",
1058  $ilDB->quote($this->getId() . ""),
1059  $ilDB->quote($row["answer"] . ""),
1060  $ilDB->quote($row["feedback"] . "")
1061  );
1062  $duplicateresult = $ilDB->query($duplicatequery);
1063  }
1064  }
1065  }
1066 
1072  {
1074  foreach ($this->answers as $index => $answer)
1075  {
1076  $text .= $this->getFeedbackSingleAnswer($index);
1077  $answer_obj = $this->answers[$index];
1078  $text .= $answer_obj->getAnswertext();
1079  }
1080  return $text;
1081  }
1082 
1086  function &getAnswers()
1087  {
1088  return $this->answers;
1089  }
1090 
1103  public function setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
1104  {
1105  include_once ("./classes/class.ilExcelUtils.php");
1106  $solution = $this->getSolutionValues($active_id, $pass);
1107  $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
1108  $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
1109  $i = 1;
1110  foreach ($this->getAnswers() as $id => $answer)
1111  {
1112  $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($answer->getAnswertext()), $format_bold);
1113  $checked = FALSE;
1114  foreach ($solution as $solutionvalue)
1115  {
1116  if ($id == $solutionvalue["value1"])
1117  {
1118  $checked = TRUE;
1119  }
1120  }
1121  if ($checked)
1122  {
1123  $worksheet->write($startrow + $i, 1, 1);
1124  }
1125  else
1126  {
1127  $worksheet->write($startrow + $i, 1, 0);
1128  }
1129  $i++;
1130  }
1131  return $startrow + $i + 1;
1132  }
1133 }
1134 
1135 ?>