ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assSingleChoice.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 
70  function assSingleChoice(
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  foreach ($this->answers as $answer)
97  {
98  if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) return false;
99  }
100  return true;
101  }
102  else
103  {
104  return false;
105  }
106  }
107 
116  function saveToDb($original_id = "")
117  {
118  global $ilDB;
119 
120  $complete = 0;
121  if ($this->isComplete())
122  {
123  $complete = 1;
124  }
125  $estw_time = $this->getEstimatedWorkingTime();
126  $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
127 
128  if ($original_id)
129  {
130  $original_id = $ilDB->quote($original_id);
131  }
132  else
133  {
134  $original_id = "NULL";
135  }
136 
137  include_once("./Services/RTE/classes/class.ilRTE.php");
138  if ($this->id == -1)
139  {
140  // Neuen Datensatz schreiben
141  $now = getdate();
142  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
143 
144  $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)",
145  $ilDB->quote($this->getQuestionTypeID() . ""),
146  $ilDB->quote($this->obj_id),
147  $ilDB->quote($this->title),
148  $ilDB->quote($this->comment),
149  $ilDB->quote($this->author),
150  $ilDB->quote($this->owner),
151  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
152  $ilDB->quote($this->getMaximumPoints() . ""),
153  $ilDB->quote($estw_time),
154  $ilDB->quote("$complete"),
155  $ilDB->quote($created),
157  );
158  $result = $ilDB->query($query);
159  if (PEAR::isError($result))
160  {
161  global $ilias;
162  $ilias->raiseError($result->getMessage());
163  }
164  else
165  {
166  $this->id = $ilDB->getLastInsertId();
167  $query = sprintf("INSERT INTO qpl_question_singlechoice (question_fi, shuffle) VALUES (%s, %s)",
168  $ilDB->quote($this->id . ""),
169  $ilDB->quote("$this->shuffle")
170  );
171  $ilDB->query($query);
172 
173  // create page object of question
174  $this->createPageObject();
175 
176  if ($this->getTestId() > 0)
177  {
178  $this->insertIntoTest($this->getTestId());
179  }
180  }
181 
182  }
183  else
184  {
185  // Vorhandenen Datensatz aktualisieren
186  $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",
187  $ilDB->quote($this->obj_id. ""),
188  $ilDB->quote($this->title),
189  $ilDB->quote($this->comment),
190  $ilDB->quote($this->author),
191  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
192  $ilDB->quote($this->getMaximumPoints() . ""),
193  $ilDB->quote($estw_time),
194  $ilDB->quote("$complete"),
195  $ilDB->quote($this->id)
196  );
197  $result = $ilDB->query($query);
198  $query = sprintf("UPDATE qpl_question_singlechoice SET shuffle = %s WHERE question_fi = %s",
199  $ilDB->quote("$this->shuffle"),
200  $ilDB->quote($this->id . "")
201  );
202  $result = $ilDB->query($query);
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_singlechoice 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  $query = sprintf("INSERT INTO qpl_answer_singlechoice (answer_id, question_fi, answertext, points, aorder, imagefile) VALUES (NULL, %s, %s, %s, %s, %s)",
223  $ilDB->quote($this->id),
224  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0)),
225  $ilDB->quote($answer_obj->getPoints() . ""),
226  $ilDB->quote($answer_obj->getOrder() . ""),
227  $ilDB->quote($answer_obj->getImage() . "")
228  );
229  $answer_result = $ilDB->query($query);
230  }
231  }
233  }
234 
244  function loadFromDb($question_id)
245  {
246  global $ilDB;
247 
248  $hasimages = 0;
249  $query = sprintf("SELECT qpl_questions.*, qpl_question_singlechoice.* FROM qpl_questions, qpl_question_singlechoice WHERE question_id = %s AND qpl_questions.question_id = qpl_question_singlechoice.question_fi",
250  $ilDB->quote($question_id));
251  $result = $ilDB->query($query);
252  if ($result->numRows() == 1)
253  {
254  $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
255  $this->id = $question_id;
256  $this->title = $data->title;
257  $this->comment = $data->comment;
258  $this->solution_hint = $data->solution_hint;
259  $this->original_id = $data->original_id;
260  $this->obj_id = $data->obj_fi;
261  $this->author = $data->author;
262  $this->owner = $data->owner;
263  $this->points = $data->points;
264  include_once("./Services/RTE/classes/class.ilRTE.php");
265  $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
266  $this->setShuffle($data->shuffle);
267  $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
268 
269  $query = sprintf("SELECT * FROM qpl_answer_singlechoice WHERE question_fi = %s ORDER BY aorder ASC",
270  $ilDB->quote($question_id));
271 
272  $result = $ilDB->query($query);
273 
274  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
275  if ($result->numRows() > 0)
276  {
277  while ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
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  if (strlen($data->imagefile)) $hasimages = 1;
287  array_push($this->answers, new ASS_AnswerBinaryStateImage($data->answertext, $data->points, $data->aorder, 1, $data->imagefile));
288  }
289  }
290  }
291 
292  $this->setGraphicalAnswerSetting($hasimages);
293  parent::loadFromDb($question_id);
294  }
295 
303  function duplicate($for_test = true, $title = "", $author = "", $owner = "")
304  {
305  if ($this->id <= 0)
306  {
307  // The question has not been saved. It cannot be duplicated
308  return;
309  }
310  // duplicate the question in database
311  $this_id = $this->getId();
312  $clone = $this;
313  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
315  $clone->id = -1;
316  if ($title)
317  {
318  $clone->setTitle($title);
319  }
320 
321  if ($author)
322  {
323  $clone->setAuthor($author);
324  }
325  if ($owner)
326  {
327  $clone->setOwner($owner);
328  }
329 
330  if ($for_test)
331  {
332  $clone->saveToDb($original_id);
333  }
334  else
335  {
336  $clone->saveToDb();
337  }
338 
339  // copy question page content
340  $clone->copyPageOfQuestion($this_id);
341  // copy XHTML media objects
342  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
343  // duplicate the images
344  $clone->duplicateImages($this_id);
345  // duplicate the generic feedback
346  $clone->duplicateFeedbackGeneric($this_id);
347  // duplicate the answer specific feedback
348  $clone->duplicateFeedbackAnswer($this_id);
349 
350  return $clone->id;
351  }
352 
360  function copyObject($target_questionpool, $title = "")
361  {
362  if ($this->id <= 0)
363  {
364  // The question has not been saved. It cannot be duplicated
365  return;
366  }
367  // duplicate the question in database
368  $clone = $this;
369  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
371  $clone->id = -1;
372  $source_questionpool = $this->getObjId();
373  $clone->setObjId($target_questionpool);
374  if ($title)
375  {
376  $clone->setTitle($title);
377  }
378  $clone->saveToDb();
379 
380  // copy question page content
381  $clone->copyPageOfQuestion($original_id);
382  // copy XHTML media objects
383  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
384  // duplicate the image
385  $clone->copyImages($original_id, $source_questionpool);
386  // duplicate the generic feedback
387  $clone->duplicateFeedbackGeneric($original_id);
388  // duplicate the answer specific feedback
389  $clone->duplicateFeedbackAnswer($original_id);
390 
391  return $clone->id;
392  }
393 
403  function getOutputType()
404  {
405  return $this->output_type;
406  }
407 
418  {
419  $this->output_type = $output_type;
420  }
421 
437  function addAnswer(
438  $answertext = "",
439  $points = 0.0,
440  $points_unchecked = 0.0,
441  $order = 0,
442  $answerimage = ""
443  )
444  {
445  $found = -1;
446  foreach ($this->answers as $key => $value)
447  {
448  if ($value->getOrder() == $order)
449  {
450  $found = $order;
451  }
452  }
453  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
454  if ($found >= 0)
455  {
456  // Antwort einfĂĽgen
457  $answer = new ASS_AnswerBinaryStateImage($answertext, $points, $found, 1, $answerimage);
458  array_push($this->answers, $answer);
459  for ($i = $found + 1; $i < count($this->answers); $i++)
460  {
461  $this->answers[$i] = $this->answers[$i-1];
462  }
463  $this->answers[$found] = $answer;
464  }
465  else
466  {
467  // Anwort anhängen
468  $answer = new ASS_AnswerBinaryStateImage($answertext, $points, count($this->answers), 1, $answerimage);
469  array_push($this->answers, $answer);
470  }
471  }
472 
482  function getAnswerCount()
483  {
484  return count($this->answers);
485  }
486 
498  function getAnswer($index = 0)
499  {
500  if ($index < 0) return NULL;
501  if (count($this->answers) < 1) return NULL;
502  if ($index >= count($this->answers)) return NULL;
503 
504  return $this->answers[$index];
505  }
506 
517  function deleteAnswer($index = 0)
518  {
519  if ($index < 0) return;
520  if (count($this->answers) < 1) return;
521  if ($index >= count($this->answers)) return;
522  $answer = $this->answers[$index];
523  if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
524  unset($this->answers[$index]);
525  $this->answers = array_values($this->answers);
526  for ($i = 0; $i < count($this->answers); $i++)
527  {
528  if ($this->answers[$i]->getOrder() > $index)
529  {
530  $this->answers[$i]->setOrder($i);
531  }
532  }
533  }
534 
543  function flushAnswers()
544  {
545  $this->answers = array();
546  }
547 
556  function getMaximumPoints()
557  {
558  $points = 0;
559  foreach ($this->answers as $key => $value)
560  {
561  if ($value->getPoints() > $points)
562  {
563  $points = $value->getPoints();
564  }
565  }
566  return $points;
567  }
568 
580  function calculateReachedPoints($active_id, $pass = NULL)
581  {
582  global $ilDB;
583 
584  $found_values = array();
585  if (is_null($pass))
586  {
587  $pass = $this->getSolutionMaxPass($active_id);
588  }
589  $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
590  $ilDB->quote($active_id . ""),
591  $ilDB->quote($this->getId() . ""),
592  $ilDB->quote($pass . "")
593  );
594  $result = $ilDB->query($query);
595  while ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
596  {
597  if (strcmp($data->value1, "") != 0)
598  {
599  array_push($found_values, $data->value1);
600  }
601  }
602  $points = 0;
603  foreach ($this->answers as $key => $answer)
604  {
605  if (count($found_values) > 0)
606  {
607  if (in_array($key, $found_values))
608  {
609  $points += $answer->getPoints();
610  }
611  }
612  }
613 
614  $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
615  return $points;
616  }
617 
628  function saveWorkingData($active_id, $pass = NULL)
629  {
630  global $ilDB;
631  global $ilUser;
632 
633  if (is_null($pass))
634  {
635  include_once "./Modules/Test/classes/class.ilObjTest.php";
636  $pass = ilObjTest::_getPass($active_id);
637  }
638  $entered_values = 0;
639 
640  $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
641  $ilDB->quote($active_id . ""),
642  $ilDB->quote($this->getId() . ""),
643  $ilDB->quote($pass . "")
644  );
645  $result = $ilDB->query($query);
646  $row = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
647  $update = $row->solution_id;
648  if ($update)
649  {
650  if (strlen($_POST["multiple_choice_result"]))
651  {
652  $query = sprintf("UPDATE tst_solutions SET value1 = %s WHERE solution_id = %s",
653  $ilDB->quote($_POST["multiple_choice_result"]),
654  $ilDB->quote($update)
655  );
656  $result = $ilDB->query($query);
657  $entered_values++;
658  }
659  else
660  {
661  $query = sprintf("DELETE FROM tst_solutions WHERE solution_id = %s",
662  $ilDB->quote($update)
663  );
664  $result = $ilDB->query($query);
665  }
666  }
667  else
668  {
669  if (strlen($_POST["multiple_choice_result"]))
670  {
671  $query = sprintf("INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
672  $ilDB->quote($active_id),
673  $ilDB->quote($this->getId()),
674  $ilDB->quote($_POST["multiple_choice_result"]),
675  $ilDB->quote($pass . "")
676  );
677  $result = $ilDB->query($query);
678  $entered_values++;
679  }
680  }
681  if ($entered_values)
682  {
683  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
685  {
686  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
687  }
688  }
689  else
690  {
691  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
693  {
694  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
695  }
696  }
697  parent::saveWorkingData($active_id, $pass);
698  return true;
699  }
700 
709  {
710  global $ilDB;
711 
712  $feedback = "";
713 
714  // delete generic feedback of the original
715  $deletequery = sprintf("DELETE FROM qpl_feedback_singlechoice WHERE question_fi = %s",
716  $ilDB->quote($this->original_id . "")
717  );
718  $result = $ilDB->query($deletequery);
719 
720  // get generic feedback of the actual question
721  $query = sprintf("SELECT * FROM qpl_feedback_singlechoice WHERE question_fi = %s",
722  $ilDB->quote($this->getId() . "")
723  );
724  $result = $ilDB->query($query);
725 
726  // save generic feedback to the original
727  if ($result->numRows())
728  {
729  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
730  {
731  $duplicatequery = sprintf("INSERT INTO qpl_feedback_singlechoice VALUES (NULL, %s, %s, %s, NULL)",
732  $ilDB->quote($this->original_id . ""),
733  $ilDB->quote($row["answer"] . ""),
734  $ilDB->quote($row["feedback"] . "")
735  );
736  $duplicateresult = $ilDB->query($duplicatequery);
737  }
738  }
739  }
740 
741  function syncWithOriginal()
742  {
743  if ($this->getOriginalId())
744  {
745  $this->syncFeedbackSingleAnswers();
746  $this->syncImages();
748  }
749  }
750 
759  function getQuestionType()
760  {
761  return "assSingleChoice";
762  }
763 
773  {
774  return "qpl_question_singlechoice";
775  }
776 
786  {
787  return "qpl_answer_singlechoice";
788  }
789 
791  {
792  global $ilUser;
793 
794  $graphicalAnswerSetting = $ilUser->getPref("graphicalAnswerSetting");
795  if ($graphicalAnswerSetting != 1)
796  {
797  $graphicalAnswerSetting = 0;
798  }
799  return $graphicalAnswerSetting;
800  }
801 
802  function setGraphicalAnswerSetting($a_setting = 0)
803  {
804  global $ilUser;
805  $ilUser->writePref("graphicalAnswerSetting", $a_setting);
806  }
807 
818  function setImageFile($image_filename, $image_tempfilename = "")
819  {
820  $result = 0;
821  if (!empty($image_tempfilename))
822  {
823  $image_filename = str_replace(" ", "_", $image_filename);
824  $imagepath = $this->getImagePath();
825  if (!file_exists($imagepath))
826  {
827  ilUtil::makeDirParents($imagepath);
828  }
829  //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
830  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
831  {
832  $result = 2;
833  }
834  else
835  {
836  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
837  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
838  if (!preg_match("/^image/", $mimetype))
839  {
840  unlink($imagepath . $image_filename);
841  $result = 1;
842  }
843  else
844  {
845  // create thumbnail file
846  $thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
847  ilUtil::convertImage($imagepath.$image_filename, $thumbpath, "JPEG", 100);
848  }
849  }
850  }
851  return $result;
852  }
853 
862  function deleteImage($image_filename)
863  {
864  $imagepath = $this->getImagePath();
865  unlink($imagepath . $image_filename);
866  $thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
867  unlink($thumbpath);
868  }
869 
870  function duplicateImages($question_id)
871  {
872  global $ilLog;
873  $imagepath = $this->getImagePath();
874  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
875  foreach ($this->answers as $answer)
876  {
877  $filename = $answer->getImage();
878  if (strlen($filename))
879  {
880  if (!file_exists($imagepath))
881  {
882  ilUtil::makeDirParents($imagepath);
883  }
884  if (!copy($imagepath_original . $filename, $imagepath . $filename))
885  {
886  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
887  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
888  }
889  if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg"))
890  {
891  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
892  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
893  }
894  }
895  }
896  }
897 
898  function copyImages($question_id, $source_questionpool)
899  {
900  global $ilLog;
901  $imagepath = $this->getImagePath();
902  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
903  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
904  foreach ($this->answers as $answer)
905  {
906  $filename = $answer->getImage();
907  if (strlen($filename))
908  {
909  if (!file_exists($imagepath))
910  {
911  ilUtil::makeDirParents($imagepath);
912  }
913  if (!copy($imagepath_original . $filename, $imagepath . $filename))
914  {
915  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
916  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
917  }
918  if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg"))
919  {
920  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
921  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
922  }
923  }
924  }
925  }
926 
930  protected function syncImages()
931  {
932  global $ilLog;
933  $question_id = $this->getOriginalId();
934  $imagepath = $this->getImagePath();
935  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
936  ilUtil::delDir($imagepath_original);
937  foreach ($this->answers as $answer)
938  {
939  $filename = $answer->getImage();
940  if (strlen($filename))
941  {
942  if (!file_exists($imagepath))
943  {
944  ilUtil::makeDirParents($imagepath);
945  }
946  if (!file_exists($imagepath_original))
947  {
948  ilUtil::makeDirParents($imagepath_original);
949  }
950  if (@file_exists($imagepath . $filename))
951  {
952  if (!@copy($imagepath . $filename, $imagepath_original . $filename))
953  {
954  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
955  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
956  }
957  }
958  if (@file_exists($imagepath . $filename . ".thumb.jpg"))
959  {
960  if (!@copy($imagepath . $filename . ".thumb.jpg", $imagepath_original . $filename . ".thumb.jpg"))
961  {
962  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
963  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
964  }
965  }
966  }
967  }
968  }
969 
979  function saveFeedbackSingleAnswer($answer_index, $feedback)
980  {
981  global $ilDB;
982 
983  $query = sprintf("DELETE FROM qpl_feedback_singlechoice WHERE question_fi = %s AND answer = %s",
984  $ilDB->quote($this->getId() . ""),
985  $ilDB->quote($answer_index . "")
986  );
987  $result = $ilDB->query($query);
988  if (strlen($feedback))
989  {
990  include_once("./Services/RTE/classes/class.ilRTE.php");
991  $query = sprintf("INSERT INTO qpl_feedback_singlechoice VALUES (NULL, %s, %s, %s, NULL)",
992  $ilDB->quote($this->getId() . ""),
993  $ilDB->quote($answer_index . ""),
994  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($feedback, 0))
995  );
996  $result = $ilDB->query($query);
997  }
998  }
999 
1009  function getFeedbackSingleAnswer($answer_index)
1010  {
1011  global $ilDB;
1012 
1013  $feedback = "";
1014  $query = sprintf("SELECT * FROM qpl_feedback_singlechoice WHERE question_fi = %s AND answer = %s",
1015  $ilDB->quote($this->getId() . ""),
1016  $ilDB->quote($answer_index . "")
1017  );
1018  $result = $ilDB->query($query);
1019  if ($result->numRows())
1020  {
1021  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
1022  include_once("./Services/RTE/classes/class.ilRTE.php");
1023  $feedback = ilRTE::_replaceMediaObjectImageSrc($row["feedback"], 1);
1024  }
1025  return $feedback;
1026  }
1027 
1037  {
1038  global $ilDB;
1039 
1040  $feedback = "";
1041  $query = sprintf("SELECT * FROM qpl_feedback_singlechoice WHERE question_fi = %s",
1042  $ilDB->quote($original_id . "")
1043  );
1044  $result = $ilDB->query($query);
1045  if ($result->numRows())
1046  {
1047  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1048  {
1049  $duplicatequery = sprintf("INSERT INTO qpl_feedback_singlechoice VALUES (NULL, %s, %s, %s, NULL)",
1050  $ilDB->quote($this->getId() . ""),
1051  $ilDB->quote($row["answer"] . ""),
1052  $ilDB->quote($row["feedback"] . "")
1053  );
1054  $duplicateresult = $ilDB->query($duplicatequery);
1055  }
1056  }
1057  }
1058 
1064  {
1066  foreach ($this->answers as $index => $answer)
1067  {
1068  $text .= $this->getFeedbackSingleAnswer($index);
1069  $answer_obj = $this->answers[$index];
1070  $text .= $answer_obj->getAnswertext();
1071  }
1072  return $text;
1073  }
1074 
1078  function &getAnswers()
1079  {
1080  return $this->answers;
1081  }
1082 
1095  public function setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
1096  {
1097  include_once ("./classes/class.ilExcelUtils.php");
1098  $solution = $this->getSolutionValues($active_id, $pass);
1099  $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
1100  $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
1101  $i = 1;
1102  foreach ($this->getAnswers() as $id => $answer)
1103  {
1104  $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($answer->getAnswertext()), $format_bold);
1105  if ($id == $solution[0]["value1"])
1106  {
1107  $worksheet->write($startrow + $i, 1, 1);
1108  }
1109  else
1110  {
1111  $worksheet->write($startrow + $i, 1, 0);
1112  }
1113  $i++;
1114  }
1115  return $startrow + $i + 1;
1116  }
1117 }
1118 
1119 ?>