ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
assKprimChoice Class Reference
+ Inheritance diagram for assKprimChoice:
+ Collaboration diagram for assKprimChoice:

Public Member Functions

 __construct ($title='', $comment='', $author='', $owner=-1, $question='')
 
 getQuestionType ()
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 setShuffleAnswersEnabled (bool $shuffle_answers_enabled)
 
 isShuffleAnswersEnabled ()
 
 setAnswerType ($answerType)
 
 getAnswerType ()
 
 setThumbSize (int $thumbSize)
 
 getThumbSize ()
 
 setScorePartialSolutionEnabled ($scorePartialSolutionEnabled)
 
 isScorePartialSolutionEnabled ()
 
 setOptionLabel (string $option_label)
 
 getOptionLabel ()
 
 setCustomTrueOptionLabel ($customTrueOptionLabel)
 
 getCustomTrueOptionLabel ()
 
 setCustomFalseOptionLabel ($customFalseOptionLabel)
 
 getCustomFalseOptionLabel ()
 
 setSpecificFeedbackSetting (int $specific_feedback_setting)
 
 getSpecificFeedbackSetting ()
 
 setAnswers ($answers)
 
 getAnswers ()
 
 getAnswer ($position)
 
 addAnswer (ilAssKprimChoiceAnswer $answer)
 
 loadFromDb ($questionId)
 
 saveToDb (?int $original_id=null)
 
 saveAdditionalQuestionDataToDb ()
 Saves a record to the question types additional data table. More...
 
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
 isComplete ()
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 calculateReachedPoints (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 getValidAnswerTypes ()
 
 isValidAnswerType ($answerType)
 
 isSingleLineAnswerType ($answerType)
 
 getAnswerTypeSelectOptions (ilLanguage $lng)
 
 getValidOptionLabels ()
 
 getValidOptionLabelsTranslated (ilLanguage $lng)
 
 getLangVarForOptionLabel (string $option_label)
 
 isValidOptionLabel (?string $option_label)
 
 getTrueOptionLabelTranslation (ilLanguage $lng, string $option_label)
 
 getTrueOptionLabel (string $option_label)
 
 getFalseOptionLabelTranslation (ilLanguage $lng, string $option_label)
 
 getInstructionTextTranslation (ilLanguage $lng, $option_label)
 
 isCustomOptionLabel ($labelValue)
 
 handleFileUploads ($answers, $files)
 
 removeAnswerImage ($position)
 
 toJSON ()
 Returns a JSON representation of the question. More...
 
 getSpecificFeedbackAllCorrectOptionLabel ()
 
 moveAnswerDown ($position)
 
 moveAnswerUp ($position)
 
 toLog (AdditionalInformationGenerator $additional_info)
 MUST return an array of the question settings that can be stored in the log. More...
 
 solutionValuesToText (array $solution_values)
 MUST convert the given solution values into text. More...
 
 getCorrectSolutionForTextOutput (int $active_id, int $pass)
 
- Public Member Functions inherited from assQuestion
 getQuestionType ()
 
 isComplete ()
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 calculateReachedPoints (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 MUST return an array of the question settings that can be stored in the log. More...
 
 getCurrentUser ()
 
 getShuffler ()
 
 setShuffler (Transformation $shuffler)
 
 setProcessLocker (ilAssQuestionProcessLocker $processLocker)
 
 getProcessLocker ()
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 toXML (bool $a_include_header=true, bool $a_include_binary=true, bool $a_shuffle=false, bool $test_output=false, bool $force_image_references=false)
 Returns a QTI xml representation of the question. More...
 
 setTitle (string $title="")
 
 setId (int $id=-1)
 
 setTestId (int $id=-1)
 
 setComment (string $comment="")
 
 setShuffle (?bool $shuffle=true)
 
 setAuthor (string $author="")
 
 setOwner (int $owner=-1)
 
 getTitle ()
 
 getTitleForHTMLOutput ()
 
 getTitleFilenameCompliant ()
 
 getId ()
 
 getShuffle ()
 
 getTestId ()
 
 getComment ()
 
 getDescriptionForHTMLOutput ()
 
 getThumbSize ()
 
 setThumbSize (int $a_size)
 
 getMinimumThumbSize ()
 
 getMaximumThumbSize ()
 
 getAuthor ()
 
 getAuthorForHTMLOutput ()
 
 getOwner ()
 
 getObjId ()
 
 setObjId (int $obj_id=0)
 
 getLifecycle ()
 
 setLifecycle (ilAssQuestionLifecycle $lifecycle)
 
 setExternalId (?string $external_id)
 
 getExternalId ()
 
 getSuggestedSolutionOutput ()
 
 getSuggestedSolutions ()
 
 getReachedPoints (int $active_id, int $pass)
 
 getMaximumPoints ()
 
 getAdjustedReachedPoints (int $active_id, int $pass, bool $authorized_solution=true)
 
 calculateResultsFromSolution (int $active_id, int $pass)
 Calculates the question results from a previously saved question solution. More...
 
 persistWorkingState (int $active_id, $pass, bool $authorized=true)
 persists the working state for current testactive and testpass More...
 
 persistPreviewState (ilAssQuestionPreviewSession $preview_session)
 persists the preview state for current user and question More...
 
 validateSolutionSubmit ()
 
 getSuggestedSolutionPath ()
 
 getImagePath ($question_id=null, $object_id=null)
 Returns the image path for web accessable images of a question. More...
 
 getSuggestedSolutionPathWeb ()
 
 getImagePathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 getTestOutputSolutions (int $activeId, int $pass)
 
 getUserSolutionPreferingIntermediate (int $active_id, ?int $pass=null)
 
 getSolutionValues (int $active_id, ?int $pass=null, bool $authorized=true)
 Loads solutions of a given user from the database an returns it. More...
 
 deleteAnswers (int $question_id)
 
 deleteAdditionalTableData (int $question_id)
 
 delete (int $question_id)
 
 getTotalAnswers ()
 
 cloneXHTMLMediaObjectsOfQuestion (int $source_question_id)
 
 createPageObject ()
 
 clonePageOfQuestion (int $a_q_id)
 
 getPageOfQuestion ()
 
 setOriginalId (?int $original_id)
 
 getOriginalId ()
 
 fixSvgToPng (string $imageFilenameContainingString)
 
 fixUnavailableSkinImageSources (string $html)
 
 loadFromDb (int $question_id)
 
 createNewQuestion (bool $a_create_page=true)
 Creates a new question without an owner when a new question is created This assures that an ID is given to the question if a file upload or something else occurs. More...
 
 saveQuestionDataToDb (?int $original_id=null)
 
 duplicate (bool $for_test=true, string $title='', string $author='', int $owner=-1, $test_obj_id=null)
 
 copyObject (int $target_parent_id, string $title='')
 
 createNewOriginalFromThisDuplicate (int $target_parent_id, string $target_question_title='')
 
 saveToDb (?int $original_id=null)
 
 deleteSuggestedSolutions ()
 
 getSuggestedSolution (int $subquestion_index=0)
 
 resolveInternalLink (string $internal_link)
 
 resolveSuggestedSolutionLinks ()
 
 getInternalLinkHref (string $target)
 
 syncWithOriginal ()
 
 getPoints ()
 
 setPoints (float $points)
 
 getSolutionMaxPass (int $active_id)
 
 isWriteable ()
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $preview_session)
 
 isPreviewSolutionCorrect (ilAssQuestionPreviewSession $preview_session)
 
 adjustReachedPointsByScoringOptions (float $points, int $active_id)
 Adjust the given reached points by checks for all special scoring options in the test container. More...
 
 buildHashedImageFilename (string $plain_image_filename, bool $unique=false)
 
 getQuestion ()
 
 getQuestionForHTMLOutput ()
 
 setQuestion (string $question="")
 
 getQuestionTypeID ()
 
 cleanupMediaObjectUsage ()
 
 getInstances ()
 
 getActiveUserData (int $active_id)
 Returns the user id and the test id for a given active id. More...
 
 hasSpecificFeedback ()
 
 getNrOfTries ()
 
 setNrOfTries (int $a_nr_of_tries)
 
 setExportImagePath (string $path)
 
 formatSAQuestion ($a_q)
 
 setPreventRteUsage (bool $prevent_rte_usage)
 
 getPreventRteUsage ()
 
 migrateContentForLearningModule (ilAssSelfAssessmentMigrator $migrator)
 
 setSelfAssessmentEditingMode (bool $selfassessmenteditingmode)
 
 getSelfAssessmentEditingMode ()
 
 setDefaultNrOfTries (int $defaultnroftries)
 
 getDefaultNrOfTries ()
 
 syncSkillAssignments (int $srcParentId, int $srcQuestionId, int $trgParentId, int $trgQuestionId)
 
 isAnswered (int $active_id, int $pass)
 
 getAdditionalContentEditingMode ()
 
 setAdditionalContentEditingMode (?string $additionalContentEditingMode)
 
 isAdditionalContentEditingModePageObject ()
 
 isValidAdditionalContentEditingMode (string $additionalContentEditingMode)
 
 getValidAdditionalContentEditingModes ()
 
 getHtmlUserSolutionPurifier ()
 
 getHtmlQuestionContentPurifier ()
 
 setLastChange (int $lastChange)
 
 getLastChange ()
 
 removeIntermediateSolution (int $active_id, int $pass)
 
 removeCurrentSolution (int $active_id, int $pass, bool $authorized=true)
 
 saveCurrentSolution (int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
 
 updateCurrentSolution (int $solutionId, $value1, $value2, bool $authorized=true)
 
 updateCurrentSolutionsAuthorization (int $activeId, int $pass, bool $authorized, bool $keepTime=false)
 
 setStep ($step)
 
 getStep ()
 
 toJSON ()
 
 intermediateSolutionExists (int $active_id, int $pass)
 
 authorizedSolutionExists (int $active_id, ?int $pass)
 
 authorizedOrIntermediateSolutionExists (int $active_id, int $pass)
 
 lookupForExistingSolutions (int $activeId, int $pass)
 Lookup if an authorized or intermediate solution exists. More...
 
 isAddableAnswerOptionValue (int $qIndex, string $answerOptionValue)
 
 addAnswerOptionValue (int $qIndex, string $answerOptionValue, float $points)
 
 removeAllExistingSolutions ()
 
 removeExistingSolutions (int $activeId, int $pass)
 
 resetUsersAnswer (int $activeId, int $pass)
 
 removeResultRecord (int $activeId, int $pass)
 
 fetchValuePairsFromIndexedValues (array $indexedValues)
 
 fetchIndexedValuesFromValuePairs (array $value_pairs)
 
 updateTimestamp ()
 
 getTestPresentationConfig ()
 
 hasWritableOriginalInQuestionPool ()
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
 getSolutionForTextOutput (int $active_id, int $pass)
 
 getCorrectSolutionForTextOutput (int $active_id, int $pass)
 
 getVariablesAsTextArray (int $active_id, int $pass)
 
 validateSolutionSubmit ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
 saveAdditionalQuestionDataToDb ()
 Saves a record to the question types additional data table. More...
 
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
 getSpecificFeedbackAllCorrectOptionLabel ()
 
 toJSON ()
 

Data Fields

const NUM_REQUIRED_ANSWERS = 4
 
const PARTIAL_SCORING_NUM_CORRECT_ANSWERS = 3
 
const ANSWER_TYPE_SINGLE_LINE = 'singleLine'
 
const ANSWER_TYPE_MULTI_LINE = 'multiLine'
 
const OPTION_LABEL_RIGHT_WRONG = 'right_wrong'
 
const OPTION_LABEL_PLUS_MINUS = 'plus_minus'
 
const OPTION_LABEL_APPLICABLE_OR_NOT = 'applicable_or_not'
 
const OPTION_LABEL_ADEQUATE_OR_NOT = 'adequate_or_not'
 
const OPTION_LABEL_CUSTOM = 'customlabel'
 
const DEFAULT_THUMB_SIZE = 150
 
const THUMB_PREFIX = 'thumb.'
 
- Data Fields inherited from assQuestion
const ADDITIONAL_CONTENT_EDITING_MODE_RTE = 'default'
 
const ADDITIONAL_CONTENT_EDITING_MODE_IPE = 'pageobject'
 
const TRIM_PATTERN = '/^[\p{C}\p{Z}]+|[\p{C}\p{Z}]+$/u'
 
ilAssQuestionFeedback $feedbackOBJ
 
bool $prevent_rte_usage = false
 
bool $selfassessmenteditingmode = false
 
int $defaultnroftries = 0
 
string $questionActionCmd = 'handleQuestionAction'
 
const KEY_VALUES_IMPLOSION_SEPARATOR = ':'
 

Protected Member Functions

 getSolutionSubmit ()
 
 calculateReachedPointsForSolution (?array $found_values, int $active_id=0)
 
 cloneQuestionTypeSpecificProperties (\assQuestion $target)
 
 getRTETextWithMediaObjects ()
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 solutionValuesToLog (AdditionalInformationGenerator $additional_info, array $solution_values)
 MUST convert the given solution values into an array or a string that can be stored in the log. More...
 
- Protected Member Functions inherited from assQuestion
 solutionValuesToLog (AdditionalInformationGenerator $additional_info, array $solution_values)
 MUST convert the given solution values into an array or a string that can be stored in the log. More...
 
 solutionValuesToText (array $solution_values)
 MUST convert the given solution values into text. More...
 
 getQuestionAction ()
 
 isNonEmptyItemListPostSubmission (string $post_submission_field_name)
 
 savePreviewData (ilAssQuestionPreviewSession $preview_session)
 
 deletePageOfQuestion (int $question_id)
 
 cloneQuestionTypeSpecificProperties (self $target)
 
 removeAllImageFiles (string $image_target_path)
 
 onDuplicate (int $original_parent_id, int $original_question_id, int $duplicate_parent_id, int $duplicate_question_id)
 
 afterSyncWithOriginal (int $original_question_id, int $clone_question_id, int $original_parent_id, int $clone_parent_id)
 
 onCopy (int $sourceParentId, int $sourceQuestionId, int $targetParentId, int $targetQuestionId)
 
 duplicateComments (int $parent_source_id, int $source_id, int $parent_target_id, int $target_id)
 
 deleteComments ()
 
 getNotesManager ()
 
 getNotesDataService ()
 
 getNotesRepo ()
 
 cloneSuggestedSolutions (int $source_question_id, int $target_question_id)
 
 duplicateSuggestedSolutionFiles (int $parent_id, int $question_id)
 Duplicates the files of a suggested solution if the question is duplicated. More...
 
 cloneSuggestedSolutionFiles (int $source_question_id, int $target_question_id)
 
 copySuggestedSolutions (int $target_question_id)
 
 ensureNonNegativePoints (float $points)
 
 purifyAndPrepareTextAreaOutput (string $content)
 
 getRTETextWithMediaObjects ()
 
 getSelfAssessmentFormatter ()
 
 lmMigrateQuestionTypeGenericContent (ilAssSelfAssessmentMigrator $migrator)
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 duplicateSkillAssignments (int $srcParentId, int $srcQuestionId, int $trgParentId, int $trgQuestionId)
 
 buildQuestionDataQuery ()
 
 getCurrentSolutionResultSet (int $active_id, int $pass, bool $authorized=true)
 
 removeSolutionRecordById (int $solutionId)
 
 getSolutionRecordById (int $solutionId)
 
 deleteDummySolutionRecord (int $activeId, int $passIndex)
 
 isDummySolutionRecord (array $solutionRecord)
 
 deleteSolutionRecordByValues (int $activeId, int $passIndex, bool $authorized, array $matchValues)
 
 duplicateIntermediateSolutionAuthorized (int $activeId, int $passIndex)
 
 forceExistingIntermediateSolution (int $activeId, int $passIndex, bool $considerDummyRecordCreation)
 
 lookupMaxStep (int $active_id, int $pass)
 
 buildTestPresentationConfig ()
 
 getSuggestedSolutionsRepo ()
 
 loadSuggestedSolutions ()
 
 answerToLog (AdditionalInformationGenerator $additional_info, int $active_id, int $pass)
 

Private Member Functions

 loadAnswerData (int $question_id)
 
 getFalseOptionLabel (string $option_label)
 
 handleFileUpload (ilAssKprimChoiceAnswer $answer, $fileData)
 
 getNumAllowedFailures ()
 

Private Attributes

bool $shuffle_answers_enabled = true
 
string $answerType = self::ANSWER_TYPE_SINGLE_LINE
 
int $thumbSize = self::DEFAULT_THUMB_SIZE
 
bool $scorePartialSolutionEnabled = true
 
string $option_label = self::OPTION_LABEL_RIGHT_WRONG
 
string $customTrueOptionLabel = ''
 
string $customFalseOptionLabel = ''
 
int $specific_feedback_setting = ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_ALL
 
 $answers = []
 

Additional Inherited Members

- Static Public Member Functions inherited from assQuestion
static setForcePassResultUpdateEnabled (bool $force_pass_results_update_enabled)
 
static isForcePassResultUpdateEnabled ()
 
static _getSuggestedSolutionOutput (int $question_id)
 
static _getReachedPoints (int $active_id, int $question_id, int $pass)
 
static isFileAvailable (string $file)
 
static saveOriginalId (int $questionId, int $originalId)
 
static resetOriginalId (int $questionId)
 
static instantiateQuestion (int $question_id)
 
static _getSolutionMaxPass (int $question_id, int $active_id)
 Returns the maximum pass a users question solution. More...
 
static getFeedbackClassNameByQuestionType (string $questionType)
 
static _questionExistsInTest (int $question_id, int $test_id)
 
static lookupParentObjId (int $question_id)
 
static implodeKeyValues (array $keyValues)
 
static explodeKeyValues (string $keyValues)
 
static convertISO8601FormatH_i_s_ExtendedToSeconds (string $time)
 
static extendedTrim (string $value)
 Trim non-printable characters from the beginning and end of a string. More...
 
- Static Protected Member Functions inherited from assQuestion
static getNumExistingSolutionRecords (int $activeId, int $pass, int $questionId)
 
- Protected Attributes inherited from assQuestion
const HAS_SPECIFIC_FEEDBACK = true
 
GeneralQuestionPropertiesRepository $questionrepository
 
RequestDataCollector $questionpool_request
 
QuestionFiles $question_files
 
ilAssQuestionProcessLocker $processLocker
 
ilTestQuestionConfig $testQuestionConfig
 
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo
 
ILIAS $ilias
 
ilGlobalPageTemplate $tpl
 
ilLanguage $lng
 
ilDBInterface $db
 
ilObjUser $current_user
 
SkillUsageService $skillUsageService
 
HTTPServices $http
 
Refinery $refinery
 
Transformation $shuffler
 
LoggingServices $log
 
Container $dic
 
ilAssQuestionLifecycle $lifecycle
 
ilAssQuestionPage $page
 
TestResultRepository $test_result_repository
 
int $id
 
string $title
 
string $comment
 
int $owner
 
string $author
 
int $thumb_size
 
string $question
 
float $points = 0.0
 
bool $shuffle = true
 
int $test_id
 
int $obj_id = 0
 
int $original_id = null
 
int $lastChange = null
 
string $external_id = null
 
int $step = null
 
array $suggested_solutions
 
- Static Protected Attributes inherited from assQuestion
static $force_pass_results_update_enabled = false
 
static $imageSourceFixReplaceMap
 

Detailed Description

Definition at line 32 of file class.assKprimChoice.php.

Constructor & Destructor Documentation

◆ __construct()

assKprimChoice::__construct (   $title = '',
  $comment = '',
  $author = '',
  $owner = -1,
  $question = '' 
)

Definition at line 63 of file class.assKprimChoice.php.

64 {
66
67 for ($i = count($this->answers); $i < self::NUM_REQUIRED_ANSWERS; $i++) {
68 $answer = new ilAssKprimChoiceAnswer();
69 $answer->setPosition($i);
70 $this->answers[$answer->getPosition()] = $answer;
71 }
72 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References assQuestion\$author, assQuestion\$comment, assQuestion\$owner, assQuestion\$question, assQuestion\$title, ILIAS\GlobalScreen\Provider\__construct(), and NUM_REQUIRED_ANSWERS.

+ Here is the call graph for this function:

Member Function Documentation

◆ addAnswer()

assKprimChoice::addAnswer ( ilAssKprimChoiceAnswer  $answer)

Definition at line 202 of file class.assKprimChoice.php.

202 : void
203 {
204 $answer->setAnswertext(
205 $this->getHtmlQuestionContentPurifier()->purify($answer->getAnswertext())
206 );
207 $this->answers[] = $answer;
208 }

References ilAssKprimChoiceAnswer\getAnswertext(), assQuestion\getHtmlQuestionContentPurifier(), and ilAssKprimChoiceAnswer\setAnswertext().

+ Here is the call graph for this function:

◆ calculateReachedPoints()

assKprimChoice::calculateReachedPoints ( int  $active_id,
?int  $pass = null,
bool  $authorized_solution = true 
)

Reimplemented from assQuestion.

Definition at line 404 of file class.assKprimChoice.php.

408 : float {
409 $found_values = [];
410 if (is_null($pass)) {
411 $pass = $this->getSolutionMaxPass($active_id);
412 }
413
414 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized_solution);
415
416 while ($data = $this->db->fetchAssoc($result)) {
417 $found_values[(int) $data['value1']] = (int) $data['value2'];
418 }
419
420 $points = $this->calculateReachedPointsForSolution($found_values, $active_id);
421
422 return $points;
423 }
calculateReachedPointsForSolution(?array $found_values, int $active_id=0)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getSolutionMaxPass(int $active_id)

◆ calculateReachedPointsForSolution()

assKprimChoice::calculateReachedPointsForSolution ( ?array  $found_values,
int  $active_id = 0 
)
protected

Definition at line 640 of file class.assKprimChoice.php.

640 : float
641 {
642 $numCorrect = 0;
643 if ($found_values === null) {
644 $found_values = [];
645 }
646 foreach ($this->getAnswers() as $answer) {
647 if (!isset($found_values[$answer->getPosition()])) {
648 continue;
649 }
650
651 if ($found_values[$answer->getPosition()] == $answer->getCorrectness()) {
652 $numCorrect++;
653 }
654 }
655
656 if ($numCorrect >= self::NUM_REQUIRED_ANSWERS) {
657 $points = $this->getPoints();
658 } elseif ($this->isScorePartialSolutionEnabled() && $numCorrect >= self::PARTIAL_SCORING_NUM_CORRECT_ANSWERS) {
659 $points = $this->getPoints() / 2;
660 } else {
661 $points = 0;
662 }
663
664 if ($active_id) {
665 if (count($found_values) == 0) {
666 $points = 0;
667 }
668 }
669 return (float) $points;
670 }

◆ cloneQuestionTypeSpecificProperties()

assKprimChoice::cloneQuestionTypeSpecificProperties ( \assQuestion  $target)
protected

Definition at line 672 of file class.assKprimChoice.php.

674 : \assQuestion {
675 $this->cloneImages(
676 $this->getId(),
677 $this->getObjId(),
678 $target->getId(),
679 $target->getObjId(),
680 $this->getAnswers()
681 );
682 return $target;
683 }

◆ getAdditionalTableName()

assKprimChoice::getAdditionalTableName ( )

Reimplemented from assQuestion.

Definition at line 79 of file class.assKprimChoice.php.

79 : string
80 {
81 return "qpl_qst_kprim";
82 }

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getAnswer()

assKprimChoice::getAnswer (   $position)

Definition at line 191 of file class.assKprimChoice.php.

192 {
193 foreach ($this->getAnswers() as $answer) {
194 if ($answer->getPosition() == $position) {
195 return $answer;
196 }
197 }
198
199 return null;
200 }

References getAnswers().

+ Here is the call graph for this function:

◆ getAnswers()

assKprimChoice::getAnswers ( )
Returns
array<ilAssKprimChoiceAnswer>

Definition at line 186 of file class.assKprimChoice.php.

186 : array
187 {
188 return $this->answers;
189 }

References $answers.

Referenced by getAnswer(), isComplete(), and saveAnswerSpecificDataToDb().

+ Here is the caller graph for this function:

◆ getAnswerTableName()

assKprimChoice::getAnswerTableName ( )

Reimplemented from assQuestion.

Definition at line 84 of file class.assKprimChoice.php.

84 : string
85 {
86 return "qpl_a_kprim";
87 }

Referenced by saveAnswerSpecificDataToDb().

+ Here is the caller graph for this function:

◆ getAnswerType()

assKprimChoice::getAnswerType ( )

Definition at line 104 of file class.assKprimChoice.php.

104 : string
105 {
106 return $this->answerType;
107 }

References $answerType.

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getAnswerTypeSelectOptions()

assKprimChoice::getAnswerTypeSelectOptions ( ilLanguage  $lng)
Parameters
ilLanguage$lng
Returns
array

Definition at line 445 of file class.assKprimChoice.php.

445 : array
446 {
447 return [
448 self::ANSWER_TYPE_SINGLE_LINE => $lng->txt('answers_singleline'),
449 self::ANSWER_TYPE_MULTI_LINE => $lng->txt('answers_multiline')
450 ];
451 }
ilLanguage $lng
txt(string $a_topic, string $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...

References $lng.

◆ getCorrectSolutionForTextOutput()

assKprimChoice::getCorrectSolutionForTextOutput ( int  $active_id,
int  $pass 
)

Reimplemented from assQuestion.

Definition at line 913 of file class.assKprimChoice.php.

913 : array
914 {
915 $true_option_label = $this->getTrueOptionLabelTranslation($this->lng, $this->getOptionLabel());
916 $false_option_label = $this->getFalseOptionLabelTranslation($this->lng, $this->getOptionLabel());
917 return array_map(
918 fn(ilAssKprimChoiceAnswer $v): string => $v->getAnswertext()
919 . ' (' . $v->getCorrectness() ? $true_option_label : $false_option_label . ')',
920 $this->getAnswers()
921 );
922 }
getFalseOptionLabelTranslation(ilLanguage $lng, string $option_label)
getTrueOptionLabelTranslation(ilLanguage $lng, string $option_label)

References ilAssKprimChoiceAnswer\getAnswertext(), ilAssKprimChoiceAnswer\getCorrectness(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getCustomFalseOptionLabel()

assKprimChoice::getCustomFalseOptionLabel ( )

Definition at line 154 of file class.assKprimChoice.php.

155 {
157 }

References $customFalseOptionLabel.

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getCustomTrueOptionLabel()

assKprimChoice::getCustomTrueOptionLabel ( )

Definition at line 144 of file class.assKprimChoice.php.

145 {
147 }

References $customTrueOptionLabel.

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getFalseOptionLabel()

assKprimChoice::getFalseOptionLabel ( string  $option_label)
private

Definition at line 535 of file class.assKprimChoice.php.

535 : string
536 {
537 switch ($option_label) {
539 return 'option_label_wrong';
540
542 return 'option_label_minus';
543
545 return 'option_label_not_applicable';
546
548 return 'option_label_not_adequate';
549
550 default:
551 throw new \ErrorException('Invalide Option Label');
552 }
553 }
const OPTION_LABEL_APPLICABLE_OR_NOT

◆ getFalseOptionLabelTranslation()

assKprimChoice::getFalseOptionLabelTranslation ( ilLanguage  $lng,
string  $option_label 
)

Definition at line 524 of file class.assKprimChoice.php.

524 : string
525 {
526 if ($option_label === self::OPTION_LABEL_CUSTOM) {
527 return $this->getCustomFalseOptionLabel();
528 }
529
530 return $lng->txt(
532 );
533 }
getFalseOptionLabel(string $option_label)

References $lng.

◆ getInstructionTextTranslation()

assKprimChoice::getInstructionTextTranslation ( ilLanguage  $lng,
  $option_label 
)

Definition at line 555 of file class.assKprimChoice.php.

555 : string
556 {
557 return sprintf(
558 $lng->txt('kprim_instruction_text'),
559 $this->getTrueOptionLabelTranslation($lng, $option_label),
560 $this->getFalseOptionLabelTranslation($lng, $option_label)
561 );
562 }

References $lng.

◆ getLangVarForOptionLabel()

assKprimChoice::getLangVarForOptionLabel ( string  $option_label)

Definition at line 476 of file class.assKprimChoice.php.

476 : string
477 {
478 return match ($option_label) {
479 self::OPTION_LABEL_RIGHT_WRONG => 'option_label_right_wrong',
480 self::OPTION_LABEL_PLUS_MINUS => 'option_label_plus_minus',
481 self::OPTION_LABEL_APPLICABLE_OR_NOT => 'option_label_applicable_or_not',
482 self::OPTION_LABEL_ADEQUATE_OR_NOT => 'option_label_adequate_or_not',
483 self::OPTION_LABEL_CUSTOM => 'option_label_custom'
484 };
485 }

◆ getNumAllowedFailures()

assKprimChoice::getNumAllowedFailures ( )
private

Definition at line 767 of file class.assKprimChoice.php.

767 : int
768 {
769 if ($this->isScorePartialSolutionEnabled()) {
770 return self::NUM_REQUIRED_ANSWERS - self::PARTIAL_SCORING_NUM_CORRECT_ANSWERS;
771 }
772
773 return 0;
774 }
const PARTIAL_SCORING_NUM_CORRECT_ANSWERS

◆ getOptionLabel()

assKprimChoice::getOptionLabel ( )

Definition at line 134 of file class.assKprimChoice.php.

134 : string
135 {
136 return $this->option_label;
137 }

References $option_label.

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getQuestionType()

assKprimChoice::getQuestionType ( )

Reimplemented from assQuestion.

Definition at line 74 of file class.assKprimChoice.php.

74 : string
75 {
76 return 'assKprimChoice';
77 }

◆ getRTETextWithMediaObjects()

assKprimChoice::getRTETextWithMediaObjects ( )
protected

Reimplemented from assQuestion.

Definition at line 685 of file class.assKprimChoice.php.

685 : string
686 {
687 $combinedText = parent::getRTETextWithMediaObjects();
688
689 foreach ($this->getAnswers() as $answer) {
690 $combinedText .= $answer->getAnswertext();
691 }
692
693 return $combinedText;
694 }

◆ getSolutionSubmit()

assKprimChoice::getSolutionSubmit ( )
protected

Definition at line 619 of file class.assKprimChoice.php.

619 : array
620 {
621 $solutionSubmit = [];
622 $post = $this->dic->http()->wrapper()->post();
623
624 foreach ($this->getAnswers() as $index => $a) {
625 if ($post->has("kprim_choice_result_$index")) {
626 $value = $post->retrieve(
627 "kprim_choice_result_$index",
628 $this->dic->refinery()->kindlyTo()->string()
629 );
630 if (is_numeric($value)) {
631 $solutionSubmit[] = $value;
632 }
633 } else {
634 $solutionSubmit[] = null;
635 }
636 }
637 return $solutionSubmit;
638 }
$post
Definition: ltitoken.php:46
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, and $post.

◆ getSpecificFeedbackAllCorrectOptionLabel()

assKprimChoice::getSpecificFeedbackAllCorrectOptionLabel ( )

Implements ilAssSpecificFeedbackOptionLabelProvider.

Definition at line 776 of file class.assKprimChoice.php.

776 : string
777 {
778 return 'feedback_correct_kprim';
779 }

◆ getSpecificFeedbackSetting()

assKprimChoice::getSpecificFeedbackSetting ( )

Definition at line 164 of file class.assKprimChoice.php.

164 : int
165 {
167 }

References $specific_feedback_setting.

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getThumbSize()

assKprimChoice::getThumbSize ( )

Reimplemented from assQuestion.

Definition at line 114 of file class.assKprimChoice.php.

114 : int
115 {
116 return $this->thumbSize;
117 }

References $thumbSize.

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getTrueOptionLabel()

assKprimChoice::getTrueOptionLabel ( string  $option_label)

Definition at line 504 of file class.assKprimChoice.php.

504 : string
505 {
506 switch ($option_label) {
508 return 'option_label_right';
509
511 return 'option_label_plus';
512
514 return 'option_label_applicable';
515
517 return 'option_label_adequate';
518
519 default:
520 throw new \ErrorException('Invalide Option Label');
521 }
522 }

◆ getTrueOptionLabelTranslation()

assKprimChoice::getTrueOptionLabelTranslation ( ilLanguage  $lng,
string  $option_label 
)

Definition at line 493 of file class.assKprimChoice.php.

493 : string
494 {
495 if ($option_label === self::OPTION_LABEL_CUSTOM) {
496 return $this->getCustomTrueOptionLabel();
497 }
498
499 return $lng->txt(
501 );
502 }
getTrueOptionLabel(string $option_label)

References $lng.

◆ getValidAnswerTypes()

assKprimChoice::getValidAnswerTypes ( )

Definition at line 425 of file class.assKprimChoice.php.

425 : array
426 {
428 }

◆ getValidOptionLabels()

assKprimChoice::getValidOptionLabels ( )

◆ getValidOptionLabelsTranslated()

assKprimChoice::getValidOptionLabelsTranslated ( ilLanguage  $lng)

Definition at line 464 of file class.assKprimChoice.php.

464 : array
465 {
466 return array_reduce(
467 $this->getValidOptionLabels(),
468 function (array $c, string $option_label) use ($lng): array {
469 $c[$option_label] = $lng->txt($this->getLangVarForOptionLabel($option_label));
470 return $c;
471 },
472 []
473 );
474 }
getLangVarForOptionLabel(string $option_label)
$c
Definition: deliver.php:25

References $c, and $lng.

◆ handleFileUpload()

assKprimChoice::handleFileUpload ( ilAssKprimChoiceAnswer  $answer,
  $fileData 
)
private

Definition at line 582 of file class.assKprimChoice.php.

582 : int
583 {
584 $imagePath = $this->getImagePath();
585
586 if (!file_exists($imagePath)) {
587 ilFileUtils::makeDirParents($imagePath);
588 }
589
590 $filename = $this->buildHashedImageFilename($fileData['name'], true);
591
592 $answer->setImageFsDir($imagePath);
593 $answer->setImageFile($filename);
594
595 if (!ilFileUtils::moveUploadedFile($fileData['tmp_name'], $filename, $answer->getImageFsPath())) {
596 return 2;
597 }
598
599 $this->generateThumbForFile($filename, $this->getImagePath(), $this->getThumbSize());
600
601 return 0;
602 }
$filename
Definition: buildRTE.php:78
buildHashedImageFilename(string $plain_image_filename, bool $unique=false)
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file

References $filename, ilAssKprimChoiceAnswer\getImageFsPath(), ilFileUtils\makeDirParents(), ilFileUtils\moveUploadedFile(), ilAssKprimChoiceAnswer\setImageFile(), and ilAssKprimChoiceAnswer\setImageFsDir().

+ Here is the call graph for this function:

◆ handleFileUploads()

assKprimChoice::handleFileUploads (   $answers,
  $files 
)

Definition at line 569 of file class.assKprimChoice.php.

569 : void
570 {
571 foreach ($answers as $answer) {
572 /* @var ilAssKprimChoiceAnswer $answer */
573
574 if (!isset($files[$answer->getPosition()])) {
575 continue;
576 }
577
578 $this->handleFileUpload($answer, $files[$answer->getPosition()]);
579 }
580 }
handleFileUpload(ilAssKprimChoiceAnswer $answer, $fileData)

◆ isComplete()

assKprimChoice::isComplete ( )

Reimplemented from assQuestion.

Definition at line 350 of file class.assKprimChoice.php.

350 : bool
351 {
352 foreach ([$this->title, $this->author, $this->question] as $text) {
353 if (!strlen($text)) {
354 return false;
355 }
356 }
357
358 if (!isset($this->points)) {
359 return false;
360 }
361
362 foreach ($this->getAnswers() as $answer) {
363 /* @var ilAssKprimChoiceAnswer $answer */
364
365 if (is_null($answer->getCorrectness())) {
366 return false;
367 }
368
369 if (
370 (!is_string($answer->getAnswertext()) || $answer->getAnswertext() === '') &&
371 (!is_string($answer->getImageFile()) || $answer->getImageFile() === '')
372 ) {
373 return false;
374 }
375 }
376
377 return true;
378 }

References getAnswers().

+ Here is the call graph for this function:

◆ isCustomOptionLabel()

assKprimChoice::isCustomOptionLabel (   $labelValue)

Definition at line 564 of file class.assKprimChoice.php.

564 : bool
565 {
566 return $labelValue == self::OPTION_LABEL_CUSTOM;
567 }

◆ isScorePartialSolutionEnabled()

assKprimChoice::isScorePartialSolutionEnabled ( )

Definition at line 124 of file class.assKprimChoice.php.

124 : bool
125 {
127 }

References $scorePartialSolutionEnabled.

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ isShuffleAnswersEnabled()

assKprimChoice::isShuffleAnswersEnabled ( )

Definition at line 94 of file class.assKprimChoice.php.

94 : bool
95 {
97 }

References $shuffle_answers_enabled.

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ isSingleLineAnswerType()

assKprimChoice::isSingleLineAnswerType (   $answerType)

Definition at line 436 of file class.assKprimChoice.php.

436 : bool
437 {
439 }

References ANSWER_TYPE_SINGLE_LINE.

◆ isValidAnswerType()

assKprimChoice::isValidAnswerType (   $answerType)

Definition at line 430 of file class.assKprimChoice.php.

430 : bool
431 {
432 $validTypes = $this->getValidAnswerTypes();
433 return in_array($answerType, $validTypes);
434 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ isValidOptionLabel()

assKprimChoice::isValidOptionLabel ( ?string  $option_label)

Definition at line 487 of file class.assKprimChoice.php.

487 : bool
488 {
489 $valid_labels = $this->getValidOptionLabels();
490 return in_array($option_label, $valid_labels);
491 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ lmMigrateQuestionTypeSpecificContent()

assKprimChoice::lmMigrateQuestionTypeSpecificContent ( ilAssSelfAssessmentMigrator  $migrator)
protected
Parameters
ilAssSelfAssessmentMigrator$migrator

Reimplemented from assQuestion.

Definition at line 699 of file class.assKprimChoice.php.

699 : void
700 {
701 foreach ($this->getAnswers() as $answer) {
702 /* @var ilAssKprimChoiceAnswer $answer */
703 $answer->setAnswertext($migrator->migrateToLmContent($answer->getAnswertext()));
704 }
705 }

References ilAssSelfAssessmentMigrator\migrateToLmContent().

+ Here is the call graph for this function:

◆ loadAnswerData()

assKprimChoice::loadAnswerData ( int  $question_id)
private

Definition at line 277 of file class.assKprimChoice.php.

277 : void
278 {
279 $res = $this->db->queryF(
280 "SELECT * FROM {$this->getAnswerTableName()} WHERE question_fi = %s ORDER BY position ASC",
281 ['integer'],
282 [$question_id]
283 );
284
285 while ($data = $this->db->fetchAssoc($res)) {
286 $answer = new ilAssKprimChoiceAnswer();
287
288 $answer->setPosition($data['position']);
289
290 $answer->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($data['answertext'] ?? '', 1));
291
292 $answer->setImageFile($data['imagefile']);
293 $answer->setThumbPrefix($this->getThumbPrefix());
294 $answer->setImageFsDir($this->getImagePath());
295 $answer->setImageWebDir($this->getImagePathWeb());
296
297 $answer->setCorrectness($data['correctness']);
298
299 $this->answers[$answer->getPosition()] = $answer;
300 }
301 }
getImagePathWeb()
Returns the web image path for web accessable images of a question.
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
$res
Definition: ltiservices.php:69

References $data, $res, ilRTE\_replaceMediaObjectImageSrc(), assQuestion\getImagePath(), and assQuestion\getImagePathWeb().

Referenced by loadFromDb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadFromDb()

assKprimChoice::loadFromDb (   $questionId)

Definition at line 210 of file class.assKprimChoice.php.

210 : void
211 {
212 $res = $this->db->queryF($this->buildQuestionDataQuery(), ['integer'], [$questionId]);
213
214 while ($data = $this->db->fetchAssoc($res)) {
215 $this->setId($questionId);
216
217 $this->setOriginalId($data['original_id']);
218
219 $this->setObjId($data['obj_fi']);
220
221 $this->setTitle($data['title'] ?? '');
222 $this->setNrOfTries($data['nr_of_tries']);
223 $this->setComment($data['description'] ?? '');
224 $this->setAuthor($data['author']);
225 $this->setPoints($data['points']);
226 $this->setOwner($data['owner']);
227 $this->setLastChange($data['tstamp']);
228 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data['question_text'] ?? '', 1));
229
230 $this->setShuffleAnswersEnabled((bool) $data['shuffle_answers']);
231
232 if ($this->isValidAnswerType($data['answer_type'])) {
233 $this->setAnswerType($data['answer_type']);
234 }
235
236 if (is_numeric($data['thumb_size'])) {
237 $this->setThumbSize((int) $data['thumb_size']);
238 }
239
240 if ($this->isValidOptionLabel($data['opt_label'])) {
241 $this->setOptionLabel($data['opt_label']);
242 }
243
244 if ($data['custom_true'] !== null) {
245 $this->setCustomTrueOptionLabel($data['custom_true']);
246 }
247
248 if ($data['custom_false'] !== null) {
249 $this->setCustomFalseOptionLabel($data['custom_false']);
250 }
251
252 if ($data['score_partsol'] !== null) {
253 $this->setScorePartialSolutionEnabled((bool) $data['score_partsol']);
254 }
255
256 if (isset($data['feedback_setting'])) {
257 $this->setSpecificFeedbackSetting((int) $data['feedback_setting']);
258 }
259
260 try {
264 }
265
266 try {
267 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
269 }
270 }
271
272 $this->loadAnswerData($questionId);
273
274 parent::loadFromDb($questionId);
275 }
setCustomTrueOptionLabel($customTrueOptionLabel)
setSpecificFeedbackSetting(int $specific_feedback_setting)
setShuffleAnswersEnabled(bool $shuffle_answers_enabled)
setCustomFalseOptionLabel($customFalseOptionLabel)
setOptionLabel(string $option_label)
setAnswerType($answerType)
loadAnswerData(int $question_id)
isValidAnswerType($answerType)
isValidOptionLabel(?string $option_label)
setScorePartialSolutionEnabled($scorePartialSolutionEnabled)
setThumbSize(int $thumbSize)
setOriginalId(?int $original_id)
setId(int $id=-1)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setQuestion(string $question="")
setAuthor(string $author="")
setComment(string $comment="")
setObjId(int $obj_id=0)
setLastChange(int $lastChange)
setOwner(int $owner=-1)
setNrOfTries(int $a_nr_of_tries)
setLifecycle(ilAssQuestionLifecycle $lifecycle)
setTitle(string $title="")
setPoints(float $points)

References $data, Vendor\Package\$e, $res, ilRTE\_replaceMediaObjectImageSrc(), assQuestion\buildQuestionDataQuery(), ilAssQuestionLifecycle\getDraftInstance(), ilAssQuestionLifecycle\getInstance(), isValidAnswerType(), isValidOptionLabel(), loadAnswerData(), assQuestion\setAdditionalContentEditingMode(), setAnswerType(), assQuestion\setAuthor(), assQuestion\setComment(), setCustomFalseOptionLabel(), setCustomTrueOptionLabel(), assQuestion\setId(), assQuestion\setLastChange(), assQuestion\setLifecycle(), assQuestion\setNrOfTries(), assQuestion\setObjId(), setOptionLabel(), assQuestion\setOriginalId(), assQuestion\setOwner(), assQuestion\setPoints(), assQuestion\setQuestion(), setScorePartialSolutionEnabled(), setShuffleAnswersEnabled(), setSpecificFeedbackSetting(), setThumbSize(), and assQuestion\setTitle().

+ Here is the call graph for this function:

◆ moveAnswerDown()

assKprimChoice::moveAnswerDown (   $position)

Definition at line 781 of file class.assKprimChoice.php.

781 : bool
782 {
783 if ($position < 0 || $position >= (self::NUM_REQUIRED_ANSWERS - 1)) {
784 return false;
785 }
786
787 for ($i = 0, $max = count($this->answers); $i < $max; $i++) {
788 if ($i == $position) {
789 $movingAnswer = $this->answers[$i];
790 $targetAnswer = $this->answers[ $i + 1 ];
791
792 $movingAnswer->setPosition($position + 1);
793 $targetAnswer->setPosition($position);
794
795 $this->answers[ $i + 1 ] = $movingAnswer;
796 $this->answers[$i] = $targetAnswer;
797 }
798 }
799 return true;
800 }

◆ moveAnswerUp()

assKprimChoice::moveAnswerUp (   $position)

Definition at line 802 of file class.assKprimChoice.php.

802 : bool
803 {
804 if ($position <= 0 || $position > (self::NUM_REQUIRED_ANSWERS - 1)) {
805 return false;
806 }
807
808 for ($i = 0, $max = count($this->answers); $i < $max; $i++) {
809 if ($i == $position) {
810 $movingAnswer = $this->answers[$i];
811 $targetAnswer = $this->answers[ $i - 1 ];
812
813 $movingAnswer->setPosition($position - 1);
814 $targetAnswer->setPosition($position);
815
816 $this->answers[ $i - 1 ] = $movingAnswer;
817 $this->answers[$i] = $targetAnswer;
818 }
819 }
820
821 return true;
822 }

◆ removeAnswerImage()

assKprimChoice::removeAnswerImage (   $position)

Definition at line 604 of file class.assKprimChoice.php.

604 : void
605 {
606 $answer = $this->getAnswer($position);
607
608 if (file_exists($answer->getImageFsPath())) {
609 ilFileUtils::delDir($answer->getImageFsPath());
610 }
611
612 if (file_exists($answer->getThumbFsPath())) {
613 ilFileUtils::delDir($answer->getThumbFsPath());
614 }
615
616 $answer->setImageFile(null);
617 }
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

References ilFileUtils\delDir().

+ Here is the call graph for this function:

◆ saveAdditionalQuestionDataToDb()

assKprimChoice::saveAdditionalQuestionDataToDb ( )

Saves a record to the question types additional data table.

Returns
mixed

Implements ilObjQuestionScoringAdjustable.

Definition at line 312 of file class.assKprimChoice.php.

313 {
314 $this->db->replace(
315 $this->getAdditionalTableName(),
316 [
317 'question_fi' => ['integer', $this->getId()]
318 ],
319 [
320 'shuffle_answers' => ['integer', (int) $this->isShuffleAnswersEnabled()],
321 'answer_type' => ['text', $this->getAnswerType()],
322 'thumb_size' => ['integer', $this->getThumbSize()],
323 'opt_label' => ['text', $this->getOptionLabel()],
324 'custom_true' => ['text', $this->getCustomTrueOptionLabel()],
325 'custom_false' => ['text', $this->getCustomFalseOptionLabel()],
326 'score_partsol' => ['integer', (int) $this->isScorePartialSolutionEnabled()],
327 'feedback_setting' => ['integer', $this->getSpecificFeedbackSetting()]
328 ]
329 );
330 }

References getAdditionalTableName(), getAnswerType(), getCustomFalseOptionLabel(), getCustomTrueOptionLabel(), assQuestion\getId(), getOptionLabel(), getSpecificFeedbackSetting(), getThumbSize(), isScorePartialSolutionEnabled(), and isShuffleAnswersEnabled().

Referenced by saveToDb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAnswerSpecificDataToDb()

assKprimChoice::saveAnswerSpecificDataToDb ( )

Saves the answer specific records into a question types answer table.

Returns
mixed

Implements ilObjAnswerScoringAdjustable.

Definition at line 332 of file class.assKprimChoice.php.

333 {
334 foreach ($this->getAnswers() as $answer) {
335 $this->db->replace(
336 $this->getAnswerTableName(),
337 [
338 'question_fi' => ['integer', $this->getId()],
339 'position' => ['integer', (int) $answer->getPosition()]
340 ],
341 [
342 'answertext' => ['text', $answer->getAnswertext()],
343 'imagefile' => ['text', $answer->getImageFile()],
344 'correctness' => ['integer', (int) $answer->getCorrectness()]
345 ]
346 );
347 }
348 }

References getAnswers(), getAnswerTableName(), and assQuestion\getId().

Referenced by saveToDb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveToDb()

assKprimChoice::saveToDb ( ?int  $original_id = null)

Reimplemented from assQuestion.

Definition at line 303 of file class.assKprimChoice.php.

303 : void
304 {
308
309 parent::saveToDb();
310 }
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
saveQuestionDataToDb(?int $original_id=null)

References assQuestion\$original_id, saveAdditionalQuestionDataToDb(), saveAnswerSpecificDataToDb(), and assQuestion\saveQuestionDataToDb().

+ Here is the call graph for this function:

◆ saveWorkingData()

assKprimChoice::saveWorkingData ( int  $active_id,
?int  $pass = null,
bool  $authorized = true 
)

Reimplemented from assQuestion.

Definition at line 380 of file class.assKprimChoice.php.

384 : bool {
385 if ($pass === null) {
386 $pass = ilObjTest::_getPass($active_id);
387 }
388
389 $answer = $this->getSolutionSubmit();
390 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
391 function () use ($answer, $active_id, $pass, $authorized) {
392 $this->removeCurrentSolution($active_id, $pass, $authorized);
393 foreach ($answer as $index => $value) {
394 if ($value !== null) {
395 $this->saveCurrentSolution($active_id, $pass, (int) $index, (int) $value, $authorized);
396 }
397 }
398 }
399 );
400
401 return true;
402 }
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.

References ilObjTest\_getPass().

+ Here is the call graph for this function:

◆ setAnswers()

assKprimChoice::setAnswers (   $answers)

Definition at line 169 of file class.assKprimChoice.php.

169 : void
170 {
171 if (is_null($answers)) {
172 return;
173 }
174 $clean_answer_text = function (ilAssKprimChoiceAnswer $answer) {
175 $answer->setAnswertext(
176 $this->getHtmlQuestionContentPurifier()->purify($answer->getAnswertext())
177 );
178 return $answer;
179 };
180 $this->answers = array_map($clean_answer_text, $answers);
181 }

References $answers, and assQuestion\getHtmlQuestionContentPurifier().

+ Here is the call graph for this function:

◆ setAnswerType()

assKprimChoice::setAnswerType (   $answerType)

Definition at line 99 of file class.assKprimChoice.php.

99 : void
100 {
101 $this->answerType = $answerType;
102 }

References $answerType.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setCustomFalseOptionLabel()

assKprimChoice::setCustomFalseOptionLabel (   $customFalseOptionLabel)

Definition at line 149 of file class.assKprimChoice.php.

149 : void
150 {
151 $this->customFalseOptionLabel = $customFalseOptionLabel;
152 }

References $customFalseOptionLabel.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setCustomTrueOptionLabel()

assKprimChoice::setCustomTrueOptionLabel (   $customTrueOptionLabel)

Definition at line 139 of file class.assKprimChoice.php.

139 : void
140 {
141 $this->customTrueOptionLabel = $customTrueOptionLabel;
142 }

References $customTrueOptionLabel.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setOptionLabel()

assKprimChoice::setOptionLabel ( string  $option_label)

Definition at line 129 of file class.assKprimChoice.php.

129 : void
130 {
131 $this->option_label = $option_label;
132 }

References $option_label.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setScorePartialSolutionEnabled()

assKprimChoice::setScorePartialSolutionEnabled (   $scorePartialSolutionEnabled)

Definition at line 119 of file class.assKprimChoice.php.

119 : void
120 {
121 $this->scorePartialSolutionEnabled = $scorePartialSolutionEnabled;
122 }

References $scorePartialSolutionEnabled.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setShuffleAnswersEnabled()

assKprimChoice::setShuffleAnswersEnabled ( bool  $shuffle_answers_enabled)

Definition at line 89 of file class.assKprimChoice.php.

89 : void
90 {
91 $this->shuffle_answers_enabled = $shuffle_answers_enabled;
92 }

References $shuffle_answers_enabled.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setSpecificFeedbackSetting()

assKprimChoice::setSpecificFeedbackSetting ( int  $specific_feedback_setting)

Definition at line 159 of file class.assKprimChoice.php.

159 : void
160 {
161 $this->specific_feedback_setting = $specific_feedback_setting;
162 }

References $specific_feedback_setting.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setThumbSize()

assKprimChoice::setThumbSize ( int  $thumbSize)

Reimplemented from assQuestion.

Definition at line 109 of file class.assKprimChoice.php.

109 : void
110 {
111 $this->thumbSize = $thumbSize;
112 }

References $thumbSize.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ solutionValuesToLog()

assKprimChoice::solutionValuesToLog ( AdditionalInformationGenerator  $additional_info,
array  $solution_values 
)
protected

MUST convert the given solution values into an array or a string that can be stored in the log.

Language variables must be generated through the corresponding functions in the AdditionalInformationGenerator. If an array is returned it will be rendered into a line per array entry in the format "key: value". If the key exists as a language variable, it will be translated.

Reimplemented from assQuestion.

Definition at line 861 of file class.assKprimChoice.php.

864 : array {
865 $parsed_solution = [];
866 $true_option_label = $this->getOptionLabel() === self::OPTION_LABEL_CUSTOM
867 ? $this->getCustomTrueOptionLabel()
868 : $this->getTrueOptionLabel($this->getOptionLabel());
869 $false_option_label = $this->getOptionLabel() === self::OPTION_LABEL_CUSTOM
871 : $this->getFalseOptionLabel($this->getOptionLabel());
872 foreach ($this->getAnswers() as $id => $answer) {
873 $value = $additional_info->getNoneTag();
874 foreach ($solution_values as $solution) {
875 if ($solution['value1'] !== (string) $id) {
876 continue;
877 }
878
879 $value = $false_option_label;
880 if ($solution['value2'] === '1') {
881 $value = $true_option_label;
882 }
883 break;
884 }
885 $parsed_solution[$answer->getAnswertext()] = $value;
886 }
887 return $parsed_solution;
888 }

References $id, and ILIAS\Test\Logging\AdditionalInformationGenerator\getNoneTag().

+ Here is the call graph for this function:

◆ solutionValuesToText()

assKprimChoice::solutionValuesToText ( array  $solution_values)

MUST convert the given solution values into text.

If the text has multiple lines each line MUST be placed as an entry in an array.

Reimplemented from assQuestion.

Definition at line 890 of file class.assKprimChoice.php.

890 : array
891 {
892 $parsed_solution = [];
893 $true_option_label = $this->getTrueOptionLabelTranslation($this->lng, $this->getOptionLabel());
894 $false_option_label = $this->getFalseOptionLabelTranslation($this->lng, $this->getOptionLabel());
895 foreach ($this->getAnswers() as $id => $answer) {
896 $value = $this->lng->txt('none');
897 foreach ($solution_values as $solution) {
898 if ($solution['value1'] !== (string) $id) {
899 continue;
900 }
901
902 $value = $false_option_label;
903 if ($solution['value2'] === '1') {
904 $value = $true_option_label;
905 }
906 break;
907 }
908 $parsed_solution[] = "{$answer->getAnswertext()} ({$value})";
909 }
910 return $parsed_solution;
911 }

References $id, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ toJSON()

assKprimChoice::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

Definition at line 710 of file class.assKprimChoice.php.

710 : string
711 {
712 $this->lng->loadLanguageModule('assessment');
713
714 $result = [];
715 $result['id'] = $this->getId();
716 $result['type'] = $this->getQuestionType();
717 $result['title'] = $this->getTitleForHTMLOutput();
718 $result['question'] = $this->formatSAQuestion($this->getQuestion());
719 $result['instruction'] = $this->getInstructionTextTranslation(
720 $this->lng,
721 $this->getOptionLabel()
722 );
723 $result['nr_of_tries'] = $this->getNrOfTries();
724 $result['shuffle'] = $this->isShuffleAnswersEnabled();
725 $result['feedback'] = [
726 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
727 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
728 ];
729
730 $result['trueOptionLabel'] = $this->getTrueOptionLabelTranslation($this->lng, $this->getOptionLabel());
731 $result['falseOptionLabel'] = $this->getFalseOptionLabelTranslation($this->lng, $this->getOptionLabel());
732
733 $result['num_allowed_failures'] = $this->getNumAllowedFailures();
734
735 $answers = [];
736 $has_image = false;
737
738 foreach ($this->getAnswers() as $key => $answer) {
739 if (strlen((string) $answer->getImageFile())) {
740 $has_image = true;
741 }
742
743 $answers[] = [
744 'answertext' => $this->formatSAQuestion($answer->getAnswertext() ?? ''),
745 'correctness' => (bool) $answer->getCorrectness(),
746 'order' => (int) $answer->getPosition(),
747 'image' => (string) $answer->getImageFile(),
748 'feedback' => $this->formatSAQuestion(
749 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
750 )
751 ];
752 }
753
754 $result['answers'] = $answers;
755
756 if ($has_image) {
757 $result['path'] = $this->getImagePathWeb();
758 $result['thumb'] = $this->getThumbSize();
759 }
760
761 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
762 $result['mobs'] = $mobs;
763
764 return json_encode($result);
765 }
getInstructionTextTranslation(ilLanguage $lng, $option_label)
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")

References ilObjMediaObject\_getMobsOfObject(), ILIAS\Survey\Mode\getId(), ILIAS\Repository\int(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ toLog()

assKprimChoice::toLog ( AdditionalInformationGenerator  $additional_info)

MUST return an array of the question settings that can be stored in the log.

Language variables must be generated through the corresponding functions in the AdditionalInformationGenerator. If an array is returned it will be rendered into a line per array entry in the format "key: value". If the key exists as a language variable, it will be translated.

Reimplemented from assQuestion.

Definition at line 824 of file class.assKprimChoice.php.

824 : array
825 {
826 $result = [
827 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->getQuestionType(),
828 AdditionalInformationGenerator::KEY_QUESTION_TITLE => $this->getTitleForHTMLOutput(),
829 AdditionalInformationGenerator::KEY_QUESTION_TEXT => $this->formatSAQuestion($this->getQuestion()),
830 AdditionalInformationGenerator::KEY_QUESTION_KPRIM_OPTION_LABEL => $additional_info
832 AdditionalInformationGenerator::KEY_QUESTION_SHUFFLE_ANSWER_OPTIONS => $additional_info
834 AdditionalInformationGenerator::KEY_FEEDBACK => [
835 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
836 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
837 ]
838 ];
839
840 $result[AdditionalInformationGenerator::KEY_QUESTION_KPRIM_SCORE_PARTIAL_SOLUTION_ENABLED] = $additional_info
842
843 $answers = [];
844 foreach ($this->getAnswers() as $key => $answer) {
845 $answers[$key + 1] = [
846 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION => $this->formatSAQuestion($answer->getAnswertext() ?? ''),
847 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_CORRECTNESS => $additional_info->getTrueFalseTagForBool((bool) $answer->getCorrectness()),
848 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_ORDER => (int) $answer->getPosition(),
849 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_IMAGE => (string) $answer->getImageFile(),
850 AdditionalInformationGenerator::KEY_FEEDBACK => $this->formatSAQuestion(
851 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
852 )
853 ];
854 }
855
856 $result[AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTIONS] = $answers;
857
858 return $result;
859 }

References ILIAS\Test\Logging\AdditionalInformationGenerator\getEnabledDisabledTagForBool(), ILIAS\Test\Logging\AdditionalInformationGenerator\getTagForLangVar(), ILIAS\Test\Logging\AdditionalInformationGenerator\getTrueFalseTagForBool(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

Field Documentation

◆ $answers

assKprimChoice::$answers = []
private

Definition at line 61 of file class.assKprimChoice.php.

Referenced by getAnswers(), and setAnswers().

◆ $answerType

string assKprimChoice::$answerType = self::ANSWER_TYPE_SINGLE_LINE
private

Definition at line 53 of file class.assKprimChoice.php.

Referenced by getAnswerType(), and setAnswerType().

◆ $customFalseOptionLabel

string assKprimChoice::$customFalseOptionLabel = ''
private

◆ $customTrueOptionLabel

string assKprimChoice::$customTrueOptionLabel = ''
private

Definition at line 57 of file class.assKprimChoice.php.

Referenced by getCustomTrueOptionLabel(), and setCustomTrueOptionLabel().

◆ $option_label

string assKprimChoice::$option_label = self::OPTION_LABEL_RIGHT_WRONG
private

Definition at line 56 of file class.assKprimChoice.php.

Referenced by getOptionLabel(), and setOptionLabel().

◆ $scorePartialSolutionEnabled

bool assKprimChoice::$scorePartialSolutionEnabled = true
private

◆ $shuffle_answers_enabled

bool assKprimChoice::$shuffle_answers_enabled = true
private

Definition at line 52 of file class.assKprimChoice.php.

Referenced by isShuffleAnswersEnabled(), and setShuffleAnswersEnabled().

◆ $specific_feedback_setting

int assKprimChoice::$specific_feedback_setting = ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_ALL
private

◆ $thumbSize

int assKprimChoice::$thumbSize = self::DEFAULT_THUMB_SIZE
private

Definition at line 54 of file class.assKprimChoice.php.

Referenced by getThumbSize(), and setThumbSize().

◆ ANSWER_TYPE_MULTI_LINE

const assKprimChoice::ANSWER_TYPE_MULTI_LINE = 'multiLine'

Definition at line 41 of file class.assKprimChoice.php.

Referenced by assKprimChoiceGUI\handleAnswerTextsSubmit().

◆ ANSWER_TYPE_SINGLE_LINE

const assKprimChoice::ANSWER_TYPE_SINGLE_LINE = 'singleLine'

Definition at line 40 of file class.assKprimChoice.php.

Referenced by isSingleLineAnswerType().

◆ DEFAULT_THUMB_SIZE

const assKprimChoice::DEFAULT_THUMB_SIZE = 150

Definition at line 49 of file class.assKprimChoice.php.

◆ NUM_REQUIRED_ANSWERS

const assKprimChoice::NUM_REQUIRED_ANSWERS = 4

Definition at line 36 of file class.assKprimChoice.php.

Referenced by __construct().

◆ OPTION_LABEL_ADEQUATE_OR_NOT

const assKprimChoice::OPTION_LABEL_ADEQUATE_OR_NOT = 'adequate_or_not'

Definition at line 46 of file class.assKprimChoice.php.

◆ OPTION_LABEL_APPLICABLE_OR_NOT

const assKprimChoice::OPTION_LABEL_APPLICABLE_OR_NOT = 'applicable_or_not'

Definition at line 45 of file class.assKprimChoice.php.

◆ OPTION_LABEL_CUSTOM

const assKprimChoice::OPTION_LABEL_CUSTOM = 'customlabel'

Definition at line 47 of file class.assKprimChoice.php.

◆ OPTION_LABEL_PLUS_MINUS

const assKprimChoice::OPTION_LABEL_PLUS_MINUS = 'plus_minus'

Definition at line 44 of file class.assKprimChoice.php.

◆ OPTION_LABEL_RIGHT_WRONG

const assKprimChoice::OPTION_LABEL_RIGHT_WRONG = 'right_wrong'

Definition at line 43 of file class.assKprimChoice.php.

◆ PARTIAL_SCORING_NUM_CORRECT_ANSWERS

const assKprimChoice::PARTIAL_SCORING_NUM_CORRECT_ANSWERS = 3

Definition at line 38 of file class.assKprimChoice.php.

◆ THUMB_PREFIX

const assKprimChoice::THUMB_PREFIX = 'thumb.'

Definition at line 50 of file class.assKprimChoice.php.


The documentation for this class was generated from the following file: