ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
assClozeTest Class Reference

Class for cloze tests. More...

+ Inheritance diagram for assClozeTest:
+ Collaboration diagram for assClozeTest:

Public Member Functions

 __construct (string $title="", string $comment="", string $author="", int $owner=-1, string $question="")
 
 isComplete ()
 Returns TRUE, if a cloze test is complete for use. More...
 
 cleanQuestiontext ($text)
 Cleans cloze question text to remove attributes or tags from older ILIAS versions. More...
 
 replaceFirstGap (string $gaptext, string $content)
 
 loadFromDb (int $question_id)
 
 saveToDb (?int $original_id=null)
 
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
 saveAdditionalQuestionDataToDb ()
 Saves a record to the question types additional data table. More...
 
 getGaps ()
 
 flushGaps ()
 
 setClozeText (string $cloze_text='')
 
 setClozeTextValue ($cloze_text="")
 
 getClozeText ()
 Returns the cloze text. More...
 
 getClozeTextForHTMLOutput ()
 Returns the cloze text as HTML (with optional nl2br) Fix for Mantis 29987: We assume Tiny embeds any text in tags, so if no tags are present, we derive it's non-HTML content and apply nl2br. More...
 
 getStartTag ()
 Returns the start tag of a cloze gap. More...
 
 setStartTag ($start_tag="[gap]")
 Sets the start tag of a cloze gap. More...
 
 getEndTag ()
 Returns the end tag of a cloze gap. More...
 
 setEndTag ($end_tag="[/gap]")
 Sets the end tag of a cloze gap. More...
 
 getFeedbackMode ()
 
 setFeedbackMode ($feedbackMode)
 
 createGapsFromQuestiontext ()
 Create gap entries by parsing the question text. More...
 
 setGapType ($gap_index, $gap_type)
 Set the type of a gap with a given index. More...
 
 setGapShuffle ($gap_index=0, $shuffle=1)
 Sets the shuffle state of a gap with a given index. More...
 
 clearGapAnswers ()
 Removes all answers from the gaps. More...
 
 getGapCount ()
 Returns the number of gaps. More...
 
 addGapAnswer ($gap_index, $order, $answer)
 Sets the answer text of a gap with a given index. More...
 
 getGap (int $gap_index=0)
 
 setGapSize ($gap_index, $size)
 
 setGapAnswerPoints ($gap_index, $order, $points)
 Sets the points of a gap with a given index and an answer with a given order. More...
 
 addGapText ($gap_index)
 Adds a new answer text value to a text gap with a given index. More...
 
 addGapAtIndex ($gap, $index)
 Adds a ClozeGap object at a given index. More...
 
 setGapAnswerLowerBound ($gap_index, $order, $bound)
 Sets the lower bound of a gap with a given index and an answer with a given order. More...
 
 setGapAnswerUpperBound ($gap_index, $order, $bound)
 Sets the upper bound of a gap with a given index and an answer with a given order. More...
 
 getMaximumPoints ()
 Returns the maximum points, a learner can reach answering the question. More...
 
 cloneQuestionTypeSpecificProperties (\assQuestion $target)
 
 updateClozeTextFromGaps ()
 Updates the gap parameters in the cloze text from the form input. More...
 
 deleteAnswerText ($gap_index, $answer_index)
 Deletes the answer text of a gap with a given index and an answer with a given order. More...
 
 deleteGap ($gap_index)
 Deletes a gap with a given index. More...
 
 getTextgapPoints ($a_original, $a_entered, $max_points)
 Returns the points for a text gap and compares the given solution with the entered solution using the text gap rating options. More...
 
 getAnswerOptionIndexForTextGapAnswer (array $answer_options, string $response)
 
 getNumericgapPoints ($a_original, $a_entered, $max_points, $lowerBound, $upperBound)
 Returns the points for a text gap and compares the given solution with the entered solution using the text gap rating options. More...
 
 checkForValidFormula (string $value)
 
 calculateReachedPoints (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 getUserResultDetails (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 fetchSolutionSubmit ()
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 getTextgapRating ()
 Returns the rating option for text gaps. More...
 
 setTextgapRating ($a_textgap_rating)
 Sets the rating option for text gaps. More...
 
 getIdenticalScoring ()
 Returns the identical scoring status of the question. More...
 
 setIdenticalScoring (bool $identical_scoring)
 Sets the identical scoring option for cloze questions. More...
 
 getAdditionalTableName ()
 Returns the name of the additional question data table in the database. More...
 
 getAnswerTableName ()
 
 setFixedTextLength (?int $fixed_text_length)
 Sets a fixed text length for all text fields in the cloze question. More...
 
 getFixedTextLength ()
 Gets the fixed text length for all text fields in the cloze question. More...
 
 getMaximumGapPoints ($gap_index)
 Returns the maximum points for a gap. More...
 
 getRTETextWithMediaObjects ()
 Collects all text in the question which could contain media objects which were created with the Rich Text Editor. More...
 
 getGapCombinationsExists ()
 
 getGapCombinations ()
 
 setGapCombinationsExists ($value)
 
 setGapCombinations ($value)
 
 toJSON ()
 Returns a JSON representation of the question. More...
 
 getOperators (string $expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. More...
 
 getUserQuestionResult (int $active_id, int $pass)
 Get the user solution for a question by active_id and the test pass. More...
 
 getAvailableAnswerOptions ($index=null)
 If index is null, the function returns an array with all anwser options Else it returns the specific answer option. More...
 
 calculateCombinationResult ($user_result)
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $preview_session)
 
 fetchAnswerValueForGap ($userSolution, $gapIndex)
 
 isAddableAnswerOptionValue (int $qIndex, string $answerOptionValue)
 
 addAnswerOptionValue (int $qIndex, string $answerOptionValue, float $points)
 
 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)
 
 toNormalized (Transformations $transformations, array $context=[])
 
 fromNormalized (array $normalized, Transformations $transformations)
 
- 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)
 
 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)
 
 updateOriginalId (?int $original_id=null)
 
 duplicate (bool $set_original_id=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)
 
 toNormalized (Transformations $transformations, array $context=[])
 
 fromNormalized (array $normalized, Transformations $transformations)
 
 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...
 
- Public Member Functions inherited from iQuestionCondition
 getOperators (string $expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. More...
 
 getUserQuestionResult (int $active_id, int $pass)
 Get the user solution for a question by active_id and the test pass. More...
 
 getAvailableAnswerOptions (?int $index=null)
 If index is null, the function returns an array with all anwser options else it returns the specific answer option. More...
 
 toJSON ()
 
 toNormalized (Transformations $transformations, array $context=[])
 Convert the internal state of the implementing object into a language-neutral array structure. More...
 
 fromNormalized (array $normalized, Transformations $transformations)
 Restore the object from its normalized representation. More...
 

Data Fields

array $gaps = []
 
string $textgap_rating = assClozeGap::TEXTGAP_RATING_CASEINSENSITIVE
 The rating option for text gaps. More...
 
ilAssQuestionFeedback $feedbackOBJ
 
- 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 = ':'
 
- Data Fields inherited from iQuestionCondition
const StringResultExpression = '~TEXT~'
 
const PercentageResultExpression = '%n%'
 
const NumericResultExpression = '#n#'
 
const MatchingResultExpression = ';n:m;'
 
const OrderingResultExpression = '$n,m,o,p$'
 
const NumberOfResultExpression = '+n+'
 
const ExclusiveResultExpression = '*n,m,o,p*'
 
const EmptyAnswerExpression = "?"
 

Protected Member Functions

 saveClozeGapItemsToDb (assClozeGap $gap, int $key)
 
 saveClozeTextGapRecordToDb (int $next_id, int $key, assAnswerCloze $item, assClozeGap $gap)
 
 saveClozeSelectGapRecordToDb (int $next_id, int $key, assAnswerCloze $item, assClozeGap $gap)
 
 saveClozeNumericGapRecordToDb (int $next_id, int $key, assAnswerCloze $item, assClozeGap $gap)
 
 isValidNumericSubmitValue ($submittedValue)
 
 getSolutionSubmit ()
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 calculateReachedPointsForSolution (?array $user_result, array &$detailed=[])
 
 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)
 

Protected Attributes

 $gap_combinations = []
 
bool $gap_combinations_exist = false
 
bool $identical_scoring = true
 Defines the scoring for "identical solutions". More...
 
int $fixed_text_length = null
 
string $cloze_text = ''
 
 $feedbackMode = ilAssClozeTestFeedback::FB_MODE_GAP_QUESTION
 
- 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
 

Private Member Functions

 fetchUserResult (int $active_id, ?int $pass)
 

Private Attributes

string $start_tag = '[gap]'
 
string $end_tag = '[/gap]'
 
RandomGroup $randomGroup
 

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)
 
- Static Protected Attributes inherited from assQuestion
static $force_pass_results_update_enabled = false
 
static $imageSourceFixReplaceMap
 

Detailed Description

Class for cloze tests.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Björn Heyser bheys.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

assClozeTest::__construct ( string  $title = "",
string  $comment = "",
string  $author = "",
int  $owner = -1,
string  $question = "" 
)

Definition at line 85 of file class.assClozeTest.php.

91 {
92 global $DIC;
94 $this->setQuestion($question); // @TODO: Should this be $question?? See setter for why this is not trivial.
95 $this->randomGroup = $DIC->refinery()->random();
96 }
setQuestion(string $question="")
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addAnswerOptionValue()

assClozeTest::addAnswerOptionValue ( int  $qIndex,
string  $answerOptionValue,
float  $points 
)

Reimplemented from assQuestion.

Definition at line 1662 of file class.assClozeTest.php.

1662 : void
1663 {
1664 $gap = $this->getGap($qIndex); /* @var assClozeGap $gap */
1665
1666 $item = new assAnswerCloze($answerOptionValue, $points);
1667 $item->setOrder($gap->getItemCount());
1668
1669 $gap->addItem($item);
1670 }
Class for cloze question numeric answers.
getGap(int $gap_index=0)

References assClozeGap\addItem(), assClozeGap\getItemCount(), and ASS_AnswerSimple\setOrder().

+ Here is the call graph for this function:

◆ addGapAnswer()

assClozeTest::addGapAnswer (   $gap_index,
  $order,
  $answer 
)

Sets the answer text of a gap with a given index.

The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters
integer$gap_indexA nonnegative index of the n-th gap
integer$orderThe order of the answer text
string$answerThe answer text @access public
See also
$gaps

Definition at line 629 of file class.assClozeTest.php.

629 : void
630 {
631 if (array_key_exists($gap_index, $this->gaps)) {
632 if ($this->gaps[$gap_index]->getType() == assClozeGap::TYPE_NUMERIC) {
633 // only allow notation with "." for real numbers
634 $answer = str_replace(",", ".", $answer);
635 }
636 $this->gaps[$gap_index]->addItem(new assAnswerCloze(trim($answer), 0, $order));
637 }
638 }

References assClozeGap\TYPE_NUMERIC.

◆ addGapAtIndex()

assClozeTest::addGapAtIndex (   $gap,
  $index 
)

Adds a ClozeGap object at a given index.

Parameters
object$gapThe gap object
integer$indexA nonnegative index of the n-th gap @access public
See also
$gaps

Definition at line 700 of file class.assClozeTest.php.

700 : void
701 {
702 $this->gaps[$index] = $gap;
703 }

◆ addGapText()

assClozeTest::addGapText (   $gap_index)

Adds a new answer text value to a text gap with a given index.

The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters
integer$gap_indexA nonnegative index of the n-th gap @access public
See also
$gaps

Definition at line 680 of file class.assClozeTest.php.

680 : void
681 {
682 if (array_key_exists($gap_index, $this->gaps)) {
683 $answer = new assAnswerCloze(
684 "",
685 0,
686 $this->gaps[$gap_index]->getItemCount()
687 );
688 $this->gaps[$gap_index]->addItem($answer);
689 }
690 }

◆ calculateCombinationResult()

assClozeTest::calculateCombinationResult (   $user_result)

Definition at line 1447 of file class.assClozeTest.php.

1447 : array
1448 {
1449 $points = 0;
1450
1451 $assClozeGapCombinationObj = new assClozeGapCombination($this->db);
1452 $gap_used_in_combination = [];
1453 if ($assClozeGapCombinationObj->combinationExistsForQid($this->getId())) {
1454 $combinations_for_question = $assClozeGapCombinationObj->getCleanCombinationArray($this->getId());
1455 $gap_answers = [];
1456
1457 foreach ($user_result as $user_result_build_list) {
1458 if (is_array($user_result_build_list)) {
1459 $gap_answers[$user_result_build_list['gap_id']] = $user_result_build_list['value'];
1460 }
1461 }
1462
1463 foreach ($combinations_for_question as $combination) {
1464 foreach ($combination as $row_key => $row_answers) {
1465 $combination_fulfilled = true;
1466 $points_for_combination = $row_answers['points'];
1467 foreach ($row_answers as $gap_key => $combination_gap_answer) {
1468 if ($gap_key !== 'points') {
1469 $gap_used_in_combination[$gap_key] = $gap_key;
1470 }
1471 if ($combination_fulfilled && array_key_exists($gap_key, $gap_answers)) {
1472 switch ($combination_gap_answer['type']) {
1474 $is_text_gap_correct = $this->getTextgapPoints($gap_answers[$gap_key], $combination_gap_answer['answer'], 1);
1475 if ($is_text_gap_correct != 1) {
1476 $combination_fulfilled = false;
1477 }
1478 break;
1480 $answer = $this->gaps[$gap_key]->getItem($gap_answers[$gap_key]);
1481 $answertext = $answer?->getAnswertext();
1482 if ($answertext != $combination_gap_answer['answer']) {
1483 $combination_fulfilled = false;
1484 }
1485 break;
1487 $answer = $this->gaps[$gap_key]->getItem(0);
1488 if ($combination_gap_answer['answer'] != 'out_of_bound') {
1489 $is_numeric_gap_correct = $this->getNumericgapPoints($answer->getAnswertext(), $gap_answers[$gap_key], 1, $answer->getLowerBound(), $answer->getUpperBound());
1490 if ($is_numeric_gap_correct != 1) {
1491 $combination_fulfilled = false;
1492 }
1493 } else {
1494 $wrong_is_the_new_right = $this->getNumericgapPoints($answer->getAnswertext(), $gap_answers[$gap_key], 1, $answer->getLowerBound(), $answer->getUpperBound());
1495 if ($wrong_is_the_new_right == 1) {
1496 $combination_fulfilled = false;
1497 }
1498 }
1499 break;
1500 }
1501 } else {
1502 if ($gap_key !== 'points') {
1503 $combination_fulfilled = false;
1504 }
1505 }
1506 }
1507 if ($combination_fulfilled) {
1508 $points += $points_for_combination;
1509 }
1510 }
1511 }
1512 }
1513 return [$points, $gap_used_in_combination];
1514 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTextgapPoints($a_original, $a_entered, $max_points)
Returns the points for a text gap and compares the given solution with the entered solution using the...
getNumericgapPoints($a_original, $a_entered, $max_points, $lowerBound, $upperBound)
Returns the points for a text gap and compares the given solution with the entered solution using the...

References ILIAS\Survey\Mode\getId(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

+ Here is the call graph for this function:

◆ calculateReachedPoints()

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

Reimplemented from assQuestion.

Definition at line 1016 of file class.assClozeTest.php.

1020 : float {
1021 $user_result = $this->fetchUserResult($active_id, $pass, $authorized_solution);
1022 return $this->calculateReachedPointsForSolution($user_result);
1023 }
calculateReachedPointsForSolution(?array $user_result, array &$detailed=[])
fetchUserResult(int $active_id, ?int $pass)

◆ calculateReachedPointsForSolution()

assClozeTest::calculateReachedPointsForSolution ( ?array  $user_result,
array &  $detailed = [] 
)
protected
Parameters
array$user_result
array$detailed

Definition at line 1519 of file class.assClozeTest.php.

1519 : float
1520 {
1521 $points = 0.0;
1522
1523 $assClozeGapCombinationObj = new assClozeGapCombination($this->db);
1524 $combinations[1] = [];
1525 if ($this->gap_combinations_exist) {
1526 $combinations = $this->calculateCombinationResult($user_result);
1527 $points = $combinations[0];
1528 }
1529
1530 $solution_values_text = []; // for identical scoring checks
1531 $solution_values_select = []; // for identical scoring checks
1532 $solution_values_numeric = []; // for identical scoring checks
1533 foreach ($user_result as $gap_id => $value) {
1534 if (is_string($value)) {
1535 $value = ["value" => $value];
1536 }
1537
1538 if (array_key_exists($gap_id, $this->gaps) && !array_key_exists($gap_id, $combinations[1])) {
1539 switch ($this->gaps[$gap_id]->getType()) {
1541 $gappoints = 0.0;
1542 for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) {
1543 $answer = $this->gaps[$gap_id]->getItem($order);
1544 $gotpoints = $this->getTextgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints());
1545 if ($gotpoints > $gappoints) {
1546 $gappoints = $gotpoints;
1547 }
1548 }
1549 if (!$this->getIdenticalScoring()) {
1550 // check if the same solution text was already entered
1551 if ((in_array($value["value"], $solution_values_text)) && ($gappoints > 0.0)) {
1552 $gappoints = 0.0;
1553 }
1554 }
1555 $points += $gappoints;
1556 $detailed[$gap_id] = ["points" => $gappoints, "best" => ($this->getMaximumGapPoints($gap_id) == $gappoints) ? true : false, "positive" => ($gappoints > 0.0) ? true : false];
1557 array_push($solution_values_text, $value["value"]);
1558 break;
1560 $gappoints = 0.0;
1561 for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) {
1562 $answer = $this->gaps[$gap_id]->getItem($order);
1563 $gotpoints = $this->getNumericgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
1564 if ($gotpoints > $gappoints) {
1565 $gappoints = $gotpoints;
1566 }
1567 }
1568 if (!$this->getIdenticalScoring()) {
1569 // check if the same solution value was already entered
1570 $eval = new EvalMath();
1571 $eval->suppress_errors = true;
1572 $found_value = false;
1573 foreach ($solution_values_numeric as $solval) {
1574 if ($eval->e($solval) == $eval->e($value["value"])) {
1575 $found_value = true;
1576 }
1577 }
1578 if ($found_value && ($gappoints > 0.0)) {
1579 $gappoints = 0.0;
1580 }
1581 }
1582 $points += $gappoints;
1583 $detailed[$gap_id] = ["points" => $gappoints, "best" => ($this->getMaximumGapPoints($gap_id) == $gappoints) ? true : false, "positive" => ($gappoints > 0.0) ? true : false];
1584 array_push($solution_values_numeric, $value["value"]);
1585 break;
1587 if ($value["value"] >= 0.0) {
1588 for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) {
1589 $answer = $this->gaps[$gap_id]->getItem($order);
1590 if ($value["value"] == $answer->getOrder()) {
1591 $answerpoints = $answer->getPoints();
1592 if (!$this->getIdenticalScoring()) {
1593 // check if the same solution value was already entered
1594 if ((in_array($answer->getAnswertext(), $solution_values_select)) && ($answerpoints > 0.0)) {
1595 $answerpoints = 0.0;
1596 }
1597 }
1598 $points += $answerpoints;
1599 $detailed[$gap_id] = ["points" => $answerpoints, "best" => ($this->getMaximumGapPoints($gap_id) == $answerpoints) ? true : false, "positive" => ($answerpoints > 0.0) ? true : false];
1600 array_push($solution_values_select, $answer->getAnswertext());
1601 }
1602 }
1603 }
1604 break;
1605 }
1606 }
1607 }
1608
1609 return $points;
1610 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMaximumGapPoints($gap_index)
Returns the maximum points for a gap.
calculateCombinationResult($user_result)
getIdenticalScoring()
Returns the identical scoring status of the question.

References assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

◆ calculateReachedPointsFromPreviewSession()

assClozeTest::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $preview_session)

Reimplemented from assQuestion.

Definition at line 1612 of file class.assClozeTest.php.

1612 : float
1613 {
1614 $participant_session = $preview_session->getParticipantsSolution();
1615
1616 if (!is_array($participant_session)) {
1617 return 0.0;
1618 }
1619
1620 $user_solution = [];
1621
1622 foreach ($participant_session as $key => $val) {
1623 $user_solution[$key] = ['gap_id' => $key, 'value' => $val];
1624 }
1625
1626 $reached_points = $this->calculateReachedPointsForSolution($user_solution);
1627
1628 return $this->ensureNonNegativePoints($reached_points);
1629 }
ensureNonNegativePoints(float $points)

References ilAssQuestionPreviewSession\getParticipantsSolution().

+ Here is the call graph for this function:

◆ checkForValidFormula()

assClozeTest::checkForValidFormula ( string  $value)

Definition at line 1011 of file class.assClozeTest.php.

1011 : int
1012 {
1013 return preg_match("/^-?(\\d*)(,|\\.|\\/){0,1}(\\d*)$/", $value, $matches);
1014 }

◆ cleanQuestiontext()

assClozeTest::cleanQuestiontext (   $text)

Cleans cloze question text to remove attributes or tags from older ILIAS versions.

Parameters
string$textThe cloze question text
Returns
string The cleaned cloze question text

Definition at line 122 of file class.assClozeTest.php.

122 : string
123 {
124 if ($text === null) {
125 return '';
126 }
127 // fau: fixGapReplace - mask dollars for replacement
128 $text = str_replace('$', 'GAPMASKEDDOLLAR', $text);
129 $text = preg_replace("/\[gap[^\]]*?\]/", "[gap]", $text);
130 $text = preg_replace("/<gap([^>]*?)>/", "[gap]", $text);
131 $text = str_replace("</gap>", "[/gap]", $text);
132 $text = str_replace('GAPMASKEDDOLLAR', '$', $text);
133 // fau.
134 return $text;
135 }
$text
Definition: xapiexit.php:21

References $text.

◆ clearGapAnswers()

assClozeTest::clearGapAnswers ( )

Removes all answers from the gaps.

@access public

See also
$gaps

Definition at line 596 of file class.assClozeTest.php.

596 : void
597 {
598 foreach ($this->gaps as $gap_index => $gap) {
599 $this->gaps[$gap_index]->clearItems();
600 }
601 }

◆ cloneQuestionTypeSpecificProperties()

assClozeTest::cloneQuestionTypeSpecificProperties ( \assQuestion  $target)

Definition at line 787 of file class.assClozeTest.php.

789 : \assQuestion {
790 if ($this->gap_combinations_exist) {
791 $gap_combination = new assClozeGapCombination($this->db);
792 $gap_combination->clearGapCombinationsFromDb($target->getId());
793 $gap_combination->importGapCombinationToDb(
794 $target->getId(),
795 $this->gap_combinations,
796 );
797
798 // Mantis 46713: The maximum points may have changed due to the combinations,
799 // so the question must be saved again
800 $target->saveToDb();
801 }
802
803 return $target;
804 }

References ILIAS\Scripts\PHPStan\$target.

◆ createGapsFromQuestiontext()

assClozeTest::createGapsFromQuestiontext ( )

Create gap entries by parsing the question text.

@access public

See also
$gaps

Definition at line 543 of file class.assClozeTest.php.

543 : void
544 {
545 $search_pattern = "|\[gap\](.*?)\[/gap\]|i";
546 preg_match_all($search_pattern, $this->getClozeText(), $found);
547 $this->gaps = [];
548 if (count($found[0])) {
549 foreach ($found[1] as $gap_index => $answers) {
550 // create text gaps by default
552 $textparams = preg_split("/(?<!\\\\),/", $answers);
553 foreach ($textparams as $key => $value) {
554 $answer = new assAnswerCloze($value, 0, $key);
555 $gap->addItem($answer);
556 }
557 $this->gaps[$gap_index] = $gap;
558 }
559 }
560 }
Class for cloze question gaps.
getClozeText()
Returns the cloze text.

References assClozeGap\addItem(), and assClozeGap\TYPE_TEXT.

+ Here is the call graph for this function:

◆ deleteAnswerText()

assClozeTest::deleteAnswerText (   $gap_index,
  $answer_index 
)

Deletes the answer text of a gap with a given index and an answer with a given order.

The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters
integer$gap_indexA nonnegative index of the n-th gap
integer$answer_indexThe order of the answer text @access public
See also
$gaps

Definition at line 836 of file class.assClozeTest.php.

836 : void
837 {
838 if (array_key_exists($gap_index, $this->gaps)) {
839 if ($this->gaps[$gap_index]->getItemCount() == 1) {
840 // this is the last answer text => remove the gap
841 $this->deleteGap($gap_index);
842 } else {
843 // remove the answer text
844 $this->gaps[$gap_index]->deleteItem($answer_index);
846 }
847 }
848 }
updateClozeTextFromGaps()
Updates the gap parameters in the cloze text from the form input.
deleteGap($gap_index)
Deletes a gap with a given index.

◆ deleteGap()

assClozeTest::deleteGap (   $gap_index)

Deletes a gap with a given index.

The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters
integer$gap_indexA nonnegative index of the n-th gap @access public
See also
$gaps

Definition at line 858 of file class.assClozeTest.php.

858 : void
859 {
860 if (array_key_exists($gap_index, $this->gaps)) {
861 $output = $this->getClozeText();
862 foreach ($this->getGaps() as $replace_gap_index => $gap) {
863 $answers = [];
864 foreach ($gap->getItemsRaw() as $item) {
865 array_push($answers, str_replace(",", "\\,", $item->getAnswerText()));
866 }
867 if ($replace_gap_index == $gap_index) {
868 // fau: fixGapReplace - use replace function
869 $output = $this->replaceFirstGap($output, '');
870 // fau.
871 } else {
872 // fau: fixGapReplace - use replace function
873 $output = $this->replaceFirstGap($output, "[_gap]" . join(",", $answers) . "[/_gap]");
874 // fau.
875 }
876 }
877 $output = str_replace("_gap]", "gap]", $output);
878 $this->cloze_text = $output;
879 unset($this->gaps[$gap_index]);
880 $this->gaps = array_values($this->gaps);
881 }
882 }
replaceFirstGap(string $gaptext, string $content)

References assClozeGap\getItemsRaw().

+ Here is the call graph for this function:

◆ fetchAnswerValueForGap()

assClozeTest::fetchAnswerValueForGap (   $userSolution,
  $gapIndex 
)

Definition at line 1631 of file class.assClozeTest.php.

1631 : string
1632 {
1633 $answerValue = '';
1634
1635 foreach ($userSolution as $value1 => $value2) {
1636 if ($value1 == $gapIndex) {
1637 $answerValue = $value2;
1638 break;
1639 }
1640 }
1641
1642 return $answerValue;
1643 }

◆ fetchSolutionSubmit()

assClozeTest::fetchSolutionSubmit ( )

Definition at line 1073 of file class.assClozeTest.php.

1073 : array
1074 {
1075 $solution_submit = [];
1076 $post_wrapper = $this->dic->http()->wrapper()->post();
1077 foreach ($this->getGaps() as $index => $gap) {
1078 if (!$post_wrapper->has("gap_$index")) {
1079 continue;
1080 }
1081 $value = trim($post_wrapper->retrieve(
1082 "gap_$index",
1083 $this->dic->refinery()->kindlyTo()->string()
1084 ));
1085 if ($value === '') {
1086 continue;
1087 }
1088
1089 if ($gap->getType() === assClozeGap::TYPE_SELECT && $value === '-1') {
1090 continue;
1091 }
1092
1093 if ($gap->getType() === assClozeGap::TYPE_NUMERIC) {
1094 $value = str_replace(',', '.', $value);
1095 if (!is_numeric($value)) {
1096 $value = null;
1097 }
1098 }
1099
1100 $solution_submit[$index] = $value;
1101 }
1102
1103 return $solution_submit;
1104 }

References assClozeGap\getType(), assClozeGap\TYPE_NUMERIC, and assClozeGap\TYPE_SELECT.

+ Here is the call graph for this function:

◆ fetchUserResult()

assClozeTest::fetchUserResult ( int  $active_id,
?int  $pass 
)
private

Definition at line 1036 of file class.assClozeTest.php.

1039 : array {
1040 if (is_null($pass)) {
1041 $pass = $this->getSolutionMaxPass($active_id);
1042 }
1043
1044 $result = $this->getCurrentSolutionResultSet($active_id, $pass, true);
1045 $user_result = [];
1046 while ($data = $this->db->fetchAssoc($result)) {
1047 if ($data['value2'] === '') {
1048 continue;
1049 }
1050 $user_result[$data['value1']] = [
1051 'gap_id' => $data['value1'],
1052 'value' => $data['value2']
1053 ];
1054 }
1055
1056 ksort($user_result);
1057 return $user_result;
1058 }
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getSolutionMaxPass(int $active_id)
$data
Definition: storeScorm.php:45

◆ flushGaps()

assClozeTest::flushGaps ( )

Definition at line 416 of file class.assClozeTest.php.

416 : void
417 {
418 $this->gaps = [];
419 }

◆ fromNormalized()

assClozeTest::fromNormalized ( array  $normalized,
Transformations  $transformations 
)
Parameters
array<array-key,mixed>$normalized

Reimplemented from assQuestion.

Definition at line 1794 of file class.assClozeTest.php.

1797 : static
1798 {
1799 $clone = parent::fromNormalized($normalized, $transformations);
1800 $clone->feedbackMode = $transformations->string($normalized['feedback_mode']);
1801 $clone->cloze_text = $transformations->string($normalized['cloze_text']);
1802 $clone->textgap_rating = $transformations->string($normalized['textgap_rating']);
1803 $clone->identical_scoring = $transformations->bool($normalized['identical_scoring']);
1804 $clone->fixed_text_length = $transformations->nullableInt($normalized['fixed_text_length']);
1805 $clone->gap_combinations_exist = $transformations->bool($normalized['gap_combinations_exist']);
1806 $clone->gap_combinations = $normalized['gap_combinations'];
1807
1808 foreach ($normalized['gaps'] as $gap) {
1809 $type = $transformations->int($gap['type']);
1810 $clone->gaps[] = $transformations->denormalize($gap, new assClozeGap($type));
1811 }
1812
1813 return $clone;
1814 }
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)

References ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\bool(), ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\denormalize(), ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\int(), ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\nullableInt(), and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\string().

+ Here is the call graph for this function:

◆ getAdditionalTableName()

assClozeTest::getAdditionalTableName ( )

Returns the name of the additional question data table in the database.

Returns
string The additional table name @access public

Reimplemented from assQuestion.

Definition at line 1219 of file class.assClozeTest.php.

1219 : string
1220 {
1221 return "qpl_qst_cloze";
1222 }

◆ getAnswerOptionIndexForTextGapAnswer()

assClozeTest::getAnswerOptionIndexForTextGapAnswer ( array  $answer_options,
string  $response 
)
Parameters
array<int,assAnswerCloze>$answer_options

Definition at line 935 of file class.assClozeTest.php.

938 : ?int {
939 $levenshtein_distance = match ($this->textgap_rating) {
945 default => null
946 };
947
948 if ($levenshtein_distance !== null) {
949 foreach ($answer_options as $answer_index => $answer_option) {
950 if ($this->refinery->string()->levenshtein()->standard(
951 $answer_option->getAnswertext(),
952 $levenshtein_distance
953 )->transform($response) >= 0) {
954 return $answer_index;
955 }
956 }
957 } elseif ($this->textgap_rating === assClozeGap::TEXTGAP_RATING_CASEINSENSITIVE) {
958 $response_to_lower = strtolower($response);
959 foreach ($answer_options as $answer_index => $answer_option) {
960 if (strtolower($answer_option->getAnswertext()) === $response_to_lower) {
961 return $answer_index;
962 }
963 }
964 } elseif ($this->textgap_rating === assClozeGap::TEXTGAP_RATING_CASESENSITIVE) {
965 foreach ($answer_options as $answer_index => $answer_option) {
966 if ($answer_option->getAnswertext() === $response) {
967 return $answer_index;
968 }
969 }
970 }
971
972 return null;
973 }
const TEXTGAP_RATING_CASESENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN1
const TEXTGAP_RATING_LEVENSHTEIN5
const TEXTGAP_RATING_CASEINSENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN4
const TEXTGAP_RATING_LEVENSHTEIN2
const TEXTGAP_RATING_LEVENSHTEIN3
$response
Definition: xapitoken.php:92

References assClozeGap\TEXTGAP_RATING_LEVENSHTEIN1, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN2, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN3, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN4, and assClozeGap\TEXTGAP_RATING_LEVENSHTEIN5.

◆ getAnswerTableName()

assClozeTest::getAnswerTableName ( )

Reimplemented from assQuestion.

Definition at line 1224 of file class.assClozeTest.php.

1224 : array
1225 {
1226 return ["qpl_a_cloze",'qpl_a_cloze_combi_res'];
1227 }

◆ getAvailableAnswerOptions()

assClozeTest::getAvailableAnswerOptions (   $index = null)

If index is null, the function returns an array with all anwser options Else it returns the specific answer option.

Parameters
null | int$index
Returns
array|ASS_AnswerSimple

Definition at line 1438 of file class.assClozeTest.php.

1439 {
1440 if ($index !== null) {
1441 return $this->getGap($index);
1442 } else {
1443 return $this->getGaps();
1444 }
1445 }

◆ getClozeText()

assClozeTest::getClozeText ( )

Returns the cloze text.

Returns
string The cloze text string @access public
See also
$cloze_text

Definition at line 440 of file class.assClozeTest.php.

440 : string
441 {
442 return $this->cloze_text;
443 }

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getClozeTextForHTMLOutput()

assClozeTest::getClozeTextForHTMLOutput ( )

Returns the cloze text as HTML (with optional nl2br) Fix for Mantis 29987: We assume Tiny embeds any text in tags, so if no tags are present, we derive it's non-HTML content and apply nl2br.

Returns
string The cloze text string as HTML
See also
$cloze_text

Definition at line 453 of file class.assClozeTest.php.

453 : string
454 {
455 $gaps = [];
456 preg_match_all('/\[gap\].*?\[\/gap\]/', $this->getClozeText(), $gaps);
457 $string_with_replaced_gaps = str_replace($gaps[0], '######GAP######', $this->getClozeText());
458 $cleaned_text = $this->getHtmlQuestionContentPurifier()->purify(
459 $string_with_replaced_gaps
460 );
461 $cleaned_text_with_gaps = preg_replace_callback('/######GAP######/', function ($match) use (&$gaps) {
462 return array_shift($gaps[0]);
463 }, $cleaned_text);
464
466 || !(new ilSetting('advanced_editing'))->get('advanced_editing_javascript_editor') === 'tinymce') {
467 $cleaned_text_with_gaps = nl2br($cleaned_text_with_gaps);
468 }
469
470 return ilLegacyFormElementsUtil::prepareTextareaOutput($cleaned_text_with_gaps, true);
471 }
isAdditionalContentEditingModePageObject()
static prepareTextareaOutput(string $txt_output, bool $prepare_for_latex_output=false, bool $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free,...
ILIAS Setting Class.

References ILIAS\Questions\AnswerFormTypes\Cloze\Migration\getHtmlQuestionContentPurifier(), and ilLegacyFormElementsUtil\prepareTextareaOutput().

+ Here is the call graph for this function:

◆ getCorrectSolutionForTextOutput()

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

Reimplemented from assQuestion.

Definition at line 1760 of file class.assClozeTest.php.

1760 : array
1761 {
1762 $answers = [];
1763 foreach ($this->getGaps() as $gap_index => $gap) {
1764 $correct_answers = array_map(
1765 fn(int $v): string => $gap->getItem($v)->getAnswertext(),
1766 $gap->getBestSolutionIndexes()
1767 );
1768 $answers[] = $this->lng->txt('gap') . ' ' . $gap_index + 1 . ': '
1769 . implode(',', $correct_answers);
1770 }
1771 return $answers;
1772 }

References assClozeGap\getBestSolutionIndexes(), assClozeGap\getItem(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getEndTag()

assClozeTest::getEndTag ( )

Returns the end tag of a cloze gap.

Returns
string The end tag of a cloze gap @access public
See also
$end_tag

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

504 : string
505 {
506 return $this->end_tag;
507 }

◆ getExpressionTypes()

◆ getFeedbackMode()

assClozeTest::getFeedbackMode ( )
Returns
string

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

524 : string
525 {
526 return $this->feedbackMode;
527 }

◆ getFixedTextLength()

assClozeTest::getFixedTextLength ( )

Gets the fixed text length for all text fields in the cloze question.

Returns
integer The text field length @access public

Definition at line 1246 of file class.assClozeTest.php.

1246 : ?int
1247 {
1249 }

◆ getGap()

assClozeTest::getGap ( int  $gap_index = 0)

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

640 : ?assClozeGap
641 {
642 if (array_key_exists($gap_index, $this->gaps)) {
643 return $this->gaps[$gap_index];
644 }
645 return null;
646 }

◆ getGapCombinations()

assClozeTest::getGapCombinations ( )

Definition at line 1288 of file class.assClozeTest.php.

1288 : array
1289 {
1291 }

◆ getGapCombinationsExists()

assClozeTest::getGapCombinationsExists ( )

Definition at line 1283 of file class.assClozeTest.php.

1283 : bool
1284 {
1286 }

◆ getGapCount()

assClozeTest::getGapCount ( )

Returns the number of gaps.

Returns
integer The number of gaps @access public
See also
$gaps

Definition at line 610 of file class.assClozeTest.php.

610 : int
611 {
612 if (is_array($this->gaps)) {
613 return count($this->gaps);
614 } else {
615 return 0;
616 }
617 }

◆ getGaps()

assClozeTest::getGaps ( )

Definition at line 411 of file class.assClozeTest.php.

411 : array
412 {
413 return $this->gaps;
414 }

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getIdenticalScoring()

assClozeTest::getIdenticalScoring ( )

Returns the identical scoring status of the question.

Returns
boolean The identical scoring status
See also
$identical_scoring @access public

Definition at line 1196 of file class.assClozeTest.php.

1196 : bool
1197 {
1199 }
bool $identical_scoring
Defines the scoring for "identical solutions".

◆ getMaximumGapPoints()

assClozeTest::getMaximumGapPoints (   $gap_index)

Returns the maximum points for a gap.

Parameters
integer$gap_indexThe index of the gap
Returns
double The maximum points for the gap @access public
See also
$points

Definition at line 1259 of file class.assClozeTest.php.

1260 {
1261 $points = 0;
1262 $gap_max_points = 0;
1263 if (array_key_exists($gap_index, $this->gaps)) {
1264 $gap = &$this->gaps[$gap_index];
1265 foreach ($gap->getItems($this->getShuffler()) as $answer) {
1266 if ($answer->getPoints() > $gap_max_points) {
1267 $gap_max_points = $answer->getPoints();
1268 }
1269 }
1270 $points += $gap_max_points;
1271 }
1272 return $points;
1273 }

References assClozeGap\getItems().

+ Here is the call graph for this function:

◆ getMaximumPoints()

assClozeTest::getMaximumPoints ( )

Returns the maximum points, a learner can reach answering the question.

@access public

See also
$points

Reimplemented from assQuestion.

Definition at line 745 of file class.assClozeTest.php.

745 : float
746 {
747 $assClozeGapCombinationObj = new assClozeGapCombination($this->db);
748 $points = 0;
749 $gaps_used_in_combination = [];
750 if ($this->gap_combinations_exist) {
751 $points = $assClozeGapCombinationObj->getMaxPointsForCombination($this->getId());
752 $gaps_used_in_combination = $assClozeGapCombinationObj->getGapsWhichAreUsedInCombination($this->getId());
753 }
754 foreach ($this->gaps as $gap_index => $gap) {
755 if (!array_key_exists($gap_index, $gaps_used_in_combination)) {
756 if ($gap->getType() == assClozeGap::TYPE_TEXT) {
757 $gap_max_points = 0;
758 foreach ($gap->getItems($this->getShuffler()) as $item) {
759 if ($item->getPoints() > $gap_max_points) {
760 $gap_max_points = $item->getPoints();
761 }
762 }
763 $points += $gap_max_points;
764 } elseif ($gap->getType() == assClozeGap::TYPE_SELECT) {
765 $srpoints = 0;
766 foreach ($gap->getItems($this->getShuffler()) as $item) {
767 if ($item->getPoints() > $srpoints) {
768 $srpoints = $item->getPoints();
769 }
770 }
771 $points += $srpoints;
772 } elseif ($gap->getType() == assClozeGap::TYPE_NUMERIC) {
773 $numpoints = 0;
774 foreach ($gap->getItems($this->getShuffler()) as $item) {
775 if ($item->getPoints() > $numpoints) {
776 $numpoints = $item->getPoints();
777 }
778 }
779 $points += $numpoints;
780 }
781 }
782 }
783
784 return $points;
785 }

References ILIAS\Survey\Mode\getId(), assClozeGap\getItems(), assClozeGap\getType(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

Referenced by isComplete().

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

◆ getNumericgapPoints()

assClozeTest::getNumericgapPoints (   $a_original,
  $a_entered,
  $max_points,
  $lowerBound,
  $upperBound 
)

Returns the points for a text gap and compares the given solution with the entered solution using the text gap rating options.

Parameters
string$a_originalThe original (correct) text
string$a_enteredThe text entered by the user
float$max_pointsThe maximum number of points for the solution @access public

Definition at line 985 of file class.assClozeTest.php.

985 : float
986 {
987 $eval = new EvalMath();
988 $eval->suppress_errors = true;
989 $result = 0.0;
990
991 if ($eval->e($a_entered) === false) {
992 return 0.0;
993 } elseif (($eval->e($lowerBound) !== false) && ($eval->e($upperBound) !== false)) {
994 if (($eval->e($a_entered) >= $eval->e($lowerBound)) && ($eval->e($a_entered) <= $eval->e($upperBound))) {
995 $result = $max_points;
996 }
997 } elseif ($eval->e($lowerBound) !== false) {
998 if (($eval->e($a_entered) >= $eval->e($lowerBound)) && ($eval->e($a_entered) <= $eval->e($a_original))) {
999 $result = $max_points;
1000 }
1001 } elseif ($eval->e($upperBound) !== false) {
1002 if (($eval->e($a_entered) >= $eval->e($a_original)) && ($eval->e($a_entered) <= $eval->e($upperBound))) {
1003 $result = $max_points;
1004 }
1005 } elseif ($eval->e($a_entered) == $eval->e($a_original)) {
1006 $result = $max_points;
1007 }
1008 return $result;
1009 }

◆ getOperators()

assClozeTest::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

Definition at line 1366 of file class.assClozeTest.php.

1366 : array
1367 {
1369 }
static getOperatorsByExpression(string $expression)

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ Here is the call graph for this function:

◆ getQuestionType()

assClozeTest::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question @access public

Reimplemented from assQuestion.

Definition at line 1147 of file class.assClozeTest.php.

1147 : string
1148 {
1149 return "assClozeTest";
1150 }

◆ getRTETextWithMediaObjects()

assClozeTest::getRTETextWithMediaObjects ( )

Collects all text in the question which could contain media objects which were created with the Rich Text Editor.

Reimplemented from assQuestion.

Definition at line 1279 of file class.assClozeTest.php.

1279 : string
1280 {
1281 return parent::getRTETextWithMediaObjects() . $this->getClozeText();
1282 }

◆ getSolutionSubmit()

assClozeTest::getSolutionSubmit ( )
protected

Definition at line 1106 of file class.assClozeTest.php.

1106 : array
1107 {
1108 return $this->fetchSolutionSubmit();
1109 }

◆ getStartTag()

assClozeTest::getStartTag ( )

Returns the start tag of a cloze gap.

Returns
string The start tag of a cloze gap @access public
See also
$start_tag

Definition at line 480 of file class.assClozeTest.php.

480 : string
481 {
482 return $this->start_tag;
483 }

◆ getTextgapPoints()

assClozeTest::getTextgapPoints (   $a_original,
  $a_entered,
  $max_points 
)

Returns the points for a text gap and compares the given solution with the entered solution using the text gap rating options.

Parameters
string$a_originalThe original (correct) text
string$a_enteredThe text entered by the user
integer$max_pointsThe maximum number of points for the solution @access public

Definition at line 893 of file class.assClozeTest.php.

893 : float
894 {
895 $result = 0.0;
896 switch ($this->textgap_rating) {
898 if (strcmp(ilStr::strToLower($a_original), ilStr::strToLower($a_entered)) == 0) {
899 $result = $max_points;
900 }
901 break;
903 if (strcmp($a_original, $a_entered) == 0) {
904 $result = $max_points;
905 }
906 break;
908 $transformation = $this->refinery->string()->levenshtein()->standard($a_original, 1);
909 break;
911 $transformation = $this->refinery->string()->levenshtein()->standard($a_original, 2);
912 break;
914 $transformation = $this->refinery->string()->levenshtein()->standard($a_original, 3);
915 break;
917 $transformation = $this->refinery->string()->levenshtein()->standard($a_original, 4);
918 break;
920 $transformation = $this->refinery->string()->levenshtein()->standard($a_original, 5);
921 break;
922 }
923
924 // run answers against Levenshtein2 methods
925 if (isset($transformation) && $transformation->transform($a_entered) >= 0) {
926 $result = $max_points;
927 }
928 return $result;
929 }
static strToLower(string $a_string)
Definition: class.ilStr.php:69

References ILIAS\Repository\refinery(), ilStr\strToLower(), assClozeGap\TEXTGAP_RATING_CASEINSENSITIVE, assClozeGap\TEXTGAP_RATING_CASESENSITIVE, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN1, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN2, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN3, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN4, and assClozeGap\TEXTGAP_RATING_LEVENSHTEIN5.

+ Here is the call graph for this function:

◆ getTextgapRating()

assClozeTest::getTextgapRating ( )

Returns the rating option for text gaps.

Returns
string The rating option for text gaps
See also
$textgap_rating @access public

Definition at line 1159 of file class.assClozeTest.php.

1159 : string
1160 {
1161 return $this->textgap_rating;
1162 }
string $textgap_rating
The rating option for text gaps.

◆ getUserQuestionResult()

assClozeTest::getUserQuestionResult ( int  $active_id,
int  $pass 
)

Get the user solution for a question by active_id and the test pass.

Implements iQuestionCondition.

Definition at line 1382 of file class.assClozeTest.php.

1386 $result = new ilUserQuestionResult($this, $active_id, $pass);
1387
1388 $maxStep = $this->lookupMaxStep($active_id, $pass);
1389 if ($maxStep > 0) {
1390 $data = $this->db->queryF(
1391 "
1392 SELECT sol.value1+1 as val, sol.value2, cloze.cloze_type
1393 FROM tst_solutions sol
1394 INNER JOIN qpl_a_cloze cloze ON cloze.gap_id = value1 AND cloze.question_fi = sol.question_fi
1395 WHERE sol.active_fi = %s AND sol.pass = %s AND sol.question_fi = %s AND sol.step = %s
1396 GROUP BY sol.solution_id, sol.value1+1, sol.value2, cloze.cloze_type
1397 ",
1398 ["integer", "integer", "integer","integer"],
1399 [$active_id, $pass, $this->getId(), $maxStep]
1400 );
1401 } else {
1402 $data = $this->db->queryF(
1403 "
1404 SELECT sol.value1+1 as val, sol.value2, cloze.cloze_type
1405 FROM tst_solutions sol
1406 INNER JOIN qpl_a_cloze cloze ON cloze.gap_id = value1 AND cloze.question_fi = sol.question_fi
1407 WHERE sol.active_fi = %s AND sol.pass = %s AND sol.question_fi = %s
1408 GROUP BY sol.solution_id, sol.value1+1, sol.value2, cloze.cloze_type
1409 ",
1410 ["integer", "integer", "integer"],
1411 [$active_id, $pass, $this->getId()]
1412 );
1413 }
1414
1415 while ($row = $this->db->fetchAssoc($data)) {
1416 if ($row["cloze_type"] == 1) {
1417 $row["value2"]++;
1418 }
1419 $result->addKeyValue($row["val"], $row["value2"]);
1420 }
1421
1422 $points = $this->calculateReachedPoints($active_id, $pass);
1423 $max_points = $this->getMaximumPoints();
1424
1425 $result->setReachedPercentage(($points / $max_points) * 100);
1426
1427 return $result;
1428 }
calculateReachedPoints(int $active_id, ?int $pass=null, bool $authorized_solution=true)
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
lookupMaxStep(int $active_id, int $pass)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getUserResultDetails()

assClozeTest::getUserResultDetails ( int  $active_id,
?int  $pass = null,
bool  $authorized_solution = true 
)

Definition at line 1025 of file class.assClozeTest.php.

1029 : array {
1030 $user_result = $this->fetchUserResult($active_id, $pass, $authorized_solution);
1031 $detailed = [];
1032 $this->calculateReachedPointsForSolution($user_result, $detailed);
1033 return $detailed;
1034 }

◆ isAddableAnswerOptionValue()

assClozeTest::isAddableAnswerOptionValue ( int  $qIndex,
string  $answerOptionValue 
)

Reimplemented from assQuestion.

Definition at line 1645 of file class.assClozeTest.php.

1645 : bool
1646 {
1647 $gap = $this->getGap($qIndex);
1648
1649 if ($gap->getType() != assClozeGap::TYPE_TEXT) {
1650 return false;
1651 }
1652
1653 foreach ($gap->getItems($this->randomGroup->dontShuffle()) as $item) {
1654 if ($item->getAnswertext() === $answerOptionValue) {
1655 return false;
1656 }
1657 }
1658
1659 return true;
1660 }

References assClozeGap\getItems(), assClozeGap\getType(), and assClozeGap\TYPE_TEXT.

+ Here is the call graph for this function:

◆ isComplete()

assClozeTest::isComplete ( )

Returns TRUE, if a cloze test is complete for use.

Returns
boolean TRUE, if the cloze test is complete for use, otherwise FALSE

Reimplemented from assQuestion.

Definition at line 103 of file class.assClozeTest.php.

103 : bool
104 {
105 if ($this->getTitle() !== ''
106 && $this->getAuthor()
107 && $this->getClozeText()
108 && count($this->getGaps())
109 && $this->getMaximumPoints() > 0) {
110 return true;
111 }
112 return false;
113 }

References assQuestion\getAuthor(), getClozeText(), getGaps(), getMaximumPoints(), and assQuestion\getTitle().

+ Here is the call graph for this function:

◆ isValidNumericSubmitValue()

assClozeTest::isValidNumericSubmitValue (   $submittedValue)
protected

Definition at line 1060 of file class.assClozeTest.php.

1060 : bool
1061 {
1062 if (is_numeric($submittedValue)) {
1063 return true;
1064 }
1065
1066 if (preg_match('/^[-+]{0,1}\d+\/\d+$/', $submittedValue)) {
1067 return true;
1068 }
1069
1070 return false;
1071 }

◆ lmMigrateQuestionTypeSpecificContent()

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

Reimplemented from assQuestion.

Definition at line 1306 of file class.assClozeTest.php.

1306 : void
1307 {
1308 // DO NOT USE SETTER FOR CLOZE TEXT -> SETTER DOES RECREATE GAP OBJECTS without having gap type info ^^
1309 //$this->setClozeText( $migrator->migrateToLmContent($this->getClozeText()) );
1310 $this->cloze_text = $migrator->migrateToLmContent($this->getClozeText());
1311 // DO NOT USE SETTER FOR CLOZE TEXT -> SETTER DOES RECREATE GAP OBJECTS without having gap type info ^^
1312 }

References ilAssSelfAssessmentMigrator\migrateToLmContent().

+ Here is the call graph for this function:

◆ loadFromDb()

assClozeTest::loadFromDb ( int  $question_id)

Reimplemented from assQuestion.

Definition at line 150 of file class.assClozeTest.php.

150 : void
151 {
152 $result = $this->db->queryF(
153 "SELECT qpl_questions.*, " . $this->getAdditionalTableName() . ".* FROM qpl_questions LEFT JOIN " . $this->getAdditionalTableName() . " ON " . $this->getAdditionalTableName() . ".question_fi = qpl_questions.question_id WHERE qpl_questions.question_id = %s",
154 ["integer"],
155 [$question_id]
156 );
157 if ($result->numRows() == 1) {
158 $data = $this->db->fetchAssoc($result);
159 $this->setId($question_id);
160 $this->setNrOfTries($data['nr_of_tries']);
161 $this->setObjId($data["obj_fi"]);
162 $this->setTitle((string) $data["title"]);
163 $this->setComment((string) $data["description"]);
164 $this->setOriginalId($data["original_id"]);
165 $this->setAuthor($data["author"]);
166 $this->setPoints($data["points"]);
167 $this->setOwner($data["owner"]);
168 $this->setQuestion($this->cleanQuestiontext($data["question_text"]));
169 $this->setClozeText($data['cloze_text'] ?? '');
170 $this->setFixedTextLength($data["fixed_textlen"]);
171 $this->setIdenticalScoring(($data['tstamp'] === 0) ? true : (bool) $data['identical_scoring']);
172 $this->setFeedbackMode($data['feedback_mode'] === null ? ilAssClozeTestFeedback::FB_MODE_GAP_QUESTION : $data['feedback_mode']);
173
174 try {
175 $this->setLifecycle(new ilAssQuestionLifecycle($data['lifecycle']));
178 }
179
180 $this->question = ilRTE::_replaceMediaObjectImageSrc($this->question, 1);
181 $this->cloze_text = ilRTE::_replaceMediaObjectImageSrc($this->cloze_text, 1);
182 $this->setTextgapRating($data["textgap_rating"]);
183
184 try {
185 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
187 }
188
189 $result = $this->db->queryF(
190 "SELECT * FROM qpl_a_cloze WHERE question_fi = %s ORDER BY gap_id, aorder ASC",
191 ["integer"],
192 [$question_id]
193 );
194 if ($result->numRows() > 0) {
195 $this->gaps = [];
196 while ($data = $this->db->fetchAssoc($result)) {
197 switch ($data["cloze_type"]) {
199 if (!array_key_exists($data["gap_id"], $this->gaps)) {
200 $this->gaps[$data["gap_id"]] = new assClozeGap(assClozeGap::TYPE_TEXT);
201 }
202 $answer = new assAnswerCloze(
203 $data["answertext"],
204 $data["points"],
205 $data["aorder"]
206 );
207 $this->gaps[$data["gap_id"]]->setGapSize((int) $data['gap_size']);
208
209 $this->gaps[$data["gap_id"]]->addItem($answer);
210 break;
212 if (!array_key_exists($data["gap_id"], $this->gaps)) {
213 $this->gaps[$data["gap_id"]] = new assClozeGap(assClozeGap::TYPE_SELECT);
214 $this->gaps[$data["gap_id"]]->setShuffle($data["shuffle"]);
215 }
216 $answer = new assAnswerCloze(
217 $data["answertext"],
218 $data["points"],
219 $data["aorder"]
220 );
221 $this->gaps[$data["gap_id"]]->addItem($answer);
222 break;
224 if (!array_key_exists($data["gap_id"], $this->gaps)) {
225 $this->gaps[$data["gap_id"]] = new assClozeGap(assClozeGap::TYPE_NUMERIC);
226 }
227 $answer = new assAnswerCloze(
228 $data["answertext"],
229 $data["points"],
230 $data["aorder"]
231 );
232 $this->gaps[$data["gap_id"]]->setGapSize((int) $data['gap_size']);
233 $answer->setLowerBound($data["lowerlimit"]);
234 $answer->setUpperBound($data["upperlimit"]);
235 $this->gaps[$data["gap_id"]]->addItem($answer);
236 break;
237 }
238 }
239 }
240 }
241 $check_for_gap_combinations = (new assClozeGapCombination($this->db))->loadFromDb($question_id);
242 if (count($check_for_gap_combinations) != 0) {
243 $this->setGapCombinationsExists(true);
244 $this->setGapCombinations($check_for_gap_combinations);
245 }
246 parent::loadFromDb($question_id);
247 }
setIdenticalScoring(bool $identical_scoring)
Sets the identical scoring option for cloze questions.
setFeedbackMode($feedbackMode)
setFixedTextLength(?int $fixed_text_length)
Sets a fixed text length for all text fields in the cloze question.
setTextgapRating($a_textgap_rating)
Sets the rating option for text gaps.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setClozeText(string $cloze_text='')
setGapCombinationsExists($value)
cleanQuestiontext($text)
Cleans cloze question text to remove attributes or tags from older ILIAS versions.
loadFromDb(int $question_id)
setOriginalId(?int $original_id)
setId(int $id=-1)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setAuthor(string $author="")
setComment(string $comment="")
setObjId(int $obj_id=0)
setOwner(int $owner=-1)
setNrOfTries(int $a_nr_of_tries)
setLifecycle(ilAssQuestionLifecycle $lifecycle)
setTitle(string $title="")
setPoints(float $points)
const FB_MODE_GAP_QUESTION
constants for different feedback modes (per gap or per gap-answers/options)
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...

References $data, Vendor\Package\$e, ilRTE\_replaceMediaObjectImageSrc(), ilAssClozeTestFeedback\FB_MODE_GAP_QUESTION, assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

+ Here is the call graph for this function:

◆ replaceFirstGap()

assClozeTest::replaceFirstGap ( string  $gaptext,
string  $content 
)

Definition at line 137 of file class.assClozeTest.php.

140 : string {
141 $output = preg_replace(
142 '/\[gap\].*?\[\/gap\]/',
143 str_replace('$', 'GAPMASKEDDOLLAR', $content),
144 $gaptext,
145 1
146 );
147 return str_replace('GAPMASKEDDOLLAR', '$', $output);
148 }

◆ saveAdditionalQuestionDataToDb()

assClozeTest::saveAdditionalQuestionDataToDb ( )

Saves a record to the question types additional data table.

Returns
mixed

Implements ilObjQuestionScoringAdjustable.

Definition at line 271 of file class.assClozeTest.php.

271 : void
272 {
273 $this->db->manipulateF(
274 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
275 [ "integer" ],
276 [ $this->getId() ]
277 );
278
279 $this->db->insert($this->getAdditionalTableName(), [
280 'question_fi' => ['integer', $this->getId()],
281 'textgap_rating' => ['text', $this->getTextgapRating()],
282 'identical_scoring' => ['text', $this->getIdenticalScoring()],
283 'fixed_textlen' => ['integer', $this->getFixedTextLength() ? $this->getFixedTextLength() : null],
284 'cloze_text' => ['text', ilRTE::_replaceMediaObjectImageSrc($this->getClozeText(), 0)],
285 'feedback_mode' => ['text', $this->getFeedbackMode()]
286 ]);
287 }
getFixedTextLength()
Gets the fixed text length for all text fields in the cloze question.
getTextgapRating()
Returns the rating option for text gaps.

References ilRTE\_replaceMediaObjectImageSrc(), and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ saveAnswerSpecificDataToDb()

assClozeTest::saveAnswerSpecificDataToDb ( )

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

Returns
mixed

Implements ilObjAnswerScoringAdjustable.

Definition at line 258 of file class.assClozeTest.php.

258 : void
259 {
260 $this->db->manipulateF(
261 "DELETE FROM qpl_a_cloze WHERE question_fi = %s",
262 [ "integer" ],
263 [ $this->getId() ]
264 );
265
266 foreach ($this->gaps as $key => $gap) {
267 $this->saveClozeGapItemsToDb($gap, $key);
268 }
269 }
saveClozeGapItemsToDb(assClozeGap $gap, int $key)

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ saveClozeGapItemsToDb()

assClozeTest::saveClozeGapItemsToDb ( assClozeGap  $gap,
int  $key 
)
protected

Definition at line 288 of file class.assClozeTest.php.

291 : void {
292 foreach ($gap->getItems($this->getShuffler()) as $item) {
293 $next_id = $this->db->nextId('qpl_a_cloze');
294 switch ($gap->getType()) {
296 $this->saveClozeTextGapRecordToDb($next_id, $key, $item, $gap);
297 break;
299 $this->saveClozeSelectGapRecordToDb($next_id, $key, $item, $gap);
300 break;
302 $this->saveClozeNumericGapRecordToDb($next_id, $key, $item, $gap);
303 break;
304 }
305 }
306 }
getItems(Transformation $shuffler, ?int $gap_index=null)
saveClozeSelectGapRecordToDb(int $next_id, int $key, assAnswerCloze $item, assClozeGap $gap)
saveClozeTextGapRecordToDb(int $next_id, int $key, assAnswerCloze $item, assClozeGap $gap)
saveClozeNumericGapRecordToDb(int $next_id, int $key, assAnswerCloze $item, assClozeGap $gap)

References assClozeGap\getType(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

+ Here is the call graph for this function:

◆ saveClozeNumericGapRecordToDb()

assClozeTest::saveClozeNumericGapRecordToDb ( int  $next_id,
int  $key,
assAnswerCloze  $item,
assClozeGap  $gap 
)
protected

Definition at line 370 of file class.assClozeTest.php.

375 : void {
376 $eval = new EvalMath();
377 $eval->suppress_errors = true;
378 $this->db->manipulateF(
379 'INSERT INTO qpl_a_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, lowerlimit, upperlimit, gap_size) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
380 [
391 ],
392 [
393 $next_id,
394 $this->getId(),
395 $key,
396 $item->getAnswertext(),
397 $item->getPoints(),
398 $item->getOrder(),
399 $gap->getType(),
400 ($eval->e($item->getLowerBound()) !== false && ($item->getLowerBound() ?? '') !== '')
401 ? $item->getLowerBound()
402 : $item->getAnswertext(),
403 ($eval->e($item->getUpperBound()) !== false && ($item->getUpperBound() ?? '') !== '')
404 ? $item->getUpperBound()
405 : $item->getAnswertext(),
406 $gap->getGapSize()
407 ]
408 );
409 }
getOrder()
Gets the sort/display order.
getPoints()
Gets the points.
getAnswertext()
Gets the answer text.
getLowerBound()
Returns the lower bound.
getUpperBound()
Returns the upper bound.

◆ saveClozeSelectGapRecordToDb()

assClozeTest::saveClozeSelectGapRecordToDb ( int  $next_id,
int  $key,
assAnswerCloze  $item,
assClozeGap  $gap 
)
protected

Definition at line 339 of file class.assClozeTest.php.

344 : void {
345 $this->db->manipulateF(
346 'INSERT INTO qpl_a_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, shuffle) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
347 [
356 ],
357 [
358 $next_id,
359 $this->getId(),
360 $key,
361 $item->getAnswertext(),
362 $item->getPoints(),
363 $item->getOrder(),
364 $gap->getType(),
365 $gap->getShuffle() ? '1' : '0'
366 ]
367 );
368 }
getShuffle()
Gets the shuffle state of the items.

◆ saveClozeTextGapRecordToDb()

assClozeTest::saveClozeTextGapRecordToDb ( int  $next_id,
int  $key,
assAnswerCloze  $item,
assClozeGap  $gap 
)
protected

Definition at line 308 of file class.assClozeTest.php.

313 : void {
314 $this->db->manipulateF(
315 'INSERT INTO qpl_a_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, gap_size) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
316 [
325 ],
326 [
327 $next_id,
328 $this->getId(),
329 $key,
330 $item->getAnswertext(),
331 $item->getPoints(),
332 $item->getOrder(),
333 $gap->getType(),
334 $gap->getGapSize()
335 ]
336 );
337 }

◆ saveToDb()

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

Reimplemented from assQuestion.

Definition at line 249 of file class.assClozeTest.php.

249 : void
250 {
254
255 parent::saveToDb();
256 }
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)

◆ saveWorkingData()

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

Reimplemented from assQuestion.

Definition at line 1111 of file class.assClozeTest.php.

1115 : bool {
1116 if (is_null($pass)) {
1117 $pass = ilObjTest::_getPass($active_id);
1118 }
1119
1120 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
1121 function () use ($active_id, $pass, $authorized) {
1122 $this->removeCurrentSolution($active_id, $pass, $authorized);
1123
1124 foreach ($this->fetchSolutionSubmit() as $key => $value) {
1125 if ($value === null || $value === '') {
1126 continue;
1127 }
1128 $gap = $this->getGap($key);
1129 if ($gap === null
1130 || $gap->getType() === assClozeGap::TYPE_SELECT && $value === -1) {
1131 continue;
1132 }
1133 $this->saveCurrentSolution($active_id, $pass, $key, $value, $authorized);
1134 }
1135 }
1136 );
1137
1138 return true;
1139 }
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:

◆ setClozeText()

assClozeTest::setClozeText ( string  $cloze_text = '')

Definition at line 421 of file class.assClozeTest.php.

421 : void
422 {
423 $this->gaps = [];
424 $this->cloze_text = $this->cleanQuestiontext($cloze_text);
426 }
createGapsFromQuestiontext()
Create gap entries by parsing the question text.

◆ setClozeTextValue()

assClozeTest::setClozeTextValue (   $cloze_text = "")

Definition at line 428 of file class.assClozeTest.php.

428 : void
429 {
430 $this->cloze_text = $cloze_text;
431 }

◆ setEndTag()

assClozeTest::setEndTag (   $end_tag = "[/gap]")

Sets the end tag of a cloze gap.

Parameters
string$end_tagThe end tag for a cloze gap @access public
See also
$end_tag

Definition at line 516 of file class.assClozeTest.php.

516 : void
517 {
518 $this->end_tag = $end_tag;
519 }

◆ setFeedbackMode()

assClozeTest::setFeedbackMode (   $feedbackMode)
Parameters
string$feedbackMode

Definition at line 532 of file class.assClozeTest.php.

532 : void
533 {
534 $this->feedbackMode = $feedbackMode;
535 }

◆ setFixedTextLength()

assClozeTest::setFixedTextLength ( ?int  $fixed_text_length)

Sets a fixed text length for all text fields in the cloze question.

Parameters
integer$a_text_lenThe text field length @access public

Definition at line 1235 of file class.assClozeTest.php.

1235 : void
1236 {
1237 $this->fixed_text_length = $fixed_text_length;
1238 }

◆ setGapAnswerLowerBound()

assClozeTest::setGapAnswerLowerBound (   $gap_index,
  $order,
  $bound 
)

Sets the lower bound of a gap with a given index and an answer with a given order.

The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters
integer$gap_indexA nonnegative index of the n-th gap
integer$orderThe order of the answer text
string$answerThe lower bound of the answer @access public
See also
$gaps

Definition at line 715 of file class.assClozeTest.php.

715 : void
716 {
717 if (array_key_exists($gap_index, $this->gaps)) {
718 $this->gaps[$gap_index]->setItemLowerBound($order, $bound);
719 }
720 }

◆ setGapAnswerPoints()

assClozeTest::setGapAnswerPoints (   $gap_index,
  $order,
  $points 
)

Sets the points of a gap with a given index and an answer with a given order.

The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters
integer$gap_indexA nonnegative index of the n-th gap
integer$orderThe order of the answer text
string$answerThe points of the answer @access public
See also
$gaps

Definition at line 665 of file class.assClozeTest.php.

665 : void
666 {
667 if (array_key_exists($gap_index, $this->gaps)) {
668 $this->gaps[$gap_index]->setItemPoints($order, $points);
669 }
670 }

◆ setGapAnswerUpperBound()

assClozeTest::setGapAnswerUpperBound (   $gap_index,
  $order,
  $bound 
)

Sets the upper bound of a gap with a given index and an answer with a given order.

The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters
integer$gap_indexA nonnegative index of the n-th gap
integer$orderThe order of the answer text
string$answerThe upper bound of the answer @access public
See also
$gaps

Definition at line 732 of file class.assClozeTest.php.

732 : void
733 {
734 if (array_key_exists($gap_index, $this->gaps)) {
735 $this->gaps[$gap_index]->setItemUpperBound($order, $bound);
736 }
737 }

◆ setGapCombinations()

assClozeTest::setGapCombinations (   $value)

Definition at line 1298 of file class.assClozeTest.php.

1298 : void
1299 {
1300 $this->gap_combinations = $value;
1301 }

◆ setGapCombinationsExists()

assClozeTest::setGapCombinationsExists (   $value)

Definition at line 1293 of file class.assClozeTest.php.

1293 : void
1294 {
1295 $this->gap_combinations_exist = $value;
1296 }

◆ setGapShuffle()

assClozeTest::setGapShuffle (   $gap_index = 0,
  $shuffle = 1 
)

Sets the shuffle state of a gap with a given index.

The index of the first gap is 0, the index of the second gap is 1 and so on.

Parameters
integer$indexA nonnegative index of the n-th gap
integer$shuffleTurn shuffle on (=1) or off (=0) @access public
See also
$gaps

Definition at line 583 of file class.assClozeTest.php.

583 : void
584 {
585 if (array_key_exists($gap_index, $this->gaps)) {
586 $this->gaps[$gap_index]->setShuffle($shuffle);
587 }
588 }

◆ setGapSize()

assClozeTest::setGapSize (   $gap_index,
  $size 
)

Definition at line 648 of file class.assClozeTest.php.

648 : void
649 {
650 if (array_key_exists($gap_index, $this->gaps)) {
651 $this->gaps[$gap_index]->setGapSize((int) $size);
652 }
653 }

◆ setGapType()

assClozeTest::setGapType (   $gap_index,
  $gap_type 
)

Set the type of a gap with a given index.

@access private

Definition at line 567 of file class.assClozeTest.php.

567 : void
568 {
569 if (array_key_exists($gap_index, $this->gaps)) {
570 $this->gaps[$gap_index]->setType($gap_type);
571 }
572 }

◆ setIdenticalScoring()

assClozeTest::setIdenticalScoring ( bool  $identical_scoring)

Sets the identical scoring option for cloze questions.

Parameters
boolean$a_identical_scoringThe identical scoring option for cloze questions
See also
$identical_scoring @access public

Definition at line 1208 of file class.assClozeTest.php.

1208 : void
1209 {
1210 $this->identical_scoring = $identical_scoring;
1211 }

◆ setStartTag()

assClozeTest::setStartTag (   $start_tag = "[gap]")

Sets the start tag of a cloze gap.

Parameters
string$start_tagThe start tag for a cloze gap @access public
See also
$start_tag

Definition at line 492 of file class.assClozeTest.php.

492 : void
493 {
494 $this->start_tag = $start_tag;
495 }

◆ setTextgapRating()

assClozeTest::setTextgapRating (   $a_textgap_rating)

Sets the rating option for text gaps.

Parameters
string$a_textgap_ratingThe rating option for text gaps
See also
$textgap_rating @access public

Definition at line 1171 of file class.assClozeTest.php.

1171 : void
1172 {
1173 switch ($a_textgap_rating) {
1181 $this->textgap_rating = $a_textgap_rating;
1182 break;
1183 default:
1184 $this->textgap_rating = assClozeGap::TEXTGAP_RATING_CASEINSENSITIVE;
1185 break;
1186 }
1187 }

References assClozeGap\TEXTGAP_RATING_CASEINSENSITIVE, assClozeGap\TEXTGAP_RATING_CASESENSITIVE, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN1, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN2, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN3, assClozeGap\TEXTGAP_RATING_LEVENSHTEIN4, and assClozeGap\TEXTGAP_RATING_LEVENSHTEIN5.

◆ solutionValuesToLog()

assClozeTest::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 1716 of file class.assClozeTest.php.

1719 : array {
1720 $parsed_solution = [];
1721 foreach ($this->getGaps() as $gap_index => $gap) {
1722 foreach ($solution_values as $solutionvalue) {
1723 if ($gap_index !== (int) $solutionvalue['value1']) {
1724 continue;
1725 }
1726
1727 if ($gap->getType() === assClozeGap::TYPE_SELECT) {
1728 $parsed_solution[$gap_index + 1] = $gap->getItem($solutionvalue['value2'])->getAnswertext();
1729 continue;
1730 }
1731
1732 $parsed_solution[$gap_index + 1] = $solutionvalue['value2'];
1733 }
1734 }
1735 return $parsed_solution;
1736 }

References assClozeGap\getItem(), assClozeGap\getType(), and assClozeGap\TYPE_SELECT.

+ Here is the call graph for this function:

◆ solutionValuesToText()

assClozeTest::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 1738 of file class.assClozeTest.php.

1738 : array
1739 {
1740 $parsed_solution = [];
1741 foreach ($this->getGaps() as $gap_index => $gap) {
1742 foreach ($solution_values as $solutionvalue) {
1743 if ($gap_index !== (int) $solutionvalue['value1']) {
1744 continue;
1745 }
1746
1747 if ($gap->getType() === assClozeGap::TYPE_SELECT) {
1748 $parsed_solution[] = $this->lng->txt('gap') . ' ' . $gap_index + 1 . ': '
1749 . $gap->getItem($solutionvalue['value2'])->getAnswertext();
1750 continue;
1751 }
1752
1753 $parsed_solution[] = $this->lng->txt('gap') . ' ' . $gap_index + 1 . ': '
1754 . $solutionvalue['value2'];
1755 }
1756 }
1757 return $parsed_solution;
1758 }

References assClozeGap\getItem(), assClozeGap\getType(), ILIAS\Repository\lng(), and assClozeGap\TYPE_SELECT.

+ Here is the call graph for this function:

◆ toJSON()

assClozeTest::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

Definition at line 1317 of file class.assClozeTest.php.

1317 : string
1318 {
1319 $result = [
1320 'id' => $this->getId(),
1321 'type' => (string) $this->getQuestionType(),
1322 'title' => $this->getTitleForHTMLOutput(),
1323 'question' => $this->formatSAQuestion($this->getQuestion()),
1324 'clozetext' => $this->formatSAQuestion($this->getClozeText()),
1325 'nr_of_tries' => $this->getNrOfTries(),
1326 'shuffle' => $this->getShuffle(),
1327 'feedback' => [
1328 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1329 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1330 ]
1331 ];
1332
1333 $gaps = [];
1334 foreach ($this->getGaps() as $key => $gap) {
1335 $items = [];
1336 foreach ($gap->getItems($this->getShuffler()) as $item) {
1337 $jitem = [];
1338 $jitem['points'] = $item->getPoints();
1339 $jitem['value'] = $this->formatSAQuestion($item->getAnswertext());
1340 $jitem['order'] = $item->getOrder();
1341 if ($gap->getType() == assClozeGap::TYPE_NUMERIC) {
1342 $jitem['lowerbound'] = $item->getLowerBound();
1343 $jitem['upperbound'] = $item->getUpperBound();
1344 } else {
1345 $jitem['value'] = trim($jitem['value']);
1346 }
1347 array_push($items, $jitem);
1348 }
1349
1350 if ($gap->getGapSize() && ($gap->getType() == assClozeGap::TYPE_TEXT || $gap->getType() == assClozeGap::TYPE_NUMERIC)) {
1351 $jgap['size'] = $gap->getGapSize();
1352 }
1353
1354 $jgap['shuffle'] = $gap->getShuffle();
1355 $jgap['type'] = $gap->getType();
1356 $jgap['item'] = $items;
1357
1358 array_push($gaps, $jgap);
1359 }
1360 $result['gaps'] = $gaps;
1361 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1362 $result['mobs'] = $mobs;
1363 return json_encode($result);
1364 }
getQuestionType()
Returns the question type of the question.
static _getMobsOfObject(string $a_type, int $a_id, int|false $a_usage_hist_nr=0, string $a_lang="-")

References ilObjMediaObject\_getMobsOfObject(), assClozeGap\getGapSize(), ILIAS\Survey\Mode\getId(), assClozeGap\getItems(), assClozeGap\getShuffle(), assClozeGap\getType(), assClozeGap\TYPE_NUMERIC, and assClozeGap\TYPE_TEXT.

+ Here is the call graph for this function:

◆ toLog()

assClozeTest::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 1672 of file class.assClozeTest.php.

1672 : array
1673 {
1674 $result = [
1675 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->getQuestionType(),
1676 AdditionalInformationGenerator::KEY_QUESTION_TITLE => $this->getTitleForHTMLOutput(),
1677 AdditionalInformationGenerator::KEY_QUESTION_TEXT => $this->formatSAQuestion($this->getQuestion()),
1678 AdditionalInformationGenerator::KEY_QUESTION_CLOZE_CLOZETEXT => $this->formatSAQuestion($this->getClozeText()),
1679 AdditionalInformationGenerator::KEY_QUESTION_SHUFFLE_ANSWER_OPTIONS => $additional_info
1681 AdditionalInformationGenerator::KEY_FEEDBACK => [
1682 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1683 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1684 ]
1685 ];
1686
1687 $gaps = [];
1688 foreach ($this->getGaps() as $gap_index => $gap) {
1689 $items = [];
1690 foreach ($gap->getItems($this->getShuffler()) as $item) {
1691 $item_array = [
1692 AdditionalInformationGenerator::KEY_QUESTION_REACHABLE_POINTS => $item->getPoints(),
1693 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION => $this->formatSAQuestion($item->getAnswertext()),
1694 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_ORDER => $item->getOrder()
1695 ];
1696 if ($gap->getType() === assClozeGap::TYPE_NUMERIC) {
1697 $item_array[AdditionalInformationGenerator::KEY_QUESTION_LOWER_LIMIT] = $item->getLowerBound();
1698 $item_array[AdditionalInformationGenerator::KEY_QUESTION_UPPER_LIMIT] = $item->getUpperBound();
1699 }
1700 array_push($items, $item_array);
1701 }
1702
1703 $gap_array[AdditionalInformationGenerator::KEY_QUESTION_TEXTSIZE] = $gap->getGapSize();
1704 $gap_array[AdditionalInformationGenerator::KEY_QUESTION_SHUFFLE_ANSWER_OPTIONS] = $additional_info->getTrueFalseTagForBool(
1705 $gap->getShuffle()
1706 );
1707 $gap_array[AdditionalInformationGenerator::KEY_QUESTION_CLOZE_GAP_TYPE] = $gap->getType();
1708 $gap_array[AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTIONS] = $items;
1709
1710 $gaps[$gap_index + 1] = $gap_array;
1711 }
1712 $result[AdditionalInformationGenerator::KEY_QUESTION_CLOZE_GAPS] = $gaps;
1713 return $result;
1714 }

References assClozeGap\getGapSize(), assClozeGap\getItems(), assClozeGap\getShuffle(), ILIAS\Test\Logging\AdditionalInformationGenerator\getTrueFalseTagForBool(), assClozeGap\getType(), and assClozeGap\TYPE_NUMERIC.

+ Here is the call graph for this function:

◆ toNormalized()

assClozeTest::toNormalized ( Transformations  $transformations,
array  $context = [] 
)
Parameters
array<string,mixed>$context
Returns
array<array-key, mixed>|float|bool|int|string|null

Reimplemented from assQuestion.

Definition at line 1775 of file class.assClozeTest.php.

1778 : array|float|bool|int|string|null
1779 {
1780 return [
1781 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
1782 'feedback_mode' => $this->feedbackMode,
1783 'cloze_text' => $this->cloze_text,
1784 'textgap_rating' => $this->textgap_rating,
1785 'identical_scoring' => $this->identical_scoring,
1786 'fixed_text_length' => $this->fixed_text_length,
1787 'gaps' => $transformations->normalize($this->gaps),
1788 'gap_combinations' => $this->gap_combinations,
1789 'gap_combinations_exist' => $this->gap_combinations_exist,
1790 ];
1791 }

References ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\normalize().

+ Here is the call graph for this function:

◆ updateClozeTextFromGaps()

assClozeTest::updateClozeTextFromGaps ( )

Updates the gap parameters in the cloze text from the form input.

@access private

Definition at line 811 of file class.assClozeTest.php.

811 : void
812 {
813 $output = $this->getClozeText();
814 foreach ($this->getGaps() as $gap_index => $gap) {
815 $answers = [];
816 foreach ($gap->getItemsRaw() as $item) {
817 array_push($answers, str_replace([',', '['], ["\\,", '[&hairsp;'], $item->getAnswerText()));
818 }
819 // fau: fixGapReplace - use replace function
820 $output = $this->replaceFirstGap($output, "[_gap]" . ilLegacyFormElementsUtil::prepareTextareaOutput(join(",", $answers), true) . "[/_gap]");
821 // fau.
822 }
823 $output = str_replace("_gap]", "gap]", $output);
824 $this->cloze_text = $output;
825 }

References assClozeGap\getItemsRaw(), and ilLegacyFormElementsUtil\prepareTextareaOutput().

+ Here is the call graph for this function:

Field Documentation

◆ $cloze_text

string assClozeTest::$cloze_text = ''
protected

Definition at line 80 of file class.assClozeTest.php.

◆ $end_tag

string assClozeTest::$end_tag = '[/gap]'
private

Definition at line 59 of file class.assClozeTest.php.

◆ $feedbackMode

assClozeTest::$feedbackMode = ilAssClozeTestFeedback::FB_MODE_GAP_QUESTION
protected

Definition at line 82 of file class.assClozeTest.php.

◆ $feedbackOBJ

ilAssQuestionFeedback assClozeTest::$feedbackOBJ

Definition at line 81 of file class.assClozeTest.php.

◆ $fixed_text_length

int assClozeTest::$fixed_text_length = null
protected

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

◆ $gap_combinations

assClozeTest::$gap_combinations = []
protected

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

◆ $gap_combinations_exist

bool assClozeTest::$gap_combinations_exist = false
protected

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

◆ $gaps

array assClozeTest::$gaps = []

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

◆ $identical_scoring

bool assClozeTest::$identical_scoring = true
protected

Defines the scoring for "identical solutions".

If the learner selects the same solution twice or more in different gaps, only the first choice will be scored if identical_scoring is 0.

Definition at line 78 of file class.assClozeTest.php.

◆ $randomGroup

RandomGroup assClozeTest::$randomGroup
private

Definition at line 83 of file class.assClozeTest.php.

◆ $start_tag

string assClozeTest::$start_tag = '[gap]'
private

Definition at line 58 of file class.assClozeTest.php.

◆ $textgap_rating

string assClozeTest::$textgap_rating = assClozeGap::TEXTGAP_RATING_CASEINSENSITIVE

The rating option for text gaps.

This could contain one of the following options:

  • case insensitive text gaps
  • case sensitive text gaps
  • various levenshtein distances

Definition at line 69 of file class.assClozeTest.php.


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