ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
assMultipleChoice Class Reference

Class for multiple choice tests. More...

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

Public Member Functions

 setIsSingleline (bool $is_singleline)
 
 __construct (string $title="", string $comment="", string $author="", int $owner=-1, string $question="", private int $output_type=self::OUTPUT_ORDER)
 assMultipleChoice constructor More...
 
 getSelectionLimit ()
 
 setSelectionLimit (?int $selection_limit)
 
 isComplete ()
 
 saveToDb (?int $original_id=null)
 
 loadFromDb (int $question_id)
 
 addAnswer (string $answertext='', float $points=0.0, float $points_unchecked=0.0, int $order=0, ?string $answerimage=null, int $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 (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 validateSolutionSubmit ()
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 saveAdditionalQuestionDataToDb ()
 
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 getAdditionalTableName ()
 Returns the name of the additional question data table in the database. More...
 
 getAnswerTableName ()
 Returns the name of the answer table in the database. More...
 
 setImageFile ($image_filename, $image_tempfilename="")
 Sets the image file and uploads the image to the object's image directory. More...
 
 getRTETextWithMediaObjects ()
 
& getAnswers ()
 Returns a reference to the answers array. More...
 
 setAnswers (array $answers)
 
 toJSON ()
 Returns a JSON representation of the question. More...
 
 removeAnswerImage ($index)
 
 getMultilineAnswerSetting ()
 
 setMultilineAnswerSetting ($setting=0)
 
 setSpecificFeedbackSetting (int $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 (string $expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. More...
 
 getUserQuestionResult (int $active_id, int $pass)
 Get the user solution for a question by active_id and the test pass. More...
 
 getAvailableAnswerOptions ($index=null)
 If index is null, the function returns an array with all anwser options Else it returns the specific answer option. More...
 
 isSingleline ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 MUST return an array of the question settings that can be stored in the log. More...
 
 solutionValuesToText (array $solution_values)
 MUST convert the given solution values into text. More...
 
 getCorrectSolutionForTextOutput (int $active_id, int $pass)
 
 toNormalized (Transformations $transformations, array $context=[])
 
 fromNormalized (array $normalized, Transformations $transformations)
 
- Public Member Functions inherited from assQuestion
 getQuestionType ()
 
 isComplete ()
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 calculateReachedPoints (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 MUST return an array of the question settings that can be stored in the log. More...
 
 getCurrentUser ()
 
 getShuffler ()
 
 setShuffler (Transformation $shuffler)
 
 setProcessLocker (ilAssQuestionProcessLocker $processLocker)
 
 getProcessLocker ()
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 toXML (bool $a_include_header=true, bool $a_include_binary=true, bool $a_shuffle=false, bool $test_output=false, bool $force_image_references=false)
 
 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 $authorized_solution=true)
 
 calculateResultsFromSolution (int $active_id, int $pass)
 Calculates the question results from a previously saved question solution. More...
 
 persistWorkingState (int $active_id, $pass, bool $authorized=true)
 persists the working state for current testactive and testpass More...
 
 persistPreviewState (ilAssQuestionPreviewSession $preview_session)
 persists the preview state for current user and question More...
 
 validateSolutionSubmit ()
 
 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, ?int $pass=null)
 
 getSolutionValues (int $active_id, ?int $pass=null, bool $authorized=true)
 Loads solutions of a given user from the database an returns it. More...
 
 deleteAnswers (int $question_id)
 
 deleteAdditionalTableData (int $question_id)
 
 delete (int $question_id)
 
 getTotalAnswers ()
 
 cloneXHTMLMediaObjectsOfQuestion (int $source_question_id)
 
 createPageObject ()
 
 clonePageOfQuestion (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=null)
 
 updateOriginalId (?int $original_id=null)
 
 duplicate (bool $set_original_id=true, string $title='', string $author='', int $owner=-1, $test_obj_id=null)
 
 copyObject (int $target_parent_id, string $title='')
 
 createNewOriginalFromThisDuplicate (int $target_parent_id, string $target_question_title='')
 
 saveToDb (?int $original_id=null)
 
 deleteSuggestedSolutions ()
 
 getSuggestedSolution (int $subquestion_index=0)
 
 resolveInternalLink (string $internal_link)
 
 resolveSuggestedSolutionLinks ()
 
 getInternalLinkHref (string $target)
 
 syncWithOriginal ()
 
 getPoints ()
 
 setPoints (float $points)
 
 getSolutionMaxPass (int $active_id)
 
 isWriteable ()
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $preview_session)
 
 isPreviewSolutionCorrect (ilAssQuestionPreviewSession $preview_session)
 
 adjustReachedPointsByScoringOptions (float $points, int $active_id)
 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="")
 
 getQuestionTypeID ()
 
 cleanupMediaObjectUsage ()
 
 getInstances ()
 
 getActiveUserData (int $active_id)
 Returns the user id and the test id for a given active id. More...
 
 hasSpecificFeedback ()
 
 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)
 
 isAnswered (int $active_id, int $pass)
 
 getAdditionalContentEditingMode ()
 
 setAdditionalContentEditingMode (?string $additionalContentEditingMode)
 
 isAdditionalContentEditingModePageObject ()
 
 isValidAdditionalContentEditingMode (string $additionalContentEditingMode)
 
 getValidAdditionalContentEditingModes ()
 
 getHtmlUserSolutionPurifier ()
 
 getHtmlQuestionContentPurifier ()
 
 setLastChange (int $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 ()
 
 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 $value_pairs)
 
 updateTimestamp ()
 
 getTestPresentationConfig ()
 
 hasWritableOriginalInQuestionPool ()
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
 getSolutionForTextOutput (int $active_id, int $pass)
 
 getCorrectSolutionForTextOutput (int $active_id, int $pass)
 
 getVariablesAsTextArray (int $active_id, int $pass)
 
 toNormalized (Transformations $transformations, array $context=[])
 
 fromNormalized (array $normalized, Transformations $transformations)
 
 validateSolutionSubmit ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
- Public Member Functions inherited from iQuestionCondition
 getOperators (string $expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. More...
 
 getUserQuestionResult (int $active_id, int $pass)
 Get the user solution for a question by active_id and the test pass. More...
 
 getAvailableAnswerOptions (?int $index=null)
 If index is null, the function returns an array with all anwser options else it returns the specific answer option. More...
 
 getSpecificFeedbackAllCorrectOptionLabel ()
 
 toJSON ()
 
 toNormalized (Transformations $transformations, array $context=[])
 Convert the internal state of the implementing object into a language-neutral array structure. More...
 
 fromNormalized (array $normalized, Transformations $transformations)
 Restore the object from its normalized representation. More...
 

Data Fields

const OUTPUT_ORDER = 0
 
const OUTPUT_RANDOM = 1
 
array $answers = []
 
bool $is_singleline = true
 
int $feedback_setting = 0
 
- Data Fields inherited from assQuestion
const ADDITIONAL_CONTENT_EDITING_MODE_RTE = 'default'
 
const ADDITIONAL_CONTENT_EDITING_MODE_IPE = 'pageobject'
 
const TRIM_PATTERN = '/^[\p{C}\p{Z}]+|[\p{C}\p{Z}]+$/u'
 
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

 cloneQuestionTypeSpecificProperties (\assQuestion $target)
 
 isForcedEmptySolution (array $solutionSubmit)
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 getSolutionSubmit ()
 
 calculateReachedPointsForSolution (?array $found_values, int $active_id=0)
 
 buildTestPresentationConfig ()
 
 solutionValuesToLog (AdditionalInformationGenerator $additional_info, array $solution_values)
 MUST convert the given solution values into an array or a string that can be stored in the log. More...
 
- Protected Member Functions inherited from assQuestion
 solutionValuesToLog (AdditionalInformationGenerator $additional_info, array $solution_values)
 MUST convert the given solution values into an array or a string that can be stored in the log. More...
 
 solutionValuesToText (array $solution_values)
 MUST convert the given solution values into text. More...
 
 getQuestionAction ()
 
 isNonEmptyItemListPostSubmission (string $post_submission_field_name)
 
 savePreviewData (ilAssQuestionPreviewSession $preview_session)
 
 deletePageOfQuestion (int $question_id)
 
 cloneQuestionTypeSpecificProperties (self $target)
 
 removeAllImageFiles (string $image_target_path)
 
 onDuplicate (int $original_parent_id, int $original_question_id, int $duplicate_parent_id, int $duplicate_question_id)
 
 afterSyncWithOriginal (int $original_question_id, int $clone_question_id, int $original_parent_id, int $clone_parent_id)
 
 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 ()
 
 cloneSuggestedSolutions (int $source_question_id, int $target_question_id)
 
 duplicateSuggestedSolutionFiles (int $parent_id, int $question_id)
 Duplicates the files of a suggested solution if the question is duplicated. More...
 
 cloneSuggestedSolutionFiles (int $source_question_id, int $target_question_id)
 
 copySuggestedSolutions (int $target_question_id)
 
 ensureNonNegativePoints (float $points)
 
 purifyAndPrepareTextAreaOutput (string $content)
 
 getRTETextWithMediaObjects ()
 
 getSelfAssessmentFormatter ()
 
 lmMigrateQuestionTypeGenericContent (ilAssSelfAssessmentMigrator $migrator)
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 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 ()
 
 getSuggestedSolutionsRepo ()
 
 loadSuggestedSolutions ()
 
 answerToLog (AdditionalInformationGenerator $additional_info, int $active_id, int $pass)
 

Protected Attributes

int $selection_limit = null
 
- Protected Attributes inherited from assQuestion
const HAS_SPECIFIC_FEEDBACK = true
 
GeneralQuestionPropertiesRepository $questionrepository
 
RequestDataCollector $questionpool_request
 
QuestionFiles $question_files
 
ilAssQuestionProcessLocker $processLocker
 
ilTestQuestionConfig $testQuestionConfig
 
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo
 
ILIAS $ilias
 
ilGlobalPageTemplate $tpl
 
ilLanguage $lng
 
ilDBInterface $db
 
ilObjUser $current_user
 
SkillUsageService $skillUsageService
 
HTTPServices $http
 
Refinery $refinery
 
Transformation $shuffler
 
LoggingServices $log
 
Container $dic
 
ilAssQuestionLifecycle $lifecycle
 
ilAssQuestionPage $page
 
TestResultRepository $test_result_repository
 
int $id
 
string $title
 
string $comment
 
int $owner
 
string $author
 
int $thumb_size
 
string $question
 
float $points = 0.0
 
bool $shuffle = true
 
int $test_id
 
int $obj_id = 0
 
int $original_id = null
 
int $lastChange = null
 
string $external_id = null
 
int $step = null
 
array $suggested_solutions
 

Additional Inherited Members

- Static Public Member Functions inherited from assQuestion
static setForcePassResultUpdateEnabled (bool $force_pass_results_update_enabled)
 
static isForcePassResultUpdateEnabled ()
 
static _getSuggestedSolutionOutput (int $question_id)
 
static _getReachedPoints (int $active_id, int $question_id, int $pass)
 
static isFileAvailable (string $file)
 
static saveOriginalId (int $questionId, int $originalId)
 
static resetOriginalId (int $questionId)
 
static instantiateQuestion (int $question_id)
 
static _getSolutionMaxPass (int $question_id, int $active_id)
 Returns the maximum pass a users question solution. More...
 
static getFeedbackClassNameByQuestionType (string $questionType)
 
static _questionExistsInTest (int $question_id, int $test_id)
 
static lookupParentObjId (int $question_id)
 
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 $force_pass_results_update_enabled = 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 44 of file class.assMultipleChoice.php.

Constructor & Destructor Documentation

◆ __construct()

assMultipleChoice::__construct ( string  $title = "",
string  $comment = "",
string  $author = "",
int  $owner = -1,
string  $question = "",
private int  $output_type = self::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 75 of file class.assMultipleChoice.php.

82 {
84 $this->answers = [];
85 $this->shuffle = true;
86 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addAnswer()

assMultipleChoice::addAnswer ( string  $answertext = '',
float  $points = 0.0,
float  $points_unchecked = 0.0,
int  $order = 0,
?string  $answerimage = null,
int  $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 213 of file class.assMultipleChoice.php.

220 : void {
221 if (array_key_exists($order, $this->answers)) {
222 // insert answer
224 $this->getHtmlQuestionContentPurifier()->purify($answertext),
225 $points,
226 $order,
227 -1,
228 0
229 );
230 $answer->setPointsUnchecked($points_unchecked);
231 $answer->setImage($answerimage);
232 $newchoices = [];
233 for ($i = 0; $i < $order; $i++) {
234 $newchoices[] = $this->answers[$i];
235 }
236 $newchoices[] = $answer;
237 for ($i = $order, $iMax = count($this->answers); $i < $iMax; $i++) {
238 $changed = $this->answers[$i];
239 $changed->setOrder($i + 1);
240 $newchoices[] = $changed;
241 }
242 $this->answers = $newchoices;
243 return;
244 } else {
246 $this->getHtmlQuestionContentPurifier()->purify($answertext),
247 $points,
248 count($this->answers),
249 $answer_id,
250 0
251 );
252 $answer->setPointsUnchecked($points_unchecked);
253 $answer->setImage($answerimage);
254 $this->answers[] = $answer;
255 }
256 }
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked,...

References ILIAS\Questions\AnswerFormTypes\Cloze\Migration\getHtmlQuestionContentPurifier().

+ Here is the call graph for this function:

◆ buildTestPresentationConfig()

assMultipleChoice::buildTestPresentationConfig ( )
protected

Reimplemented from assQuestion.

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

870 {
871 $config = parent::buildTestPresentationConfig();
872 $config->setUseUnchangedAnswerLabel($this->lng->txt('tst_mc_label_none_above'));
873 return $config;
874 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ calculateReachedPoints()

assMultipleChoice::calculateReachedPoints ( int  $active_id,
?int  $pass = null,
bool  $authorized_solution = true 
)

Reimplemented from assQuestion.

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

351 : float {
352 $found_values = [];
353 if ($pass === null) {
354 $pass = $this->getSolutionMaxPass($active_id);
355 }
356 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized_solution);
357 while ($data = $this->db->fetchAssoc($result)) {
358 if ($data['value1'] !== '') {
359 array_push($found_values, $data['value1']);
360 }
361 }
362
363 return $this->calculateReachedPointsForSolution($found_values, $active_id);
364 }
calculateReachedPointsForSolution(?array $found_values, int $active_id=0)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getSolutionMaxPass(int $active_id)
$data
Definition: storeScorm.php:45

◆ calculateReachedPointsForSolution()

assMultipleChoice::calculateReachedPointsForSolution ( ?array  $found_values,
int  $active_id = 0 
)
protected

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

787 : float {
788 if ($found_values === []
789 && $active_id !== 0) {
790 return 0.0;
791 }
792
793 $found_values ??= [];
794 $points = 0.0;
795 foreach ($this->answers as $key => $answer) {
796 if (in_array($key, $found_values)) {
797 $points += $answer->getPoints();
798 continue;
799 }
800 $points += $answer->getPointsUnchecked();
801 }
802
803 return $points;
804 }

◆ cloneQuestionTypeSpecificProperties()

assMultipleChoice::cloneQuestionTypeSpecificProperties ( \assQuestion  $target)
protected

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

188 : \assQuestion {
189 $this->cloneImages(
190 $this->getId(),
191 $this->getObjId(),
192 $target->getId(),
193 $target->getObjId(),
194 $this->getAnswers()
195 );
196 return $target;
197 }

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

299 : void
300 {
301 if ($index < 0) {
302 return;
303 }
304 if (count($this->answers) < 1) {
305 return;
306 }
307 if ($index >= count($this->answers)) {
308 return;
309 }
310 $answer = $this->answers[$index];
311 if ($answer->hasImage()) {
312 $this->deleteImage($answer->getImage());
313 }
314 unset($this->answers[$index]);
315 $this->answers = array_values($this->answers);
316 for ($i = 0, $iMax = count($this->answers); $i < $iMax; $i++) {
317 if ($this->answers[$i]->getOrder() > $index) {
318 $this->answers[$i]->setOrder($i);
319 }
320 }
321 }

References ILIAS\UI\Implementation\Component\Table\getOrder().

+ Here is the call graph for this function:

◆ flushAnswers()

assMultipleChoice::flushAnswers ( )

Deletes all answers.

See also
$answers

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

328 : void
329 {
330 $this->answers = [];
331 }

◆ fromNormalized()

assMultipleChoice::fromNormalized ( array  $normalized,
Transformations  $transformations 
)
Parameters
array<array-key,mixed>$normalized

Reimplemented from assQuestion.

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

981 : static
982 {
983 $clone = parent::fromNormalized($normalized, $transformations);
984 $clone->selection_limit = $transformations->nullableInt($normalized['selection_limit']);
985 $clone->is_singleline = $transformations->bool($normalized['single_line']);
986 $clone->answers = array_map(
987 static fn(array $answer): ASS_AnswerMultipleResponseImage => $transformations->denormalize($answer, new ASS_AnswerMultipleResponseImage()),
988 $normalized['answers']
989 );
990
991 return $clone;
992 }
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)

References ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\bool(), ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\denormalize(), and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\nullableInt().

+ Here is the call graph for this function:

◆ getAdditionalTableName()

assMultipleChoice::getAdditionalTableName ( )

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

Returns
string The additional table name

Reimplemented from assQuestion.

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

576 : string
577 {
578 return "qpl_qst_mc";
579 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ getAnswer()

assMultipleChoice::getAnswer (   $index = 0)

Returns an answer with a given index.

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

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

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

277 : ?object
278 {
279 if ($index < 0) {
280 return null;
281 }
282 if (count($this->answers) < 1) {
283 return null;
284 }
285 if ($index >= count($this->answers)) {
286 return null;
287 }
288
289 return $this->answers[$index];
290 }

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

264 : int
265 {
266 return count($this->answers);
267 }

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getAnswers()

& assMultipleChoice::getAnswers ( )

Returns a reference to the answers array.

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

643 : array
644 {
645 return $this->answers;
646 }

◆ getAnswerTableName()

assMultipleChoice::getAnswerTableName ( )

Returns the name of the answer table in the database.

Returns
string The answer table name

Reimplemented from assQuestion.

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

586 : string
587 {
588 return "qpl_a_mc";
589 }

◆ 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

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

861 {
862 if ($index !== null) {
863 return $this->getAnswer($index);
864 } else {
865 return $this->getAnswers();
866 }
867 }
getAnswer($index=0)
Returns an answer with a given index.
& getAnswers()
Returns a reference to the answers array.

◆ getCorrectSolutionForTextOutput()

assMultipleChoice::getCorrectSolutionForTextOutput ( int  $active_id,
int  $pass 
)

Reimplemented from assQuestion.

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

952 : array
953 {
954 return array_map(
955 fn(ASS_AnswerMultipleResponseImage $v): string => $v->getAnswertext()
956 . "({$this->lng->txt('points')} "
957 . "{$this->lng->txt('checked')}: {$v->getPointsChecked()}, "
958 . "{$this->lng->txt('unchecked')}: {$v->getPointsUnchecked()})",
959 $this->getAnswers()
960 );
961 }
getAnswertext()
Gets the answer text.

References ASS_AnswerSimple\getAnswertext().

+ Here is the call graph for this function:

◆ getExpressionTypes()

◆ getMaximumPoints()

assMultipleChoice::getMaximumPoints ( )

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

See also
$points

Reimplemented from assQuestion.

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

338 : float
339 {
340 $total_max_points = 0.0;
341 foreach ($this->getAnswers() as $answer) {
342 $total_max_points += max($answer->getPointsChecked(), $answer->getPointsUnchecked());
343 }
344 return $total_max_points;
345 }

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assMultipleChoice::getMultilineAnswerSetting ( )

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

721 : int
722 {
723 return $this->current_user->getPref('tst_multiline_answers') === '1' ? 1 : 0;
724 }

◆ getOperators()

assMultipleChoice::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

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

806 : array
807 {
809 }
static getOperatorsByExpression(string $expression)

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ 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

Reimplemented from assQuestion.

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

566 : string
567 {
568 return "assMultipleChoice";
569 }

◆ getRTETextWithMediaObjects()

assMultipleChoice::getRTETextWithMediaObjects ( )

Reimplemented from assQuestion.

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

629 : string
630 {
631 $text = parent::getRTETextWithMediaObjects();
632 foreach ($this->answers as $index => $answer) {
633 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), 0, $index);
634 $answer_obj = $this->answers[$index];
635 $text .= $answer_obj->getAnswertext();
636 }
637 return $text;
638 }
$text
Definition: xapiexit.php:21

References $text, and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ getSelectionLimit()

assMultipleChoice::getSelectionLimit ( )

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

88 : ?int
89 {
91 }

References $selection_limit.

◆ getSolutionSubmit()

assMultipleChoice::getSolutionSubmit ( )
protected

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

768 : array
769 {
770 $solutionSubmit = [];
771 $post = $this->dic->http()->wrapper()->post();
772
773 foreach ($this->getAnswers() as $index => $a) {
774 if ($post->has("multiple_choice_result_$index")) {
775 $value = $post->retrieve("multiple_choice_result_$index", $this->dic->refinery()->kindlyTo()->string());
776 if (is_numeric($value)) {
777 $solutionSubmit[] = $value;
778 }
779 }
780 }
781 return $solutionSubmit;
782 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a.

◆ getSpecificFeedbackAllCorrectOptionLabel()

assMultipleChoice::getSpecificFeedbackAllCorrectOptionLabel ( )

Implements ilAssSpecificFeedbackOptionLabelProvider.

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

763 : string
764 {
765 return 'feedback_correct_sc_mc';
766 }

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

754 : int
755 {
756 if ($this->feedback_setting) {
758 } else {
759 return 1;
760 }
761 }

◆ getUserQuestionResult()

assMultipleChoice::getUserQuestionResult ( int  $active_id,
int  $pass 
)

Get the user solution for a question by active_id and the test pass.

Implements iQuestionCondition.

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

825 $result = new ilUserQuestionResult($this, $active_id, $pass);
826
827 $maxStep = $this->lookupMaxStep($active_id, $pass);
828 if ($maxStep > 0) {
829 $data = $this->db->queryF(
830 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
831 ["integer", "integer", "integer","integer"],
832 [$active_id, $pass, $this->getId(), $maxStep]
833 );
834 } else {
835 $data = $this->db->queryF(
836 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
837 ["integer", "integer", "integer"],
838 [$active_id, $pass, $this->getId()]
839 );
840 }
841
842 while ($row = $this->db->fetchAssoc($data)) {
843 $result->addKeyValue($row["value1"], $row["value1"]);
844 }
845
846 $points = $this->calculateReachedPoints($active_id, $pass);
847 $max_points = $this->getMaximumPoints();
848
849 $result->setReachedPercentage(($points / $max_points) * 100);
850
851 return $result;
852 }
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
calculateReachedPoints(int $active_id, ?int $pass=null, bool $authorized_solution=true)
lookupMaxStep(int $active_id, int $pass)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ isComplete()

assMultipleChoice::isComplete ( )

Reimplemented from assQuestion.

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

98 : bool
99 {
100 return $this->title !== ''
101 && $this->author !== ''
102 && $this->question !== ''
103 && $this->getAnswerCount() > 0
104 && $this->getMaximumPoints() >= 0;
105 }
getAnswerCount()
Returns the number of answers.

References getAnswerCount(), and getMaximumPoints().

+ Here is the call graph for this function:

◆ isForcedEmptySolution()

assMultipleChoice::isForcedEmptySolution ( array  $solutionSubmit)
protected

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

386 : bool
387 {
388 $tst_force_form_diff_input = $this->questionpool_request->strArray('tst_force_form_diff_input');
389 return !count($solutionSubmit) && !empty($tst_force_form_diff_input);
390 }

◆ isSingleline()

assMultipleChoice::isSingleline ( )

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

876 : bool
877 {
879 }

◆ lmMigrateQuestionTypeSpecificContent()

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

Reimplemented from assQuestion.

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

656 : void
657 {
658 foreach ($this->getAnswers() as $answer) {
659 /* @var ASS_AnswerBinaryStateImage $answer */
660 $answer->setAnswertext($migrator->migrateToLmContent($answer->getAnswertext()));
661 }
662 }

References ilAssSelfAssessmentMigrator\migrateToLmContent().

+ Here is the call graph for this function:

◆ loadFromDb()

assMultipleChoice::loadFromDb ( int  $question_id)

Reimplemented from assQuestion.

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

115 : void
116 {
117 $result = $this->db->queryF(
118 "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",
119 ["integer"],
120 [$question_id]
121 );
122 if ($result->numRows() == 1) {
123 $data = $this->db->fetchAssoc($result);
124 $this->setId($question_id);
125 $this->setObjId($data["obj_fi"]);
126 $this->setTitle($data["title"] ?? '');
127 $this->setNrOfTries($data['nr_of_tries']);
128 $this->setComment($data["description"] ?? '');
129 $this->setOriginalId($data["original_id"]);
130 $this->setAuthor($data["author"]);
131 $this->setPoints($data["points"]);
132 $this->setOwner($data["owner"]);
133 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"] ?? '', 1));
134 $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
135 $this->setShuffle((bool) $shuffle);
136 if ($data['thumb_size'] !== null && $data['thumb_size'] >= $this->getMinimumThumbSize()) {
137 $this->setThumbSize($data['thumb_size']);
138 }
139 $this->is_singleline = $data['allow_images'] === null || $data['allow_images'] === '0';
140 $this->lastChange = $data['tstamp'];
141 $this->setSelectionLimit((int) $data['selection_limit'] > 0 ? (int) $data['selection_limit'] : null);
142 if (isset($data['feedback_setting'])) {
143 $this->feedback_setting = $data['feedback_setting'];
144 }
145
146 try {
147 $this->setLifecycle(new ilAssQuestionLifecycle($data['lifecycle']));
150 }
151
152 try {
153 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
155 }
156 }
157
158 $result = $this->db->queryF(
159 "SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
160 ['integer'],
161 [$question_id]
162 );
163 if ($result->numRows() > 0) {
164 while ($data = $this->db->fetchAssoc($result)) {
165 $imagefilename = $this->getImagePath() . $data["imagefile"];
166 if (!file_exists($imagefilename)) {
167 $data["imagefile"] = null;
168 }
169 $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"] ?? '', 1);
170
172 $data["answertext"],
173 $data["points"],
174 $data["aorder"],
175 $data["answer_id"]
176 );
177 $answer->setPointsUnchecked($data["points_unchecked"]);
178 $answer->setImage($data["imagefile"] ? $data["imagefile"] : null);
179 array_push($this->answers, $answer);
180 }
181 }
182
183 parent::loadFromDb($question_id);
184 }
setSelectionLimit(?int $selection_limit)
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setOriginalId(?int $original_id)
setId(int $id=-1)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setShuffle(?bool $shuffle=true)
setQuestion(string $question="")
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
setAuthor(string $author="")
setThumbSize(int $a_size)
setComment(string $comment="")
setObjId(int $obj_id=0)
setOwner(int $owner=-1)
setNrOfTries(int $a_nr_of_tries)
setLifecycle(ilAssQuestionLifecycle $lifecycle)
setTitle(string $title="")
setPoints(float $points)
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...

References $data, Vendor\Package\$e, assQuestion\$shuffle, ilRTE\_replaceMediaObjectImageSrc(), getAdditionalTableName(), assQuestion\getImagePath(), assQuestion\getMinimumThumbSize(), 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().

+ Here is the call graph for this function:

◆ removeAnswerImage()

assMultipleChoice::removeAnswerImage (   $index)

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

712 : void
713 {
714 $answer = $this->answers[$index];
715 if (is_object($answer)) {
716 $this->deleteImage($answer->getImage());
717 $answer->setImage(null);
718 }
719 }

◆ saveAdditionalQuestionDataToDb()

assMultipleChoice::saveAdditionalQuestionDataToDb ( )

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

422 {
423 if (!$this->is_singleline) {
425 }
426
427 // save additional data
428 $this->db->replace(
429 $this->getAdditionalTableName(),
430 [
431 'shuffle' => ['text', $this->getShuffle()],
432 'allow_images' => ['text', $this->is_singleline ? 0 : 1],
433 'thumb_size' => ['integer', $this->getThumbSize()],
434 'selection_limit' => ['integer', $this->getSelectionLimit()],
435 'feedback_setting' => ['integer', $this->getSpecificFeedbackSetting()]
436 ],
437 ['question_fi' => ['integer', $this->getId()]]
438 );
439 }
getSpecificFeedbackSetting()
Gets the current feedback settings in effect for the question.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

References ilFileUtils\delDir(), and ILIAS\Survey\Mode\getId().

Referenced by saveToDb().

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

◆ saveAnswerSpecificDataToDb()

assMultipleChoice::saveAnswerSpecificDataToDb ( )

Saves the answer specific records into a question types answer table.

Returns
mixed

Implements ilObjAnswerScoringAdjustable.

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

441 : void
442 {
443 // Get all feedback entries
444 $result = $this->db->queryF(
445 "SELECT * FROM qpl_fb_specific WHERE question_fi = %s",
446 ['integer'],
447 [$this->getId()]
448 );
449 $db_feedback = $this->db->fetchAll($result);
450
451 // Check if feedback exists and the regular editor is used and not the page editor
452 if (sizeof($db_feedback) >= 1 && $this->getAdditionalContentEditingMode() == 'default') {
453 // Get all existing answer data for question
454 $result = $this->db->queryF(
455 "SELECT answer_id, aorder FROM qpl_a_mc WHERE question_fi = %s",
456 ['integer'],
457 [$this->getId()]
458 );
459 $db_answers = $this->db->fetchAll($result);
460
461 // Collect old and new order entries by ids and order to calculate a diff/intersection and remove/update feedback
462 $post_answer_order_for_id = [];
463 foreach ($this->answers as $answer) {
464 // Only the first appearance of an id is used
465 if ($answer->getId() !== null && !in_array($answer->getId(), array_keys($post_answer_order_for_id))) {
466 // -1 is happening while import and also if a new multi line answer is generated
467 if ($answer->getId() == -1) {
468 continue;
469 }
470 $post_answer_order_for_id[$answer->getId()] = $answer->getOrder();
471 }
472 }
473
474 // If there is no usable ids from post, it's better to not touch the feedback
475 // This is useful since the import is also using this function or the first creation of a new question in general
476 if (sizeof($post_answer_order_for_id) >= 1) {
477 $db_answer_order_for_id = [];
478 $db_answer_id_for_order = [];
479 foreach ($db_answers as $db_answer) {
480 $db_answer_order_for_id[intval($db_answer['answer_id'])] = intval($db_answer['aorder']);
481 $db_answer_id_for_order[intval($db_answer['aorder'])] = intval($db_answer['answer_id']);
482 }
483
484 // Handle feedback
485 // the diff between the already existing answer ids from the Database and the answer ids from post
486 // feedback related to the answer ids should be deleted or in our case not recreated.
487 $db_answer_ids = array_keys($db_answer_order_for_id);
488 $post_answer_ids = array_keys($post_answer_order_for_id);
489 $diff_db_post_answer_ids = array_diff($db_answer_ids, $post_answer_ids);
490 $unused_answer_ids = array_keys($diff_db_post_answer_ids);
491
492 // Delete all feedback in the database
493 $this->feedbackOBJ->deleteSpecificAnswerFeedbacks($this->getId(), false);
494 // Recreate feedback
495 foreach ($db_feedback as $feedback_option) {
496 // skip feedback which answer is deleted
497 if (in_array(intval($feedback_option['answer']), $unused_answer_ids)) {
498 continue;
499 }
500
501 // Reorder feedback
502 $feedback_order_db = intval($feedback_option['answer']);
503 $db_answer_id = $db_answer_id_for_order[$feedback_order_db] ?? null;
504 // This cuts feedback that currently would have no corresponding answer
505 // This case can happen while copying "broken" questions
506 // Or when saving a question with less answers than feedback
507 if (is_null($db_answer_id) || $db_answer_id < 0) {
508 continue;
509 }
510 $feedback_order_post = $post_answer_order_for_id[$db_answer_id];
511 $feedback_option['answer'] = $feedback_order_post;
512
513 // Recreate remaining feedback in database
514 $next_id = $this->db->nextId('qpl_fb_specific');
515 $this->db->manipulateF(
516 "INSERT INTO qpl_fb_specific (feedback_id, question_fi, answer, tstamp, feedback, question)
517 VALUES (%s, %s, %s, %s, %s, %s)",
518 ['integer', 'integer', 'integer', 'integer', 'text', 'integer'],
519 [
520 $next_id,
521 $feedback_option['question_fi'],
522 $feedback_option['answer'],
523 time(),
524 $feedback_option['feedback'],
525 $feedback_option['question']
526 ]
527 );
528 }
529 }
530 }
531
532 // Delete all entries in qpl_a_mc for question
533 $this->db->manipulateF(
534 "DELETE FROM qpl_a_mc WHERE question_fi = %s",
535 ['integer'],
536 [$this->getId()]
537 );
538
539 // Recreate answers one by one
540 foreach ($this->answers as $key => $value) {
541 $answer_obj = $this->answers[$key];
542 $next_id = $this->db->nextId('qpl_a_mc');
543 $this->db->manipulateF(
544 "INSERT INTO qpl_a_mc (answer_id, question_fi, answertext, points, points_unchecked, aorder, imagefile, tstamp)
545 VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
546 ['integer', 'integer', 'text', 'float', 'float', 'integer', 'text', 'integer'],
547 [
548 $next_id,
549 $this->getId(),
550 ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0),
551 $answer_obj->getPoints(),
552 $answer_obj->getPointsUnchecked(),
553 $answer_obj->getOrder(),
554 $answer_obj->getImage(),
555 time()
556 ]
557 );
558 }
559 }

References ilRTE\_replaceMediaObjectImageSrc(), and ILIAS\Survey\Mode\getId().

Referenced by saveToDb().

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

◆ saveToDb()

assMultipleChoice::saveToDb ( ?int  $original_id = null)

Reimplemented from assQuestion.

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

107 : void
108 {
112 parent::saveToDb($original_id);
113 }
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveQuestionDataToDb(?int $original_id=null)

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

+ Here is the call graph for this function:

◆ saveWorkingData()

assMultipleChoice::saveWorkingData ( int  $active_id,
?int  $pass = null,
bool  $authorized = true 
)

Reimplemented from assQuestion.

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

396 : bool {
397 $pass = $pass ?? ilObjTest::_getPass($active_id);
398
399 $answer = $this->getSolutionSubmit();
400 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
401 function () use ($answer, $active_id, $pass, $authorized) {
402 $this->removeCurrentSolution($active_id, $pass, $authorized);
403
404 foreach ($answer as $value) {
405 if ($value !== '') {
406 $this->saveCurrentSolution($active_id, $pass, $value, null, $authorized);
407 }
408 }
409
410 // fau: testNav - write a dummy entry for the evil mc questions with "None of the above" checked
411 if ($this->isForcedEmptySolution($answer)) {
412 $this->saveCurrentSolution($active_id, $pass, 'mc_none_above', null, $authorized);
413 }
414 // fau.
415 }
416 );
417
418 return true;
419 }
isForcedEmptySolution(array $solutionSubmit)
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.

◆ setAnswers()

assMultipleChoice::setAnswers ( array  $answers)

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

648 : void
649 {
650 $this->answers = $answers;
651 }

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

598 : int
599 {
600 $result = 0;
601 if (!empty($image_tempfilename)) {
602 $image_filename = str_replace(" ", "_", $image_filename);
603 $imagepath = $this->getImagePath();
604 if (!file_exists($imagepath)) {
605 ilFileUtils::makeDirParents($imagepath);
606 }
607 if (!ilFileUtils::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) {
608 $result = 2;
609 } else {
610 $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
611 if (!preg_match("/^image/", $mimetype)) {
612 unlink($imagepath . $image_filename);
613 $result = 1;
614 } else {
615 // create thumbnail file
616 if ($this->is_singleline && ($this->getThumbSize())) {
617 $this->generateThumbForFile(
618 $image_filename,
619 $this->getImagePath(),
620 $this->getThumbSize()
621 );
622 }
623 }
624 }
625 }
626 return $result;
627 }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file

References ilObjMediaObject\getMimeType(), ilFileUtils\makeDirParents(), and ilFileUtils\moveUploadedFile().

+ Here is the call graph for this function:

◆ setIsSingleline()

assMultipleChoice::setIsSingleline ( bool  $is_singleline)

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

56 : void
57 {
58 $this->is_singleline = $is_singleline;
59 }

References $is_singleline.

◆ setMultilineAnswerSetting()

assMultipleChoice::setMultilineAnswerSetting (   $setting = 0)

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

726 : void
727 {
728 $this->current_user->writePref('tst_multiline_answers', (string) $setting);
729 }

◆ setSelectionLimit()

assMultipleChoice::setSelectionLimit ( ?int  $selection_limit)

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

93 : void
94 {
95 $this->selection_limit = $selection_limit;
96 }

References $selection_limit.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setSpecificFeedbackSetting()

assMultipleChoice::setSpecificFeedbackSetting ( int  $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 740 of file class.assMultipleChoice.php.

740 : void
741 {
742 $this->feedback_setting = $feedback_setting;
743 }

◆ solutionValuesToLog()

assMultipleChoice::solutionValuesToLog ( AdditionalInformationGenerator  $additional_info,
array  $solution_values 
)
protected

MUST convert the given solution values into an array or a string that can be stored in the log.

Language variables must be generated through the corresponding functions in the AdditionalInformationGenerator. If an array is returned it will be rendered into a line per array entry in the format "key: value". If the key exists as a language variable, it will be translated.

Reimplemented from assQuestion.

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

915 : array {
916 $solution_ids = array_map(
917 static fn(array $v): string => $v['value1'],
918 $solution_values
919 );
920 $parsed_solutions = [];
921 foreach ($this->getAnswers() as $id => $answer) {
922 $checked = false;
923 if (in_array($id, $solution_ids)) {
924 $checked = true;
925 }
926 $parsed_solutions[$answer->getAnswertext()] = $additional_info
928 }
929 return $parsed_solutions;
930 }

References $id, and ILIAS\Test\Logging\AdditionalInformationGenerator\getCheckedUncheckedTagForBool().

+ Here is the call graph for this function:

◆ solutionValuesToText()

assMultipleChoice::solutionValuesToText ( array  $solution_values)

MUST convert the given solution values into text.

If the text has multiple lines each line MUST be placed as an entry in an array.

Reimplemented from assQuestion.

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

932 : array
933 {
934 $solution_ids = array_map(
935 fn(array $v): int => $this->refinery->kindlyTo()->int()->transform($v['value1']),
936 $solution_values
937 );
938
939 return array_map(
940 function (ASS_AnswerMultipleResponseImage $v, int $k) use ($solution_ids): string {
941 $checked = 'unchecked';
942 if (in_array($k, $solution_ids)) {
943 $checked = 'checked';
944 }
945 return "{$v->getAnswertext()} ({$this->lng->txt($checked)})";
946 },
947 $this->getAnswers(),
948 array_keys($this->getAnswers())
949 );
950 }

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ toJSON()

assMultipleChoice::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

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

667 : string
668 {
669 $result = [];
670 $result['id'] = $this->getId();
671 $result['type'] = (string) $this->getQuestionType();
672 $result['title'] = $this->getTitleForHTMLOutput();
673 $result['question'] = $this->formatSAQuestion($this->getQuestion());
674 $result['nr_of_tries'] = $this->getNrOfTries();
675 $result['shuffle'] = $this->getShuffle();
676 $result['selection_limit'] = (int) $this->getSelectionLimit();
677 $result['feedback'] = [
678 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
679 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
680 ];
681
682 $answers = [];
683 $has_image = false;
684 foreach ($this->getAnswers() as $key => $answer_obj) {
685 if ((string) $answer_obj->getImage()) {
686 $has_image = true;
687 }
688 array_push($answers, [
689 "answertext" => $this->formatSAQuestion($answer_obj->getAnswertext()),
690 "points_checked" => (float) $answer_obj->getPointsChecked(),
691 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
692 "order" => (int) $answer_obj->getOrder(),
693 "image" => (string) $answer_obj->getImage(),
694 "feedback" => $this->formatSAQuestion(
695 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
696 )
697 ]);
698 }
699 $result['answers'] = $answers;
700
701 if ($has_image) {
702 $result['path'] = $this->getImagePathWeb();
703 $result['thumb'] = $this->getThumbSize();
704 }
705
706 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
707 $result['mobs'] = $mobs;
708
709 return json_encode($result);
710 }
getQuestionType()
Returns the question type of the question.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
static _getMobsOfObject(string $a_type, int $a_id, int|false $a_usage_hist_nr=0, string $a_lang="-")

References ilObjMediaObject\_getMobsOfObject(), ILIAS\Survey\Mode\getId(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ toLog()

assMultipleChoice::toLog ( AdditionalInformationGenerator  $additional_info)

MUST return an array of the question settings that can be stored in the log.

Language variables must be generated through the corresponding functions in the AdditionalInformationGenerator. If an array is returned it will be rendered into a line per array entry in the format "key: value". If the key exists as a language variable, it will be translated.

Reimplemented from assQuestion.

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

881 : array
882 {
883 $result = [
884 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->getQuestionType(),
885 AdditionalInformationGenerator::KEY_QUESTION_TITLE => $this->getTitleForHTMLOutput(),
886 AdditionalInformationGenerator::KEY_QUESTION_TEXT => $this->formatSAQuestion($this->getQuestion()),
887 AdditionalInformationGenerator::KEY_QUESTION_SHUFFLE_ANSWER_OPTIONS => $additional_info
889 'ass_mc_sel_lim_setting' => (int) $this->getSelectionLimit(),
890 AdditionalInformationGenerator::KEY_FEEDBACK => [
891 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
892 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
893 ]
894 ];
895
896 foreach ($this->getAnswers() as $key => $answer_obj) {
897 $result[AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTIONS][$key + 1] = [
898 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION => $this->formatSAQuestion($answer_obj->getAnswertext()),
899 AdditionalInformationGenerator::KEY_QUESTION_POINTS_CHECKED => (float) $answer_obj->getPointsChecked(),
900 AdditionalInformationGenerator::KEY_QUESTION_POINTS_UNCHECKED => (float) $answer_obj->getPointsUnchecked(),
901 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_ORDER => (int) $answer_obj->getOrder(),
902 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_IMAGE => (string) $answer_obj->getImage(),
903 AdditionalInformationGenerator::KEY_FEEDBACK => $this->formatSAQuestion(
904 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
905 )
906 ];
907 }
908
909 return $result;
910 }

References ILIAS\Test\Logging\AdditionalInformationGenerator\getTrueFalseTagForBool(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ toNormalized()

assMultipleChoice::toNormalized ( Transformations  $transformations,
array  $context = [] 
)
Parameters
array<string,mixed>$context
Returns
array<array-key, mixed>|float|bool|int|string|null

Reimplemented from assQuestion.

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

967 : array|float|bool|int|string|null
968 {
969 return [
970 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
971 'selection_limit' => $this->selection_limit,
972 'single_line' => $this->is_singleline,
973 'answers' => $transformations->normalize($this->answers, ['question_id' => $this->getId()]),
974 ];
975 }

References ILIAS\Survey\Mode\getId(), and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\normalize().

+ Here is the call graph for this function:

◆ validateSolutionSubmit()

assMultipleChoice::validateSolutionSubmit ( )

Reimplemented from assQuestion.

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

366 : bool
367 {
368 $submit = $this->getSolutionSubmit();
369
370 if ($this->getSelectionLimit()) {
371 if (count($submit) > $this->getSelectionLimit()) {
372 $failureMsg = sprintf(
373 $this->lng->txt('ass_mc_sel_lim_exhausted_hint'),
374 $this->getSelectionLimit(),
375 $this->getAnswerCount()
376 );
377
378 $this->tpl->setOnScreenMessage('failure', $failureMsg, true);
379 return false;
380 }
381 }
382
383 return true;
384 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

Field Documentation

◆ $answers

array assMultipleChoice::$answers = []

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

◆ $feedback_setting

int assMultipleChoice::$feedback_setting = 0

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

◆ $is_singleline

bool assMultipleChoice::$is_singleline = true

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

Referenced by setIsSingleline().

◆ $selection_limit

int assMultipleChoice::$selection_limit = null
protected

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

Referenced by getSelectionLimit(), and setSelectionLimit().

◆ OUTPUT_ORDER

const assMultipleChoice::OUTPUT_ORDER = 0

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

◆ OUTPUT_RANDOM

const assMultipleChoice::OUTPUT_RANDOM = 1

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


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