ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
assMultipleChoice Class Reference

Class for multiple choice tests. More...

+ Inheritance diagram for assMultipleChoice:
+ Collaboration diagram for assMultipleChoice:

Public Member Functions

 setIsSingleline ($isSingleline)
 
 getIsSingleline ()
 
 setLastChange ($lastChange)
 
 getLastChange ()
 
 __construct ( $title="", $comment="", $author="", $owner=-1, $question="", $output_type=OUTPUT_ORDER)
 assMultipleChoice constructor More...
 
 isComplete ()
 Returns true, if a multiple choice question is complete for use. More...
 
 saveToDb ($original_id="")
 Saves a assMultipleChoice object to a database. More...
 
 getThumbPrefix ()
 
 loadFromDb ($question_id)
 Loads a assMultipleChoice object from a database. More...
 
 duplicate ($for_test=true, $title="", $author="", $owner="", $testObjId=null)
 Duplicates an assMultipleChoiceQuestion. More...
 
 copyObject ($target_questionpool_id, $title="")
 Copies an assMultipleChoice object. More...
 
 createNewOriginalFromThisDuplicate ($targetParentId, $targetQuestionTitle="")
 
 getOutputType ()
 Gets the multiple 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 assMultipleChoice object. More...
 
 addAnswer ( $answertext="", $points=0.0, $points_unchecked=0.0, $order=0, $answerimage="")
 Adds a possible answer for a multiple 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, $returndetails=FALSE)
 Returns the points, a learner has reached answering the question. More...
 
 syncWithOriginal ()
 
 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...
 
 duplicateImages ($question_id, $objectId=null)
 
 copyImages ($question_id, $source_questionpool)
 
 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 (&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
 Creates an Excel worksheet for the detailed cumulated results of this question. More...
 
 getThumbSize ()
 
 setThumbSize ($a_size)
 
 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...
 
 isAnswered ($active_id, $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...
 
- Public Member Functions inherited from assQuestion
 __construct ( $title="", $comment="", $author="", $owner=-1, $question="")
 assQuestion constructor More...
 
 setProcessLocker ($processLocker)
 
 getProcessLocker ()
 
 fromXML (&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Receives parameters from a QTI parser and creates a valid ILIAS question object. More...
 
 toXML ($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $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 ($questionpool_id, $title)
 Returns TRUE if the question title exists in the database. More...
 
 setTitle ($title="")
 Sets the title string of the assQuestion object. More...
 
 setId ($id=-1)
 Sets the id of the assQuestion object. More...
 
 setTestId ($id=-1)
 Sets the test id of the assQuestion object. More...
 
 setComment ($comment="")
 Sets the comment string of the assQuestion object. More...
 
 setOutputType ($outputType=OUTPUT_HTML)
 Sets the output type. More...
 
 setShuffle ($shuffle=true)
 Sets the shuffle flag. More...
 
 setEstimatedWorkingTime ($hour=0, $min=0, $sec=0)
 Sets the estimated working time of a question from given hour, minute and second. More...
 
 setEstimatedWorkingTimeFromDurationString ($durationString)
 Sets the estimated working time of a question from a given datetime string. More...
 
 keyInArray ($searchkey, $array)
 returns TRUE if the key occurs in an array More...
 
 setAuthor ($author="")
 Sets the authors name of the assQuestion object. More...
 
 setOwner ($owner="")
 Sets the creator/owner ID of the assQuestion object. More...
 
 getTitle ()
 Gets the title string of the assQuestion object. More...
 
 getId ()
 Gets the id of the assQuestion object. More...
 
 getShuffle ()
 Gets the shuffle flag. More...
 
 getTestId ()
 Gets the test id of the assQuestion object. More...
 
 getComment ()
 Gets the comment string of the assQuestion object. More...
 
 getOutputType ()
 Gets the output type. More...
 
 supportsJavascriptOutput ()
 Returns true if the question type supports JavaScript output. More...
 
 supportsNonJsOutput ()
 
 requiresJsSwitch ()
 
 getEstimatedWorkingTime ()
 Gets the estimated working time of a question. More...
 
 getAuthor ()
 Gets the authors name of the assQuestion object. More...
 
 getOwner ()
 Gets the creator/owner ID of the assQuestion object. More...
 
 getObjId ()
 Get the object id of the container object. More...
 
 setObjId ($obj_id=0)
 Set the object id of the container object. More...
 
 setExternalId ($external_id)
 
 getExternalId ()
 
 _getMaximumPoints ($question_id)
 Returns the maximum points, a learner can reach answering the question. More...
 
_getQuestionInfo ($question_id)
 Returns question information from the database. More...
 
 getSuggestedSolutionOutput ()
 
_getSuggestedSolution ($question_id, $subquestion_index=0)
 Returns a suggested solution for a given subquestion index. More...
 
 getSuggestedSolutions ()
 Return the suggested solutions. More...
 
 _getReachedPoints ($active_id, $question_id, $pass=NULL)
 Returns the points, a learner has reached answering the question. More...
 
 getReachedPoints ($active_id, $pass=NULL)
 Returns the points, a learner has reached answering the question This is the fast way to get the points directly from the database. More...
 
 getMaximumPoints ()
 Returns the maximum points, a learner can reach answering the question. More...
 
 getAdjustedReachedPoints ($active_id, $pass=NULL)
 returns the reached points ... More...
 
 calculateResultsFromSolution ($active_id, $pass=NULL, $obligationsEnabled=false)
 Calculates the question results from a previously saved question solution. More...
 
 persistWorkingState ($active_id, $pass=NULL, $obligationsEnabled=false)
 persists the working state for current testactive and testpass More...
 
 persistPreviewState (ilAssQuestionPreviewSession $previewSession)
 persists the preview state for current user and question More...
 
 saveWorkingData ($active_id, $pass=NULL)
 Saves the learners input of the question to the database. More...
 
 _updateTestResultCache ($active_id, ilAssQuestionProcessLocker $processLocker=null)
 @TODO Move this to a proper place. More...
 
 logAction ($logtext="", $active_id="", $question_id="")
 Logs an action into the Test&Assessment log. More...
 
 _logAction ($logtext="", $active_id="", $question_id="")
 Logs an action into the Test&Assessment log. More...
 
 moveUploadedMediaFile ($file, $name)
 Move an uploaded media file to an public accessible temp dir to present it. More...
 
 getSuggestedSolutionPath ()
 Returns the path for a suggested solution. More...
 
 getJavaPath ()
 Returns the image path for web accessable images of a question. More...
 
 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...
 
 getJavaPathWeb ()
 Returns the web image path for web accessable java applets of a question. More...
 
 getSuggestedSolutionPathWeb ()
 Returns the web path for a suggested solution. More...
 
 getImagePathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 getFlashPathWeb ()
 Returns the web image path for web accessable flash applications of a question. More...
 
getSolutionValues ($active_id, $pass=NULL)
 Loads solutions of a given user from the database an returns it. More...
 
 isInUse ($question_id="")
 Checks whether the question is in use or not. More...
 
 isClone ($question_id="")
 Checks whether the question is a clone of another question or not. More...
 
 pcArrayShuffle ($array)
 Shuffles the values of a given array. More...
 
 getQuestionTypeFromDb ($question_id)
 get question type for question id 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...
 
 deleteAnswers ($question_id)
 Deletes datasets from answers tables. More...
 
 deleteAdditionalTableData ($question_id)
 Deletes datasets from the additional question table in the database. More...
 
 delete ($question_id)
 Deletes a question and all materials from the database. More...
 
 getTotalAnswers ()
 get total number of answers More...
 
 _getTotalAnswers ($a_q_id)
 get number of answers for question id (static) note: do not use $this inside this method More...
 
 _getTitle ($a_q_id)
 Returns the title of a question. More...
 
 _getQuestionText ($a_q_id)
 Returns question text. More...
 
 copyXHTMLMediaObjectsOfQuestion ($a_q_id)
 
 syncXHTMLMediaObjectsOfQuestion ()
 
 createPageObject ()
 create page object of question More...
 
 copyPageOfQuestion ($a_q_id)
 
 getPageOfQuestion ()
 
 _getQuestionType ($question_id)
 Returns the question type of a question with a given id. More...
 
 _getQuestionTitle ($question_id)
 Returns the question title of a question with a given id. More...
 
 setOriginalId ($original_id)
 
 getOriginalId ()
 
 fixSvgToPng ($imageFilenameContainingString)
 
 fixUnavailableSkinImageSources ($html)
 
 loadFromDb ($question_id)
 Loads the question from the database. More...
 
 createNewQuestion ($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 ($original_id="")
 
 saveToDb ($original_id="")
 Saves the question to the database. More...
 
 setNewOriginalId ($newId)
 
 deleteSuggestedSolutions ()
 Deletes all suggestes solutions in the database. More...
 
 getSuggestedSolution ($subquestion_index=0)
 Returns a suggested solution for a given subquestion index. More...
 
 getSuggestedSolutionTitle ($subquestion_index=0)
 Returns the title of a suggested solution at a given subquestion_index. More...
 
 setSuggestedSolution ($solution_id="", $subquestion_index=0, $is_import=false)
 Sets a suggested solution for the question. More...
 
 _resolveInternalLink ($internal_link)
 
 _resolveIntLinks ($question_id)
 
 _getInternalLinkHref ($target="")
 
 syncWithOriginal ()
 
 createRandomSolution ($test_id, $user_id)
 
 _questionExists ($question_id)
 Returns true if the question already exists in the database. More...
 
 _questionExistsInPool ($question_id)
 Returns true if the question already exists in the database and is assigned to a question pool. More...
 
 getPoints ()
 Returns the maximum available points for the question. More...
 
 setPoints ($a_points)
 Sets the maximum available points for the question. More...
 
 getSolutionMaxPass ($active_id)
 Returns the maximum pass a users question solution. More...
 
 _getSolutionMaxPass ($question_id, $active_id)
 Returns the maximum pass a users question solution. More...
 
 _isWriteable ($question_id, $user_id)
 Returns true if the question is writeable by a certain user. More...
 
 _isUsedInRandomTest ($question_id="")
 Checks whether the question is used in a random test or not. More...
 
 calculateReachedPoints ($active_id, $pass=NULL, $returndetails=FALSE)
 Returns the points, a learner has reached answering the question. More...
 
 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 ($txt_output, $prepare_for_latex_output=FALSE)
 Prepares a string for a text area output in tests. More...
 
 QTIMaterialToString ($a_material)
 Reads an QTI material tag an creates a text string. More...
 
 addQTIMaterial (&$a_xml_writer, $a_material, $close_material_tag=TRUE, $add_mobs=TRUE)
 Creates a QTI material tag from a plain text or xhtml text. More...
 
 createNewImageFileName ($image_filename, $unique=false)
 
 _setReachedPoints ($active_id, $question_id, $points, $maxpoints, $pass, $manualscoring, $obligationsEnabled)
 Sets the points, a learner has reached answering the question Additionally objective results are updated. More...
 
 getQuestion ()
 Gets the question string of the question object. More...
 
 setQuestion ($question="")
 Sets the question string of the question object. More...
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 getQuestionTypeID ()
 Returns the question type of the question. More...
 
 cleanupMediaObjectUsage ()
 synchronises appearances of media objects in the question with media object usage table More...
 
getInstances ()
 Gets all instances of the question. More...
 
 _needsManualScoring ($question_id)
 
 getActiveUserData ($active_id)
 Returns the user id and the test id for a given active id. More...
 
 setExportDetailsXLS (&$worksheet, $startrow, $active_id, $pass, &$format_title, &$format_bold)
 Creates an Excel worksheet for the detailed cumulated results of this question. More...
 
 __get ($value)
 Object getter. More...
 
 __set ($key, $value)
 Object setter. More...
 
 getNrOfTries ()
 
 setNrOfTries ($a_nr_of_tries)
 
 setExportImagePath ($a_path)
 
 _questionExistsInTest ($question_id, $test_id)
 
 formatSAQuestion ($a_q)
 Format self assessment question. More...
 
 setPreventRteUsage ($a_val)
 Set prevent rte usage. More...
 
 getPreventRteUsage ()
 Get prevent rte usage. More...
 
 setSelfAssessmentEditingMode ($a_selfassessmenteditingmode)
 Set Self-Assessment Editing Mode. More...
 
 getSelfAssessmentEditingMode ()
 Get Self-Assessment Editing Mode. More...
 
 setDefaultNrOfTries ($a_defaultnroftries)
 Set Default Nr of Tries. More...
 
 getDefaultNrOfTries ()
 Get Default Nr of Tries. More...
 
 isAnswered ($active_id, $pass=null)
 returns boolean wether the question is answered during test pass or not More...
 
 setObligationsToBeConsidered ($obligationsToBeConsidered=true)
 sets the flag wether obligations are to be considered or not More...
 
 areObligationsToBeConsidered ()
 gets the flag wether obligations are to be considered or not More...
 
 isAutosaveable ()
 
 getAdditionalContentEditingMode ()
 getter for additional content editing mode for this question More...
 
 setAdditionalContentEditingMode ($additinalContentEditingMode)
 setter for additional content editing mode for this question More...
 
 isAdditionalContentEditingModePageObject ()
 isser for additional "pageobject" content editing mode More...
 
 isValidAdditionalContentEditingMode ($additionalContentEditingMode)
 returns the fact wether the passed additional content mode is valid or not More...
 
 getValidAdditionalContentEditingModes ()
 getter for valid additional content editing modes More...
 
 addQuestionChangeListener (ilQuestionChangeListener $listener)
 
 getQuestionChangeListeners ()
 
 getHtmlUserSolutionPurifier ()
 
 getHtmlQuestionContentPurifier ()
 
 setLastChange ($lastChange)
 
 getLastChange ()
 
 setStep ($step)
 
 getStep ()
 
 toJSON ()
 
 duplicate ($for_test=true, $title="", $author="", $owner="", $testObjId=null)
 
- 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...
 

Data Fields

 $answers
 
 $output_type
 
 $isSingleline
 
 $lastChange
 
 $feedback_setting
 
- 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 ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT = 'default'
 constant for additional content editing mode "default" More...
 
const ADDITIONAL_CONTENT_EDITING_MODE_PAGE_OBJECT = 'pageobject'
 constant for additional content editing mode "pageobject" More...
 
 $feedbackOBJ = null
 
 $prevent_rte_usage = false
 
 $selfassessmenteditingmode = false
 
 $defaultnroftries = 0
 
 $questionActionCmd = 'handleQuestionAction'
 
- 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 ()
 Rebuild the thumbnail images with a new thumbnail size. More...
 
 generateThumbForFile ($path, $file)
 
 reworkWorkingData ($active_id, $pass, $obligationsAnswered)
 Reworks the allready saved working data if neccessary. More...
 
 deleteImage ($image_filename)
 Deletes an image file. More...
 
 syncImages ()
 Sync images of a MC question on synchronisation with the original question. More...
 
 getSolutionSubmit ()
 
 calculateReachedPointsForSolution ($found_values, $active_id=0)
 
- Protected Member Functions inherited from assQuestion
 reworkWorkingData ($active_id, $pass, $obligationsAnswered)
 Reworks the allready saved working data if neccessary. More...
 
 savePreviewData (ilAssQuestionPreviewSession $previewSession)
 
 deletePageOfQuestion ($question_id)
 Deletes the page object of a question with a given ID. More...
 
 onDuplicate ($originalParentId, $originalQuestionId, $duplicateParentId, $duplicateQuestionId)
 Will be called when a question is duplicated (inside a question pool or for insertion in a test) More...
 
 beforeSyncWithOriginal ($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)
 
 afterSyncWithOriginal ($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId)
 
 onCopy ($sourceParentId, $sourceQuestionId, $targetParentId, $targetQuestionId)
 Will be called when a question is copied (into another question pool) More...
 
 duplicateSuggestedSolutionFiles ($parent_id, $question_id)
 Duplicates the files of a suggested solution if the question is duplicated. More...
 
 syncSuggestedSolutionFiles ($original_id)
 Syncs the files of a suggested solution if the question is synced. More...
 
 copySuggestedSolutionFiles ($source_questionpool_id, $source_question_id)
 
 getRTETextWithMediaObjects ()
 Collects all text in the question which could contain media objects which were created with the Rich Text Editor. More...
 
 duplicateQuestionHints ($originalQuestionId, $duplicateQuestionId)
 
 buildQuestionDataQuery ()
 
 getSelfAssessmentFormatter ()
 

Protected Attributes

 $thumb_size
 
- Protected Attributes inherited from assQuestion
 $id
 
 $title
 
 $comment
 
 $owner
 
 $author
 
 $question
 
 $points
 
 $est_working_time
 
 $shuffle
 
 $test_id
 
 $obj_id
 
 $ilias
 
 $tpl
 
 $lng
 
 $db
 
 $outputType
 
 $suggested_solutions
 
 $original_id
 
 $page
 
 $external_id = ''
 
 $questionChangeListeners = array()
 
 $processLocker
 
 $step = null
 
 $lastChange
 

Additional Inherited Members

- Static Public Member Functions inherited from assQuestion
static isAllowedImageMimeType ($mimeType)
 
static fetchMimeTypeIdentifier ($contentTypeString)
 
static getAllowedFileExtensionsForMimeType ($mimeType)
 
static isAllowedImageFileExtension ($mimeType, $fileExtension)
 
static getAllowedImageFileExtensions ()
 
static _getSuggestedSolutionCount ($question_id)
 Returns the number of suggested solutions associated with a question. More...
 
static _getSuggestedSolutionOutput ($question_id)
 Returns the output of the suggested solution. More...
 
static _getTotalRightAnswers ($a_q_id)
 get number of answers for question id (static) note: do not use $this inside this method More...
 
static isFileAvailable ($file)
 
static _getOriginalId ($question_id)
 Returns the original id of a question. More...
 
static originalQuestionExists ($questionId)
 
static _instanciateQuestion ($question_id)
 Creates an instance of a question with a given question id. More...
 
static _instantiateQuestion ($question_id)
 
static _isWorkedThrough ($active_id, $question_id, $pass=NULL)
 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 ($a_user_id, $a_question_ids)
 Checks if an array of question ids is answered by an user or not. More...
 
static _includeClass ($question_type, $gui=0)
 Include the php class file for a given question type. More...
 
static getGuiClassNameByQuestionType ($questionType)
 
static getObjectClassNameByQuestionType ($questionType)
 
static getFeedbackClassNameByQuestionType ($questionType)
 
static isCoreQuestionType ($questionType)
 
static includeCoreClass ($questionType, $withGuiClass)
 
static includePluginClass ($questionType, $withGuiClass)
 
static _getQuestionTypeName ($type_tag)
 Return the translation for a given question type tag. More...
 
static & _instanciateQuestionGUI ($question_id)
 Creates an instance of a question gui with a given question id. More...
 
static instantiateQuestionGUI ($a_question_id)
 Creates an instance of a question gui with a given question id. More...
 
static lookupParentObjId ($questionId)
 @global ilDB $ilDB More...
 
static lookupOriginalParentObjId ($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 ($questionId)
 returns boolean wether it is possible to set this question type as obligatory or not considering the current question configuration More...
 
static setResultGateway ($resultGateway)
 
static getResultGateway ()
 
static sumTimesInISO8601FormatH_i_s_Extended ($time1, $time2)
 
static convertISO8601FormatH_i_s_ExtendedToSeconds ($time)
 
- Static Protected Member Functions inherited from assQuestion
static getNumExistingSolutionRecords ($activeId, $pass, $questionId)
 returns the number of existing solution records for the given test active / pass and given question id More...
 
- Static Protected Attributes inherited from assQuestion
static $allowedFileExtensionsByMimeType
 
static $allowedCharsetsByMimeType
 
static $imageSourceFixReplaceMap
 

Detailed Description

Class for multiple choice tests.

assMultipleChoice is a class for multiple 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 bheys.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 26 of file class.assMultipleChoice.php.

Constructor & Destructor Documentation

◆ __construct()

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

assMultipleChoice constructor

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

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

108 {
109 parent::__construct($title, $comment, $author, $owner, $question);
110 $this->output_type = $output_type;
111 $this->thumb_size = 150;
112 $this->answers = array();
113 $this->shuffle = 1;
114 }

References assQuestion\$author, assQuestion\$comment, $output_type, assQuestion\$owner, assQuestion\$question, and assQuestion\$title.

Member Function Documentation

◆ addAnswer()

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

Adds a possible answer for a multiple choice question.

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

Parameters
string$answertextThe answer text
double$pointsThe points for selecting the answer (even negative points can be used)
float$points_uncheckedThe points for not selecting the answer (even positive points can be used)
integer$orderA possible display order of the answer
string$answerimage
See also
$answers
ASS_AnswerBinaryStateImage

Definition at line 436 of file class.assMultipleChoice.php.

443 {
444 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
445 if (array_key_exists($order, $this->answers))
446 {
447 // insert answer
448 $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, $order, $points_unchecked, $answerimage);
449 $newchoices = array();
450 for ($i = 0; $i < $order; $i++)
451 {
452 array_push($newchoices, $this->answers[$i]);
453 }
454 array_push($newchoices, $answer);
455 for ($i = $order; $i < count($this->answers); $i++)
456 {
457 $changed = $this->answers[$i];
458 $changed->setOrder($i+1);
459 array_push($newchoices, $changed);
460 }
461 $this->answers = $newchoices;
462 }
463 else
464 {
465 // add answer
466 $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, count($this->answers), $points_unchecked, $answerimage);
467 array_push($this->answers, $answer);
468 }
469 }
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked,...

References $changed, and assQuestion\$points.

◆ calculateReachedPoints()

assMultipleChoice::calculateReachedPoints (   $active_id,
  $pass = NULL,
  $returndetails = FALSE 
)

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

The points are calculated from the given answers.

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

Reimplemented from assQuestion.

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

569 {
570 if( $returndetails )
571 {
572 throw new ilTestException('return details not implemented for '.__METHOD__);
573 }
574
575 global $ilDB;
576
577 $found_values = array();
578 if (is_null($pass))
579 {
580 $pass = $this->getSolutionMaxPass($active_id);
581 }
582 $result = $this->getCurrentSolutionResultSet($active_id, $pass);
583 while ($data = $ilDB->fetchAssoc($result))
584 {
585 if (strcmp($data["value1"], "") != 0)
586 {
587 array_push($found_values, $data["value1"]);
588 }
589 }
590
591 $points = $this->calculateReachedPointsForSolution($found_values, $active_id);
592
593 return $points;
594 }
$result
calculateReachedPointsForSolution($found_values, $active_id=0)
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
Base Exception for all Exceptions relating to Modules/Test.
global $ilDB

References $data, $ilDB, $pass, assQuestion\$points, $result, calculateReachedPointsForSolution(), and assQuestion\getSolutionMaxPass().

+ Here is the call graph for this function:

◆ calculateReachedPointsForSolution()

assMultipleChoice::calculateReachedPointsForSolution (   $found_values,
  $active_id = 0 
)
protected
Parameters
$found_values
$active_id
Returns
int

Definition at line 1268 of file class.assMultipleChoice.php.

1269 {
1270 $points = 0;
1271 foreach($this->answers as $key => $answer)
1272 {
1273 if(in_array($key, $found_values))
1274 {
1275 $points += $answer->getPoints();
1276 } else
1277 {
1278 $points += $answer->getPointsUnchecked();
1279 }
1280 }
1281 if($active_id)
1282 {
1283 include_once "./Modules/Test/classes/class.ilObjTest.php";
1284 $mc_scoring = ilObjTest::_getMCScoring($active_id);
1285 if(($mc_scoring == 0) && (count($found_values) == 0))
1286 {
1287 $points = 0;
1288 }
1289 }
1290 return $points;
1291 }
_getMCScoring($active_id)
Gets the scoring type for multiple choice questions.

References assQuestion\$points, and ilObjTest\_getMCScoring().

Referenced by calculateReachedPoints().

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

◆ copyImages()

assMultipleChoice::copyImages (   $question_id,
  $source_questionpool 
)

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

873 {
874 global $ilLog;
875 $imagepath = $this->getImagePath();
876 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
877 $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
878 foreach ($this->answers as $answer)
879 {
880 $filename = $answer->getImage();
881 if (strlen($filename))
882 {
883 if (!file_exists($imagepath))
884 {
885 ilUtil::makeDirParents($imagepath);
886 }
887 if (!@copy($imagepath_original . $filename, $imagepath . $filename))
888 {
889 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
890 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
891 }
892 if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
893 {
894 if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
895 {
896 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
897 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
898 }
899 }
900 }
901 }
902 }
$filename
Definition: buildRTE.php:89
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
static makeDirParents($a_dir)
Create a new directory and all parent directories.

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

+ Here is the call graph for this function:

◆ copyObject()

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

Copies an assMultipleChoice object.

Definition at line 332 of file class.assMultipleChoice.php.

333 {
334 if ($this->id <= 0)
335 {
336 // The question has not been saved. It cannot be duplicated
337 return;
338 }
339 // duplicate the question in database
340 $clone = $this;
341 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
343 $clone->id = -1;
344 $source_questionpool_id = $this->getObjId();
345 $clone->setObjId($target_questionpool_id);
346 if ($title)
347 {
348 $clone->setTitle($title);
349 }
350 $clone->saveToDb();
351 // copy question page content
352 $clone->copyPageOfQuestion($original_id);
353 // copy XHTML media objects
354 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
355 // duplicate the image
356 $clone->copyImages($original_id, $source_questionpool_id);
357
358 $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
359
360 return $clone->id;
361 }
static _getOriginalId($question_id)
Returns the original id of a question.
getObjId()
Get the object id of the container object.

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

+ Here is the call graph for this function:

◆ createNewOriginalFromThisDuplicate()

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

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

364 {
365 if ($this->id <= 0)
366 {
367 // The question has not been saved. It cannot be duplicated
368 return;
369 }
370
371 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
372
373 $sourceQuestionId = $this->id;
374 $sourceParentId = $this->getObjId();
375
376 // duplicate the question in database
377 $clone = $this;
378 $clone->id = -1;
379
380 $clone->setObjId($targetParentId);
381
382 if ($targetQuestionTitle)
383 {
384 $clone->setTitle($targetQuestionTitle);
385 }
386
387 $clone->saveToDb();
388 // copy question page content
389 $clone->copyPageOfQuestion($sourceQuestionId);
390 // copy XHTML media objects
391 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
392 // duplicate the image
393 $clone->copyImages($sourceQuestionId, $sourceParentId);
394
395 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
396
397 return $clone->id;
398 }

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

+ Here is the call graph for this function:

◆ deleteAnswer()

assMultipleChoice::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
See also
$answers

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

507 {
508 if ($index < 0) return;
509 if (count($this->answers) < 1) return;
510 if ($index >= count($this->answers)) return;
511 $answer = $this->answers[$index];
512 if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
513 unset($this->answers[$index]);
514 $this->answers = array_values($this->answers);
515 for ($i = 0; $i < count($this->answers); $i++)
516 {
517 if ($this->answers[$i]->getOrder() > $index)
518 {
519 $this->answers[$i]->setOrder($i);
520 }
521 }
522 }
deleteImage($image_filename)
Deletes an image file.

References deleteImage().

+ Here is the call graph for this function:

◆ deleteImage()

assMultipleChoice::deleteImage (   $image_filename)
protected

Deletes an image file.

Parameters
string$image_filenameName of the image file to delete

Definition at line 827 of file class.assMultipleChoice.php.

828 {
829 $imagepath = $this->getImagePath();
830 @unlink($imagepath . $image_filename);
831 $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
832 @unlink($thumbpath);
833 }

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

Referenced by deleteAnswer(), and removeAnswerImage().

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

◆ duplicate()

assMultipleChoice::duplicate (   $for_test = true,
  $title = "",
  $author = "",
  $owner = "",
  $testObjId = null 
)

Duplicates an assMultipleChoiceQuestion.

Reimplemented from assQuestion.

Definition at line 273 of file class.assMultipleChoice.php.

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

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

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

Definition at line 835 of file class.assMultipleChoice.php.

836 {
837 global $ilLog;
838 $imagepath = $this->getImagePath();
839 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
840
841 if( (int)$objectId > 0 )
842 {
843 $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
844 }
845
846 foreach ($this->answers as $answer)
847 {
848 $filename = $answer->getImage();
849 if (strlen($filename))
850 {
851 if (!file_exists($imagepath))
852 {
853 ilUtil::makeDirParents($imagepath);
854 }
855 if (!@copy($imagepath_original . $filename, $imagepath . $filename))
856 {
857 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
858 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
859 }
860 if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
861 {
862 if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
863 {
864 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
865 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
866 }
867 }
868 }
869 }
870 }

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

+ Here is the call graph for this function:

◆ flushAnswers()

assMultipleChoice::flushAnswers ( )

Deletes all answers.

See also
$answers

Definition at line 529 of file class.assMultipleChoice.php.

530 {
531 $this->answers = array();
532 }

◆ generateThumbForFile()

assMultipleChoice::generateThumbForFile (   $path,
  $file 
)
protected
Parameters
$pathstring
$filestring

Definition at line 178 of file class.assMultipleChoice.php.

179 {
181 if (@file_exists($filename))
182 {
183 $thumbpath = $path . $this->getThumbPrefix() . $file;
184 $path_info = @pathinfo($filename);
185 $ext = "";
186 switch (strtoupper($path_info['extension']))
187 {
188 case 'PNG':
189 $ext = 'PNG';
190 break;
191 case 'GIF':
192 $ext = 'GIF';
193 break;
194 default:
195 $ext = 'JPEG';
196 break;
197 }
198 ilUtil::convertImage($filename, $thumbpath, $ext, $this->getThumbSize());
199 }
200 }
print $file
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
$path
Definition: index.php:22

References $file, $filename, $path, ilUtil\convertImage(), getThumbPrefix(), and getThumbSize().

Referenced by rebuildThumbnails(), and setImageFile().

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

◆ getAdditionalTableName()

assMultipleChoice::getAdditionalTableName ( )

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

Returns
string The additional table name

Reimplemented from assQuestion.

Definition at line 763 of file class.assMultipleChoice.php.

764 {
765 return "qpl_qst_mc";
766 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ getAnswer()

assMultipleChoice::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
See also
$answers

Definition at line 490 of file class.assMultipleChoice.php.

491 {
492 if ($index < 0) return NULL;
493 if (count($this->answers) < 1) return NULL;
494 if ($index >= count($this->answers)) return NULL;
495
496 return $this->answers[$index];
497 }

Referenced by getAvailableAnswerOptions().

+ Here is the caller graph for this function:

◆ getAnswerCount()

assMultipleChoice::getAnswerCount ( )

Returns the number of answers.

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

Definition at line 477 of file class.assMultipleChoice.php.

478 {
479 return count($this->answers);
480 }

◆ getAnswers()

& assMultipleChoice::getAnswers ( )

Returns a reference to the answers array.

Definition at line 969 of file class.assMultipleChoice.php.

970 {
971 return $this->answers;
972 }

References $answers.

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

+ Here is the caller graph for this function:

◆ getAnswerTableName()

assMultipleChoice::getAnswerTableName ( )

Returns the name of the answer table in the database.

Returns
string The answer table name

Reimplemented from assQuestion.

Definition at line 773 of file class.assMultipleChoice.php.

774 {
775 return "qpl_a_mc";
776 }

◆ getAvailableAnswerOptions()

assMultipleChoice::getAvailableAnswerOptions (   $index = null)

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

Parameters
null | int$index
Returns
array|ASS_AnswerSimple

Implements iQuestionCondition.

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

1365 {
1366 if($index !== null)
1367 {
1368 return $this->getAnswer($index);
1369 }
1370 else
1371 {
1372 return $this->getAnswers();
1373 }
1374 }
getAnswer($index=0)
Returns an answer with a given index.
& getAnswers()
Returns a reference to the answers array.

References getAnswer(), and getAnswers().

+ Here is the call graph for this function:

◆ getExpressionTypes()

◆ getIsSingleline()

assMultipleChoice::getIsSingleline ( )
Returns
mixed

Definition at line 65 of file class.assMultipleChoice.php.

References $isSingleline.

◆ getLastChange()

assMultipleChoice::getLastChange ( )
Returns
mixed

Reimplemented from assQuestion.

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

References $lastChange.

◆ getMaximumPoints()

assMultipleChoice::getMaximumPoints ( )

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

See also
$points

Reimplemented from assQuestion.

Definition at line 539 of file class.assMultipleChoice.php.

540 {
541 $points = 0;
542 $allpoints = 0;
543 foreach ($this->answers as $key => $value)
544 {
545 if ($value->getPoints() > $value->getPointsUnchecked())
546 {
547 $allpoints += $value->getPoints();
548 }
549 else
550 {
551 $allpoints += $value->getPointsUnchecked();
552 }
553 }
554 return $allpoints;
555 }

References assQuestion\$points.

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assMultipleChoice::getMultilineAnswerSetting ( )

Definition at line 1088 of file class.assMultipleChoice.php.

1089 {
1090 global $ilUser;
1091
1092 $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1093 if ($multilineAnswerSetting != 1)
1094 {
1095 $multilineAnswerSetting = 0;
1096 }
1097 return $multilineAnswerSetting;
1098 }
global $ilUser
Definition: imgupload.php:15

References $ilUser.

◆ getOperators()

assMultipleChoice::getOperators (   $expression)

Get all available operations for a specific question.

Parameters
string$expression

Implements iQuestionCondition.

Definition at line 1301 of file class.assMultipleChoice.php.

1302 {
1303 require_once "./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
1305 }

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ Here is the call graph for this function:

◆ getOutputType()

assMultipleChoice::getOutputType ( )

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

Returns
integer The output type of the assMultipleChoice object
See also
$output_type

Reimplemented from assQuestion.

Definition at line 406 of file class.assMultipleChoice.php.

407 {
408 return $this->output_type;
409 }

References $output_type.

◆ getQuestionType()

assMultipleChoice::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question

Reimplemented from assQuestion.

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

754 {
755 return "assMultipleChoice";
756 }

Referenced by toJSON().

+ Here is the caller graph for this function:

◆ getRTETextWithMediaObjects()

assMultipleChoice::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 954 of file class.assMultipleChoice.php.

955 {
956 $text = parent::getRTETextWithMediaObjects();
957 foreach ($this->answers as $index => $answer)
958 {
959 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), $index);
960 $answer_obj = $this->answers[$index];
961 $text .= $answer_obj->getAnswertext();
962 }
963 return $text;
964 }

References assQuestion\getId().

+ Here is the call graph for this function:

◆ getSolutionSubmit()

assMultipleChoice::getSolutionSubmit ( )
protected
Returns
array

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

1248 {
1249 $solutionSubmit = array();
1250 foreach($_POST as $key => $value)
1251 {
1252 if(preg_match("/^multiple_choice_result_(\d+)/", $key))
1253 {
1254 if(strlen($value))
1255 {
1256 $solutionSubmit[] = $value;
1257 }
1258 }
1259 }
1260 return $solutionSubmit;
1261 }
$_POST['username']
Definition: cron.php:12

References $_POST.

◆ getSpecificFeedbackSetting()

assMultipleChoice::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 1129 of file class.assMultipleChoice.php.

1130 {
1131 if ($this->feedback_setting)
1132 {
1134 }
1135 else
1136 {
1137 return 1;
1138 }
1139 }

References $feedback_setting.

◆ getThumbPrefix()

assMultipleChoice::getThumbPrefix ( )
Returns
string

Definition at line 169 of file class.assMultipleChoice.php.

170 {
171 return "thumb.";
172 }

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

+ Here is the caller graph for this function:

◆ getThumbSize()

assMultipleChoice::getThumbSize ( )

Definition at line 1017 of file class.assMultipleChoice.php.

1018 {
1019 return $this->thumb_size;
1020 }

References $thumb_size.

Referenced by generateThumbForFile(), rebuildThumbnails(), setImageFile(), and toJSON().

+ Here is the caller graph for this function:

◆ isAnswered()

assMultipleChoice::isAnswered (   $active_id,
  $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 1152 of file class.assMultipleChoice.php.

1153 {
1154 $numExistingSolutionRecords = assQuestion::getNumExistingSolutionRecords($active_id, $pass, $this->getId());
1155
1156 return $numExistingSolutionRecords > 0;
1157 }
static getNumExistingSolutionRecords($activeId, $pass, $questionId)
returns the number of existing solution records for the given test active / pass and given question i...

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

+ Here is the call graph for this function:

◆ isComplete()

assMultipleChoice::isComplete ( )

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

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

Reimplemented from assQuestion.

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

123 {
124 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
125 {
126 return true;
127 }
128 else
129 {
130 return false;
131 }
132 }
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.

References getMaximumPoints().

+ Here is the call graph for this function:

◆ loadFromDb()

assMultipleChoice::loadFromDb (   $question_id)

Loads a assMultipleChoice object from a database.

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

Reimplemented from assQuestion.

Definition at line 207 of file class.assMultipleChoice.php.

208 {
209 global $ilDB;
210 $hasimages = 0;
211
212 $result = $ilDB->queryF("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",
213 array("integer"),
214 array($question_id)
215 );
216 if ($result->numRows() == 1)
217 {
218 $data = $ilDB->fetchAssoc($result);
219 $this->setId($question_id);
220 $this->setObjId($data["obj_fi"]);
221 $this->setTitle($data["title"]);
222 $this->setNrOfTries($data['nr_of_tries']);
223 $this->setComment($data["description"]);
224 $this->setOriginalId($data["original_id"]);
225 $this->setAuthor($data["author"]);
226 $this->setPoints($data["points"]);
227 $this->setOwner($data["owner"]);
228 include_once("./Services/RTE/classes/class.ilRTE.php");
229 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
230 $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
231 $this->setShuffle($shuffle);
232 $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
233 $this->setThumbSize($data['thumb_size']);
234 $this->isSingleline = ($data['allow_images']) ? false : true;
235 $this->lastChange = $data['tstamp'];
236 $this->feedback_setting = $data['feedback_setting'];
237
238 try
239 {
240 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
241 }
243 {
244 }
245 }
246
247 $result = $ilDB->queryF("SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
248 array('integer'),
249 array($question_id)
250 );
251 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
252 if ($result->numRows() > 0)
253 {
254 while ($data = $ilDB->fetchAssoc($result))
255 {
256 $imagefilename = $this->getImagePath() . $data["imagefile"];
257 if (!@file_exists($imagefilename))
258 {
259 $data["imagefile"] = "";
260 }
261 include_once("./Services/RTE/classes/class.ilRTE.php");
262 $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"], 1);
263 array_push($this->answers, new ASS_AnswerMultipleResponseImage($data["answertext"], $data["points"], $data["aorder"], $data["points_unchecked"], $data["imagefile"]));
264 }
265 }
266
267 parent::loadFromDb($question_id);
268 }
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setShuffle($shuffle=true)
Sets the shuffle flag.
setId($id=-1)
Sets the id of the assQuestion object.
setOriginalId($original_id)
setObjId($obj_id=0)
Set the object id of the container object.
setTitle($title="")
Sets the title string of the assQuestion object.
setOwner($owner="")
Sets the creator/owner ID of the assQuestion object.
setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
Sets the estimated working time of a question from given hour, minute and second.
setAuthor($author="")
Sets the authors name of the assQuestion object.
setPoints($a_points)
Sets the maximum available points for the question.
setComment($comment="")
Sets the comment string of the assQuestion object.
setNrOfTries($a_nr_of_tries)
setAdditionalContentEditingMode($additinalContentEditingMode)
setter for additional content editing mode for this question
setQuestion($question="")
Sets the question string of the question object.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...

References $data, $ilDB, $result, assQuestion\$shuffle, ilRTE\_replaceMediaObjectImageSrc(), getAdditionalTableName(), assQuestion\getImagePath(), assQuestion\setAdditionalContentEditingMode(), assQuestion\setAuthor(), assQuestion\setComment(), assQuestion\setEstimatedWorkingTime(), assQuestion\setId(), assQuestion\setNrOfTries(), assQuestion\setObjId(), assQuestion\setOriginalId(), assQuestion\setOwner(), assQuestion\setPoints(), assQuestion\setQuestion(), assQuestion\setShuffle(), setThumbSize(), and assQuestion\setTitle().

+ Here is the call graph for this function:

◆ rebuildThumbnails()

assMultipleChoice::rebuildThumbnails ( )
protected

Rebuild the thumbnail images with a new thumbnail size.

Definition at line 152 of file class.assMultipleChoice.php.

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

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

+ Here is the call graph for this function:

◆ removeAnswerImage()

assMultipleChoice::removeAnswerImage (   $index)

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

1079 {
1080 $answer = $this->answers[$index];
1081 if (is_object($answer))
1082 {
1083 $this->deleteImage($answer->getImage());
1084 $answer->setImage('');
1085 }
1086 }

References deleteImage().

+ Here is the call graph for this function:

◆ reworkWorkingData()

assMultipleChoice::reworkWorkingData (   $active_id,
  $pass,
  $obligationsAnswered 
)
protected

Reworks the allready saved working data if neccessary.

Parameters
integer$active_id
integer$pass
boolean$obligationsAnswered

Reimplemented from assQuestion.

Definition at line 734 of file class.assMultipleChoice.php.

735 {
736 // nothing to rework!
737 }

◆ saveToDb()

assMultipleChoice::saveToDb (   $original_id = "")

Saves a assMultipleChoice object to a database.

Parameters
string$original_id

Reimplemented from assQuestion.

Definition at line 139 of file class.assMultipleChoice.php.

140 {
144
145 $this->ensureNoInvalidObligation($this->getId());
146 parent::saveToDb($original_id);
147 }
saveQuestionDataToDb($original_id="")
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.

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

+ Here is the call graph for this function:

◆ setExportDetailsXLS()

assMultipleChoice::setExportDetailsXLS ( $worksheet,
  $startrow,
  $active_id,
  $pass,
$format_title,
$format_bold 
)

Creates an Excel worksheet for the detailed cumulated results of this question.

Parameters
object$worksheetReference to the parent excel worksheet
object$startrowStartrow of the output in the excel worksheet
object$active_idActive id of the participant
object$passTest pass
object$format_titleExcel title format
object$format_boldExcel bold format
Returns
object

Reimplemented from assQuestion.

Definition at line 986 of file class.assMultipleChoice.php.

987 {
988 include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
989 $solution = $this->getSolutionValues($active_id, $pass);
990 $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
991 $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
992 $i = 1;
993 foreach ($this->getAnswers() as $id => $answer)
994 {
995 $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($answer->getAnswertext()), $format_bold);
996 $checked = FALSE;
997 foreach ($solution as $solutionvalue)
998 {
999 if ($id == $solutionvalue["value1"])
1000 {
1001 $checked = TRUE;
1002 }
1003 }
1004 if ($checked)
1005 {
1006 $worksheet->write($startrow + $i, 1, 1);
1007 }
1008 else
1009 {
1010 $worksheet->write($startrow + $i, 1, 0);
1011 }
1012 $i++;
1013 }
1014 return $startrow + $i + 1;
1015 }
& getSolutionValues($active_id, $pass=NULL)
Loads solutions of a given user from the database an returns it.
getTitle()
Gets the title string of the assQuestion object.
_convert_text($a_text, $a_target="has been removed")

References assQuestion\$id, $pass, ilExcelUtils\_convert_text(), getAnswers(), assQuestion\getSolutionValues(), and assQuestion\getTitle().

+ Here is the call graph for this function:

◆ setImageFile()

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

Definition at line 785 of file class.assMultipleChoice.php.

786 {
787 $result = 0;
788 if (!empty($image_tempfilename))
789 {
790 $image_filename = str_replace(" ", "_", $image_filename);
791 $imagepath = $this->getImagePath();
792 if (!file_exists($imagepath))
793 {
794 ilUtil::makeDirParents($imagepath);
795 }
796 if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
797 {
798 $result = 2;
799 }
800 else
801 {
802 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
803 $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
804 if (!preg_match("/^image/", $mimetype))
805 {
806 unlink($imagepath . $image_filename);
807 $result = 1;
808 }
809 else
810 {
811 // create thumbnail file
812 if ($this->isSingleline && ($this->getThumbSize()))
813 {
814 $this->generateThumbForFile($imagepath, $image_filename);
815 }
816 }
817 }
818 }
819 return $result;
820 }
static getMimeType($a_file)
get mime type for file
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file

References $result, generateThumbForFile(), assQuestion\getImagePath(), ilObjMediaObject\getMimeType(), getThumbSize(), ilUtil\makeDirParents(), and ilUtil\moveUploadedFile().

+ Here is the call graph for this function:

◆ setIsSingleline()

assMultipleChoice::setIsSingleline (   $isSingleline)
Parameters
mixed$isSingleline

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

58 {
59 $this->isSingleline = $isSingleline;
60 }

References $isSingleline.

◆ setLastChange()

assMultipleChoice::setLastChange (   $lastChange)
Parameters
mixed$lastChange

Reimplemented from assQuestion.

Definition at line 73 of file class.assMultipleChoice.php.

74 {
75 $this->lastChange = $lastChange;
76 }

References $lastChange.

◆ setMultilineAnswerSetting()

assMultipleChoice::setMultilineAnswerSetting (   $a_setting = 0)

Definition at line 1100 of file class.assMultipleChoice.php.

1101 {
1102 global $ilUser;
1103 $ilUser->writePref("tst_multiline_answers", $a_setting);
1104 }

References $ilUser.

◆ setOutputType()

assMultipleChoice::setOutputType (   $output_type = OUTPUT_ORDER)

Sets the output type of the assMultipleChoice object.

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

Reimplemented from assQuestion.

Definition at line 418 of file class.assMultipleChoice.php.

419 {
420 $this->output_type = $output_type;
421 }

References $output_type.

◆ setSpecificFeedbackSetting()

assMultipleChoice::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 1115 of file class.assMultipleChoice.php.

1116 {
1117 $this->feedback_setting = $a_feedback_setting;
1118 }

◆ setThumbSize()

assMultipleChoice::setThumbSize (   $a_size)

Definition at line 1022 of file class.assMultipleChoice.php.

1023 {
1024 $this->thumb_size = $a_size;
1025 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ syncImages()

assMultipleChoice::syncImages ( )
protected

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

Definition at line 907 of file class.assMultipleChoice.php.

908 {
909 global $ilLog;
910
911 $imagepath = $this->getImagePath();
912
913 $question_id = $this->getOriginalId();
914 $originalObjId = parent::lookupParentObjId($this->getOriginalId());
915 $imagepath_original = $this->getImagePath($question_id, $originalObjId);
916
917 ilUtil::delDir($imagepath_original);
918 foreach ($this->answers as $answer)
919 {
920 $filename = $answer->getImage();
921 if (strlen($filename))
922 {
923 if (@file_exists($imagepath . $filename))
924 {
925 if (!file_exists($imagepath))
926 {
927 ilUtil::makeDirParents($imagepath);
928 }
929 if (!file_exists($imagepath_original))
930 {
931 ilUtil::makeDirParents($imagepath_original);
932 }
933 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
934 {
935 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
936 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
937 }
938 }
939 if (@file_exists($imagepath . $this->getThumbPrefix() . $filename))
940 {
941 if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename))
942 {
943 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
944 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
945 }
946 }
947 }
948 }
949 }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

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

Referenced by syncWithOriginal().

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

◆ syncWithOriginal()

assMultipleChoice::syncWithOriginal ( )

Reimplemented from assQuestion.

Definition at line 739 of file class.assMultipleChoice.php.

740 {
741 if ($this->getOriginalId())
742 {
743 $this->syncImages();
744 parent::syncWithOriginal();
745 }
746 }
syncImages()
Sync images of a MC question on synchronisation with the original question.

References assQuestion\getOriginalId(), and syncImages().

+ Here is the call graph for this function:

◆ toJSON()

assMultipleChoice::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

Definition at line 1030 of file class.assMultipleChoice.php.

1031 {
1032 require_once './Services/RTE/classes/class.ilRTE.php';
1033 $result = array();
1034 $result['id'] = (int) $this->getId();
1035 $result['type'] = (string) $this->getQuestionType();
1036 $result['title'] = (string) $this->getTitle();
1037 $result['question'] = $this->formatSAQuestion($this->getQuestion());
1038 $result['nr_of_tries'] = (int) $this->getNrOfTries();
1039 $result['shuffle'] = (bool) $this->getShuffle();
1040 $result['feedback'] = array(
1041 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1042 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1043 );
1044
1045 $answers = array();
1046 $has_image = false;
1047 foreach ($this->getAnswers() as $key => $answer_obj)
1048 {
1049 if((string) $answer_obj->getImage())
1050 {
1051 $has_image = true;
1052 }
1053 array_push($answers, array(
1054 "answertext" => (string) $this->formatSAQuestion($answer_obj->getAnswertext()),
1055 "points_checked" => (float) $answer_obj->getPointsChecked(),
1056 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1057 "order" => (int) $answer_obj->getOrder(),
1058 "image" => (string) $answer_obj->getImage(),
1059 "feedback" => $this->formatSAQuestion(
1060 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key)
1061 )
1062 ));
1063 }
1064 $result['answers'] = $answers;
1065
1066 if($has_image)
1067 {
1068 $result['path'] = $this->getImagePathWeb();
1069 $result['thumb'] = $this->getThumbSize();
1070 }
1071
1072 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1073 $result['mobs'] = $mobs;
1074
1075 return json_encode($result);
1076 }
getQuestionType()
Returns the question type of the question.
formatSAQuestion($a_q)
Format self assessment question.
getShuffle()
Gets the shuffle flag.
getQuestion()
Gets the question string of the question object.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
$mobs

References $answers, $mobs, $result, ilObjMediaObject\_getMobsOfObject(), assQuestion\formatSAQuestion(), getAnswers(), assQuestion\getId(), assQuestion\getImagePathWeb(), assQuestion\getNrOfTries(), assQuestion\getQuestion(), getQuestionType(), assQuestion\getShuffle(), getThumbSize(), and assQuestion\getTitle().

+ Here is the call graph for this function:

Field Documentation

◆ $answers

assMultipleChoice::$answers

Definition at line 35 of file class.assMultipleChoice.php.

Referenced by getAnswers(), and toJSON().

◆ $feedback_setting

assMultipleChoice::$feedback_setting

Definition at line 49 of file class.assMultipleChoice.php.

Referenced by getSpecificFeedbackSetting().

◆ $isSingleline

assMultipleChoice::$isSingleline

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

Referenced by getIsSingleline(), and setIsSingleline().

◆ $lastChange

assMultipleChoice::$lastChange

Definition at line 48 of file class.assMultipleChoice.php.

Referenced by getLastChange(), and setLastChange().

◆ $output_type

assMultipleChoice::$output_type

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

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

◆ $thumb_size

assMultipleChoice::$thumb_size
protected

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

Referenced by getThumbSize().


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