ILIAS  release_4-4 Revision
assSingleChoice Class Reference

Class for single choice questions. More...

+ Inheritance diagram for assSingleChoice:
+ Collaboration diagram for assSingleChoice:

Public Member Functions

 __construct ( $title="", $comment="", $author="", $owner=-1, $question="", $output_type=OUTPUT_ORDER)
 assSingleChoice constructor More...
 
 isComplete ()
 Returns true, if a single choice question is complete for use. More...
 
 getThumbPrefix ()
 
 loadFromDb ($question_id)
 Loads a assSingleChoice object from a database. More...
 
 duplicate ($for_test=true, $title="", $author="", $owner="", $testObjId=null)
 Duplicates an assSingleChoiceQuestion. More...
 
 copyObject ($target_questionpool_id, $title="")
 Copies an assSingleChoice object. More...
 
 createNewOriginalFromThisDuplicate ($targetParentId, $targetQuestionTitle="")
 
 getOutputType ()
 Gets the single choice output type which is either OUTPUT_ORDER (=0) or OUTPUT_RANDOM (=1). More...
 
 setOutputType ($output_type=OUTPUT_ORDER)
 Sets the output type of the assSingleChoice object. More...
 
 addAnswer ( $answertext="", $points=0.0, $order=0, $answerimage="")
 Adds a possible answer for a single choice question. More...
 
 getAnswerCount ()
 Returns the number of answers. More...
 
 getAnswer ($index=0)
 Returns an answer with a given index. More...
 
 deleteAnswer ($index=0)
 Deletes an answer with a given index. More...
 
 flushAnswers ()
 Deletes all answers. More...
 
 getMaximumPoints ()
 Returns the maximum points, a learner can reach answering the question. More...
 
 calculateReachedPoints ($active_id, $pass=NULL, $returndetails=FALSE)
 Returns the points, a learner has reached answering the question. More...
 
 saveWorkingData ($active_id, $pass=NULL)
 Saves the learners input of the question to the database. 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...
 
 deleteImage ($image_filename)
 Deletes an image file. 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)
 
 createRandomSolution ($active_id, $pass)
 
 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...
 

Static Public Member Functions

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

Data Fields

 $answers
 
 $output_type
 
- 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 ()
 
 generateThumbForFile ($path, $file)
 
 reworkWorkingData ($active_id, $pass, $obligationsAnswered)
 Reworks the allready saved working data if neccessary. 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
 
 $feedback_setting
 
- 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 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 single choice questions.

assSingleChoice is a class for single choice questions.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Björn Heyser bheys.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

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

assSingleChoice constructor

The constructor takes possible arguments an creates an instance of the assSingleChoice object.

Parameters
string$titleA title string to describe the question
string$commentA comment string to describe the question
string$authorA string containing the name of the questions author
integer$ownerA numerical ID to identify the owner/creator
string$questionThe question string of the single choice question
int | string$output_typeThe output order of the single choice answers
See also
assQuestion:assQuestion()

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

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

80  {
81  parent::__construct($title, $comment, $author, $owner, $question);
82  $this->thumb_size = 150;
83  $this->output_type = $output_type;
84  $this->answers = array();
85  $this->shuffle = 1;
86  $this->feedback_setting = 2;
87  }

Member Function Documentation

◆ addAnswer()

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

Adds a possible answer for a single choice question.

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

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

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

References $changed, and assQuestion\$points.

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

◆ calculateReachedPoints()

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

public

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

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

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

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 (count($found_values) > 0)
595  {
596  if (in_array($key, $found_values))
597  {
598  $points += $answer->getPoints();
599  }
600  }
601  }
602 
603  return $points;
604  }
getId()
Gets the id of the assQuestion object.
$result
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()

assSingleChoice::copyImages (   $question_id,
  $source_questionpool 
)

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

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

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

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

Copies an assSingleChoice object.

public

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

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

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

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

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

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

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

◆ createRandomSolution()

assSingleChoice::createRandomSolution (   $active_id,
  $pass 
)

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

References $_POST, $pass, and saveWorkingData().

1109  {
1110  $value = rand(0, count($this->answers)-1);
1111  $_POST["multiple_choice_result"] = (strlen($value)) ? (string)$value : '0';
1112  $this->saveWorkingData($active_id, $pass);
1113  }
$_POST['username']
Definition: cron.php:12
saveWorkingData($active_id, $pass=NULL)
Saves the learners input of the question to the database.
+ Here is the call graph for this function:

◆ deleteAnswer()

assSingleChoice::deleteAnswer (   $index = 0)

Deletes an answer with a given index.

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

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

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

References deleteImage().

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

◆ deleteImage()

assSingleChoice::deleteImage (   $image_filename)

Deletes an image file.

Parameters
string$image_filenameName of the image file to delete private

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

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

Referenced by deleteAnswer(), and removeAnswerImage().

860  {
861  $imagepath = $this->getImagePath();
862  @unlink($imagepath . $image_filename);
863  $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
864  @unlink($thumbpath);
865  }
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ duplicate()

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

Duplicates an assSingleChoiceQuestion.

public

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

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

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

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

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

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

868  {
869  global $ilLog;
870  $imagepath = $this->getImagePath();
871  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
872 
873  if( (int)$objectId > 0 )
874  {
875  $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
876  }
877 
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  }
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()

assSingleChoice::flushAnswers ( )

Deletes all answers.

public

See also
$answers

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

533  {
534  $this->answers = array();
535  }

◆ generateThumbForFile()

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

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

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

Referenced by rebuildThumbnails(), and setImageFile().

171  {
172  $filename = $path . $file;
173  if (@file_exists($filename))
174  {
175  $thumbpath = $path . $this->getThumbPrefix() . $file;
176  $path_info = @pathinfo($filename);
177  $ext = "";
178  switch (strtoupper($path_info['extension']))
179  {
180  case 'PNG':
181  $ext = 'PNG';
182  break;
183  case 'GIF':
184  $ext = 'GIF';
185  break;
186  default:
187  $ext = 'JPEG';
188  break;
189  }
190  ilUtil::convertImage($filename, $thumbpath, $ext, $this->getThumbSize());
191  }
192  }
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()

assSingleChoice::getAdditionalTableName ( )

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

Returns
string The additional table name public

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

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

792  {
793  return "qpl_qst_sc";
794  }
+ Here is the caller graph for this function:

◆ getAnswer()

assSingleChoice::getAnswer (   $index = 0)

Returns an answer with a given index.

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

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

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

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

◆ getAnswerCount()

assSingleChoice::getAnswerCount ( )

Returns the number of answers.

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

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

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

◆ getAnswers()

& assSingleChoice::getAnswers ( )

Returns a reference to the answers array.

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

References $answers.

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

999  {
1000  return $this->answers;
1001  }
+ Here is the caller graph for this function:

◆ getAnswerTableName()

assSingleChoice::getAnswerTableName ( )

Returns the name of the answer table in the database.

Returns
string The answer table name public

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

803  {
804  return "qpl_a_sc";
805  }

◆ getMaximumPoints()

assSingleChoice::getMaximumPoints ( )

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

public

See also
$points

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

References assQuestion\$points.

Referenced by isComplete().

544  {
545  $points = 0;
546  foreach ($this->answers as $key => $value)
547  {
548  if ($value->getPoints() > $points)
549  {
550  $points = $value->getPoints();
551  }
552  }
553  return $points;
554  }
+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assSingleChoice::getMultilineAnswerSetting ( )

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

References $ilUser.

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

◆ getOutputType()

assSingleChoice::getOutputType ( )

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

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

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

References $output_type.

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

◆ getQuestionType()

assSingleChoice::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question public

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

Referenced by toJSON().

781  {
782  return "assSingleChoice";
783  }
+ Here is the caller graph for this function:

◆ getRTETextWithMediaObjects()

assSingleChoice::getRTETextWithMediaObjects ( )

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

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

References assQuestion\getId().

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

◆ getSpecificFeedbackSetting()

assSingleChoice::getSpecificFeedbackSetting ( )

Gets the current feedback settings in effect for the question.

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

Returns
integer

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

References $feedback_setting.

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

◆ getThumbPrefix()

assSingleChoice::getThumbPrefix ( )

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

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

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

◆ getThumbSize()

assSingleChoice::getThumbSize ( )

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

References $thumb_size.

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

1039  {
1040  return $this->thumb_size;
1041  }
+ Here is the caller graph for this function:

◆ isAnswered()

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

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

1179  {
1180  $answered = assQuestion::doesSolutionRecordsExist($active_id, $pass, $this->getId());
1181 
1182  return $answered;
1183  }
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()

assSingleChoice::isComplete ( )

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

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

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

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

96  {
97  if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
98  {
99  foreach ($this->answers as $answer)
100  {
101  if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) return false;
102  }
103  return true;
104  }
105  else
106  {
107  return false;
108  }
109  }
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
+ Here is the call graph for this function:

◆ isObligationPossible()

static assSingleChoice::isObligationPossible (   $questionId)
static

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

(overwrites method in class assQuestion)

Parameters
integer$questionId
Returns
boolean $obligationPossible

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

1196  {
1197  return true;
1198  }

◆ loadFromDb()

assSingleChoice::loadFromDb (   $question_id)

Loads a assSingleChoice object from a database.

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

Definition at line 201 of file class.assSingleChoice.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().

202  {
203  global $ilDB;
204 
205  $hasimages = 0;
206 
207  $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",
208  array("integer"),
209  array($question_id)
210  );
211  if ($result->numRows() == 1)
212  {
213  $data = $ilDB->fetchAssoc($result);
214  $this->setId($question_id);
215  $this->setObjId($data["obj_fi"]);
216  $this->setTitle($data["title"]);
217  $this->setNrOfTries($data['nr_of_tries']);
218  $this->setComment($data["description"]);
219  $this->setOriginalId($data["original_id"]);
220  $this->setAuthor($data["author"]);
221  $this->setPoints($data["points"]);
222  $this->setOwner($data["owner"]);
223  include_once("./Services/RTE/classes/class.ilRTE.php");
224  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
225  $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
226  $this->setShuffle($shuffle);
227  $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
228  $this->setThumbSize($data['thumb_size']);
229  $this->isSingleline = ($data['allow_images']) ? false : true;
230  $this->lastChange = $data['tstamp'];
231  $this->feedback_setting = $data['feedback_setting'];
232 
233  try
234  {
235  $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
236  }
238  {
239  }
240  }
241 
242  $result = $ilDB->queryF("SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
243  array('integer'),
244  array($question_id)
245  );
246  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
247  if ($result->numRows() > 0)
248  {
249  while ($data = $ilDB->fetchAssoc($result))
250  {
251  $imagefilename = $this->getImagePath() . $data["imagefile"];
252  if (!@file_exists($imagefilename))
253  {
254  $data["imagefile"] = "";
255  }
256  include_once("./Services/RTE/classes/class.ilRTE.php");
257  $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"], 1);
258  array_push($this->answers, new ASS_AnswerBinaryStateImage($data["answertext"], $data["points"], $data["aorder"], 1, $data["imagefile"]));
259  }
260  }
261 
262  parent::loadFromDb($question_id);
263  }
$result
Class for answers with a binary state indicator.
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.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
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.
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()

assSingleChoice::rebuildThumbnails ( )
protected

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

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

Referenced by saveWorkingData().

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

◆ removeAnswerImage()

assSingleChoice::removeAnswerImage (   $index)

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

References deleteImage().

1099  {
1100  $answer = $this->answers[$index];
1101  if (is_object($answer))
1102  {
1103  $this->deleteImage($answer->getImage());
1104  $answer->setImage('');
1105  }
1106  }
deleteImage($image_filename)
Deletes an image file.
+ Here is the call graph for this function:

◆ reworkWorkingData()

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

Reworks the allready saved working data if neccessary.

protected

Parameters
integer$active_id
integer$pass
boolean$obligationsAnswered

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

761  {
762  // nothing to rework!
763  }

◆ saveWorkingData()

assSingleChoice::saveWorkingData (   $active_id,
  $pass = NULL 
)

Saves the learners input of the question to the database.

public

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

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

References $_POST, $ilUser, $pass, $result, $row, ilObjAssessmentFolder\_enabledAssessmentLogging(), ilObjAssessmentFolder\_getLogLanguage(), ilObjTest\_getPass(), ilRTE\_replaceMediaObjectImageSrc(), ilUtil\delDir(), getAdditionalTableName(), assQuestion\getId(), assQuestion\getImagePath(), assQuestion\getProcessLocker(), assQuestion\getShuffle(), getThumbSize(), assQuestion\logAction(), rebuildThumbnails(), ilObjQuestionScoringAdjustable\saveAdditionalQuestionDataToDb(), and ilObjAnswerScoringAdjustable\saveAnswerSpecificDataToDb().

Referenced by createRandomSolution().

615  {
616  global $ilDB;
617  global $ilUser;
618 
619  if (is_null($pass))
620  {
621  include_once "./Modules/Test/classes/class.ilObjTest.php";
622  $pass = ilObjTest::_getPass($active_id);
623  }
624  $entered_values = 0;
625 
626  $this->getProcessLocker()->requestUserSolutionUpdateLock();
627 
628  $result = $ilDB->queryF("SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
629  array('integer','integer','integer'),
630  array($active_id, $this->getId(), $pass)
631  );
632  $row = $ilDB->fetchAssoc($result);
633  $update = $row["solution_id"];
634 
635  if ($update)
636  {
637  if (strlen($_POST["multiple_choice_result"]))
638  {
639  $affectedRows = $ilDB->update("tst_solutions", array(
640  "value1" => array("clob", $_POST["multiple_choice_result"]),
641  "tstamp" => array("integer", time())
642  ), array(
643  "solution_id" => array("integer", $update)
644  ));
645  $entered_values++;
646  }
647  else
648  {
649  $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE solution_id = %s",
650  array('integer'),
651  array($update)
652  );
653  }
654  }
655  else
656  {
657  if (strlen($_POST["multiple_choice_result"]))
658  {
659  $next_id = $ilDB->nextId('tst_solutions');
660  $affectedRows = $ilDB->insert("tst_solutions", array(
661  "solution_id" => array("integer", $next_id),
662  "active_fi" => array("integer", $active_id),
663  "question_fi" => array("integer", $this->getId()),
664  "value1" => array("clob", $_POST['multiple_choice_result']),
665  "value2" => array("clob", null),
666  "pass" => array("integer", $pass),
667  "tstamp" => array("integer", time())
668  ));
669  $entered_values++;
670  }
671  }
672 
673  $this->getProcessLocker()->releaseUserSolutionUpdateLock();
674 
675  if ($entered_values)
676  {
677  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
679  {
680  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
681  }
682  }
683  else
684  {
685  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
687  {
688  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
689  }
690  }
691 
692  return true;
693  }
getId()
Gets the id of the assQuestion object.
$_POST['username']
Definition: cron.php:12
$result
_getPass($active_id)
Retrieves the actual pass of a given user for a given test.
_enabledAssessmentLogging()
check wether assessment logging is enabled or not
_getLogLanguage()
retrieve the log language for assessment logging
global $ilUser
Definition: imgupload.php:15
logAction($logtext="", $active_id="", $question_id="")
Logs an action into the Test&Assessment log.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setExportDetailsXLS()

assSingleChoice::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
array$eval_dataCumulated evaluation data public

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

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

1016  {
1017  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
1018  $solution = $this->getSolutionValues($active_id, $pass);
1019  $worksheet->writeString($startrow, 0, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())), $format_title);
1020  $worksheet->writeString($startrow, 1, ilExcelUtils::_convert_text($this->getTitle()), $format_title);
1021  $i = 1;
1022  foreach ($this->getAnswers() as $id => $answer)
1023  {
1024  $worksheet->writeString($startrow + $i, 0, ilExcelUtils::_convert_text($answer->getAnswertext()), $format_bold);
1025  if ($id == $solution[0]["value1"])
1026  {
1027  $worksheet->write($startrow + $i, 1, 1);
1028  }
1029  else
1030  {
1031  $worksheet->write($startrow + $i, 1, 0);
1032  }
1033  $i++;
1034  }
1035  return $startrow + $i + 1;
1036  }
& 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()

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

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

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

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

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

816  {
817  $result = 0;
818  if (!empty($image_tempfilename))
819  {
820  $image_filename = str_replace(" ", "_", $image_filename);
821  $imagepath = $this->getImagePath();
822  if (!file_exists($imagepath))
823  {
824  ilUtil::makeDirParents($imagepath);
825  }
826  //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
827  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
828  {
829  $result = 2;
830  }
831  else
832  {
833  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
834  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
835  if (!preg_match("/^image/", $mimetype))
836  {
837  unlink($imagepath . $image_filename);
838  $result = 1;
839  }
840  else
841  {
842  // create thumbnail file
843  if ($this->isSingleline && ($this->getThumbSize()))
844  {
845  $this->generateThumbForFile($imagepath, $image_filename);
846  }
847  }
848  }
849  }
850  return $result;
851  }
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:

◆ setMultilineAnswerSetting()

assSingleChoice::setMultilineAnswerSetting (   $a_setting = 0)

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

References $ilUser.

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

◆ setOutputType()

assSingleChoice::setOutputType (   $output_type = OUTPUT_ORDER)

Sets the output type of the assSingleChoice object.

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

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

References $output_type.

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

◆ setSpecificFeedbackSetting()

assSingleChoice::setSpecificFeedbackSetting (   $a_feedback_setting)

Sets the feedback settings in effect for the question.

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

Parameters
integer$a_feedback_setting

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

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

◆ setThumbSize()

assSingleChoice::setThumbSize (   $a_size)

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

Referenced by loadFromDb().

1044  {
1045  $this->thumb_size = $a_size;
1046  }
+ Here is the caller graph for this function:

◆ syncImages()

assSingleChoice::syncImages ( )
protected

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

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

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

Referenced by syncWithOriginal().

940  {
941  global $ilLog;
942  $question_id = $this->getOriginalId();
943  $imagepath = $this->getImagePath();
944  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
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()

assSingleChoice::syncWithOriginal ( )

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

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

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

◆ toJSON()

assSingleChoice::toJSON ( )

Returns a JSON representation of the question.

Definition at line 1051 of file class.assSingleChoice.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().

1052  {
1053  include_once("./Services/RTE/classes/class.ilRTE.php");
1054  $result = array();
1055  $result['id'] = (int) $this->getId();
1056  $result['type'] = (string) $this->getQuestionType();
1057  $reilUtilsult['title'] = (string) $this->getTitle();
1058  $result['question'] = $this->formatSAQuestion($this->getQuestion());
1059  $result['nr_of_tries'] = (int) $this->getNrOfTries();
1060  $result['shuffle'] = (bool) $this->getShuffle();
1061 
1062  $result['feedback'] = array(
1063  "onenotcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false),
1064  "allcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true)
1065  );
1066 
1067  $answers = array();
1068  $has_image = false;
1069  foreach ($this->getAnswers() as $key => $answer_obj)
1070  {
1071  if((string) $answer_obj->getImage())
1072  {
1073  $has_image = true;
1074  }
1075  array_push($answers, array(
1076  "answertext" => (string) $this->formatSAQuestion($answer_obj->getAnswertext()),
1077  "points" => (float)$answer_obj->getPoints(),
1078  "order" => (int)$answer_obj->getOrder(),
1079  "image" => (string) $answer_obj->getImage(),
1080  "feedback" => ilRTE::_replaceMediaObjectImageSrc(
1081  $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key), 0
1082  )
1083  ));
1084  }
1085  $result['answers'] = $answers;
1086  if($has_image)
1087  {
1088  $result['path'] = $this->getImagePathWeb();
1089  $result['thumb'] = $this->getThumbSize();
1090  }
1091 
1092  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1093  $result['mobs'] = $mobs;
1094 
1095  return json_encode($result);
1096  }
getId()
Gets the id of the assQuestion object.
formatSAQuestion($a_q)
Format self assessment question.
$result
& getAnswers()
Returns a reference to the answers array.
getQuestionType()
Returns the question type of the question.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getShuffle()
Gets the shuffle flag.
$mobs
getQuestion()
Gets the question string of the question object.
_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

assSingleChoice::$answers

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

Referenced by getAnswers(), and toJSON().

◆ $feedback_setting

assSingleChoice::$feedback_setting
protected

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

Referenced by getSpecificFeedbackSetting().

◆ $output_type

assSingleChoice::$output_type

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

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

◆ $thumb_size

assSingleChoice::$thumb_size
protected

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

Referenced by getThumbSize().


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