ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assOrderingQuestion.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 
24 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
25 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
26 
37 {
45  var $answers;
46 
56 
62  var $thumb_geometry = 100;
63 
70 
83  function __construct(
84  $title = "",
85  $comment = "",
86  $author = "",
87  $owner = -1,
88  $question = "",
90  )
91  {
93  $this->answers = array();
94  $this->ordering_type = $ordering_type;
95  }
96 
103  function isComplete()
104  {
105  if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
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  // save additional data
128  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
129  array("integer"),
130  array($this->getId())
131  );
132 
133  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, ordering_type, thumb_geometry, element_height) VALUES (%s, %s, %s, %s)",
134  array("integer", "text","integer","integer"),
135  array(
136  $this->getId(),
137  $this->ordering_type,
138  $this->getThumbGeometry(),
139  ($this->getElementHeight() > 20) ? $this->getElementHeight() : NULL
140  )
141  );
142 
143  $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_ordering WHERE question_fi = %s",
144  array('integer'),
145  array($this->getId())
146  );
147 
148  // Anworten wegschreiben
149  foreach ($this->answers as $key => $value)
150  {
151  $answer_obj = $this->answers[$key];
152  $next_id = $ilDB->nextId('qpl_a_ordering');
153  $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_ordering (answer_id, question_fi, answertext, solution_order, ".
154  "random_id, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
155  array('integer','integer','text','integer','integer','integer'),
156  array(
157  $next_id,
158  $this->getId(),
159  ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0),
160  $key,
161  $answer_obj->getRandomID(),
162  time()
163  )
164  );
165  }
166 
167  if ($this->getOrderingType() == OQ_PICTURES)
168  {
169  $this->rebuildThumbnails();
170  }
171 
172  $this->cleanImagefiles();
174  }
175 
183  function loadFromDb($question_id)
184  {
185  global $ilDB;
186 
187  $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",
188  array("integer"),
189  array($question_id)
190  );
191  if ($result->numRows() == 1)
192  {
193  $data = $ilDB->fetchAssoc($result);
194  $this->setId($question_id);
195  $this->setObjId($data["obj_fi"]);
196  $this->setTitle($data["title"]);
197  $this->setComment($data["description"]);
198  $this->setOriginalId($data["original_id"]);
199  $this->setAuthor($data["author"]);
200  $this->setNrOfTries($data['nr_of_tries']);
201  $this->setPoints($data["points"]);
202  $this->setOwner($data["owner"]);
203  include_once("./Services/RTE/classes/class.ilRTE.php");
204  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
205  $this->ordering_type = strlen($data["ordering_type"]) ? $data["ordering_type"] : OQ_TERMS;
206  $this->thumb_geometry = $data["thumb_geometry"];
207  $this->element_height = $data["element_height"];
208  $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
209  }
210 
211  $result = $ilDB->queryF("SELECT * FROM qpl_a_ordering WHERE question_fi = %s ORDER BY solution_order ASC",
212  array('integer'),
213  array($question_id)
214  );
215 
216  include_once "./Modules/TestQuestionPool/classes/class.assAnswerOrdering.php";
217  if ($result->numRows() > 0)
218  {
219  while ($data = $ilDB->fetchAssoc($result))
220  {
221  include_once("./Services/RTE/classes/class.ilRTE.php");
222  $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"], 1);
223  array_push($this->answers, new ASS_AnswerOrdering($data["answertext"], $data["random_id"]));
224  }
225  }
226  parent::loadFromDb($question_id);
227  }
228 
234  function duplicate($for_test = true, $title = "", $author = "", $owner = "", $testObjId = null)
235  {
236  if ($this->id <= 0)
237  {
238  // The question has not been saved. It cannot be duplicated
239  return;
240  }
241  // duplicate the question in database
242  $this_id = $this->getId();
243 
244  if( (int)$testObjId > 0 )
245  {
246  $thisObjId = $this->getObjId();
247  }
248 
249  $clone = $this;
250  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
252  $clone->id = -1;
253 
254  if( (int)$testObjId > 0 )
255  {
256  $clone->setObjId($testObjId);
257  }
258 
259  if ($title)
260  {
261  $clone->setTitle($title);
262  }
263  if ($author)
264  {
265  $clone->setAuthor($author);
266  }
267  if ($owner)
268  {
269  $clone->setOwner($owner);
270  }
271  if ($for_test)
272  {
273  $clone->saveToDb($original_id);
274  }
275  else
276  {
277  $clone->saveToDb();
278  }
279 
280  // copy question page content
281  $clone->copyPageOfQuestion($this_id);
282  // copy XHTML media objects
283  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
284  // duplicate the generic feedback
285  $clone->duplicateFeedbackGeneric($this_id);
286 
287  // duplicate the image
288  $clone->duplicateImages($this_id, $thisObjId, $clone->getId(), $testObjId);
289 
290  $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
291 
292  return $clone->id;
293  }
294 
300  function copyObject($target_questionpool, $title = "")
301  {
302  if ($this->id <= 0)
303  {
304  // The question has not been saved. It cannot be duplicated
305  return;
306  }
307  // duplicate the question in database
308  $clone = $this;
309  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
311  $clone->id = -1;
312  $source_questionpool = $this->getObjId();
313  $clone->setObjId($target_questionpool);
314  if ($title)
315  {
316  $clone->setTitle($title);
317  }
318 
319  $clone->saveToDb();
320 
321  // copy question page content
322  $clone->copyPageOfQuestion($original_id);
323  // copy XHTML media objects
324  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
325  // duplicate the generic feedback
326  $clone->duplicateFeedbackGeneric($original_id);
327 
328  // duplicate the image
329  $clone->copyImages($original_id, $source_questionpool);
330  $clone->onCopy($this->getObjId(), $this->getId());
331  return $clone->id;
332  }
333 
334  function duplicateImages($src_question_id, $src_object_id, $dest_question_id, $dest_object_id)
335  {
336  global $ilLog;
337  if ($this->getOrderingType() == OQ_PICTURES)
338  {
339  $imagepath_original = $this->getImagePath($src_question_id, $src_object_id);
340  $imagepath = $this->getImagePath($dest_question_id, $dest_object_id);
341 
342  if (!file_exists($imagepath)) {
343  ilUtil::makeDirParents($imagepath);
344  }
345  foreach ($this->answers as $answer)
346  {
347  $filename = $answer->getAnswertext();
348  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
349  {
350  $ilLog->write("image could not be duplicated!!!!");
351  }
352  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
353  {
354  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
355  {
356  $ilLog->write("image thumbnail could not be duplicated!!!!");
357  }
358  }
359  }
360  }
361  }
362 
363  function copyImages($question_id, $source_questionpool)
364  {
365  global $ilLog;
366  if ($this->getOrderingType() == OQ_PICTURES)
367  {
368  $imagepath = $this->getImagePath();
369  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
370  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
371  if (!file_exists($imagepath)) {
372  ilUtil::makeDirParents($imagepath);
373  }
374  foreach ($this->answers as $answer)
375  {
376  $filename = $answer->getAnswertext();
377  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
378  {
379  $ilLog->write("Ordering Question image could not be copied: $imagepath_original$filename");
380  }
381  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
382  {
383  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
384  {
385  $ilLog->write("Ordering Question image thumbnail could not be copied: $imagepath_original" . $this->getThumbPrefix() . $filename);
386  }
387  }
388  }
389  }
390  }
391 
400  {
401  $this->ordering_type = $ordering_type;
402  }
403 
411  function getOrderingType()
412  {
413  return $this->ordering_type;
414  }
415 
429  function addAnswer(
430  $answertext = "",
431  $solution_order = -1
432  )
433  {
434  include_once "./Modules/TestQuestionPool/classes/class.assAnswerOrdering.php";
435  $answer = new ASS_AnswerOrdering($answertext, $this->getRandomID());
436  if (($solution_order >= 0) && ($solution_order < count($this->answers)))
437  {
438  $part1 = array_slice($this->answers, 0, $solution_order);
439  $part2 = array_slice($this->answers, $solution_order);
440  $this->answers = array_merge($part1, array($answer), $part2);
441  }
442  else
443  {
444  array_push($this->answers, $answer);
445  }
446  }
447 
448  public function moveAnswerUp($position)
449  {
450  if ($position > 0)
451  {
452  $temp = $this->answers[$position-1];
453  $this->answers[$position-1] = $this->answers[$position];
454  $this->answers[$position] = $temp;
455  }
456  }
457 
458  public function moveAnswerDown($position)
459  {
460  if ($position < count($this->answers)-1)
461  {
462  $temp = $this->answers[$position+1];
463  $this->answers[$position+1] = $this->answers[$position];
464  $this->answers[$position] = $temp;
465  }
466  }
467 
468  protected function getRandomID()
469  {
470  $random_number = mt_rand(1, 100000);
471  $found = true;
472  while ($found)
473  {
474  $found = false;
475  foreach ($this->getAnswers() as $answer)
476  {
477  if ($answer->getRandomID() == $random_number)
478  {
479  $found = true;
480  $random_number++;
481  }
482  }
483  }
484  return $random_number;
485  }
486 
496  function getAnswer($index = 0)
497  {
498  if ($index < 0) return NULL;
499  if (count($this->answers) < 1) return NULL;
500  if ($index >= count($this->answers)) return NULL;
501  return $this->answers[$index];
502  }
503 
512  function deleteAnswer($index = 0)
513  {
514  if ($index < 0)
515  {
516  return;
517  }
518  if (count($this->answers) < 1)
519  {
520  return;
521  }
522  if ($index >= count($this->answers))
523  {
524  return;
525  }
526  unset($this->answers[$index]);
527  $this->answers = array_values($this->answers);
528  for ($i = 0; $i < count($this->answers); $i++)
529  {
530  if ($this->answers[$i]->getOrder() > $index)
531  {
532  $this->answers[$i]->setOrder($i);
533  }
534  }
535  }
536 
543  function flushAnswers()
544  {
545  $this->answers = array();
546  }
547 
555  function getAnswerCount()
556  {
557  return count($this->answers);
558  }
559 
567  {
568  if (count($this->answers) == 0)
569  {
570  $max = 0;
571  }
572  else
573  {
574  $max = $this->answers[0]->getSolutionOrder();
575  }
576  foreach ($this->answers as $key => $value)
577  {
578  if ($value->getSolutionOrder() > $max)
579  {
580  $max = $value->getSolutionOrder();
581  }
582  }
583  return $max;
584  }
585 
595  function calculateReachedPoints($active_id, $pass = NULL)
596  {
597  global $ilDB;
598 
599  $found_value1 = array();
600  $found_value2 = array();
601  if (is_null($pass))
602  {
603  $pass = $this->getSolutionMaxPass($active_id);
604  }
605  $result = $ilDB->queryF("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
606  array('integer','integer','integer'),
607  array($active_id, $this->getId(), $pass)
608  );
609  $user_order = array();
610  while ($data = $ilDB->fetchAssoc($result))
611  {
612  if ((strcmp($data["value1"], "") != 0) && (strcmp($data["value2"], "") != 0))
613  {
614  $user_order[$data["value2"]] = $data["value1"];
615  }
616  }
617  ksort($user_order);
618  $user_order = array_values($user_order);
619  $points = 0;
620  $correctcount = 0;
621  foreach ($this->answers as $index => $answer)
622  {
623  if ($index == $user_order[$index])
624  {
625  $correctcount++;
626  }
627  }
628  if ($correctcount == count($this->answers))
629  {
630  $points = $this->getPoints();
631  }
632 
633  $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
634  return $points;
635  }
636 
643  public function getMaximumPoints()
644  {
645  return $this->getPoints();
646  }
647 
648  /*
649  * Returns the encrypted save filename of a matching picture
650  * Images are saved with an encrypted filename to prevent users from
651  * cheating by guessing the solution from the image filename
652  *
653  * @param string $filename Original filename
654  * @return string Encrypted filename
655  */
657  {
658  $extension = "";
659  if (preg_match("/.*\\.(\\w+)$/", $filename, $matches))
660  {
661  $extension = $matches[1];
662  }
663  return md5($filename) . "." . $extension;
664  }
665 
666  protected function cleanImagefiles()
667  {
668  if ($this->getOrderingType() == OQ_PICTURES)
669  {
670  if (@file_exists($this->getImagePath()))
671  {
672  $contents = ilUtil::getDir($this->getImagePath());
673  foreach ($contents as $f)
674  {
675  if (strcmp($f['type'], 'file') == 0)
676  {
677  $found = false;
678  foreach ($this->getAnswers() as $answer)
679  {
680  if (strcmp($f['entry'], $answer->getAnswertext()) == 0) $found = true;
681  if (strcmp($f['entry'], $this->getThumbPrefix() . $answer->getAnswertext()) == 0) $found = true;
682  }
683  if (!$found)
684  {
685  if (@file_exists($this->getImagePath() . $f['entry'])) @unlink($this->getImagePath() . $f['entry']);
686  }
687  }
688  }
689  }
690  }
691  else
692  {
693  if (@file_exists($this->getImagePath()))
694  {
695  ilUtil::delDir($this->getImagePath());
696  }
697  }
698  }
699 
700  /*
701  * Deletes an imagefile from the system if the file is deleted manually
702  *
703  * @param string $filename Image file filename
704  * @return boolean Success
705  */
706  public function deleteImagefile($filename)
707  {
708  $deletename = $$filename;
709  $result = @unlink($this->getImagePath().$deletename);
710  $result = $result & @unlink($this->getImagePath().$this->getThumbPrefix() . $deletename);
711  return $result;
712  }
713 
722  function setImageFile($image_tempfilename, $image_filename, $previous_filename)
723  {
724  $result = TRUE;
725  if (strlen($image_tempfilename))
726  {
727  $image_filename = str_replace(" ", "_", $image_filename);
728  $imagepath = $this->getImagePath();
729  if (!file_exists($imagepath))
730  {
731  ilUtil::makeDirParents($imagepath);
732  }
733  $savename = $image_filename;
734  if (!ilUtil::moveUploadedFile($image_tempfilename, $savename, $imagepath.$savename))
735  {
736  $result = FALSE;
737  }
738  else
739  {
740  // create thumbnail file
741  $thumbpath = $imagepath . $this->getThumbPrefix() . $savename;
742  ilUtil::convertImage($imagepath.$savename, $thumbpath, "JPEG", $this->getThumbGeometry());
743  }
744  if ($result && (strcmp($image_filename, $previous_filename) != 0) && (strlen($previous_filename)))
745  {
746  $this->deleteImagefile($previous_filename);
747  }
748  }
749  return $result;
750  }
751 
759  function checkSaveData()
760  {
761  $result = true;
762  if ($this->getOutputType() == OUTPUT_JAVASCRIPT)
763  {
764  if (strlen($_POST["orderresult"]))
765  {
766  return $result;
767  }
768  }
769  $order_values = array();
770  foreach ($_POST as $key => $value)
771  {
772  if (preg_match("/^order_(\d+)/", $key, $matches))
773  {
774  if (strcmp($value, "") != 0)
775  {
776  array_push($order_values, $value);
777  }
778  }
779  }
780  $check_order = array_flip($order_values);
781  if (count($check_order) != count($order_values))
782  {
783  // duplicate order values!!!
784  $result = false;
785  ilUtil::sendInfo($this->lng->txt("duplicate_order_values_entered"), TRUE);
786  }
787  return $result;
788  }
789 
798  function saveWorkingData($active_id, $pass = NULL)
799  {
800  global $ilDB;
801  global $ilUser;
802 
803  $saveWorkingDataResult = $this->checkSaveData();
804  $entered_values = 0;
805  if ($saveWorkingDataResult)
806  {
807  if (is_null($pass))
808  {
809  include_once "./Modules/Test/classes/class.ilObjTest.php";
810  $pass = ilObjTest::_getPass($active_id);
811  }
812 
813  $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
814  array('integer','integer','integer'),
815  array($active_id, $this->getId(), $pass)
816  );
817  if (array_key_exists("orderresult", $_POST))
818  {
819  $orderresult = $_POST["orderresult"];
820  if (strlen($orderresult))
821  {
822  $orderarray = explode(":", $orderresult);
823  $ordervalue = 1;
824  foreach ($orderarray as $index)
825  {
826  if (preg_match("/id_(\\d+)/", $index, $idmatch))
827  {
828  $randomid = $idmatch[1];
829  foreach ($this->getAnswers() as $answeridx => $answer)
830  {
831  if ($answer->getRandomID() == $randomid)
832  {
833  $next_id = $ilDB->nextId('tst_solutions');
834  $affectedRows = $ilDB->insert("tst_solutions", array(
835  "solution_id" => array("integer", $next_id),
836  "active_fi" => array("integer", $active_id),
837  "question_fi" => array("integer", $this->getId()),
838  "value1" => array("clob", $answeridx),
839  "value2" => array("clob", trim($ordervalue)),
840  "pass" => array("integer", $pass),
841  "tstamp" => array("integer", time())
842  ));
843  $ordervalue++;
844  $entered_values++;
845  }
846  }
847  }
848  }
849  }
850  }
851  else
852  {
853  foreach ($_POST as $key => $value)
854  {
855  if (preg_match("/^order_(\d+)/", $key, $matches))
856  {
857  if (!(preg_match("/initial_value_\d+/", $value)))
858  {
859  if (strlen($value))
860  {
861  foreach ($this->getAnswers() as $answeridx => $answer)
862  {
863  if ($answer->getRandomID() == $matches[1])
864  {
865  $next_id = $ilDB->nextId('tst_solutions');
866  $affectedRows = $ilDB->insert("tst_solutions", array(
867  "solution_id" => array("integer", $next_id),
868  "active_fi" => array("integer", $active_id),
869  "question_fi" => array("integer", $this->getId()),
870  "value1" => array("clob", $answeridx),
871  "value2" => array("clob", $value),
872  "pass" => array("integer", $pass),
873  "tstamp" => array("integer", time())
874  ));
875  $entered_values++;
876  }
877  }
878  }
879  }
880  }
881  }
882  }
883  }
884  if ($entered_values)
885  {
886  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
888  {
889  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
890  }
891  }
892  else
893  {
894  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
896  {
897  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
898  }
899  }
900  parent::saveWorkingData($active_id, $pass);
901  return $saveWorkingDataResult;
902  }
903 
910  function getQuestionType()
911  {
912  return "assOrderingQuestion";
913  }
914 
922  {
923  return "qpl_qst_ordering";
924  }
925 
933  {
934  return "qpl_a_ordering";
935  }
936 
942  {
944  foreach ($this->answers as $index => $answer)
945  {
946  $answer_obj = $this->answers[$index];
947  $text .= $answer_obj->getAnswertext();
948  }
949  return $text;
950  }
951 
955  function &getAnswers()
956  {
957  return $this->answers;
958  }
959 
967  {
968  return TRUE;
969  }
970 
983  public function setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
984  {
985  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
986  $solutions = $this->getSolutionValues($active_id, $pass);
987  $sol = array();
988  foreach ($solutions as $solution)
989  {
990  $sol[$solution["value1"]] = $solution["value2"];
991  }
992  asort($sol);
993  $sol = array_keys($sol);
994  $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
995  $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
996  $i = 1;
997  $answers = $this->getAnswers();
998  foreach ($sol as $idx)
999  {
1000  foreach ($solutions as $solution)
1001  {
1002  if ($solution["value1"] == $idx) $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($solution["value2"]));
1003  }
1004  $worksheet->writeString($startrow + $i, 1, ilExcelUtils::_convert_text($answers[$idx]->getAnswertext()));
1005  $i++;
1006  }
1007  return $startrow + $i + 1;
1008  }
1009 
1010  /*
1011  * Get the thumbnail geometry
1012  *
1013  * @return integer Geometry
1014  */
1015  public function getThumbGeometry()
1016  {
1017  return $this->thumb_geometry;
1018  }
1019 
1020  public function getThumbSize()
1021  {
1022  return $this->getThumbGeometry();
1023  }
1024 
1025  /*
1026  * Set the thumbnail geometry
1027  *
1028  * @param integer $a_geometry Geometry
1029  */
1030  public function setThumbGeometry($a_geometry)
1031  {
1032  $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1033  }
1034 
1035  /*
1036  * Get the minimum element height
1037  *
1038  * @return integer Height
1039  */
1040  public function getElementHeight()
1041  {
1042  return $this->element_height;
1043  }
1044 
1045  /*
1046  * Set the minimum element height
1047  *
1048  * @param integer $a_height Height
1049  */
1050  public function setElementHeight($a_height)
1051  {
1052  $this->element_height = ($a_height < 20) ? "" : $a_height;
1053  }
1054 
1055  /*
1056  * Rebuild the thumbnail images with a new thumbnail size
1057  */
1058  public function rebuildThumbnails()
1059  {
1060  if ($this->getOrderingType() == OQ_PICTURES)
1061  {
1062  foreach ($this->getAnswers() as $answer)
1063  {
1064  $this->generateThumbForFile($this->getImagePath(), $answer->getAnswertext());
1065  }
1066  }
1067  }
1068 
1069  public function getThumbPrefix()
1070  {
1071  return "thumb.";
1072  }
1073 
1074  protected function generateThumbForFile($path, $file)
1075  {
1076  $filename = $path . $file;
1077  if (@file_exists($filename))
1078  {
1079  $thumbpath = $path . $this->getThumbPrefix() . $file;
1080  $path_info = @pathinfo($filename);
1081  $ext = "";
1082  switch (strtoupper($path_info['extension']))
1083  {
1084  case 'PNG':
1085  $ext = 'PNG';
1086  break;
1087  case 'GIF':
1088  $ext = 'GIF';
1089  break;
1090  default:
1091  $ext = 'JPEG';
1092  break;
1093  }
1094  ilUtil::convertImage($filename, $thumbpath, $ext, $this->getThumbGeometry());
1095  }
1096  }
1097 
1101  public function toJSON()
1102  {
1103  include_once("./Services/RTE/classes/class.ilRTE.php");
1104  $result = array();
1105  $result['id'] = (int) $this->getId();
1106  $result['type'] = (string) $this->getQuestionType();
1107  $result['title'] = (string) $this->getTitle();
1108  $result['question'] = $this->formatSAQuestion($this->getQuestion());
1109  $result['nr_of_tries'] = (int) $this->getNrOfTries();
1110  $result['shuffle'] = (bool) true;
1111  $result['points'] = (bool) $this->getPoints();
1112  $result['feedback'] = array(
1113  "onenotcorrect" => nl2br(ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackGeneric(0), 0)),
1114  "allcorrect" => nl2br(ilRTE::_replaceMediaObjectImageSrc($this->getFeedbackGeneric(1), 0))
1115  );
1116  if ($this->getOrderingType() == OQ_PICTURES)
1117  {
1118  $result['path'] = $this->getImagePathWeb();
1119  }
1120 
1121  $counter = 1;
1122  $answers = array();
1123  foreach ($this->getAnswers() as $answer_obj)
1124  {
1125  $answers[$counter] = $answer_obj->getAnswertext();
1126  $counter++;
1127  }
1128  $answers = $this->pcArrayShuffle($answers);
1129  $arr = array();
1130  foreach ($answers as $order => $answer)
1131  {
1132  array_push($arr, array(
1133  "answertext" => (string) $answer,
1134  "order" => (int) $order
1135  ));
1136  }
1137  $result['answers'] = $arr;
1138 
1139  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1140  $result['mobs'] = $mobs;
1141 
1142  return json_encode($result);
1143  }
1144 
1145  public function removeAnswerImage($index)
1146  {
1147  $answer = $this->answers[$index];
1148  if (is_object($answer))
1149  {
1150  $this->deleteImagefile($answer->getAnswertext());
1151  $answer->setAnswertext('');
1152  }
1153  }
1154 
1155 }
1156 
1157 ?>