ILIAS  trunk Revision v5.2.0beta1-34132-g2d4d73d4a0
assClozeTest Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 __construct ( $title="", $comment="", $author="", $owner=-1, $question="")
 assClozeTest constructor More...
 
 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 ($gaptext, $content)
 Replace the first gap in a string without treating backreferences. More...
 
 loadFromDb ($question_id)
 Loads a assClozeTest object from a database. More...
 
 saveToDb ($original_id="")
 Saves a assClozeTest object to a database. More...
 
 saveAnswerSpecificDataToDb ()
 Save all gaps to the database. More...
 
 saveAdditionalQuestionDataToDb ()
 Saves the data for the additional data table. More...
 
 getGaps ()
 Returns the array of gaps. More...
 
 flushGaps ()
 Deletes all gaps without changing the cloze text. More...
 
 setClozeText ($cloze_text="")
 Evaluates the text gap solutions from the cloze text. More...
 
 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 ($gap_index=0)
 Returns the gap at a given index. More...
 
 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...
 
 duplicate (bool $for_test=true, string $title="", string $author="", int $owner=-1, $testObjId=null)
 Duplicates an assClozeTest. More...
 
 copyObject ($target_questionpool_id, $title="")
 Copies an assClozeTest object. More...
 
 createNewOriginalFromThisDuplicate ($targetParentId, $targetQuestionTitle="")
 
 copyGapCombination ($orgID, $newID)
 
 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...
 
 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 ($value)
 
 calculateReachedPoints ($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
 Returns the points, a learner has reached answering the question. More...
 
 validateSolutionSubmit ()
 
 fetchSolutionSubmit ($submit)
 
 getSolutionSubmitValidation ()
 
 getSolutionSubmit ()
 
 saveWorkingData ($active_id, $pass=null, $authorized=true)
 Saves the learners input of the question to the database. More...
 
 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 ($a_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 ($a_text_len)
 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)
 
 setExportDetailsXLSX (ilAssExcelFormatHelper $worksheet, int $startrow, int $col, int $active_id, int $pass)
 {} More...
 
 toJSON ()
 Returns a JSON representation of the question. More...
 
 getOperators ($expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. 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)
 
- Public Member Functions inherited from assQuestion
 __construct (string $title="", string $comment="", string $author="", int $owner=-1, string $question="")
 assQuestion constructor More...
 
 getShuffler ()
 
 setShuffler (Transformation $shuffler)
 
 setProcessLocker (ilAssQuestionProcessLocker $processLocker)
 
 getProcessLocker ()
 
 fromXML ($item, int $questionpool_id, ?int $tst_id, &$tst_object, int &$question_counter, array $import_mapping, array &$solutionhints=[])
 Receives parameters from a QTI parser and creates a valid ILIAS question object. More...
 
 toXML (bool $a_include_header=true, bool $a_include_binary=true, bool $a_shuffle=false, bool $test_output=false, bool $force_image_references=false)
 Returns a QTI xml representation of the question. More...
 
 isComplete ()
 Returns true, if a question is complete for use. More...
 
 setTitle (string $title="")
 
 setId (int $id=-1)
 
 setTestId (int $id=-1)
 
 setComment (string $comment="")
 
 setShuffle (?bool $shuffle=true)
 
 setAuthor (string $author="")
 
 setOwner (int $owner=-1)
 
 getTitle ()
 
 getTitleForHTMLOutput ()
 
 getTitleFilenameCompliant ()
 
 getId ()
 
 getShuffle ()
 
 getTestId ()
 
 getComment ()
 
 getDescriptionForHTMLOutput ()
 
 getThumbSize ()
 
 setThumbSize (int $a_size)
 
 getMinimumThumbSize ()
 
 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 $authorizedSolution=true)
 returns the reached points ... More...
 
 calculateResultsFromSolution (int $active_id, int $pass, bool $obligationsEnabled=false)
 Calculates the question results from a previously saved question solution. More...
 
 persistWorkingState (int $active_id, $pass, bool $obligationsEnabled=false, bool $authorized=true)
 persists the working state for current testactive and testpass More...
 
 persistPreviewState (ilAssQuestionPreviewSession $previewSession)
 persists the preview state for current user and question More...
 
 validateSolutionSubmit ()
 
 saveWorkingData (int $active_id, int $pass, bool $authorized=true)
 Saves the learners input of the question to the database. More...
 
 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, $pass=null)
 
 getSolutionValues ($active_id, $pass=null, bool $authorized=true)
 Loads solutions of a given user from the database an returns it. More...
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 deleteAnswers (int $question_id)
 
 deleteAdditionalTableData (int $question_id)
 
 delete (int $question_id)
 
 getTotalAnswers ()
 
 copyXHTMLMediaObjectsOfQuestion (int $a_q_id)
 
 syncXHTMLMediaObjectsOfQuestion ()
 
 createPageObject ()
 
 copyPageOfQuestion (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=-1)
 
 saveToDb ()
 
 deleteSuggestedSolutions ()
 
 getSuggestedSolution (int $subquestion_index=0)
 
 resolveInternalLink (string $internal_link)
 
 _resolveIntLinks (int $question_id)
 
 syncWithOriginal ()
 
 getPoints ()
 
 setPoints (float $points)
 
 getSolutionMaxPass (int $active_id)
 
 calculateReachedPoints ($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
 Returns the points, a learner has reached answering the question. More...
 
 deductHintPointsFromReachedPoints (ilAssQuestionPreviewSession $previewSession, $reachedPoints)
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $previewSession)
 
 isPreviewSolutionCorrect (ilAssQuestionPreviewSession $previewSession)
 
 adjustReachedPointsByScoringOptions ($points, $active_id, $pass=null)
 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="")
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 getQuestionTypeID ()
 
 syncHints ()
 
 cleanupMediaObjectUsage ()
 
 getInstances ()
 
 getActiveUserData (int $active_id)
 Returns the user id and the test id for a given active id. More...
 
 hasSpecificFeedback ()
 
 setExportDetailsXLSX (ilAssExcelFormatHelper $worksheet, int $startrow, int $col, int $active_id, int $pass)
 
 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)
 
 ensureHintPageObjectExists ($pageObjectId)
 
 isAnswered (int $active_id, int $pass)
 
 getAdditionalContentEditingMode ()
 
 setAdditionalContentEditingMode (?string $additionalContentEditingMode)
 
 isAdditionalContentEditingModePageObject ()
 
 isValidAdditionalContentEditingMode (string $additionalContentEditingMode)
 
 getValidAdditionalContentEditingModes ()
 
 getHtmlUserSolutionPurifier ()
 
 getHtmlQuestionContentPurifier ()
 
 setLastChange ($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 ()
 
 duplicate (bool $for_test=true, string $title="", string $author="", int $owner=-1, $testObjId=null)
 
 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 $valuePairs)
 
 areObligationsToBeConsidered ()
 
 setObligationsToBeConsidered (bool $obligationsToBeConsidered)
 
 updateTimestamp ()
 
 getTestPresentationConfig ()
 
- Public Member Functions inherited from iQuestionCondition
 getUserQuestionResult ($active_id, $pass)
 Get the user solution for a question by active_id and the test pass. More...
 

Data Fields

array $gaps = []
 
 $gap_combinations
 
 $gap_combinations_exists
 
 $start_tag
 
 $end_tag
 
 $textgap_rating
 
 $identical_scoring
 
 $fixedTextLength
 
 $cloze_text
 
ilAssQuestionFeedback $feedbackOBJ
 
- Data Fields inherited from assQuestion
const TRIM_PATTERN = '/^[\p{C}\p{Z}]+|[\p{C}\p{Z}]+$/u'
 
const ADDITIONAL_CONTENT_EDITING_MODE_RTE = 'default'
 
const ADDITIONAL_CONTENT_EDITING_MODE_IPE = 'pageobject'
 
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 ($gap, $key)
 Save all items belonging to one cloze gap to the db. More...
 
 saveClozeTextGapRecordToDb ($next_id, $key, $item, $gap)
 Saves a gap-item record. More...
 
 saveClozeSelectGapRecordToDb ($next_id, $key, $item, $gap)
 Saves a gap-item record. More...
 
 saveClozeNumericGapRecordToDb ($next_id, $key, $item, $gap)
 Saves a gap-item record. More...
 
 isValidNumericSubmitValue ($submittedValue)
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 calculateReachedPointsForSolution ($user_result, &$detailed=null)
 
- Protected Member Functions inherited from assQuestion
 getQuestionAction ()
 
 isNonEmptyItemListPostSubmission (string $postSubmissionFieldname)
 
 log (int $active_id, string $langVar)
 
 savePreviewData (ilAssQuestionPreviewSession $previewSession)
 
 deletePageOfQuestion (int $question_id)
 
 onDuplicate (int $originalParentId, int $originalQuestionId, int $duplicateParentId, int $duplicateQuestionId)
 
 beforeSyncWithOriginal (int $origQuestionId, int $dupQuestionId, int $origParentObjId, int $dupParentObjId)
 
 afterSyncWithOriginal (int $origQuestionId, int $dupQuestionId, int $origParentObjId, int $dupParentObjId)
 
 onCopy (int $sourceParentId, int $sourceQuestionId, int $targetParentId, int $targetQuestionId)
 
 syncSuggestedSolutions (int $target_question_id, int $target_obj_id)
 
 duplicateSuggestedSolutionFiles (int $parent_id, int $question_id)
 Duplicates the files of a suggested solution if the question is duplicated. More...
 
 syncSuggestedSolutionFiles (int $target_question_id, int $target_obj_id)
 
 copySuggestedSolutionFiles (int $source_questionpool_id, int $source_question_id)
 
 ensureNonNegativePoints ($points)
 
 purifyAndPrepareTextAreaOutput (string $content)
 
 getRTETextWithMediaObjects ()
 
 getSelfAssessmentFormatter ()
 
 lmMigrateQuestionTypeGenericContent (ilAssSelfAssessmentMigrator $migrator)
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 duplicateQuestionHints (int $originalQuestionId, int $duplicateQuestionId)
 
 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 ()
 build basic test question configuration instance More...
 
 getSuggestedSolutionsRepo ()
 
 loadSuggestedSolutions ()
 

Protected Attributes

 $feedbackMode = ilAssClozeTestFeedback::FB_MODE_GAP_QUESTION
 
- Protected Attributes inherited from assQuestion
const HAS_SPECIFIC_FEEDBACK = true
 
const DEFAULT_THUMB_SIZE = 150
 
const MINIMUM_THUMB_SIZE = 20
 
ILIAS TestQuestionPool QuestionInfoService $questioninfo
 
ILIAS Test TestParticipantInfoService $testParticipantInfo
 
ILIAS HTTP Services $http
 
ILIAS Refinery Factory $refinery
 
ILIAS TestQuestionPool QuestionFilesService $questionFilesService
 
ILIAS DI LoggingServices $ilLog
 
int $id
 
string $title
 
string $comment
 
string $owner
 
string $author
 
int $thumb_size
 
string $question
 The question text. More...
 
float $points
 The maximum available points for the question. More...
 
bool $shuffle
 Indicates whether the answers will be shuffled or not. More...
 
int $test_id
 The database id of a test in which the question is contained. More...
 
int $obj_id = 0
 Object id of the container object. More...
 
 $ilias
 
ilGlobalPageTemplate $tpl
 
ilLanguage $lng
 
ilDBInterface $db
 
Container $dic
 
array $suggested_solutions
 
int $original_id = null
 
 $page
 
string $external_id = null
 
ilAssQuestionProcessLocker $processLocker
 
 $step
 
 $lastChange
 
Transformation $shuffler
 
ilTestQuestionConfig $testQuestionConfig
 
ilAssQuestionLifecycle $lifecycle
 
ilObjUser $current_user
 
SkillUsageService $skillUsageService
 
assQuestionSuggestedSolutionsDatabaseRepository $suggestedsolution_repo = null
 

Private Attributes

RandomGroup $randomGroup
 

Additional Inherited Members

- Static Public Member Functions inherited from assQuestion
static setForcePassResultUpdateEnabled (bool $forcePassResultsUpdateEnabled)
 
static isForcePassResultUpdateEnabled ()
 
static _getSuggestedSolutionOutput (int $question_id)
 
static _getReachedPoints (int $active_id, int $question_id, int $pass)
 
static logAction (string $logtext, int $active_id, int $question_id)
 
static isFileAvailable (string $file)
 
static saveOriginalId (int $questionId, int $originalId)
 
static resetOriginalId (int $questionId)
 
static _getInternalLinkHref (string $target="")
 
static instantiateQuestion (int $question_id)
 
static _getSolutionMaxPass (int $question_id, int $active_id)
 Returns the maximum pass a users question solution. More...
 
static _isWriteable (int $question_id, int $user_id)
 
static _setReachedPoints (int $active_id, int $question_id, float $points, float $maxpoints, int $pass, bool $manualscoring, bool $obligationsEnabled)
 Sets the points, a learner has reached answering the question Additionally objective results are updated. More...
 
static _needsManualScoring (int $question_id)
 
static getFeedbackClassNameByQuestionType (string $questionType)
 
static instantiateQuestionGUI (int $a_question_id)
 
static _questionExistsInTest (int $question_id, int $test_id)
 
static lookupParentObjId (int $questionId)
 
static isObligationPossible (int $questionId)
 
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 $forcePassResultsUpdateEnabled = false
 
static $imageSourceFixReplaceMap
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 32 of file class.assClozeTest.php.

Constructor & Destructor Documentation

◆ __construct()

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

assClozeTest constructor

The constructor takes possible arguments an creates an instance of the assClozeTest object.

Parameters
string$titleA title string to describe the question
string$commentA comment string to describe the question
string$authorA string containing the name of the questions author
integer$ownerA numerical ID to identify the owner/creator
string$question

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

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

128  {
129  global $DIC;
130 
132  $this->start_tag = "[gap]";
133  $this->end_tag = "[/gap]";
134  $this->gaps = [];
135  $this->setQuestion($question); // @TODO: Should this be $question?? See setter for why this is not trivial.
136  $this->fixedTextLength = "";
137  $this->identical_scoring = 1;
138  $this->gap_combinations_exists = false;
139  $this->gap_combinations = [];
140  $this->randomGroup = $DIC->refinery()->random();
141  }
$DIC
Definition: xapitoken.php:62
string $question
The question text.
__construct(Container $dic, ilPlugin $plugin)
setQuestion(string $question="")
+ Here is the call graph for this function:

Member Function Documentation

◆ addAnswerOptionValue()

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

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

References getGap().

2009  : void
2010  {
2011  $gap = $this->getGap($qIndex); /* @var assClozeGap $gap */
2012 
2013  $item = new assAnswerCloze($answerOptionValue, $points);
2014  $item->setOrder($gap->getItemCount());
2015 
2016  $gap->addItem($item);
2017  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getGap($gap_index=0)
Returns the gap at a given index.
float $points
The maximum available points for the question.
+ 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 public
See also
$gaps

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

References assClozeGap\TYPE_NUMERIC.

764  : void
765  {
766  if (array_key_exists($gap_index, $this->gaps)) {
767  if ($this->gaps[$gap_index]->getType() == assClozeGap::TYPE_NUMERIC) {
768  // only allow notation with "." for real numbers
769  $answer = str_replace(",", ".", $answer);
770  }
771  $this->gaps[$gap_index]->addItem(new assAnswerCloze(trim($answer), 0, $order));
772  }
773  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ 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 public
See also
$gaps

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

842  : void
843  {
844  $this->gaps[$index] = $gap;
845  }

◆ 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 public
See also
$gaps

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

822  : void
823  {
824  if (array_key_exists($gap_index, $this->gaps)) {
825  $answer = new assAnswerCloze(
826  "",
827  0,
828  $this->gaps[$gap_index]->getItemCount()
829  );
830  $this->gaps[$gap_index]->addItem($answer);
831  }
832  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ calculateCombinationResult()

assClozeTest::calculateCombinationResult (   $user_result)

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

References assQuestion\$points, assQuestion\getId(), getNumericgapPoints(), getTextgapPoints(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

Referenced by calculateReachedPointsForSolution().

1789  : array
1790  {
1791  $points = 0;
1792 
1793  $assClozeGapCombinationObj = new assClozeGapCombination();
1794  $gap_used_in_combination = [];
1795  if ($assClozeGapCombinationObj->combinationExistsForQid($this->getId())) {
1796  $combinations_for_question = $assClozeGapCombinationObj->getCleanCombinationArray($this->getId());
1797  $gap_answers = [];
1798 
1799  foreach ($user_result as $user_result_build_list) {
1800  if (is_array($user_result_build_list)) {
1801  $gap_answers[$user_result_build_list['gap_id']] = $user_result_build_list['value'];
1802  }
1803  }
1804 
1805  foreach ($combinations_for_question as $combination) {
1806  foreach ($combination as $row_key => $row_answers) {
1807  $combination_fulfilled = true;
1808  $points_for_combination = $row_answers['points'];
1809  foreach ($row_answers as $gap_key => $combination_gap_answer) {
1810  if ($gap_key !== 'points') {
1811  $gap_used_in_combination[$gap_key] = $gap_key;
1812  }
1813  if ($combination_fulfilled && array_key_exists($gap_key, $gap_answers)) {
1814  switch ($combination_gap_answer['type']) {
1816  $is_text_gap_correct = $this->getTextgapPoints($gap_answers[$gap_key], $combination_gap_answer['answer'], 1);
1817  if ($is_text_gap_correct != 1) {
1818  $combination_fulfilled = false;
1819  }
1820  break;
1822  $answer = $this->gaps[$gap_key]->getItem($gap_answers[$gap_key]);
1823  $answertext = $answer->getAnswertext();
1824  if ($answertext != $combination_gap_answer['answer']) {
1825  $combination_fulfilled = false;
1826  }
1827  break;
1829  $answer = $this->gaps[$gap_key]->getItem(0);
1830  if ($combination_gap_answer['answer'] != 'out_of_bound') {
1831  $is_numeric_gap_correct = $this->getNumericgapPoints($answer->getAnswertext(), $gap_answers[$gap_key], 1, $answer->getLowerBound(), $answer->getUpperBound());
1832  if ($is_numeric_gap_correct != 1) {
1833  $combination_fulfilled = false;
1834  }
1835  } else {
1836  $wrong_is_the_new_right = $this->getNumericgapPoints($answer->getAnswertext(), $gap_answers[$gap_key], 1, $answer->getLowerBound(), $answer->getUpperBound());
1837  if ($wrong_is_the_new_right == 1) {
1838  $combination_fulfilled = false;
1839  }
1840  }
1841  break;
1842  }
1843  } else {
1844  if ($gap_key !== 'points') {
1845  $combination_fulfilled = false;
1846  }
1847  }
1848  }
1849  if ($combination_fulfilled) {
1850  $points += $points_for_combination;
1851  }
1852  }
1853  }
1854  }
1855  return [$points, $gap_used_in_combination];
1856  }
float $points
The maximum available points for the question.
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...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calculateReachedPoints()

assClozeTest::calculateReachedPoints (   $active_id,
  $pass = null,
  $authorizedSolution = true,
  $returndetails = false 
)

Returns the points, a learner has reached answering the question.

The points are calculated from the given answers.

public

Parameters
integer$active_id
integer$pass
boolean$returndetails(deprecated !!)

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

References $data, assQuestion\$db, $ilDB, calculateReachedPointsForSolution(), assQuestion\getCurrentSolutionResultSet(), and assQuestion\getSolutionMaxPass().

Referenced by getExpressionTypes().

1247  : float|array
1248  {
1249  $ilDB = $this->db;
1250 
1251  if (is_null($pass)) {
1252  $pass = $this->getSolutionMaxPass($active_id);
1253  }
1254 
1255  $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorizedSolution);
1256  $user_result = [];
1257  while ($data = $ilDB->fetchAssoc($result)) {
1258  if (strcmp($data["value2"], "") != 0) {
1259  $user_result[$data["value1"]] = [
1260  "gap_id" => $data["value1"],
1261  "value" => $data["value2"]
1262  ];
1263  }
1264  }
1265 
1266  ksort($user_result); // this is required when identical scoring for same solutions is disabled
1267 
1268  if ($returndetails) {
1269  $detailed = [];
1270  $this->calculateReachedPointsForSolution($user_result, $detailed);
1271  return $detailed;
1272  }
1273 
1274  return $this->calculateReachedPointsForSolution($user_result);
1275  }
getSolutionMaxPass(int $active_id)
ilDBInterface $db
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
calculateReachedPointsForSolution($user_result, &$detailed=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calculateReachedPointsForSolution()

assClozeTest::calculateReachedPointsForSolution (   $user_result,
$detailed = null 
)
protected
Parameters
array$user_result
array$detailed

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

References assQuestion\$points, calculateCombinationResult(), getIdenticalScoring(), getMaximumGapPoints(), getNumericgapPoints(), getTextgapPoints(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

Referenced by calculateReachedPoints(), and calculateReachedPointsFromPreviewSession().

1861  : float
1862  {
1863  if ($detailed === null) {
1864  $detailed = [];
1865  }
1866 
1867  $points = 0;
1868 
1869  $assClozeGapCombinationObj = new assClozeGapCombination();
1870  $combinations[1] = [];
1871  if ($assClozeGapCombinationObj->combinationExistsForQid($this->getId())) {
1872  $combinations = $this->calculateCombinationResult($user_result);
1873  $points = $combinations[0];
1874  }
1875  $counter = 0;
1876  $solution_values_text = []; // for identical scoring checks
1877  $solution_values_select = []; // for identical scoring checks
1878  $solution_values_numeric = []; // for identical scoring checks
1879  foreach ($user_result as $gap_id => $value) {
1880  if (is_string($value)) {
1881  $value = ["value" => $value];
1882  }
1883 
1884  if (array_key_exists($gap_id, $this->gaps) && !array_key_exists($gap_id, $combinations[1])) {
1885  switch ($this->gaps[$gap_id]->getType()) {
1887  $gappoints = 0;
1888  for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) {
1889  $answer = $this->gaps[$gap_id]->getItem($order);
1890  $gotpoints = $this->getTextgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints());
1891  if ($gotpoints > $gappoints) {
1892  $gappoints = $gotpoints;
1893  }
1894  }
1895  if (!$this->getIdenticalScoring()) {
1896  // check if the same solution text was already entered
1897  if ((in_array($value["value"], $solution_values_text)) && ($gappoints > 0)) {
1898  $gappoints = 0;
1899  }
1900  }
1901  $points += $gappoints;
1902  $detailed[$gap_id] = ["points" => $gappoints, "best" => ($this->getMaximumGapPoints($gap_id) == $gappoints) ? true : false, "positive" => ($gappoints > 0) ? true : false];
1903  array_push($solution_values_text, $value["value"]);
1904  break;
1906  $gappoints = 0;
1907  for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) {
1908  $answer = $this->gaps[$gap_id]->getItem($order);
1909  $gotpoints = $this->getNumericgapPoints($answer->getAnswertext(), $value["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
1910  if ($gotpoints > $gappoints) {
1911  $gappoints = $gotpoints;
1912  }
1913  }
1914  if (!$this->getIdenticalScoring()) {
1915  // check if the same solution value was already entered
1916  $eval = new EvalMath();
1917  $eval->suppress_errors = true;
1918  $found_value = false;
1919  foreach ($solution_values_numeric as $solval) {
1920  if ($eval->e($solval) == $eval->e($value["value"])) {
1921  $found_value = true;
1922  }
1923  }
1924  if ($found_value && ($gappoints > 0)) {
1925  $gappoints = 0;
1926  }
1927  }
1928  $points += $gappoints;
1929  $detailed[$gap_id] = ["points" => $gappoints, "best" => ($this->getMaximumGapPoints($gap_id) == $gappoints) ? true : false, "positive" => ($gappoints > 0) ? true : false];
1930  array_push($solution_values_numeric, $value["value"]);
1931  break;
1933  if ($value["value"] >= 0) {
1934  for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++) {
1935  $answer = $this->gaps[$gap_id]->getItem($order);
1936  if ($value["value"] == $answer->getOrder()) {
1937  $answerpoints = $answer->getPoints();
1938  if (!$this->getIdenticalScoring()) {
1939  // check if the same solution value was already entered
1940  if ((in_array($answer->getAnswertext(), $solution_values_select)) && ($answerpoints > 0)) {
1941  $answerpoints = 0;
1942  }
1943  }
1944  $points += $answerpoints;
1945  $detailed[$gap_id] = ["points" => $answerpoints, "best" => ($this->getMaximumGapPoints($gap_id) == $answerpoints) ? true : false, "positive" => ($answerpoints > 0) ? true : false];
1946  array_push($solution_values_select, $answer->getAnswertext());
1947  }
1948  }
1949  }
1950  break;
1951  }
1952  }
1953  }
1954 
1955  return (float)$points;
1956  }
getMaximumGapPoints($gap_index)
Returns the maximum points for a gap.
calculateCombinationResult($user_result)
float $points
The maximum available points for the question.
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...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getIdenticalScoring()
Returns the identical scoring status of the question.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calculateReachedPointsFromPreviewSession()

assClozeTest::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $preview_session)

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

References ILIAS\LTI\ToolProvider\$key, calculateReachedPointsForSolution(), assQuestion\deductHintPointsFromReachedPoints(), assQuestion\ensureNonNegativePoints(), and ilAssQuestionPreviewSession\getParticipantsSolution().

1959  {
1960  $participant_session = $preview_session->getParticipantsSolution();
1961 
1962  if (!is_array($participant_session)) {
1963  return 0;
1964  }
1965 
1966  $user_solution = [];
1967 
1968  foreach ($participant_session as $key => $val) {
1969  $user_solution[$key] = ['gap_id' => $key, 'value' => $val];
1970  }
1971 
1972  $reached_points = $this->calculateReachedPointsForSolution($user_solution);
1973  $reached_points = $this->deductHintPointsFromReachedPoints($preview_session, $reached_points);
1974 
1975  return $this->ensureNonNegativePoints($reached_points);
1976  }
ensureNonNegativePoints($points)
string $key
Consumer key/client ID value.
Definition: System.php:193
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
calculateReachedPointsForSolution($user_result, &$detailed=null)
+ Here is the call graph for this function:

◆ checkForValidFormula()

assClozeTest::checkForValidFormula (   $value)
Parameters
$value
Returns
int

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

1234  : int
1235  {
1236  return preg_match("/^-?(\\d*)(,|\\.|\\/){0,1}(\\d*)$/", $value, $matches);
1237  }

◆ 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 167 of file class.assClozeTest.php.

Referenced by loadFromDb(), and setClozeText().

167  : string
168  {
169  if ($text === null) {
170  return '';
171  }
172  // fau: fixGapReplace - mask dollars for replacement
173  $text = str_replace('$', 'GAPMASKEDDOLLAR', $text);
174  $text = preg_replace("/\[gap[^\]]*?\]/", "[gap]", $text);
175  $text = preg_replace("/<gap([^>]*?)>/", "[gap]", $text);
176  $text = str_replace("</gap>", "[/gap]", $text);
177  $text = str_replace('GAPMASKEDDOLLAR', '$', $text);
178  // fau.
179  return $text;
180  }
+ Here is the caller graph for this function:

◆ clearGapAnswers()

assClozeTest::clearGapAnswers ( )

Removes all answers from the gaps.

public

See also
$gaps

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

731  : void
732  {
733  foreach ($this->gaps as $gap_index => $gap) {
734  $this->gaps[$gap_index]->clearItems();
735  }
736  }

◆ copyGapCombination()

assClozeTest::copyGapCombination (   $orgID,
  $newID 
)

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

Referenced by copyObject(), createNewOriginalFromThisDuplicate(), and duplicate().

1058  : void
1059  {
1060  $assClozeGapCombinationObj = new assClozeGapCombination();
1061  $array = $assClozeGapCombinationObj->loadFromDb($orgID);
1062  $assClozeGapCombinationObj->importGapCombinationToDb($newID, $array);
1063  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ copyObject()

assClozeTest::copyObject (   $target_questionpool_id,
  $title = "" 
)

Copies an assClozeTest object.

public

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

References assQuestion\$original_id, assQuestion\$title, copyGapCombination(), assQuestion\getId(), and assQuestion\getObjId().

989  : int
990  {
991  if ($this->getId() <= 0) {
992  throw new RuntimeException('The question has not been saved. It cannot be duplicated');
993  }
994 
995  $thisId = $this->getId();
996  $thisObjId = $this->getObjId();
997 
998  $clone = $this;
999  $original_id = $this->questioninfo->getOriginalId($this->getId());
1000  $clone->id = -1;
1001  $clone->setObjId($target_questionpool_id);
1002  if ($title) {
1003  $clone->setTitle($title);
1004  }
1005 
1006  $clone->saveToDb();
1007 
1008  if ($this->gap_combinations_exists) {
1009  $this->copyGapCombination($original_id, $clone->getId());
1010  $clone->saveToDb();
1011  }
1012 
1013  // copy question page content
1014  $clone->copyPageOfQuestion($original_id);
1015  // copy XHTML media objects
1016  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
1017 
1018  $clone->onCopy($thisObjId, $thisId, $clone->getObjId(), $clone->getId());
1019 
1020  return $clone->getId();
1021  }
copyGapCombination($orgID, $newID)
+ Here is the call graph for this function:

◆ createGapsFromQuestiontext()

assClozeTest::createGapsFromQuestiontext ( )

Create gap entries by parsing the question text.

public

See also
$gaps

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

References ILIAS\LTI\ToolProvider\$key, getClozeText(), and assClozeGap\TYPE_TEXT.

Referenced by setClozeText().

678  : void
679  {
680  $search_pattern = "|\[gap\](.*?)\[/gap\]|i";
681  preg_match_all($search_pattern, $this->getClozeText(), $found);
682  $this->gaps = [];
683  if (count($found[0])) {
684  foreach ($found[1] as $gap_index => $answers) {
685  // create text gaps by default
687  $textparams = preg_split("/(?<!\\\\),/", $answers);
688  foreach ($textparams as $key => $value) {
689  $answer = new assAnswerCloze($value, 0, $key);
690  $gap->addItem($answer);
691  }
692  $this->gaps[$gap_index] = $gap;
693  }
694  }
695  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for cloze question gaps.
string $key
Consumer key/client ID value.
Definition: System.php:193
getClozeText()
Returns the cloze text.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createNewOriginalFromThisDuplicate()

assClozeTest::createNewOriginalFromThisDuplicate (   $targetParentId,
  $targetQuestionTitle = "" 
)

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

References assQuestion\$id, copyGapCombination(), assQuestion\getId(), and assQuestion\getObjId().

1023  : int
1024  {
1025  if ($this->getId() <= 0) {
1026  throw new RuntimeException('The question has not been saved. It cannot be duplicated');
1027  }
1028 
1029  $sourceQuestionId = $this->id;
1030  $sourceParentId = $this->getObjId();
1031 
1032  // duplicate the question in database
1033  $clone = $this;
1034  $clone->id = -1;
1035 
1036  $clone->setObjId($targetParentId);
1037 
1038  if ($targetQuestionTitle) {
1039  $clone->setTitle($targetQuestionTitle);
1040  }
1041 
1042  $clone->saveToDb();
1043 
1044  if ($this->gap_combinations_exists) {
1045  $this->copyGapCombination($sourceQuestionId, $clone->getId());
1046  $clone->saveToDb();
1047  }
1048  // copy question page content
1049  $clone->copyPageOfQuestion($sourceQuestionId);
1050  // copy XHTML media objects
1051  $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
1052 
1053  $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
1054 
1055  return $clone->id;
1056  }
copyGapCombination($orgID, $newID)
+ 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 public
See also
$gaps

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

References deleteGap(), and updateClozeTextFromGaps().

1095  : void
1096  {
1097  if (array_key_exists($gap_index, $this->gaps)) {
1098  if ($this->gaps[$gap_index]->getItemCount() == 1) {
1099  // this is the last answer text => remove the gap
1100  $this->deleteGap($gap_index);
1101  } else {
1102  // remove the answer text
1103  $this->gaps[$gap_index]->deleteItem($answer_index);
1104  $this->updateClozeTextFromGaps();
1105  }
1106  }
1107  }
deleteGap($gap_index)
Deletes a gap with a given index.
updateClozeTextFromGaps()
Updates the gap parameters in the cloze text from the form input.
+ Here is the call graph for this function:

◆ 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 public
See also
$gaps

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

References getClozeText(), getGaps(), and replaceFirstGap().

Referenced by deleteAnswerText().

1117  : void
1118  {
1119  if (array_key_exists($gap_index, $this->gaps)) {
1120  $output = $this->getClozeText();
1121  foreach ($this->getGaps() as $replace_gap_index => $gap) {
1122  $answers = [];
1123  foreach ($gap->getItemsRaw() as $item) {
1124  array_push($answers, str_replace(",", "\\,", $item->getAnswerText()));
1125  }
1126  if ($replace_gap_index == $gap_index) {
1127  // fau: fixGapReplace - use replace function
1128  $output = $this->replaceFirstGap($output, '');
1129  // fau.
1130  } else {
1131  // fau: fixGapReplace - use replace function
1132  $output = $this->replaceFirstGap($output, "[_gap]" . join(",", $answers) . "[/_gap]");
1133  // fau.
1134  }
1135  }
1136  $output = str_replace("_gap]", "gap]", $output);
1137  $this->cloze_text = $output;
1138  unset($this->gaps[$gap_index]);
1139  $this->gaps = array_values($this->gaps);
1140  }
1141  }
getGaps()
Returns the array of gaps.
replaceFirstGap($gaptext, $content)
Replace the first gap in a string without treating backreferences.
getClozeText()
Returns the cloze text.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ duplicate()

assClozeTest::duplicate ( bool  $for_test = true,
string  $title = "",
string  $author = "",
int  $owner = -1,
  $testObjId = null 
)

Duplicates an assClozeTest.

public

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

References assQuestion\$author, assQuestion\$original_id, assQuestion\$owner, assQuestion\$title, copyGapCombination(), assQuestion\getId(), and assQuestion\getObjId().

934  : int
935  {
936  if ($this->id <= 0) {
937  // The question has not been saved. It cannot be duplicated
938  return -1;
939  }
940  // duplicate the question in database
941  $this_id = $this->getId();
942  $thisObjId = $this->getObjId();
943 
944  $clone = $this;
945  $original_id = $this->questioninfo->getOriginalId($this->id);
946  $clone->id = -1;
947 
948  if ((int) $testObjId > 0) {
949  $clone->setObjId($testObjId);
950  }
951 
952  if ($title) {
953  $clone->setTitle($title);
954  }
955  if ($author) {
956  $clone->setAuthor($author);
957  }
958  if ($owner) {
959  $clone->setOwner($owner);
960  }
961  if ($for_test) {
962  $clone->saveToDb($original_id);
963  } else {
964  $clone->saveToDb();
965  }
966  if ($this->gap_combinations_exists) {
967  $this->copyGapCombination($this_id, $clone->getId());
968  }
969  if ($for_test) {
970  $clone->saveToDb($original_id);
971  } else {
972  $clone->saveToDb();
973  }
974  // copy question page content
975  $clone->copyPageOfQuestion($this_id);
976  // copy XHTML media objects
977  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
978 
979  $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
980 
981  return $clone->getId();
982  }
copyGapCombination($orgID, $newID)
+ Here is the call graph for this function:

◆ fetchAnswerValueForGap()

assClozeTest::fetchAnswerValueForGap (   $userSolution,
  $gapIndex 
)

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

1978  : string
1979  {
1980  $answerValue = '';
1981 
1982  foreach ($userSolution as $value1 => $value2) {
1983  if ($value1 == $gapIndex) {
1984  $answerValue = $value2;
1985  break;
1986  }
1987  }
1988 
1989  return $answerValue;
1990  }

◆ fetchSolutionSubmit()

assClozeTest::fetchSolutionSubmit (   $submit)

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

References getGaps(), ILIAS\Repository\int(), assClozeGap\TYPE_NUMERIC, and assClozeGap\TYPE_SELECT.

Referenced by getSolutionSubmit().

1308  : array
1309  {
1310  $solutionSubmit = [];
1311  $post_wrapper = $this->dic->http()->wrapper()->post();
1312  foreach ($this->getGaps() as $index => $gap) {
1313  if (!$post_wrapper->has("gap_$index")) {
1314  continue;
1315  }
1316  $value = trim($post_wrapper->retrieve(
1317  "gap_$index",
1318  $this->dic->refinery()->kindlyTo()->string()
1319  ));
1320  if ($value === '') {
1321  continue;
1322  }
1323 
1324  if (!(($gap->getType() === (int) assClozeGap::TYPE_SELECT) && ($value === -1))) {
1325  if (
1326  $gap->getType() === (int) assClozeGap::TYPE_NUMERIC
1327  && !is_numeric(str_replace(",", ".", $value))
1328  ) {
1329  $value = null;
1330  } elseif ($gap->getType() === (int) assClozeGap::TYPE_NUMERIC) {
1331  $value = str_replace(",", ".", $value);
1332  }
1333  $solutionSubmit[$index] = $value;
1334  }
1335  }
1336 
1337  return $solutionSubmit;
1338  }
getGaps()
Returns the array of gaps.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flushGaps()

assClozeTest::flushGaps ( )

Deletes all gaps without changing the cloze text.

See also
$gaps

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

542  : void
543  {
544  $this->gaps = [];
545  }

◆ getAdditionalTableName()

assClozeTest::getAdditionalTableName ( )

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

Returns
string The additional table name public

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

Referenced by loadFromDb(), and saveAdditionalQuestionDataToDb().

1501  : string
1502  {
1503  return "qpl_qst_cloze";
1504  }
+ Here is the caller graph for this function:

◆ getAnswerTableName()

assClozeTest::getAnswerTableName ( )

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

1506  : array
1507  {
1508  return ["qpl_a_cloze",'qpl_a_cloze_combi_res'];
1509  }

◆ 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

Implements iQuestionCondition.

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

References getGap(), and getGaps().

1781  {
1782  if ($index !== null) {
1783  return $this->getGap($index);
1784  } else {
1785  return $this->getGaps();
1786  }
1787  }
getGap($gap_index=0)
Returns the gap at a given index.
getGaps()
Returns the array of gaps.
+ Here is the call graph for this function:

◆ getClozeText()

assClozeTest::getClozeText ( )

Returns the cloze text.

Returns
string The cloze text string public
See also
$cloze_text

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

References $cloze_text.

Referenced by createGapsFromQuestiontext(), deleteGap(), getClozeTextForHTMLOutput(), getRTETextWithMediaObjects(), isComplete(), lmMigrateQuestionTypeSpecificContent(), saveAdditionalQuestionDataToDb(), toJSON(), and updateClozeTextFromGaps().

575  : string
576  {
577  return $this->cloze_text;
578  }
+ 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 588 of file class.assClozeTest.php.

References getClozeText(), assQuestion\getHtmlQuestionContentPurifier(), assQuestion\isAdditionalContentEditingModePageObject(), and ilLegacyFormElementsUtil\prepareTextareaOutput().

588  : string
589  {
590  $gaps = [];
591  preg_match_all('/\[gap\].*?\[\/gap\]/', $this->getClozeText(), $gaps);
592  $string_with_replaced_gaps = str_replace($gaps[0], '######GAP######', $this->getClozeText());
593  $cleaned_text = $this->getHtmlQuestionContentPurifier()->purify(
594  $string_with_replaced_gaps
595  );
596  $cleaned_text_with_gaps = preg_replace_callback('/######GAP######/', function ($match) use (&$gaps) {
597  return array_shift($gaps[0]);
598  }, $cleaned_text);
599 
601  || !(new ilSetting('advanced_editing'))->get('advanced_editing_javascript_editor') === 'tinymce') {
602  $cleaned_text_with_gaps = nl2br($cleaned_text_with_gaps);
603  }
604 
605  return ilLegacyFormElementsUtil::prepareTextareaOutput($cleaned_text_with_gaps, true);
606  }
isAdditionalContentEditingModePageObject()
getClozeText()
Returns the cloze text.
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...
+ 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 public
See also
$end_tag

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

References $end_tag.

639  : string
640  {
641  return $this->end_tag;
642  }

◆ getExpressionTypes()

assClozeTest::getExpressionTypes ( )

Get all available expression types for a specific question.

Returns
array

Implements iQuestionCondition.

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

References $data, $DIC, $ilDB, assQuestion\$points, calculateReachedPoints(), iQuestionCondition\EmptyAnswerExpression, assQuestion\getId(), getMaximumPoints(), iQuestionCondition\getUserQuestionResult(), assQuestion\lookupMaxStep(), iQuestionCondition\NumberOfResultExpression, iQuestionCondition\NumericResultExpression, iQuestionCondition\PercentageResultExpression, and iQuestionCondition\StringResultExpression.

+ Here is the call graph for this function:

◆ getFeedbackMode()

assClozeTest::getFeedbackMode ( )
Returns
string

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

References $feedbackMode.

Referenced by saveAdditionalQuestionDataToDb().

659  : string
660  {
661  return $this->feedbackMode;
662  }
+ Here is the caller graph for this function:

◆ getFixedTextLength()

assClozeTest::getFixedTextLength ( )

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

Returns
integer The text field length public

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

References $fixedTextLength.

Referenced by saveAdditionalQuestionDataToDb().

1529  {
1530  return $this->fixedTextLength;
1531  }
+ Here is the caller graph for this function:

◆ getGap()

assClozeTest::getGap (   $gap_index = 0)

Returns the gap at a given index.

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

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

Referenced by addAnswerOptionValue(), getAvailableAnswerOptions(), getSolutionSubmitValidation(), isAddableAnswerOptionValue(), saveWorkingData(), and validateSolutionSubmit().

782  {
783  if (array_key_exists($gap_index, $this->gaps)) {
784  return $this->gaps[$gap_index];
785  } else {
786  return null;
787  }
788  }
+ Here is the caller graph for this function:

◆ getGapCombinations()

assClozeTest::getGapCombinations ( )

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

References $gap_combinations.

1570  : array
1571  {
1572  return $this->gap_combinations;
1573  }

◆ getGapCombinationsExists()

assClozeTest::getGapCombinationsExists ( )

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

References $gap_combinations_exists.

1565  : bool
1566  {
1568  }

◆ getGapCount()

assClozeTest::getGapCount ( )

Returns the number of gaps.

Returns
integer The number of gaps public
See also
$gaps

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

745  : int
746  {
747  if (is_array($this->gaps)) {
748  return count($this->gaps);
749  } else {
750  return 0;
751  }
752  }

◆ getGaps()

assClozeTest::getGaps ( )

Returns the array of gaps.

Returns
array<int, assClozeGap> A map containing the gap objects of the cloze question gaps mapped to the respective gap id.

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

References $gaps.

Referenced by deleteGap(), fetchSolutionSubmit(), getAvailableAnswerOptions(), isComplete(), setExportDetailsXLSX(), toJSON(), and updateClozeTextFromGaps().

532  : array
533  {
534  return $this->gaps;
535  }
+ 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 public

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

Referenced by calculateReachedPointsForSolution(), and saveAdditionalQuestionDataToDb().

1479  {
1480  return ($this->identical_scoring) ? 1 : 0;
1481  }
+ Here is the caller graph for this function:

◆ 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 public
See also
$points

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

References assQuestion\$points.

Referenced by calculateReachedPointsForSolution().

1542  {
1543  $points = 0;
1544  $gap_max_points = 0;
1545  if (array_key_exists($gap_index, $this->gaps)) {
1546  $gap = &$this->gaps[$gap_index];
1547  foreach ($gap->getItems($this->getShuffler()) as $answer) {
1548  if ($answer->getPoints() > $gap_max_points) {
1549  $gap_max_points = $answer->getPoints();
1550  }
1551  }
1552  $points += $gap_max_points;
1553  }
1554  return $points;
1555  }
float $points
The maximum available points for the question.
+ Here is the caller graph for this function:

◆ getMaximumPoints()

assClozeTest::getMaximumPoints ( )

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

public

See also
$points

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

References assQuestion\$points, assQuestion\getId(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

Referenced by getExpressionTypes(), and isComplete().

887  : float
888  {
889  $assClozeGapCombinationObj = new assClozeGapCombination();
890  $points = 0;
891  $gaps_used_in_combination = [];
892  if ($assClozeGapCombinationObj->combinationExistsForQid($this->getId())) {
893  $points = $assClozeGapCombinationObj->getMaxPointsForCombination($this->getId());
894  $gaps_used_in_combination = $assClozeGapCombinationObj->getGapsWhichAreUsedInCombination($this->getId());
895  }
896  foreach ($this->gaps as $gap_index => $gap) {
897  if (!array_key_exists($gap_index, $gaps_used_in_combination)) {
898  if ($gap->getType() == assClozeGap::TYPE_TEXT) {
899  $gap_max_points = 0;
900  foreach ($gap->getItems($this->getShuffler()) as $item) {
901  if ($item->getPoints() > $gap_max_points) {
902  $gap_max_points = $item->getPoints();
903  }
904  }
905  $points += $gap_max_points;
906  } elseif ($gap->getType() == assClozeGap::TYPE_SELECT) {
907  $srpoints = 0;
908  foreach ($gap->getItems($this->getShuffler()) as $item) {
909  if ($item->getPoints() > $srpoints) {
910  $srpoints = $item->getPoints();
911  }
912  }
913  $points += $srpoints;
914  } elseif ($gap->getType() == assClozeGap::TYPE_NUMERIC) {
915  $numpoints = 0;
916  foreach ($gap->getItems($this->getShuffler()) as $item) {
917  if ($item->getPoints() > $numpoints) {
918  $numpoints = $item->getPoints();
919  }
920  }
921  $points += $numpoints;
922  }
923  }
924  }
925 
926  return $points;
927  }
float $points
The maximum available points for the question.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ 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 public

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

Referenced by calculateCombinationResult(), and calculateReachedPointsForSolution().

1204  : float
1205  {
1206  $eval = new EvalMath();
1207  $eval->suppress_errors = true;
1208  $result = 0.0;
1209 
1210  if ($eval->e($a_entered) === false) {
1211  return 0.0;
1212  } elseif (($eval->e($lowerBound) !== false) && ($eval->e($upperBound) !== false)) {
1213  if (($eval->e($a_entered) >= $eval->e($lowerBound)) && ($eval->e($a_entered) <= $eval->e($upperBound))) {
1214  $result = $max_points;
1215  }
1216  } elseif ($eval->e($lowerBound) !== false) {
1217  if (($eval->e($a_entered) >= $eval->e($lowerBound)) && ($eval->e($a_entered) <= $eval->e($a_original))) {
1218  $result = $max_points;
1219  }
1220  } elseif ($eval->e($upperBound) !== false) {
1221  if (($eval->e($a_entered) >= $eval->e($a_original)) && ($eval->e($a_entered) <= $eval->e($upperBound))) {
1222  $result = $max_points;
1223  }
1224  } elseif ($eval->e($a_entered) == $eval->e($a_original)) {
1225  $result = $max_points;
1226  }
1227  return $result;
1228  }
+ Here is the caller graph for this function:

◆ getOperators()

assClozeTest::getOperators (   $expression)

Get all available operations for a specific question.

Parameters
string$expression

Implements iQuestionCondition.

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

References ilOperatorsExpressionMapping\getOperatorsByExpression().

1694  : array
1695  {
1697  }
+ 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 public

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

Referenced by toJSON().

1429  : string
1430  {
1431  return "assClozeTest";
1432  }
+ Here is the caller graph for this function:

◆ getRTETextWithMediaObjects()

assClozeTest::getRTETextWithMediaObjects ( )

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

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

References getClozeText().

1561  : string
1562  {
1563  return parent::getRTETextWithMediaObjects() . $this->getClozeText();
1564  }
getClozeText()
Returns the cloze text.
+ Here is the call graph for this function:

◆ getSolutionSubmit()

assClozeTest::getSolutionSubmit ( )

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

References fetchSolutionSubmit().

Referenced by saveWorkingData().

1364  : array
1365  {
1366  return $this->fetchSolutionSubmit($_POST);
1367  }
fetchSolutionSubmit($submit)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSolutionSubmitValidation()

assClozeTest::getSolutionSubmitValidation ( )

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

References ILIAS\LTI\ToolProvider\$key, getGap(), assClozeGap\TYPE_NUMERIC, and assClozeGap\TYPE_SELECT.

Referenced by validateSolutionSubmit().

1340  : array
1341  {
1342  $submit = $_POST;
1343  $solutionSubmit = [];
1344 
1345  foreach ($submit as $key => $value) {
1346  if (preg_match("/^gap_(\d+)/", $key, $matches)) {
1347  if ($value !== null && $value !== '') {
1348  $gap = $this->getGap($matches[1]);
1349  if (is_object($gap)) {
1350  if (!(($gap->getType() == assClozeGap::TYPE_SELECT) && ($value == -1))) {
1351  if ($gap->getType() == assClozeGap::TYPE_NUMERIC) {
1352  $value = str_replace(",", ".", $value);
1353  }
1354  $solutionSubmit[trim($matches[1])] = $value;
1355  }
1356  }
1357  }
1358  }
1359  }
1360 
1361  return $solutionSubmit;
1362  }
getGap($gap_index=0)
Returns the gap at a given index.
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStartTag()

assClozeTest::getStartTag ( )

Returns the start tag of a cloze gap.

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

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

References $start_tag.

615  : string
616  {
617  return $this->start_tag;
618  }

◆ 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 public

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

References $DIC, assQuestion\$refinery, getTextgapRating(), 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.

Referenced by calculateCombinationResult(), and calculateReachedPointsForSolution().

1152  : float
1153  {
1154  global $DIC;
1155  $refinery = $DIC->refinery();
1156  $result = 0;
1157  $gaprating = $this->getTextgapRating();
1158 
1159  switch ($gaprating) {
1161  if (strcmp(ilStr::strToLower($a_original), ilStr::strToLower($a_entered)) == 0) {
1162  $result = $max_points;
1163  }
1164  break;
1166  if (strcmp($a_original, $a_entered) == 0) {
1167  $result = $max_points;
1168  }
1169  break;
1171  $transformation = $refinery->string()->levenshtein()->standard($a_original, 1);
1172  break;
1174  $transformation = $refinery->string()->levenshtein()->standard($a_original, 2);
1175  break;
1177  $transformation = $refinery->string()->levenshtein()->standard($a_original, 3);
1178  break;
1180  $transformation = $refinery->string()->levenshtein()->standard($a_original, 4);
1181  break;
1183  $transformation = $refinery->string()->levenshtein()->standard($a_original, 5);
1184  break;
1185  }
1186 
1187  // run answers against Levenshtein2 methods
1188  if (isset($transformation) && $transformation->transform($a_entered) >= 0) {
1189  $result = $max_points;
1190  }
1191  return $result;
1192  }
const TEXTGAP_RATING_LEVENSHTEIN3
const TEXTGAP_RATING_CASEINSENSITIVE
getTextgapRating()
Returns the rating option for text gaps.
const TEXTGAP_RATING_LEVENSHTEIN5
const TEXTGAP_RATING_LEVENSHTEIN2
const TEXTGAP_RATING_CASESENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN1
$DIC
Definition: xapitoken.php:62
static strToLower(string $a_string)
Definition: class.ilStr.php:72
const TEXTGAP_RATING_LEVENSHTEIN4
ILIAS Refinery Factory $refinery
+ Here is the call graph for this function:
+ Here is the caller 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 public

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

References $textgap_rating.

Referenced by getTextgapPoints(), and saveAdditionalQuestionDataToDb().

1441  : string
1442  {
1443  return $this->textgap_rating;
1444  }
+ Here is the caller graph for this function:

◆ isAddableAnswerOptionValue()

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

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

References getGap(), and assClozeGap\TYPE_TEXT.

1992  : bool
1993  {
1994  $gap = $this->getGap($qIndex);
1995 
1996  if ($gap->getType() != assClozeGap::TYPE_TEXT) {
1997  return false;
1998  }
1999 
2000  foreach ($gap->getItems($this->randomGroup->dontShuffle()) as $item) {
2001  if ($item->getAnswertext() === $answerOptionValue) {
2002  return false;
2003  }
2004  }
2005 
2006  return true;
2007  }
getGap($gap_index=0)
Returns the gap at a given index.
+ 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

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

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

148  : bool
149  {
150  if (strlen($this->getTitle())
151  && $this->getAuthor()
152  && $this->getClozeText()
153  && count($this->getGaps())
154  && $this->getMaximumPoints() > 0) {
155  return true;
156  }
157  return false;
158  }
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
getGaps()
Returns the array of gaps.
getClozeText()
Returns the cloze text.
+ Here is the call graph for this function:

◆ isValidNumericSubmitValue()

assClozeTest::isValidNumericSubmitValue (   $submittedValue)
protected

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

Referenced by validateSolutionSubmit().

1277  : bool
1278  {
1279  if (is_numeric($submittedValue)) {
1280  return true;
1281  }
1282 
1283  if (preg_match('/^[-+]{0,1}\d+\/\d+$/', $submittedValue)) {
1284  return true;
1285  }
1286 
1287  return false;
1288  }
+ Here is the caller graph for this function:

◆ lmMigrateQuestionTypeSpecificContent()

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

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

References getClozeText(), and ilAssSelfAssessmentMigrator\migrateToLmContent().

1627  : void
1628  {
1629  // DO NOT USE SETTER FOR CLOZE TEXT -> SETTER DOES RECREATE GAP OBJECTS without having gap type info ^^
1630  //$this->setClozeText( $migrator->migrateToLmContent($this->getClozeText()) );
1631  $this->cloze_text = $migrator->migrateToLmContent($this->getClozeText());
1632  // DO NOT USE SETTER FOR CLOZE TEXT -> SETTER DOES RECREATE GAP OBJECTS without having gap type info ^^
1633  }
getClozeText()
Returns the cloze text.
+ Here is the call graph for this function:

◆ loadFromDb()

assClozeTest::loadFromDb (   $question_id)

Loads a assClozeTest object from a database.

Parameters
integer$question_idA unique key which defines the cloze test in the database

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

References $data, $DIC, Vendor\Package\$e, $ilDB, ilRTE\_replaceMediaObjectImageSrc(), cleanQuestiontext(), ilAssClozeTestFeedback\FB_MODE_GAP_QUESTION, getAdditionalTableName(), ilAssQuestionLifecycle\getDraftInstance(), ilAssQuestionLifecycle\getInstance(), assQuestion\setAdditionalContentEditingMode(), assQuestion\setAuthor(), setClozeText(), assQuestion\setComment(), setFeedbackMode(), setFixedTextLength(), setGapCombinations(), setGapCombinationsExists(), assQuestion\setId(), setIdenticalScoring(), assQuestion\setLifecycle(), assQuestion\setNrOfTries(), assQuestion\setObjId(), assQuestion\setOriginalId(), assQuestion\setOwner(), assQuestion\setPoints(), assQuestion\setQuestion(), setTextgapRating(), assQuestion\setTitle(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

204  : void
205  {
206  global $DIC;
207  $ilDB = $DIC['ilDB'];
208  $result = $ilDB->queryF(
209  "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",
210  ["integer"],
211  [$question_id]
212  );
213  if ($result->numRows() == 1) {
214  $data = $ilDB->fetchAssoc($result);
215  $this->setId($question_id);
216  $this->setNrOfTries($data['nr_of_tries']);
217  $this->setObjId($data["obj_fi"]);
218  $this->setTitle((string) $data["title"]);
219  $this->setComment((string) $data["description"]);
220  $this->setOriginalId($data["original_id"]);
221  $this->setAuthor($data["author"]);
222  $this->setPoints($data["points"]);
223  $this->setOwner($data["owner"]);
224  $this->setQuestion($this->cleanQuestiontext($data["question_text"]));
225  $this->setClozeText($data['cloze_text']);
226  $this->setFixedTextLength($data["fixed_textlen"]);
227  $this->setIdenticalScoring(($data['tstamp'] == 0) ? true : $data["identical_scoring"]);
228  $this->setFeedbackMode($data['feedback_mode'] === null ? ilAssClozeTestFeedback::FB_MODE_GAP_QUESTION : $data['feedback_mode']);
229 
230  try {
234  }
235 
236  $this->question = ilRTE::_replaceMediaObjectImageSrc($this->question, 1);
237  $this->cloze_text = ilRTE::_replaceMediaObjectImageSrc($this->cloze_text, 1);
238  $this->setTextgapRating($data["textgap_rating"]);
239 
240  try {
241  $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
242  } catch (ilTestQuestionPoolException $e) {
243  }
244 
245  $result = $ilDB->queryF(
246  "SELECT * FROM qpl_a_cloze WHERE question_fi = %s ORDER BY gap_id, aorder ASC",
247  ["integer"],
248  [$question_id]
249  );
250  if ($result->numRows() > 0) {
251  $this->gaps = [];
252  while ($data = $ilDB->fetchAssoc($result)) {
253  switch ($data["cloze_type"]) {
255  if (!array_key_exists($data["gap_id"], $this->gaps)) {
256  $this->gaps[$data["gap_id"]] = new assClozeGap(assClozeGap::TYPE_TEXT);
257  }
258  $answer = new assAnswerCloze(
259  $data["answertext"],
260  $data["points"],
261  $data["aorder"]
262  );
263  $this->gaps[$data["gap_id"]]->setGapSize((int) $data['gap_size']);
264 
265  $this->gaps[$data["gap_id"]]->addItem($answer);
266  break;
268  if (!array_key_exists($data["gap_id"], $this->gaps)) {
269  $this->gaps[$data["gap_id"]] = new assClozeGap(assClozeGap::TYPE_SELECT);
270  $this->gaps[$data["gap_id"]]->setShuffle($data["shuffle"]);
271  }
272  $answer = new assAnswerCloze(
273  $data["answertext"],
274  $data["points"],
275  $data["aorder"]
276  );
277  $this->gaps[$data["gap_id"]]->addItem($answer);
278  break;
280  if (!array_key_exists($data["gap_id"], $this->gaps)) {
281  $this->gaps[$data["gap_id"]] = new assClozeGap(assClozeGap::TYPE_NUMERIC);
282  }
283  $answer = new assAnswerCloze(
284  $data["answertext"],
285  $data["points"],
286  $data["aorder"]
287  );
288  $this->gaps[$data["gap_id"]]->setGapSize((int) $data['gap_size']);
289  $answer->setLowerBound($data["lowerlimit"]);
290  $answer->setUpperBound($data["upperlimit"]);
291  $this->gaps[$data["gap_id"]]->addItem($answer);
292  break;
293  }
294  }
295  }
296  }
297  $assClozeGapCombinationObj = new assClozeGapCombination();
298  $check_for_gap_combinations = $assClozeGapCombinationObj->loadFromDb($question_id);
299  if (count($check_for_gap_combinations) != 0) {
300  $this->setGapCombinationsExists(true);
301  $this->setGapCombinations($check_for_gap_combinations);
302  }
303  parent::loadFromDb($question_id);
304  }
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...
setNrOfTries(int $a_nr_of_tries)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setOwner(int $owner=-1)
Class for cloze question gaps.
setComment(string $comment="")
setGapCombinationsExists($value)
setFixedTextLength($a_text_len)
Sets a fixed text length for all text fields in the cloze question.
$DIC
Definition: xapitoken.php:62
setPoints(float $points)
setObjId(int $obj_id=0)
setClozeText($cloze_text="")
Evaluates the text gap solutions from the cloze text.
cleanQuestiontext($text)
Cleans cloze question text to remove attributes or tags from older ILIAS versions.
setFeedbackMode($feedbackMode)
setTextgapRating($a_textgap_rating)
Sets the rating option for text gaps.
setId(int $id=-1)
setOriginalId(?int $original_id)
setTitle(string $title="")
setLifecycle(ilAssQuestionLifecycle $lifecycle)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setAuthor(string $author="")
setIdenticalScoring($a_identical_scoring)
Sets the identical scoring option for cloze questions.
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
const FB_MODE_GAP_QUESTION
constants for different feedback modes (per gap or per gap-answers/options)
setQuestion(string $question="")
+ Here is the call graph for this function:

◆ replaceFirstGap()

assClozeTest::replaceFirstGap (   $gaptext,
  $content 
)

Replace the first gap in a string without treating backreferences.

Parameters
string$gaptexttext with gap tags
string$contentcontent for the first gap
Returns
string

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

Referenced by deleteGap(), and updateClozeTextFromGaps().

189  : string
190  {
191  $content = str_replace('$', 'GAPMASKEDDOLLAR', $content);
192  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $content, $gaptext, 1);
193  $output = str_replace('GAPMASKEDDOLLAR', '$', $output);
194 
195  return $output;
196  }
+ Here is the caller graph for this function:

◆ saveAdditionalQuestionDataToDb()

assClozeTest::saveAdditionalQuestionDataToDb ( )

Saves the data for the additional data table.

This method uses the ugly DELETE-INSERT. Here, this does no harm.

Implements ilObjQuestionScoringAdjustable.

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

References $DIC, ilRTE\_replaceMediaObjectImageSrc(), getAdditionalTableName(), getClozeText(), getFeedbackMode(), getFixedTextLength(), assQuestion\getId(), getIdenticalScoring(), and getTextgapRating().

Referenced by saveToDb().

355  {
356  global $DIC; /* @var ILIAS\DI\Container $DIC */
357 
358 
359  $DIC->database()->manipulateF(
360  "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
361  [ "integer" ],
362  [ $this->getId() ]
363  );
364 
365  $DIC->database()->insert($this->getAdditionalTableName(), [
366  'question_fi' => ['integer', $this->getId()],
367  'textgap_rating' => ['text', $this->getTextgapRating()],
368  'identical_scoring' => ['text', $this->getIdenticalScoring()],
369  'fixed_textlen' => ['integer', $this->getFixedTextLength() ? $this->getFixedTextLength() : null],
370  'cloze_text' => ['text', ilRTE::_replaceMediaObjectImageSrc($this->getClozeText(), 0)],
371  'feedback_mode' => ['text', $this->getFeedbackMode()]
372  ]);
373  }
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...
getAdditionalTableName()
Returns the name of the additional question data table in the database.
getTextgapRating()
Returns the rating option for text gaps.
$DIC
Definition: xapitoken.php:62
getFixedTextLength()
Gets the fixed text length for all text fields in the cloze question.
getClozeText()
Returns the cloze text.
getIdenticalScoring()
Returns the identical scoring status of the question.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAnswerSpecificDataToDb()

assClozeTest::saveAnswerSpecificDataToDb ( )

Save all gaps to the database.

Implements ilObjAnswerScoringAdjustable.

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

References $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, assQuestion\getId(), and saveClozeGapItemsToDb().

Referenced by saveToDb().

334  {
335  global $DIC;
336  $ilDB = $DIC['ilDB'];
337 
338  $ilDB->manipulateF(
339  "DELETE FROM qpl_a_cloze WHERE question_fi = %s",
340  [ "integer" ],
341  [ $this->getId() ]
342  );
343 
344  foreach ($this->gaps as $key => $gap) {
345  $this->saveClozeGapItemsToDb($gap, $key);
346  }
347  }
string $key
Consumer key/client ID value.
Definition: System.php:193
$DIC
Definition: xapitoken.php:62
saveClozeGapItemsToDb($gap, $key)
Save all items belonging to one cloze gap to the db.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClozeGapItemsToDb()

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

Save all items belonging to one cloze gap to the db.

Parameters
$gap
$key

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

References $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, saveClozeNumericGapRecordToDb(), saveClozeSelectGapRecordToDb(), saveClozeTextGapRecordToDb(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

Referenced by saveAnswerSpecificDataToDb().

381  : void
382  {
383  global $DIC;
384  $ilDB = $DIC['ilDB'];
385  foreach ($gap->getItems($this->getShuffler()) as $item) {
386  $query = "";
387  $next_id = $ilDB->nextId('qpl_a_cloze');
388  switch ($gap->getType()) {
390  $this->saveClozeTextGapRecordToDb($next_id, $key, $item, $gap);
391  break;
393  $this->saveClozeSelectGapRecordToDb($next_id, $key, $item, $gap);
394  break;
396  $this->saveClozeNumericGapRecordToDb($next_id, $key, $item, $gap);
397  break;
398  }
399  }
400  }
string $key
Consumer key/client ID value.
Definition: System.php:193
$DIC
Definition: xapitoken.php:62
saveClozeTextGapRecordToDb($next_id, $key, $item, $gap)
Saves a gap-item record.
saveClozeNumericGapRecordToDb($next_id, $key, $item, $gap)
Saves a gap-item record.
saveClozeSelectGapRecordToDb($next_id, $key, $item, $gap)
Saves a gap-item record.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClozeNumericGapRecordToDb()

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

Saves a gap-item record.

Parameters
$next_idint Next Id for the record.
$keyint Gap Id
$itemmixed Gap item data object.
$gapmixed Gap data object.

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

References $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, assQuestion\getId(), and ILIAS\Repository\int().

Referenced by saveClozeGapItemsToDb().

484  : void
485  {
486  global $DIC;
487  $ilDB = $DIC['ilDB'];
488 
489  $eval = new EvalMath();
490  $eval->suppress_errors = true;
491  $ilDB->manipulateF(
492  "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)",
493  [
494  "integer",
495  "integer",
496  "integer",
497  "text",
498  "float",
499  "integer",
500  "text",
501  "text",
502  "text",
503  "integer"
504  ],
505  [
506  $next_id,
507  $this->getId(),
508  $key,
509  strlen($item->getAnswertext()) ? $item->getAnswertext() : "",
510  $item->getPoints(),
511  $item->getOrder(),
512  $gap->getType(),
513  ($eval->e($item->getLowerBound() !== false) && strlen(
514  $item->getLowerBound()
515  ) > 0) ? $item->getLowerBound() : $item->getAnswertext(),
516  ($eval->e($item->getUpperBound() !== false) && strlen(
517  $item->getUpperBound()
518  ) > 0) ? $item->getUpperBound() : $item->getAnswertext(),
519  (int) $gap->getGapSize()
520  ]
521  );
522  }
string $key
Consumer key/client ID value.
Definition: System.php:193
$DIC
Definition: xapitoken.php:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClozeSelectGapRecordToDb()

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

Saves a gap-item record.

Parameters
$next_idint Next Id for the record.
$keyint Gap Id
$itemmixed Gap item data object.
$gapmixed Gap data object.

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

References $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, and assQuestion\getId().

Referenced by saveClozeGapItemsToDb().

447  : void
448  {
449  global $DIC;
450  $ilDB = $DIC['ilDB'];
451  $ilDB->manipulateF(
452  "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)",
453  [
454  "integer",
455  "integer",
456  "integer",
457  "text",
458  "float",
459  "integer",
460  "text",
461  "text"
462  ],
463  [
464  $next_id,
465  $this->getId(),
466  $key,
467  strlen($item->getAnswertext()) ? $item->getAnswertext() : "",
468  $item->getPoints(),
469  $item->getOrder(),
470  $gap->getType(),
471  ($gap->getShuffle()) ? "1" : "0"
472  ]
473  );
474  }
string $key
Consumer key/client ID value.
Definition: System.php:193
$DIC
Definition: xapitoken.php:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClozeTextGapRecordToDb()

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

Saves a gap-item record.

Parameters
$next_idint Next Id for the record.
$keyint Gap Id
$itemmixed Gap item data object.
$gapmixed Gap data object.

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

References $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, assQuestion\getId(), and ILIAS\Repository\int().

Referenced by saveClozeGapItemsToDb().

410  : void
411  {
412  global $DIC;
413  $ilDB = $DIC['ilDB'];
414  $ilDB->manipulateF(
415  "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)",
416  [
417  "integer",
418  "integer",
419  "integer",
420  "text",
421  "float",
422  "integer",
423  "text",
424  "integer"
425  ],
426  [
427  $next_id,
428  $this->getId(),
429  $key,
430  strlen($item->getAnswertext()) ? $item->getAnswertext() : "",
431  $item->getPoints(),
432  $item->getOrder(),
433  $gap->getType(),
434  (int) $gap->getGapSize()
435  ]
436  );
437  }
string $key
Consumer key/client ID value.
Definition: System.php:193
$DIC
Definition: xapitoken.php:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveToDb()

assClozeTest::saveToDb (   $original_id = "")

Saves a assClozeTest object to a database.

Parameters
int | string$original_idID of the original question
Returns
mixed|void

public

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

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

317  : void
318  {
319  if ($original_id == "") {
320  $this->saveQuestionDataToDb();
321  } else {
323  }
326 
327  parent::saveToDb();
328  }
saveAnswerSpecificDataToDb()
Save all gaps to the database.
saveAdditionalQuestionDataToDb()
Saves the data for the additional data table.
saveQuestionDataToDb(int $original_id=-1)
+ Here is the call graph for this function:

◆ saveWorkingData()

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

Saves the learners input of the question to the database.

public

Parameters
integer$active_idActive id of the user
integer$passTest pass
Returns
boolean $status

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

References ILIAS\LTI\ToolProvider\$key, ilObjAssessmentFolder\_enabledAssessmentLogging(), ilObjAssessmentFolder\_getLogLanguage(), ilObjTest\_getPass(), getGap(), assQuestion\getId(), assQuestion\getProcessLocker(), getSolutionSubmit(), ILIAS\Repository\lng(), assQuestion\logAction(), assQuestion\removeCurrentSolution(), assQuestion\saveCurrentSolution(), ilUtil\stripSlashes(), and assClozeGap\TYPE_SELECT.

1377  : bool
1378  {
1379  if (is_null($pass)) {
1380  $pass = ilObjTest::_getPass($active_id);
1381  }
1382 
1383  $entered_values = 0;
1384 
1385  $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(function () use (&$entered_values, $active_id, $pass, $authorized) {
1386  $this->removeCurrentSolution($active_id, $pass, $authorized);
1387 
1388  foreach ($this->getSolutionSubmit() as $key => $value) {
1389  if ($value !== null && $value !== '') {
1390  $gap = $this->getGap(trim(ilUtil::stripSlashes($key)));
1391  if (is_object($gap)) {
1392 
1393  if (!(($gap->getType() == assClozeGap::TYPE_SELECT) && ($value == -1))) {
1394  $this->saveCurrentSolution($active_id, $pass, $val1, $value, $authorized);
1395  $entered_values++;
1396  }
1397  }
1398  }
1399  }
1400  });
1401 
1402  if ($entered_values) {
1404  assQuestion::logAction($this->lng->txtlng(
1405  "assessment",
1406  "log_user_entered_values",
1408  ), $active_id, $this->getId());
1409  }
1410  } else {
1412  assQuestion::logAction($this->lng->txtlng(
1413  "assessment",
1414  "log_user_not_entered_values",
1416  ), $active_id, $this->getId());
1417  }
1418  }
1419 
1420  return true;
1421  }
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
getGap($gap_index=0)
Returns the gap at a given index.
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
static logAction(string $logtext, int $active_id, int $question_id)
string $key
Consumer key/client ID value.
Definition: System.php:193
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
+ Here is the call graph for this function:

◆ setClozeText()

assClozeTest::setClozeText (   $cloze_text = "")

Evaluates the text gap solutions from the cloze text.

A single or multiple text gap solutions could be entered using the following syntax in the cloze text: solution1 [, solution2, ..., solutionN] enclosed in the text gap selector gap[]

Parameters
string$cloze_textThe cloze text with all gaps and gap gaps public
See also
$cloze_text

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

References $cloze_text, cleanQuestiontext(), and createGapsFromQuestiontext().

Referenced by loadFromDb().

556  : void
557  {
558  $this->gaps = [];
559  $this->cloze_text = $this->cleanQuestiontext($cloze_text);
561  }
createGapsFromQuestiontext()
Create gap entries by parsing the question text.
cleanQuestiontext($text)
Cleans cloze question text to remove attributes or tags from older ILIAS versions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setClozeTextValue()

assClozeTest::setClozeTextValue (   $cloze_text = "")

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

References $cloze_text.

563  : void
564  {
565  $this->cloze_text = $cloze_text;
566  }

◆ setEndTag()

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

Sets the end tag of a cloze gap.

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

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

References $end_tag.

651  : void
652  {
653  $this->end_tag = $end_tag;
654  }

◆ setExportDetailsXLSX()

assClozeTest::setExportDetailsXLSX ( ilAssExcelFormatHelper  $worksheet,
int  $startrow,
int  $col,
int  $active_id,
int  $pass 
)

{}

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

References $i, ilExcel\getColumnCoord(), getGaps(), assQuestion\getSolutionValues(), ilAssExcelFormatHelper\getStringEscaping(), ILIAS\Repository\lng(), ilExcel\setBold(), ilAssExcelFormatHelper\setCell(), ilAssExcelFormatHelper\setStringEscaping(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

1588  : int
1589  {
1590  parent::setExportDetailsXLSX($worksheet, $startrow, $col, $active_id, $pass);
1591 
1592  $solution = $this->getSolutionValues($active_id, $pass);
1593  $i = 1;
1594  foreach ($this->getGaps() as $gap_index => $gap) {
1595  $worksheet->setCell($startrow + $i, $col, $this->lng->txt("gap") . " $i");
1596  $worksheet->setBold($worksheet->getColumnCoord($col) . ($startrow + $i));
1597  $checked = false;
1598  foreach ($solution as $solutionvalue) {
1599  if ($gap_index == $solutionvalue["value1"]) {
1600  $string_escaping_org_value = $worksheet->getStringEscaping();
1601  try {
1602  $worksheet->setStringEscaping(false);
1603 
1604  switch ($gap->getType()) {
1606  $worksheet->setCell($startrow + $i, $col + 2, $gap->getItem($solutionvalue["value2"])->getAnswertext());
1607  break;
1610  $worksheet->setCell($startrow + $i, $col + 2, $solutionvalue["value2"]);
1611  break;
1612  }
1613  } finally {
1614  $worksheet->setStringEscaping($string_escaping_org_value);
1615  }
1616  }
1617  }
1618  $i++;
1619  }
1620 
1621  return $startrow + $i + 1;
1622  }
getSolutionValues($active_id, $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
getColumnCoord(int $a_col)
Get column "name" from number.
setCell($a_row, $a_col, $a_value, $datatype=null)
getGaps()
Returns the array of gaps.
setBold(string $a_coords)
Set cell(s) to bold.
$i
Definition: saml1-acs.php:28
+ Here is the call graph for this function:

◆ setFeedbackMode()

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

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

References $feedbackMode.

Referenced by loadFromDb().

667  : void
668  {
669  $this->feedbackMode = $feedbackMode;
670  }
+ Here is the caller graph for this function:

◆ setFixedTextLength()

assClozeTest::setFixedTextLength (   $a_text_len)

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

Parameters
integer$a_text_lenThe text field length public

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

Referenced by loadFromDb().

1517  : void
1518  {
1519  $this->fixedTextLength = $a_text_len;
1520  }
+ Here is the caller graph for this function:

◆ 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 public
See also
$gaps

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

857  : void
858  {
859  if (array_key_exists($gap_index, $this->gaps)) {
860  $this->gaps[$gap_index]->setItemLowerBound($order, $bound);
861  }
862  }

◆ 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 public
See also
$gaps

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

References assQuestion\$points.

807  : void
808  {
809  if (array_key_exists($gap_index, $this->gaps)) {
810  $this->gaps[$gap_index]->setItemPoints($order, $points);
811  }
812  }
float $points
The maximum available points for the question.

◆ 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 public
See also
$gaps

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

874  : void
875  {
876  if (array_key_exists($gap_index, $this->gaps)) {
877  $this->gaps[$gap_index]->setItemUpperBound($order, $bound);
878  }
879  }

◆ setGapCombinations()

assClozeTest::setGapCombinations (   $value)

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

Referenced by loadFromDb().

1580  : void
1581  {
1582  $this->gap_combinations = $value;
1583  }
+ Here is the caller graph for this function:

◆ setGapCombinationsExists()

assClozeTest::setGapCombinationsExists (   $value)

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

Referenced by loadFromDb().

1575  : void
1576  {
1577  $this->gap_combinations_exists = $value;
1578  }
+ Here is the caller graph for this function:

◆ 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) public
See also
$gaps

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

References assQuestion\$shuffle.

718  : void
719  {
720  if (array_key_exists($gap_index, $this->gaps)) {
721  $this->gaps[$gap_index]->setShuffle($shuffle);
722  }
723  }
bool $shuffle
Indicates whether the answers will be shuffled or not.

◆ setGapSize()

assClozeTest::setGapSize (   $gap_index,
  $size 
)

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

790  : void
791  {
792  if (array_key_exists($gap_index, $this->gaps)) {
793  $this->gaps[$gap_index]->setGapSize((int) $size);
794  }
795  }

◆ setGapType()

assClozeTest::setGapType (   $gap_index,
  $gap_type 
)

Set the type of a gap with a given index.

private

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

702  : void
703  {
704  if (array_key_exists($gap_index, $this->gaps)) {
705  $this->gaps[$gap_index]->setType($gap_type);
706  }
707  }

◆ setIdenticalScoring()

assClozeTest::setIdenticalScoring (   $a_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 public

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

Referenced by loadFromDb().

1490  : void
1491  {
1492  $this->identical_scoring = ($a_identical_scoring) ? 1 : 0;
1493  }
+ Here is the caller graph for this function:

◆ setStartTag()

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

Sets the start tag of a cloze gap.

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

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

References $start_tag.

627  : void
628  {
629  $this->start_tag = $start_tag;
630  }

◆ 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 public

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

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.

Referenced by loadFromDb().

1453  : void
1454  {
1455  switch ($a_textgap_rating) {
1463  $this->textgap_rating = $a_textgap_rating;
1464  break;
1465  default:
1466  $this->textgap_rating = assClozeGap::TEXTGAP_RATING_CASEINSENSITIVE;
1467  break;
1468  }
1469  }
const TEXTGAP_RATING_LEVENSHTEIN3
const TEXTGAP_RATING_CASEINSENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN5
const TEXTGAP_RATING_LEVENSHTEIN2
const TEXTGAP_RATING_CASESENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN1
const TEXTGAP_RATING_LEVENSHTEIN4
+ Here is the caller graph for this function:

◆ toJSON()

assClozeTest::toJSON ( )

Returns a JSON representation of the question.

Implements ilAssQuestionLMExportable.

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

References $gaps, ILIAS\LTI\ToolProvider\$key, ilObjMediaObject\_getMobsOfObject(), assQuestion\formatSAQuestion(), getClozeText(), getGaps(), assQuestion\getId(), assQuestion\getNrOfTries(), assQuestion\getQuestion(), getQuestionType(), assQuestion\getShuffle(), assQuestion\getTitle(), assClozeGap\TYPE_NUMERIC, and assClozeGap\TYPE_TEXT.

1638  : string
1639  {
1640  $result = [];
1641  $result['id'] = $this->getId();
1642  $result['type'] = (string) $this->getQuestionType();
1643  $result['title'] = $this->getTitle();
1644  $result['question'] = $this->formatSAQuestion($this->getQuestion());
1645  $result['clozetext'] = $this->formatSAQuestion($this->getClozeText());
1646  $result['nr_of_tries'] = $this->getNrOfTries();
1647  $result['shuffle'] = $this->getShuffle();
1648  $result['feedback'] = [
1649  'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1650  'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1651  ];
1652 
1653  $gaps = [];
1654  foreach ($this->getGaps() as $key => $gap) {
1655  $items = [];
1656  foreach ($gap->getItems($this->getShuffler()) as $item) {
1657  $jitem = [];
1658  $jitem['points'] = $item->getPoints();
1659  $jitem['value'] = $this->formatSAQuestion($item->getAnswertext());
1660  $jitem['order'] = $item->getOrder();
1661  if ($gap->getType() == assClozeGap::TYPE_NUMERIC) {
1662  $jitem['lowerbound'] = $item->getLowerBound();
1663  $jitem['upperbound'] = $item->getUpperBound();
1664  } else {
1665  $jitem['value'] = trim($jitem['value']);
1666  }
1667  array_push($items, $jitem);
1668  }
1669 
1670  if ($gap->getGapSize() && ($gap->getType() == assClozeGap::TYPE_TEXT || $gap->getType() == assClozeGap::TYPE_NUMERIC)) {
1671  $jgap['size'] = $gap->getGapSize();
1672  }
1673 
1674  $jgap['shuffle'] = $gap->getShuffle();
1675  $jgap['type'] = $gap->getType();
1676  $jgap['item'] = $items;
1677 
1678  array_push($gaps, $jgap);
1679  }
1680  $result['gaps'] = $gaps;
1681  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1682  $result['mobs'] = $mobs;
1683  return json_encode($result);
1684  }
getQuestionType()
Returns the question type of the question.
getGaps()
Returns the array of gaps.
string $key
Consumer key/client ID value.
Definition: System.php:193
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
getClozeText()
Returns the cloze text.
+ Here is the call graph for this function:

◆ updateClozeTextFromGaps()

assClozeTest::updateClozeTextFromGaps ( )

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

private

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

References getClozeText(), getGaps(), ilLegacyFormElementsUtil\prepareTextareaOutput(), and replaceFirstGap().

Referenced by deleteAnswerText().

1070  : void
1071  {
1072  $output = $this->getClozeText();
1073  foreach ($this->getGaps() as $gap_index => $gap) {
1074  $answers = [];
1075  foreach ($gap->getItemsRaw() as $item) {
1076  array_push($answers, str_replace([',', '['], ["\\,", '[&hairsp;'], $item->getAnswerText()));
1077  }
1078  // fau: fixGapReplace - use replace function
1079  $output = $this->replaceFirstGap($output, "[_gap]" . ilLegacyFormElementsUtil::prepareTextareaOutput(join(",", $answers), true) . "[/_gap]");
1080  // fau.
1081  }
1082  $output = str_replace("_gap]", "gap]", $output);
1083  $this->cloze_text = $output;
1084  }
getGaps()
Returns the array of gaps.
replaceFirstGap($gaptext, $content)
Replace the first gap in a string without treating backreferences.
getClozeText()
Returns the cloze text.
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...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateSolutionSubmit()

assClozeTest::validateSolutionSubmit ( )

Implements assQuestionInterface.

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

References getGap(), getSolutionSubmitValidation(), isValidNumericSubmitValue(), ILIAS\Repository\lng(), and assClozeGap\TYPE_NUMERIC.

1290  : bool
1291  {
1292  foreach ($this->getSolutionSubmitValidation() as $gapIndex => $value) {
1293  $gap = $this->getGap($gapIndex);
1294 
1295  if ($gap->getType() != assClozeGap::TYPE_NUMERIC) {
1296  continue;
1297  }
1298 
1299  if (strlen($value) && !$this->isValidNumericSubmitValue($value)) {
1300  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("err_no_numeric_value"), true);
1301  return false;
1302  }
1303  }
1304 
1305  return true;
1306  }
getGap($gap_index=0)
Returns the gap at a given index.
isValidNumericSubmitValue($submittedValue)
+ Here is the call graph for this function:

Field Documentation

◆ $cloze_text

assClozeTest::$cloze_text

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

Referenced by getClozeText(), setClozeText(), and setClozeTextValue().

◆ $end_tag

assClozeTest::$end_tag

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

Referenced by getEndTag(), and setEndTag().

◆ $feedbackMode

assClozeTest::$feedbackMode = ilAssClozeTestFeedback::FB_MODE_GAP_QUESTION
protected

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

Referenced by getFeedbackMode(), and setFeedbackMode().

◆ $feedbackOBJ

ilAssQuestionFeedback assClozeTest::$feedbackOBJ

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

◆ $fixedTextLength

assClozeTest::$fixedTextLength

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

Referenced by getFixedTextLength().

◆ $gap_combinations

assClozeTest::$gap_combinations

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

Referenced by getGapCombinations().

◆ $gap_combinations_exists

assClozeTest::$gap_combinations_exists

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

Referenced by getGapCombinationsExists().

◆ $gaps

array assClozeTest::$gaps = []

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

Referenced by getGaps(), and toJSON().

◆ $identical_scoring

assClozeTest::$identical_scoring

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

◆ $randomGroup

RandomGroup assClozeTest::$randomGroup
private

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

◆ $start_tag

assClozeTest::$start_tag

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

Referenced by getStartTag(), and setStartTag().

◆ $textgap_rating

assClozeTest::$textgap_rating

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

Referenced by getTextgapRating().


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