ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.assSingleChoice.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
5require_once './Modules/Test/classes/inc.AssessmentConstants.php';
6require_once './Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
7require_once './Modules/TestQuestionPool/interfaces/interface.ilObjAnswerScoringAdjustable.php';
8require_once './Modules/TestQuestionPool/interfaces/interface.iQuestionCondition.php';
9require_once './Modules/TestQuestionPool/classes/class.ilUserQuestionResult.php';
10
25{
34
44
50 protected $thumb_size;
51
59
74 public function __construct(
75 $title = "",
76 $comment = "",
77 $author = "",
78 $owner = -1,
79 $question = "",
81 )
82 {
83 parent::__construct($title, $comment, $author, $owner, $question);
84 $this->thumb_size = 150;
85 $this->output_type = $output_type;
86 $this->answers = array();
87 $this->shuffle = 1;
88 $this->feedback_setting = 2;
89 }
90
97 function isComplete()
98 {
99 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
100 {
101 foreach ($this->answers as $answer)
102 {
103 if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) return false;
104 }
105 return true;
106 }
107 else
108 {
109 return false;
110 }
111 }
112
119 public function saveToDb($original_id = "")
120 {
122 global $ilDB;
123
125
126 // kann das weg?
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
142
144
146
147 parent::saveToDb($original_id);
148 }
149
150 /*
151 * Rebuild the thumbnail images with a new thumbnail size
152 */
153 protected function rebuildThumbnails()
154 {
155 if ($this->isSingleline && ($this->getThumbSize()))
156 {
157 foreach ($this->getAnswers() as $answer)
158 {
159 if (strlen($answer->getImage()))
160 {
161 $this->generateThumbForFile($this->getImagePath(), $answer->getImage());
162 }
163 }
164 }
165 }
166
167 public function getThumbPrefix()
168 {
169 return "thumb.";
170 }
171
172 protected function generateThumbForFile($path, $file)
173 {
175 if (@file_exists($filename))
176 {
177 $thumbpath = $path . $this->getThumbPrefix() . $file;
178 $path_info = @pathinfo($filename);
179 $ext = "";
180 switch (strtoupper($path_info['extension']))
181 {
182 case 'PNG':
183 $ext = 'PNG';
184 break;
185 case 'GIF':
186 $ext = 'GIF';
187 break;
188 default:
189 $ext = 'JPEG';
190 break;
191 }
192 ilUtil::convertImage($filename, $thumbpath, $ext, $this->getThumbSize());
193 }
194 }
195
203 function loadFromDb($question_id)
204 {
205 global $ilDB;
206
207 $hasimages = 0;
208
209 $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",
210 array("integer"),
211 array($question_id)
212 );
213 if ($result->numRows() == 1)
214 {
215 $data = $ilDB->fetchAssoc($result);
216 $this->setId($question_id);
217 $this->setObjId($data["obj_fi"]);
218 $this->setTitle($data["title"]);
219 $this->setNrOfTries($data['nr_of_tries']);
220 $this->setComment($data["description"]);
221 $this->setOriginalId($data["original_id"]);
222 $this->setAuthor($data["author"]);
223 $this->setPoints($data["points"]);
224 $this->setOwner($data["owner"]);
225 include_once("./Services/RTE/classes/class.ilRTE.php");
226 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
227 $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
228 $this->setShuffle($shuffle);
229 $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
230 $this->setThumbSize($data['thumb_size']);
231 $this->isSingleline = ($data['allow_images']) ? false : true;
232 $this->lastChange = $data['tstamp'];
233 $this->feedback_setting = $data['feedback_setting'];
234
235 try
236 {
237 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
238 }
240 {
241 }
242 }
243
244 $result = $ilDB->queryF("SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
245 array('integer'),
246 array($question_id)
247 );
248 include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
249 if ($result->numRows() > 0)
250 {
251 while ($data = $ilDB->fetchAssoc($result))
252 {
253 $imagefilename = $this->getImagePath() . $data["imagefile"];
254 if (!@file_exists($imagefilename))
255 {
256 $data["imagefile"] = "";
257 }
258 include_once("./Services/RTE/classes/class.ilRTE.php");
259 $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"], 1);
260 array_push($this->answers, new ASS_AnswerBinaryStateImage($data["answertext"], $data["points"], $data["aorder"], 1, $data["imagefile"]));
261 }
262 }
263
264 parent::loadFromDb($question_id);
265 }
266
272 function duplicate($for_test = true, $title = "", $author = "", $owner = "", $testObjId = null)
273 {
274 if ($this->id <= 0)
275 {
276 // The question has not been saved. It cannot be duplicated
277 return;
278 }
279 // duplicate the question in database
280 $this_id = $this->getId();
281 $thisObjId = $this->getObjId();
282
283 $clone = $this;
284 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
286 $clone->id = -1;
287
288 if( (int)$testObjId > 0 )
289 {
290 $clone->setObjId($testObjId);
291 }
292
293 if ($title)
294 {
295 $clone->setTitle($title);
296 }
297
298 if ($author)
299 {
300 $clone->setAuthor($author);
301 }
302 if ($owner)
303 {
304 $clone->setOwner($owner);
305 }
306 if ($for_test)
307 {
308 $clone->saveToDb($original_id);
309 }
310 else
311 {
312 $clone->saveToDb();
313 }
314
315 // copy question page content
316 $clone->copyPageOfQuestion($this_id);
317
318 // copy XHTML media objects
319 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
320 // duplicate the images
321 $clone->duplicateImages($this_id, $thisObjId);
322
323 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
324
325 return $clone->id;
326 }
327
333 function copyObject($target_questionpool_id, $title = "")
334 {
335 if ($this->id <= 0)
336 {
337 // The question has not been saved. It cannot be duplicated
338 return;
339 }
340 // duplicate the question in database
341 $clone = $this;
342 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
344 $clone->id = -1;
345 $source_questionpool_id = $this->getObjId();
346 $clone->setObjId($target_questionpool_id);
347 if ($title)
348 {
349 $clone->setTitle($title);
350 }
351 $clone->saveToDb();
352 // copy question page content
353 $clone->copyPageOfQuestion($original_id);
354 // copy XHTML media objects
355 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
356 // duplicate the image
357 $clone->copyImages($original_id, $source_questionpool_id);
358
359 $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
360
361 return $clone->id;
362 }
363
364 public function createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle = "")
365 {
366 if ($this->id <= 0)
367 {
368 // The question has not been saved. It cannot be duplicated
369 return;
370 }
371
372 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
373
374 $sourceQuestionId = $this->id;
375 $sourceParentId = $this->getObjId();
376
377 // duplicate the question in database
378 $clone = $this;
379 $clone->id = -1;
380
381 $clone->setObjId($targetParentId);
382
383 if ($targetQuestionTitle)
384 {
385 $clone->setTitle($targetQuestionTitle);
386 }
387
388 $clone->saveToDb();
389 // copy question page content
390 $clone->copyPageOfQuestion($sourceQuestionId);
391 // copy XHTML media objects
392 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
393 // duplicate the image
394 $clone->copyImages($sourceQuestionId, $sourceParentId);
395
396 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
397
398 return $clone->id;
399 }
400
408 function getOutputType()
409 {
410 return $this->output_type;
411 }
412
421 {
422 $this->output_type = $output_type;
423 }
424
438 function addAnswer(
439 $answertext = "",
440 $points = 0.0,
441 $order = 0,
442 $answerimage = ""
443 )
444 {
445 include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
446 if (array_key_exists($order, $this->answers))
447 {
448 // insert answer
449 $answer = new ASS_AnswerBinaryStateImage($answertext, $points, $order, 1, $answerimage);
450 $newchoices = array();
451 for ($i = 0; $i < $order; $i++)
452 {
453 array_push($newchoices, $this->answers[$i]);
454 }
455 array_push($newchoices, $answer);
456 for ($i = $order; $i < count($this->answers); $i++)
457 {
458 $changed = $this->answers[$i];
459 $changed->setOrder($i+1);
460 array_push($newchoices, $changed);
461 }
462 $this->answers = $newchoices;
463 }
464 else
465 {
466 // add answer
467 $answer = new ASS_AnswerBinaryStateImage($answertext, $points, count($this->answers), 1, $answerimage);
468 array_push($this->answers, $answer);
469 }
470 }
471
479 function getAnswerCount()
480 {
481 return count($this->answers);
482 }
483
493 function getAnswer($index = 0)
494 {
495 if ($index < 0) return NULL;
496 if (count($this->answers) < 1) return NULL;
497 if ($index >= count($this->answers)) return NULL;
498
499 return $this->answers[$index];
500 }
501
510 function deleteAnswer($index = 0)
511 {
512 if ($index < 0) return;
513 if (count($this->answers) < 1) return;
514 if ($index >= count($this->answers)) return;
515 $answer = $this->answers[$index];
516 if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
517 unset($this->answers[$index]);
518 $this->answers = array_values($this->answers);
519 for ($i = 0; $i < count($this->answers); $i++)
520 {
521 if ($this->answers[$i]->getOrder() > $index)
522 {
523 $this->answers[$i]->setOrder($i);
524 }
525 }
526 }
527
534 function flushAnswers()
535 {
536 $this->answers = array();
537 }
538
546 {
547 $points = 0;
548 foreach ($this->answers as $key => $value)
549 {
550 if ($value->getPoints() > $points)
551 {
552 $points = $value->getPoints();
553 }
554 }
555 return $points;
556 }
557
568 public function calculateReachedPoints($active_id, $pass = NULL, $returndetails = FALSE)
569 {
570 if( $returndetails )
571 {
572 throw new ilTestException('return details not implemented for '.__METHOD__);
573 }
574
575 global $ilDB;
576
577 $found_values = array();
578 if (is_null($pass))
579 {
580 $pass = $this->getSolutionMaxPass($active_id);
581 }
582 $result = $this->getCurrentSolutionResultSet($active_id, $pass);
583 while ($data = $ilDB->fetchAssoc($result))
584 {
585 if (strcmp($data["value1"], "") != 0)
586 {
587 array_push($found_values, $data["value1"]);
588 }
589 }
590 $points = 0;
591 foreach ($this->answers as $key => $answer)
592 {
593 if (count($found_values) > 0)
594 {
595 if (in_array($key, $found_values))
596 {
597 $points += $answer->getPoints();
598 }
599 }
600 }
601
602 return $points;
603 }
604
606 {
607 foreach ($this->answers as $key => $answer)
608 {
609 if( $key == $previewSession->getParticipantsSolution() )
610 {
611 return $answer->getPoints();
612 }
613 }
614
615 return 0;
616 }
617
626 public function saveWorkingData($active_id, $pass = NULL)
627 {
628 global $ilDB;
629 global $ilUser;
630
631 if (is_null($pass))
632 {
633 include_once "./Modules/Test/classes/class.ilObjTest.php";
634 $pass = ilObjTest::_getPass($active_id);
635 }
636 $entered_values = 0;
637
638 $this->getProcessLocker()->requestUserSolutionUpdateLock();
639
640 $result = $this->getCurrentSolutionResultSet($active_id, $pass);
641 $row = $ilDB->fetchAssoc($result);
642 $update = $row["solution_id"];
643
644 if ($update)
645 {
646 if (strlen($_POST["multiple_choice_result"]))
647 {
648 $affectedRows = $ilDB->update("tst_solutions", array(
649 "value1" => array("clob", $_POST["multiple_choice_result"]),
650 "tstamp" => array("integer", time())
651 ), array(
652 "solution_id" => array("integer", $update)
653 ));
654 $entered_values++;
655 }
656 else
657 {
658 $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE solution_id = %s",
659 array('integer'),
660 array($update)
661 );
662 }
663 }
664 else
665 {
666 if (strlen($_POST["multiple_choice_result"]))
667 {
668 $affectedRows = $this->saveCurrentSolution($active_id, $pass, $_POST['multiple_choice_result'], null);
669 $entered_values++;
670 }
671 }
672
673 $this->getProcessLocker()->releaseUserSolutionUpdateLock();
674
675 if ($entered_values)
676 {
677 include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
679 {
680 $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
681 }
682 }
683 else
684 {
685 include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
687 {
688 $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
689 }
690 }
691
692 return true;
693 }
694
695 protected function savePreviewData(ilAssQuestionPreviewSession $previewSession)
696 {
697 if( strlen($_POST['multiple_choice_result'.$this->getId().'ID']) )
698 {
699 $previewSession->setParticipantsSolution($_POST['multiple_choice_result'.$this->getId().'ID']);
700 }
701 else
702 {
703 $previewSession->setParticipantsSolution(null);
704 }
705 }
706
707 public function saveAdditionalQuestionDataToDb()
708 {
710 global $ilDB;
711
712 // save additional data
713 $ilDB->manipulateF( "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
714 array( "integer" ),
715 array( $this->getId() )
716 );
717
718 $ilDB->manipulateF( "INSERT INTO " . $this->getAdditionalTableName(
719 ) . " (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
720 array( "integer", "text", "text", "integer" ),
721 array(
722 $this->getId(),
723 $this->getShuffle(),
724 ($this->isSingleline) ? "0" : "1",
725 (strlen( $this->getThumbSize() ) == 0) ? null : $this->getThumbSize()
726 )
727 );
728 }
729
730 public function saveAnswerSpecificDataToDb()
731 {
733 global $ilDB;
734 if (!$this->isSingleline)
735 {
736 ilUtil::delDir( $this->getImagePath() );
737 }
738 $ilDB->manipulateF( "DELETE FROM qpl_a_sc WHERE question_fi = %s",
739 array( 'integer' ),
740 array( $this->getId() )
741 );
742
743 foreach ($this->answers as $key => $value)
744 {
746 $answer_obj = $this->answers[$key];
747 $next_id = $ilDB->nextId( 'qpl_a_sc' );
748 $ilDB->manipulateF( "INSERT INTO qpl_a_sc (answer_id, question_fi, answertext, points, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
749 array( 'integer', 'integer', 'text', 'float', 'integer', 'text', 'integer' ),
750 array(
751 $next_id,
752 $this->getId(),
753 ilRTE::_replaceMediaObjectImageSrc( $answer_obj->getAnswertext(), 0 ),
754 $answer_obj->getPoints(),
755 $answer_obj->getOrder(),
756 $answer_obj->getImage(),
757 time()
758 )
759 );
760 }
761 $this->rebuildThumbnails();
762 }
763
772 protected function reworkWorkingData($active_id, $pass, $obligationsAnswered)
773 {
774 // nothing to rework!
775 }
776
784 {
785 return "assSingleChoice";
786 }
787
795 {
796 return "qpl_qst_sc";
797 }
798
806 {
807 return "qpl_a_sc";
808 }
809
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 if ($this->isSingleline && ($this->getThumbSize()))
847 {
848 $this->generateThumbForFile($imagepath, $image_filename);
849 }
850 }
851 }
852 }
853 return $result;
854 }
855
862 function deleteImage($image_filename)
863 {
864 $imagepath = $this->getImagePath();
865 @unlink($imagepath . $image_filename);
866 $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
867 @unlink($thumbpath);
868 }
869
870 function duplicateImages($question_id, $objectId = null)
871 {
872 global $ilLog;
873 $imagepath = $this->getImagePath();
874 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
875
876 if( (int)$objectId > 0 )
877 {
878 $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
879 }
880
881 foreach ($this->answers as $answer)
882 {
883 $filename = $answer->getImage();
884 if (strlen($filename))
885 {
886 if (!file_exists($imagepath))
887 {
888 ilUtil::makeDirParents($imagepath);
889 }
890 if (!@copy($imagepath_original . $filename, $imagepath . $filename))
891 {
892 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
893 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
894 }
895 if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
896 {
897 if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
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
907 function copyImages($question_id, $source_questionpool)
908 {
909 global $ilLog;
910 $imagepath = $this->getImagePath();
911 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
912 $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
913 foreach ($this->answers as $answer)
914 {
915 $filename = $answer->getImage();
916 if (strlen($filename))
917 {
918 if (!file_exists($imagepath))
919 {
920 ilUtil::makeDirParents($imagepath);
921 }
922 if (!@copy($imagepath_original . $filename, $imagepath . $filename))
923 {
924 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
925 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
926 }
927 if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
928 {
929 if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
930 {
931 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
932 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
933 }
934 }
935 }
936 }
937 }
938
942 protected function syncImages()
943 {
944 global $ilLog;
945 $question_id = $this->getOriginalId();
946 $imagepath = $this->getImagePath();
947 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
948 ilUtil::delDir($imagepath_original);
949 foreach ($this->answers as $answer)
950 {
951 $filename = $answer->getImage();
952 if (strlen($filename))
953 {
954 if (@file_exists($imagepath . $filename))
955 {
956 if (!file_exists($imagepath))
957 {
958 ilUtil::makeDirParents($imagepath);
959 }
960 if (!file_exists($imagepath_original))
961 {
962 ilUtil::makeDirParents($imagepath_original);
963 }
964 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
965 {
966 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
967 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
968 }
969 }
970 if (@file_exists($imagepath . $this->getThumbPrefix() . $filename))
971 {
972 if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename))
973 {
974 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
975 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
976 }
977 }
978 }
979 }
980 }
981
987 {
988 $text = parent::getRTETextWithMediaObjects();
989 foreach ($this->answers as $index => $answer)
990 {
991 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), $index);
992 $answer_obj = $this->answers[$index];
993 $text .= $answer_obj->getAnswertext();
994 }
995 return $text;
996 }
997
1001 function &getAnswers()
1002 {
1003 return $this->answers;
1004 }
1005
1018 public function setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
1019 {
1020 include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
1021 $solution = $this->getSolutionValues($active_id, $pass);
1022 $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
1023 $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
1024 $i = 1;
1025 foreach ($this->getAnswers() as $id => $answer)
1026 {
1027 $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($answer->getAnswertext()), $format_bold);
1028 if(
1029 count($solution) > 0 &&
1030 isset($solution[0]) &&
1031 is_array($solution[0]) &&
1032 strlen($solution[0]['value1']) > 0 && $id == $solution[0]['value1'])
1033 {
1034 $worksheet->write($startrow + $i, 1, 1);
1035 }
1036 else
1037 {
1038 $worksheet->write($startrow + $i, 1, 0);
1039 }
1040 $i++;
1041 }
1042 return $startrow + $i + 1;
1043 }
1044
1045 public function getThumbSize()
1046 {
1047 return $this->thumb_size;
1048 }
1049
1050 public function setThumbSize($a_size)
1051 {
1052 $this->thumb_size = $a_size;
1053 }
1054
1058 public function toJSON()
1059 {
1060 include_once("./Services/RTE/classes/class.ilRTE.php");
1061 $result = array();
1062 $result['id'] = (int) $this->getId();
1063 $result['type'] = (string) $this->getQuestionType();
1064 $reilUtilsult['title'] = (string) $this->getTitle();
1065 $result['question'] = $this->formatSAQuestion($this->getQuestion());
1066 $result['nr_of_tries'] = (int) $this->getNrOfTries();
1067 $result['shuffle'] = (bool) $this->getShuffle();
1068
1069 $result['feedback'] = array(
1070 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1071 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1072 );
1073
1074 $answers = array();
1075 $has_image = false;
1076 foreach ($this->getAnswers() as $key => $answer_obj)
1077 {
1078 if((string) $answer_obj->getImage())
1079 {
1080 $has_image = true;
1081 }
1082 array_push($answers, array(
1083 "answertext" => (string) $this->formatSAQuestion($answer_obj->getAnswertext()),
1084 "points" => (float)$answer_obj->getPoints(),
1085 "order" => (int)$answer_obj->getOrder(),
1086 "image" => (string) $answer_obj->getImage(),
1087 "feedback" => $this->formatSAQuestion(
1088 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key)
1089 )
1090 ));
1091 }
1092 $result['answers'] = $answers;
1093 if($has_image)
1094 {
1095 $result['path'] = $this->getImagePathWeb();
1096 $result['thumb'] = $this->getThumbSize();
1097 }
1098
1099 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1100 $result['mobs'] = $mobs;
1101
1102 return json_encode($result);
1103 }
1104
1105 public function removeAnswerImage($index)
1106 {
1107 $answer = $this->answers[$index];
1108 if (is_object($answer))
1109 {
1110 $this->deleteImage($answer->getImage());
1111 $answer->setImage('');
1112 }
1113 }
1114
1115 function createRandomSolution($active_id, $pass)
1116 {
1117 $value = rand(0, count($this->answers)-1);
1118 $_POST["multiple_choice_result"] = (strlen($value)) ? (string)$value : '0';
1119 $this->saveWorkingData($active_id, $pass);
1120 }
1121
1123 {
1124 global $ilUser;
1125
1126 $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1127 if ($multilineAnswerSetting != 1)
1128 {
1129 $multilineAnswerSetting = 0;
1130 }
1131 return $multilineAnswerSetting;
1132 }
1133
1134 function setMultilineAnswerSetting($a_setting = 0)
1135 {
1136 global $ilUser;
1137 $ilUser->writePref("tst_multiline_answers", $a_setting);
1138 }
1139
1149 public function setSpecificFeedbackSetting($a_feedback_setting)
1150 {
1151 $this->feedback_setting = $a_feedback_setting;
1152 }
1153
1164 {
1165 if ($this->feedback_setting)
1166 {
1168 }
1169 else
1170 {
1171 return 1;
1172 }
1173 }
1174
1185 public function isAnswered($active_id, $pass)
1186 {
1187 $numExistingSolutionRecords = assQuestion::getNumExistingSolutionRecords($active_id, $pass, $this->getId());
1188
1189 return $numExistingSolutionRecords > 0;
1190 }
1191
1202 public static function isObligationPossible($questionId)
1203 {
1204 return true;
1205 }
1206
1215 public function getOperators($expression)
1216 {
1217 require_once "./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
1219 }
1220
1225 public function getExpressionTypes()
1226 {
1227 return array(
1231 );
1232 }
1233
1242 public function getUserQuestionResult($active_id, $pass)
1243 {
1245 global $ilDB;
1246 $result = new ilUserQuestionResult($this, $active_id, $pass);
1247
1248 $data = $ilDB->queryF(
1249 "SELECT * FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = (
1250 SELECT MAX(step) FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s
1251 )",
1252 array("integer", "integer", "integer","integer", "integer", "integer"),
1253 array($active_id, $pass, $this->getId(), $active_id, $pass, $this->getId())
1254 );
1255
1256 $row = $ilDB->fetchAssoc($data);
1257
1258 if($row != null)
1259 {
1260 ++$row["value1"];
1261 $result->addKeyValue($row["value1"], $row["value1"]);
1262 }
1263
1264 $points = $this->calculateReachedPoints($active_id, $pass);
1265 $max_points = $this->getMaximumPoints();
1266
1267 $result->setReachedPercentage(($points/$max_points) * 100);
1268
1269 return $result;
1270 }
1271
1280 public function getAvailableAnswerOptions($index = null)
1281 {
1282 if($index !== null)
1283 {
1284 return $this->getAnswer($index);
1285 }
1286 else
1287 {
1288 return $this->getAnswers();
1289 }
1290 }
1291
1295 protected function afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)
1296 {
1297 parent::afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId);
1298
1299 $origImagePath = $this->buildImagePath($origQuestionId, $origParentObjId);
1300 $dupImagePath = $this->buildImagePath($dupQuestionId, $dupParentObjId);
1301
1302 ilUtil::delDir($origImagePath);
1303 if(is_dir($dupImagePath))
1304 {
1305 ilUtil::makeDirParents($origImagePath);
1306 ilUtil::rCopy($dupImagePath, $origImagePath);
1307 }
1308 }
1309}
$result
print $file
$filename
Definition: buildRTE.php:89
Class for answers with a binary state indicator.
Abstract basic class which is to be extended by the concrete assessment question type classes.
& getSolutionValues($active_id, $pass=NULL)
Loads solutions of a given user from the database an returns it.
static _getOriginalId($question_id)
Returns the original id of a question.
formatSAQuestion($a_q)
Format self assessment question.
setShuffle($shuffle=true)
Sets the shuffle flag.
setId($id=-1)
Sets the id of the assQuestion object.
setOriginalId($original_id)
setObjId($obj_id=0)
Set the object id of the container object.
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
saveQuestionDataToDb($original_id="")
getId()
Gets the id of the assQuestion object.
getObjId()
Get the object id of the container object.
setTitle($title="")
Sets the title string of the assQuestion object.
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.
setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
Sets the estimated working time of a question from given hour, minute and second.
buildImagePath($questionId, $parentObjectId)
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
static getNumExistingSolutionRecords($activeId, $pass, $questionId)
returns the number of existing solution records for the given test active / pass and given question i...
setAuthor($author="")
Sets the authors name of the assQuestion object.
getShuffle()
Gets the shuffle flag.
logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
getTitle()
Gets the title string of the assQuestion object.
setPoints($a_points)
Sets the maximum available points for the question.
setComment($comment="")
Sets the comment string of the assQuestion object.
setNrOfTries($a_nr_of_tries)
getQuestion()
Gets the question string of the question object.
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
saveToDb($original_id="")
Saves the question to the database.
setQuestion($question="")
Sets the question string of the question object.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
Class for single choice questions.
copyImages($question_id, $source_questionpool)
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
saveWorkingData($active_id, $pass=NULL)
Saves the learners input of the question to the database.
loadFromDb($question_id)
Loads a assSingleChoice object from a database.
deleteImage($image_filename)
Deletes an image file.
setOutputType($output_type=OUTPUT_ORDER)
Sets the output type of the assSingleChoice object.
calculateReachedPoints($active_id, $pass=NULL, $returndetails=FALSE)
Returns the points, a learner has reached answering the question.
getQuestionType()
Returns the question type of the question.
getAnswerCount()
Returns the number of answers.
reworkWorkingData($active_id, $pass, $obligationsAnswered)
Reworks the allready saved working data if neccessary.
toJSON()
Returns a JSON representation of the question.
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
generateThumbForFile($path, $file)
syncImages()
Sync images of a MC question on synchronisation with the original question.
createRandomSolution($active_id, $pass)
setSpecificFeedbackSetting($a_feedback_setting)
Sets the feedback settings in effect for the question.
getOutputType()
Gets the single choice output type which is either OUTPUT_ORDER (=0) or OUTPUT_RANDOM (=1).
addAnswer( $answertext="", $points=0.0, $order=0, $answerimage="")
Adds a possible answer for a single choice question.
getSpecificFeedbackSetting()
Gets the current feedback settings in effect for the question.
getOperators($expression)
Get all available operations for a specific question.
setMultilineAnswerSetting($a_setting=0)
setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
Creates an Excel worksheet for the detailed cumulated results of this question.
getExpressionTypes()
Get all available expression types for a specific question.
getAvailableAnswerOptions($index=null)
If index is null, the function returns an array with all anwser options Else it returns the specific ...
afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)
{}
& getAnswers()
Returns a reference to the answers array.
isComplete()
Returns true, if a single choice question is complete for use.
deleteAnswer($index=0)
Deletes an answer with a given index.
savePreviewData(ilAssQuestionPreviewSession $previewSession)
isAnswered($active_id, $pass)
returns boolean wether the question is answered during test pass or not
static isObligationPossible($questionId)
returns boolean wether it is possible to set this question type as obligatory or not considering the ...
setImageFile($image_filename, $image_tempfilename="")
Sets the image file and uploads the image to the object's image directory.
copyObject($target_questionpool_id, $title="")
Copies an assSingleChoice object.
__construct( $title="", $comment="", $author="", $owner=-1, $question="", $output_type=OUTPUT_ORDER)
assSingleChoice constructor
flushAnswers()
Deletes all answers.
getAnswer($index=0)
Returns an answer with a given index.
calculateReachedPointsFromPreviewSession(ilAssQuestionPreviewSession $previewSession)
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
duplicateImages($question_id, $objectId=null)
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
Duplicates an assSingleChoiceQuestion.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
getAnswerTableName()
Returns the name of the answer table in the database.
_convert_text($a_text, $a_target="has been removed")
_getLogLanguage()
retrieve the log language for assessment logging
_enabledAssessmentLogging()
check wether assessment logging is enabled or not
static getMimeType($a_file)
get mime type for file
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
_getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
Base Exception for all Exceptions relating to Modules/Test.
Class ilUserQuestionResult.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$_POST['username']
Definition: cron.php:12
const OUTPUT_ORDER
Class iQuestionCondition.
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
Interface ilObjAnswerScoringAdjustable.
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
Interface ilObjQuestionScoringAdjustable.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
$path
Definition: index.php:22
global $ilDB
$mobs
global $ilUser
Definition: imgupload.php:15