ILIAS  eassessment Revision 61809
 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 
61  protected $thumb_size;
62 
77  function __construct(
78  $title = "",
79  $comment = "",
80  $author = "",
81  $owner = -1,
82  $question = "",
84  )
85  {
87  $this->thumb_size = 150;
88  $this->output_type = $output_type;
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  foreach ($this->answers as $answer)
104  {
105  if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) return false;
106  }
107  return true;
108  }
109  else
110  {
111  return false;
112  }
113  }
114 
121  function saveToDb($original_id = "")
122  {
123  global $ilDB;
124 
126 
127  $oldthumbsize = 0;
128  if ($this->isSingleline && ($this->getThumbSize()))
129  {
130  // get old thumbnail size
131  $result = $ilDB->queryF("SELECT thumb_size FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
132  array("integer"),
133  array($this->getId())
134  );
135  if ($result->numRows() == 1)
136  {
137  $data = $ilDB->fetchAssoc($result);
138  $oldthumbsize = $data['thumb_size'];
139  }
140  }
141  if (!$this->isSingleline)
142  {
143  ilUtil::delDir($this->getImagePath());
144  }
145 
146  // save additional data
147  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
148  array("integer"),
149  array($this->getId())
150  );
151 
152  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
153  array("integer", "text", "text", "integer"),
154  array(
155  $this->getId(),
156  $this->getShuffle(),
157  ($this->isSingleline) ? "0" : "1",
158  (strlen($this->getThumbSize()) == 0) ? null : $this->getThumbSize()
159  )
160  );
161 
162  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_sc WHERE question_fi = %s",
163  array('integer'),
164  array($this->getId())
165  );
166 
167  foreach ($this->answers as $key => $value)
168  {
169  $answer_obj = $this->answers[$key];
170  $next_id = $ilDB->nextId('qpl_a_sc');
171  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_sc (answer_id, question_fi, answertext, points, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
172  array('integer','integer','text','float','integer','text','integer'),
173  array(
174  $next_id,
175  $this->getId(),
176  ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0),
177  $answer_obj->getPoints(),
178  $answer_obj->getOrder(),
179  $answer_obj->getImage(),
180  time()
181  )
182  );
183  }
184 
185  $this->rebuildThumbnails();
187  }
188 
189  /*
190  * Rebuild the thumbnail images with a new thumbnail size
191  */
192  protected function rebuildThumbnails()
193  {
194  if ($this->isSingleline && ($this->getThumbSize()))
195  {
196  foreach ($this->getAnswers() as $answer)
197  {
198  if (strlen($answer->getImage()))
199  {
200  $this->generateThumbForFile($this->getImagePath(), $answer->getImage());
201  }
202  }
203  }
204  }
205 
206  public function getThumbPrefix()
207  {
208  return "thumb.";
209  }
210 
211  protected function generateThumbForFile($path, $file)
212  {
213  $filename = $path . $file;
214  if (@file_exists($filename))
215  {
216  $thumbpath = $path . $this->getThumbPrefix() . $file;
217  $path_info = @pathinfo($filename);
218  $ext = "";
219  switch (strtoupper($path_info['extension']))
220  {
221  case 'PNG':
222  $ext = 'PNG';
223  break;
224  case 'GIF':
225  $ext = 'GIF';
226  break;
227  default:
228  $ext = 'JPEG';
229  break;
230  }
231  ilUtil::convertImage($filename, $thumbpath, $ext, $this->getThumbSize());
232  }
233  }
234 
242  function loadFromDb($question_id)
243  {
244  global $ilDB;
245 
246  $hasimages = 0;
247 
248  $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",
249  array("integer"),
250  array($question_id)
251  );
252  if ($result->numRows() == 1)
253  {
254  $data = $ilDB->fetchAssoc($result);
255  $this->setId($question_id);
256  $this->setObjId($data["obj_fi"]);
257  $this->setTitle($data["title"]);
258  $this->setNrOfTries($data['nr_of_tries']);
259  $this->setComment($data["description"]);
260  $this->setOriginalId($data["original_id"]);
261  $this->setAuthor($data["author"]);
262  $this->setPoints($data["points"]);
263  $this->setOwner($data["owner"]);
264  include_once("./Services/RTE/classes/class.ilRTE.php");
265  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
266  $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
267  $this->setShuffle($shuffle);
268  $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
269  $this->setThumbSize($data['thumb_size']);
270  $this->isSingleline = ($data['allow_images']) ? false : true;
271  $this->lastChange = $data['tstamp'];
272  }
273 
274  $result = $ilDB->queryF("SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
275  array('integer'),
276  array($question_id)
277  );
278  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
279  if ($result->numRows() > 0)
280  {
281  while ($data = $ilDB->fetchAssoc($result))
282  {
283  $imagefilename = $this->getImagePath() . $data["imagefile"];
284  if (!@file_exists($imagefilename))
285  {
286  $data["imagefile"] = "";
287  }
288  include_once("./Services/RTE/classes/class.ilRTE.php");
289  $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"], 1);
290  array_push($this->answers, new ASS_AnswerBinaryStateImage($data["answertext"], $data["points"], $data["aorder"], 1, $data["imagefile"]));
291  }
292  }
293 
294  parent::loadFromDb($question_id);
295  }
296 
302  function duplicate($for_test = true, $title = "", $author = "", $owner = "")
303  {
304  if ($this->id <= 0)
305  {
306  // The question has not been saved. It cannot be duplicated
307  return;
308  }
309  // duplicate the question in database
310  $this_id = $this->getId();
311  $clone = $this;
312  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
314  $clone->id = -1;
315  if ($title)
316  {
317  $clone->setTitle($title);
318  }
319 
320  if ($author)
321  {
322  $clone->setAuthor($author);
323  }
324  if ($owner)
325  {
326  $clone->setOwner($owner);
327  }
328  if ($for_test)
329  {
330  $clone->saveToDb($original_id);
331  }
332  else
333  {
334  $clone->saveToDb();
335  }
336 
337  // copy question page content
338  $clone->copyPageOfQuestion($this_id);
339 
340  // copy XHTML media objects
341  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
342  // duplicate the images
343  $clone->duplicateImages($this_id);
344  // duplicate the generic feedback
345  $clone->duplicateFeedbackGeneric($this_id);
346  // duplicate the answer specific feedback
347  $clone->duplicateFeedbackAnswer($this_id);
348  $clone->onDuplicate($this_id);
349 
350  return $clone->id;
351  }
352 
358  function copyObject($target_questionpool, $title = "")
359  {
360  if ($this->id <= 0)
361  {
362  // The question has not been saved. It cannot be duplicated
363  return;
364  }
365  // duplicate the question in database
366  $clone = $this;
367  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
369  $clone->id = -1;
370  $source_questionpool = $this->getObjId();
371  $clone->setObjId($target_questionpool);
372  if ($title)
373  {
374  $clone->setTitle($title);
375  }
376  $clone->saveToDb();
377  // copy question page content
378  $clone->copyPageOfQuestion($original_id);
379  // copy XHTML media objects
380  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
381  // duplicate the image
382  $clone->copyImages($original_id, $source_questionpool);
383  // duplicate the generic feedback
384  $clone->duplicateFeedbackGeneric($original_id);
385  // duplicate the answer specific feedback
386  $clone->duplicateFeedbackAnswer($original_id);
387  $clone->onCopy($this->getObjId(), $this->getId());
388 
389  return $clone->id;
390  }
391 
399  function getOutputType()
400  {
401  return $this->output_type;
402  }
403 
412  {
413  $this->output_type = $output_type;
414  }
415 
429  function addAnswer(
430  $answertext = "",
431  $points = 0.0,
432  $order = 0,
433  $answerimage = ""
434  )
435  {
436  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
437  if (array_key_exists($order, $this->answers))
438  {
439  // insert answer
440  $answer = new ASS_AnswerBinaryStateImage($answertext, $points, $order, 1, $answerimage);
441  $newchoices = array();
442  for ($i = 0; $i < $order; $i++)
443  {
444  array_push($newchoices, $this->answers[$i]);
445  }
446  array_push($newchoices, $answer);
447  for ($i = $order; $i < count($this->answers); $i++)
448  {
449  $changed = $this->answers[$i];
450  $changed->setOrder($i+1);
451  array_push($newchoices, $changed);
452  }
453  $this->answers = $newchoices;
454  }
455  else
456  {
457  // add answer
458  $answer = new ASS_AnswerBinaryStateImage($answertext, $points, count($this->answers), 1, $answerimage);
459  array_push($this->answers, $answer);
460  }
461  }
462 
470  function getAnswerCount()
471  {
472  return count($this->answers);
473  }
474 
484  function getAnswer($index = 0)
485  {
486  if ($index < 0) return NULL;
487  if (count($this->answers) < 1) return NULL;
488  if ($index >= count($this->answers)) return NULL;
489 
490  return $this->answers[$index];
491  }
492 
501  function deleteAnswer($index = 0)
502  {
503  if ($index < 0) return;
504  if (count($this->answers) < 1) return;
505  if ($index >= count($this->answers)) return;
506  $answer = $this->answers[$index];
507  if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
508  unset($this->answers[$index]);
509  $this->answers = array_values($this->answers);
510  for ($i = 0; $i < count($this->answers); $i++)
511  {
512  if ($this->answers[$i]->getOrder() > $index)
513  {
514  $this->answers[$i]->setOrder($i);
515  }
516  }
517  }
518 
525  function flushAnswers()
526  {
527  $this->answers = array();
528  }
529 
536  function getMaximumPoints()
537  {
538  $points = 0;
539  foreach ($this->answers as $key => $value)
540  {
541  if ($value->getPoints() > $points)
542  {
543  $points = $value->getPoints();
544  }
545  }
546  return $points;
547  }
548 
558  function calculateReachedPoints($active_id, $pass = NULL)
559  {
560  global $ilDB;
561 
562  $found_values = array();
563  if (is_null($pass))
564  {
565  $pass = $this->getSolutionMaxPass($active_id);
566  }
567  $result = $ilDB->queryF("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
568  array('integer','integer','integer'),
569  array($active_id, $this->getId(), $pass)
570  );
571  while ($data = $ilDB->fetchAssoc($result))
572  {
573  if (strcmp($data["value1"], "") != 0)
574  {
575  array_push($found_values, $data["value1"]);
576  }
577  }
578  $points = 0;
579  foreach ($this->answers as $key => $answer)
580  {
581  if (count($found_values) > 0)
582  {
583  if (in_array($key, $found_values))
584  {
585  $points += $answer->getPoints();
586  }
587  }
588  }
589 
590  $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
591  return $points;
592  }
593 
602  function saveWorkingData($active_id, $pass = NULL)
603  {
604  global $ilDB;
605  global $ilUser;
606 
607  if (is_null($pass))
608  {
609  include_once "./Modules/Test/classes/class.ilObjTest.php";
610  $pass = ilObjTest::_getPass($active_id);
611  }
612  $entered_values = 0;
613 
614  $result = $ilDB->queryF("SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
615  array('integer','integer','integer'),
616  array($active_id, $this->getId(), $pass)
617  );
618  $row = $ilDB->fetchAssoc($result);
619  $update = $row["solution_id"];
620 
621  if ($update)
622  {
623  if (strlen($_POST["multiple_choice_result"]))
624  {
625  $affectedRows = $ilDB->update("tst_solutions", array(
626  "value1" => array("clob", $_POST["multiple_choice_result"]),
627  "tstamp" => array("integer", time())
628  ), array(
629  "solution_id" => array("integer", $update)
630  ));
631  $entered_values++;
632  }
633  else
634  {
635  $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE solution_id = %s",
636  array('integer'),
637  array($update)
638  );
639  }
640  }
641  else
642  {
643  if (strlen($_POST["multiple_choice_result"]))
644  {
645  $next_id = $ilDB->nextId('tst_solutions');
646  $affectedRows = $ilDB->insert("tst_solutions", array(
647  "solution_id" => array("integer", $next_id),
648  "active_fi" => array("integer", $active_id),
649  "question_fi" => array("integer", $this->getId()),
650  "value1" => array("clob", $_POST['multiple_choice_result']),
651  "value2" => array("clob", null),
652  "pass" => array("integer", $pass),
653  "tstamp" => array("integer", time())
654  ));
655  $entered_values++;
656  }
657  }
658  if ($entered_values)
659  {
660  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
662  {
663  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
664  }
665  }
666  else
667  {
668  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
670  {
671  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
672  }
673  }
674  parent::saveWorkingData($active_id, $pass);
675  return true;
676  }
677 
684  {
685  global $ilDB;
686 
687  $feedback = "";
688 
689  // delete generic feedback of the original
690  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_fb_sc WHERE question_fi = %s",
691  array('integer'),
692  array($this->original_id)
693  );
694 
695  // get generic feedback of the actual question
696  $result = $ilDB->queryF("SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
697  array('integer'),
698  array($this->getId())
699  );
700 
701  // save generic feedback to the original
702  if ($result->numRows())
703  {
704  while ($row = $ilDB->fetchAssoc($result))
705  {
706  $next_id = $ilDB->nextId('qpl_fb_sc');
707  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_fb_sc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
708  array('integer','integer','integer','text','integer'),
709  array(
710  $next_id,
711  $this->original_id,
712  $row["answer"],
713  $row["feedback"],
714  time()
715  )
716  );
717  }
718  }
719  }
720 
721  function syncWithOriginal()
722  {
723  if ($this->getOriginalId())
724  {
725  $this->syncFeedbackSingleAnswers();
726  $this->syncImages();
728  }
729  }
730 
737  function getQuestionType()
738  {
739  return "assSingleChoice";
740  }
741 
749  {
750  return "qpl_qst_sc";
751  }
752 
760  {
761  return "qpl_a_sc";
762  }
763 
772  function setImageFile($image_filename, $image_tempfilename = "")
773  {
774  $result = 0;
775  if (!empty($image_tempfilename))
776  {
777  $image_filename = str_replace(" ", "_", $image_filename);
778  $imagepath = $this->getImagePath();
779  if (!file_exists($imagepath))
780  {
781  ilUtil::makeDirParents($imagepath);
782  }
783  //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
784  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
785  {
786  $result = 2;
787  }
788  else
789  {
790  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
791  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
792  if (!preg_match("/^image/", $mimetype))
793  {
794  unlink($imagepath . $image_filename);
795  $result = 1;
796  }
797  else
798  {
799  // create thumbnail file
800  if ($this->isSingleline && ($this->getThumbSize()))
801  {
802  $this->generateThumbForFile($imagepath, $image_filename);
803  }
804  }
805  }
806  }
807  return $result;
808  }
809 
816  function deleteImage($image_filename)
817  {
818  $imagepath = $this->getImagePath();
819  @unlink($imagepath . $image_filename);
820  $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
821  @unlink($thumbpath);
822  }
823 
824  function duplicateImages($question_id)
825  {
826  global $ilLog;
827  $imagepath = $this->getImagePath();
828  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
829  foreach ($this->answers as $answer)
830  {
831  $filename = $answer->getImage();
832  if (strlen($filename))
833  {
834  if (!file_exists($imagepath))
835  {
836  ilUtil::makeDirParents($imagepath);
837  }
838  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
839  {
840  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
841  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
842  }
843  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
844  {
845  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
846  {
847  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
848  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
849  }
850  }
851  }
852  }
853  }
854 
855  function copyImages($question_id, $source_questionpool)
856  {
857  global $ilLog;
858  $imagepath = $this->getImagePath();
859  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
860  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
861  foreach ($this->answers as $answer)
862  {
863  $filename = $answer->getImage();
864  if (strlen($filename))
865  {
866  if (!file_exists($imagepath))
867  {
868  ilUtil::makeDirParents($imagepath);
869  }
870  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
871  {
872  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
873  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
874  }
875  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
876  {
877  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
878  {
879  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
880  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
881  }
882  }
883  }
884  }
885  }
886 
890  protected function syncImages()
891  {
892  global $ilLog;
893  $question_id = $this->getOriginalId();
894  $imagepath = $this->getImagePath();
895  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
896  ilUtil::delDir($imagepath_original);
897  foreach ($this->answers as $answer)
898  {
899  $filename = $answer->getImage();
900  if (strlen($filename))
901  {
902  if (@file_exists($imagepath . $filename))
903  {
904  if (!file_exists($imagepath))
905  {
906  ilUtil::makeDirParents($imagepath);
907  }
908  if (!file_exists($imagepath_original))
909  {
910  ilUtil::makeDirParents($imagepath_original);
911  }
912  if (!@copy($imagepath . $filename, $imagepath_original . $filename))
913  {
914  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
915  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
916  }
917  }
918  if (@file_exists($imagepath . $this->getThumbPrefix() . $filename))
919  {
920  if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename))
921  {
922  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
923  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
924  }
925  }
926  }
927  }
928  }
929 
937  function saveFeedbackSingleAnswer($answer_index, $feedback)
938  {
939  global $ilDB;
940 
941  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
942  array('integer','integer'),
943  array($this->getId(), $answer_index)
944  );
945  if (strlen($feedback))
946  {
947  include_once("./Services/RTE/classes/class.ilRTE.php");
948  $next_id = $ilDB->nextId('qpl_fb_sc');
949  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_fb_sc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
950  array('integer','integer','integer','text','integer'),
951  array(
952  $next_id,
953  $this->getId(),
954  $answer_index,
956  time()
957  )
958  );
959  }
960  }
961 
969  function getFeedbackSingleAnswer($answer_index)
970  {
971  global $ilDB;
972 
973  $feedback = "";
974  $result = $ilDB->queryF("SELECT * FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
975  array('integer','integer'),
976  array($this->getId(), $answer_index)
977  );
978  if ($result->numRows())
979  {
980  $row = $ilDB->fetchAssoc($result);
981  include_once("./Services/RTE/classes/class.ilRTE.php");
982  $feedback = ilRTE::_replaceMediaObjectImageSrc($row["feedback"], 1);
983  }
984  return $feedback;
985  }
986 
994  {
995  global $ilDB;
996 
997  $feedback = "";
998  $result = $ilDB->queryF("SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
999  array('integer'),
1000  array($original_id)
1001  );
1002  if ($result->numRows())
1003  {
1004  while ($row = $ilDB->fetchAssoc($result))
1005  {
1006  $next_id = $ilDB->nextId('qpl_fb_sc');
1007  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_fb_sc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
1008  array('integer','integer','integer','text','integer'),
1009  array(
1010  $next_id,
1011  $this->getId(),
1012  $row["answer"],
1013  $row["feedback"],
1014  time()
1015  )
1016  );
1017  }
1018  }
1019  }
1020 
1026  {
1028  foreach ($this->answers as $index => $answer)
1029  {
1030  $text .= $this->getFeedbackSingleAnswer($index);
1031  $answer_obj = $this->answers[$index];
1032  $text .= $answer_obj->getAnswertext();
1033  }
1034  return $text;
1035  }
1036 
1040  function &getAnswers()
1041  {
1042  return $this->answers;
1043  }
1044 
1045  function _getAnswerTexts($question_id)
1046  {
1047  global $ilDB;
1048 
1049  $result = $ilDB->queryF("SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
1050  array('integer'),
1051  array($question_id)
1052  );
1053  $answers = array();
1054  if ($result->numRows() > 0)
1055  {
1056  while ($data = $ilDB->fetchAssoc($result))
1057  {
1058  array_push($answers, $data["answertext"]);
1059  }
1060  }
1061  return $answers;
1062  }
1063 
1073  public function setExportDetailsXLS(&$adapter, $startrow, $active_id, $pass)
1074  {
1075  $solution = $this->getSolutionValues($active_id, $pass);
1076  $adapter->setCellValue($startrow, 0, $this->lng->txt($this->getQuestionType()), CELL_FORMAT_TITLE);
1077  $adapter->setCellValue($startrow, 1, $this->getTitle(), CELL_FORMAT_TITLE);
1078  $i = 1;
1079  foreach ($this->getAnswers() as $id => $answer)
1080  {
1081  $adapter->setCellValue($startrow+$i, 0, $answer->getAnswertext(), CELL_FORMAT_BOLD);
1082  if ($id == $solution[0]["value1"] && strlen($solution[0]["value1"]) > 0)
1083  {
1084  $adapter->setCellValue($startrow+$i, 1, 1);
1085  }
1086  else
1087  {
1088  $adapter->setCellValue($startrow+$i, 1, 0);
1089  }
1090  $i++;
1091  }
1092  return $startrow + $i + 1;
1093  }
1094 
1095  public function getThumbSize()
1096  {
1097  return $this->thumb_size;
1098  }
1099 
1100  public function setThumbSize($a_size)
1101  {
1102  $this->thumb_size = $a_size;
1103  }
1104 
1108  public function toJSON()
1109  {
1110  include_once("./Services/RTE/classes/class.ilRTE.php");
1111  $result = array();
1112  $result['id'] = (int) $this->getId();
1113  $result['type'] = (string) $this->getQuestionType();
1114  $result['title'] = (string) $this->getTitle();
1115  $result['question'] = (string) ilRTE::_replaceMediaObjectImageSrc($this->getQuestion(), 0);
1116  $result['nr_of_tries'] = (int) $this->getNrOfTries();
1117  $result['shuffle'] = (bool) $this->getShuffle();
1118  $result['feedback'] = array(
1119  "onenotcorrect" => ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackGeneric(0), 0),
1120  "allcorrect" => ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackGeneric(1), 0)
1121  );
1122  $answers = array();
1123  foreach ($this->getAnswers() as $key => $answer_obj)
1124  {
1125  array_push($answers, array(
1126  "answertext" => (string) $answer_obj->getAnswertext(),
1127  "points" => (float)$answer_obj->getPoints(),
1128  "order" => (int)$answer_obj->getOrder(),
1129  "image" => $answer_obj->getImage(),
1130  "feedback" => ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackSingleAnswer($key), 0)
1131  ));
1132  }
1133  $result['answers'] = $answers;
1134  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1135  $result['mobs'] = $mobs;
1136  return json_encode($result);
1137  }
1138 
1139  public function removeAnswerImage($index)
1140  {
1141  $answer = $this->answers[$index];
1142  if (is_object($answer))
1143  {
1144  $this->deleteImage($answer->getImage());
1145  $answer->setImage('');
1146  }
1147  }
1148 
1149  function createRandomSolution($active_id, $pass)
1150  {
1151  $value = rand(0, count($this->answers)-1);
1152  $_POST["multiple_choice_result"] = (strlen($value)) ? (string)$value : '0';
1153  $this->saveWorkingData($active_id, $pass);
1154  }
1155 
1157  {
1158  global $ilUser;
1159 
1160  $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1161  if ($multilineAnswerSetting != 1)
1162  {
1163  $multilineAnswerSetting = 0;
1164  }
1165  return $multilineAnswerSetting;
1166  }
1167 
1168  function setMultilineAnswerSetting($a_setting = 0)
1169  {
1170  global $ilUser;
1171  $ilUser->writePref("tst_multiline_answers", $a_setting);
1172  }
1173 }
1174 
1175 ?>