ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
assSingleChoice Class Reference

Class for single choice questions. More...

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

Public Member Functions

 __construct (string $title="", string $comment="", string $author="", int $owner=-1, string $question="", int $output_type=self::OUTPUT_ORDER)
 
 isComplete ()
 
 saveToDb (?int $original_id=null)
 
 loadFromDb (int $question_id)
 
 addAnswer (string $answertext='', float $points=0.0, int $order=0, ?string $answerimage=null, int $answer_id=-1)
 
 getAnswerCount ()
 Returns the number of answers. More...
 
 getAnswer (int $index=0)
 Returns an answer with a given index. More...
 
 deleteAnswer (int $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)
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $preview_session)
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 saveAdditionalQuestionDataToDb ()
 Saves a record to the question types additional data 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 (string $image_filename, string $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 (int $index)
 
 getMultilineAnswerSetting ()
 
 setMultilineAnswerSetting ($setting='0')
 
 setSpecificFeedbackSetting (int $feedback_setting)
 Sets the feedback settings in effect for the question. More...
 
 getSpecificFeedbackSetting ()
 
 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 ()
 
 setIsSingleline (bool $is_singleline)
 
 getFeedbackSetting ()
 
 setFeedbackSetting (int $feedback_setting)
 
 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)
 
- 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)
 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 ()
 
 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 ()
 
 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)
 
 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)
 
 saveAdditionalQuestionDataToDb ()
 Saves a record to the question types additional data table. More...
 
- Public Member Functions inherited from ilObjAnswerScoringAdjustable
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
- Public Member Functions inherited from iQuestionCondition
 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 ()
 

Data Fields

array $answers = []
 
int $output_type
 
- 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)
 
 savePreviewData (ilAssQuestionPreviewSession $previewSession)
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 afterSyncWithOriginal (int $original_question_id, int $clone_question_id, int $original_parent_id, int $clone_parent_id)
 {} More...
 
 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

const OUTPUT_ORDER = 0
 
const OUTPUT_RANDOM = 1
 
const FEEDBACK_MODE_ALL_ANSWERS = 1
 
const FEEDBACK_MODE_SELECTED_ANSWERS = 2
 
const FEEDBACK_MODE_CORRECT_ANSWERS = 3
 
int $feedback_setting = self::FEEDBACK_MODE_SELECTED_ANSWERS
 
- 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
 

Private Attributes

bool $is_singleline = true
 

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 single choice questions.

assSingleChoice is a class for single choice questions.

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

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

Constructor & Destructor Documentation

◆ __construct()

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

Member Function Documentation

◆ addAnswer()

assSingleChoice::addAnswer ( string  $answertext = '',
float  $points = 0.0,
int  $order = 0,
?string  $answerimage = null,
int  $answer_id = -1 
)

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

186 : void {
187 if (array_key_exists($order, $this->answers)) {
188 // insert answer
189 $answer = new ASS_AnswerBinaryStateImage(
190 $this->getHtmlQuestionContentPurifier()->purify($answertext),
191 $points,
192 $order,
193 true,
194 $answerimage,
195 $answer_id
196 );
197 $newchoices = [];
198 for ($i = 0; $i < $order; $i++) {
199 $newchoices[] = $this->answers[$i];
200 }
201 $newchoices[] = $answer;
202 for ($i = $order, $iMax = count($this->answers); $i < $iMax; $i++) {
203 $changed = $this->answers[$i];
204 $changed->setOrder($i + 1);
205 $newchoices[] = $changed;
206 }
207 $this->answers = $newchoices;
208 return;
209 }
210
211 $answer = new ASS_AnswerBinaryStateImage(
212 $this->getHtmlQuestionContentPurifier()->purify($answertext),
213 $points,
214 count($this->answers),
215 true,
216 $answerimage,
217 $answer_id
218 );
219 $this->answers[] = $answer;
220 }
Class for answers with a binary state indicator.

◆ afterSyncWithOriginal()

assSingleChoice::afterSyncWithOriginal ( int  $original_question_id,
int  $clone_question_id,
int  $original_parent_id,
int  $clone_parent_id 
)
protected

{}

Reimplemented from assQuestion.

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

847 : void {
848 parent::afterSyncWithOriginal($original_question_id, $clone_question_id, $original_parent_id, $clone_parent_id);
849
850 $original_image_path = $this->question_files->buildImagePath($original_question_id, $original_parent_id);
851 $clone_image_path = $this->question_files->buildImagePath($clone_question_id, $clone_parent_id);
852
853 ilFileUtils::delDir($original_image_path);
854 if (is_dir($clone_image_path)) {
855 ilFileUtils::makeDirParents($original_image_path);
856 ilFileUtils::rCopy($clone_image_path, $original_image_path);
857 }
858 }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.

◆ calculateReachedPoints()

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

Reimplemented from assQuestion.

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

322 : float {
323 $found_values = [];
324 if (is_null($pass)) {
325 $pass = $this->getSolutionMaxPass($active_id);
326 }
327 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized_solution);
328 while ($data = $this->db->fetchAssoc($result)) {
329 if ($data['value1'] !== '') {
330 array_push($found_values, $data['value1']);
331 }
332 }
333 $points = 0.0;
334 foreach ($this->answers as $key => $answer) {
335 if ($found_values !== []
336 && in_array($key, $found_values)) {
337 $points += $answer->getPoints();
338 }
339 }
340
341 return $points;
342 }
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getSolutionMaxPass(int $active_id)

◆ calculateReachedPointsFromPreviewSession()

assSingleChoice::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $preview_session)

Reimplemented from assQuestion.

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

346 : float {
347 $participant_solution = $preview_session->getParticipantsSolution();
348
349 $points = 0.0;
350 foreach ($this->answers as $key => $answer) {
351 if (is_numeric($participant_solution)
352 && $key === (int) $participant_solution) {
353 $points = $answer->getPoints();
354 }
355 }
356
357 return $this->ensureNonNegativePoints($points);
358 }
ensureNonNegativePoints(float $points)

◆ cloneQuestionTypeSpecificProperties()

assSingleChoice::cloneQuestionTypeSpecificProperties ( \assQuestion  $target)
protected

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

169 : \assQuestion {
170 $this->cloneImages(
171 $this->getId(),
172 $this->getObjId(),
173 $target->getId(),
174 $target->getObjId(),
175 $this->getAnswers()
176 );
177 return $target;
178 }

◆ deleteAnswer()

assSingleChoice::deleteAnswer ( int  $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 @access public
See also
$answers

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

266 : void
267 {
268 if ($index < 0) {
269 return;
270 }
271 if (count($this->answers) < 1) {
272 return;
273 }
274 if ($index >= count($this->answers)) {
275 return;
276 }
277 $answer = $this->answers[$index];
278 if ($answer->hasImage()) {
279 $this->deleteImage($answer->getImage());
280 }
281 unset($this->answers[$index]);
282 $this->answers = array_values($this->answers);
283 for ($i = 0, $iMax = count($this->answers); $i < $iMax; $i++) {
284 if ($this->answers[$i]->getOrder() > $index) {
285 $this->answers[$i]->setOrder($i);
286 }
287 }
288 }

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

+ Here is the call graph for this function:

◆ flushAnswers()

assSingleChoice::flushAnswers ( )

Deletes all answers.

@access public

See also
$answers

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

296 : void
297 {
298 $this->answers = [];
299 }

◆ getAdditionalTableName()

assSingleChoice::getAdditionalTableName ( )

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

Returns
string The additional table name @access public

Reimplemented from assQuestion.

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

582 : string
583 {
584 return "qpl_qst_sc";
585 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ getAnswer()

assSingleChoice::getAnswer ( int  $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 @access public
See also
$answers

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

244 {
245 if ($index < 0) {
246 return null;
247 }
248 if (count($this->answers) < 1) {
249 return null;
250 }
251 if ($index >= count($this->answers)) {
252 return null;
253 }
254
255 return $this->answers[$index];
256 }

◆ getAnswerCount()

assSingleChoice::getAnswerCount ( )

Returns the number of answers.

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

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

229 : int
230 {
231 return count($this->answers);
232 }

◆ getAnswers()

assSingleChoice::getAnswers ( )

Returns a reference to the answers array.

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

659 : array
660 {
661 return $this->answers;
662 }

◆ getAnswerTableName()

assSingleChoice::getAnswerTableName ( )

Returns the name of the answer table in the database.

Returns
string The answer table name @access public

Reimplemented from assQuestion.

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

593 : string
594 {
595 return "qpl_a_sc";
596 }

◆ getAvailableAnswerOptions()

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

831 {
832 if ($index !== null) {
833 return $this->getAnswer($index);
834 } else {
835 return $this->getAnswers();
836 }
837 }
getAnswer(int $index=0)
Returns an answer with a given index.
getAnswers()
Returns a reference to the answers array.

◆ getCorrectSolutionForTextOutput()

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

Reimplemented from assQuestion.

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

933 : array
934 {
935 return array_reduce(
936 $this->getAnswers(),
937 function (array $c, ASS_AnswerBinaryStateImage $v): array {
938 if ($v->getPoints() > 0.0) {
939 $c[] = $v->getAnswertext()
940 . "({$this->lng->txt('points')}: {$v->getPoints()})";
941 }
942 return $c;
943 },
944 []
945 );
946 }
getPoints()
Gets the points.
$c
Definition: deliver.php:25

References $c, and ASS_AnswerSimple\getPoints().

+ Here is the call graph for this function:

◆ getExpressionTypes()

assSingleChoice::getExpressionTypes ( )

◆ getFeedbackSetting()

assSingleChoice::getFeedbackSetting ( )

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

870 : int
871 {
873 }

◆ getMaximumPoints()

assSingleChoice::getMaximumPoints ( )

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

@access public

See also
$points

Reimplemented from assQuestion.

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

307 : float
308 {
309 $points = 0;
310 foreach ($this->answers as $key => $value) {
311 if ($value->getPoints() > $points) {
312 $points = $value->getPoints();
313 }
314 }
315 return $points;
316 }

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assSingleChoice::getMultilineAnswerSetting ( )

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

742 : int
743 {
744 return $this->current_user->getPref('tst_multiline_answers') === '1' ? 1 : 0;
745 }

◆ getOperators()

assSingleChoice::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

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

774 : array
775 {
777 }
static getOperatorsByExpression(string $expression)

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ Here is the call graph for this function:

◆ getQuestionType()

assSingleChoice::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question @access public

Reimplemented from assQuestion.

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

571 : string
572 {
573 return "assSingleChoice";
574 }

◆ getRTETextWithMediaObjects()

assSingleChoice::getRTETextWithMediaObjects ( )

Reimplemented from assQuestion.

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

645 : string
646 {
647 $text = parent::getRTETextWithMediaObjects();
648 foreach (array_keys($this->answers) as $index) {
649 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), 0, $index);
650 $answer_obj = $this->answers[$index];
651 $text .= $answer_obj->getAnswertext();
652 }
653 return $text;
654 }

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ getSpecificFeedbackAllCorrectOptionLabel()

assSingleChoice::getSpecificFeedbackAllCorrectOptionLabel ( )

Implements ilAssSpecificFeedbackOptionLabelProvider.

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

769 : string
770 {
771 return 'feedback_correct_sc_mc';
772 }

◆ getSpecificFeedbackSetting()

assSingleChoice::getSpecificFeedbackSetting ( )

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

764 : int
765 {
767 }

◆ getUserQuestionResult()

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

792 $result = new ilUserQuestionResult($this, $active_id, $pass);
793
794 $maxStep = $this->lookupMaxStep($active_id, $pass);
795 if ($maxStep > 0) {
796 $data = $this->db->queryF(
797 "SELECT * FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
798 ["integer", "integer", "integer","integer"],
799 [$active_id, $pass, $this->getId(), $maxStep]
800 );
801 } else {
802 $data = $this->db->queryF(
803 "SELECT * FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
804 ["integer", "integer", "integer"],
805 [$active_id, $pass, $this->getId()]
806 );
807 }
808
809 $row = $this->db->fetchAssoc($data);
810
811 if ($row != null) {
812 ++$row["value1"];
813 $result->addKeyValue($row["value1"], $row["value1"]);
814 }
815
816 $points = $this->calculateReachedPoints($active_id, $pass);
817 $max_points = $this->getMaximumPoints();
818
819 $result->setReachedPercentage(($points / $max_points) * 100);
820
821 return $result;
822 }
lookupMaxStep(int $active_id, int $pass)
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
calculateReachedPoints(int $active_id, ?int $pass=null, bool $authorized_solution=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ isComplete()

assSingleChoice::isComplete ( )

Reimplemented from assQuestion.

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

71 : bool
72 {
73 if (
74 $this->title !== ''
75 && $this->author !== null && $this->author !== ''
76 && $this->question !== null && $this->question !== ''
77 && $this->answers !== []
78 && $this->getMaximumPoints() > 0
79 ) {
80 foreach ($this->answers as $answer) {
81 if ($answer->getAnswertext() === '' && $answer->getImage() === '') {
82 return false;
83 }
84 }
85 return true;
86 }
87 return false;
88 }

References getMaximumPoints().

+ Here is the call graph for this function:

◆ isSingleline()

assSingleChoice::isSingleline ( )

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

860 : bool
861 {
863 }

◆ lmMigrateQuestionTypeSpecificContent()

assSingleChoice::lmMigrateQuestionTypeSpecificContent ( ilAssSelfAssessmentMigrator  $migrator)
protected

Reimplemented from assQuestion.

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

671 : void {
672 foreach ($this->getAnswers() as $answer) {
673 /* @var ASS_AnswerBinaryStateImage $answer */
674 $answer->setAnswertext($migrator->migrateToLmContent($answer->getAnswertext()));
675 }
676 }

References ilAssSelfAssessmentMigrator\migrateToLmContent().

+ Here is the call graph for this function:

◆ loadFromDb()

assSingleChoice::loadFromDb ( int  $question_id)

Reimplemented from assQuestion.

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

98 : void
99 {
100 $result = $this->db->queryF(
101 "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",
102 ["integer"],
103 [$question_id]
104 );
105 if ($result->numRows() == 1) {
106 $data = $this->db->fetchAssoc($result);
107 $this->setId($question_id);
108 $this->setObjId($data["obj_fi"]);
109 $this->setTitle($data["title"] ?? '');
110 $this->setNrOfTries($data['nr_of_tries']);
111 $this->setComment($data["description"] ?? '');
112 $this->setOriginalId($data["original_id"]);
113 $this->setAuthor($data["author"]);
114 $this->setPoints($data["points"]);
115 $this->setOwner($data["owner"]);
116 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"] ?? '', 1));
117 $shuffle = (is_null($data['shuffle'])) ? true : $data['shuffle'];
118 $this->setShuffle((bool) $shuffle);
119 if ($data['thumb_size'] !== null && $data['thumb_size'] >= $this->getMinimumThumbSize()) {
120 $this->setThumbSize($data['thumb_size']);
121 }
122 $this->is_singleline = $data['allow_images'] === null || $data['allow_images'] === '0';
123 $this->lastChange = $data['tstamp'];
124 $this->feedback_setting = $data['feedback_setting'] ?? self::FEEDBACK_MODE_SELECTED_ANSWERS;
125
126 try {
130 }
131
132 try {
133 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
135 }
136 }
137
138 $result = $this->db->queryF(
139 "SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
140 ['integer'],
141 [$question_id]
142 );
143
144 if ($result->numRows() > 0) {
145 while ($data = $this->db->fetchAssoc($result)) {
146 $imagefilename = $this->getImagePath() . $data["imagefile"];
147 if (!file_exists($imagefilename)) {
148 $data["imagefile"] = null;
149 }
150
151 $data["answertext"] = ilRTE::_replaceMediaObjectImageSrc($data["answertext"] ?? '', 1);
152 $image = new ASS_AnswerBinaryStateImage(
153 $data["answertext"],
154 $data["points"],
155 $data["aorder"],
156 true,
157 $data["imagefile"] ? $data["imagefile"] : null,
158 $data["answer_id"]
159 );
160 $this->answers[] = $image;
161 }
162 }
163
164 parent::loadFromDb($question_id);
165 }
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)
getAdditionalTableName()
Returns the name of the additional question data table in the database.
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(), FEEDBACK_MODE_SELECTED_ANSWERS, getAdditionalTableName(), ilAssQuestionLifecycle\getDraftInstance(), assQuestion\getImagePath(), ilAssQuestionLifecycle\getInstance(), assQuestion\getMinimumThumbSize(), assQuestion\setAdditionalContentEditingMode(), assQuestion\setAuthor(), assQuestion\setComment(), assQuestion\setId(), assQuestion\setLifecycle(), assQuestion\setNrOfTries(), assQuestion\setObjId(), assQuestion\setOriginalId(), assQuestion\setOwner(), assQuestion\setPoints(), assQuestion\setQuestion(), assQuestion\setShuffle(), assQuestion\setThumbSize(), and assQuestion\setTitle().

+ Here is the call graph for this function:

◆ removeAnswerImage()

assSingleChoice::removeAnswerImage ( int  $index)

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

733 : void
734 {
735 $answer = $this->answers[$index];
736 if (is_object($answer)) {
737 $this->deleteImage($answer->getImage());
738 $answer->setImage(null);
739 }
740 }

◆ saveAdditionalQuestionDataToDb()

assSingleChoice::saveAdditionalQuestionDataToDb ( )

Saves a record to the question types additional data table.

Returns
mixed

Implements ilObjQuestionScoringAdjustable.

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

416 : void
417 {
418 // save additional data
419 $this->db->manipulateF(
420 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
421 [ "integer" ],
422 [ $this->getId() ]
423 );
424
425 $this->db->manipulateF(
426 "INSERT INTO " . $this->getAdditionalTableName(
427 ) . " (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
428 [ "integer", "text", "text", "integer" ],
429 [
430 $this->getId(),
431 $this->getShuffle(),
432 $this->is_singleline ? '0' : '1',
433 $this->getThumbSize()
434 ]
435 );
436 }

References ILIAS\Survey\Mode\getId().

Referenced by saveToDb().

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

◆ savePreviewData()

assSingleChoice::savePreviewData ( ilAssQuestionPreviewSession  $previewSession)
protected

Reimplemented from assQuestion.

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

403 : void
404 {
405 $mc_result_key = 'multiple_choice_result' . $this->getId() . 'ID';
406 if (
407 $this->http->wrapper()->post()->has($mc_result_key) &&
408 ($mc_result = $this->http->wrapper()->post()->retrieve($mc_result_key, $this->refinery->kindlyTo()->string())) !== ''
409 ) {
410 $previewSession->setParticipantsSolution($mc_result);
411 } else {
412 $previewSession->setParticipantsSolution(null);
413 }
414 }
static http()
Fetches the global http state from ILIAS.

References ILIAS\Survey\Mode\getId(), ILIAS\FileDelivery\http(), and ilAssQuestionPreviewSession\setParticipantsSolution().

+ Here is the call graph for this function:

◆ saveToDb()

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

Reimplemented from assQuestion.

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

90 : void
91 {
95 parent::saveToDb($original_id);
96 }
saveQuestionDataToDb(?int $original_id=null)
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.

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

+ Here is the call graph for this function:

◆ saveWorkingData()

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

Reimplemented from assQuestion.

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

364 : bool {
365 if (is_null($pass)) {
366 $pass = ilObjTest::_getPass($active_id);
367 }
368
369 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
370 function () use ($active_id, $pass, $authorized) {
371 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized);
372
373 $update = -1;
374 if ($this->db->numRows($result)) {
375 $row = $this->db->fetchAssoc($result);
376 $update = $row["solution_id"];
377 }
378
379 $multiple_choice_result = $this->http->wrapper()->post()->has('multiple_choice_result') ?
380 $this->http->wrapper()->post()->retrieve('multiple_choice_result', $this->refinery->kindlyTo()->string()) :
381 '';
382
383 if ($update !== -1
384 && $multiple_choice_result === '') {
385 $this->removeSolutionRecordById($update);
386 return;
387 }
388
389 if ($update !== -1) {
390 $this->updateCurrentSolution($update, $multiple_choice_result, null, $authorized);
391 return;
392 }
393
394 if ($multiple_choice_result !== '') {
395 $this->saveCurrentSolution($active_id, $pass, $multiple_choice_result, null, $authorized);
396 }
397 }
398 );
399
400 return true;
401 }
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
updateCurrentSolution(int $solutionId, $value1, $value2, bool $authorized=true)
removeSolutionRecordById(int $solutionId)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.

References ilObjTest\_getPass().

+ Here is the call graph for this function:

◆ setAnswers()

assSingleChoice::setAnswers ( array  $answers)

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

664 : void
665 {
666 $this->answers = $answers;
667 }

◆ setFeedbackSetting()

assSingleChoice::setFeedbackSetting ( int  $feedback_setting)

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

875 : void
876 {
877 $this->feedback_setting = $feedback_setting;
878 }

◆ setImageFile()

assSingleChoice::setImageFile ( string  $image_filename,
string  $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 @access public

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

609 : int {
610 if (empty($image_tempfilename)) {
611 return 0;
612 }
613
614 $cleaned_image_filename = str_replace(" ", "_", $image_filename);
615 $imagepath = $this->getImagePath();
616 if (!file_exists($imagepath)) {
617 ilFileUtils::makeDirParents($imagepath);
618 }
619
620 if (!ilFileUtils::moveUploadedFile($image_tempfilename, $cleaned_image_filename, $imagepath . $cleaned_image_filename)) {
621 return 2;
622 }
623
624 $mimetype = ilObjMediaObject::getMimeType($imagepath . $cleaned_image_filename);
625 if (!preg_match("/^image/", $mimetype)) {
626 unlink($imagepath . $cleaned_image_filename);
627 return 1;
628 }
629
630 if ($this->is_singleline && $this->getThumbSize()) {
631 $this->generateThumbForFile(
632 $cleaned_image_filename,
633 $this->getImagePath(),
634 $this->getThumbSize()
635 );
636 }
637
638 return 0;
639 }
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

◆ setIsSingleline()

assSingleChoice::setIsSingleline ( bool  $is_singleline)

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

865 : void
866 {
867 $this->is_singleline = $is_singleline;
868 }

◆ setMultilineAnswerSetting()

assSingleChoice::setMultilineAnswerSetting (   $setting = '0')

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

747 : void
748 {
749 $this->current_user->writePref('tst_multiline_answers', (string) $setting);
750 }

◆ setSpecificFeedbackSetting()

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

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

759 : void
760 {
761 $this->feedback_setting = $feedback_setting;
762 }

◆ solutionValuesToLog()

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

912 : string {
913 if ($solution_values === []
914 || !array_key_exists(0, $solution_values)
915 || !is_array($solution_values[0])) {
916 return $additional_info->getNoneTag();
917 }
918
919 return $this->getAnswer((int) $solution_values[0]['value1'])->getAnswertext();
920 }

References ILIAS\Test\Logging\AdditionalInformationGenerator\getNoneTag().

+ Here is the call graph for this function:

◆ solutionValuesToText()

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

922 : string
923 {
924 if ($solution_values === []
925 || !array_key_exists(0, $solution_values)
926 || !is_array($solution_values[0])) {
927 return '';
928 }
929
930 return $this->getAnswer((int) $solution_values[0]['value1'])->getAnswertext();
931 }

◆ toJSON()

assSingleChoice::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

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

681 : string
682 {
683 $result = [];
684 $result['id'] = $this->getId();
685 $result['type'] = (string) $this->getQuestionType();
686 $result['title'] = $this->getTitleForHTMLOutput();
687 $result['question'] = $this->formatSAQuestion($this->getQuestion());
688 $result['nr_of_tries'] = $this->getNrOfTries();
689 $result['shuffle'] = $this->getShuffle();
690
691 $result['feedback'] = [
692 'onenotcorrect' => $this->formatSAQuestion(
693 $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)
694 ),
695 'allcorrect' => $this->formatSAQuestion(
696 $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true)
697 )
698 ];
699
700 $answers = [];
701 $has_image = false;
702 foreach ($this->getAnswers() as $key => $answer_obj) {
703 if ((string) $answer_obj->getImage()) {
704 $has_image = true;
705 }
706 array_push($answers, [
707 "answertext" => $this->formatSAQuestion($answer_obj->getAnswertext()),
708 'html_id' => $this->getId() . '_' . $key,
709 "points" => (float) $answer_obj->getPoints(),
710 "order" => (int) $answer_obj->getOrder(),
711 "image" => (string) $answer_obj->getImage(),
712 "feedback" => $this->formatSAQuestion(
713 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
714 $this->getId(),
715 0,
716 $key
717 )
718 )
719 ]);
720 }
721 $result['answers'] = $answers;
722 if ($has_image) {
723 $result['path'] = $this->getImagePathWeb();
724 $result['thumb'] = $this->getThumbSize();
725 }
726
727 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
728 $result['mobs'] = $mobs;
729
730 return json_encode($result);
731 }
getImagePathWeb()
Returns the web image path for web accessable images of a question.
getQuestionType()
Returns the question type of the question.
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")

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

+ Here is the call graph for this function:

◆ toLog()

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

880 : array
881 {
882 $result = [
883 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->getQuestionType(),
884 AdditionalInformationGenerator::KEY_QUESTION_TITLE => $this->getTitleForHTMLOutput(),
885 AdditionalInformationGenerator::KEY_QUESTION_TEXT => $this->formatSAQuestion($this->getQuestion()),
886 AdditionalInformationGenerator::KEY_QUESTION_SHUFFLE_ANSWER_OPTIONS => $additional_info
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_REACHABLE_POINTS => (float) $answer_obj->getPoints(),
898 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_ORDER => (int) $answer_obj->getOrder(),
899 AdditionalInformationGenerator::KEY_QUESTION_ANSWER_OPTION_IMAGE => (string) $answer_obj->getImage(),
900 AdditionalInformationGenerator::KEY_FEEDBACK => $this->formatSAQuestion(
901 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
902 )
903 ];
904 }
905
906 return $result;
907 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $answers

array assSingleChoice::$answers = []

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

◆ $feedback_setting

int assSingleChoice::$feedback_setting = self::FEEDBACK_MODE_SELECTED_ANSWERS
protected

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

◆ $is_singleline

bool assSingleChoice::$is_singleline = true
private

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

◆ $output_type

int assSingleChoice::$output_type

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

Referenced by __construct().

◆ FEEDBACK_MODE_ALL_ANSWERS

const assSingleChoice::FEEDBACK_MODE_ALL_ANSWERS = 1
protected

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

◆ FEEDBACK_MODE_CORRECT_ANSWERS

const assSingleChoice::FEEDBACK_MODE_CORRECT_ANSWERS = 3
protected

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

◆ FEEDBACK_MODE_SELECTED_ANSWERS

const assSingleChoice::FEEDBACK_MODE_SELECTED_ANSWERS = 2
protected

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

Referenced by loadFromDb().

◆ OUTPUT_ORDER

const assSingleChoice::OUTPUT_ORDER = 0
protected

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

◆ OUTPUT_RANDOM

const assSingleChoice::OUTPUT_RANDOM = 1
protected

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


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