ILIAS  release_8 Revision v8.24
assTextQuestion 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 assTextQuestion:
+ Collaboration diagram for assTextQuestion:

Public Member Functions

 __construct ( $title="", $comment="", $author="", $owner=-1, $question="")
 assTextQuestion constructor More...
 
 getMatchcondition ()
 
 setMatchcondition (int $matchcondition)
 
 isComplete ()
 Returns true, if a multiple choice question is complete for use. More...
 
 saveToDb ($original_id="")
 Saves a assTextQuestion object to a database. More...
 
 loadFromDb ($question_id)
 Loads a assTextQuestion object from a database. More...
 
 duplicate (bool $for_test=true, string $title="", string $author="", string $owner="", $testObjId=null)
 Duplicates an assTextQuestion. More...
 
 copyObject ($target_questionpool_id, $title="")
 Copies an assTextQuestion object. More...
 
 createNewOriginalFromThisDuplicate ($targetParentId, $targetQuestionTitle="")
 
 getMaxNumOfChars ()
 Gets the maximum number of characters for the text solution. More...
 
 setMaxNumOfChars ($maxchars=0)
 Sets the maximum number of characters for the text solution. More...
 
 isWordCounterEnabled ()
 
 setWordCounterEnabled ($wordCounterEnabled)
 
 getMaximumPoints ()
 Returns the maximum points, a learner can reach answering the question. More...
 
 getMinimumPoints ()
 
 setReachedPoints ($active_id, $points, $pass=null)
 Sets the points, a learner has reached answering the question. More...
 
 isKeywordMatching ($answertext, $a_keyword)
 Checks if one of the keywords matches the answertext. More...
 
 calculateReachedPoints ($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
 Returns the points, a learner has reached answering the question. More...
 
 saveWorkingData ($active_id, $pass=null, $authorized=true)
 Saves the learners input of the question to the database. More...
 
 getSolutionSubmit ()
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 getTextRating ()
 Returns the rating option for text comparisons. More...
 
 setTextRating ($a_text_rating)
 Sets the rating option for text comparisons. More...
 
 getAdditionalTableName ()
 Returns the name of the additional question data table in the database. More...
 
 getRTETextWithMediaObjects ()
 Collects all text in the question which could contain media objects which were created with the Rich Text Editor. More...
 
 setExportDetailsXLS (ilAssExcelFormatHelper $worksheet, int $startrow, int $active_id, int $pass)
 {} More...
 
 toJSON ()
 Returns a JSON representation of the question. More...
 
 getAnswerCount ()
 
 addAnswer ( $answertext="", $points=0.0, $points_unchecked=0.0, $order=0, $answerimage="")
 Adds a possible answer for a multiple choice question. More...
 
 getAnswers ()
 
 getAnswer ($index=0)
 Returns an answer with a given index. More...
 
 deleteAnswer ($index=0)
 Deletes an answer with a given index. More...
 
 getAnswerTableName ()
 
 flushAnswers ()
 Deletes all answers. More...
 
 setAnswers ($answers)
 
 duplicateAnswers ($original_id)
 
 getKeywordRelation ()
 
 setKeywordRelation ($a_relation)
 This method implements a default behaviour. More...
 
 isAnswered (int $active_id, int $pass)
 returns boolean wether the question is answered during test pass or not More...
 
 countLetters ($text)
 
 countWords ($text)
 
 getLatestAutosaveContent (int $active_id, int $pass)
 
- 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...
 
 questionTitleExists (int $questionpool_id, string $title)
 Returns TRUE if the question title exists in a question pool in the database. More...
 
 setTitle (string $title="")
 
 setId (int $id=-1)
 
 setTestId (int $id=-1)
 
 setComment (string $comment="")
 
 setOutputType (int $outputType=OUTPUT_HTML)
 
 setShuffle (?bool $shuffle=true)
 
 setAuthor (string $author="")
 
 setOwner (int $owner=-1)
 
 getTitle ()
 
 getTitleForHTMLOutput ()
 
 getTitleFilenameCompliant ()
 
 getId ()
 
 getShuffle ()
 
 getTestId ()
 
 getComment ()
 
 getDescriptionForHTMLOutput ()
 
 getThumbSize ()
 
 setThumbSize (int $a_size)
 
 getMinimumThumbSize ()
 
 getMaximumThumbSize ()
 
 getOutputType ()
 
 supportsJavascriptOutput ()
 
 supportsNonJsOutput ()
 
 requiresJsSwitch ()
 
 getAuthor ()
 
 getAuthorForHTMLOutput ()
 
 getOwner ()
 
 getObjId ()
 
 setObjId (int $obj_id=0)
 
 getLifecycle ()
 
 setLifecycle (ilAssQuestionLifecycle $lifecycle)
 
 setExternalId (?string $external_id)
 
 getExternalId ()
 
 getSuggestedSolutionOutput ()
 
 _getSuggestedSolution (int $question_id, int $subquestion_index=0)
 
 loadSuggestedSolution (int $question_id, int $subquestion_index=0)
 Returns a suggested solution for a given subquestion index. More...
 
 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...
 
 moveUploadedMediaFile (string $file, string $name)
 Move an uploaded media file to an public accessible temp dir to present it. More...
 
 getSuggestedSolutionPath ()
 
 getImagePath ($question_id=null, $object_id=null)
 Returns the image path for web accessable images of a question. More...
 
 buildImagePath ($questionId, $parentObjectId)
 
 getFlashPath ()
 Returns the image path for web accessable flash files 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...
 
 isInUse (int $question_id=0)
 Checks whether the question is in use or not in pools or tests. More...
 
 usageNumber (int $question_id=0)
 Returns the number of place the question is in use in pools or tests. More...
 
 isClone (int $question_id=0)
 Checks whether the question is a clone of another question or not. 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 ()
 
 setNewOriginalId (int $newId)
 
 deleteSuggestedSolutions ()
 
 getSuggestedSolution (int $subquestion_index=0)
 Returns a suggested solution for a given subquestion index. More...
 
 getSuggestedSolutionTitle (int $subquestion_index=0)
 Returns the title of a suggested solution at a given subquestion_index. More...
 
 setSuggestedSolution (string $solution_id="", int $subquestion_index=0, bool $is_import=false)
 Sets a suggested solution for the question. More...
 
 updateSuggestedSolutions (int $original_id=-1, int $original_obj_id=-1)
 
 _resolveInternalLink (string $internal_link)
 
 _resolveIntLinks (int $question_id)
 
 syncWithOriginal ()
 
 _questionExists ($question_id)
 Returns true if the question already exists in the database. More...
 
 _questionExistsInPool (int $question_id)
 
 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...
 
 isHTML ($a_text)
 Checks if a given string contains HTML or not. More...
 
 prepareTextareaOutput (string $txt_output, bool $prepare_for_latex_output=false, bool $omitNl2BrWhenTextArea=false)
 
 QTIMaterialToString (ilQTIMaterial $a_material)
 Reads an QTI material tag and creates a text or XHTML string. More...
 
 addQTIMaterial (ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
 
 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 ()
 
 setExportDetailsXLS (ilAssExcelFormatHelper $worksheet, int $startrow, int $active_id, int $pass)
 
 __get ($value)
 Object getter. More...
 
 __set ($key, $value)
 Object setter. More...
 
 __isset ($key)
 Object issetter. More...
 
 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)
 
 isAutosaveable ()
 
 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="", string $owner="", $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 ()
 
 savePartial ()
 
 isInActiveTest ()
 
- Public Member Functions inherited from ilObjQuestionScoringAdjustable
 saveAdditionalQuestionDataToDb ()
 Saves a record to the question types additional data table. More...
 
- Public Member Functions inherited from ilObjAnswerScoringAdjustable
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 

Static Public Member Functions

static getValidScoringModes ()
 
static getScoringModesWithPointsByQuestion ()
 
static getScoringModesWithPointsByKeyword ()
 
static isObligationPossible (int $questionId)
 returns boolean wether it is possible to set this question type as obligatory or not considering the current question configuration More...
 
- Static Public Member Functions inherited from assQuestion
static setForcePassResultUpdateEnabled (bool $forcePassResultsUpdateEnabled)
 
static isForcePassResultUpdateEnabled ()
 
static isAllowedImageMimeType ($mimeType)
 
static fetchMimeTypeIdentifier (string $contentType)
 
static getAllowedFileExtensionsForMimeType (string $mimeType)
 
static isAllowedImageFileExtension (string $mimeType, string $fileExtension)
 
static getAllowedImageMaterialFileExtensions ()
 
static _getMaximumPoints (int $question_id)
 Returns the maximum points, a learner can reach answering the question. More...
 
static _getQuestionInfo (int $question_id)
 
static _getSuggestedSolutionCount (int $question_id)
 
static _getSuggestedSolutionOutput (int $question_id)
 
static _getReachedPoints (int $active_id, int $question_id, int $pass)
 
static _updateTestResultCache (int $active_id, ilAssQuestionProcessLocker $processLocker=null)
 @TODO Move this to a proper place. More...
 
static logAction (string $logtext, int $active_id, int $question_id)
 
static getQuestionTypeFromDb (int $question_id)
 
static _getTotalRightAnswers (int $a_q_id)
 
static _getTitle (int $a_q_id)
 
static _getQuestionText (int $a_q_id)
 
static isFileAvailable (string $file)
 
static _getQuestionType (int $question_id)
 
static _getQuestionTitle (int $question_id)
 
static saveOriginalId (int $questionId, int $originalId)
 
static resetOriginalId (int $questionId)
 
static _getInternalLinkHref (string $target="")
 
static _getOriginalId (int $question_id)
 
static originalQuestionExists (int $questionId)
 
static _instanciateQuestion (int $question_id)
 
static _instantiateQuestion (int $question_id)
 
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 _isUsedInRandomTest (int $question_id)
 
static _isWorkedThrough (int $active_id, int $question_id, int $pass)
 Returns true if the question was worked through in the given pass Worked through means that the user entered at least one value. More...
 
static _areAnswered (int $a_user_id, array $a_question_ids)
 Checks if an array of question ids is answered by a user or not. More...
 
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 _includeClass (string $question_type, int $gui=0)
 
static getFeedbackClassNameByQuestionType (string $questionType)
 
static isCoreQuestionType (string $questionType)
 
static includeCoreClass ($questionType, $withGuiClass)
 
static _getQuestionTypeName ($type_tag)
 
static _instanciateQuestionGUI (int $question_id)
 
static instantiateQuestionGUI (int $a_question_id)
 
static _questionExistsInTest (int $question_id, int $test_id)
 
static lookupParentObjId (int $questionId)
 
static lookupOriginalParentObjId (int $originalQuestionId)
 returns the parent object id for given original question id (should be a qpl id, but theoretically it can be a tst id, too) More...
 
static isObligationPossible (int $questionId)
 
static implodeKeyValues (array $keyValues)
 
static explodeKeyValues (string $keyValues)
 
static convertISO8601FormatH_i_s_ExtendedToSeconds (string $time)
 
static missingResultRecordExists (int $activeId, int $pass, array $questionIds)
 
static getQuestionsMissingResultRecord (int $activeId, int $pass, array $questionIds)
 
static lookupResultRecordExist (int $activeId, int $questionId, int $pass)
 
static extendedTrim (string $value)
 Trim non-printable characters from the beginning and end of a string. More...
 

Data Fields

 $maxNumOfChars
 
 $keywords
 
 $answers
 
 $text_rating
 
 $keyword_relation = 'any'
 
- Data Fields inherited from assQuestion
const IMG_MIME_TYPE_JPG = 'image/jpeg'
 
const IMG_MIME_TYPE_PNG = 'image/png'
 
const IMG_MIME_TYPE_GIF = 'image/gif'
 
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 = ':'
 

Protected Member Functions

 calculateReachedPointsForSolution ($solution)
 
- Protected Member Functions inherited from assQuestion
 getQuestionAction ()
 
 isNonEmptyItemListPostSubmission (string $postSubmissionFieldname)
 
 ensureCurrentTestPass (int $active_id, int $pass)
 
 lookupCurrentTestPass (int $active_id, int $pass)
 
 lookupTestId (int $active_id)
 @refactor Move to ilObjTest or similar More...
 
 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)
 
 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...
 

Protected Attributes

const HAS_SPECIFIC_FEEDBACK = false
 
 $wordCounterEnabled
 
- Protected Attributes inherited from assQuestion
const HAS_SPECIFIC_FEEDBACK = true
 
ILIAS HTTP Services $http
 
ILIAS Refinery Factory $refinery
 
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
 
int $outputType = OUTPUT_JAVASCRIPT
 Contains the output type of a question. More...
 
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
 

Private Member Functions

 isValidTextRating ($textRating)
 

Private Attributes

 $matchcondition
 

Additional Inherited Members

- Static Protected Member Functions inherited from assQuestion
static getNumExistingSolutionRecords (int $activeId, int $pass, int $questionId)
 
- Static Protected Attributes inherited from assQuestion
static $allowedFileExtensionsByMimeType
 
static $allowedCharsetsByMimeType
 
static $allowedImageMaterialFileExtensionsByMimeType
 
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 text questions

assTextQuestion is a class for text questions

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 37 of file class.assTextQuestion.php.

Constructor & Destructor Documentation

◆ __construct()

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

assTextQuestion constructor

The constructor takes possible arguments an creates an instance of the assTextQuestion 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$questionThe question string of the text question

Definition at line 90 of file class.assTextQuestion.php.

96 {
98 $this->wordCounterEnabled = false;
99 $this->maxNumOfChars = 0;
100 $this->points = 1;
101 $this->answers = array();
102 $this->matchcondition = 0;
103 }
string $question
The question text.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addAnswer()

assTextQuestion::addAnswer (   $answertext = "",
  $points = 0.0,
  $points_unchecked = 0.0,
  $order = 0,
  $answerimage = "" 
)

Adds a possible answer for a multiple choice question.

A ASS_AnswerBinaryStateImage object will be created and assigned to the array $this->answers.

Parameters
string$answertextThe answer text
double$pointsThe points for selecting the answer (even negative points can be used)
boolean$stateDefines the answer as correct (TRUE) or incorrect (FALSE)
integer$orderA possible display order of the answer
double$pointsThe points for not selecting the answer (even negative points can be used) @access public
See also
$answers
ASS_AnswerBinaryStateImage

Definition at line 880 of file class.assTextQuestion.php.

886 : void {
887 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
888
889 // add answer
890 $answer = new ASS_AnswerMultipleResponseImage($answertext, $points);
891 $this->answers[] = $answer;
892 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
float $points
The maximum available points for the question.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ calculateReachedPoints()

assTextQuestion::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.

@access public

Parameters
integer$active_id
integer$pass
boolean$returndetails(deprecated !!)
Returns
integer/array $points/$details (array $details is deprecated !!)

Reimplemented from assQuestion.

Definition at line 592 of file class.assTextQuestion.php.

593 {
594 if ($returndetails) {
595 throw new ilTestException('return details not implemented for ' . __METHOD__);
596 }
597
598 global $DIC;
599 $ilDB = $DIC['ilDB'];
600
601 if (is_null($pass)) {
602 $pass = $this->getSolutionMaxPass($active_id);
603 }
604
605 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorizedSolution);
606
607 // Return min points when no answer was given.
608 if ($ilDB->numRows($result) == 0) {
609 return $this->getMinimumPoints();
610 }
611
612 // Return points of points are already on the row.
613 $row = $ilDB->fetchAssoc($result);
614 if ($row["points"] != null) {
615 return $row["points"];
616 }
617
618 return $this->calculateReachedPointsForSolution($row['value1']);
619 }
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getSolutionMaxPass(int $active_id)
calculateReachedPointsForSolution($solution)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28

References $DIC, $ilDB, calculateReachedPointsForSolution(), assQuestion\getCurrentSolutionResultSet(), getMinimumPoints(), and assQuestion\getSolutionMaxPass().

+ Here is the call graph for this function:

◆ calculateReachedPointsForSolution()

assTextQuestion::calculateReachedPointsForSolution (   $solution)
protected

Definition at line 527 of file class.assTextQuestion.php.

528 {
529 $solution = html_entity_decode($solution);
530 // Return min points when keyword relation is NON KEYWORDS
531 if ($this->getKeywordRelation() == 'non') {
532 return $this->getMinimumPoints();
533 }
534
535 // Return min points if there are no answers present.
536 $answers = $this->getAnswers();
537
538 if (count($answers) == 0) {
539 return $this->getMinimumPoints();
540 }
541
542 switch ($this->getKeywordRelation()) {
543 case 'any':
544 $points = 0;
545 foreach ($answers as $answer) {
546 $qst_answer = $answer->getAnswertext();
547 $user_answer = ' ' . $solution;
548 if ($this->isKeywordMatching($user_answer, $qst_answer)) {
549 $points += $answer->getPoints();
550 }
551 }
552 break;
553
554 case 'all':
555 $points = $this->getMaximumPoints();
556 foreach ($answers as $answer) {
557 $qst_answer = $answer->getAnswertext();
558 $user_answer = ' ' . $solution;
559 if (!$this->isKeywordMatching($user_answer, $qst_answer)) {
560 $points = 0;
561 break;
562 }
563 }
564 break;
565
566 case 'one':
567 $points = 0;
568 foreach ($answers as $answer) {
569 $qst_answer = $answer->getAnswertext();
570 $user_answer = ' ' . $solution;
571 if ($this->isKeywordMatching($user_answer, $qst_answer)) {
572 $points = $this->getMaximumPoints();
573 break;
574 }
575 }
576 break;
577 }
578
579 return $points;
580 }
isKeywordMatching($answertext, $a_keyword)
Checks if one of the keywords matches the answertext.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.

References $answers, assQuestion\$points, getAnswers(), getKeywordRelation(), getMaximumPoints(), getMinimumPoints(), and isKeywordMatching().

Referenced by calculateReachedPoints().

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

◆ copyObject()

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

Copies an assTextQuestion object.

@access public

Definition at line 270 of file class.assTextQuestion.php.

270 : int
271 {
272 if ($this->getId() <= 0) {
273 throw new RuntimeException('The question has not been saved. It cannot be duplicated');
274 }
275 // duplicate the question in database
276 $clone = $this;
277 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
279 $clone->id = -1;
280 $source_questionpool_id = $this->getObjId();
281 $clone->setObjId($target_questionpool_id);
282 if ($title) {
283 $clone->setTitle($title);
284 }
285 $clone->saveToDb();
286 // copy question page content
287 $clone->copyPageOfQuestion($original_id);
288 // copy XHTML media objects
289 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
290 // duplicate answers
291 #$clone->duplicateAnswers($original_id);
292
293 $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
294
295 return $clone->id;
296 }
static _getOriginalId(int $question_id)

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

+ Here is the call graph for this function:

◆ countLetters()

assTextQuestion::countLetters (   $text)

Definition at line 1077 of file class.assTextQuestion.php.

1077 : int
1078 {
1079 $text = strip_tags($text);
1080
1081 $text = str_replace('&gt;', '>', $text);
1082 $text = str_replace('&lt;', '<', $text);
1083 $text = str_replace('&nbsp;', ' ', $text);
1084 $text = str_replace('&amp;', '&', $text);
1085
1086 $text = str_replace("\r\n", "\n", $text);
1087 $text = str_replace("\n", "", $text);
1088
1089 return ilStr::strLen($text);
1090 }
static strLen(string $a_string)
Definition: class.ilStr.php:63

References ilStr\strLen().

+ Here is the call graph for this function:

◆ countWords()

assTextQuestion::countWords (   $text)

Definition at line 1092 of file class.assTextQuestion.php.

1092 : int
1093 {
1094 if ($text === '') {
1095 return 0;
1096 }
1097 $text = str_replace('&nbsp;', ' ', $text);
1098
1099 $text = preg_replace('/[.,:;!?\-_#\'"+*\\/=()&%§$]/m', '', $text);
1100
1101 $text = preg_replace('/^\s*/m', '', $text);
1102 $text = preg_replace('/\s*$/m', '', $text);
1103 $text = preg_replace('/\s+/m', ' ', $text);
1104
1105 return count(explode(' ', $text));
1106 }

◆ createNewOriginalFromThisDuplicate()

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

Definition at line 298 of file class.assTextQuestion.php.

298 : int
299 {
300 if ($this->getId() <= 0) {
301 throw new RuntimeException('The question has not been saved. It cannot be duplicated');
302 }
303
304 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
305
306 $sourceQuestionId = $this->id;
307 $sourceParentId = $this->getObjId();
308
309 // duplicate the question in database
310 $clone = $this;
311 $clone->id = -1;
312
313 $clone->setObjId($targetParentId);
314
315 if ($targetQuestionTitle) {
316 $clone->setTitle($targetQuestionTitle);
317 }
318
319 $clone->saveToDb();
320 // copy question page content
321 $clone->copyPageOfQuestion($sourceQuestionId);
322 // copy XHTML media objects
323 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
324 // duplicate answers
325 #$clone->duplicateAnswers($sourceQuestionId);
326
327 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
328
329 return $clone->id;
330 }

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

+ Here is the call graph for this function:

◆ deleteAnswer()

assTextQuestion::deleteAnswer (   $index = 0)

Deletes an answer with a given index.

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

Parameters
integer$indexA nonnegative index of the n-th answer @access public
See also
$answers

Definition at line 931 of file class.assTextQuestion.php.

931 : void
932 {
933 if ($index < 0) {
934 return;
935 }
936 if (count($this->answers) < 1) {
937 return;
938 }
939 if ($index >= count($this->answers)) {
940 return;
941 }
942 $answer = $this->answers[$index];
943 //if (strlen($answer->getImage())) {
944 // $this->deleteImage($answer->getImage());
945 //}
946 unset($this->answers[$index]);
947 $this->answers = array_values($this->answers);
948 for ($i = 0, $iMax = count($this->answers); $i < $iMax; $i++) {
949 if ($this->answers[$i]->getOrder() > $index) {
950 $this->answers[$i]->setOrder($i);
951 }
952 }
953 }
$index
Definition: metadata.php:145
$i
Definition: metadata.php:41

References $i, and $index.

◆ duplicate()

assTextQuestion::duplicate ( bool  $for_test = true,
string  $title = "",
string  $author = "",
string  $owner = "",
  $testObjId = null 
)

Duplicates an assTextQuestion.

@access public

Reimplemented from assQuestion.

Definition at line 218 of file class.assTextQuestion.php.

218 : int
219 {
220 if ($this->id <= 0) {
221 // The question has not been saved. It cannot be duplicated
222 return -1;
223 }
224 // duplicate the question in database
225 $this_id = $this->getId();
226 $thisObjId = $this->getObjId();
227
228 $clone = $this;
229 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
231 $clone->id = -1;
232
233 if ((int) $testObjId > 0) {
234 $clone->setObjId($testObjId);
235 }
236
237 if ($title) {
238 $clone->setTitle($title);
239 }
240
241 if ($author) {
242 $clone->setAuthor($author);
243 }
244 if ($owner) {
245 $clone->setOwner($owner);
246 }
247
248 if ($for_test) {
249 $clone->saveToDb($original_id);
250 } else {
251 $clone->saveToDb();
252 }
253
254 // copy question page content
255 $clone->copyPageOfQuestion($this_id);
256 // copy XHTML media objects
257 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
258 #$clone->duplicateAnswers($this_id);
259
260 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
261
262 return $clone->id;
263 }

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

+ Here is the call graph for this function:

◆ duplicateAnswers()

assTextQuestion::duplicateAnswers (   $original_id)

Definition at line 992 of file class.assTextQuestion.php.

992 : void
993 {
994 global $DIC;
995 $ilDB = $DIC['ilDB'];
996
997 $result = $ilDB->queryF(
998 "SELECT * FROM qpl_a_essay WHERE question_fi = %s",
999 array('integer'),
1000 array($original_id)
1001 );
1002 if ($result->numRows()) {
1003 while ($row = $ilDB->fetchAssoc($result)) {
1004 $next_id = $ilDB->nextId('qpl_a_essay');
1005 $affectedRows = $ilDB->manipulateF(
1006 "INSERT INTO qpl_a_essay (answer_id, question_fi, answertext, points)
1007 VALUES (%s, %s, %s, %s)",
1008 array('integer','integer','text','float'),
1009 array($next_id, $this->getId(), $row["answertext"], $row["points"])
1010 );
1011 }
1012 }
1013 }

References $DIC, $ilDB, and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ flushAnswers()

assTextQuestion::flushAnswers ( )

Deletes all answers.

@access public

See also
$answers

Definition at line 966 of file class.assTextQuestion.php.

966 : void
967 {
968 $this->answers = array();
969 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ getAdditionalTableName()

assTextQuestion::getAdditionalTableName ( )

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

Returns
string The additional table name @access public

Reimplemented from assQuestion.

Definition at line 801 of file class.assTextQuestion.php.

801 : string
802 {
803 return "qpl_qst_essay";
804 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ getAnswer()

assTextQuestion::getAnswer (   $index = 0)

Returns an answer with a given index.

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

Parameters
integer$indexA nonnegative index of the n-th answer
Returns
object ASS_AnswerBinaryStateImage-Object containing the answer @access public
See also
$answers

Definition at line 908 of file class.assTextQuestion.php.

908 : ?object
909 {
910 if ($index < 0) {
911 return null;
912 }
913 if (count($this->answers) < 1) {
914 return null;
915 }
916 if ($index >= count($this->answers)) {
917 return null;
918 }
919
920 return $this->answers[$index];
921 }

References $index.

◆ getAnswerCount()

assTextQuestion::getAnswerCount ( )

Definition at line 862 of file class.assTextQuestion.php.

862 : int
863 {
864 return count($this->answers);
865 }

◆ getAnswers()

assTextQuestion::getAnswers ( )

Definition at line 894 of file class.assTextQuestion.php.

894 : array
895 {
896 return $this->answers;
897 }

Referenced by calculateReachedPointsForSolution().

+ Here is the caller graph for this function:

◆ getAnswerTableName()

assTextQuestion::getAnswerTableName ( )
Returns
string|array Or Array?
See also
Deletion methods here

Reimplemented from assQuestion.

Definition at line 955 of file class.assTextQuestion.php.

955 : string
956 {
957 return 'qpl_a_essay';
958 }

◆ getKeywordRelation()

assTextQuestion::getKeywordRelation ( )

Definition at line 1015 of file class.assTextQuestion.php.

1016 {
1018 }

Referenced by calculateReachedPointsForSolution(), getMaximumPoints(), and getMinimumPoints().

+ Here is the caller graph for this function:

◆ getLatestAutosaveContent()

assTextQuestion::getLatestAutosaveContent ( int  $active_id,
int  $pass 
)

Definition at line 1108 of file class.assTextQuestion.php.

1108 : ?string
1109 {
1110 // Do we have an unauthorized result?
1111 $cntresult = $this->db->query(
1112 '
1113 SELECT count(solution_id) cnt
1114 FROM tst_solutions
1115 WHERE active_fi = ' . $this->db->quote($active_id, 'int') . '
1116 AND question_fi = ' . $this->db->quote($this->getId(), 'int') . '
1117 AND authorized = ' . $this->db->quote(0, 'int')
1118 . ' AND pass = ' . $this->db->quote($pass, 'int')
1119 );
1120 $row = $this->db->fetchAssoc($cntresult);
1121 if ($row['cnt'] > 0) {
1122 $tresult = $this->db->query(
1123 '
1124 SELECT value1
1125 FROM tst_solutions
1126 WHERE active_fi = ' . $this->db->quote($active_id, 'int') . '
1127 AND question_fi = ' . $this->db->quote($this->getId(), 'int') . '
1128 AND authorized = ' . $this->db->quote(0, 'int')
1129 . ' AND pass = ' . $this->db->quote($pass, 'int')
1130 );
1131 $trow = $this->db->fetchAssoc($tresult);
1132 return $trow['value1'];
1133 }
1134 return null;
1135 }

◆ getMatchcondition()

assTextQuestion::getMatchcondition ( )

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

105 : int
106 {
108 }

References $matchcondition.

◆ getMaximumPoints()

assTextQuestion::getMaximumPoints ( )

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

@access public

See also
$points

Reimplemented from assQuestion.

Definition at line 382 of file class.assTextQuestion.php.

382 : float
383 {
384 if (in_array($this->getKeywordRelation(), self::getScoringModesWithPointsByQuestion())) {
385 return parent::getPoints();
386 }
387
388 $points = 0;
389
390 foreach ($this->answers as $answer) {
391 if ($answer->getPoints() > 0) {
392 $points = $points + $answer->getPoints();
393 }
394 }
395
396 return $points;
397 }

References assQuestion\$points, and getKeywordRelation().

Referenced by calculateReachedPointsForSolution(), and isComplete().

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

◆ getMaxNumOfChars()

assTextQuestion::getMaxNumOfChars ( )

Gets the maximum number of characters for the text solution.

Returns
integer The maximum number of characters for the text solution @access public
See also
$maxNumOfChars

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

339 : int
340 {
341 if (strcmp($this->maxNumOfChars, "") == 0) {
342 return 0;
343 } else {
345 }
346 }

References $maxNumOfChars.

Referenced by toJSON().

+ Here is the caller graph for this function:

◆ getMinimumPoints()

assTextQuestion::getMinimumPoints ( )

Definition at line 399 of file class.assTextQuestion.php.

400 {
401 if (in_array($this->getKeywordRelation(), self::getScoringModesWithPointsByQuestion())) {
402 return 0;
403 }
404
405 $points = 0;
406
407 foreach ($this->answers as $answer) {
408 if ($answer->getPoints() < 0) {
409 $points = $points + $answer->getPoints();
410 }
411 }
412
413 return $points;
414 }

References assQuestion\$points, and getKeywordRelation().

Referenced by calculateReachedPoints(), and calculateReachedPointsForSolution().

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

◆ getQuestionType()

assTextQuestion::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question @access public

Reimplemented from assQuestion.

Definition at line 753 of file class.assTextQuestion.php.

753 : string
754 {
755 return "assTextQuestion";
756 }

Referenced by toJSON().

+ Here is the caller graph for this function:

◆ getRTETextWithMediaObjects()

assTextQuestion::getRTETextWithMediaObjects ( )

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

Reimplemented from assQuestion.

Definition at line 810 of file class.assTextQuestion.php.

810 : string
811 {
812 return parent::getRTETextWithMediaObjects();
813 }

◆ getScoringModesWithPointsByKeyword()

static assTextQuestion::getScoringModesWithPointsByKeyword ( )
static

Definition at line 1039 of file class.assTextQuestion.php.

1039 : array
1040 {
1041 return array('any');
1042 }

Referenced by assTextQuestionGUI\getBestAnswer().

+ Here is the caller graph for this function:

◆ getScoringModesWithPointsByQuestion()

static assTextQuestion::getScoringModesWithPointsByQuestion ( )
static

Definition at line 1034 of file class.assTextQuestion.php.

1034 : array
1035 {
1036 return array('non', 'all', 'one');
1037 }

◆ getSolutionSubmit()

assTextQuestion::getSolutionSubmit ( )
Returns
mixed|string

Definition at line 679 of file class.assTextQuestion.php.

680 {
681 if (ilObjAdvancedEditing::_getRichTextEditor() === 'tinymce') {
682 $text = ilUtil::stripSlashes($_POST["TEXT"], false);
683 } else {
684 $text = htmlentities($_POST["TEXT"]);
685 }
686
687 if (ilUtil::isHTML($text)) {
688 $text = $this->getHtmlUserSolutionPurifier()->purify($text);
689 }
690
691 return $text;
692 }
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
static isHTML(string $a_text)
Checks if a given string contains HTML or not.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")

References ilObjAdvancedEditing\_getRichTextEditor(), assQuestion\getHtmlUserSolutionPurifier(), ilUtil\isHTML(), and ilUtil\stripSlashes().

Referenced by saveWorkingData().

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

◆ getTextRating()

assTextQuestion::getTextRating ( )

Returns the rating option for text comparisons.

Returns
string The rating option for text comparisons
See also
$text_rating @access public

Definition at line 765 of file class.assTextQuestion.php.

765 : string
766 {
767 return $this->text_rating;
768 }

References $text_rating.

Referenced by isKeywordMatching().

+ Here is the caller graph for this function:

◆ getValidScoringModes()

static assTextQuestion::getValidScoringModes ( )
static

Definition at line 1029 of file class.assTextQuestion.php.

1029 : array
1030 {
1031 return array_merge(self::getScoringModesWithPointsByQuestion(), self::getScoringModesWithPointsByKeyword());
1032 }

◆ isAnswered()

assTextQuestion::isAnswered ( int  $active_id,
int  $pass 
)

returns boolean wether the question is answered during test pass or not

(overwrites method in class assQuestion)

Parameters
integer$active_id
integer$pass
Returns
boolean $answered

Reimplemented from assQuestion.

Definition at line 1055 of file class.assTextQuestion.php.

1055 : bool
1056 {
1057 $numExistingSolutionRecords = assQuestion::getNumExistingSolutionRecords($active_id, $pass, $this->getId());
1058
1059 return $numExistingSolutionRecords > 0;
1060 }
static getNumExistingSolutionRecords(int $activeId, int $pass, int $questionId)

References ILIAS\Survey\Mode\getId(), and assQuestion\getNumExistingSolutionRecords().

+ Here is the call graph for this function:

◆ isComplete()

assTextQuestion::isComplete ( )

Returns true, if a multiple choice question is complete for use.

Returns
boolean True, if the multiple choice question is complete for use, otherwise false

Reimplemented from assQuestion.

Definition at line 120 of file class.assTextQuestion.php.

120 : bool
121 {
122 if (strlen($this->title)
123 && $this->author
124 && $this->question
125 && $this->getMaximumPoints() > 0
126 ) {
127 return true;
128 }
129 return false;
130 }

References getMaximumPoints().

+ Here is the call graph for this function:

◆ isKeywordMatching()

assTextQuestion::isKeywordMatching (   $answertext,
  $a_keyword 
)

Checks if one of the keywords matches the answertext.

Parameters
string$answertextThe answertext of the user
string$a_keywordThe keyword which should be checked
Returns
boolean TRUE if the keyword matches, FALSE otherwise @access private

Definition at line 469 of file class.assTextQuestion.php.

469 : bool
470 {
471 global $DIC;
472 $refinery = $DIC->refinery();
473 $result = false;
474 $textrating = $this->getTextRating();
475 include_once "./Services/Utilities/classes/class.ilStr.php";
476
477 switch ($textrating) {
479 if (ilStr::strPos(ilStr::strToLower($answertext), ilStr::strToLower($a_keyword)) !== false) {
480 return true;
481 }
482 break;
484 if (ilStr::strPos($answertext, $a_keyword) !== false) {
485 return true;
486 }
487 break;
488 }
489
490 // "<p>red</p>" would not match "red" even with distance of 5
491 $answertext = strip_tags($answertext);
492 $answerwords = array();
493 if (preg_match_all("/([^\s.]+)/", $answertext, $matches)) {
494 foreach ($matches[1] as $answerword) {
495 array_push($answerwords, trim($answerword));
496 }
497 }
498
499 // create correct transformation
500 switch ($textrating) {
502 $transformation = $refinery->string()->levenshtein()->standard($a_keyword, 1);
503 break;
505 $transformation = $refinery->string()->levenshtein()->standard($a_keyword, 2);
506 break;
508 $transformation = $refinery->string()->levenshtein()->standard($a_keyword, 3);
509 break;
511 $transformation = $refinery->string()->levenshtein()->standard($a_keyword, 4);
512 break;
514 $transformation = $refinery->string()->levenshtein()->standard($a_keyword, 5);
515 break;
516 }
517
518 // run answers against Levenshtein methods
519 foreach ($answerwords as $a_original) {
520 if (isset($transformation) && $transformation->transform($a_original) >= 0) {
521 return true;
522 }
523 }
524 return $result;
525 }
ILIAS Refinery Factory $refinery
getTextRating()
Returns the rating option for text comparisons.
static strPos(string $a_haystack, string $a_needle, ?int $a_offset=null)
Definition: class.ilStr.php:42
static strToLower(string $a_string)
Definition: class.ilStr.php:72
const TEXTGAP_RATING_LEVENSHTEIN5
const TEXTGAP_RATING_LEVENSHTEIN4
const TEXTGAP_RATING_LEVENSHTEIN3
const TEXTGAP_RATING_CASESENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN2
const TEXTGAP_RATING_CASEINSENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN1

References $DIC, assQuestion\$refinery, getTextRating(), ilStr\strPos(), ilStr\strToLower(), TEXTGAP_RATING_CASEINSENSITIVE, TEXTGAP_RATING_CASESENSITIVE, TEXTGAP_RATING_LEVENSHTEIN1, TEXTGAP_RATING_LEVENSHTEIN2, TEXTGAP_RATING_LEVENSHTEIN3, TEXTGAP_RATING_LEVENSHTEIN4, and TEXTGAP_RATING_LEVENSHTEIN5.

Referenced by calculateReachedPointsForSolution().

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

◆ isObligationPossible()

static assTextQuestion::isObligationPossible ( int  $questionId)
static

returns boolean wether it is possible to set this question type as obligatory or not considering the current question configuration

(overwrites method in class assQuestion)

Parameters
integer$questionId
Returns
boolean $obligationPossible

Reimplemented from assQuestion.

Definition at line 1072 of file class.assTextQuestion.php.

1072 : bool
1073 {
1074 return true;
1075 }

◆ isValidTextRating()

assTextQuestion::isValidTextRating (   $textRating)
private

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

445 : bool
446 {
447 switch ($textRating) {
455 return true;
456 }
457
458 return false;
459 }

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

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ isWordCounterEnabled()

assTextQuestion::isWordCounterEnabled ( )
Returns
bool

Definition at line 363 of file class.assTextQuestion.php.

363 : bool
364 {
366 }

References $wordCounterEnabled.

◆ loadFromDb()

assTextQuestion::loadFromDb (   $question_id)

Loads a assTextQuestion object from a database.

Parameters
object$dbA pear DB object
integer$question_idA unique key which defines the text question in the database @access public

Definition at line 157 of file class.assTextQuestion.php.

157 : void
158 {
159 global $DIC;
160 $ilDB = $DIC['ilDB'];
161
162 $result = $ilDB->queryF(
163 "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",
164 array("integer"),
165 array($question_id)
166 );
167 if ($ilDB->numRows($result) == 1) {
168 $data = $ilDB->fetchAssoc($result);
169 $this->setId($question_id);
170 $this->setObjId($data["obj_fi"]);
171 $this->setTitle((string) $data["title"]);
172 $this->setComment((string) $data["description"]);
173 $this->setOriginalId($data["original_id"]);
174 $this->setNrOfTries($data['nr_of_tries']);
175 $this->setAuthor($data["author"]);
176 $this->setPoints((float) $data["points"]);
177 $this->setOwner($data["owner"]);
178 include_once("./Services/RTE/classes/class.ilRTE.php");
179 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc((string) $data["question_text"], 1));
180 $this->setShuffle(false);
181 $this->setWordCounterEnabled((bool) $data['word_cnt_enabled']);
182 $this->setMaxNumOfChars($data["maxnumofchars"]);
183 $this->setTextRating($this->isValidTextRating($data["textgap_rating"]) ? $data["textgap_rating"] : TEXTGAP_RATING_CASEINSENSITIVE);
184 $this->matchcondition = (strlen($data['matchcondition'])) ? (int) $data['matchcondition'] : 0;
185 $this->setKeywordRelation(($data['keyword_relation']));
186
187 try {
191 }
192
193 try {
194 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
196 }
197 }
198
199 $result = $ilDB->queryF(
200 "SELECT * FROM qpl_a_essay WHERE question_fi = %s",
201 array("integer"),
202 array($this->getId())
203 );
204
205 $this->flushAnswers();
206 while ($row = $ilDB->fetchAssoc($result)) {
207 $this->addAnswer($row['answertext'], $row['points']);
208 }
209
210 parent::loadFromDb($question_id);
211 }
setOriginalId(?int $original_id)
setId(int $id=-1)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setShuffle(?bool $shuffle=true)
setQuestion(string $question="")
setAuthor(string $author="")
setComment(string $comment="")
setObjId(int $obj_id=0)
setOwner(int $owner=-1)
setNrOfTries(int $a_nr_of_tries)
setLifecycle(ilAssQuestionLifecycle $lifecycle)
setTitle(string $title="")
setPoints(float $points)
setMaxNumOfChars($maxchars=0)
Sets the maximum number of characters for the text solution.
addAnswer( $answertext="", $points=0.0, $points_unchecked=0.0, $order=0, $answerimage="")
Adds a possible answer for a multiple choice question.
setKeywordRelation($a_relation)
This method implements a default behaviour.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setWordCounterEnabled($wordCounterEnabled)
flushAnswers()
Deletes all answers.
setTextRating($a_text_rating)
Sets the rating option for text comparisons.
isValidTextRating($textRating)
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...

References $data, $DIC, Vendor\Package\$e, $ilDB, ilRTE\_replaceMediaObjectImageSrc(), addAnswer(), flushAnswers(), getAdditionalTableName(), ilAssQuestionLifecycle\getDraftInstance(), assQuestion\getId(), ilAssQuestionLifecycle\getInstance(), isValidTextRating(), assQuestion\setAdditionalContentEditingMode(), assQuestion\setAuthor(), assQuestion\setComment(), assQuestion\setId(), setKeywordRelation(), assQuestion\setLifecycle(), setMaxNumOfChars(), assQuestion\setNrOfTries(), assQuestion\setObjId(), assQuestion\setOriginalId(), assQuestion\setOwner(), assQuestion\setPoints(), assQuestion\setQuestion(), assQuestion\setShuffle(), setTextRating(), assQuestion\setTitle(), setWordCounterEnabled(), and TEXTGAP_RATING_CASEINSENSITIVE.

+ Here is the call graph for this function:

◆ saveToDb()

assTextQuestion::saveToDb (   $original_id = "")

Saves a assTextQuestion object to a database.

Parameters
string$original_id

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

137 : void
138 {
139 if ($original_id == '') {
140 $this->saveQuestionDataToDb();
141 } else {
143 }
144
147 parent::saveToDb();
148 }
saveQuestionDataToDb(int $original_id=-1)
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.

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

+ Here is the call graph for this function:

◆ saveWorkingData()

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

Saves the learners input of the question to the database.

@access public

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

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

629 : bool
630 {
631 global $DIC;
632 $ilDB = $DIC['ilDB'];
633 $ilUser = $DIC['ilUser'];
634
635 include_once "./Services/Utilities/classes/class.ilStr.php";
636 if (is_null($pass)) {
637 include_once "./Modules/Test/classes/class.ilObjTest.php";
638 $pass = ilObjTest::_getPass($active_id);
639 }
640
641 $entered_values = 0;
642 $text = $this->getSolutionSubmit();
643
644 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(function () use (&$entered_values, $active_id, $pass, $authorized, $text) {
645 $this->removeCurrentSolution($active_id, $pass, $authorized);
646
647 if (strlen($text)) {
648 $this->saveCurrentSolution($active_id, $pass, trim($text), null, $authorized);
649 $entered_values++;
650 }
651 });
652
653 if ($entered_values) {
654 include_once("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
656 assQuestion::logAction($this->lng->txtlng(
657 "assessment",
658 "log_user_entered_values",
660 ), $active_id, $this->getId());
661 }
662 } else {
663 include_once("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
665 assQuestion::logAction($this->lng->txtlng(
666 "assessment",
667 "log_user_not_entered_values",
669 ), $active_id, $this->getId());
670 }
671 }
672
673 return true;
674 }
static logAction(string $logtext, int $active_id, int $question_id)
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
$ilUser
Definition: imgupload.php:34

References $DIC, $ilDB, $ilUser, ilObjAssessmentFolder\_enabledAssessmentLogging(), ilObjAssessmentFolder\_getLogLanguage(), ilObjTest\_getPass(), assQuestion\getProcessLocker(), getSolutionSubmit(), ILIAS\Repository\lng(), assQuestion\logAction(), assQuestion\removeCurrentSolution(), and assQuestion\saveCurrentSolution().

+ Here is the call graph for this function:

◆ setAnswers()

assTextQuestion::setAnswers (   $answers)

Definition at line 971 of file class.assTextQuestion.php.

971 : void
972 {
973 if (isset($answers['answer'])) {
974 $count = count($answers['answer']);
975 $withPoints = true;
976 } else {
977 $count = count($answers);
978 $withPoints = false;
979 }
980
981 $this->flushAnswers();
982
983 for ($i = 0; $i < $count; $i++) {
984 if ($withPoints) {
985 $this->addAnswer($answers['answer'][$i], $answers['points'][$i]);
986 } else {
987 $this->addAnswer($answers[$i], 0);
988 }
989 }
990 }

References $i.

◆ setExportDetailsXLS()

assTextQuestion::setExportDetailsXLS ( ilAssExcelFormatHelper  $worksheet,
int  $startrow,
int  $active_id,
int  $pass 
)

{}

Reimplemented from assQuestion.

Definition at line 818 of file class.assTextQuestion.php.

818 : int
819 {
820 parent::setExportDetailsXLS($worksheet, $startrow, $active_id, $pass);
821
822 $solutions = $this->getSolutionValues($active_id, $pass);
823
824 $i = 1;
825 $worksheet->setCell($startrow + $i, 0, $this->lng->txt("result"));
826 $worksheet->setBold($worksheet->getColumnCoord(0) . ($startrow + $i));
827
828 require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
829 $assessment_folder = new ilObjAssessmentFolder();
830
831 $string_escaping_org_value = $worksheet->getStringEscaping();
832 if ($assessment_folder->getExportEssayQuestionsWithHtml()) {
833 $worksheet->setStringEscaping(false);
834 }
835
836 if (array_key_exists(0, $solutions) && strlen($solutions[0]["value1"])) {
837 $worksheet->setCell($startrow + $i, 2, html_entity_decode($solutions[0]["value1"]));
838 }
839 $i++;
840
841 $worksheet->setStringEscaping($string_escaping_org_value);
842 return $startrow + $i + 1;
843 }
getSolutionValues($active_id, $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
setCell($a_row, $a_col, $a_value, $datatype=null)
setBold(string $a_coords)
Set cell(s) to bold.
getColumnCoord(int $a_col)
Get column "name" from number.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

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

+ Here is the call graph for this function:

◆ setKeywordRelation()

assTextQuestion::setKeywordRelation (   $a_relation)

This method implements a default behaviour.

During the creation of a text question, the record which holds the keyword relation is not existing, so keyword_relation defaults to 'one'.

Definition at line 1024 of file class.assTextQuestion.php.

1024 : void
1025 {
1026 $this->keyword_relation = $a_relation;
1027 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setMatchcondition()

assTextQuestion::setMatchcondition ( int  $matchcondition)

Definition at line 110 of file class.assTextQuestion.php.

110 : void
111 {
112 $this->matchcondition = $matchcondition;
113 }

References $matchcondition.

◆ setMaxNumOfChars()

assTextQuestion::setMaxNumOfChars (   $maxchars = 0)

Sets the maximum number of characters for the text solution.

Parameters
integer$maxcharsThe maximum number of characters for the text solution @access public
See also
$maxNumOfChars

Definition at line 355 of file class.assTextQuestion.php.

355 : void
356 {
357 $this->maxNumOfChars = $maxchars;
358 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setReachedPoints()

assTextQuestion::setReachedPoints (   $active_id,
  $points,
  $pass = null 
)

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

Parameters
integer$user_idThe database ID of the learner
integer$test_idThe database Id of the test containing the question
integer$pointsThe points the user has reached answering the question
Returns
boolean true on success, otherwise false @access public

Definition at line 424 of file class.assTextQuestion.php.

424 : bool
425 {
426 global $DIC;
427 $ilDB = $DIC['ilDB'];
428
429 if (($points > 0) && ($points <= $this->getPoints())) {
430 if (is_null($pass)) {
431 $pass = $this->getSolutionMaxPass($active_id);
432 }
433 $affectedRows = $ilDB->manipulateF(
434 "UPDATE tst_test_result SET points = %s WHERE active_fi = %s AND question_fi = %s AND pass = %s",
435 array('float','integer','integer','integer'),
436 array($points, $active_id, $this->getId(), $pass)
437 );
438 self::_updateTestPassResults($active_id, $pass);
439 return true;
440 } else {
441 return true;
442 }
443 }

References $DIC, $ilDB, assQuestion\$points, assQuestion\getId(), assQuestion\getPoints(), and assQuestion\getSolutionMaxPass().

+ Here is the call graph for this function:

◆ setTextRating()

assTextQuestion::setTextRating (   $a_text_rating)

Sets the rating option for text comparisons.

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

Definition at line 777 of file class.assTextQuestion.php.

777 : void
778 {
779 switch ($a_text_rating) {
787 $this->text_rating = $a_text_rating;
788 break;
789 default:
790 $this->text_rating = TEXTGAP_RATING_CASEINSENSITIVE;
791 break;
792 }
793 }

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

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setWordCounterEnabled()

assTextQuestion::setWordCounterEnabled (   $wordCounterEnabled)
Parameters
bool$wordCounterEnabled

Definition at line 371 of file class.assTextQuestion.php.

371 : void
372 {
373 $this->wordCounterEnabled = $wordCounterEnabled;
374 }

References $wordCounterEnabled.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ toJSON()

assTextQuestion::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

Definition at line 848 of file class.assTextQuestion.php.

848 : string
849 {
850 include_once("./Services/RTE/classes/class.ilRTE.php");
851 $result = array();
852 $result['id'] = $this->getId();
853 $result['type'] = (string) $this->getQuestionType();
854 $result['title'] = $this->getTitleForHTMLOutput();
855 $result['question'] = $this->formatSAQuestion($this->getQuestion());
856 $result['nr_of_tries'] = $this->getNrOfTries();
857 $result['shuffle'] = $this->getShuffle();
858 $result['maxlength'] = $this->getMaxNumOfChars();
859 return json_encode($result);
860 }
getQuestionType()
Returns the question type of the question.
getMaxNumOfChars()
Gets the maximum number of characters for the text solution.

References assQuestion\formatSAQuestion(), assQuestion\getId(), getMaxNumOfChars(), assQuestion\getNrOfTries(), assQuestion\getQuestion(), getQuestionType(), assQuestion\getShuffle(), and assQuestion\getTitleForHTMLOutput().

+ Here is the call graph for this function:

Field Documentation

◆ $answers

assTextQuestion::$answers

Definition at line 64 of file class.assTextQuestion.php.

Referenced by calculateReachedPointsForSolution().

◆ $keyword_relation

assTextQuestion::$keyword_relation = 'any'

Definition at line 76 of file class.assTextQuestion.php.

◆ $keywords

assTextQuestion::$keywords

Definition at line 62 of file class.assTextQuestion.php.

◆ $matchcondition

assTextQuestion::$matchcondition
private

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

Referenced by getMatchcondition(), and setMatchcondition().

◆ $maxNumOfChars

assTextQuestion::$maxNumOfChars

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

Referenced by getMaxNumOfChars().

◆ $text_rating

assTextQuestion::$text_rating

Definition at line 71 of file class.assTextQuestion.php.

Referenced by getTextRating().

◆ $wordCounterEnabled

assTextQuestion::$wordCounterEnabled
protected

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

Referenced by isWordCounterEnabled(), and setWordCounterEnabled().

◆ HAS_SPECIFIC_FEEDBACK

const assTextQuestion::HAS_SPECIFIC_FEEDBACK = false
protected

Definition at line 39 of file class.assTextQuestion.php.


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