ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 ()
 Saves a record to the question types additional data table. More...
 
 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)
 
 solutionValuesToText (array $solution_values)
 
 getCorrectSolutionForTextOutput (int $active_id, int $pass)
 
- 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, array $solutionhints=[])
 
 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...
 
 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 ()
 
static 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)
 
 duplicate (bool $for_test=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 ()
 
 deductHintPointsFromReachedPoints (ilAssQuestionPreviewSession $preview_session, $reached_points)
 
 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 ()
 
 cloneHints (int $source_question_id, int $target_question_id)
 
 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)
 
 ensureHintPageObjectExists ($pageObjectId)
 
 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)
 
- Public Member Functions inherited from iQuestionCondition
 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...
 

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)
 
- 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)
 
 duplicateQuestionHints (int $original_question_id, int $duplicate_question_id)
 
 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
 
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 _setReachedPoints (int $active_id, int $question_id, float $points, float $maxpoints, int $pass, bool $manualscoring)
 Sets the points, a learner has reached answering the question Additionally objective results are updated. 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 42 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 73 of file class.assMultipleChoice.php.

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

80  {
82  $this->answers = [];
83  $this->shuffle = true;
84  }
__construct(Container $dic, ilPlugin $plugin)
+ 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 211 of file class.assMultipleChoice.php.

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

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

◆ buildTestPresentationConfig()

assMultipleChoice::buildTestPresentationConfig ( )
protected

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

References ILIAS\Repository\lng().

868  {
869  $config = parent::buildTestPresentationConfig();
870  $config->setUseUnchangedAnswerLabel($this->lng->txt('tst_mc_label_none_above'));
871  return $config;
872  }
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 ( int  $active_id,
?int  $pass = null,
bool  $authorized_solution = true 
)

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

References $data, calculateReachedPointsForSolution(), assQuestion\getCurrentSolutionResultSet(), assQuestion\getSolutionMaxPass(), and null.

Referenced by getUserQuestionResult().

349  : float {
350  $found_values = [];
351  if ($pass === null) {
352  $pass = $this->getSolutionMaxPass($active_id);
353  }
354  $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized_solution);
355  while ($data = $this->db->fetchAssoc($result)) {
356  if ($data['value1'] !== '') {
357  array_push($found_values, $data['value1']);
358  }
359  }
360 
361  return $this->calculateReachedPointsForSolution($found_values, $active_id);
362  }
calculateReachedPointsForSolution(?array $found_values, int $active_id=0)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 ( ?array  $found_values,
int  $active_id = 0 
)
protected

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

References assQuestion\$points.

Referenced by calculateReachedPoints().

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

◆ cloneQuestionTypeSpecificProperties()

assMultipleChoice::cloneQuestionTypeSpecificProperties ( \assQuestion  $target)
protected

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

References getAnswers(), assQuestion\getId(), and assQuestion\getObjId().

186  : \assQuestion {
187  $this->cloneImages(
188  $this->getId(),
189  $this->getObjId(),
190  $target->getId(),
191  $target->getObjId(),
192  $this->getAnswers()
193  );
194  return $target;
195  }
& getAnswers()
Returns a reference to the answers array.
+ 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 297 of file class.assMultipleChoice.php.

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

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

◆ flushAnswers()

assMultipleChoice::flushAnswers ( )

Deletes all answers.

See also
$answers

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

326  : void
327  {
328  $this->answers = [];
329  }

◆ getAdditionalTableName()

assMultipleChoice::getAdditionalTableName ( )

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

Returns
string The additional table name

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

Referenced by loadFromDb(), and saveAdditionalQuestionDataToDb().

574  : string
575  {
576  return "qpl_qst_mc";
577  }
+ 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 275 of file class.assMultipleChoice.php.

References null.

Referenced by getAvailableAnswerOptions().

275  : ?object
276  {
277  if ($index < 0) {
278  return null;
279  }
280  if (count($this->answers) < 1) {
281  return null;
282  }
283  if ($index >= count($this->answers)) {
284  return null;
285  }
286 
287  return $this->answers[$index];
288  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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 262 of file class.assMultipleChoice.php.

Referenced by isComplete(), and validateSolutionSubmit().

262  : int
263  {
264  return count($this->answers);
265  }
+ Here is the caller graph for this function:

◆ getAnswers()

& assMultipleChoice::getAnswers ( )

Returns a reference to the answers array.

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

References $answers.

Referenced by cloneQuestionTypeSpecificProperties(), getAvailableAnswerOptions(), getCorrectSolutionForTextOutput(), getMaximumPoints(), getSolutionSubmit(), lmMigrateQuestionTypeSpecificContent(), solutionValuesToLog(), solutionValuesToText(), toJSON(), and toLog().

641  : array
642  {
643  return $this->answers;
644  }
+ 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 584 of file class.assMultipleChoice.php.

584  : string
585  {
586  return "qpl_a_mc";
587  }

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

References getAnswer(), getAnswers(), and null.

859  {
860  if ($index !== null) {
861  return $this->getAnswer($index);
862  } else {
863  return $this->getAnswers();
864  }
865  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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:

◆ getCorrectSolutionForTextOutput()

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

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

References getAnswers(), and ASS_AnswerSimple\getAnswertext().

949  : array
950  {
951  return array_map(
952  fn(ASS_AnswerMultipleResponseImage $v): string => $v->getAnswertext()
953  . "({$this->lng->txt('points')} "
954  . "{$this->lng->txt('checked')}: {$v->getPointsChecked()}, "
955  . "{$this->lng->txt('unchecked')}: {$v->getPointsUnchecked()})",
956  $this->getAnswers()
957  );
958  }
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
& getAnswers()
Returns a reference to the answers array.
getAnswertext()
Gets the answer text.
+ 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

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

References getAnswers().

Referenced by getUserQuestionResult(), and isComplete().

336  : float
337  {
338  $total_max_points = 0.0;
339  foreach ($this->getAnswers() as $answer) {
340  $total_max_points += max($answer->getPointsChecked(), $answer->getPointsUnchecked());
341  }
342  return $total_max_points;
343  }
& 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 719 of file class.assMultipleChoice.php.

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

◆ getOperators()

assMultipleChoice::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

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

804  : array
805  {
806  return ilOperatorsExpressionMapping::getOperatorsByExpression($expression);
807  }

◆ getQuestionType()

assMultipleChoice::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question

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

Referenced by toJSON(), and toLog().

564  : string
565  {
566  return "assMultipleChoice";
567  }
+ Here is the caller graph for this function:

◆ getRTETextWithMediaObjects()

assMultipleChoice::getRTETextWithMediaObjects ( )

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

References assQuestion\getId().

627  : string
628  {
629  $text = parent::getRTETextWithMediaObjects();
630  foreach ($this->answers as $index => $answer) {
631  $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), 0, $index);
632  $answer_obj = $this->answers[$index];
633  $text .= $answer_obj->getAnswertext();
634  }
635  return $text;
636  }
+ Here is the call graph for this function:

◆ getSelectionLimit()

assMultipleChoice::getSelectionLimit ( )

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

References $selection_limit.

Referenced by saveAdditionalQuestionDataToDb(), toJSON(), toLog(), and validateSolutionSubmit().

86  : ?int
87  {
89  }
+ Here is the caller graph for this function:

◆ getSolutionSubmit()

assMultipleChoice::getSolutionSubmit ( )
protected

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

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

Referenced by saveWorkingData(), and validateSolutionSubmit().

766  : array
767  {
768  $solutionSubmit = [];
769  $post = $this->dic->http()->wrapper()->post();
770 
771  foreach ($this->getAnswers() as $index => $a) {
772  if ($post->has("multiple_choice_result_$index")) {
773  $value = $post->retrieve("multiple_choice_result_$index", $this->dic->refinery()->kindlyTo()->string());
774  if (is_numeric($value)) {
775  $solutionSubmit[] = $value;
776  }
777  }
778  }
779  return $solutionSubmit;
780  }
& 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:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSpecificFeedbackAllCorrectOptionLabel()

assMultipleChoice::getSpecificFeedbackAllCorrectOptionLabel ( )

Implements ilAssSpecificFeedbackOptionLabelProvider.

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

761  : string
762  {
763  return 'feedback_correct_sc_mc';
764  }

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

References $feedback_setting.

Referenced by saveAdditionalQuestionDataToDb().

752  : int
753  {
754  if ($this->feedback_setting) {
756  } else {
757  return 1;
758  }
759  }
+ Here is the caller graph for this function:

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

References $data, assQuestion\$points, calculateReachedPoints(), assQuestion\getId(), getMaximumPoints(), and assQuestion\lookupMaxStep().

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

◆ isComplete()

assMultipleChoice::isComplete ( )

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

References getAnswerCount(), and getMaximumPoints().

96  : bool
97  {
98  return $this->title !== ''
99  && $this->author !== ''
100  && $this->question !== ''
101  && $this->getAnswerCount() > 0
102  && $this->getMaximumPoints() >= 0;
103  }
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()

assMultipleChoice::isForcedEmptySolution ( array  $solutionSubmit)
protected

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

Referenced by saveWorkingData().

384  : bool
385  {
386  $tst_force_form_diff_input = $this->questionpool_request->strArray('tst_force_form_diff_input');
387  return !count($solutionSubmit) && !empty($tst_force_form_diff_input);
388  }
+ Here is the caller graph for this function:

◆ isSingleline()

assMultipleChoice::isSingleline ( )

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

References $is_singleline.

874  : bool
875  {
876  return $this->is_singleline;
877  }

◆ lmMigrateQuestionTypeSpecificContent()

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

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

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

654  : void
655  {
656  foreach ($this->getAnswers() as $answer) {
657  /* @var ASS_AnswerBinaryStateImage $answer */
658  $answer->setAnswertext($migrator->migrateToLmContent($answer->getAnswertext()));
659  }
660  }
& getAnswers()
Returns a reference to the answers array.
+ Here is the call graph for this function:

◆ loadFromDb()

assMultipleChoice::loadFromDb ( int  $question_id)

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

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

113  : void
114  {
115  $result = $this->db->queryF(
116  "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",
117  ["integer"],
118  [$question_id]
119  );
120  if ($result->numRows() == 1) {
121  $data = $this->db->fetchAssoc($result);
122  $this->setId($question_id);
123  $this->setObjId($data["obj_fi"]);
124  $this->setTitle($data["title"] ?? '');
125  $this->setNrOfTries($data['nr_of_tries']);
126  $this->setComment($data["description"] ?? '');
127  $this->setOriginalId($data["original_id"]);
128  $this->setAuthor($data["author"]);
129  $this->setPoints($data["points"]);
130  $this->setOwner($data["owner"]);
131  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"] ?? '', 1));
132  $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
133  $this->setShuffle((bool) $shuffle);
134  if ($data['thumb_size'] !== null && $data['thumb_size'] >= $this->getMinimumThumbSize()) {
135  $this->setThumbSize($data['thumb_size']);
136  }
137  $this->is_singleline = $data['allow_images'] === null || $data['allow_images'] === '0';
138  $this->lastChange = $data['tstamp'];
139  $this->setSelectionLimit((int) $data['selection_limit'] > 0 ? (int) $data['selection_limit'] : null);
140  if (isset($data['feedback_setting'])) {
141  $this->feedback_setting = $data['feedback_setting'];
142  }
143 
144  try {
148  }
149 
150  try {
151  $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
152  } catch (ilTestQuestionPoolException $e) {
153  }
154  }
155 
156  $result = $this->db->queryF(
157  "SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
158  ['integer'],
159  [$question_id]
160  );
161  if ($result->numRows() > 0) {
162  while ($data = $this->db->fetchAssoc($result)) {
163  $imagefilename = $this->getImagePath() . $data["imagefile"];
164  if (!file_exists($imagefilename)) {
165  $data["imagefile"] = null;
166  }
167  $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"] ?? '', 1);
168 
169  $answer = new ASS_AnswerMultipleResponseImage(
170  $data["answertext"],
171  $data["points"],
172  $data["aorder"],
173  $data["answer_id"]
174  );
175  $answer->setPointsUnchecked($data["points_unchecked"]);
176  $answer->setImage($data["imagefile"] ? $data["imagefile"] : null);
177  array_push($this->answers, $answer);
178  }
179  }
180 
181  parent::loadFromDb($question_id);
182  }
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)
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
setThumbSize(int $a_size)
setComment(string $comment="")
setSelectionLimit(?int $selection_limit)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 710 of file class.assMultipleChoice.php.

References null.

710  : void
711  {
712  $answer = $this->answers[$index];
713  if (is_object($answer)) {
714  $this->deleteImage($answer->getImage());
715  $answer->setImage(null);
716  }
717  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ saveAdditionalQuestionDataToDb()

assMultipleChoice::saveAdditionalQuestionDataToDb ( )

Saves a record to the question types additional data table.

Returns
mixed

Implements ilObjQuestionScoringAdjustable.

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

References ilFileUtils\delDir(), getAdditionalTableName(), assQuestion\getId(), assQuestion\getImagePath(), getSelectionLimit(), assQuestion\getShuffle(), getSpecificFeedbackSetting(), and assQuestion\getThumbSize().

Referenced by saveToDb().

420  {
421  if (!$this->is_singleline) {
423  }
424 
425  // save additional data
426  $this->db->replace(
427  $this->getAdditionalTableName(),
428  [
429  'shuffle' => ['text', $this->getShuffle()],
430  'allow_images' => ['text', $this->is_singleline ? 0 : 1],
431  'thumb_size' => ['integer', $this->getThumbSize()],
432  'selection_limit' => ['integer', $this->getSelectionLimit()],
433  'feedback_setting' => ['integer', $this->getSpecificFeedbackSetting()]
434  ],
435  ['question_fi' => ['integer', $this->getId()]]
436  );
437  }
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
getSpecificFeedbackSetting()
Gets the current feedback settings in effect for the question.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
+ 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 439 of file class.assMultipleChoice.php.

References ilRTE\_replaceMediaObjectImageSrc(), assQuestion\getAdditionalContentEditingMode(), assQuestion\getId(), and null.

Referenced by saveToDb().

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

◆ saveToDb()

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

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

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

105  : void
106  {
110  parent::saveToDb($original_id);
111  }
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
saveQuestionDataToDb(?int $original_id=null)
+ Here is the call graph for this function:

◆ saveWorkingData()

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

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

References ilObjTest\_getPass(), assQuestion\getProcessLocker(), getSolutionSubmit(), isForcedEmptySolution(), null, assQuestion\removeCurrentSolution(), and assQuestion\saveCurrentSolution().

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

◆ setAnswers()

assMultipleChoice::setAnswers ( array  $answers)

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

References $answers.

646  : void
647  {
648  $this->answers = $answers;
649  }

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

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

596  : int
597  {
598  $result = 0;
599  if (!empty($image_tempfilename)) {
600  $image_filename = str_replace(" ", "_", $image_filename);
601  $imagepath = $this->getImagePath();
602  if (!file_exists($imagepath)) {
603  ilFileUtils::makeDirParents($imagepath);
604  }
605  if (!ilFileUtils::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) {
606  $result = 2;
607  } else {
608  $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
609  if (!preg_match("/^image/", $mimetype)) {
610  unlink($imagepath . $image_filename);
611  $result = 1;
612  } else {
613  // create thumbnail file
614  if ($this->is_singleline && ($this->getThumbSize())) {
615  $this->generateThumbForFile(
616  $image_filename,
617  $this->getImagePath(),
618  $this->getThumbSize()
619  );
620  }
621  }
622  }
623  }
624  return $result;
625  }
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 ( bool  $is_singleline)

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

References $is_singleline.

54  : void
55  {
56  $this->is_singleline = $is_singleline;
57  }

◆ setMultilineAnswerSetting()

assMultipleChoice::setMultilineAnswerSetting (   $setting = 0)

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

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

◆ setSelectionLimit()

assMultipleChoice::setSelectionLimit ( ?int  $selection_limit)

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

References $selection_limit.

Referenced by loadFromDb().

91  : void
92  {
93  $this->selection_limit = $selection_limit;
94  }
+ 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 738 of file class.assMultipleChoice.php.

References $feedback_setting.

738  : void
739  {
740  $this->feedback_setting = $feedback_setting;
741  }

◆ solutionValuesToLog()

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

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

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

913  : array {
914  $solution_ids = array_map(
915  static fn(array $v): string => $v['value1'],
916  $solution_values
917  );
918  $parsed_solutions = [];
919  foreach ($this->getAnswers() as $id => $answer) {
920  $checked = false;
921  if (in_array($id, $solution_ids)) {
922  $checked = true;
923  }
924  $parsed_solutions[$answer->getAnswertext()] = $additional_info
925  ->getCheckedUncheckedTagForBool($checked);
926  }
927  return $parsed_solutions;
928  }
& getAnswers()
Returns a reference to the answers array.
+ Here is the call graph for this function:

◆ solutionValuesToText()

assMultipleChoice::solutionValuesToText ( array  $solution_values)

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

References getAnswers(), and ASS_AnswerSimple\getId().

930  : array
931  {
932  $solution_ids = array_map(
933  static fn(array $v): string => $v['value1'],
934  $solution_values
935  );
936 
937  return array_map(
938  function (ASS_AnswerMultipleResponseImage $v) use ($solution_ids): string {
939  $checked = 'unchecked';
940  if (in_array($v->getId(), $solution_ids)) {
941  $checked = 'checked';
942  }
943  return "{$v->getAnswertext()} ({$this->lng->txt($checked)})";
944  },
945  $this->getAnswers()
946  );
947  }
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
getId()
Gets the answer id.
& getAnswers()
Returns a reference to the answers array.
+ Here is the call graph for this function:

◆ toJSON()

assMultipleChoice::toJSON ( )

Returns a JSON representation of the question.

Implements ILIAS\TestQuestionPool\Questions\QuestionLMExportable.

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

References $answers, 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().

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

◆ toLog()

assMultipleChoice::toLog ( AdditionalInformationGenerator  $additional_info)

Implements ILIAS\TestQuestionPool\Questions\Question.

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

References assQuestion\formatSAQuestion(), getAnswers(), assQuestion\getQuestion(), getQuestionType(), getSelectionLimit(), assQuestion\getShuffle(), assQuestion\getTitleForHTMLOutput(), ILIAS\Test\Logging\AdditionalInformationGenerator\getTrueFalseTagForBool(), and ILIAS\Repository\int().

879  : array
880  {
881  $result = [
882  AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->getQuestionType(),
883  AdditionalInformationGenerator::KEY_QUESTION_TITLE => $this->getTitleForHTMLOutput(),
884  AdditionalInformationGenerator::KEY_QUESTION_TEXT => $this->formatSAQuestion($this->getQuestion()),
885  AdditionalInformationGenerator::KEY_QUESTION_SHUFFLE_ANSWER_OPTIONS => $additional_info
887  'ass_mc_sel_lim_setting' => (int) $this->getSelectionLimit(),
888  AdditionalInformationGenerator::KEY_FEEDBACK => [
889  AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
890  AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
891  ]
892  ];
893 
894  foreach ($this->getAnswers() as $key => $answer_obj) {
895  $result[AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTIONS][$key + 1] = [
896  AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION => $this->formatSAQuestion($answer_obj->getAnswertext()),
897  AdditionalInformationGenerator::KEY_QUESTION_POINTS_CHECKED => (float) $answer_obj->getPointsChecked(),
898  AdditionalInformationGenerator::KEY_QUESTION_POINTS_UNCHECKED => (float) $answer_obj->getPointsUnchecked(),
899  AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_ORDER => (int) $answer_obj->getOrder(),
900  AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_IMAGE => (string) $answer_obj->getImage(),
901  AdditionalInformationGenerator::KEY_FEEDBACK => $this->formatSAQuestion(
902  $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
903  )
904  ];
905  }
906 
907  return $result;
908  }
getQuestionType()
Returns the question type of the question.
& getAnswers()
Returns a reference to the answers array.
+ Here is the call graph for this function:

◆ validateSolutionSubmit()

assMultipleChoice::validateSolutionSubmit ( )

Implements ILIAS\TestQuestionPool\Questions\Question.

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

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

364  : bool
365  {
366  $submit = $this->getSolutionSubmit();
367 
368  if ($this->getSelectionLimit()) {
369  if (count($submit) > $this->getSelectionLimit()) {
370  $failureMsg = sprintf(
371  $this->lng->txt('ass_mc_sel_lim_exhausted_hint'),
372  $this->getSelectionLimit(),
373  $this->getAnswerCount()
374  );
375 
376  $this->tpl->setOnScreenMessage('failure', $failureMsg, true);
377  return false;
378  }
379  }
380 
381  return true;
382  }
getAnswerCount()
Returns the number of answers.
+ Here is the call graph for this function:

Field Documentation

◆ $answers

array assMultipleChoice::$answers = []

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

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

◆ $feedback_setting

int assMultipleChoice::$feedback_setting = 0

◆ $is_singleline

bool assMultipleChoice::$is_singleline = true

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

Referenced by isSingleline(), and setIsSingleline().

◆ $selection_limit

int assMultipleChoice::$selection_limit = null
protected

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

Referenced by getSelectionLimit(), and setSelectionLimit().

◆ OUTPUT_ORDER

const assMultipleChoice::OUTPUT_ORDER = 0

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

◆ OUTPUT_RANDOM

const assMultipleChoice::OUTPUT_RANDOM = 1

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


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