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

Class for single choice questions. More...

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

Public Member Functions

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

Static Public Member Functions

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

Data Fields

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

Protected Member Functions

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

Protected Attributes

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

Private Attributes

bool $isSingleline = true
 

Additional Inherited Members

- Static Protected Member Functions inherited from assQuestion
static getNumExistingSolutionRecords (int $activeId, int $pass, int $questionId)
 
- Static Protected Attributes inherited from assQuestion
static $forcePassResultsUpdateEnabled = false
 
static $imageSourceFixReplaceMap
 

Detailed Description

Class for 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 36 of file class.assSingleChoice.php.

Constructor & Destructor Documentation

◆ __construct()

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

assSingleChoice constructor

The constructor takes possible arguments an creates an instance of the assSingleChoice object.

Parameters
string$titleA title string to describe the question
string$commentA comment string to describe the question
string$authorA string containing the name of the questions author
integer$ownerA numerical ID to identify the owner/creator
string$questionThe question string of the single choice question
int | string$output_typeThe output order of the single choice answers
See also
assQuestion:assQuestion()

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

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

90  {
92  $this->output_type = $output_type;
93  $this->answers = [];
94  $this->shuffle = 1;
95  $this->feedback_setting = 2;
96  }
__construct(VocabulariesInterface $vocabularies)
string $question
The question text.
+ Here is the call graph for this function:

Member Function Documentation

◆ addAnswer()

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

Adds a possible answer for a single choice question.

A ASS_AnswerBinaryStateImage object will be created and assigned to the array $this->answers.

Parameters
string$answertextThe answer text
double$pointsThe points for selecting the answer (even negative points can be used)
boolean$stateDefines the answer as correct (TRUE) or incorrect (FALSE)
integer$orderA possible display order of the answer
double$pointsThe points for not selecting the answer (even negative points can be used) public
See also
$answers
ASS_AnswerBinaryStateImage

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

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

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

◆ afterSyncWithOriginal()

assSingleChoice::afterSyncWithOriginal (   $origQuestionId,
  $dupQuestionId,
  $origParentObjId,
  $dupParentObjId 
)
protected

{}

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

References ilFileUtils\delDir(), ilFileUtils\makeDirParents(), and ilFileUtils\rCopy().

1283  : void
1284  {
1285  parent::afterSyncWithOriginal($origQuestionId, $dupQuestionId, $origParentObjId, $dupParentObjId);
1286 
1287  $origImagePath = $this->questionFilesService->buildImagePath($origQuestionId, $origParentObjId);
1288  $dupImagePath = $this->questionFilesService->buildImagePath($dupQuestionId, $dupParentObjId);
1289 
1290  ilFileUtils::delDir($origImagePath);
1291  if (is_dir($dupImagePath)) {
1292  ilFileUtils::makeDirParents($origImagePath);
1293  ilFileUtils::rCopy($dupImagePath, $origImagePath);
1294  }
1295  }
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
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
+ Here is the call graph for this function:

◆ calculateReachedPoints()

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

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

The points are calculated from the given answers.

public

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

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

References $data, $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, assQuestion\$points, assQuestion\getCurrentSolutionResultSet(), and assQuestion\getSolutionMaxPass().

Referenced by getExpressionTypes().

511  : float
512  {
513  if ($returndetails) {
514  throw new ilTestException('return details not implemented for ' . __METHOD__);
515  }
516 
517  global $DIC;
518  $ilDB = $DIC['ilDB'];
519 
520  $found_values = [];
521  if (is_null($pass)) {
522  $pass = $this->getSolutionMaxPass($active_id);
523  }
524  $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorizedSolution);
525  while ($data = $ilDB->fetchAssoc($result)) {
526  if (strcmp($data["value1"], "") != 0) {
527  array_push($found_values, $data["value1"]);
528  }
529  }
530  $points = 0;
531  foreach ($this->answers as $key => $answer) {
532  if (count($found_values) > 0) {
533  if (in_array($key, $found_values)) {
534  $points += $answer->getPoints();
535  }
536  }
537  }
538 
539  return (float) $points;
540  }
float $points
The maximum available points for the question.
Base Exception for all Exceptions relating to Modules/Test.
global $DIC
Definition: feed.php:28
string $key
Consumer key/client ID value.
Definition: System.php:193
getSolutionMaxPass(int $active_id)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calculateReachedPointsFromPreviewSession()

assSingleChoice::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $previewSession)

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

References ILIAS\LTI\ToolProvider\$key, assQuestion\$points, assQuestion\deductHintPointsFromReachedPoints(), assQuestion\ensureNonNegativePoints(), and ilAssQuestionPreviewSession\getParticipantsSolution().

543  {
544  $participantSolution = $previewSession->getParticipantsSolution();
545 
546  $points = 0;
547 
548  foreach ($this->answers as $key => $answer) {
549  if (is_numeric($participantSolution) && $key == $participantSolution) {
550  $points = $answer->getPoints();
551  }
552  }
553 
554  $reachedPoints = $this->deductHintPointsFromReachedPoints($previewSession, $points);
555 
556  return $this->ensureNonNegativePoints($reachedPoints);
557  }
ensureNonNegativePoints($points)
float $points
The maximum available points for the question.
string $key
Consumer key/client ID value.
Definition: System.php:193
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
+ Here is the call graph for this function:

◆ copyObject()

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

Copies an assSingleChoice object.

public

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

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

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

◆ createNewOriginalFromThisDuplicate()

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

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

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

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

◆ deleteAnswer()

assSingleChoice::deleteAnswer (   $index = 0)

Deletes an answer with a given index.

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

Parameters
integer$indexA nonnegative index of the n-th answer public
See also
$answers

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

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

449  : void
450  {
451  if ($index < 0) {
452  return;
453  }
454  if (count($this->answers) < 1) {
455  return;
456  }
457  if ($index >= count($this->answers)) {
458  return;
459  }
460  $answer = $this->answers[$index];
461  if ($answer->hasImage()) {
462  $this->deleteImage($answer->getImage());
463  }
464  unset($this->answers[$index]);
465  $this->answers = array_values($this->answers);
466  for ($i = 0, $iMax = count($this->answers); $i < $iMax; $i++) {
467  if ($this->answers[$i]->getOrder() > $index) {
468  $this->answers[$i]->setOrder($i);
469  }
470  }
471  }
deleteImage($image_filename)
Deletes an image file.
+ Here is the call graph for this function:

◆ deleteImage()

assSingleChoice::deleteImage (   $image_filename)

Deletes an image file.

Parameters
string$image_filenameName of the image file to delete private

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

References assQuestion\getImagePath().

Referenced by deleteAnswer(), and removeAnswerImage().

877  : void
878  {
879  $imagepath = $this->getImagePath();
880  @unlink($imagepath . $image_filename);
881  $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
882  @unlink($thumbpath);
883  }
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ duplicate()

assSingleChoice::duplicate ( bool  $for_test = true,
string  $title = "",
string  $author = "",
int  $owner = -1,
  $testObjId = null 
)

Duplicates an assSingleChoiceQuestion.

public

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

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

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

◆ duplicateImages()

assSingleChoice::duplicateImages (   $question_id,
  $objectId = null 
)

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

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

885  : void
886  {
887  global $DIC;
888  $ilLog = $DIC['ilLog'];
889  $imagepath = $this->getImagePath();
890  $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
891 
892  if ((int) $objectId > 0) {
893  $imagepath_original = str_replace("/$this->obj_id/", "/$objectId/", $imagepath_original);
894  }
895 
896  foreach ($this->answers as $answer) {
897  if ($answer->hasImage()) {
898  $filename = $answer->getImage();
899  if (!file_exists($imagepath)) {
900  ilFileUtils::makeDirParents($imagepath);
901  }
902  if (!@copy($imagepath_original . $filename, $imagepath . $filename)) {
903  $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
904  $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
905  }
906  if (@file_exists($imagepath_original . $this->getThumbPrefix() . $filename)) {
907  if (!@copy($imagepath_original . $this->getThumbPrefix() . $filename, $imagepath . $this->getThumbPrefix() . $filename)) {
908  $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
909  $ilLog->write("object: " . print_r($this, true), $ilLog->ERROR);
910  }
911  }
912  }
913  }
914  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: feed.php:28
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.
$filename
Definition: buildRTE.php:78
ILIAS DI LoggingServices $ilLog
+ Here is the call graph for this function:

◆ flushAnswers()

assSingleChoice::flushAnswers ( )

Deletes all answers.

public

See also
$answers

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

479  : void
480  {
481  $this->answers = [];
482  }

◆ getAdditionalTableName()

assSingleChoice::getAdditionalTableName ( )

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

Returns
string The additional table name public

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

Referenced by isComplete(), loadFromDb(), and savePreviewData().

814  : string
815  {
816  return "qpl_qst_sc";
817  }
+ Here is the caller graph for this function:

◆ getAnswer()

assSingleChoice::getAnswer (   $index = 0)

Returns an answer with a given index.

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

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

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

Referenced by getAvailableAnswerOptions().

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

◆ getAnswerCount()

assSingleChoice::getAnswerCount ( )

Returns the number of answers.

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

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

412  : int
413  {
414  return count($this->answers);
415  }

◆ getAnswers()

& assSingleChoice::getAnswers ( )

Returns a reference to the answers array.

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

References $answers.

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

1017  : array
1018  {
1019  return $this->answers;
1020  }
+ Here is the caller graph for this function:

◆ getAnswerTableName()

assSingleChoice::getAnswerTableName ( )

Returns the name of the answer table in the database.

Returns
string The answer table name public

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

825  : string
826  {
827  return "qpl_a_sc";
828  }

◆ 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

Implements iQuestionCondition.

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

References getAnswer(), and getAnswers().

1272  {
1273  if ($index !== null) {
1274  return $this->getAnswer($index);
1275  } else {
1276  return $this->getAnswers();
1277  }
1278  }
& getAnswers()
Returns a reference to the answers array.
getAnswer($index=0)
Returns an answer with a given index.
+ Here is the call graph for this function:

◆ getExpressionTypes()

◆ getFeedbackSetting()

assSingleChoice::getFeedbackSetting ( )

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

References $feedback_setting.

1307  : int
1308  {
1309  return $this->feedback_setting;
1310  }

◆ getMaximumPoints()

assSingleChoice::getMaximumPoints ( )

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

public

See also
$points

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

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

Referenced by getExpressionTypes(), and isComplete().

490  : float
491  {
492  $points = 0;
493  foreach ($this->answers as $key => $value) {
494  if ($value->getPoints() > $points) {
495  $points = $value->getPoints();
496  }
497  }
498  return $points;
499  }
float $points
The maximum available points for the question.
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the caller graph for this function:

◆ getMultilineAnswerSetting()

assSingleChoice::getMultilineAnswerSetting ( )

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

References $DIC.

1123  {
1124  global $DIC;
1125  $ilUser = $DIC['ilUser'];
1126 
1127  $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
1128  if ($multilineAnswerSetting != 1) {
1129  $multilineAnswerSetting = 0;
1130  }
1131  return $multilineAnswerSetting;
1132  }
global $DIC
Definition: feed.php:28

◆ getOperators()

assSingleChoice::getOperators (   $expression)

Get all available operations for a specific question.

Parameters
string$expression

Implements iQuestionCondition.

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

References ilOperatorsExpressionMapping\getOperatorsByExpression().

1201  : array
1202  {
1204  }
+ 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 public

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

Referenced by toJSON().

803  : string
804  {
805  return "assSingleChoice";
806  }
+ Here is the caller graph for this function:

◆ getRTETextWithMediaObjects()

assSingleChoice::getRTETextWithMediaObjects ( )

Collects all text in the question which could contain media objects which were created with the Rich Text Editor.

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

References assQuestion\getId().

1003  : string
1004  {
1005  $text = parent::getRTETextWithMediaObjects();
1006  foreach ($this->answers as $index => $answer) {
1007  $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->getId(), 0, $index);
1008  $answer_obj = $this->answers[$index];
1009  $text .= $answer_obj->getAnswertext();
1010  }
1011  return $text;
1012  }
+ Here is the call graph for this function:

◆ getSpecificFeedbackAllCorrectOptionLabel()

assSingleChoice::getSpecificFeedbackAllCorrectOptionLabel ( )

Implements ilAssSpecificFeedbackOptionLabelProvider.

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

1173  : string
1174  {
1175  return 'feedback_correct_sc_mc';
1176  }

◆ getSpecificFeedbackSetting()

assSingleChoice::getSpecificFeedbackSetting ( )

Gets the current feedback settings in effect for the question.

Values are: 1 - Feedback is shown for all answer options. 2 - Feedback is shown for all checked/selected options. 3 - Feedback is shown for all correct options.

Returns
integer

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

References $feedback_setting.

1164  : int
1165  {
1166  if ($this->feedback_setting) {
1167  return $this->feedback_setting;
1168  } else {
1169  return 1;
1170  }
1171  }

◆ isComplete()

assSingleChoice::isComplete ( )

Returns true, if a single choice question is complete for use.

Returns
boolean True, if the single choice question is complete for use, otherwise false public

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

References $data, $DIC, $ilDB, assQuestion\$original_id, getAdditionalTableName(), assQuestion\getId(), getMaximumPoints(), assQuestion\getThumbSize(), isSingleline(), ilObjQuestionScoringAdjustable\saveAdditionalQuestionDataToDb(), ilObjAnswerScoringAdjustable\saveAnswerSpecificDataToDb(), assQuestion\saveQuestionDataToDb(), and assQuestion\saveToDb().

104  : bool
105  {
106  if ($this->title !== ''
107  && $this->author !== null && $this->author !== ''
108  && $this->question !== null && $this->question !== ''
109  && $this->answers !== []
110  && $this->getMaximumPoints() > 0) {
111  foreach ($this->answers as $answer) {
112  if ($answer->getAnswertext() === '' && !$answer->hasImage()) {
113  return false;
114  }
115  }
116  return true;
117  } else {
118  return false;
119  }
120  }
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
+ Here is the call graph for this function:

◆ isObligationPossible()

static assSingleChoice::isObligationPossible ( int  $questionId)
static

returns boolean wether it is possible to set this question type as obligatory or not considering the current question configuration

(overwrites method in class assQuestion)

Parameters
integer$questionId
Returns
boolean $obligationPossible

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

1188  : bool
1189  {
1190  return true;
1191  }

◆ isSingleline()

assSingleChoice::isSingleline ( )

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

References $isSingleline.

Referenced by isComplete(), loadFromDb(), savePreviewData(), setImageFile(), and setIsSingleline().

1297  : bool
1298  {
1299  return $this->isSingleline;
1300  }
+ Here is the caller graph for this function:

◆ lmMigrateQuestionTypeSpecificContent()

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

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

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

1058  : void
1059  {
1060  foreach ($this->getAnswers() as $answer) {
1061  /* @var ASS_AnswerBinaryStateImage $answer */
1062  $answer->setAnswertext($migrator->migrateToLmContent($answer->getAnswertext()));
1063  }
1064  }
& getAnswers()
Returns a reference to the answers array.
+ Here is the call graph for this function:

◆ loadFromDb()

assSingleChoice::loadFromDb (   $question_id)

Loads a assSingleChoice object from a database.

Parameters
object$dbA pear DB object
integer$question_idA unique key which defines the multiple choice test in the database public

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

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

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

◆ removeAnswerImage()

assSingleChoice::removeAnswerImage (   $index)

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

References deleteImage().

1113  : void
1114  {
1115  $answer = $this->answers[$index];
1116  if (is_object($answer)) {
1117  $this->deleteImage($answer->getImage());
1118  $answer->setImage(null);
1119  }
1120  }
deleteImage($image_filename)
Deletes an image file.
+ Here is the call graph for this function:

◆ savePreviewData()

assSingleChoice::savePreviewData ( ilAssQuestionPreviewSession  $previewSession)
protected

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

References $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, ilRTE\_replaceMediaObjectImageSrc(), ilFileUtils\delDir(), assQuestion\getAdditionalContentEditingMode(), getAdditionalTableName(), assQuestion\getId(), assQuestion\getImagePath(), assQuestion\getShuffle(), assQuestion\getThumbSize(), ILIAS\FileDelivery\http(), isSingleline(), ILIAS\Repository\refinery(), ilObjQuestionScoringAdjustable\saveAdditionalQuestionDataToDb(), ilObjAnswerScoringAdjustable\saveAnswerSpecificDataToDb(), and ilAssQuestionPreviewSession\setParticipantsSolution().

627  : void
628  {
629  $mc_result_key = 'multiple_choice_result' . $this->getId() . 'ID';
630  if (
631  $this->http->wrapper()->post()->has($mc_result_key) &&
632  ($mc_result = $this->http->wrapper()->post()->retrieve($mc_result_key, $this->refinery->kindlyTo()->string())) !== ''
633  ) {
634  $previewSession->setParticipantsSolution($mc_result);
635  } else {
636  $previewSession->setParticipantsSolution(null);
637  }
638  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ saveWorkingData()

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

Saves the learners input of the question to the database.

public

Parameters
integer$active_idActive id of the user
integer$passTest pass
Returns
boolean $status

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

References $DIC, $ilDB, ilObjAssessmentFolder\_enabledAssessmentLogging(), ilObjAssessmentFolder\_getLogLanguage(), ilObjTest\_getPass(), assQuestion\getCurrentSolutionResultSet(), assQuestion\getId(), assQuestion\getProcessLocker(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), assQuestion\logAction(), ILIAS\Repository\refinery(), assQuestion\removeSolutionRecordById(), assQuestion\saveCurrentSolution(), and assQuestion\updateCurrentSolution().

566  : bool
567  {
568  global $DIC;
569  $ilDB = $DIC['ilDB'];
570  $ilUser = $DIC['ilUser'];
571 
572  if (is_null($pass)) {
573  $pass = ilObjTest::_getPass($active_id);
574  }
575 
576  $entered_values = 0;
577 
578  $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(function () use (&$entered_values, $ilDB, $active_id, $pass, $authorized) {
579  $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized);
580 
581  $update = -1;
582  if ($ilDB->numRows($result)) {
583  $row = $ilDB->fetchAssoc($result);
584  $update = $row["solution_id"];
585  }
586 
587  $multiple_choice_result = $this->http->wrapper()->post()->has('multiple_choice_result') ?
588  $this->http->wrapper()->post()->retrieve('multiple_choice_result', $this->refinery->kindlyTo()->string()) :
589  '';
590 
591  if ($update != -1) {
592  if ($multiple_choice_result !== '') {
593  $this->updateCurrentSolution($update, $multiple_choice_result, null, $authorized);
594  $entered_values++;
595  } else {
596  $this->removeSolutionRecordById($update);
597  }
598  } else {
599  if ($multiple_choice_result !== '') {
600  $this->saveCurrentSolution($active_id, $pass, $multiple_choice_result, null, $authorized);
601  $entered_values++;
602  }
603  }
604  });
605 
606  if ($entered_values) {
608  assQuestion::logAction($this->lng->txtlng(
609  "assessment",
610  "log_user_entered_values",
612  ), $active_id, $this->getId());
613  }
614  } else {
616  assQuestion::logAction($this->lng->txtlng(
617  "assessment",
618  "log_user_not_entered_values",
620  ), $active_id, $this->getId());
621  }
622  }
623 
624  return true;
625  }
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
updateCurrentSolution(int $solutionId, $value1, $value2, bool $authorized=true)
global $DIC
Definition: feed.php:28
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
static http()
Fetches the global http state from ILIAS.
static logAction(string $logtext, int $active_id, int $question_id)
removeSolutionRecordById(int $solutionId)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
+ Here is the call graph for this function:

◆ setAnswers()

assSingleChoice::setAnswers ( array  $answers)

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

References $answers.

1022  : void
1023  {
1024  $this->answers = $answers;
1025  }

◆ setExportDetailsXLSX()

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

{}

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

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

1030  : int
1031  {
1032  parent::setExportDetailsXLSX($worksheet, $startrow, $col, $active_id, $pass);
1033 
1034  $solution = $this->getSolutionValues($active_id, $pass);
1035  $i = 1;
1036  foreach ($this->getAnswers() as $id => $answer) {
1037  $worksheet->setCell($startrow + $i, $col, $answer->getAnswertext());
1038  $worksheet->setBold($worksheet->getColumnCoord($col) . ($startrow + $i));
1039  if (
1040  count($solution) > 0 &&
1041  isset($solution[0]) &&
1042  is_array($solution[0]) &&
1043  strlen($solution[0]['value1']) > 0 && $id == $solution[0]['value1']
1044  ) {
1045  $worksheet->setCell($startrow + $i, $col + 2, 1);
1046  } else {
1047  $worksheet->setCell($startrow + $i, $col + 2, 0);
1048  }
1049  $i++;
1050  }
1051 
1052  return $startrow + $i + 1;
1053  }
getSolutionValues($active_id, $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
& getAnswers()
Returns a reference to the answers array.
getColumnCoord(int $a_col)
Get column "name" from number.
setCell($a_row, $a_col, $a_value, $datatype=null)
setBold(string $a_coords)
Set cell(s) to bold.
+ Here is the call graph for this function:

◆ setFeedbackSetting()

assSingleChoice::setFeedbackSetting ( int  $feedback_setting)

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

References $feedback_setting.

1312  : void
1313  {
1314  $this->feedback_setting = $feedback_setting;
1315  }

◆ setImageFile()

assSingleChoice::setImageFile (   $image_filename,
  $image_tempfilename = "" 
)

Sets the image file and uploads the image to the object's image directory.

Parameters
string$image_filenameName of the original image file
string$image_tempfilenameName of the temporary uploaded image file
Returns
integer An errorcode if the image upload fails, 0 otherwise public

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

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

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

◆ setIsSingleline()

assSingleChoice::setIsSingleline ( bool  $isSingleline)

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

References $isSingleline, and isSingleline().

1302  : void
1303  {
1304  $this->isSingleline = $isSingleline;
1305  }
+ Here is the call graph for this function:

◆ setMultilineAnswerSetting()

assSingleChoice::setMultilineAnswerSetting (   $a_setting = 0)

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

References $DIC.

1134  : void
1135  {
1136  global $DIC;
1137  $ilUser = $DIC['ilUser'];
1138  $ilUser->writePref("tst_multiline_answers", (string) $a_setting);
1139  }
global $DIC
Definition: feed.php:28

◆ setSpecificFeedbackSetting()

assSingleChoice::setSpecificFeedbackSetting (   $a_feedback_setting)

Sets the feedback settings in effect for the question.

Options are: 1 - Feedback is shown for all answer options. 2 - Feedback is shown for all checked/selected options. 3 - Feedback is shown for all correct options.

Parameters
integer$a_feedback_setting

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

1150  : void
1151  {
1152  $this->feedback_setting = $a_feedback_setting;
1153  }

◆ syncImages()

assSingleChoice::syncImages ( )
protected

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

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

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

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

◆ toJSON()

assSingleChoice::toJSON ( )

Returns a JSON representation of the question.

Implements ilAssQuestionLMExportable.

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

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

1069  : string
1070  {
1071  $result = [];
1072  $result['id'] = $this->getId();
1073  $result['type'] = (string) $this->getQuestionType();
1074  $result['title'] = $this->getTitleForHTMLOutput();
1075  $result['question'] = $this->formatSAQuestion($this->getQuestion());
1076  $result['nr_of_tries'] = $this->getNrOfTries();
1077  $result['shuffle'] = $this->getShuffle();
1078 
1079  $result['feedback'] = [
1080  'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1081  'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1082  ];
1083 
1084  $answers = [];
1085  $has_image = false;
1086  foreach ($this->getAnswers() as $key => $answer_obj) {
1087  if ((string) $answer_obj->getImage()) {
1088  $has_image = true;
1089  }
1090  array_push($answers, [
1091  "answertext" => $this->formatSAQuestion($answer_obj->getAnswertext()),
1092  'html_id' => $this->getId() . '_' . $key,
1093  "points" => (float) $answer_obj->getPoints(),
1094  "order" => (int) $answer_obj->getOrder(),
1095  "image" => (string) $answer_obj->getImage(),
1096  "feedback" => $this->formatSAQuestion(
1097  $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), 0, $key)
1098  )
1099  ]);
1100  }
1101  $result['answers'] = $answers;
1102  if ($has_image) {
1103  $result['path'] = $this->getImagePathWeb();
1104  $result['thumb'] = $this->getThumbSize();
1105  }
1106 
1107  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1108  $result['mobs'] = $mobs;
1109 
1110  return json_encode($result);
1111  }
& getAnswers()
Returns a reference to the answers array.
getQuestionType()
Returns the question type of the question.
getImagePathWeb()
Returns the web image path for web accessable images of a question.
string $key
Consumer key/client ID value.
Definition: System.php:193
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
+ Here is the call graph for this function:

Field Documentation

◆ $answers

assSingleChoice::$answers

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

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

◆ $feedback_setting

assSingleChoice::$feedback_setting
protected

◆ $isSingleline

bool assSingleChoice::$isSingleline = true
private

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

Referenced by isSingleline(), and setIsSingleline().

◆ $output_type

assSingleChoice::$output_type

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

Referenced by __construct().


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