ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
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
 getUserQuestionResult ($active_id, $pass)
 Get the user solution for a question by active_id and the test pass. More...
 

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)
 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)
 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.

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

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)
+ 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) public
See also
$answers
ASS_AnswerBinaryStateImage

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

References $i, assQuestion\$points, and assQuestion\getHtmlQuestionContentPurifier().

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
+ Here is the call graph for this function:

◆ afterSyncWithOriginal()

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

{}

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

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

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  }
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
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
buildImagePath($questionId, $parentObjectId)
+ 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.

public

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

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

References $data, $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, assQuestion\$points, assQuestion\getCurrentSolutionResultSet(), and assQuestion\getSolutionMaxPass().

Referenced by getExpressionTypes().

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  }
float $points
The maximum available points for the question.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
string $key
Consumer key/client ID value.
Definition: System.php:193
getSolutionMaxPass(int $active_id)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calculateReachedPointsFromPreviewSession()

assSingleChoice::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $previewSession)

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

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

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  }
ensureNonNegativePoints($points)
float $points
The maximum available points for the question.
string $key
Consumer key/client ID value.
Definition: System.php:193
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
+ Here is the call graph for this function:

◆ copyObject()

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

Copies an assSingleChoice object.

public

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

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

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)
+ Here is the call graph for this function:

◆ createNewOriginalFromThisDuplicate()

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

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

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

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  }
+ 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 public
See also
$answers

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

References $i, $index, and deleteImage().

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  }
$index
Definition: metadata.php:145
deleteImage($image_filename)
Deletes an image file.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

◆ deleteImage()

assSingleChoice::deleteImage (   $image_filename)

Deletes an image file.

Parameters
string$image_filenameName of the image file to delete private

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

References assQuestion\getImagePath(), and getThumbPrefix().

Referenced by deleteAnswer(), and removeAnswerImage().

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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ duplicate()

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

Duplicates an assSingleChoiceQuestion.

public

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

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

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  }
static _getOriginalId(int $question_id)
+ Here is the call graph for this function:

◆ duplicateImages()

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

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

References $DIC, $filename, assQuestion\$ilLog, assQuestion\getImagePath(), getThumbPrefix(), and ilFileUtils\makeDirParents().

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  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: feed.php:28
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
$filename
Definition: buildRTE.php:78
ILIAS DI LoggingServices $ilLog
+ Here is the call graph for this function:

◆ flushAnswers()

assSingleChoice::flushAnswers ( )

Deletes all answers.

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.

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

Referenced by rebuildThumbnails(), and setImageFile().

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  }
$path
Definition: ltiservices.php:32
static convertImage(string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
convert image
$filename
Definition: buildRTE.php:78
+ 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 public

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

Referenced by isComplete(), loadFromDb(), and savePreviewData().

872  : string
873  {
874  return "qpl_qst_sc";
875  }
+ 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 public
See also
$answers

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

References $index.

Referenced by getAvailableAnswerOptions().

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  }
$index
Definition: metadata.php:145
+ Here is the caller graph for this function:

◆ getAnswerCount()

assSingleChoice::getAnswerCount ( )

Returns the number of answers.

Returns
integer The number of answers of the multiple choice question 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.

References $answers.

Referenced by getAvailableAnswerOptions(), lmMigrateQuestionTypeSpecificContent(), rebuildThumbnails(), setExportDetailsXLS(), and toJSON().

1070  : array
1071  {
1072  return $this->answers;
1073  }
+ 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 public

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.

References $index, getAnswer(), and getAnswers().

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.
$index
Definition: metadata.php:145
+ Here is the call graph for this function:

◆ getExpressionTypes()

◆ getFeedbackSetting()

assSingleChoice::getFeedbackSetting ( )

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

References $feedback_setting.

1372  : int
1373  {
1374  return $this->feedback_setting;
1375  }

◆ getMaximumPoints()

assSingleChoice::getMaximumPoints ( )

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

public

See also
$points

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

References ILIAS\LTI\ToolProvider\$key, and assQuestion\$points.

Referenced by getExpressionTypes(), and isComplete().

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  }
float $points
The maximum available points for the question.
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assSingleChoice::getMultilineAnswerSetting ( )

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

References $DIC, and $ilUser.

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  }
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34

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

References ilOperatorsExpressionMapping\getOperatorsByExpression().

1266  : array
1267  {
1269  }
+ 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 public
See also
$output_type

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

References $output_type.

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

◆ getQuestionType()

assSingleChoice::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question public

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

Referenced by toJSON().

861  : string
862  {
863  return "assSingleChoice";
864  }
+ Here is the caller graph for this function:

◆ getRTETextWithMediaObjects()

assSingleChoice::getRTETextWithMediaObjects ( )

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

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

References $index, and assQuestion\getId().

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  }
$index
Definition: metadata.php:145
+ 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.

References $feedback_setting.

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

◆ getThumbPrefix()

assSingleChoice::getThumbPrefix ( )

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

Referenced by deleteImage(), duplicateImages(), generateThumbForFile(), and syncImages().

168  : string
169  {
170  return "thumb.";
171  }
+ 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

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

References assQuestion\getId(), and assQuestion\getNumExistingSolutionRecords().

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)
+ 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 public

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

References $data, $DIC, $ilDB, assQuestion\$original_id, getAdditionalTableName(), assQuestion\getId(), getMaximumPoints(), assQuestion\getThumbSize(), isSingleline(), ilObjQuestionScoringAdjustable\saveAdditionalQuestionDataToDb(), ilObjAnswerScoringAdjustable\saveAnswerSpecificDataToDb(), assQuestion\saveQuestionDataToDb(), and assQuestion\saveToDb().

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.
+ 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

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.

References $isSingleline.

Referenced by isComplete(), loadFromDb(), rebuildThumbnails(), savePreviewData(), setImageFile(), and setIsSingleline().

1362  : bool
1363  {
1364  return $this->isSingleline;
1365  }
+ Here is the caller graph for this function:

◆ lmMigrateQuestionTypeSpecificContent()

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

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

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

1106  : void
1107  {
1108  foreach ($this->getAnswers() as $answer) {
1109  /* @var ASS_AnswerBinaryStateImage $answer */
1110  $answer->setAnswertext($migrator->migrateToLmContent($answer->getAnswertext()));
1111  }
1112  }
& getAnswers()
Returns a reference to the answers array.
+ 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 public

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

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().

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']);
241  } catch (ilTestQuestionPoolException $e) {
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  }
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
setNrOfTries(int $a_nr_of_tries)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOwner(int $owner=-1)
bool $shuffle
Indicates whether the answers will be shuffled or not.
setThumbSize(int $a_size)
setComment(string $comment="")
global $DIC
Definition: feed.php:28
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
setPoints(float $points)
setObjId(int $obj_id=0)
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setId(int $id=-1)
setOriginalId(?int $original_id)
setTitle(string $title="")
setLifecycle(ilAssQuestionLifecycle $lifecycle)
setAuthor(string $author="")
setShuffle(?bool $shuffle=true)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setQuestion(string $question="")
+ Here is the call graph for this function:

◆ rebuildThumbnails()

assSingleChoice::rebuildThumbnails ( )
protected

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

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

Referenced by savePreviewData().

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)
& getAnswers()
Returns a reference to the answers array.
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeAnswerImage()

assSingleChoice::removeAnswerImage (   $index)

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

References $index, and deleteImage().

1161  : void
1162  {
1163  $answer = $this->answers[$index];
1164  if (is_object($answer)) {
1165  $this->deleteImage($answer->getImage());
1166  $answer->setImage('');
1167  }
1168  }
$index
Definition: metadata.php:145
deleteImage($image_filename)
Deletes an image file.
+ Here is the call graph for this function:

◆ savePreviewData()

assSingleChoice::savePreviewData ( ilAssQuestionPreviewSession  $previewSession)
protected

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

References $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, ilRTE\_replaceMediaObjectImageSrc(), ilFileUtils\delDir(), assQuestion\getAdditionalContentEditingMode(), getAdditionalTableName(), assQuestion\getId(), assQuestion\getImagePath(), assQuestion\getShuffle(), assQuestion\getThumbSize(), ILIAS\FileDelivery\http(), isSingleline(), rebuildThumbnails(), ILIAS\Repository\refinery(), ilObjQuestionScoringAdjustable\saveAdditionalQuestionDataToDb(), ilObjAnswerScoringAdjustable\saveAnswerSpecificDataToDb(), and ilAssQuestionPreviewSession\setParticipantsSolution().

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.
+ 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.

public

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

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

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

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 _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
$update
Definition: imgupload.php:92
updateCurrentSolution(int $solutionId, $value1, $value2, bool $authorized=true)
global $DIC
Definition: feed.php:28
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
static http()
Fetches the global http state from ILIAS.
static logAction(string $logtext, int $active_id, int $question_id)
removeSolutionRecordById(int $solutionId)
$ilUser
Definition: imgupload.php:34
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
+ Here is the call graph for this function:

◆ setExportDetailsXLS()

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

{}

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

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

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.
& getAnswers()
Returns a reference to the answers array.
getColumnCoord(int $a_col)
Get column "name" from number.
setCell($a_row, $a_col, $a_value, $datatype=null)
setBold(string $a_coords)
Set cell(s) to bold.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

◆ setFeedbackSetting()

assSingleChoice::setFeedbackSetting ( int  $feedback_setting)

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

References $feedback_setting.

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 public

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

References generateThumbForFile(), assQuestion\getImagePath(), ilObjMediaObject\getMimeType(), assQuestion\getThumbSize(), isSingleline(), ilFileUtils\makeDirParents(), and ilFileUtils\moveUploadedFile().

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  }
generateThumbForFile($path, $file)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
+ Here is the call graph for this function:

◆ setIsSingleline()

assSingleChoice::setIsSingleline ( bool  $isSingleline)

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

References $isSingleline, and isSingleline().

1367  : void
1368  {
1369  $this->isSingleline = $isSingleline;
1370  }
+ Here is the call graph for this function:

◆ setMultilineAnswerSetting()

assSingleChoice::setMultilineAnswerSetting (   $a_setting = 0)

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

References $DIC, and $ilUser.

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

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

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

References $output_type.

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

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

References $DIC, $filename, assQuestion\$ilLog, ilFileUtils\delDir(), assQuestion\getImagePath(), assQuestion\getOriginalId(), getThumbPrefix(), and ilFileUtils\makeDirParents().

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  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: feed.php:28
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$filename
Definition: buildRTE.php:78
ILIAS DI LoggingServices $ilLog
+ Here is the call graph for this function:

◆ toJSON()

assSingleChoice::toJSON ( )

Returns a JSON representation of the question.

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

References $answers, ILIAS\LTI\ToolProvider\$key, $mobs, ilObjMediaObject\_getMobsOfObject(), assQuestion\formatSAQuestion(), getAnswers(), assQuestion\getId(), assQuestion\getImagePathWeb(), assQuestion\getNrOfTries(), assQuestion\getQuestion(), getQuestionType(), assQuestion\getShuffle(), assQuestion\getThumbSize(), assQuestion\getTitleForHTMLOutput(), and ILIAS\Repository\int().

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  }
$mobs
Definition: imgupload.php:70
& getAnswers()
Returns a reference to the answers array.
getQuestionType()
Returns the question type of the question.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
string $key
Consumer key/client ID value.
Definition: System.php:193
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
+ Here is the call graph for this function:

Field Documentation

◆ $answers

assSingleChoice::$answers

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

Referenced by getAnswers(), and toJSON().

◆ $feedback_setting

assSingleChoice::$feedback_setting
protected

◆ $isSingleline

bool assSingleChoice::$isSingleline = true
private

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

Referenced by isSingleline(), and setIsSingleline().

◆ $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: