ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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)
 
 toNormalized (Transformations $transformations, array $context=[])
 
 fromNormalized (array $normalized, Transformations $transformations)
 
- Public Member Functions inherited from assQuestion
 getQuestionType ()
 
 isComplete ()
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 calculateReachedPoints (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 MUST return an array of the question settings that can be stored in the log. More...
 
 getCurrentUser ()
 
 getShuffler ()
 
 setShuffler (Transformation $shuffler)
 
 setProcessLocker (ilAssQuestionProcessLocker $processLocker)
 
 getProcessLocker ()
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 toXML (bool $a_include_header=true, bool $a_include_binary=true, bool $a_shuffle=false, bool $test_output=false, bool $force_image_references=false)
 
 setTitle (string $title="")
 
 setId (int $id=-1)
 
 setTestId (int $id=-1)
 
 setComment (string $comment="")
 
 setShuffle (?bool $shuffle=true)
 
 setAuthor (string $author="")
 
 setOwner (int $owner=-1)
 
 getTitle ()
 
 getTitleForHTMLOutput ()
 
 getTitleFilenameCompliant ()
 
 getId ()
 
 getShuffle ()
 
 getTestId ()
 
 getComment ()
 
 getDescriptionForHTMLOutput ()
 
 getThumbSize ()
 
 setThumbSize (int $a_size)
 
 getMinimumThumbSize ()
 
 getMaximumThumbSize ()
 
 getAuthor ()
 
 getAuthorForHTMLOutput ()
 
 getOwner ()
 
 getObjId ()
 
 setObjId (int $obj_id=0)
 
 getLifecycle ()
 
 setLifecycle (ilAssQuestionLifecycle $lifecycle)
 
 setExternalId (?string $external_id)
 
 getExternalId ()
 
 getSuggestedSolutionOutput ()
 
 getSuggestedSolutions ()
 
 getReachedPoints (int $active_id, int $pass)
 
 getMaximumPoints ()
 
 getAdjustedReachedPoints (int $active_id, int $pass, bool $authorized_solution=true)
 
 calculateResultsFromSolution (int $active_id, int $pass)
 Calculates the question results from a previously saved question solution. More...
 
 persistWorkingState (int $active_id, $pass, bool $authorized=true)
 persists the working state for current testactive and testpass More...
 
 persistPreviewState (ilAssQuestionPreviewSession $preview_session)
 persists the preview state for current user and question More...
 
 validateSolutionSubmit ()
 
 getSuggestedSolutionPath ()
 
 getImagePath ($question_id=null, $object_id=null)
 Returns the image path for web accessable images of a question. More...
 
 getSuggestedSolutionPathWeb ()
 
 getImagePathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 getTestOutputSolutions (int $activeId, int $pass)
 
 getUserSolutionPreferingIntermediate (int $active_id, ?int $pass=null)
 
 getSolutionValues (int $active_id, ?int $pass=null, bool $authorized=true)
 Loads solutions of a given user from the database an returns it. More...
 
 deleteAnswers (int $question_id)
 
 deleteAdditionalTableData (int $question_id)
 
 delete (int $question_id)
 
 getTotalAnswers ()
 
 cloneXHTMLMediaObjectsOfQuestion (int $source_question_id)
 
 createPageObject ()
 
 clonePageOfQuestion (int $a_q_id)
 
 getPageOfQuestion ()
 
 setOriginalId (?int $original_id)
 
 getOriginalId ()
 
 fixSvgToPng (string $imageFilenameContainingString)
 
 fixUnavailableSkinImageSources (string $html)
 
 loadFromDb (int $question_id)
 
 createNewQuestion (bool $a_create_page=true)
 Creates a new question without an owner when a new question is created This assures that an ID is given to the question if a file upload or something else occurs. More...
 
 saveQuestionDataToDb (?int $original_id=null)
 
 updateOriginalId (?int $original_id=null)
 
 duplicate (bool $set_original_id=true, string $title='', string $author='', int $owner=-1, $test_obj_id=null)
 
 copyObject (int $target_parent_id, string $title='')
 
 createNewOriginalFromThisDuplicate (int $target_parent_id, string $target_question_title='')
 
 saveToDb (?int $original_id=null)
 
 deleteSuggestedSolutions ()
 
 getSuggestedSolution (int $subquestion_index=0)
 
 resolveInternalLink (string $internal_link)
 
 resolveSuggestedSolutionLinks ()
 
 getInternalLinkHref (string $target)
 
 syncWithOriginal ()
 
 getPoints ()
 
 setPoints (float $points)
 
 getSolutionMaxPass (int $active_id)
 
 isWriteable ()
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $preview_session)
 
 isPreviewSolutionCorrect (ilAssQuestionPreviewSession $preview_session)
 
 adjustReachedPointsByScoringOptions (float $points, int $active_id)
 Adjust the given reached points by checks for all special scoring options in the test container. More...
 
 buildHashedImageFilename (string $plain_image_filename, bool $unique=false)
 
 getQuestion ()
 
 getQuestionForHTMLOutput ()
 
 setQuestion (string $question="")
 
 getQuestionTypeID ()
 
 cleanupMediaObjectUsage ()
 
 getInstances ()
 
 getActiveUserData (int $active_id)
 Returns the user id and the test id for a given active id. More...
 
 hasSpecificFeedback ()
 
 getNrOfTries ()
 
 setNrOfTries (int $a_nr_of_tries)
 
 setExportImagePath (string $path)
 
 formatSAQuestion ($a_q)
 
 setPreventRteUsage (bool $prevent_rte_usage)
 
 getPreventRteUsage ()
 
 migrateContentForLearningModule (ilAssSelfAssessmentMigrator $migrator)
 
 setSelfAssessmentEditingMode (bool $selfassessmenteditingmode)
 
 getSelfAssessmentEditingMode ()
 
 setDefaultNrOfTries (int $defaultnroftries)
 
 getDefaultNrOfTries ()
 
 syncSkillAssignments (int $srcParentId, int $srcQuestionId, int $trgParentId, int $trgQuestionId)
 
 isAnswered (int $active_id, int $pass)
 
 getAdditionalContentEditingMode ()
 
 setAdditionalContentEditingMode (?string $additionalContentEditingMode)
 
 isAdditionalContentEditingModePageObject ()
 
 isValidAdditionalContentEditingMode (string $additionalContentEditingMode)
 
 getValidAdditionalContentEditingModes ()
 
 getHtmlUserSolutionPurifier ()
 
 getHtmlQuestionContentPurifier ()
 
 setLastChange (int $lastChange)
 
 getLastChange ()
 
 removeIntermediateSolution (int $active_id, int $pass)
 
 removeCurrentSolution (int $active_id, int $pass, bool $authorized=true)
 
 saveCurrentSolution (int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
 
 updateCurrentSolution (int $solutionId, $value1, $value2, bool $authorized=true)
 
 updateCurrentSolutionsAuthorization (int $activeId, int $pass, bool $authorized, bool $keepTime=false)
 
 setStep ($step)
 
 getStep ()
 
 toJSON ()
 
 intermediateSolutionExists (int $active_id, int $pass)
 
 authorizedSolutionExists (int $active_id, ?int $pass)
 
 authorizedOrIntermediateSolutionExists (int $active_id, int $pass)
 
 lookupForExistingSolutions (int $activeId, int $pass)
 Lookup if an authorized or intermediate solution exists. More...
 
 isAddableAnswerOptionValue (int $qIndex, string $answerOptionValue)
 
 addAnswerOptionValue (int $qIndex, string $answerOptionValue, float $points)
 
 removeAllExistingSolutions ()
 
 removeExistingSolutions (int $activeId, int $pass)
 
 resetUsersAnswer (int $activeId, int $pass)
 
 removeResultRecord (int $activeId, int $pass)
 
 fetchValuePairsFromIndexedValues (array $indexedValues)
 
 fetchIndexedValuesFromValuePairs (array $value_pairs)
 
 updateTimestamp ()
 
 getTestPresentationConfig ()
 
 hasWritableOriginalInQuestionPool ()
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
 getSolutionForTextOutput (int $active_id, int $pass)
 
 getCorrectSolutionForTextOutput (int $active_id, int $pass)
 
 getVariablesAsTextArray (int $active_id, int $pass)
 
 toNormalized (Transformations $transformations, array $context=[])
 
 fromNormalized (array $normalized, Transformations $transformations)
 
 validateSolutionSubmit ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
 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 ()
 
 toNormalized (Transformations $transformations, array $context=[])
 Convert the internal state of the implementing object into a language-neutral array structure. More...
 
 fromNormalized (array $normalized, Transformations $transformations)
 Restore the object from its normalized representation. More...
 

Data Fields

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 42 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 183 of file class.assSingleChoice.php.

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

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

+ Here is the call graph for this function:

◆ 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 845 of file class.assSingleChoice.php.

850 : void {
851 parent::afterSyncWithOriginal($original_question_id, $clone_question_id, $original_parent_id, $clone_parent_id);
852
853 $original_image_path = $this->question_files->buildImagePath($original_question_id, $original_parent_id);
854 $clone_image_path = $this->question_files->buildImagePath($clone_question_id, $clone_parent_id);
855
856 ilFileUtils::delDir($original_image_path);
857 if (is_dir($clone_image_path)) {
858 ilFileUtils::makeDirParents($original_image_path);
859 ilFileUtils::rCopy($clone_image_path, $original_image_path);
860 }
861 }
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 321 of file class.assSingleChoice.php.

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

◆ calculateReachedPointsFromPreviewSession()

assSingleChoice::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $preview_session)

Reimplemented from assQuestion.

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

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

◆ cloneQuestionTypeSpecificProperties()

assSingleChoice::cloneQuestionTypeSpecificProperties ( \assQuestion  $target)
protected

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

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

◆ 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 269 of file class.assSingleChoice.php.

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

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

299 : void
300 {
301 $this->answers = [];
302 }

◆ fromNormalized()

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

Reimplemented from assQuestion.

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

968 : static
969 {
970 $clone = parent::fromNormalized($normalized, $transformations);
971 $clone->is_singleline = $transformations->bool($normalized['is_singleline']);
972 $clone->feedback_setting = $transformations->int($normalized['feedback_setting']);
973 $clone->answers = array_map(
974 static fn(array $answer): ASS_AnswerBinaryStateImage => $transformations->denormalize($answer, new ASS_AnswerBinaryStateImage()),
975 $normalized['answers']
976 );
977 return $clone;
978 }
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)

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

+ Here is the call graph for this function:

◆ getAdditionalTableName()

assSingleChoice::getAdditionalTableName ( )

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

Returns
string The additional table name @access public

Reimplemented from assQuestion.

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

585 : string
586 {
587 return "qpl_qst_sc";
588 }

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

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

◆ 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 232 of file class.assSingleChoice.php.

232 : int
233 {
234 return count($this->answers);
235 }

◆ getAnswers()

assSingleChoice::getAnswers ( )

Returns a reference to the answers array.

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

662 : array
663 {
664 return $this->answers;
665 }

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

596 : string
597 {
598 return "qpl_a_sc";
599 }

◆ 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 833 of file class.assSingleChoice.php.

834 {
835 if ($index !== null) {
836 return $this->getAnswer($index);
837 } else {
838 return $this->getAnswers();
839 }
840 }
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 936 of file class.assSingleChoice.php.

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

References Vendor\Package\$c, and ASS_AnswerSimple\getPoints().

+ Here is the call graph for this function:

◆ getExpressionTypes()

assSingleChoice::getExpressionTypes ( )

◆ getFeedbackSetting()

assSingleChoice::getFeedbackSetting ( )

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

873 : int
874 {
876 }

◆ 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 310 of file class.assSingleChoice.php.

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

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assSingleChoice::getMultilineAnswerSetting ( )

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

745 : int
746 {
747 return $this->current_user->getPref('tst_multiline_answers') === '1' ? 1 : 0;
748 }

◆ getOperators()

assSingleChoice::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

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

777 : array
778 {
780 }
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 574 of file class.assSingleChoice.php.

574 : string
575 {
576 return "assSingleChoice";
577 }

◆ getRTETextWithMediaObjects()

assSingleChoice::getRTETextWithMediaObjects ( )

Reimplemented from assQuestion.

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

648 : string
649 {
650 $text = parent::getRTETextWithMediaObjects();
651 foreach (array_keys($this->answers) as $index) {
652 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), 0, $index);
653 $answer_obj = $this->answers[$index];
654 $text .= $answer_obj->getAnswertext();
655 }
656 return $text;
657 }
$text
Definition: xapiexit.php:21

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

+ Here is the call graph for this function:

◆ getSpecificFeedbackAllCorrectOptionLabel()

assSingleChoice::getSpecificFeedbackAllCorrectOptionLabel ( )

Implements ilAssSpecificFeedbackOptionLabelProvider.

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

772 : string
773 {
774 return 'feedback_correct_sc_mc';
775 }

◆ getSpecificFeedbackSetting()

assSingleChoice::getSpecificFeedbackSetting ( )

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

767 : int
768 {
770 }

◆ 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 791 of file class.assSingleChoice.php.

795 $result = new ilUserQuestionResult($this, $active_id, $pass);
796
797 $maxStep = $this->lookupMaxStep($active_id, $pass);
798 if ($maxStep > 0) {
799 $data = $this->db->queryF(
800 "SELECT * FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
801 ["integer", "integer", "integer","integer"],
802 [$active_id, $pass, $this->getId(), $maxStep]
803 );
804 } else {
805 $data = $this->db->queryF(
806 "SELECT * FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
807 ["integer", "integer", "integer"],
808 [$active_id, $pass, $this->getId()]
809 );
810 }
811
812 $row = $this->db->fetchAssoc($data);
813
814 if ($row != null) {
815 ++$row["value1"];
816 $result->addKeyValue($row["value1"], $row["value1"]);
817 }
818
819 $points = $this->calculateReachedPoints($active_id, $pass);
820 $max_points = $this->getMaximumPoints();
821
822 $result->setReachedPercentage(($points / $max_points) * 100);
823
824 return $result;
825 }
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 74 of file class.assSingleChoice.php.

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

References getMaximumPoints().

+ Here is the call graph for this function:

◆ isSingleline()

assSingleChoice::isSingleline ( )

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

863 : bool
864 {
866 }

◆ lmMigrateQuestionTypeSpecificContent()

assSingleChoice::lmMigrateQuestionTypeSpecificContent ( ilAssSelfAssessmentMigrator  $migrator)
protected

Reimplemented from assQuestion.

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

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

References ilAssSelfAssessmentMigrator\migrateToLmContent().

+ Here is the call graph for this function:

◆ loadFromDb()

assSingleChoice::loadFromDb ( int  $question_id)

Reimplemented from assQuestion.

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

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

+ Here is the call graph for this function:

◆ removeAnswerImage()

assSingleChoice::removeAnswerImage ( int  $index)

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

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

◆ saveAdditionalQuestionDataToDb()

assSingleChoice::saveAdditionalQuestionDataToDb ( )

Saves a record to the question types additional data table.

Returns
mixed

Implements ilObjQuestionScoringAdjustable.

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

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

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

406 : void
407 {
408 $mc_result_key = 'multiple_choice_result' . $this->getId() . 'ID';
409 if (
410 $this->http->wrapper()->post()->has($mc_result_key) &&
411 ($mc_result = $this->http->wrapper()->post()->retrieve($mc_result_key, $this->refinery->kindlyTo()->string())) !== ''
412 ) {
413 $previewSession->setParticipantsSolution($mc_result);
414 } else {
415 $previewSession->setParticipantsSolution(null);
416 }
417 }
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 93 of file class.assSingleChoice.php.

93 : void
94 {
98 parent::saveToDb($original_id);
99 }
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 363 of file class.assSingleChoice.php.

367 : bool {
368 if (is_null($pass)) {
369 $pass = ilObjTest::_getPass($active_id);
370 }
371
372 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
373 function () use ($active_id, $pass, $authorized) {
374 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized);
375
376 $update = -1;
377 if ($this->db->numRows($result)) {
378 $row = $this->db->fetchAssoc($result);
379 $update = $row["solution_id"];
380 }
381
382 $multiple_choice_result = $this->http->wrapper()->post()->has('multiple_choice_result') ?
383 $this->http->wrapper()->post()->retrieve('multiple_choice_result', $this->refinery->kindlyTo()->string()) :
384 '';
385
386 if ($update !== -1
387 && $multiple_choice_result === '') {
388 $this->removeSolutionRecordById($update);
389 return;
390 }
391
392 if ($update !== -1) {
393 $this->updateCurrentSolution($update, $multiple_choice_result, null, $authorized);
394 return;
395 }
396
397 if ($multiple_choice_result !== '') {
398 $this->saveCurrentSolution($active_id, $pass, $multiple_choice_result, null, $authorized);
399 }
400 }
401 );
402
403 return true;
404 }
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 667 of file class.assSingleChoice.php.

667 : void
668 {
669 $this->answers = $answers;
670 }

◆ setFeedbackSetting()

assSingleChoice::setFeedbackSetting ( int  $feedback_setting)

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

878 : void
879 {
880 $this->feedback_setting = $feedback_setting;
881 }

◆ 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 609 of file class.assSingleChoice.php.

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

868 : void
869 {
870 $this->is_singleline = $is_singleline;
871 }

◆ setMultilineAnswerSetting()

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

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

750 : void
751 {
752 $this->current_user->writePref('tst_multiline_answers', (string) $setting);
753 }

◆ 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 762 of file class.assSingleChoice.php.

762 : void
763 {
764 $this->feedback_setting = $feedback_setting;
765 }

◆ 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 912 of file class.assSingleChoice.php.

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

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

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

◆ toJSON()

assSingleChoice::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

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

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

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

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

+ Here is the call graph for this function:

◆ toNormalized()

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

Reimplemented from assQuestion.

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

955 : array|float|bool|int|string|null
956 {
957 $normalized = $transformations->normalize(parent::toNormalized($transformations, $context));
958 $normalized['is_singleline'] = $this->is_singleline;
959 $normalized['feedback_setting'] = $this->feedback_setting;
960 $normalized['answers'] = $transformations->normalize($this->answers, ['question_id' => $this->getId()]);
961 return $normalized;
962 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $answers

array assSingleChoice::$answers = []

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

◆ $feedback_setting

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

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

◆ $is_singleline

bool assSingleChoice::$is_singleline = true
private

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

◆ $output_type

int assSingleChoice::$output_type

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

Referenced by __construct().

◆ FEEDBACK_MODE_ALL_ANSWERS

const assSingleChoice::FEEDBACK_MODE_ALL_ANSWERS = 1
protected

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

◆ FEEDBACK_MODE_CORRECT_ANSWERS

const assSingleChoice::FEEDBACK_MODE_CORRECT_ANSWERS = 3
protected

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

◆ FEEDBACK_MODE_SELECTED_ANSWERS

const assSingleChoice::FEEDBACK_MODE_SELECTED_ANSWERS = 2
protected

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

Referenced by loadFromDb().

◆ OUTPUT_ORDER

const assSingleChoice::OUTPUT_ORDER = 0
protected

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

◆ OUTPUT_RANDOM

const assSingleChoice::OUTPUT_RANDOM = 1
protected

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


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