ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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...
 
- 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. 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...
 
 saveWorkingData ($active_id, $pass=NULL)
 Saves the learners input of the question to the database. More...
 
 _updateTestResultCache ($active_id, ilAssQuestionProcessLocker $processLocker=null)
 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...
 
 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...
 
 _getTotalRightAnswers ($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 ()
 
 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...
 
 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)
 
 _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...
 
 getRTETextWithMediaObjects ()
 Collects all text in the question which could contain media objects which were created with the Rich Text Editor. 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 ()
 
 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...
 

Data Fields

 $answers
 
 $output_type
 
 $isSingleline
 
 $lastChange
 
 $feedback_setting
 
- Data Fields inherited from assQuestion
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 = false
 

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...
 
- Protected Member Functions inherited from assQuestion
 reworkWorkingData ($active_id, $pass, $obligationsAnswered)
 Reworks the allready saved working data if neccessary. More...
 
 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...
 
 onSyncWithOriginal ($originalQuestionId, $duplicateQuestionId)
 
 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)
 
 duplicateQuestionHints ($originalQuestionId, $duplicateQuestionId)
 

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
 
 $outputType
 
 $suggested_solutions
 
 $original_id
 
 $page
 
 $external_id = ''
 
 $questionChangeListeners = array()
 
 $processLocker
 

Additional Inherited Members

- Static Public Member Functions inherited from assQuestion
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 _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)
 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 Protected Member Functions inherited from assQuestion
static doesSolutionRecordsExist ($activeId, $pass, $questionId)
 checks wether there are existing solution records for the given test active / pass and given question id More...
 

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 24 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 98 of file class.assMultipleChoice.php.

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

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

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

References $changed, and assQuestion\$points.

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

◆ 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 !!)

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

References $_POST, $data, $pass, assQuestion\$points, $result, ilObjAssessmentFolder\_enabledAssessmentLogging(), ilObjAssessmentFolder\_getLogLanguage(), ilObjTest\_getMCScoring(), ilObjTest\_getPass(), ilRTE\_replaceMediaObjectImageSrc(), ilUtil\delDir(), ilDB\fetchAssoc(), getAdditionalTableName(), assQuestion\getId(), assQuestion\getImagePath(), assQuestion\getProcessLocker(), assQuestion\getShuffle(), assQuestion\getSolutionMaxPass(), getThumbSize(), assQuestion\logAction(), rebuildThumbnails(), ilObjQuestionScoringAdjustable\saveAdditionalQuestionDataToDb(), ilObjAnswerScoringAdjustable\saveAnswerSpecificDataToDb(), and assQuestion\saveWorkingData().

567  {
568  if( $returndetails )
569  {
570  throw new ilTestException('return details not implemented for '.__METHOD__);
571  }
572 
573  global $ilDB;
574 
575  $found_values = array();
576  if (is_null($pass))
577  {
578  $pass = $this->getSolutionMaxPass($active_id);
579  }
580  $result = $ilDB->queryF("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
581  array('integer','integer','integer'),
582  array($active_id, $this->getId(), $pass)
583  );
584  while ($data = $ilDB->fetchAssoc($result))
585  {
586  if (strcmp($data["value1"], "") != 0)
587  {
588  array_push($found_values, $data["value1"]);
589  }
590  }
591  $points = 0;
592  foreach ($this->answers as $key => $answer)
593  {
594  if (in_array($key, $found_values))
595  {
596  $points += $answer->getPoints();
597  }
598  else
599  {
600  $points += $answer->getPointsUnchecked();
601  }
602  }
603  include_once "./Modules/Test/classes/class.ilObjTest.php";
604  $mc_scoring = ilObjTest::_getMCScoring($active_id);
605  if (($mc_scoring == 0) && (count($found_values) == 0))
606  {
607  $points = 0;
608  }
609  return $points;
610  }
getId()
Gets the id of the assQuestion object.
$result
_getMCScoring($active_id)
Gets the scoring type for multiple choice questions.
getSolutionMaxPass($active_id)
Returns the maximum pass a users question solution.
Base Exception for all Exceptions relating to Modules/Test.
fetchAssoc($a_set)
Fetch row as associative array from result set.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the call graph for this function:

◆ copyImages()

assMultipleChoice::copyImages (   $question_id,
  $source_questionpool 
)

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

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

901  {
902  global $ilLog;
903  $imagepath = $this->getImagePath();
904  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
905  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
906  foreach ($this->answers as $answer)
907  {
908  $filename = $answer->getImage();
909  if (strlen($filename))
910  {
911  if (!file_exists($imagepath))
912  {
913  ilUtil::makeDirParents($imagepath);
914  }
915  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
916  {
917  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
918  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
919  }
920  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
921  {
922  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
923  {
924  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
925  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
926  }
927  }
928  }
929  }
930  }
static makeDirParents($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.
$filename
Definition: buildRTE.php:89
+ Here is the call graph for this function:

◆ copyObject()

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

Copies an assMultipleChoice object.

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

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

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

◆ createNewOriginalFromThisDuplicate()

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

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

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

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

References deleteImage().

505  {
506  if ($index < 0) return;
507  if (count($this->answers) < 1) return;
508  if ($index >= count($this->answers)) return;
509  $answer = $this->answers[$index];
510  if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
511  unset($this->answers[$index]);
512  $this->answers = array_values($this->answers);
513  for ($i = 0; $i < count($this->answers); $i++)
514  {
515  if ($this->answers[$i]->getOrder() > $index)
516  {
517  $this->answers[$i]->setOrder($i);
518  }
519  }
520  }
deleteImage($image_filename)
Deletes an image file.
+ 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 855 of file class.assMultipleChoice.php.

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

Referenced by deleteAnswer(), and removeAnswerImage().

856  {
857  $imagepath = $this->getImagePath();
858  @unlink($imagepath . $image_filename);
859  $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
860  @unlink($thumbpath);
861  }
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()

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

Duplicates an assMultipleChoiceQuestion.

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

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

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

◆ duplicateImages()

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

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

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

864  {
865  global $ilLog;
866  $imagepath = $this->getImagePath();
867  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
868 
869  if( (int)$objectId > 0 )
870  {
871  $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
872  }
873 
874  foreach ($this->answers as $answer)
875  {
876  $filename = $answer->getImage();
877  if (strlen($filename))
878  {
879  if (!file_exists($imagepath))
880  {
881  ilUtil::makeDirParents($imagepath);
882  }
883  if (!@copy($imagepath_original . $filename, $imagepath . $filename))
884  {
885  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
886  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
887  }
888  if (@file_exists($imagepath_original. $this->getThumbPrefix(). $filename))
889  {
890  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename))
891  {
892  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
893  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
894  }
895  }
896  }
897  }
898  }
static makeDirParents($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.
$filename
Definition: buildRTE.php:89
+ Here is the call graph for this function:

◆ flushAnswers()

assMultipleChoice::flushAnswers ( )

Deletes all answers.

See also
$answers

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

528  {
529  $this->answers = array();
530  }

◆ generateThumbForFile()

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

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

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

Referenced by rebuildThumbnails(), and setImageFile().

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

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

Referenced by calculateReachedPoints(), and loadFromDb().

792  {
793  return "qpl_qst_mc";
794  }
+ 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 488 of file class.assMultipleChoice.php.

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

◆ 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 475 of file class.assMultipleChoice.php.

476  {
477  return count($this->answers);
478  }

◆ getAnswers()

& assMultipleChoice::getAnswers ( )

Returns a reference to the answers array.

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

References $answers.

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

998  {
999  return $this->answers;
1000  }
+ 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

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

802  {
803  return "qpl_a_mc";
804  }

◆ getIsSingleline()

assMultipleChoice::getIsSingleline ( )
Returns
mixed

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

References $isSingleline.

64  {
65  return $this->isSingleline;
66  }

◆ getLastChange()

assMultipleChoice::getLastChange ( )
Returns
mixed

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

References $lastChange.

80  {
81  return $this->lastChange;
82  }

◆ getMaximumPoints()

assMultipleChoice::getMaximumPoints ( )

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

See also
$points

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

References assQuestion\$points.

Referenced by isComplete().

538  {
539  $points = 0;
540  $allpoints = 0;
541  foreach ($this->answers as $key => $value)
542  {
543  if ($value->getPoints() > $value->getPointsUnchecked())
544  {
545  $allpoints += $value->getPoints();
546  }
547  else
548  {
549  $allpoints += $value->getPointsUnchecked();
550  }
551  }
552  return $allpoints;
553  }
+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assMultipleChoice::getMultilineAnswerSetting ( )

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

References $ilUser.

1117  {
1118  global $ilUser;
1119 
1120  $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1121  if ($multilineAnswerSetting != 1)
1122  {
1123  $multilineAnswerSetting = 0;
1124  }
1125  return $multilineAnswerSetting;
1126  }
global $ilUser
Definition: imgupload.php:15

◆ 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

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

References $output_type.

405  {
406  return $this->output_type;
407  }

◆ getQuestionType()

assMultipleChoice::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question

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

Referenced by toJSON().

782  {
783  return "assMultipleChoice";
784  }
+ 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.

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

References assQuestion\getId().

983  {
984  $text = parent::getRTETextWithMediaObjects();
985  foreach ($this->answers as $index => $answer)
986  {
987  $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), $index);
988  $answer_obj = $this->answers[$index];
989  $text .= $answer_obj->getAnswertext();
990  }
991  return $text;
992  }
getId()
Gets the id of the assQuestion object.
+ Here is the call graph for this function:

◆ 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 1157 of file class.assMultipleChoice.php.

References $feedback_setting.

1158  {
1159  if ($this->feedback_setting)
1160  {
1161  return $this->feedback_setting;
1162  }
1163  else
1164  {
1165  return 1;
1166  }
1167  }

◆ getThumbPrefix()

assMultipleChoice::getThumbPrefix ( )
Returns
string

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

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

168  {
169  return "thumb.";
170  }
+ Here is the caller graph for this function:

◆ getThumbSize()

assMultipleChoice::getThumbSize ( )

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

References $thumb_size.

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

1046  {
1047  return $this->thumb_size;
1048  }
+ 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

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

References $pass, $query, $res, $row, assQuestion\doesSolutionRecordsExist(), assQuestion\getId(), and assQuestion\isObligationPossible().

1181  {
1182  $answered = assQuestion::doesSolutionRecordsExist($active_id, $pass, $this->getId());
1183 
1184  return $answered;
1185  }
getId()
Gets the id of the assQuestion object.
static doesSolutionRecordsExist($activeId, $pass, $questionId)
checks wether there are existing solution records for the given test active / pass and given question...
+ 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 public

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

References getMaximumPoints().

121  {
122  if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
123  {
124  return true;
125  }
126  else
127  {
128  return false;
129  }
130  }
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
+ 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

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

References $data, $result, assQuestion\$shuffle, ilRTE\_replaceMediaObjectImageSrc(), ilDB\fetchAssoc(), 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().

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

◆ rebuildThumbnails()

assMultipleChoice::rebuildThumbnails ( )
protected

Rebuild the thumbnail images with a new thumbnail size.

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

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

Referenced by calculateReachedPoints().

151  {
152  if ($this->isSingleline && ($this->getThumbSize()))
153  {
154  foreach ($this->getAnswers() as $answer)
155  {
156  if (strlen($answer->getImage()))
157  {
158  $this->generateThumbForFile($this->getImagePath(), $answer->getImage());
159  }
160  }
161  }
162  }
generateThumbForFile($path, $file)
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
& getAnswers()
Returns a reference to the answers array.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeAnswerImage()

assMultipleChoice::removeAnswerImage (   $index)

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

References deleteImage().

1107  {
1108  $answer = $this->answers[$index];
1109  if (is_object($answer))
1110  {
1111  $this->deleteImage($answer->getImage());
1112  $answer->setImage('');
1113  }
1114  }
deleteImage($image_filename)
Deletes an image file.
+ 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

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

763  {
764  // nothing to rework!
765  }

◆ saveToDb()

assMultipleChoice::saveToDb (   $original_id = "")

Saves a assMultipleChoice object to a database.

Parameters
string$original_id

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

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

138  {
142 
143  $this->ensureNoInvalidObligation($this->getId());
144  parent::saveToDb($original_id);
145  }
getId()
Gets the id of the assQuestion object.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveQuestionDataToDb($original_id="")
+ 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

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

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

1015  {
1016  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
1017  $solution = $this->getSolutionValues($active_id, $pass);
1018  $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
1019  $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
1020  $i = 1;
1021  foreach ($this->getAnswers() as $id => $answer)
1022  {
1023  $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($answer->getAnswertext()), $format_bold);
1024  $checked = FALSE;
1025  foreach ($solution as $solutionvalue)
1026  {
1027  if ($id == $solutionvalue["value1"])
1028  {
1029  $checked = TRUE;
1030  }
1031  }
1032  if ($checked)
1033  {
1034  $worksheet->write($startrow + $i, 1, 1);
1035  }
1036  else
1037  {
1038  $worksheet->write($startrow + $i, 1, 0);
1039  }
1040  $i++;
1041  }
1042  return $startrow + $i + 1;
1043  }
& getSolutionValues($active_id, $pass=NULL)
Loads solutions of a given user from the database an returns it.
_convert_text($a_text, $a_target="has been removed")
& getAnswers()
Returns a reference to the answers array.
getTitle()
Gets the title string of the assQuestion object.
+ 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 813 of file class.assMultipleChoice.php.

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

814  {
815  $result = 0;
816  if (!empty($image_tempfilename))
817  {
818  $image_filename = str_replace(" ", "_", $image_filename);
819  $imagepath = $this->getImagePath();
820  if (!file_exists($imagepath))
821  {
822  ilUtil::makeDirParents($imagepath);
823  }
824  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
825  {
826  $result = 2;
827  }
828  else
829  {
830  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
831  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
832  if (!preg_match("/^image/", $mimetype))
833  {
834  unlink($imagepath . $image_filename);
835  $result = 1;
836  }
837  else
838  {
839  // create thumbnail file
840  if ($this->isSingleline && ($this->getThumbSize()))
841  {
842  $this->generateThumbForFile($imagepath, $image_filename);
843  }
844  }
845  }
846  }
847  return $result;
848  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
generateThumbForFile($path, $file)
$result
static getMimeType($a_file)
get mime type for file
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
+ Here is the call graph for this function:

◆ setIsSingleline()

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

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

References $isSingleline.

56  {
57  $this->isSingleline = $isSingleline;
58  }

◆ setLastChange()

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

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

References $lastChange.

72  {
73  $this->lastChange = $lastChange;
74  }

◆ setMultilineAnswerSetting()

assMultipleChoice::setMultilineAnswerSetting (   $a_setting = 0)

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

References $ilUser.

1129  {
1130  global $ilUser;
1131  $ilUser->writePref("tst_multiline_answers", $a_setting);
1132  }
global $ilUser
Definition: imgupload.php:15

◆ 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

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

References $output_type.

417  {
418  $this->output_type = $output_type;
419  }

◆ 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 1143 of file class.assMultipleChoice.php.

1144  {
1145  $this->feedback_setting = $a_feedback_setting;
1146  }

◆ setThumbSize()

assMultipleChoice::setThumbSize (   $a_size)

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

Referenced by loadFromDb().

1051  {
1052  $this->thumb_size = $a_size;
1053  }
+ 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 935 of file class.assMultipleChoice.php.

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

Referenced by syncWithOriginal().

936  {
937  global $ilLog;
938 
939  $imagepath = $this->getImagePath();
940 
941  $question_id = $this->getOriginalId();
942  $originalObjId = parent::lookupOriginalParentObjId($this->getOriginalId());
943  $imagepath_original = $this->getImagePath($question_id, $originalObjId);
944 
945  ilUtil::delDir($imagepath_original);
946  foreach ($this->answers as $answer)
947  {
948  $filename = $answer->getImage();
949  if (strlen($filename))
950  {
951  if (@file_exists($imagepath . $filename))
952  {
953  if (!file_exists($imagepath))
954  {
955  ilUtil::makeDirParents($imagepath);
956  }
957  if (!file_exists($imagepath_original))
958  {
959  ilUtil::makeDirParents($imagepath_original);
960  }
961  if (!@copy($imagepath . $filename, $imagepath_original . $filename))
962  {
963  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
964  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
965  }
966  }
967  if (@file_exists($imagepath . $this->getThumbPrefix() . $filename))
968  {
969  if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename))
970  {
971  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
972  $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
973  }
974  }
975  }
976  }
977  }
static makeDirParents($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.
$filename
Definition: buildRTE.php:89
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ syncWithOriginal()

assMultipleChoice::syncWithOriginal ( )

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

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

768  {
769  if ($this->getOriginalId())
770  {
771  $this->syncImages();
772  parent::syncWithOriginal();
773  }
774  }
syncImages()
Sync images of a MC question on synchronisation with the original question.
+ Here is the call graph for this function:

◆ toJSON()

assMultipleChoice::toJSON ( )

Returns a JSON representation of the question.

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

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

1059  {
1060  require_once './Services/RTE/classes/class.ilRTE.php';
1061  $result = array();
1062  $result['id'] = (int) $this->getId();
1063  $result['type'] = (string) $this->getQuestionType();
1064  $result['title'] = (string) $this->getTitle();
1065  $result['question'] = $this->formatSAQuestion($this->getQuestion());
1066  $result['nr_of_tries'] = (int) $this->getNrOfTries();
1067  $result['shuffle'] = (bool) $this->getShuffle();
1068  $result['feedback'] = array(
1069  "onenotcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false),
1070  "allcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true)
1071  );
1072 
1073  $answers = array();
1074  $has_image = false;
1075  foreach ($this->getAnswers() as $key => $answer_obj)
1076  {
1077  if((string) $answer_obj->getImage())
1078  {
1079  $has_image = true;
1080  }
1081  array_push($answers, array(
1082  "answertext" => (string) $this->formatSAQuestion($answer_obj->getAnswertext()),
1083  "points_checked" => (float) $answer_obj->getPointsChecked(),
1084  "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1085  "order" => (int) $answer_obj->getOrder(),
1086  "image" => (string) $answer_obj->getImage(),
1087  "feedback" => ilRTE::_replaceMediaObjectImageSrc(
1088  $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key), 0
1089  )
1090  ));
1091  }
1092  $result['answers'] = $answers;
1093 
1094  if($has_image)
1095  {
1096  $result['path'] = $this->getImagePathWeb();
1097  $result['thumb'] = $this->getThumbSize();
1098  }
1099 
1100  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1101  $result['mobs'] = $mobs;
1102 
1103  return json_encode($result);
1104  }
getId()
Gets the id of the assQuestion object.
formatSAQuestion($a_q)
Format self assessment question.
$result
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getQuestionType()
Returns the question type of the question.
getShuffle()
Gets the shuffle flag.
$mobs
getQuestion()
Gets the question string of the question object.
& getAnswers()
Returns a reference to the answers array.
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _replaceMediaObjectImageSrc($a_text, $a_direction=0)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
getTitle()
Gets the title string of the assQuestion object.
+ Here is the call graph for this function:

Field Documentation

◆ $answers

assMultipleChoice::$answers

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

Referenced by getAnswers(), and toJSON().

◆ $feedback_setting

assMultipleChoice::$feedback_setting

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

Referenced by getSpecificFeedbackSetting().

◆ $isSingleline

assMultipleChoice::$isSingleline

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

Referenced by getIsSingleline(), and setIsSingleline().

◆ $lastChange

assMultipleChoice::$lastChange

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

Referenced by getLastChange(), and setLastChange().

◆ $output_type

assMultipleChoice::$output_type

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

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

◆ $thumb_size

assMultipleChoice::$thumb_size
protected

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

Referenced by getThumbSize().


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