ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
assMultipleChoice Class Reference

Class for multiple choice tests. More...

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

Public Member Functions

 setIsSingleline ($isSingleline)
 
 getIsSingleline ()
 
 __construct ( $title="", $comment="", $author="", $owner=-1, $question="", $output_type=OUTPUT_ORDER)
 assMultipleChoice constructor More...
 
 getSelectionLimit ()
 
 setSelectionLimit ($selectionLimit)
 
 isComplete ()
 Returns true, if a multiple choice question is complete for use. More...
 
 saveToDb ($original_id="")
 Saves a assMultipleChoice object to a database. More...
 
 loadFromDb ($question_id)
 Loads a assMultipleChoice object from a database. More...
 
 duplicate (bool $for_test=true, string $title="", string $author="", int $owner=-1, $testObjId=null)
 Duplicates an assMultipleChoiceQuestion. More...
 
 copyObject ($target_questionpool_id, $title="")
 Copies an assMultipleChoice object. More...
 
 createNewOriginalFromThisDuplicate ($targetParentId, $targetQuestionTitle="")
 
 addAnswer ( $answertext="", $points=0.0, $points_unchecked=0.0, $order=0, $answerimage=null, $answer_id=-1)
 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, $authorizedSolution=true, $returndetails=false)
 Returns the points, a learner has reached answering the question. More...
 
 validateSolutionSubmit ()
 
 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...
 
 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...
 
 setAnswers (array $answers)
 
 setExportDetailsXLSX (ilAssExcelFormatHelper $worksheet, int $startrow, int $col, int $active_id, int $pass)
 {} More...
 
 toJSON ()
 Returns a JSON representation of the question. More...
 
 removeAnswerImage ($index)
 
 getMultilineAnswerSetting ()
 
 setMultilineAnswerSetting ($a_setting=0)
 
 setSpecificFeedbackSetting ($a_feedback_setting)
 Sets the feedback settings in effect for the question. More...
 
 getSpecificFeedbackSetting ()
 Gets the current feedback settings in effect for the question. More...
 
 getSpecificFeedbackAllCorrectOptionLabel ()
 
 getOperators ($expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. More...
 
 getAvailableAnswerOptions ($index=null)
 If index is null, the function returns an array with all anwser options Else it returns the specific answer option. More...
 
 isSingleline ()
 
- Public Member Functions inherited from assQuestion
 __construct (string $title="", string $comment="", string $author="", int $owner=-1, string $question="")
 assQuestion constructor More...
 
 getShuffler ()
 
 setShuffler (Transformation $shuffler)
 
 setProcessLocker (ilAssQuestionProcessLocker $processLocker)
 
 getProcessLocker ()
 
 fromXML ($item, int $questionpool_id, ?int $tst_id, &$tst_object, int &$question_counter, array $import_mapping, array &$solutionhints=[])
 Receives parameters from a QTI parser and creates a valid ILIAS question object. More...
 
 toXML (bool $a_include_header=true, bool $a_include_binary=true, bool $a_shuffle=false, bool $test_output=false, bool $force_image_references=false)
 Returns a QTI xml representation of the question. More...
 
 isComplete ()
 Returns true, if a question is complete for use. More...
 
 setTitle (string $title="")
 
 setId (int $id=-1)
 
 setTestId (int $id=-1)
 
 setComment (string $comment="")
 
 setShuffle (?bool $shuffle=true)
 
 setAuthor (string $author="")
 
 setOwner (int $owner=-1)
 
 getTitle ()
 
 getTitleForHTMLOutput ()
 
 getTitleFilenameCompliant ()
 
 getId ()
 
 getShuffle ()
 
 getTestId ()
 
 getComment ()
 
 getDescriptionForHTMLOutput ()
 
 getThumbSize ()
 
 setThumbSize (int $a_size)
 
 getMinimumThumbSize ()
 
 getMaximumThumbSize ()
 
 getAuthor ()
 
 getAuthorForHTMLOutput ()
 
 getOwner ()
 
 getObjId ()
 
 setObjId (int $obj_id=0)
 
 getLifecycle ()
 
 setLifecycle (ilAssQuestionLifecycle $lifecycle)
 
 setExternalId (?string $external_id)
 
 getExternalId ()
 
 getSuggestedSolutionOutput ()
 
 getSuggestedSolutions ()
 
 getReachedPoints (int $active_id, int $pass)
 
 getMaximumPoints ()
 
 getAdjustedReachedPoints (int $active_id, int $pass, bool $authorizedSolution=true)
 returns the reached points ... More...
 
 calculateResultsFromSolution (int $active_id, int $pass, bool $obligationsEnabled=false)
 Calculates the question results from a previously saved question solution. More...
 
 persistWorkingState (int $active_id, $pass, bool $obligationsEnabled=false, bool $authorized=true)
 persists the working state for current testactive and testpass More...
 
 persistPreviewState (ilAssQuestionPreviewSession $previewSession)
 persists the preview state for current user and question More...
 
 validateSolutionSubmit ()
 
 saveWorkingData (int $active_id, int $pass, bool $authorized=true)
 Saves the learners input of the question to the database. More...
 
 getSuggestedSolutionPath ()
 
 getImagePath ($question_id=null, $object_id=null)
 Returns the image path for web accessable images of a question. More...
 
 getSuggestedSolutionPathWeb ()
 
 getImagePathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 getTestOutputSolutions (int $activeId, int $pass)
 
 getUserSolutionPreferingIntermediate (int $active_id, $pass=null)
 
 getSolutionValues ($active_id, $pass=null, bool $authorized=true)
 Loads solutions of a given user from the database an returns it. More...
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 deleteAnswers (int $question_id)
 
 deleteAdditionalTableData (int $question_id)
 
 delete (int $question_id)
 
 getTotalAnswers ()
 
 copyXHTMLMediaObjectsOfQuestion (int $a_q_id)
 
 syncXHTMLMediaObjectsOfQuestion ()
 
 createPageObject ()
 
 copyPageOfQuestion (int $a_q_id)
 
 getPageOfQuestion ()
 
 setOriginalId (?int $original_id)
 
 getOriginalId ()
 
 fixSvgToPng (string $imageFilenameContainingString)
 
 fixUnavailableSkinImageSources (string $html)
 
 loadFromDb (int $question_id)
 
 createNewQuestion (bool $a_create_page=true)
 Creates a new question without an owner when a new question is created This assures that an ID is given to the question if a file upload or something else occurs. More...
 
 saveQuestionDataToDb (int $original_id=-1)
 
 saveToDb ()
 
 deleteSuggestedSolutions ()
 
 getSuggestedSolution (int $subquestion_index=0)
 
 resolveInternalLink (string $internal_link)
 
 resolveSuggestedSolutionLinks ()
 
 syncWithOriginal ()
 
 getPoints ()
 
 setPoints (float $points)
 
 getSolutionMaxPass (int $active_id)
 
 calculateReachedPoints ($active_id, $pass=null, $authorizedSolution=true, $returndetails=false)
 Returns the points, a learner has reached answering the question. More...
 
 deductHintPointsFromReachedPoints (ilAssQuestionPreviewSession $previewSession, $reachedPoints)
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $previewSession)
 
 isPreviewSolutionCorrect (ilAssQuestionPreviewSession $previewSession)
 
 adjustReachedPointsByScoringOptions ($points, $active_id, $pass=null)
 Adjust the given reached points by checks for all special scoring options in the test container. More...
 
 buildHashedImageFilename (string $plain_image_filename, bool $unique=false)
 
 getQuestion ()
 
 getQuestionForHTMLOutput ()
 
 setQuestion (string $question="")
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 getQuestionTypeID ()
 
 syncHints ()
 
 cleanupMediaObjectUsage ()
 
 getInstances ()
 
 getActiveUserData (int $active_id)
 Returns the user id and the test id for a given active id. More...
 
 hasSpecificFeedback ()
 
 setExportDetailsXLSX (ilAssExcelFormatHelper $worksheet, int $startrow, int $col, int $active_id, int $pass)
 
 getNrOfTries ()
 
 setNrOfTries (int $a_nr_of_tries)
 
 setExportImagePath (string $path)
 
 formatSAQuestion ($a_q)
 
 setPreventRteUsage (bool $prevent_rte_usage)
 
 getPreventRteUsage ()
 
 migrateContentForLearningModule (ilAssSelfAssessmentMigrator $migrator)
 
 setSelfAssessmentEditingMode (bool $selfassessmenteditingmode)
 
 getSelfAssessmentEditingMode ()
 
 setDefaultNrOfTries (int $defaultnroftries)
 
 getDefaultNrOfTries ()
 
 syncSkillAssignments (int $srcParentId, int $srcQuestionId, int $trgParentId, int $trgQuestionId)
 
 ensureHintPageObjectExists ($pageObjectId)
 
 isAnswered (int $active_id, int $pass)
 
 getAdditionalContentEditingMode ()
 
 setAdditionalContentEditingMode (?string $additionalContentEditingMode)
 
 isAdditionalContentEditingModePageObject ()
 
 isValidAdditionalContentEditingMode (string $additionalContentEditingMode)
 
 getValidAdditionalContentEditingModes ()
 
 getHtmlUserSolutionPurifier ()
 
 getHtmlQuestionContentPurifier ()
 
 setLastChange ($lastChange)
 
 getLastChange ()
 
 removeIntermediateSolution (int $active_id, int $pass)
 
 removeCurrentSolution (int $active_id, int $pass, bool $authorized=true)
 
 saveCurrentSolution (int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
 
 updateCurrentSolution (int $solutionId, $value1, $value2, bool $authorized=true)
 
 updateCurrentSolutionsAuthorization (int $activeId, int $pass, bool $authorized, bool $keepTime=false)
 
 setStep ($step)
 
 getStep ()
 
 toJSON ()
 
 duplicate (bool $for_test=true, string $title="", string $author="", int $owner=-1, $testObjId=null)
 
 intermediateSolutionExists (int $active_id, int $pass)
 
 authorizedSolutionExists (int $active_id, ?int $pass)
 
 authorizedOrIntermediateSolutionExists (int $active_id, int $pass)
 
 lookupForExistingSolutions (int $activeId, int $pass)
 Lookup if an authorized or intermediate solution exists. More...
 
 isAddableAnswerOptionValue (int $qIndex, string $answerOptionValue)
 
 addAnswerOptionValue (int $qIndex, string $answerOptionValue, float $points)
 
 removeAllExistingSolutions ()
 
 removeExistingSolutions (int $activeId, int $pass)
 
 resetUsersAnswer (int $activeId, int $pass)
 
 removeResultRecord (int $activeId, int $pass)
 
 fetchValuePairsFromIndexedValues (array $indexedValues)
 
 fetchIndexedValuesFromValuePairs (array $valuePairs)
 
 areObligationsToBeConsidered ()
 
 setObligationsToBeConsidered (bool $obligationsToBeConsidered)
 
 updateTimestamp ()
 
 getTestPresentationConfig ()
 
- Public Member Functions inherited from ilObjQuestionScoringAdjustable
 saveAdditionalQuestionDataToDb ()
 Saves a record to the question types additional data table. More...
 
- Public Member Functions inherited from ilObjAnswerScoringAdjustable
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
- Public Member Functions inherited from iQuestionCondition
 getUserQuestionResult ($active_id, $pass)
 Get the user solution for a question by active_id and the test pass. More...
 

Data Fields

 $answers
 
 $output_type
 
 $isSingleline
 
 $lastChange
 
 $feedback_setting
 
- Data Fields inherited from assQuestion
const TRIM_PATTERN = '/^[\p{C}\p{Z}]+|[\p{C}\p{Z}]+$/u'
 
const ADDITIONAL_CONTENT_EDITING_MODE_RTE = 'default'
 
const ADDITIONAL_CONTENT_EDITING_MODE_IPE = 'pageobject'
 
ilAssQuestionFeedback $feedbackOBJ
 
bool $prevent_rte_usage = false
 
bool $selfassessmenteditingmode = false
 
int $defaultnroftries = 0
 
string $questionActionCmd = 'handleQuestionAction'
 
const KEY_VALUES_IMPLOSION_SEPARATOR = ':'
 
- Data Fields inherited from iQuestionCondition
const StringResultExpression = '~TEXT~'
 
const PercentageResultExpression = '%n%'
 
const NumericResultExpression = '#n#'
 
const MatchingResultExpression = ';n:m;'
 
const OrderingResultExpression = '$n,m,o,p$'
 
const NumberOfResultExpression = '+n+'
 
const ExclusiveResultExpression = '*n,m,o,p*'
 
const EmptyAnswerExpression = "?"
 

Protected Member Functions

 isForcedEmptySolution ($solutionSubmit)
 
 deleteImage ($image_filename)
 Deletes an image file. More...
 
 syncImages ()
 Sync images of a MC question on synchronisation with the original question. More...
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 getSolutionSubmit ()
 
 calculateReachedPointsForSolution ($found_values, $active_id=0)
 
 buildTestPresentationConfig ()
 
- Protected Member Functions inherited from assQuestion
 getQuestionAction ()
 
 isNonEmptyItemListPostSubmission (string $postSubmissionFieldname)
 
 log (int $active_id, string $langVar)
 
 savePreviewData (ilAssQuestionPreviewSession $previewSession)
 
 deletePageOfQuestion (int $question_id)
 
 onDuplicate (int $originalParentId, int $originalQuestionId, int $duplicateParentId, int $duplicateQuestionId)
 
 beforeSyncWithOriginal (int $origQuestionId, int $dupQuestionId, int $origParentObjId, int $dupParentObjId)
 
 afterSyncWithOriginal (int $origQuestionId, int $dupQuestionId, int $origParentObjId, int $dupParentObjId)
 
 onCopy (int $sourceParentId, int $sourceQuestionId, int $targetParentId, int $targetQuestionId)
 
 duplicateComments (int $parent_source_id, int $source_id, int $parent_target_id, int $target_id)
 
 deleteComments ()
 
 getNotesManager ()
 
 getNotesDataService ()
 
 getNotesRepo ()
 
 syncSuggestedSolutions (int $target_question_id, int $target_obj_id)
 
 duplicateSuggestedSolutionFiles (int $parent_id, int $question_id)
 Duplicates the files of a suggested solution if the question is duplicated. More...
 
 syncSuggestedSolutionFiles (int $target_question_id, int $target_obj_id)
 
 copySuggestedSolutionFiles (int $source_questionpool_id, int $source_question_id)
 
 copySuggestedSolutions (int $target_question_id)
 
 ensureNonNegativePoints ($points)
 
 purifyAndPrepareTextAreaOutput (string $content)
 
 getRTETextWithMediaObjects ()
 
 getSelfAssessmentFormatter ()
 
 lmMigrateQuestionTypeGenericContent (ilAssSelfAssessmentMigrator $migrator)
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 duplicateQuestionHints (int $originalQuestionId, int $duplicateQuestionId)
 
 duplicateSkillAssignments (int $srcParentId, int $srcQuestionId, int $trgParentId, int $trgQuestionId)
 
 buildQuestionDataQuery ()
 
 getCurrentSolutionResultSet (int $active_id, int $pass, bool $authorized=true)
 
 removeSolutionRecordById (int $solutionId)
 
 getSolutionRecordById (int $solutionId)
 
 deleteDummySolutionRecord (int $activeId, int $passIndex)
 
 isDummySolutionRecord (array $solutionRecord)
 
 deleteSolutionRecordByValues (int $activeId, int $passIndex, bool $authorized, array $matchValues)
 
 duplicateIntermediateSolutionAuthorized (int $activeId, int $passIndex)
 
 forceExistingIntermediateSolution (int $activeId, int $passIndex, bool $considerDummyRecordCreation)
 
 lookupMaxStep (int $active_id, int $pass)
 
 buildTestPresentationConfig ()
 build basic test question configuration instance More...
 
 getSuggestedSolutionsRepo ()
 
 loadSuggestedSolutions ()
 

Protected Attributes

 $selectionLimit
 
- Protected Attributes inherited from assQuestion
const HAS_SPECIFIC_FEEDBACK = true
 
ILIAS TestQuestionPool QuestionInfoService $questioninfo
 
ILIAS Test TestParticipantInfoService $testParticipantInfo
 
ILIAS HTTP Services $http
 
ILIAS Refinery Factory $refinery
 
ILIAS TestQuestionPool QuestionFilesService $questionFilesService
 
ILIAS DI LoggingServices $ilLog
 
int $id
 
string $title
 
string $comment
 
string $owner
 
string $author
 
int $thumb_size
 
string $question
 The question text. More...
 
float $points
 The maximum available points for the question. More...
 
bool $shuffle
 Indicates whether the answers will be shuffled or not. More...
 
int $test_id
 The database id of a test in which the question is contained. More...
 
int $obj_id = 0
 Object id of the container object. More...
 
 $ilias
 
ilGlobalPageTemplate $tpl
 
ilLanguage $lng
 
ilDBInterface $db
 
Container $dic
 
array $suggested_solutions
 
int $original_id = null
 
 $page
 
string $external_id = null
 
ilAssQuestionProcessLocker $processLocker
 
 $step
 
 $lastChange
 
Transformation $shuffler
 
ilTestQuestionConfig $testQuestionConfig
 
ilAssQuestionLifecycle $lifecycle
 
ilObjUser $current_user
 
SkillUsageService $skillUsageService
 
assQuestionSuggestedSolutionsDatabaseRepository $suggestedsolution_repo = null
 

Additional Inherited Members

- Static Public Member Functions inherited from assQuestion
static setForcePassResultUpdateEnabled (bool $forcePassResultsUpdateEnabled)
 
static isForcePassResultUpdateEnabled ()
 
static _getSuggestedSolutionOutput (int $question_id)
 
static _getReachedPoints (int $active_id, int $question_id, int $pass)
 
static logAction (string $logtext, int $active_id, int $question_id)
 
static isFileAvailable (string $file)
 
static saveOriginalId (int $questionId, int $originalId)
 
static resetOriginalId (int $questionId)
 
static _getInternalLinkHref (string $target="")
 
static instantiateQuestion (int $question_id)
 
static _getSolutionMaxPass (int $question_id, int $active_id)
 Returns the maximum pass a users question solution. More...
 
static _isWriteable (int $question_id, int $user_id)
 
static _setReachedPoints (int $active_id, int $question_id, float $points, float $maxpoints, int $pass, bool $manualscoring, bool $obligationsEnabled, ?int $test_id=null)
 Sets the points, a learner has reached answering the question Additionally objective results are updated. More...
 
static _needsManualScoring (int $question_id)
 
static getFeedbackClassNameByQuestionType (string $questionType)
 
static instantiateQuestionGUI (int $a_question_id)
 
static _questionExistsInTest (int $question_id, int $test_id)
 
static lookupParentObjId (int $questionId)
 
static isObligationPossible (int $questionId)
 
static implodeKeyValues (array $keyValues)
 
static explodeKeyValues (string $keyValues)
 
static convertISO8601FormatH_i_s_ExtendedToSeconds (string $time)
 
static extendedTrim (string $value)
 Trim non-printable characters from the beginning and end of a string. More...
 
- Static Protected Member Functions inherited from assQuestion
static getNumExistingSolutionRecords (int $activeId, int $pass, int $questionId)
 
- Static Protected Attributes inherited from assQuestion
static $forcePassResultsUpdateEnabled = false
 
static $imageSourceFixReplaceMap
 

Detailed Description

Class for multiple choice tests.

assMultipleChoice is a class for multiple choice questions.

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

Definition at line 38 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 99 of file class.assMultipleChoice.php.

References assQuestion\$author, assQuestion\$comment, $output_type, assQuestion\$owner, assQuestion\$question, assQuestion\$title, and ILIAS\MetaData\Repository\Validation\Data\__construct().

106  {
108  $this->output_type = $output_type;
109  $this->answers = [];
110  $this->shuffle = 1;
111  $this->selectionLimit = null;
112  $this->feedback_setting = 0;
113  }
__construct(VocabulariesInterface $vocabularies)
string $question
The question text.
+ Here is the call graph for this function:

Member Function Documentation

◆ addAnswer()

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

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
int$answer_idThe Answer id used in the database
See also
$answers
ASS_AnswerBinaryStateImage

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

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

378  : void {
379  $answertext = $this->getHtmlQuestionContentPurifier()->purify($answertext);
380  if (array_key_exists($order, $this->answers)) {
381  // insert answer
382  $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, $order, -1, 0);
383  $answer->setPointsUnchecked($points_unchecked);
384  $answer->setImage($answerimage);
385  $newchoices = [];
386  for ($i = 0; $i < $order; $i++) {
387  $newchoices[] = $this->answers[$i];
388  }
389  $newchoices[] = $answer;
390  for ($i = $order, $iMax = count($this->answers); $i < $iMax; $i++) {
391  $changed = $this->answers[$i];
392  $changed->setOrder($i + 1);
393  $newchoices[] = $changed;
394  }
395  $this->answers = $newchoices;
396  } else {
397  $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, count($this->answers), (int) $answer_id, 0);
398  $answer->setPointsUnchecked($points_unchecked);
399  $answer->setImage($answerimage);
400  $this->answers[] = $answer;
401  }
402  }
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
float $points
The maximum available points for the question.
+ Here is the call graph for this function:

◆ buildTestPresentationConfig()

assMultipleChoice::buildTestPresentationConfig ( )
protected

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

References ILIAS\Repository\lng().

1386  {
1387  $config = parent::buildTestPresentationConfig();
1388  $config->setUseUnchangedAnswerLabel($this->lng->txt('tst_mc_label_none_above'));
1389  return $config;
1390  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ calculateReachedPoints()

assMultipleChoice::calculateReachedPoints (   $active_id,
  $pass = null,
  $authorizedSolution = true,
  $returndetails = false 
)

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

The points are calculated from the given answers.

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

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

References $data, $DIC, $ilDB, assQuestion\$points, calculateReachedPointsForSolution(), assQuestion\getCurrentSolutionResultSet(), and assQuestion\getSolutionMaxPass().

Referenced by getExpressionTypes().

504  : float
505  {
506  if ($returndetails) {
507  throw new ilTestException('return details not implemented for ' . __METHOD__);
508  }
509 
510  global $DIC;
511  $ilDB = $DIC['ilDB'];
512 
513  $found_values = [];
514  if (is_null($pass)) {
515  $pass = $this->getSolutionMaxPass($active_id);
516  }
517  $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorizedSolution);
518  while ($data = $ilDB->fetchAssoc($result)) {
519  if (strcmp($data["value1"], "") != 0) {
520  array_push($found_values, $data["value1"]);
521  }
522  }
523 
524  $points = $this->calculateReachedPointsForSolution($found_values, $active_id);
525 
526  return $points;
527  }
calculateReachedPointsForSolution($found_values, $active_id=0)
float $points
The maximum available points for the question.
Base Exception for all Exceptions relating to Modules/Test.
global $DIC
Definition: feed.php:28
getSolutionMaxPass(int $active_id)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calculateReachedPointsForSolution()

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

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

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

Referenced by calculateReachedPoints().

1279  : float
1280  {
1281  if ($found_values == null) {
1282  $found_values = [];
1283  }
1284  $points = 0;
1285  foreach ($this->answers as $key => $answer) {
1286  if (in_array($key, $found_values)) {
1287  $points += $answer->getPoints();
1288  } else {
1289  $points += $answer->getPointsUnchecked();
1290  }
1291  }
1292  if ($active_id) {
1293  if (count($found_values) == 0) {
1294  $points = 0;
1295  }
1296  }
1297  return $points;
1298  }
float $points
The maximum available points for the question.
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the caller graph for this function:

◆ copyImages()

assMultipleChoice::copyImages (   $question_id,
  $source_questionpool 
)

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

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

925  : void
926  {
927  global $DIC;
928  $ilLog = $DIC['ilLog'];
929  $imagepath = $this->getImagePath();
930  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
931  $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
932  foreach ($this->answers as $answer) {
933  if ($answer->hasImage()) {
934  $filename = $answer->getImage();
935  if (!file_exists($imagepath)) {
936  ilFileUtils::makeDirParents($imagepath);
937  }
938  if (!@copy($imagepath_original . $filename, $imagepath . $filename)) {
939  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
940  $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
941  }
942  if (@file_exists($imagepath_original . $this->getThumbPrefix() . $filename)) {
943  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename)) {
944  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
945  $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
946  }
947  }
948  }
949  }
950  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: feed.php:28
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
$filename
Definition: buildRTE.php:78
ILIAS DI LoggingServices $ilLog
+ Here is the call graph for this function:

◆ copyObject()

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

Copies an assMultipleChoice object.

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

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

297  : int
298  {
299  if ($this->getId() <= 0) {
300  throw new RuntimeException('The question has not been saved. It cannot be duplicated');
301  }
302  // duplicate the question in database
303  $clone = $this;
304 
305  $original_id = $this->questioninfo->getOriginalId($this->id);
306  $clone->id = -1;
307  $source_questionpool_id = $this->getObjId();
308  $clone->setObjId($target_questionpool_id);
309  if ($title) {
310  $clone->setTitle($title);
311  }
312  $clone->saveToDb();
313  // copy question page content
314  $clone->copyPageOfQuestion($original_id);
315  // copy XHTML media objects
316  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
317  // duplicate the image
318  $clone->copyImages($original_id, $source_questionpool_id);
319 
320  $clone->onCopy($source_questionpool_id, $original_id, $clone->getObjId(), $clone->getId());
321 
322  return $clone->id;
323  }
+ Here is the call graph for this function:

◆ createNewOriginalFromThisDuplicate()

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

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

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

325  : int
326  {
327  if ($this->getId() <= 0) {
328  throw new RuntimeException('The question has not been saved. It cannot be duplicated');
329  }
330 
331  $sourceQuestionId = $this->id;
332  $sourceParentId = $this->getObjId();
333 
334  // duplicate the question in database
335  $clone = $this;
336  $clone->id = -1;
337 
338  $clone->setObjId($targetParentId);
339 
340  if ($targetQuestionTitle) {
341  $clone->setTitle($targetQuestionTitle);
342  }
343 
344  $clone->saveToDb();
345  // copy question page content
346  $clone->copyPageOfQuestion($sourceQuestionId);
347  // copy XHTML media objects
348  $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
349  // duplicate the image
350  $clone->copyImages($sourceQuestionId, $sourceParentId);
351 
352  $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
353 
354  return $clone->id;
355  }
+ 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 445 of file class.assMultipleChoice.php.

References deleteImage(), and ILIAS\UI\Implementation\Component\Table\getOrder().

445  : void
446  {
447  if ($index < 0) {
448  return;
449  }
450  if (count($this->answers) < 1) {
451  return;
452  }
453  if ($index >= count($this->answers)) {
454  return;
455  }
456  $answer = $this->answers[$index];
457  if ($answer->hasImage()) {
458  $this->deleteImage($answer->getImage());
459  }
460  unset($this->answers[$index]);
461  $this->answers = array_values($this->answers);
462  for ($i = 0, $iMax = count($this->answers); $i < $iMax; $i++) {
463  if ($this->answers[$i]->getOrder() > $index) {
464  $this->answers[$i]->setOrder($i);
465  }
466  }
467  }
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 866 of file class.assMultipleChoice.php.

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

Referenced by deleteAnswer(), and removeAnswerImage().

866  : void
867  {
868  $imagepath = $this->getImagePath();
869  @unlink($imagepath . $image_filename);
870  $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
871  @unlink($thumbpath);
872  }
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 ( bool  $for_test = true,
string  $title = "",
string  $author = "",
int  $owner = -1,
  $testObjId = null 
)

Duplicates an assMultipleChoiceQuestion.

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

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

246  : int
247  {
248  if ($this->id <= 0) {
249  // The question has not been saved. It cannot be duplicated
250  return -1;
251  }
252  // duplicate the question in database
253  $this_id = $this->getId();
254  $thisObjId = $this->getObjId();
255 
256  $clone = $this;
257 
258  $original_id = $this->questioninfo->getOriginalId($this->id);
259  $clone->id = -1;
260 
261  if ((int) $testObjId > 0) {
262  $clone->setObjId($testObjId);
263  }
264 
265  if ($title) {
266  $clone->setTitle($title);
267  }
268 
269  if ($author) {
270  $clone->setAuthor($author);
271  }
272  if ($owner) {
273  $clone->setOwner($owner);
274  }
275 
276  if ($for_test) {
277  $clone->saveToDb($original_id);
278  } else {
279  $clone->saveToDb();
280  }
281 
282  // copy question page content
283  $clone->copyPageOfQuestion($this_id);
284  // copy XHTML media objects
285  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
286  // duplicate the images
287  $clone->duplicateImages($this_id, $thisObjId);
288 
289  $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
290 
291  return $clone->id;
292  }
+ Here is the call graph for this function:

◆ flushAnswers()

assMultipleChoice::flushAnswers ( )

Deletes all answers.

See also
$answers

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

474  : void
475  {
476  $this->answers = [];
477  }

◆ getAdditionalTableName()

assMultipleChoice::getAdditionalTableName ( )

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

Returns
string The additional table name

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

Referenced by isForcedEmptySolution(), and loadFromDb().

808  : string
809  {
810  return "qpl_qst_mc";
811  }
+ 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 423 of file class.assMultipleChoice.php.

Referenced by getAvailableAnswerOptions().

423  : ?object
424  {
425  if ($index < 0) {
426  return null;
427  }
428  if (count($this->answers) < 1) {
429  return null;
430  }
431  if ($index >= count($this->answers)) {
432  return null;
433  }
434 
435  return $this->answers[$index];
436  }
+ Here is the caller graph for this function:

◆ getAnswerCount()

assMultipleChoice::getAnswerCount ( )

Returns the number of answers.

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

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

Referenced by isComplete(), and validateSolutionSubmit().

410  : int
411  {
412  return count($this->answers);
413  }
+ Here is the caller graph for this function:

◆ getAnswers()

& assMultipleChoice::getAnswers ( )

Returns a reference to the answers array.

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

References $answers.

Referenced by getAvailableAnswerOptions(), getMaximumPoints(), getSolutionSubmit(), lmMigrateQuestionTypeSpecificContent(), setExportDetailsXLSX(), and toJSON().

1007  : array
1008  {
1009  return $this->answers;
1010  }
+ 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 818 of file class.assMultipleChoice.php.

818  : string
819  {
820  return "qpl_a_mc";
821  }

◆ getAvailableAnswerOptions()

assMultipleChoice::getAvailableAnswerOptions (   $index = null)

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

Parameters
null | int$index

Implements iQuestionCondition.

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

References getAnswer(), and getAnswers().

1377  {
1378  if ($index !== null) {
1379  return $this->getAnswer($index);
1380  } else {
1381  return $this->getAnswers();
1382  }
1383  }
getAnswer($index=0)
Returns an answer with a given index.
& getAnswers()
Returns a reference to the answers array.
+ Here is the call graph for this function:

◆ getExpressionTypes()

◆ getIsSingleline()

assMultipleChoice::getIsSingleline ( )
Returns
mixed

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

References $isSingleline.

81  {
82  return $this->isSingleline;
83  }

◆ getMaximumPoints()

assMultipleChoice::getMaximumPoints ( )

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

See also
$points

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

References getAnswers().

Referenced by getExpressionTypes(), and isComplete().

484  : float
485  {
486  $total_max_points = 0.0;
487  foreach ($this->getAnswers() as $answer) {
488  $total_max_points += max($answer->getPointsChecked(), $answer->getPointsUnchecked());
489  }
490  return $total_max_points;
491  }
& getAnswers()
Returns a reference to the answers array.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assMultipleChoice::getMultilineAnswerSetting ( )

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

References $DIC.

1115  : int
1116  {
1117  global $DIC;
1118  $ilUser = $DIC['ilUser'];
1119 
1120  $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1121  if ($multilineAnswerSetting != 1) {
1122  $multilineAnswerSetting = 0;
1123  }
1124  return $multilineAnswerSetting;
1125  }
global $DIC
Definition: feed.php:28

◆ getOperators()

assMultipleChoice::getOperators (   $expression)

Get all available operations for a specific question.

Parameters
string$expression

Implements iQuestionCondition.

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

References ilOperatorsExpressionMapping\getOperatorsByExpression().

1308  : array
1309  {
1311  }
+ Here is the call graph for this function:

◆ getQuestionType()

assMultipleChoice::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question

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

Referenced by toJSON().

798  : string
799  {
800  return "assMultipleChoice";
801  }
+ 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 993 of file class.assMultipleChoice.php.

References assQuestion\getId().

993  : string
994  {
995  $text = parent::getRTETextWithMediaObjects();
996  foreach ($this->answers as $index => $answer) {
997  $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), 0, $index);
998  $answer_obj = $this->answers[$index];
999  $text .= $answer_obj->getAnswertext();
1000  }
1001  return $text;
1002  }
+ Here is the call graph for this function:

◆ getSelectionLimit()

assMultipleChoice::getSelectionLimit ( )
Returns
int

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

References $selectionLimit.

Referenced by isForcedEmptySolution(), toJSON(), and validateSolutionSubmit().

118  : ?int
119  {
120  return $this->selectionLimit;
121  }
+ Here is the caller graph for this function:

◆ getSolutionSubmit()

assMultipleChoice::getSolutionSubmit ( )
protected

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

References Vendor\Package\$a, $post, and getAnswers().

Referenced by isForcedEmptySolution(), and validateSolutionSubmit().

1258  : array
1259  {
1260  $solutionSubmit = [];
1261  $post = $this->dic->http()->wrapper()->post();
1262 
1263  foreach ($this->getAnswers() as $index => $a) {
1264  if ($post->has("multiple_choice_result_$index")) {
1265  $value = $post->retrieve("multiple_choice_result_$index", $this->dic->refinery()->kindlyTo()->string());
1266  if (is_numeric($value)) {
1267  $solutionSubmit[] = $value;
1268  }
1269  }
1270  }
1271  return $solutionSubmit;
1272  }
& getAnswers()
Returns a reference to the answers array.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$post
Definition: ltitoken.php:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSpecificFeedbackAllCorrectOptionLabel()

assMultipleChoice::getSpecificFeedbackAllCorrectOptionLabel ( )

Implements ilAssSpecificFeedbackOptionLabelProvider.

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

References $DIC, $ilDB, $res, and assQuestion\isObligationPossible().

1166  : string
1167  {
1168  return 'feedback_correct_sc_mc';
1169  }
+ 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.

Referenced by isForcedEmptySolution().

1157  : int
1158  {
1159  if ($this->feedback_setting) {
1160  return $this->feedback_setting;
1161  } else {
1162  return 1;
1163  }
1164  }
+ Here is the caller 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 137 of file class.assMultipleChoice.php.

References getAnswerCount(), and getMaximumPoints().

137  : bool
138  {
139  return $this->title !== ''
140  && $this->author !== ''
141  && $this->question !== ''
142  && $this->getAnswerCount() > 0
143  && $this->getMaximumPoints() >= 0;
144  }
getAnswerCount()
Returns the number of answers.
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
+ Here is the call graph for this function:

◆ isForcedEmptySolution()

◆ isSingleline()

assMultipleChoice::isSingleline ( )

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

References $isSingleline.

Referenced by isForcedEmptySolution(), loadFromDb(), setImageFile(), and setIsSingleline().

1392  : bool
1393  {
1394  return (bool) $this->isSingleline;
1395  }
+ Here is the caller graph for this function:

◆ lmMigrateQuestionTypeSpecificContent()

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

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

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

1050  : void
1051  {
1052  foreach ($this->getAnswers() as $answer) {
1053  /* @var ASS_AnswerBinaryStateImage $answer */
1054  $answer->setAnswertext($migrator->migrateToLmContent($answer->getAnswertext()));
1055  }
1056  }
& getAnswers()
Returns a reference to the answers array.
+ 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 170 of file class.assMultipleChoice.php.

References $data, $DIC, Vendor\Package\$e, $ilDB, assQuestion\$shuffle, ilRTE\_replaceMediaObjectImageSrc(), getAdditionalTableName(), ilAssQuestionLifecycle\getDraftInstance(), assQuestion\getImagePath(), ilAssQuestionLifecycle\getInstance(), assQuestion\getMinimumThumbSize(), isSingleline(), assQuestion\setAdditionalContentEditingMode(), assQuestion\setAuthor(), assQuestion\setComment(), assQuestion\setId(), assQuestion\setLifecycle(), assQuestion\setNrOfTries(), assQuestion\setObjId(), assQuestion\setOriginalId(), assQuestion\setOwner(), assQuestion\setPoints(), assQuestion\setQuestion(), setSelectionLimit(), assQuestion\setShuffle(), assQuestion\setThumbSize(), and assQuestion\setTitle().

170  : void
171  {
172  global $DIC;
173  $ilDB = $DIC['ilDB'];
174  $hasimages = 0;
175 
176  $result = $ilDB->queryF(
177  "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",
178  ["integer"],
179  [$question_id]
180  );
181  if ($result->numRows() == 1) {
182  $data = $ilDB->fetchAssoc($result);
183  $this->setId($question_id);
184  $this->setObjId($data["obj_fi"]);
185  $this->setTitle($data["title"] ?? '');
186  $this->setNrOfTries($data['nr_of_tries']);
187  $this->setComment($data["description"] ?? '');
188  $this->setOriginalId($data["original_id"]);
189  $this->setAuthor($data["author"]);
190  $this->setPoints($data["points"]);
191  $this->setOwner($data["owner"]);
192  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"] ?? '', 1));
193  $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
194  $this->setShuffle((bool) $shuffle);
195  if ($data['thumb_size'] !== null && $data['thumb_size'] >= $this->getMinimumThumbSize()) {
196  $this->setThumbSize($data['thumb_size']);
197  }
198  $this->isSingleline = $data['allow_images'] === null || $data['allow_images'] === '0';
199  $this->lastChange = $data['tstamp'];
200  $this->setSelectionLimit((int) $data['selection_limit'] > 0 ? (int) $data['selection_limit'] : null);
201  $this->feedback_setting = $data['feedback_setting'];
202 
203  try {
207  }
208 
209  try {
210  $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
211  } catch (ilTestQuestionPoolException $e) {
212  }
213  }
214 
215  $result = $ilDB->queryF(
216  "SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
217  ['integer'],
218  [$question_id]
219  );
220  if ($result->numRows() > 0) {
221  while ($data = $ilDB->fetchAssoc($result)) {
222  $imagefilename = $this->getImagePath() . $data["imagefile"];
223  if (!file_exists($imagefilename)) {
224  $data["imagefile"] = null;
225  }
226  $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"] ?? '', 1);
227 
228  $answer = new ASS_AnswerMultipleResponseImage(
229  $data["answertext"],
230  $data["points"],
231  $data["aorder"],
232  $data["answer_id"]
233  );
234  $answer->setPointsUnchecked($data["points_unchecked"]);
235  $answer->setImage($data["imagefile"] ? $data["imagefile"] : null);
236  array_push($this->answers, $answer);
237  }
238  }
239 
240  parent::loadFromDb($question_id);
241  }
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
setNrOfTries(int $a_nr_of_tries)
setOwner(int $owner=-1)
bool $shuffle
Indicates whether the answers will be shuffled or not.
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
setSelectionLimit($selectionLimit)
setThumbSize(int $a_size)
setComment(string $comment="")
global $DIC
Definition: feed.php:28
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
setPoints(float $points)
setObjId(int $obj_id=0)
setId(int $id=-1)
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setOriginalId(?int $original_id)
setTitle(string $title="")
setLifecycle(ilAssQuestionLifecycle $lifecycle)
setAuthor(string $author="")
setShuffle(?bool $shuffle=true)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setQuestion(string $question="")
+ Here is the call graph for this function:

◆ removeAnswerImage()

assMultipleChoice::removeAnswerImage (   $index)

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

References deleteImage().

1106  : void
1107  {
1108  $answer = $this->answers[$index];
1109  if (is_object($answer)) {
1110  $this->deleteImage($answer->getImage());
1111  $answer->setImage(null);
1112  }
1113  }
deleteImage($image_filename)
Deletes an image file.
+ Here is the call graph for this function:

◆ saveToDb()

assMultipleChoice::saveToDb (   $original_id = "")

Saves a assMultipleChoice object to a database.

Parameters
string$original_id

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

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

151  : void
152  {
153  if ($original_id == "") {
154  $this->saveQuestionDataToDb();
155  } else {
157  }
160 
161  $this->ensureNoInvalidObligation($this->getId());
162  parent::saveToDb($original_id);
163  }
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveQuestionDataToDb(int $original_id=-1)
+ Here is the call graph for this function:

◆ setAnswers()

assMultipleChoice::setAnswers ( array  $answers)

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

References $answers.

1012  : void
1013  {
1014  $this->answers = $answers;
1015  }

◆ setExportDetailsXLSX()

assMultipleChoice::setExportDetailsXLSX ( ilAssExcelFormatHelper  $worksheet,
int  $startrow,
int  $col,
int  $active_id,
int  $pass 
)

{}

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

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

1020  : int
1021  {
1022  parent::setExportDetailsXLSX($worksheet, $startrow, $col, $active_id, $pass);
1023 
1024  $solution = $this->getSolutionValues($active_id, $pass);
1025 
1026  $i = 1;
1027  foreach ($this->getAnswers() as $id => $answer) {
1028  $worksheet->setCell($startrow + $i, $col, $answer->getAnswertext());
1029  $worksheet->setBold($worksheet->getColumnCoord($col) . ($startrow + $i));
1030  $checked = false;
1031  foreach ($solution as $solutionvalue) {
1032  if ($id == $solutionvalue["value1"]) {
1033  $checked = true;
1034  }
1035  }
1036  if ($checked) {
1037  $worksheet->setCell($startrow + $i, $col + 2, 1);
1038  } else {
1039  $worksheet->setCell($startrow + $i, $col + 2, 0);
1040  }
1041  $i++;
1042  }
1043 
1044  return $startrow + $i + 1;
1045  }
getSolutionValues($active_id, $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
getColumnCoord(int $a_col)
Get column "name" from number.
setCell($a_row, $a_col, $a_value, $datatype=null)
setBold(string $a_coords)
Set cell(s) to bold.
& getAnswers()
Returns a reference to the answers array.
+ 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 830 of file class.assMultipleChoice.php.

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

830  : int
831  {
832  $result = 0;
833  if (!empty($image_tempfilename)) {
834  $image_filename = str_replace(" ", "_", $image_filename);
835  $imagepath = $this->getImagePath();
836  if (!file_exists($imagepath)) {
837  ilFileUtils::makeDirParents($imagepath);
838  }
839  if (!ilFileUtils::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) {
840  $result = 2;
841  } else {
842  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
843  if (!preg_match("/^image/", $mimetype)) {
844  unlink($imagepath . $image_filename);
845  $result = 1;
846  } else {
847  // create thumbnail file
848  if ($this->isSingleline && ($this->getThumbSize())) {
849  $this->generateThumbForFile(
850  $image_filename,
851  $this->getImagePath(),
852  $this->getThumbSize()
853  );
854  }
855  }
856  }
857  }
858  return $result;
859  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
+ Here is the call graph for this function:

◆ setIsSingleline()

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

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

References $isSingleline, and isSingleline().

+ Here is the call graph for this function:

◆ setMultilineAnswerSetting()

assMultipleChoice::setMultilineAnswerSetting (   $a_setting = 0)

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

References $DIC.

1127  : void
1128  {
1129  global $DIC;
1130  $ilUser = $DIC['ilUser'];
1131  $ilUser->writePref("tst_multiline_answers", $a_setting);
1132  }
global $DIC
Definition: feed.php:28

◆ setSelectionLimit()

assMultipleChoice::setSelectionLimit (   $selectionLimit)
Parameters
int$selectionLimit

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

References $selectionLimit.

Referenced by loadFromDb().

126  : void
127  {
128  $this->selectionLimit = $selectionLimit;
129  }
+ Here is the caller graph for this function:

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

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

◆ syncImages()

assMultipleChoice::syncImages ( )
protected

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

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

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

Referenced by syncWithOriginal().

955  : void
956  {
957  global $DIC;
958  $ilLog = $DIC['ilLog'];
959  $imagepath = $this->getImagePath();
960  $question_id = $this->questioninfo->getOriginalId($this->getId());
961  $originalObjId = parent::lookupParentObjId($this->questioninfo->getOriginalId($this->getId()));
962  $imagepath_original = $this->getImagePath($question_id, $originalObjId);
963 
964  ilFileUtils::delDir($imagepath_original);
965  foreach ($this->answers as $answer) {
966  if ($answer->hasImage()) {
967  $filename = $answer->getImage();
968  if (@file_exists($imagepath . $filename)) {
969  if (!file_exists($imagepath)) {
970  ilFileUtils::makeDirParents($imagepath);
971  }
972  if (!file_exists($imagepath_original)) {
973  ilFileUtils::makeDirParents($imagepath_original);
974  }
975  if (!@copy($imagepath . $filename, $imagepath_original . $filename)) {
976  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
977  $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
978  }
979  }
980  if (@file_exists($imagepath . $this->getThumbPrefix() . $filename)) {
981  if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename)) {
982  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
983  $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
984  }
985  }
986  }
987  }
988  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: feed.php:28
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$filename
Definition: buildRTE.php:78
ILIAS DI LoggingServices $ilLog
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ syncWithOriginal()

assMultipleChoice::syncWithOriginal ( )

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

References syncImages().

785  : void
786  {
787  if ($this->questioninfo->getOriginalId($this->getId())) {
788  $this->syncImages();
789  parent::syncWithOriginal();
790  }
791  }
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.

Implements ilAssQuestionLMExportable.

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

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

1061  : string
1062  {
1063  $result = [];
1064  $result['id'] = $this->getId();
1065  $result['type'] = (string) $this->getQuestionType();
1066  $result['title'] = $this->getTitleForHTMLOutput();
1067  $result['question'] = $this->formatSAQuestion($this->getQuestion());
1068  $result['nr_of_tries'] = $this->getNrOfTries();
1069  $result['shuffle'] = $this->getShuffle();
1070  $result['selection_limit'] = (int) $this->getSelectionLimit();
1071  $result['feedback'] = [
1072  'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1073  'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1074  ];
1075 
1076  $answers = [];
1077  $has_image = false;
1078  foreach ($this->getAnswers() as $key => $answer_obj) {
1079  if ((string) $answer_obj->getImage()) {
1080  $has_image = true;
1081  }
1082  array_push($answers, [
1083  "answertext" => $this->formatSAQuestion($answer_obj->getAnswertext()),
1084  "points_checked" => (float) $answer_obj->getPointsChecked(),
1085  "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1086  "order" => (int) $answer_obj->getOrder(),
1087  "image" => (string) $answer_obj->getImage(),
1088  "feedback" => $this->formatSAQuestion(
1089  $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
1090  )
1091  ]);
1092  }
1093  $result['answers'] = $answers;
1094 
1095  if ($has_image) {
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  }
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getQuestionType()
Returns the question type of the question.
string $key
Consumer key/client ID value.
Definition: System.php:193
& getAnswers()
Returns a reference to the answers array.
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
+ Here is the call graph for this function:

◆ validateSolutionSubmit()

assMultipleChoice::validateSolutionSubmit ( )

Implements assQuestionInterface.

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

References getAnswerCount(), getSelectionLimit(), getSolutionSubmit(), and ILIAS\Repository\lng().

529  : bool
530  {
531  $submit = $this->getSolutionSubmit();
532 
533  if ($this->getSelectionLimit()) {
534  if (count($submit) > $this->getSelectionLimit()) {
535  $failureMsg = sprintf(
536  $this->lng->txt('ass_mc_sel_lim_exhausted_hint'),
537  $this->getSelectionLimit(),
538  $this->getAnswerCount()
539  );
540 
541  $this->tpl->setOnScreenMessage('failure', $failureMsg, true);
542  return false;
543  }
544  }
545 
546  return true;
547  }
getAnswerCount()
Returns the number of answers.
+ Here is the call graph for this function:

Field Documentation

◆ $answers

assMultipleChoice::$answers

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

Referenced by getAnswers(), setAnswers(), and toJSON().

◆ $feedback_setting

assMultipleChoice::$feedback_setting

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

Referenced by getSpecificFeedbackSetting().

◆ $isSingleline

assMultipleChoice::$isSingleline

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

Referenced by getIsSingleline(), isSingleline(), and setIsSingleline().

◆ $lastChange

assMultipleChoice::$lastChange

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

◆ $output_type

assMultipleChoice::$output_type

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

Referenced by __construct().

◆ $selectionLimit

assMultipleChoice::$selectionLimit
protected

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

Referenced by getSelectionLimit(), and setSelectionLimit().


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