4 require_once
'Modules/TestQuestionPool/classes/class.assQuestion.php';
5 require_once
'Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
6 require_once
'Modules/TestQuestionPool/interfaces/interface.ilObjAnswerScoringAdjustable.php';
54 $this->shuffleAnswersEnabled =
true;
57 $this->scorePartialSolutionEnabled =
true;
59 $this->customTrueOptionLabel =
'';
60 $this->customFalseOptionLabel =
'';
62 require_once
'Modules/TestQuestionPool/classes/feedback/class.ilAssConfigurableMultiOptionQuestionFeedback.php';
65 $this->answers = array();
72 return 'assKprimChoice';
77 return "qpl_qst_kprim";
179 if($answer->getPosition() == $position)
190 $this->answers[] = $answer;
197 while($data = $this->db->fetchAssoc(
$res))
199 $this->
setId($questionId);
213 require_once
'Services/RTE/classes/class.ilRTE.php';
223 if( is_numeric($data[
'thumb_size']) )
236 if( $data[
'score_partsol'] !== null )
241 if( isset($data[
'feedback_setting']) )
264 $res = $this->db->queryF(
265 "SELECT * FROM {$this->getAnswerTableName()} WHERE question_fi = %s ORDER BY position ASC",
266 array(
'integer'), array($questionId)
269 require_once
'Modules/TestQuestionPool/classes/class.ilAssKprimChoiceAnswer.php';
270 require_once
'Services/RTE/classes/class.ilRTE.php';
272 while($data = $ilDB->fetchAssoc(
$res))
276 $answer->setPosition($data[
'position']);
280 $answer->setImageFile($data[
'imagefile']);
285 $answer->setCorrectness($data[
'correctness']);
287 $this->answers[$answer->getPosition()] = $answer;
294 $answer->setPosition($i);
296 $this->answers[$answer->getPosition()] = $answer;
315 'question_fi' => array(
'integer', $this->
getId())
320 'thumb_size' => array(
'integer', (
int)$this->
getThumbSize()),
337 'question_fi' => array(
'integer', (
int)$this->
getId()),
338 'position' => array(
'integer', (
int)$answer->getPosition())
341 'answertext' => array(
'text', $answer->getAnswertext()),
342 'imagefile' => array(
'text', $answer->getImageFile()),
343 'correctness' => array(
'integer', (
int)$answer->getCorrectness())
353 foreach( array($this->title, $this->author, $this->question) as $text )
370 if( is_null($answer->getCorrectness()) )
375 if( !strlen($answer->getAnswertext()) && !strlen($answer->getImageFile()) )
399 include_once
"./Modules/Test/classes/class.ilObjTest.php";
407 $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
408 array(
'integer',
'integer',
'integer'),
413 foreach($solutionSubmit as $answerIndex => $answerValue)
415 $next_id = $ilDB->nextId(
'tst_solutions');
416 $ilDB->insert(
"tst_solutions", array(
417 "solution_id" => array(
"integer", $next_id),
418 "active_fi" => array(
"integer", $active_id),
419 "question_fi" => array(
"integer", $this->
getId()),
420 "value1" => array(
"clob", (
int)$answerIndex),
421 "value2" => array(
"clob", (
int)$answerValue),
422 "pass" => array(
"integer",
$pass),
423 "tstamp" => array(
"integer", time())
432 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
440 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
477 throw new ilTestException(
'return details not implemented for '.__METHOD__);
482 $found_values = array();
487 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
488 array(
'integer',
'integer',
'integer'),
491 while ($data = $ilDB->fetchAssoc(
$result))
493 $found_values[(int)$data[
'value1']] = (
int)$data[
'value2'];
503 return array(self::ANSWER_TYPE_SINGLE_LINE, self::ANSWER_TYPE_MULTI_LINE);
524 self::ANSWER_TYPE_SINGLE_LINE => $lng->
txt(
'answers_singleline'),
525 self::ANSWER_TYPE_MULTI_LINE => $lng->
txt(
'answers_multiline')
532 self::OPTION_LABEL_RIGHT_WRONG,
533 self::OPTION_LABEL_PLUS_MINUS,
534 self::OPTION_LABEL_APPLICABLE_OR_NOT,
535 self::OPTION_LABEL_ADEQUATE_OR_NOT,
536 self::OPTION_LABEL_CUSTOM
543 self::OPTION_LABEL_RIGHT_WRONG => $lng->
txt(
'option_label_right_wrong'),
544 self::OPTION_LABEL_PLUS_MINUS => $lng->
txt(
'option_label_plus_minus'),
545 self::OPTION_LABEL_APPLICABLE_OR_NOT => $lng->
txt(
'option_label_applicable_or_not'),
546 self::OPTION_LABEL_ADEQUATE_OR_NOT => $lng->
txt(
'option_label_adequate_or_not'),
547 self::OPTION_LABEL_CUSTOM => $lng->
txt(
'option_label_custom')
561 case self::OPTION_LABEL_RIGHT_WRONG:
562 return $lng->
txt(
'option_label_right');
564 case self::OPTION_LABEL_PLUS_MINUS:
565 return $lng->
txt(
'option_label_plus');
567 case self::OPTION_LABEL_APPLICABLE_OR_NOT:
568 return $lng->
txt(
'option_label_applicable');
570 case self::OPTION_LABEL_ADEQUATE_OR_NOT:
571 return $lng->
txt(
'option_label_adequate');
573 case self::OPTION_LABEL_CUSTOM:
582 case self::OPTION_LABEL_RIGHT_WRONG:
583 return $lng->
txt(
'option_label_wrong');
585 case self::OPTION_LABEL_PLUS_MINUS:
586 return $lng->
txt(
'option_label_minus');
588 case self::OPTION_LABEL_APPLICABLE_OR_NOT:
589 return $lng->
txt(
'option_label_not_applicable');
591 case self::OPTION_LABEL_ADEQUATE_OR_NOT:
592 return $lng->
txt(
'option_label_not_adequate');
594 case self::OPTION_LABEL_CUSTOM:
602 $lng->
txt(
'kprim_instruction_text'),
624 if (strlen($answer->getImageFile()))
640 switch (strtoupper($path_info[
'extension']))
662 if( !isset($files[$answer->getPosition()]) )
675 if( !file_exists($imagePath) )
697 if( file_exists($answer->getImageFsPath()) )
699 unlink($answer->getImageFsPath());
702 if( file_exists($answer->getThumbFsPath()) )
704 unlink($answer->getThumbFsPath());
707 $answer->setImageFile(null);
712 $solutionSubmit = array();
713 foreach(
$_POST as $key => $value)
717 if(preg_match(
"/^kprim_choice_result_(\d+)/", $key, $matches))
721 $solutionSubmit[$matches[1]] = $value;
725 return $solutionSubmit;
732 foreach($this->
getAnswers() as $key => $answer)
734 if( !isset($found_values[$answer->getPosition()]) )
739 if( $found_values[$answer->getPosition()] == $answer->getCorrectness() )
745 if( $numCorrect >= self::NUM_REQUIRED_ANSWERS )
760 include_once
"./Modules/Test/classes/class.ilObjTest.php";
762 if(($mc_scoring == 0) && (count($found_values) == 0))
778 $this_id = $this->
getId();
782 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
786 if( (
int)$testObjId > 0 )
788 $clone->setObjId($testObjId);
815 $clone->copyPageOfQuestion($this_id);
817 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
819 $clone->cloneAnswerImages($this_id, $thisObjId, $clone->getId(), $clone->getObjId());
821 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
834 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
837 $sourceParentId = $this->
getObjId();
843 $clone->setObjId($targetParentId);
845 if ($targetQuestionTitle)
847 $clone->setTitle($targetQuestionTitle);
852 $clone->copyPageOfQuestion($sourceQuestionId);
854 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
856 $clone->cloneAnswerImages($sourceQuestionId, $sourceParentId, $clone->getId(), $clone->getObjId());
858 $clone->onCopy($sourceParentId, $sourceQuestionId, $targetParentId, $clone->getId());
875 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
878 $source_questionpool_id = $this->
getObjId();
879 $clone->setObjId($target_questionpool_id);
890 $clone->cloneAnswerImages(
$original_id, $source_questionpool_id, $clone->getId(), $clone->getObjId());
892 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
903 foreach(
$question->getAnswers() as $answer)
905 $question->removeAnswerImage($answer->getPosition());
913 $this->
cloneAnswerImages($dupQuestionId, $dupParentObjId, $origQuestionId, $origParentObjId);
916 protected function cloneAnswerImages($sourceQuestionId, $sourceParentId, $targetQuestionId, $targetParentId)
920 $sourcePath = $this->
buildImagePath($sourceQuestionId, $sourceParentId);
921 $targetPath = $this->
buildImagePath($targetQuestionId, $targetParentId);
929 if (!file_exists($targetPath))
934 if (!@copy($sourcePath.$filename, $targetPath.$filename))
936 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
937 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
940 if (@file_exists($sourcePath.$this->getThumbPrefix().$filename))
942 if (!@copy($sourcePath.$this->getThumbPrefix().$filename, $targetPath.$this->getThumbPrefix().$filename))
944 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
945 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
958 $combinedText .= $answer->getAnswertext();
961 return $combinedText;
969 $this->lng->loadLanguageModule(
'assessment');
971 require_once
'./Services/RTE/classes/class.ilRTE.php';
983 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
984 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
995 foreach( $this->
getAnswers() as $key => $answer )
997 if( strlen((
string)$answer->getImageFile()) )
1003 'answertext' => (
string) $this->
formatSAQuestion($answer->getAnswertext()),
1004 'correctness' => (
bool) $answer->getCorrectness(),
1005 'order' => (int)$answer->getPosition(),
1006 'image' => (string)$answer->getImageFile(),
1008 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key), 0
1022 $result[
'mobs'] =
$mobs;
1024 return json_encode($result);
1046 return $numExistingSolutionRecords >= 4;
1054 require_once
'Services/Excel/classes/class.ilExcelUtils.php';
1064 $correctness = FALSE;
1065 foreach($solution as $solutionvalue)
1067 if(
$id == $solutionvalue[
'value1'])
1069 $correctness = $solutionvalue[
'value2'];
1073 $worksheet->write($startrow + $i, 1, $correctness);
1076 return $startrow + $i + 1;
1081 if( $position < 0 || $position >= (self::NUM_REQUIRED_ANSWERS - 1) )
1086 for($i = 0, $max = count($this->answers); $i < $max; $i++)
1088 if( $i == $position )
1090 $movingAnswer = $this->answers[$i];
1091 $targetAnswer = $this->answers[ $i + 1 ];
1093 $movingAnswer->setPosition( $position + 1 );
1094 $targetAnswer->setPosition( $position );
1096 $this->answers[ $i + 1 ] = $movingAnswer;
1097 $this->answers[$i] = $targetAnswer;
1104 if( $position <= 0 || $position > (self::NUM_REQUIRED_ANSWERS - 1) )
1109 for($i = 0, $max = count($this->answers); $i < $max; $i++)
1111 if( $i == $position )
1113 $movingAnswer = $this->answers[$i];
1114 $targetAnswer = $this->answers[ $i - 1 ];
1116 $movingAnswer->setPosition( $position - 1 );
1117 $targetAnswer->setPosition( $position );
1119 $this->answers[ $i - 1 ] = $movingAnswer;
1120 $this->answers[$i] = $targetAnswer;