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

Public Member Functions

 __construct ( $title="", $comment="", $author="", $owner=-1, $question="", $output_type=OUTPUT_ORDER)
 assSingleChoice constructor More...
 
 isComplete ()
 Returns true, if a single choice question is complete for use. More...
 
 getThumbPrefix ()
 
 loadFromDb ($question_id)
 Loads a assSingleChoice object from a database. More...
 
 duplicate (bool $for_test=true, string $title="", string $author="", string $owner="", $testObjId=null)
 Duplicates an assSingleChoiceQuestion. More...
 
 copyObject ($target_questionpool_id, $title="")
 Copies an assSingleChoice object. More...
 
 createNewOriginalFromThisDuplicate ($targetParentId, $targetQuestionTitle="")
 
 getOutputType ()
 Gets the single choice output type which is either OUTPUT_ORDER (=0) or OUTPUT_RANDOM (=1). More...
 
 setOutputType ($output_type=OUTPUT_ORDER)
 Sets the output type of the assSingleChoice object. More...
 
 addAnswer ( $answertext="", $points=0.0, $order=0, $answerimage="", $answer_id=-1)
 Adds a possible answer for a single choice question. More...
 
 getAnswerCount ()
 Returns the number of answers. More...
 
 getAnswer ($index=0)
 Returns an answer with a given index. More...
 
 deleteAnswer ($index=0)
 Deletes an answer with a given index. More...
 
 flushAnswers ()
 Deletes all answers. More...
 
 getMaximumPoints ()
 Returns the maximum points, a learner can reach answering the question. More...
 
 calculateReachedPoints ($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
 Returns the points, a learner has reached answering the question. More...
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $previewSession)
 
 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...
 
 getAdditionalTableName ()
 Returns the name of the additional question data table in the database. More...
 
 getAnswerTableName ()
 Returns the name of the answer table in the database. More...
 
 setImageFile ($image_filename, $image_tempfilename="")
 Sets the image file and uploads the image to the object's image directory. More...
 
 deleteImage ($image_filename)
 Deletes an image file. More...
 
 duplicateImages ($question_id, $objectId=null)
 
 getRTETextWithMediaObjects ()
 Collects all text in the question which could contain media objects which were created with the Rich Text Editor. More...
 
getAnswers ()
 Returns a reference to the answers array. More...
 
 setExportDetailsXLS (ilAssExcelFormatHelper $worksheet, int $startrow, int $active_id, int $pass)
 {} More...
 
 toJSON ()
 Returns a JSON representation of the question. More...
 
 removeAnswerImage ($index)
 
 getMultilineAnswerSetting ()
 
 setMultilineAnswerSetting ($a_setting=0)
 
 setSpecificFeedbackSetting ($a_feedback_setting)
 Sets the feedback settings in effect for the question. More...
 
 getSpecificFeedbackSetting ()
 Gets the current feedback settings in effect for the question. More...
 
 getSpecificFeedbackAllCorrectOptionLabel ()
 
 isAnswered (int $active_id, int $pass)
 returns boolean wether the question is answered during test pass or not 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...
 
 isSingleline ()
 
 setIsSingleline (bool $isSingleline)
 
 getFeedbackSetting ()
 
 setFeedbackSetting (int $feedback_setting)
 
- 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...
 
- Public Member Functions inherited from iQuestionCondition
 getOperators ($expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. More...
 
 getUserQuestionResult ($active_id, $pass)
 Get the user solution for a question by active_id and the test pass. More...
 
 getAvailableAnswerOptions ($index=null)
 If index is null, the function returns an array with all anwser options Else it returns the specific answer option. More...
 
 getSpecificFeedbackAllCorrectOptionLabel ()
 

Static Public Member Functions

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

 $answers
 
 $output_type
 
- 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 = ':'
 
- 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

 rebuildThumbnails ()
 
 generateThumbForFile ($path, $file)
 
 savePreviewData (ilAssQuestionPreviewSession $previewSession)
 
 syncImages ()
 Sync images of a MC question on synchronisation with the original question. More...
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 afterSyncWithOriginal ($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)
 {} More...
 
- 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

 $feedback_setting
 
- 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 Attributes

bool $isSingleline = true
 

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 single choice questions

assSingleChoice is a class for single choice 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 34 of file class.assSingleChoice.php.

Constructor & Destructor Documentation

◆ __construct()

assSingleChoice::__construct (   $title = "",
  $comment = "",
  $author = "",
  $owner = -1,
  $question = "",
  $output_type = OUTPUT_ORDER 
)

assSingleChoice constructor

The constructor takes possible arguments an creates an instance of the assSingleChoice 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 single choice question
int | string$output_typeThe output order of the single choice answers
See also
assQuestion:assQuestion()

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

86 {
88 $this->output_type = $output_type;
89 $this->answers = array();
90 $this->shuffle = 1;
91 $this->feedback_setting = 2;
92 }
string $question
The question text.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addAnswer()

assSingleChoice::addAnswer (   $answertext = "",
  $points = 0.0,
  $order = 0,
  $answerimage = "",
  $answer_id = -1 
)

Adds a possible answer for a single 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 427 of file class.assSingleChoice.php.

433 : void {
434 $answertext = $this->getHtmlQuestionContentPurifier()->purify($answertext);
435 if (array_key_exists($order, $this->answers)) {
436 // insert answer
437 $answer = new ASS_AnswerBinaryStateImage($answertext, $points, $order, 1, $answerimage, $answer_id);
438 $newchoices = array();
439 for ($i = 0; $i < $order; $i++) {
440 $newchoices[] = $this->answers[$i];
441 }
442 $newchoices[] = $answer;
443 for ($i = $order, $iMax = count($this->answers); $i < $iMax; $i++) {
444 $changed = $this->answers[$i];
445 $changed->setOrder($i + 1);
446 $newchoices[] = $changed;
447 }
448 $this->answers = $newchoices;
449 } else {
450 $answer = new ASS_AnswerBinaryStateImage(
451 $answertext,
452 $points,
453 count($this->answers),
454 1,
455 $answerimage,
456 $answer_id
457 );
458 $this->answers[] = $answer;
459 }
460 }
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.
$i
Definition: metadata.php:41

References $i, and assQuestion\$points.

◆ afterSyncWithOriginal()

assSingleChoice::afterSyncWithOriginal (   $origQuestionId,
  $dupQuestionId,
  $origParentObjId,
  $dupParentObjId 
)
protected

{}

Definition at line 1348 of file class.assSingleChoice.php.

1348 : void
1349 {
1350 parent::afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId);
1351
1352 $origImagePath = $this->buildImagePath($origQuestionId, $origParentObjId);
1353 $dupImagePath = $this->buildImagePath($dupQuestionId, $dupParentObjId);
1354
1355 ilFileUtils::delDir($origImagePath);
1356 if (is_dir($dupImagePath)) {
1357 ilFileUtils::makeDirParents($origImagePath);
1358 ilFileUtils::rCopy($dupImagePath, $origImagePath);
1359 }
1360 }
buildImagePath($questionId, $parentObjectId)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.

References ilFileUtils\delDir(), ilFileUtils\makeDirParents(), and ilFileUtils\rCopy().

+ Here is the call graph for this function:

◆ calculateReachedPoints()

assSingleChoice::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 568 of file class.assSingleChoice.php.

569 {
570 if ($returndetails) {
571 throw new ilTestException('return details not implemented for ' . __METHOD__);
572 }
573
574 global $DIC;
575 $ilDB = $DIC['ilDB'];
576
577 $found_values = array();
578 if (is_null($pass)) {
579 $pass = $this->getSolutionMaxPass($active_id);
580 }
581 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorizedSolution);
582 while ($data = $ilDB->fetchAssoc($result)) {
583 if (strcmp($data["value1"], "") != 0) {
584 array_push($found_values, $data["value1"]);
585 }
586 }
587 $points = 0;
588 foreach ($this->answers as $key => $answer) {
589 if (count($found_values) > 0) {
590 if (in_array($key, $found_values)) {
591 $points += $answer->getPoints();
592 }
593 }
594 }
595
596 return $points;
597 }
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getSolutionMaxPass(int $active_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
string $key
Consumer key/client ID value.
Definition: System.php:193

References $data, $DIC, $ilDB, and ILIAS\LTI\ToolProvider\$key.

◆ calculateReachedPointsFromPreviewSession()

assSingleChoice::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $previewSession)

Reimplemented from assQuestion.

Definition at line 599 of file class.assSingleChoice.php.

600 {
601 $participantSolution = $previewSession->getParticipantsSolution();
602
603 $points = 0;
604
605 foreach ($this->answers as $key => $answer) {
606 if (is_numeric($participantSolution) && $key == $participantSolution) {
607 $points = $answer->getPoints();
608 }
609 }
610
611 $reachedPoints = $this->deductHintPointsFromReachedPoints($previewSession, $points);
612
613 return $this->ensureNonNegativePoints($reachedPoints);
614 }
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
ensureNonNegativePoints($points)

References ILIAS\LTI\ToolProvider\$key, and ilAssQuestionPreviewSession\getParticipantsSolution().

+ Here is the call graph for this function:

◆ copyObject()

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

Copies an assSingleChoice object.

@access public

Definition at line 331 of file class.assSingleChoice.php.

331 : int
332 {
333 if ($this->getId() <= 0) {
334 throw new RuntimeException('The question has not been saved. It cannot be duplicated');
335 }
336 // duplicate the question in database
337 $clone = $this;
339 $clone->id = -1;
340 $source_questionpool_id = $this->getObjId();
341 $clone->setObjId($target_questionpool_id);
342 if ($title) {
343 $clone->setTitle($title);
344 }
345 $clone->saveToDb();
346 // copy question page content
347 $clone->copyPageOfQuestion($original_id);
348 // copy XHTML media objects
349 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
350 // duplicate the image
351 $clone->copyImages($original_id, $source_questionpool_id);
352
353 $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
354
355 return $clone->id;
356 }
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:

◆ createNewOriginalFromThisDuplicate()

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

Definition at line 358 of file class.assSingleChoice.php.

358 : int
359 {
360 if ($this->getId() <= 0) {
361 throw new RuntimeException('The question has not been saved. It cannot be duplicated');
362 }
363
364 $sourceQuestionId = $this->id;
365 $sourceParentId = $this->getObjId();
366
367 // duplicate the question in database
368 $clone = $this;
369 $clone->id = -1;
370
371 $clone->setObjId($targetParentId);
372
373 if ($targetQuestionTitle) {
374 $clone->setTitle($targetQuestionTitle);
375 }
376
377 $clone->saveToDb();
378 // copy question page content
379 $clone->copyPageOfQuestion($sourceQuestionId);
380 // copy XHTML media objects
381 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
382 // duplicate the image
383 $clone->copyImages($sourceQuestionId, $sourceParentId);
384
385 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
386
387 return $clone->id;
388 }

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

+ Here is the call graph for this function:

◆ deleteAnswer()

assSingleChoice::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 506 of file class.assSingleChoice.php.

506 : void
507 {
508 if ($index < 0) {
509 return;
510 }
511 if (count($this->answers) < 1) {
512 return;
513 }
514 if ($index >= count($this->answers)) {
515 return;
516 }
517 $answer = $this->answers[$index];
518 if (strlen($answer->getImage())) {
519 $this->deleteImage($answer->getImage());
520 }
521 unset($this->answers[$index]);
522 $this->answers = array_values($this->answers);
523 for ($i = 0, $iMax = count($this->answers); $i < $iMax; $i++) {
524 if ($this->answers[$i]->getOrder() > $index) {
525 $this->answers[$i]->setOrder($i);
526 }
527 }
528 }
deleteImage($image_filename)
Deletes an image file.
$index
Definition: metadata.php:145

References $i, and $index.

◆ deleteImage()

assSingleChoice::deleteImage (   $image_filename)

Deletes an image file.

Parameters
string$image_filenameName of the image file to delete @access private

Definition at line 930 of file class.assSingleChoice.php.

930 : void
931 {
932 $imagepath = $this->getImagePath();
933 @unlink($imagepath . $image_filename);
934 $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
935 @unlink($thumbpath);
936 }
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.

◆ duplicate()

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

Duplicates an assSingleChoiceQuestion.

@access public

Reimplemented from assQuestion.

Definition at line 279 of file class.assSingleChoice.php.

279 : int
280 {
281 if ($this->id <= 0) {
282 // The question has not been saved. It cannot be duplicated
283 return -1;
284 }
285 // duplicate the question in database
286 $this_id = $this->getId();
287 $thisObjId = $this->getObjId();
288
289 $clone = $this;
291 $clone->id = -1;
292
293 if ((int) $testObjId > 0) {
294 $clone->setObjId($testObjId);
295 }
296
297 if ($title) {
298 $clone->setTitle($title);
299 }
300
301 if ($author) {
302 $clone->setAuthor($author);
303 }
304 if ($owner) {
305 $clone->setOwner($owner);
306 }
307 if ($for_test) {
308 $clone->saveToDb($original_id);
309 } else {
310 $clone->saveToDb();
311 }
312
313 // copy question page content
314 $clone->copyPageOfQuestion($this_id);
315
316 // copy XHTML media objects
317 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
318 // duplicate the images
319 $clone->duplicateImages($this_id, $thisObjId);
320
321 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
322
323 return $clone->id;
324 }

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:

◆ duplicateImages()

assSingleChoice::duplicateImages (   $question_id,
  $objectId = null 
)

Definition at line 938 of file class.assSingleChoice.php.

938 : void
939 {
940 global $DIC;
941 $ilLog = $DIC['ilLog'];
942 $imagepath = $this->getImagePath();
943 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
944
945 if ((int) $objectId > 0) {
946 $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
947 }
948
949 foreach ($this->answers as $answer) {
950 $filename = $answer->getImage();
951 if (strlen($filename)) {
952 if (!file_exists($imagepath)) {
953 ilFileUtils::makeDirParents($imagepath);
954 }
955 if (!@copy($imagepath_original . $filename, $imagepath . $filename)) {
956 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
957 $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
958 }
959 if (@file_exists($imagepath_original . $this->getThumbPrefix() . $filename)) {
960 if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename)) {
961 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
962 $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
963 }
964 }
965 }
966 }
967 }
$filename
Definition: buildRTE.php:78
ILIAS DI LoggingServices $ilLog

References $DIC, $filename, and ilFileUtils\makeDirParents().

+ Here is the call graph for this function:

◆ flushAnswers()

assSingleChoice::flushAnswers ( )

Deletes all answers.

@access public

See also
$answers

Definition at line 536 of file class.assSingleChoice.php.

536 : void
537 {
538 $this->answers = array();
539 }

◆ generateThumbForFile()

assSingleChoice::generateThumbForFile (   $path,
  $file 
)
protected

Definition at line 173 of file class.assSingleChoice.php.

173 : void
174 {
175 $filename = $path . $file;
176 if (@file_exists($filename)) {
177 $thumbpath = $path . $this->getThumbPrefix() . $file;
178 $path_info = @pathinfo($filename);
179 $ext = "";
180 switch (strtoupper($path_info['extension'])) {
181 case 'PNG':
182 $ext = 'PNG';
183 break;
184 case 'GIF':
185 $ext = 'GIF';
186 break;
187 default:
188 $ext = 'JPEG';
189 break;
190 }
191 ilShellUtil::convertImage($filename, $thumbpath, $ext, (string) $this->getThumbSize());
192 }
193 }
static convertImage(string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
convert image
$path
Definition: ltiservices.php:32

References $filename, $path, ilShellUtil\convertImage(), getThumbPrefix(), and assQuestion\getThumbSize().

Referenced by rebuildThumbnails().

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

◆ getAdditionalTableName()

assSingleChoice::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 872 of file class.assSingleChoice.php.

872 : string
873 {
874 return "qpl_qst_sc";
875 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ getAnswer()

assSingleChoice::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 483 of file class.assSingleChoice.php.

483 : ?object
484 {
485 if ($index < 0) {
486 return null;
487 }
488 if (count($this->answers) < 1) {
489 return null;
490 }
491 if ($index >= count($this->answers)) {
492 return null;
493 }
494
495 return $this->answers[$index];
496 }

References $index.

◆ getAnswerCount()

assSingleChoice::getAnswerCount ( )

Returns the number of answers.

Returns
integer The number of answers of the multiple choice question @access public
See also
$answers

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

469 : int
470 {
471 return count($this->answers);
472 }

◆ getAnswers()

& assSingleChoice::getAnswers ( )

Returns a reference to the answers array.

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

1070 : array
1071 {
1072 return $this->answers;
1073 }

Referenced by rebuildThumbnails().

+ Here is the caller graph for this function:

◆ getAnswerTableName()

assSingleChoice::getAnswerTableName ( )

Returns the name of the answer table in the database.

Returns
string The answer table name @access public

Reimplemented from assQuestion.

Definition at line 883 of file class.assSingleChoice.php.

883 : string
884 {
885 return "qpl_a_sc";
886 }

◆ getAvailableAnswerOptions()

assSingleChoice::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

Implements iQuestionCondition.

Definition at line 1336 of file class.assSingleChoice.php.

1337 {
1338 if ($index !== null) {
1339 return $this->getAnswer($index);
1340 } else {
1341 return $this->getAnswers();
1342 }
1343 }
& getAnswers()
Returns a reference to the answers array.
getAnswer($index=0)
Returns an answer with a given index.

References $index.

◆ getExpressionTypes()

assSingleChoice::getExpressionTypes ( )

◆ getFeedbackSetting()

assSingleChoice::getFeedbackSetting ( )

Definition at line 1372 of file class.assSingleChoice.php.

1372 : int
1373 {
1375 }

◆ getMaximumPoints()

assSingleChoice::getMaximumPoints ( )

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

@access public

See also
$points

Reimplemented from assQuestion.

Definition at line 547 of file class.assSingleChoice.php.

547 : float
548 {
549 $points = 0;
550 foreach ($this->answers as $key => $value) {
551 if ($value->getPoints() > $points) {
552 $points = $value->getPoints();
553 }
554 }
555 return $points;
556 }

References ILIAS\LTI\ToolProvider\$key.

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assSingleChoice::getMultilineAnswerSetting ( )

Definition at line 1170 of file class.assSingleChoice.php.

1171 {
1172 global $DIC;
1173 $ilUser = $DIC['ilUser'];
1174
1175 $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1176 if ($multilineAnswerSetting != 1) {
1177 $multilineAnswerSetting = 0;
1178 }
1179 return $multilineAnswerSetting;
1180 }
$ilUser
Definition: imgupload.php:34

References $DIC, and $ilUser.

◆ getOperators()

assSingleChoice::getOperators (   $expression)

Get all available operations for a specific question.

Parameters
string$expression

Implements iQuestionCondition.

Definition at line 1266 of file class.assSingleChoice.php.

1266 : array
1267 {
1269 }

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ Here is the call graph for this function:

◆ getOutputType()

assSingleChoice::getOutputType ( )

Gets the single choice output type which is either OUTPUT_ORDER (=0) or OUTPUT_RANDOM (=1).

Returns
integer The output type of the assSingleChoice object @access public
See also
$output_type

Reimplemented from assQuestion.

Definition at line 397 of file class.assSingleChoice.php.

397 : int
398 {
399 return $this->output_type;
400 }

References $output_type.

◆ getQuestionType()

assSingleChoice::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question @access public

Reimplemented from assQuestion.

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

861 : string
862 {
863 return "assSingleChoice";
864 }

◆ getRTETextWithMediaObjects()

assSingleChoice::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 1056 of file class.assSingleChoice.php.

1056 : string
1057 {
1058 $text = parent::getRTETextWithMediaObjects();
1059 foreach ($this->answers as $index => $answer) {
1060 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), 0, $index);
1061 $answer_obj = $this->answers[$index];
1062 $text .= $answer_obj->getAnswertext();
1063 }
1064 return $text;
1065 }

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

+ Here is the call graph for this function:

◆ getSpecificFeedbackAllCorrectOptionLabel()

assSingleChoice::getSpecificFeedbackAllCorrectOptionLabel ( )

Implements ilAssSpecificFeedbackOptionLabelProvider.

Definition at line 1221 of file class.assSingleChoice.php.

1221 : string
1222 {
1223 return 'feedback_correct_sc_mc';
1224 }

◆ getSpecificFeedbackSetting()

assSingleChoice::getSpecificFeedbackSetting ( )

Gets the current feedback settings in effect for the question.

Values are: 1 - Feedback is shown for all answer options. 2 - Feedback is shown for all checked/selected options. 3 - Feedback is shown for all correct options.

Returns
integer

Definition at line 1212 of file class.assSingleChoice.php.

1212 : int
1213 {
1214 if ($this->feedback_setting) {
1216 } else {
1217 return 1;
1218 }
1219 }

◆ getThumbPrefix()

assSingleChoice::getThumbPrefix ( )

Definition at line 168 of file class.assSingleChoice.php.

168 : string
169 {
170 return "thumb.";
171 }

Referenced by generateThumbForFile().

+ Here is the caller graph for this function:

◆ isAnswered()

assSingleChoice::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 1236 of file class.assSingleChoice.php.

1236 : bool
1237 {
1238 $numExistingSolutionRecords = assQuestion::getNumExistingSolutionRecords($active_id, $pass, $this->getId());
1239
1240 return $numExistingSolutionRecords > 0;
1241 }
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()

assSingleChoice::isComplete ( )

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

Returns
boolean True, if the single choice question is complete for use, otherwise false @access public

Reimplemented from assQuestion.

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

100 : bool
101 {
102 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0)) {
103 foreach ($this->answers as $answer) {
104 if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) {
105 return false;
106 }
107 }
108 return true;
109 } else {
110 return false;
111 }
112 }
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.

References getMaximumPoints().

+ Here is the call graph for this function:

◆ isObligationPossible()

static assSingleChoice::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 1253 of file class.assSingleChoice.php.

1253 : bool
1254 {
1255 return true;
1256 }

◆ isSingleline()

assSingleChoice::isSingleline ( )

Definition at line 1362 of file class.assSingleChoice.php.

1362 : bool
1363 {
1364 return $this->isSingleline;
1365 }

Referenced by loadFromDb(), and rebuildThumbnails().

+ Here is the caller graph for this function:

◆ lmMigrateQuestionTypeSpecificContent()

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

Reimplemented from assQuestion.

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

1106 : void
1107 {
1108 foreach ($this->getAnswers() as $answer) {
1109 /* @var ASS_AnswerBinaryStateImage $answer */
1110 $answer->setAnswertext($migrator->migrateToLmContent($answer->getAnswertext()));
1111 }
1112 }

References ilAssSelfAssessmentMigrator\migrateToLmContent().

+ Here is the call graph for this function:

◆ loadFromDb()

assSingleChoice::loadFromDb (   $question_id)

Loads a assSingleChoice object from a database.

Parameters
object$dbA pear DB object
integer$question_idA unique key which defines the multiple choice test in the database @access public

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

202 : void
203 {
204 global $DIC;
205 $ilDB = $DIC['ilDB'];
206
207 $result = $ilDB->queryF(
208 "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",
209 array("integer"),
210 array($question_id)
211 );
212 if ($result->numRows() == 1) {
213 $data = $ilDB->fetchAssoc($result);
214 $this->setId($question_id);
215 $this->setObjId($data["obj_fi"]);
216 $this->setTitle($data["title"] ?? '');
217 $this->setNrOfTries($data['nr_of_tries']);
218 $this->setComment($data["description"] ?? '');
219 $this->setOriginalId($data["original_id"]);
220 $this->setAuthor($data["author"]);
221 $this->setPoints($data["points"]);
222 $this->setOwner($data["owner"]);
223 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"] ?? '', 1));
224 $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
225 $this->setShuffle((bool) $shuffle);
226 if ($data['thumb_size'] !== null && $data['thumb_size'] >= $this->getMinimumThumbSize()) {
227 $this->setThumbSize($data['thumb_size']);
228 }
229 $this->isSingleline = $data['allow_images'] === null || $data['allow_images'] === '0';
230 $this->lastChange = $data['tstamp'];
231 $this->feedback_setting = $data['feedback_setting'];
232
233 try {
237 }
238
239 try {
240 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
242 }
243 }
244
245 $result = $ilDB->queryF(
246 "SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
247 array('integer'),
248 array($question_id)
249 );
250
251 if ($result->numRows() > 0) {
252 while ($data = $ilDB->fetchAssoc($result)) {
253 $imagefilename = $this->getImagePath() . $data["imagefile"];
254 if (!@file_exists($imagefilename)) {
255 $data["imagefile"] = "";
256 }
257
258 $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"] ?? '', 1);
259 $image = new ASS_AnswerBinaryStateImage(
260 $data["answertext"],
261 $data["points"],
262 $data["aorder"],
263 1,
264 $data["imagefile"],
265 $data["answer_id"]
266 );
267 $this->answers[] = $image;
268 }
269 }
270
271 parent::loadFromDb($question_id);
272 }
setOriginalId(?int $original_id)
setId(int $id=-1)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setShuffle(?bool $shuffle=true)
setQuestion(string $question="")
setAuthor(string $author="")
setThumbSize(int $a_size)
bool $shuffle
Indicates whether the answers will be shuffled or not.
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)
getAdditionalTableName()
Returns the name of the additional question data table in the database.
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, assQuestion\$shuffle, ilRTE\_replaceMediaObjectImageSrc(), getAdditionalTableName(), ilAssQuestionLifecycle\getDraftInstance(), assQuestion\getImagePath(), ilAssQuestionLifecycle\getInstance(), assQuestion\getMinimumThumbSize(), isSingleline(), assQuestion\setAdditionalContentEditingMode(), assQuestion\setAuthor(), assQuestion\setComment(), assQuestion\setId(), assQuestion\setLifecycle(), assQuestion\setNrOfTries(), assQuestion\setObjId(), assQuestion\setOriginalId(), assQuestion\setOwner(), assQuestion\setPoints(), assQuestion\setQuestion(), assQuestion\setShuffle(), assQuestion\setThumbSize(), and assQuestion\setTitle().

+ Here is the call graph for this function:

◆ rebuildThumbnails()

assSingleChoice::rebuildThumbnails ( )
protected

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

157 : void
158 {
159 if ($this->isSingleline && ($this->getThumbSize())) {
160 foreach ($this->getAnswers() as $answer) {
161 if (strlen($answer->getImage())) {
162 $this->generateThumbForFile($this->getImagePath(), $answer->getImage());
163 }
164 }
165 }
166 }
generateThumbForFile($path, $file)

References generateThumbForFile(), getAnswers(), assQuestion\getImagePath(), assQuestion\getThumbSize(), and isSingleline().

+ Here is the call graph for this function:

◆ removeAnswerImage()

assSingleChoice::removeAnswerImage (   $index)

Definition at line 1161 of file class.assSingleChoice.php.

1161 : void
1162 {
1163 $answer = $this->answers[$index];
1164 if (is_object($answer)) {
1165 $this->deleteImage($answer->getImage());
1166 $answer->setImage('');
1167 }
1168 }

References $index.

◆ savePreviewData()

assSingleChoice::savePreviewData ( ilAssQuestionPreviewSession  $previewSession)
protected

Reimplemented from assQuestion.

Definition at line 684 of file class.assSingleChoice.php.

684 : void
685 {
686 $mc_result_key = 'multiple_choice_result' . $this->getId() . 'ID';
687 if (
688 $this->http->wrapper()->post()->has($mc_result_key) &&
689 ($mc_result = $this->http->wrapper()->post()->retrieve($mc_result_key, $this->refinery->kindlyTo()->string())) !== ''
690 ) {
691 $previewSession->setParticipantsSolution($mc_result);
692 } else {
693 $previewSession->setParticipantsSolution(null);
694 }
695 }
static http()
Fetches the global http state from ILIAS.

References ILIAS\Survey\Mode\getId(), ILIAS\FileDelivery\http(), and ilAssQuestionPreviewSession\setParticipantsSolution().

+ Here is the call graph for this function:

◆ saveWorkingData()

assSingleChoice::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 623 of file class.assSingleChoice.php.

623 : bool
624 {
625 global $DIC;
626 $ilDB = $DIC['ilDB'];
627 $ilUser = $DIC['ilUser'];
628
629 if (is_null($pass)) {
630 $pass = ilObjTest::_getPass($active_id);
631 }
632
633 $entered_values = 0;
634
635 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(function () use (&$entered_values, $ilDB, $active_id, $pass, $authorized) {
636 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized);
637
638 $update = -1;
639 if ($ilDB->numRows($result)) {
640 $row = $ilDB->fetchAssoc($result);
641 $update = $row["solution_id"];
642 }
643
644 $multiple_choice_result = $this->http->wrapper()->post()->has('multiple_choice_result') ?
645 $this->http->wrapper()->post()->retrieve('multiple_choice_result', $this->refinery->kindlyTo()->string()) :
646 '';
647
648 if ($update != -1) {
649 if ($multiple_choice_result !== '') {
650 $this->updateCurrentSolution($update, $multiple_choice_result, null, $authorized);
651 $entered_values++;
652 } else {
654 }
655 } else {
656 if ($multiple_choice_result !== '') {
657 $this->saveCurrentSolution($active_id, $pass, $multiple_choice_result, null, $authorized);
658 $entered_values++;
659 }
660 }
661 });
662
663 if ($entered_values) {
665 assQuestion::logAction($this->lng->txtlng(
666 "assessment",
667 "log_user_entered_values",
669 ), $active_id, $this->getId());
670 }
671 } else {
673 assQuestion::logAction($this->lng->txtlng(
674 "assessment",
675 "log_user_not_entered_values",
677 ), $active_id, $this->getId());
678 }
679 }
680
681 return true;
682 }
static logAction(string $logtext, int $active_id, int $question_id)
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
updateCurrentSolution(int $solutionId, $value1, $value2, bool $authorized=true)
removeSolutionRecordById(int $solutionId)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
$update
Definition: imgupload.php:92

References $DIC, $ilDB, $ilUser, $update, ilObjAssessmentFolder\_enabledAssessmentLogging(), ilObjAssessmentFolder\_getLogLanguage(), ilObjTest\_getPass(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), assQuestion\logAction(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ setExportDetailsXLS()

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

{}

Reimplemented from assQuestion.

Definition at line 1078 of file class.assSingleChoice.php.

1078 : int
1079 {
1080 parent::setExportDetailsXLS($worksheet, $startrow, $active_id, $pass);
1081
1082 $solution = $this->getSolutionValues($active_id, $pass);
1083 $i = 1;
1084 foreach ($this->getAnswers() as $id => $answer) {
1085 $worksheet->setCell($startrow + $i, 0, $answer->getAnswertext());
1086 $worksheet->setBold($worksheet->getColumnCoord(0) . ($startrow + $i));
1087 if (
1088 count($solution) > 0 &&
1089 isset($solution[0]) &&
1090 is_array($solution[0]) &&
1091 strlen($solution[0]['value1']) > 0 && $id == $solution[0]['value1']
1092 ) {
1093 $worksheet->setCell($startrow + $i, 2, 1);
1094 } else {
1095 $worksheet->setCell($startrow + $i, 2, 0);
1096 }
1097 $i++;
1098 }
1099
1100 return $startrow + $i + 1;
1101 }
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.

References $i, $id, ilExcel\getColumnCoord(), ilExcel\setBold(), and ilAssExcelFormatHelper\setCell().

+ Here is the call graph for this function:

◆ setFeedbackSetting()

assSingleChoice::setFeedbackSetting ( int  $feedback_setting)

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

1377 : void
1378 {
1379 $this->feedback_setting = $feedback_setting;
1380 }

◆ setImageFile()

assSingleChoice::setImageFile (   $image_filename,
  $image_tempfilename = "" 
)

Sets the image file and uploads the image to the object's image directory.

Parameters
string$image_filenameName of the original image file
string$image_tempfilenameName of the temporary uploaded image file
Returns
integer An errorcode if the image upload fails, 0 otherwise @access public

Definition at line 896 of file class.assSingleChoice.php.

896 : int
897 {
898 $result = 0;
899 if (!empty($image_tempfilename)) {
900 $image_filename = str_replace(" ", "_", $image_filename);
901 $imagepath = $this->getImagePath();
902 if (!file_exists($imagepath)) {
903 ilFileUtils::makeDirParents($imagepath);
904 }
905 //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
906 if (!ilFileUtils::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) {
907 $result = 2;
908 } else {
909 $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
910 if (!preg_match("/^image/", $mimetype)) {
911 unlink($imagepath . $image_filename);
912 $result = 1;
913 } else {
914 // create thumbnail file
915 if ($this->isSingleline && ($this->getThumbSize())) {
916 $this->generateThumbForFile($imagepath, $image_filename);
917 }
918 }
919 }
920 }
921 return $result;
922 }
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file

References ilObjMediaObject\getMimeType(), ilFileUtils\makeDirParents(), and ilFileUtils\moveUploadedFile().

+ Here is the call graph for this function:

◆ setIsSingleline()

assSingleChoice::setIsSingleline ( bool  $isSingleline)

Definition at line 1367 of file class.assSingleChoice.php.

1367 : void
1368 {
1369 $this->isSingleline = $isSingleline;
1370 }

◆ setMultilineAnswerSetting()

assSingleChoice::setMultilineAnswerSetting (   $a_setting = 0)

Definition at line 1182 of file class.assSingleChoice.php.

1182 : void
1183 {
1184 global $DIC;
1185 $ilUser = $DIC['ilUser'];
1186 $ilUser->writePref("tst_multiline_answers", (string) $a_setting);
1187 }

References $DIC, and $ilUser.

◆ setOutputType()

assSingleChoice::setOutputType (   $output_type = OUTPUT_ORDER)

Sets the output type of the assSingleChoice object.

Parameters
integer$output_typeA nonnegative integer value specifying the output type. It is OUTPUT_ORDER (=0) or OUTPUT_RANDOM (=1). @access public
See also
$response

Definition at line 409 of file class.assSingleChoice.php.

409 : void
410 {
411 $this->output_type = $output_type;
412 }

References $output_type.

◆ setSpecificFeedbackSetting()

assSingleChoice::setSpecificFeedbackSetting (   $a_feedback_setting)

Sets the feedback settings in effect for the question.

Options are: 1 - Feedback is shown for all answer options. 2 - Feedback is shown for all checked/selected options. 3 - Feedback is shown for all correct options.

Parameters
integer$a_feedback_setting

Definition at line 1198 of file class.assSingleChoice.php.

1198 : void
1199 {
1200 $this->feedback_setting = $a_feedback_setting;
1201 }

◆ syncImages()

assSingleChoice::syncImages ( )
protected

Sync images of a MC question on synchronisation with the original question.

Definition at line 1019 of file class.assSingleChoice.php.

1019 : void
1020 {
1021 global $DIC;
1022 $ilLog = $DIC['ilLog'];
1023 $question_id = $this->getOriginalId();
1024 $imagepath = $this->getImagePath();
1025 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
1026 ilFileUtils::delDir($imagepath_original);
1027 foreach ($this->answers as $answer) {
1028 $filename = $answer->getImage();
1029 if (strlen($filename)) {
1030 if (@file_exists($imagepath . $filename)) {
1031 if (!file_exists($imagepath)) {
1032 ilFileUtils::makeDirParents($imagepath);
1033 }
1034 if (!file_exists($imagepath_original)) {
1035 ilFileUtils::makeDirParents($imagepath_original);
1036 }
1037 if (!@copy($imagepath . $filename, $imagepath_original . $filename)) {
1038 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
1039 $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
1040 }
1041 }
1042 if (@file_exists($imagepath . $this->getThumbPrefix() . $filename)) {
1043 if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename)) {
1044 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
1045 $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
1046 }
1047 }
1048 }
1049 }
1050 }

References $DIC, $filename, ilFileUtils\delDir(), and ilFileUtils\makeDirParents().

+ Here is the call graph for this function:

◆ toJSON()

assSingleChoice::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

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

1117 : string
1118 {
1119 $result = array();
1120 $result['id'] = $this->getId();
1121 $result['type'] = (string) $this->getQuestionType();
1122 $result['title'] = $this->getTitleForHTMLOutput();
1123 $result['question'] = $this->formatSAQuestion($this->getQuestion());
1124 $result['nr_of_tries'] = $this->getNrOfTries();
1125 $result['shuffle'] = $this->getShuffle();
1126
1127 $result['feedback'] = array(
1128 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1129 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1130 );
1131
1132 $answers = array();
1133 $has_image = false;
1134 foreach ($this->getAnswers() as $key => $answer_obj) {
1135 if ((string) $answer_obj->getImage()) {
1136 $has_image = true;
1137 }
1138 array_push($answers, array(
1139 "answertext" => $this->formatSAQuestion($answer_obj->getAnswertext()),
1140 'html_id' => $this->getId() . '_' . $key,
1141 "points" => (float) $answer_obj->getPoints(),
1142 "order" => (int) $answer_obj->getOrder(),
1143 "image" => (string) $answer_obj->getImage(),
1144 "feedback" => $this->formatSAQuestion(
1145 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
1146 )
1147 ));
1148 }
1149 $result['answers'] = $answers;
1150 if ($has_image) {
1151 $result['path'] = $this->getImagePathWeb();
1152 $result['thumb'] = $this->getThumbSize();
1153 }
1154
1155 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1156 $result['mobs'] = $mobs;
1157
1158 return json_encode($result);
1159 }
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getQuestionType()
Returns the question type of the question.
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
$mobs
Definition: imgupload.php:70

References ILIAS\LTI\ToolProvider\$key, $mobs, ilObjMediaObject\_getMobsOfObject(), and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

Field Documentation

◆ $answers

assSingleChoice::$answers

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

◆ $feedback_setting

assSingleChoice::$feedback_setting
protected

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

◆ $isSingleline

bool assSingleChoice::$isSingleline = true
private

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

◆ $output_type

assSingleChoice::$output_type

Definition at line 55 of file class.assSingleChoice.php.

Referenced by __construct(), getOutputType(), and setOutputType().


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