4require_once 
'Modules/TestQuestionPool/classes/class.assQuestion.php';
 
    5require_once 
'Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
 
    6require_once 
'Modules/TestQuestionPool/interfaces/interface.ilObjAnswerScoringAdjustable.php';
 
    7require_once 
'Modules/TestQuestionPool/interfaces/interface.ilAssSpecificFeedbackOptionLabelProvider.php';
 
   55        $this->shuffleAnswersEnabled = 
true;
 
   58        $this->scorePartialSolutionEnabled = 
true;
 
   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";
 
  172            $answer->setAnswertext(
 
  177        $this->answers = array_map($clean_answer_text, 
$answers);
 
  188            if ($answer->getPosition() == $position) {
 
  201        $this->answers[] = $answer;
 
  208        while (
$data = $this->db->fetchAssoc(
$res)) {
 
  209            $this->
setId($questionId);
 
  223            require_once 
'Services/RTE/classes/class.ilRTE.php';
 
  232            if (is_numeric(
$data[
'thumb_size'])) {
 
  243            if (
$data[
'score_partsol'] !== 
null) {
 
  247            if (isset(
$data[
'feedback_setting'])) {
 
  265        parent::loadFromDb($questionId);
 
  273        $res = $this->db->queryF(
 
  274            "SELECT * FROM {$this->getAnswerTableName()} WHERE question_fi = %s ORDER BY position ASC",
 
  279        require_once 
'Modules/TestQuestionPool/classes/class.ilAssKprimChoiceAnswer.php';
 
  280        require_once 
'Services/RTE/classes/class.ilRTE.php';
 
  285            $answer->setPosition(
$data[
'position']);
 
  289            $answer->setImageFile(
$data[
'imagefile']);
 
  294            $answer->setCorrectness(
$data[
'correctness']);
 
  296            $answers[$answer->getPosition()] = $answer;
 
  304            $answer->setPosition(
$i);
 
  306            $this->answers[$answer->getPosition()] = $answer;
 
  317        parent::saveToDb($originalId);
 
  325                'question_fi' => array(
'integer', $this->
getId())
 
  330                'thumb_size' => array(
'integer', (
int) $this->
getThumbSize()),
 
  346                    'question_fi' => array(
'integer', (
int) $this->
getId()),
 
  347                    'position' => array(
'integer', (
int) $answer->getPosition())
 
  350                    'answertext' => array(
'text', $answer->getAnswertext()),
 
  351                    'imagefile' => array(
'text', $answer->getImageFile()),
 
  352                    'correctness' => array(
'integer', (
int) $answer->getCorrectness())
 
  362        foreach (array($this->title, $this->author, $this->question) as $text) {
 
  363            if (!strlen($text)) {
 
  375            if (is_null($answer->getCorrectness())) {
 
  379            if (!strlen($answer->getAnswertext()) && !strlen($answer->getImageFile())) {
 
  400        if (is_null(
$pass)) {
 
  401            include_once 
"./Modules/Test/classes/class.ilObjTest.php";
 
  407        $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$entered_values, $active_id, 
$pass, $authorized) {
 
  412            foreach ($solutionSubmit as $answerIndex => $answerValue) {
 
  418        if ($entered_values) {
 
  419            include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
 
  424            include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
 
  445        if ($returndetails) {
 
  446            throw new ilTestException(
'return details not implemented for ' . __METHOD__);
 
  452        $found_values = array();
 
  453        if (is_null(
$pass)) {
 
  460            $found_values[(int) 
$data[
'value1']] = (
int) 
$data[
'value2'];
 
  470        return array(self::ANSWER_TYPE_SINGLE_LINE, self::ANSWER_TYPE_MULTI_LINE);
 
  491            self::ANSWER_TYPE_SINGLE_LINE => 
$lng->txt(
'answers_singleline'),
 
  492            self::ANSWER_TYPE_MULTI_LINE => 
$lng->txt(
'answers_multiline')
 
  499            self::OPTION_LABEL_RIGHT_WRONG,
 
  500            self::OPTION_LABEL_PLUS_MINUS,
 
  501            self::OPTION_LABEL_APPLICABLE_OR_NOT,
 
  502            self::OPTION_LABEL_ADEQUATE_OR_NOT,
 
  503            self::OPTION_LABEL_CUSTOM
 
  510            self::OPTION_LABEL_RIGHT_WRONG => 
$lng->txt(
'option_label_right_wrong'),
 
  511            self::OPTION_LABEL_PLUS_MINUS => 
$lng->txt(
'option_label_plus_minus'),
 
  512            self::OPTION_LABEL_APPLICABLE_OR_NOT => 
$lng->txt(
'option_label_applicable_or_not'),
 
  513            self::OPTION_LABEL_ADEQUATE_OR_NOT => 
$lng->txt(
'option_label_adequate_or_not'),
 
  514            self::OPTION_LABEL_CUSTOM => 
$lng->txt(
'option_label_custom')
 
  528                return $lng->txt(
'option_label_right');
 
  531                return $lng->txt(
'option_label_plus');
 
  534                return $lng->txt(
'option_label_applicable');
 
  537                return $lng->txt(
'option_label_adequate');
 
  548                return $lng->txt(
'option_label_wrong');
 
  551                return $lng->txt(
'option_label_minus');
 
  554                return $lng->txt(
'option_label_not_applicable');
 
  557                return $lng->txt(
'option_label_not_adequate');
 
  567            $lng->txt(
'kprim_instruction_text'),
 
  587                if (strlen($answer->getImageFile())) {
 
  601            switch (strtoupper($path_info[
'extension'])) {
 
  621            if (!isset($files[$answer->getPosition()])) {
 
  633        if (!file_exists($imagePath)) {
 
  653        if (file_exists($answer->getImageFsPath())) {
 
  657        if (file_exists($answer->getThumbFsPath())) {
 
  661        $answer->setImageFile(
null);
 
  666        $solutionSubmit = array();
 
  667        foreach (
$_POST as $key => $value) {
 
  670            if (preg_match(
"/^kprim_choice_result_(\d+)/", $key, $matches)) {
 
  671                if (strlen($value)) {
 
  672                    $solutionSubmit[$matches[1]] = $value;
 
  676        return $solutionSubmit;
 
  683        foreach ($this->
getAnswers() as $key => $answer) {
 
  684            if (!isset($found_values[$answer->getPosition()])) {
 
  688            if ($found_values[$answer->getPosition()] == $answer->getCorrectness()) {
 
  693        if ($numCorrect >= self::NUM_REQUIRED_ANSWERS) {
 
  702            include_once 
"./Modules/Test/classes/class.ilObjTest.php";
 
  704            if (($mc_scoring == 0) && (count($found_values) == 0)) {
 
  713        if ($this->
id <= 0) {
 
  718        $this_id = $this->
getId();
 
  722        include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
 
  726        if ((
int) $testObjId > 0) {
 
  727            $clone->setObjId($testObjId);
 
  748        $clone->copyPageOfQuestion($this_id);
 
  750        $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
 
  752        $clone->cloneAnswerImages($this_id, $thisObjId, $clone->getId(), $clone->getObjId());
 
  754        $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
 
  761        if ($this->
id <= 0) {
 
  766        include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
 
  769        $sourceParentId = $this->
getObjId();
 
  775        $clone->setObjId($targetParentId);
 
  777        if ($targetQuestionTitle) {
 
  778            $clone->setTitle($targetQuestionTitle);
 
  783        $clone->copyPageOfQuestion($sourceQuestionId);
 
  785        $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
 
  787        $clone->cloneAnswerImages($sourceQuestionId, $sourceParentId, $clone->getId(), $clone->getObjId());
 
  789        $clone->onCopy($sourceParentId, $sourceQuestionId, $targetParentId, $clone->getId());
 
  799        if ($this->
id <= 0) {
 
  805        include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
 
  808        $source_questionpool_id = $this->
getObjId();
 
  809        $clone->setObjId($target_questionpool_id);
 
  819        $clone->cloneAnswerImages(
$original_id, $source_questionpool_id, $clone->getId(), $clone->getObjId());
 
  821        $clone->onCopy($source_questionpool_id, 
$original_id, $clone->getObjId(), $clone->getId());
 
  828        parent::beforeSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId);
 
  832        foreach (
$question->getAnswers() as $answer) {
 
  833            $question->removeAnswerImage($answer->getPosition());
 
  839        parent::afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId);
 
  841        $this->cloneAnswerImages($dupQuestionId, $dupParentObjId, $origQuestionId, $origParentObjId);
 
  844    protected function cloneAnswerImages($sourceQuestionId, $sourceParentId, $targetQuestionId, $targetParentId)
 
  850        $sourcePath = $this->
buildImagePath($sourceQuestionId, $sourceParentId);
 
  851        $targetPath = $this->
buildImagePath($targetQuestionId, $targetParentId);
 
  857                if (!file_exists($targetPath)) {
 
  861                if (file_exists($sourcePath . 
$filename)) {
 
  864                            "Could not clone source image '%s' to '%s' (srcQuestionId: %s|tgtQuestionId: %s|srcParentObjId: %s|tgtParentObjId: %s)",
 
  875                if (file_exists($sourcePath . $this->
getThumbPrefix() . $filename)) {
 
  878                            "Could not clone thumbnail source image '%s' to '%s' (srcQuestionId: %s|tgtQuestionId: %s|srcParentObjId: %s|tgtParentObjId: %s)",
 
  894        $combinedText = parent::getRTETextWithMediaObjects();
 
  897            $combinedText .= $answer->getAnswertext();
 
  900        return $combinedText;
 
  919        $this->lng->loadLanguageModule(
'assessment');
 
  921        require_once 
'./Services/RTE/classes/class.ilRTE.php';
 
  934            'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), 
false)),
 
  935            'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), 
true))
 
  946        foreach ($this->
getAnswers() as $key => $answer) {
 
  947            if (strlen((
string) $answer->getImageFile())) {
 
  953                'correctness' => (
bool) $answer->getCorrectness(),
 
  954                'order' => (
int) $answer->getPosition(),
 
  955                'image' => (
string) $answer->getImageFile(),
 
  956                'feedback' => $this->formatSAQuestion(
 
  957                    $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
 
  986        return 'feedback_correct_kprim';
 
  998        return $numExistingSolutionRecords >= 4;
 
 1006        parent::setExportDetailsXLS($worksheet, $startrow, $active_id, 
$pass);
 
 1012            $worksheet->setCell($startrow + 
$i, 0, $answer->getAnswertext());
 
 1013            $worksheet->setBold($worksheet->getColumnCoord(0) . ($startrow + 
$i));
 
 1014            $correctness = 
false;
 
 1015            foreach ($solution as $solutionvalue) {
 
 1016                if (
$id == $solutionvalue[
'value1']) {
 
 1017                    $correctness = $solutionvalue[
'value2'];
 
 1021            $worksheet->setCell($startrow + 
$i, 1, $correctness);
 
 1025        return $startrow + 
$i + 1;
 
 1030        if ($position < 0 || $position >= (self::NUM_REQUIRED_ANSWERS - 1)) {
 
 1034        for (
$i = 0, $max = count($this->answers); 
$i < $max; 
$i++) {
 
 1035            if (
$i == $position) {
 
 1036                $movingAnswer = $this->answers[
$i];
 
 1037                $targetAnswer = $this->answers[ 
$i + 1 ];
 
 1039                $movingAnswer->setPosition($position + 1);
 
 1040                $targetAnswer->setPosition($position);
 
 1042                $this->answers[ 
$i + 1 ] = $movingAnswer;
 
 1043                $this->answers[
$i] = $targetAnswer;
 
 1050        if ($position <= 0 || $position > (self::NUM_REQUIRED_ANSWERS - 1)) {
 
 1054        for (
$i = 0, $max = count($this->answers); 
$i < $max; 
$i++) {
 
 1055            if (
$i == $position) {
 
 1056                $movingAnswer = $this->answers[
$i];
 
 1057                $targetAnswer = $this->answers[ 
$i - 1 ];
 
 1059                $movingAnswer->setPosition($position - 1);
 
 1060                $targetAnswer->setPosition($position);
 
 1062                $this->answers[ 
$i - 1 ] = $movingAnswer;
 
 1063                $this->answers[
$i] = $targetAnswer;
 
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
An exception for terminatinating execution or to throw for unit testing.
$scorePartialSolutionEnabled
getSpecificFeedbackAllCorrectOptionLabel()
getQuestionType()
Returns the question type of the question.
const PARTIAL_SCORING_NUM_CORRECT_ANSWERS
getRTETextWithMediaObjects()
Collects all text in the question which could contain media objects which were created with the Rich ...
toJSON()
Returns a JSON representation of the question.
beforeSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)
const OPTION_LABEL_RIGHT_WRONG
isSingleLineAnswerType($answerType)
setCustomTrueOptionLabel($customTrueOptionLabel)
getAdditionalTableName()
Returns the name of the additional question data table in the database.
handleFileUpload(ilAssKprimChoiceAnswer $answer, $fileData)
const ANSWER_TYPE_MULTI_LINE
handleFileUploads($answers, $files)
setCustomFalseOptionLabel($customFalseOptionLabel)
const NUM_REQUIRED_ANSWERS
getAnswerTableName()
Returns the name of the answer table in the database.
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
const ANSWER_TYPE_SINGLE_LINE
duplicate($for_test=true, $title="", $author="", $owner="", $testObjId=null)
isScorePartialSolutionEnabled()
addAnswer(ilAssKprimChoiceAnswer $answer)
generateThumbForFile($path, $file)
removeAnswerImage($position)
copyObject($target_questionpool_id, $title="")
Copies an assMultipleChoice object.
afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)
const OPTION_LABEL_ADEQUATE_OR_NOT
static isObligationPossible($questionId)
returns boolean wether it is possible to set this question type as obligatory or not considering the ...
loadAnswerData($questionId)
const OPTION_LABEL_CUSTOM
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
setSpecificFeedbackSetting($specificFeedbackSetting)
createNewOriginalFromThisDuplicate($targetParentId, $targetQuestionTitle="")
getValidOptionLabelsTranslated(ilLanguage $lng)
getTrueOptionLabelTranslation(ilLanguage $lng, $optionLabel)
isAnswered($active_id, $pass=null)
returns boolean wether the question is answered during test pass or not
getCustomFalseOptionLabel()
setAnswerType($answerType)
saveToDb($originalId='')
Saves the question to the database.
getFalseOptionLabelTranslation(ilLanguage $lng, $optionLabel)
calculateReachedPointsForSolution($found_values, $active_id=0)
setExportDetailsXLS($worksheet, $startrow, $active_id, $pass)
{Creates an Excel worksheet for the detailed cumulated results of this question.object}
const OPTION_LABEL_PLUS_MINUS
isValidOptionLabel($optionLabel)
isCustomOptionLabel($labelValue)
isValidAnswerType($answerType)
lmMigrateQuestionTypeSpecificContent(ilAssSelfAssessmentMigrator $migrator)
getInstructionTextTranslation(ilLanguage $lng, $optionLabel)
setOptionLabel($optionLabel)
isShuffleAnswersEnabled()
moveAnswerDown($position)
getSpecificFeedbackSetting()
loadFromDb($questionId)
Loads the question from the database.
isComplete()
Returns true, if a question is complete for use.
getAnswerTypeSelectOptions(ilLanguage $lng)
setShuffleAnswersEnabled($shuffleAnswersEnabled)
calculateReachedPoints($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
Returns the points, a learner has reached answering the question.
const OPTION_LABEL_APPLICABLE_OR_NOT
__construct($title='', $comment='', $author='', $owner=-1, $question='')
assQuestion constructor
setScorePartialSolutionEnabled($scorePartialSolutionEnabled)
getCustomTrueOptionLabel()
Abstract basic class which is to be extended by the concrete assessment question type classes.
getCurrentSolutionResultSet($active_id, $pass, $authorized=true)
Get a restulset for the current user solution for a this question by active_id and pass.
getSolutionValues($active_id, $pass=null, $authorized=true)
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.
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="")
getHtmlQuestionContentPurifier()
getId()
Gets the id of the assQuestion object.
saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized=true, $tstamp=null)
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.
setEstimatedWorkingTimeFromDurationString($durationString)
Sets the estimated working time of a question from a given datetime string.
buildImagePath($questionId, $parentObjectId)
static logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
removeCurrentSolution($active_id, $pass, $authorized=true)
buildHashedImageFilename($plain_image_filename, $unique=false)
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.
getPoints()
Returns the maximum available points for the question.
saveWorkingData($active_id, $pass=null, $authorized=true)
Saves the learners input of the question to the database.
setLifecycle(ilAssQuestionLifecycle $lifecycle)
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
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
setQuestion($question="")
Sets the question string of the question object.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
setLastChange($lastChange)
const FEEDBACK_SETTING_ALL
setAnswertext($answertext)
setImageFsDir($imageFsDir)
static getDraftInstance()
static getInstance($identifier)
static _getLogLanguage()
retrieve the log language for assessment logging
static _enabledAssessmentLogging()
check wether assessment logging is enabled or not
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static _getMCScoring($active_id)
Gets the scoring type for multiple choice questions.
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.
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 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.
migrateToLmContent($content)
Interface ilObjAnswerScoringAdjustable.
Interface ilObjQuestionScoringAdjustable.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
foreach($_POST as $key=> $value) $res