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';
7 require_once
'Modules/TestQuestionPool/interfaces/interface.ilAssSpecificFeedbackOptionLabelProvider.php';
55 $this->shuffleAnswersEnabled =
true;
56 $this->answerType = self::ANSWER_TYPE_SINGLE_LINE;
57 $this->thumbSize = self::DEFAULT_THUMB_SIZE;
58 $this->scorePartialSolutionEnabled =
true;
59 $this->optionLabel = self::OPTION_LABEL_RIGHT_WRONG;
60 $this->customTrueOptionLabel =
'';
61 $this->customFalseOptionLabel =
'';
63 require_once
'Modules/TestQuestionPool/classes/feedback/class.ilAssConfigurableMultiOptionQuestionFeedback.php';
66 $this->answers = array();
73 return 'assKprimChoice';
78 return "qpl_qst_kprim";
180 if($answer->getPosition() == $position)
191 $this->answers[] = $answer;
198 while(
$data = $this->db->fetchAssoc(
$res))
200 $this->
setId($questionId);
214 require_once
'Services/RTE/classes/class.ilRTE.php';
224 if( is_numeric($data[
'thumb_size']) )
237 if( $data[
'score_partsol'] !== null )
242 if( isset($data[
'feedback_setting']) )
258 parent::loadFromDb($questionId);
265 $res = $this->db->queryF(
266 "SELECT * FROM {$this->getAnswerTableName()} WHERE question_fi = %s ORDER BY position ASC",
267 array(
'integer'), array($questionId)
270 require_once
'Modules/TestQuestionPool/classes/class.ilAssKprimChoiceAnswer.php';
271 require_once
'Services/RTE/classes/class.ilRTE.php';
277 $answer->setPosition(
$data[
'position']);
281 $answer->setImageFile(
$data[
'imagefile']);
286 $answer->setCorrectness(
$data[
'correctness']);
288 $this->answers[$answer->getPosition()] = $answer;
291 for( $i = count($this->answers); $i < self::NUM_REQUIRED_ANSWERS; $i++ )
295 $answer->setPosition($i);
297 $this->answers[$answer->getPosition()] = $answer;
308 parent::saveToDb($originalId);
316 'question_fi' => array(
'integer', $this->
getId())
321 'thumb_size' => array(
'integer', (
int)$this->
getThumbSize()),
338 'question_fi' => array(
'integer', (
int)$this->
getId()),
339 'position' => array(
'integer', (
int)$answer->getPosition())
342 'answertext' => array(
'text', $answer->getAnswertext()),
343 'imagefile' => array(
'text', $answer->getImageFile()),
344 'correctness' => array(
'integer', (
int)$answer->getCorrectness())
354 foreach( array($this->title, $this->author, $this->question) as
$text )
371 if( is_null($answer->getCorrectness()) )
376 if( !strlen($answer->getAnswertext()) && !strlen($answer->getImageFile()) )
400 include_once
"./Modules/Test/classes/class.ilObjTest.php";
412 foreach($solutionSubmit as $answerIndex => $answerValue)
422 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
430 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
467 throw new ilTestException(
'return details not implemented for '.__METHOD__);
472 $found_values = array();
482 $found_values[(int)
$data[
'value1']] = (
int)
$data[
'value2'];
492 return array(self::ANSWER_TYPE_SINGLE_LINE, self::ANSWER_TYPE_MULTI_LINE);
513 self::ANSWER_TYPE_SINGLE_LINE => $lng->
txt(
'answers_singleline'),
514 self::ANSWER_TYPE_MULTI_LINE => $lng->
txt(
'answers_multiline')
521 self::OPTION_LABEL_RIGHT_WRONG,
522 self::OPTION_LABEL_PLUS_MINUS,
523 self::OPTION_LABEL_APPLICABLE_OR_NOT,
524 self::OPTION_LABEL_ADEQUATE_OR_NOT,
525 self::OPTION_LABEL_CUSTOM
532 self::OPTION_LABEL_RIGHT_WRONG => $lng->
txt(
'option_label_right_wrong'),
533 self::OPTION_LABEL_PLUS_MINUS => $lng->
txt(
'option_label_plus_minus'),
534 self::OPTION_LABEL_APPLICABLE_OR_NOT => $lng->
txt(
'option_label_applicable_or_not'),
535 self::OPTION_LABEL_ADEQUATE_OR_NOT => $lng->
txt(
'option_label_adequate_or_not'),
536 self::OPTION_LABEL_CUSTOM => $lng->
txt(
'option_label_custom')
550 case self::OPTION_LABEL_RIGHT_WRONG:
551 return $lng->
txt(
'option_label_right');
553 case self::OPTION_LABEL_PLUS_MINUS:
554 return $lng->
txt(
'option_label_plus');
556 case self::OPTION_LABEL_APPLICABLE_OR_NOT:
557 return $lng->
txt(
'option_label_applicable');
559 case self::OPTION_LABEL_ADEQUATE_OR_NOT:
560 return $lng->
txt(
'option_label_adequate');
562 case self::OPTION_LABEL_CUSTOM:
571 case self::OPTION_LABEL_RIGHT_WRONG:
572 return $lng->
txt(
'option_label_wrong');
574 case self::OPTION_LABEL_PLUS_MINUS:
575 return $lng->
txt(
'option_label_minus');
577 case self::OPTION_LABEL_APPLICABLE_OR_NOT:
578 return $lng->
txt(
'option_label_not_applicable');
580 case self::OPTION_LABEL_ADEQUATE_OR_NOT:
581 return $lng->
txt(
'option_label_not_adequate');
583 case self::OPTION_LABEL_CUSTOM:
591 $lng->
txt(
'kprim_instruction_text'),
599 return $labelValue == self::OPTION_LABEL_CUSTOM;
604 return self::THUMB_PREFIX;
613 if (strlen($answer->getImageFile()))
629 switch (strtoupper($path_info[
'extension']))
651 if( !isset($files[$answer->getPosition()]) )
664 if( !file_exists($imagePath) )
686 if( file_exists($answer->getImageFsPath()) )
691 if( file_exists($answer->getThumbFsPath()) )
696 $answer->setImageFile(null);
701 $solutionSubmit = array();
702 foreach(
$_POST as $key => $value)
706 if(preg_match(
"/^kprim_choice_result_(\d+)/", $key, $matches))
710 $solutionSubmit[$matches[1]] = $value;
714 return $solutionSubmit;
721 foreach($this->
getAnswers() as $key => $answer)
723 if( !isset($found_values[$answer->getPosition()]) )
728 if( $found_values[$answer->getPosition()] == $answer->getCorrectness() )
734 if( $numCorrect >= self::NUM_REQUIRED_ANSWERS )
749 include_once
"./Modules/Test/classes/class.ilObjTest.php";
751 if(($mc_scoring == 0) && (count($found_values) == 0))
767 $this_id = $this->
getId();
771 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
775 if( (
int)$testObjId > 0 )
777 $clone->setObjId($testObjId);
804 $clone->copyPageOfQuestion($this_id);
806 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
808 $clone->cloneAnswerImages($this_id, $thisObjId, $clone->getId(), $clone->getObjId());
810 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
823 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
826 $sourceParentId = $this->
getObjId();
832 $clone->setObjId($targetParentId);
834 if ($targetQuestionTitle)
836 $clone->setTitle($targetQuestionTitle);
841 $clone->copyPageOfQuestion($sourceQuestionId);
843 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
845 $clone->cloneAnswerImages($sourceQuestionId, $sourceParentId, $clone->getId(), $clone->getObjId());
847 $clone->onCopy($sourceParentId, $sourceQuestionId, $targetParentId, $clone->getId());
864 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
867 $source_questionpool_id = $this->
getObjId();
868 $clone->setObjId($target_questionpool_id);
879 $clone->cloneAnswerImages(
$original_id, $source_questionpool_id, $clone->getId(), $clone->getObjId());
881 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
888 parent::beforeSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId);
890 $question = self::_instanciateQuestion($origQuestionId);
892 foreach(
$question->getAnswers() as $answer)
894 $question->removeAnswerImage($answer->getPosition());
900 parent::afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId);
902 $this->cloneAnswerImages($dupQuestionId, $dupParentObjId, $origQuestionId, $origParentObjId);
905 protected function cloneAnswerImages($sourceQuestionId, $sourceParentId, $targetQuestionId, $targetParentId)
910 $sourcePath = $this->
buildImagePath($sourceQuestionId, $sourceParentId);
911 $targetPath = $this->
buildImagePath($targetQuestionId, $targetParentId);
919 if (!file_exists($targetPath))
924 if(!@copy($sourcePath .
$filename, $targetPath . $filename))
926 $ilLog->warning(sprintf(
927 "Could not clone source image '%s' to '%s' (srcQuestionId: %s|tgtQuestionId: %s|srcParentObjId: %s|tgtParentObjId: %s)",
928 $sourcePath . $filename, $targetPath . $filename,
929 $sourceQuestionId, $targetQuestionId, $sourceParentId, $targetParentId
933 if(@file_exists($sourcePath . $this->
getThumbPrefix() . $filename))
937 $ilLog->warning(sprintf(
938 "Could not clone thumbnail source image '%s' to '%s' (srcQuestionId: %s|tgtQuestionId: %s|srcParentObjId: %s|tgtParentObjId: %s)",
940 $sourceQuestionId, $targetQuestionId, $sourceParentId, $targetParentId
950 $combinedText = parent::getRTETextWithMediaObjects();
954 $combinedText .= $answer->getAnswertext();
957 return $combinedText;
977 $this->lng->loadLanguageModule(
'assessment');
979 require_once
'./Services/RTE/classes/class.ilRTE.php';
991 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
992 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
1003 foreach( $this->
getAnswers() as $key => $answer )
1005 if( strlen((
string)$answer->getImageFile()) )
1011 'answertext' => (
string) $this->
formatSAQuestion($answer->getAnswertext()),
1012 'correctness' => (
bool) $answer->getCorrectness(),
1013 'order' => (int)$answer->getPosition(),
1014 'image' => (string)$answer->getImageFile(),
1016 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key)
1030 $result[
'mobs'] =
$mobs;
1032 return json_encode($result);
1039 return self::NUM_REQUIRED_ANSWERS - self::PARTIAL_SCORING_NUM_CORRECT_ANSWERS;
1047 return 'feedback_correct_kprim';
1059 return $numExistingSolutionRecords >= 4;
1067 require_once
'Services/Excel/classes/class.ilExcelUtils.php';
1077 $correctness = FALSE;
1078 foreach($solution as $solutionvalue)
1080 if(
$id == $solutionvalue[
'value1'])
1082 $correctness = $solutionvalue[
'value2'];
1086 $worksheet->write($startrow + $i, 1, $correctness);
1089 return $startrow + $i + 1;
1094 if( $position < 0 || $position >= (self::NUM_REQUIRED_ANSWERS - 1) )
1099 for($i = 0, $max = count($this->answers); $i < $max; $i++)
1101 if( $i == $position )
1103 $movingAnswer = $this->answers[$i];
1104 $targetAnswer = $this->answers[ $i + 1 ];
1106 $movingAnswer->setPosition( $position + 1 );
1107 $targetAnswer->setPosition( $position );
1109 $this->answers[ $i + 1 ] = $movingAnswer;
1110 $this->answers[$i] = $targetAnswer;
1117 if( $position <= 0 || $position > (self::NUM_REQUIRED_ANSWERS - 1) )
1122 for($i = 0, $max = count($this->answers); $i < $max; $i++)
1124 if( $i == $position )
1126 $movingAnswer = $this->answers[$i];
1127 $targetAnswer = $this->answers[ $i - 1 ];
1129 $movingAnswer->setPosition( $position - 1 );
1130 $targetAnswer->setPosition( $position );
1132 $this->answers[ $i - 1 ] = $movingAnswer;
1133 $this->answers[$i] = $targetAnswer;
getValidOptionLabelsTranslated(ilLanguage $lng)
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getId()
Gets the id of the assQuestion object.
setImageFsDir($imageFsDir)
static _getOriginalId($question_id)
Returns the original id of a question.
formatSAQuestion($a_q)
Format self assessment question.
isValidAnswerType($answerType)
static getNumExistingSolutionRecords($activeId, $pass, $questionId)
returns the number of existing solution records for the given test active / pass and given question i...
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
getRTETextWithMediaObjects()
setScorePartialSolutionEnabled($scorePartialSolutionEnabled)
getPoints()
Returns the maximum available points for the question.
static isObligationPossible($questionId)
const OPTION_LABEL_RIGHT_WRONG
isCustomOptionLabel($labelValue)
Abstract basic class which is to be extended by the concrete assessment question type classes...
_getPass($active_id)
Retrieves the actual pass of a given user for a given test.
__construct($title='', $comment='', $author='', $owner=-1, $question='')
_convert_text($a_text, $a_target="has been removed")
const OPTION_LABEL_ADEQUATE_OR_NOT
setId($id=-1)
Sets the id of the assQuestion object.
const NUM_REQUIRED_ANSWERS
_getMCScoring($active_id)
Gets the scoring type for multiple choice questions.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
const PARTIAL_SCORING_NUM_CORRECT_ANSWERS
removeAnswerImage($position)
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
lmMigrateQuestionTypeSpecificContent(ilAssSelfAssessmentMigrator $migrator)
getSpecificFeedbackSetting()
migrateToLmContent($content)
moveAnswerDown($position)
copyObject($target_questionpool_id, $title="")
Copies an assMultipleChoice object.
saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized=true)
getSpecificFeedbackAllCorrectOptionLabel()
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
setEstimatedWorkingTimeFromDurationString($durationString)
Sets the estimated working time of a question from a given datetime string.
setNrOfTries($a_nr_of_tries)
_enabledAssessmentLogging()
check wether assessment logging is enabled or not
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
setCustomTrueOptionLabel($customTrueOptionLabel)
isValidOptionLabel($optionLabel)
loadAnswerData($questionId)
getTrueOptionLabelTranslation(ilLanguage $lng, $optionLabel)
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...
getObjId()
Get the object id of the container object.
beforeSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)
addAnswer(ilAssKprimChoiceAnswer $answer)
Base Exception for all Exceptions relating to Modules/Test.
setOptionLabel($optionLabel)
reworkWorkingData($active_id, $pass, $obligationsAnswered)
Reworks the allready saved working data if neccessary.
const ANSWER_TYPE_MULTI_LINE
isScorePartialSolutionEnabled()
setAuthor($author="")
Sets the authors name of the assQuestion object.
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
isSingleLineAnswerType($answerType)
getAnswerTypeSelectOptions(ilLanguage $lng)
removeCurrentSolution($active_id, $pass, $authorized=true, $ignoredSolutionIds=array())
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
isShuffleAnswersEnabled()
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
setShuffleAnswersEnabled($shuffleAnswersEnabled)
Interface ilObjAnswerScoringAdjustable.
const OPTION_LABEL_APPLICABLE_OR_NOT
saveWorkingData($active_id, $pass=NULL, $authorized=true)
Saves the learners input of the question to the database.
getCustomFalseOptionLabel()
handleFileUploads($answers, $files)
getQuestion()
Gets the question string of the question object.
isAnswered($active_id, $pass=null)
calculateReachedPoints($active_id, $pass=NULL, $authorizedSolution=true, $returndetails=FALSE)
Returns the points, a learner has reached answering the question.
_getLogLanguage()
retrieve the log language for assessment logging
setPoints($a_points)
Sets the maximum available points for the question.
saveQuestionDataToDb($original_id="")
setCustomFalseOptionLabel($customFalseOptionLabel)
getFalseOptionLabelTranslation(ilLanguage $lng, $optionLabel)
const OPTION_LABEL_CUSTOM
calculateReachedPointsForSolution($found_values, $active_id=0)
setExportDetailsXLS(&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
{}
setQuestion($question="")
Sets the question string of the question object.
const FEEDBACK_SETTING_ALL
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
Interface ilObjQuestionScoringAdjustable.
setSpecificFeedbackSetting($specificFeedbackSetting)
buildImagePath($questionId, $parentObjectId)
setOriginalId($original_id)
generateThumbForFile($path, $file)
setLastChange($lastChange)
getCurrentSolutionResultSet($active_id, $pass, $authorized=true)
Get a restulset for the current user solution for a this question by active_id and pass...
getCustomTrueOptionLabel()
getSolutionValues($active_id, $pass=NULL, $authorized=true)
Loads solutions of a given user from the database an returns it.
logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
getTitle()
Gets the title string of the assQuestion object.
handleFileUpload(ilAssKprimChoiceAnswer $answer, $fileData)
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
$scorePartialSolutionEnabled
txt($a_topic, $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
const OPTION_LABEL_PLUS_MINUS
setTitle($title="")
Sets the title string of the assQuestion object.
setObjId($obj_id=0)
Set the object id of the container object.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
setComment($comment="")
Sets the comment string of the assQuestion object.
setAnswerType($answerType)
getInstructionTextTranslation(ilLanguage $lng, $optionLabel)
createNewImageFileName($image_filename, $unique=false)
const ANSWER_TYPE_SINGLE_LINE
toJSON()
Returns a JSON representation of the question.
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.
afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)