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

Class for error text questions. More...

+ Inheritance diagram for assErrorText:
+ Collaboration diagram for assErrorText:

Public Member Functions

 __construct (string $title='', string $comment='', string $author='', int $owner=-1, string $question='')
 
 isComplete ()
 
 saveToDb (?int $original_id=null)
 
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
 saveAdditionalQuestionDataToDb ()
 Saves the data for the additional data table. More...
 
 loadFromDb ($question_id)
 Loads the object from the database. 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)
 
 savePreviewData (ilAssQuestionPreviewSession $previewSession)
 
 getQuestionType ()
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 setErrorsFromParsedErrorText ()
 
 setErrorData (array $errors)
 
 removeErrorDataWithoutPosition ()
 
 assembleErrorTextOutput (array $selections, bool $graphical_output=false, bool $show_correct_solution=false, bool $use_link_tags=true, array $correctness_icons=[])
 
 createErrorTextExport (array $selections)
 
 getBestSelection (bool $with_positive_points_only=true)
 
 flushErrorData ()
 
 getErrorData ()
 
 getErrorText ()
 
 setErrorText (?string $text)
 
 getParsedErrorText ()
 
 setParsedErrorText (array $parsed_errortext)
 
 getTextSize ()
 
 setTextSize ($a_value)
 
 getPointsWrong ()
 
 setPointsWrong ($a_value)
 
 toJSON ()
 
 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...
 
 parseErrorText ()
 
 getAvailableAnswerOptions ($index=null)
 If index is null, the function returns an array with all anwser options Else it returns the specific answer option. More...
 
 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...
 
 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...
 
 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...
 

Protected Member Functions

 getPointsForSelectedPositions (array $selected_word_positions)
 
 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 ERROR_TYPE_WORD = 1
 
const ERROR_TYPE_PASSAGE = 2
 
const DEFAULT_TEXT_SIZE = 100.0
 
const ERROR_MAX_LENGTH = 150
 
const PARAGRAPH_SPLIT_REGEXP = '/[\n\r]+/'
 
const WORD_SPLIT_REGEXP = '/\s+/'
 
const FIND_PUNCTUATION_REGEXP = '/\p{P}/'
 
const ERROR_WORD_MARKER = '#'
 
const ERROR_PARAGRAPH_DELIMITERS
 
string $errortext = ''
 
array $parsed_errortext = []
 
array $errordata = []
 
float $textsize
 
float $points_wrong = null
 
- Protected Attributes inherited from assQuestion
const HAS_SPECIFIC_FEEDBACK = true
 
GeneralQuestionPropertiesRepository $questionrepository
 
RequestDataCollector $questionpool_request
 
QuestionFiles $question_files
 
ilAssQuestionProcessLocker $processLocker
 
ilTestQuestionConfig $testQuestionConfig
 
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo
 
ILIAS $ilias
 
ilGlobalPageTemplate $tpl
 
ilLanguage $lng
 
ilDBInterface $db
 
ilObjUser $current_user
 
SkillUsageService $skillUsageService
 
HTTPServices $http
 
Refinery $refinery
 
Transformation $shuffler
 
LoggingServices $log
 
Container $dic
 
ilAssQuestionLifecycle $lifecycle
 
ilAssQuestionPage $page
 
TestResultRepository $test_result_repository
 
int $id
 
string $title
 
string $comment
 
int $owner
 
string $author
 
int $thumb_size
 
string $question
 
float $points = 0.0
 
bool $shuffle = true
 
int $test_id
 
int $obj_id = 0
 
int $original_id = null
 
int $lastChange = null
 
string $external_id = null
 
int $step = null
 
array $suggested_solutions
 

Private Member Functions

 correctDataAfterParserUpdate ()
 
 getAnswersFromRequest ()
 
 addPositionToErrorAnswer (assAnswerErrorText $error)
 
 completeParsedErrorTextFromErrorData ()
 
 getAdditionalInformationFromExistingErrorDataByErrorText (array $current_error_data, string $text_wrong)
 
 generateOutputStringFromPosition (int $position, array $selections, array $paragraph, bool $graphical_output, bool $show_correct_solution, bool $use_link_tags, array $correctness_icons)
 
 getTextForPosition (int $position, array $paragraph, bool $show_correct_solution)
 
 getClassForPosition (int $position, bool $show_correct_solution, array $selections)
 
 getCorrectnessIconForPosition (int $position, bool $graphical_output, array $selections, array $correctness_icons)
 
 getErrorDataAsArrayForJS ()
 
 getParsedErrorTextForJS ()
 
 addErrorInformationToTextParagraphArray (array $paragraph, int $offset)
 
 parsePassageEndWord (string $word)
 
 generateArrayByPositionFromErrorData ()
 
 getErrorTokenHtml ($item, $class, $useLinkTags)
 

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...
 
- 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 = "?"
 
- 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 error text 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
Grégory Saive gsaiv.nosp@m.e@da.nosp@m.tabay.nosp@m..de
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

assErrorText::__construct ( string  $title = '',
string  $comment = '',
string  $author = '',
int  $owner = -1,
string  $question = '' 
)

Member Function Documentation

◆ addErrorInformationToTextParagraphArray()

assErrorText::addErrorInformationToTextParagraphArray ( array  $paragraph,
int  $offset 
)
private
Parameters
list<string>$paragraph
Returns
array<string|array>

Definition at line 819 of file class.assErrorText.php.

819 : array
820 {
821 $paragraph_with_error_info = [];
822 $passage_start = null;
823 foreach ($paragraph as $position => $word) {
824 $actual_position = $position + $offset;
825 if ($passage_start !== null
826 && (mb_strrpos($word, self::ERROR_PARAGRAPH_DELIMITERS['end']) === mb_strlen($word) - 2
827 || mb_strrpos($word, self::ERROR_PARAGRAPH_DELIMITERS['end']) === mb_strlen($word) - 3
828 && preg_match(self::FIND_PUNCTUATION_REGEXP, mb_substr($word, -1)) === 1)) {
829 $actual_word = $this->parsePassageEndWord($word);
830
831 $paragraph_with_error_info[$passage_start]['text_wrong'] .=
832 ' ' . $actual_word;
833 $paragraph_with_error_info[$actual_position] = [
834 'text' => $actual_word,
835 'error_type' => 'passage_end'
836 ];
837 $passage_start = null;
838 continue;
839 }
840 if ($passage_start !== null) {
841 $paragraph_with_error_info[$passage_start]['text_wrong'] .= ' ' . $word;
842 $paragraph_with_error_info[$actual_position] = [
843 'text' => $word,
844 'error_type' => 'in_passage'
845 ];
846 continue;
847 }
848 if (mb_strpos($word, self::ERROR_PARAGRAPH_DELIMITERS['start']) === 0) {
849 $paragraph_with_error_info[$actual_position] = [
850 'text' => substr($word, 2),
851 'text_wrong' => substr($word, 2),
852 'error_type' => 'passage_start',
853 'error_position' => $actual_position,
854 ];
855 $passage_start = $actual_position;
856 continue;
857 }
858 if (mb_strpos($word, self::ERROR_WORD_MARKER) === 0) {
859 $paragraph_with_error_info[$actual_position] = [
860 'text' => substr($word, 1),
861 'text_wrong' => substr($word, 1),
862 'error_type' => 'word',
863 'error_position' => $actual_position,
864 ];
865 continue;
866 }
867
868 $paragraph_with_error_info[$actual_position] = [
869 'text' => $word,
870 'error_type' => 'none',
871 'points' => $this->getPointsWrong()
872 ];
873 }
874
875 return $paragraph_with_error_info;
876 }
parsePassageEndWord(string $word)

◆ addPositionToErrorAnswer()

assErrorText::addPositionToErrorAnswer ( assAnswerErrorText  $error)
private

Definition at line 361 of file class.assErrorText.php.

362 {
363 foreach ($this->getParsedErrorText() as $paragraph) {
364 foreach ($paragraph as $position => $word) {
365 if (isset($word['text_wrong'])
366 && ($word['text_wrong'] === $error->getTextWrong()
367 || mb_substr($word['text_wrong'], 0, -1) === $error->getTextWrong()
368 && preg_match(self::FIND_PUNCTUATION_REGEXP, mb_substr($word['text_wrong'], -1)) === 1)
369 && !array_key_exists($position, $this->generateArrayByPositionFromErrorData())
370 ) {
371 return $error->withPosition($position);
372 }
373 }
374 }
375
376 return $error;
377 }
Class for error text answers.
generateArrayByPositionFromErrorData()

References assAnswerErrorText\getTextWrong(), and assAnswerErrorText\withPosition().

Referenced by correctDataAfterParserUpdate().

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

◆ assembleErrorTextOutput()

assErrorText::assembleErrorTextOutput ( array  $selections,
bool  $graphical_output = false,
bool  $show_correct_solution = false,
bool  $use_link_tags = true,
array  $correctness_icons = [] 
)

Definition at line 444 of file class.assErrorText.php.

450 : string {
451 $output_array = [];
452 foreach ($this->getParsedErrorText() as $paragraph) {
453 $array_reduce_function = fn(?string $carry, int $position)
454 => $carry . $this->generateOutputStringFromPosition(
455 $position,
456 $selections,
457 $paragraph,
458 $graphical_output,
459 $show_correct_solution,
460 $use_link_tags,
461 $correctness_icons
462 );
463 $output_array[] = '<p>' . trim(array_reduce(array_keys($paragraph), $array_reduce_function)) . '</p>';
464 }
465
466 return implode("\n", $output_array);
467 }
generateOutputStringFromPosition(int $position, array $selections, array $paragraph, bool $graphical_output, bool $show_correct_solution, bool $use_link_tags, array $correctness_icons)

◆ calculateReachedPoints()

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

Reimplemented from assQuestion.

Definition at line 252 of file class.assErrorText.php.

256 : float {
257 if ($pass === null) {
258 $pass = $this->getSolutionMaxPass($active_id);
259 }
260 $result = $this->getCurrentSolutionResultSet($active_id, $pass, $authorized_solution);
261
262 $positions = [];
263 while ($row = $this->db->fetchAssoc($result)) {
264 $positions[] = $row['value1'];
265 }
266 $points = $this->getPointsForSelectedPositions($positions);
267 return $points;
268 }
getPointsForSelectedPositions(array $selected_word_positions)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getSolutionMaxPass(int $active_id)

References assQuestion\getSolutionMaxPass().

+ Here is the call graph for this function:

◆ calculateReachedPointsFromPreviewSession()

assErrorText::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $preview_session)

Reimplemented from assQuestion.

Definition at line 270 of file class.assErrorText.php.

271 {
272 $reached_points = $this->getPointsForSelectedPositions($preview_session->getParticipantsSolution() ?? []);
273 return $this->ensureNonNegativePoints($reached_points);
274 }
ensureNonNegativePoints(float $points)

References ilAssQuestionPreviewSession\getParticipantsSolution().

+ Here is the call graph for this function:

◆ completeParsedErrorTextFromErrorData()

assErrorText::completeParsedErrorTextFromErrorData ( )
private

Definition at line 379 of file class.assErrorText.php.

379 : void
380 {
381 foreach ($this->errordata as $error) {
382 $position = $error->getPosition();
383 if ($position === null) {
384 continue;
385 }
386
387 foreach ($this->getParsedErrorText() as $key => $paragraph) {
388 if (array_key_exists($position, $paragraph)) {
389 $this->parsed_errortext[$key][$position]['text_correct'] =
390 $error->getTextCorrect();
391 $this->parsed_errortext[$key][$position]['points'] =
392 $error->getPoints();
393 break;
394 }
395 }
396 }
397 }

Referenced by correctDataAfterParserUpdate().

+ Here is the caller graph for this function:

◆ correctDataAfterParserUpdate()

assErrorText::correctDataAfterParserUpdate ( )
private

Definition at line 211 of file class.assErrorText.php.

211 : void
212 {
213 if ($this->getErrorText() === '') {
214 return;
215 }
216 $needs_finalizing = false;
217 if ($this->getParsedErrorText() === []) {
218 $needs_finalizing = true;
219 $this->parseErrorText();
220 }
221
222 if (isset($this->errordata[0])
223 && $this->errordata[0]->getPosition() === null) {
224 foreach ($this->errordata as $key => $error) {
225 $this->errordata[$key] = $this->addPositionToErrorAnswer($error);
226 }
228 }
229
230 if ($needs_finalizing) {
233 }
234 }
completeParsedErrorTextFromErrorData()
addPositionToErrorAnswer(assAnswerErrorText $error)
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveAdditionalQuestionDataToDb()
Saves the data for the additional data table.

References addPositionToErrorAnswer(), completeParsedErrorTextFromErrorData(), getErrorText(), getParsedErrorText(), parseErrorText(), saveAdditionalQuestionDataToDb(), and saveAnswerSpecificDataToDb().

Referenced by loadFromDb().

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

◆ createErrorTextExport()

assErrorText::createErrorTextExport ( array  $selections)

Definition at line 551 of file class.assErrorText.php.

551 : string
552 {
553 if (!is_array($selections)) {
554 $selections = [];
555 }
556
557 foreach ($this->getParsedErrorText() as $paragraph) {
558 $array_reduce_function = function ($carry, $k) use ($paragraph, $selections) {
559 $text = $paragraph[$k]['text'];
560 if (in_array($k, $selections)) {
561 $text = self::ERROR_WORD_MARKER . $paragraph[$k]['text'] . self::ERROR_WORD_MARKER;
562 }
563 return $carry . ' ' . $text;
564 };
565 $output_array[] = trim(array_reduce(array_keys($paragraph), $array_reduce_function));
566 }
567 return implode("\n", $output_array);
568 }
$text
Definition: xapiexit.php:21

References $text.

◆ flushErrorData()

assErrorText::flushErrorData ( )

Definition at line 638 of file class.assErrorText.php.

638 : void
639 {
640 $this->errordata = [];
641 }

◆ fromNormalized()

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

Reimplemented from assQuestion.

Definition at line 1023 of file class.assErrorText.php.

1026 : static
1027 {
1028 $clone = parent::fromNormalized($normalized, $transformations);
1029 $clone->errortext = $transformations->string($normalized['errortext']);
1030 $clone->parsed_errortext = $normalized['errortext_parsed'];
1031 $clone->points_wrong = $transformations->nullableFloat($normalized['points_wrong']);
1032 $clone->errordata = array_map(
1033 fn(array $error) => $transformations->denormalize($error, new assAnswerErrorText()),
1034 $normalized['errordata']
1035 );
1036
1037 return $clone;
1038 }
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)

References ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\denormalize(), ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\nullableFloat(), and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\string().

+ Here is the call graph for this function:

◆ generateArrayByPositionFromErrorData()

assErrorText::generateArrayByPositionFromErrorData ( )
private

Definition at line 911 of file class.assErrorText.php.

911 : array
912 {
913 $array_by_position = [];
914 foreach ($this->errordata as $error) {
915 $position = $error->getPosition();
916 if ($position === null) {
917 continue;
918 }
919 $array_by_position[$position] = [
920 'length' => $error->getLength(),
921 'points' => $error->getPoints(),
922 'text' => $error->getTextWrong(),
923 'text_correct' => $error->getTextCorrect()
924 ];
925 }
926 ksort($array_by_position);
927 return $array_by_position;
928 }

◆ generateOutputStringFromPosition()

assErrorText::generateOutputStringFromPosition ( int  $position,
array  $selections,
array  $paragraph,
bool  $graphical_output,
bool  $show_correct_solution,
bool  $use_link_tags,
array  $correctness_icons 
)
private

Definition at line 469 of file class.assErrorText.php.

477 : string {
478 $text = $this->getTextForPosition($position, $paragraph, $show_correct_solution);
479 if ($text === '') {
480 return '';
481 }
482 $class = $this->getClassForPosition($position, $show_correct_solution, $selections);
483 $img = $this->getCorrectnessIconForPosition(
484 $position,
485 $graphical_output,
486 $selections,
487 $correctness_icons
488 );
489
490 return ' ' . $this->getErrorTokenHtml($text, $class, $use_link_tags) . $img;
491 }
getClassForPosition(int $position, bool $show_correct_solution, array $selections)
getTextForPosition(int $position, array $paragraph, bool $show_correct_solution)
getErrorTokenHtml($item, $class, $useLinkTags)
getCorrectnessIconForPosition(int $position, bool $graphical_output, array $selections, array $correctness_icons)

◆ getAdditionalInformationFromExistingErrorDataByErrorText()

assErrorText::getAdditionalInformationFromExistingErrorDataByErrorText ( array  $current_error_data,
string  $text_wrong 
)
private
Parameters
array<assAnswerErrorText>$current_error_data
Returns
array<mixed>

Definition at line 429 of file class.assErrorText.php.

432 : array {
433 foreach ($current_error_data as $answer_object) {
434 if (strcmp($answer_object->getTextWrong(), $text_wrong) === 0) {
435 return[
436 $answer_object->getTextCorrect(),
437 $answer_object->getPoints()
438 ];
439 }
440 }
441 return ['', 0.0];
442 }

◆ getAdditionalTableName()

assErrorText::getAdditionalTableName ( )

Reimplemented from assQuestion.

Definition at line 317 of file class.assErrorText.php.

317 : string
318 {
319 return 'qpl_qst_errortext';
320 }

Referenced by loadFromDb(), and saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getAnswersFromRequest()

assErrorText::getAnswersFromRequest ( )
private

Definition at line 304 of file class.assErrorText.php.

304 : array
305 {
306 return explode(
307 ',',
308 $this->questionpool_request->string('qst_' . $this->getId())
309 );
310 }

◆ getAnswerTableName()

assErrorText::getAnswerTableName ( )

Reimplemented from assQuestion.

Definition at line 322 of file class.assErrorText.php.

322 : string
323 {
324 return 'qpl_a_errortext';
325 }

◆ getAvailableAnswerOptions()

assErrorText::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 893 of file class.assErrorText.php.

893 : ?int
894 {
895 $error_text_array = array_reduce(
896 $this->parsed_errortext,
897 fn($c, $v) => $c + $v
898 );
899
900 if ($index === null) {
901 return $error_text_array;
902 }
903
904 if (array_key_exists($index, $error_text_array)) {
905 return $error_text_array[$index];
906 }
907
908 return null;
909 }

References Vendor\Package\$c.

◆ getBestSelection()

assErrorText::getBestSelection ( bool  $with_positive_points_only = true)

Definition at line 570 of file class.assErrorText.php.

570 : array
571 {
572 $positions_array = $this->generateArrayByPositionFromErrorData();
573 $selections = [];
574 foreach ($positions_array as $position => $position_data) {
575 if ($position === ''
576 || $with_positive_points_only && $position_data['points'] <= 0) {
577 continue;
578 }
579
580 $selections[] = $position;
581 if ($position_data['length'] > 1) {
582 for ($i = 1;$i < $position_data['length'];$i++) {
583 $selections[] = $position + $i;
584 }
585 }
586 }
587
588 return $selections;
589 }

◆ getClassForPosition()

assErrorText::getClassForPosition ( int  $position,
bool  $show_correct_solution,
array  $selections 
)
private

Definition at line 513 of file class.assErrorText.php.

517 : string {
518 if ($show_correct_solution !== true
519 && in_array($position, $selections['user'])) {
520 return 'ilc_qetitem_ErrorTextSelected';
521 }
522
523 if ($show_correct_solution === true
524 && in_array($position, $selections['best'])) {
525 return 'ilc_qetitem_ErrorTextSelected';
526 }
527
528 return 'ilc_qetitem_ErrorTextItem';
529 }

◆ getCorrectnessIconForPosition()

assErrorText::getCorrectnessIconForPosition ( int  $position,
bool  $graphical_output,
array  $selections,
array  $correctness_icons 
)
private

Definition at line 531 of file class.assErrorText.php.

536 : string {
537 if ($graphical_output === true
538 && (in_array($position, $selections['user']) && !in_array($position, $selections['best'])
539 || !in_array($position, $selections['user']) && in_array($position, $selections['best']))) {
540 return $correctness_icons['not_correct'];
541 }
542
543 if ($graphical_output === true
544 && in_array($position, $selections['user']) && in_array($position, $selections['best'])) {
545 return $correctness_icons['correct'];
546 }
547
548 return '';
549 }

◆ getCorrectSolutionForTextOutput()

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

Reimplemented from assQuestion.

Definition at line 1002 of file class.assErrorText.php.

1002 : string
1003 {
1004 return $this->createErrorTextExport($this->getBestSelection());
1005 }
createErrorTextExport(array $selections)
getBestSelection(bool $with_positive_points_only=true)

◆ getErrorData()

assErrorText::getErrorData ( )
Returns
array<assAnswerErrorText>

Definition at line 647 of file class.assErrorText.php.

647 : array
648 {
649 return $this->errordata;
650 }

◆ getErrorDataAsArrayForJS()

assErrorText::getErrorDataAsArrayForJS ( )
private
Returns
array<mixed>

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

656 : array
657 {
658 $correct_answers = [];
659 foreach ($this->getErrorData() as $index => $answer_obj) {
660 $correct_answers[] = [
661 'answertext_wrong' => $answer_obj->getTextWrong(),
662 'answertext_correct' => $answer_obj->getTextCorrect(),
663 'points' => $answer_obj->getPoints(),
664 'length' => $answer_obj->getLength(),
665 'pos' => $this->getId() . '_' . $answer_obj->getPosition()
666 ];
667 }
668 return $correct_answers;
669 }

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ getErrorText()

assErrorText::getErrorText ( )

Definition at line 671 of file class.assErrorText.php.

671 : string
672 {
673 return $this->errortext ?? '';
674 }

Referenced by correctDataAfterParserUpdate(), and saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getErrorTokenHtml()

assErrorText::getErrorTokenHtml (   $item,
  $class,
  $useLinkTags 
)
private
Parameters
$item
$class
Returns
string

Definition at line 935 of file class.assErrorText.php.

935 : string
936 {
937 if ($useLinkTags) {
938 return '<a class="' . $class . '" href="#">' . ($item == '&nbsp;' ? $item : ilLegacyFormElementsUtil::prepareFormOutput(
939 $item
940 )) . '</a>';
941 }
942
943 return '<span class="' . $class . '">' . ($item == '&nbsp;' ? $item : ilLegacyFormElementsUtil::prepareFormOutput(
944 $item
945 )) . '</span>';
946 }
static prepareFormOutput($a_str, bool $a_strip=false)

References ilLegacyFormElementsUtil\prepareFormOutput().

+ Here is the call graph for this function:

◆ getExpressionTypes()

◆ getMaximumPoints()

assErrorText::getMaximumPoints ( )

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

See also
$points

Reimplemented from assQuestion.

Definition at line 241 of file class.assErrorText.php.

241 : float
242 {
243 $maxpoints = 0.0;
244 foreach ($this->errordata as $error) {
245 if ($error->getPoints() > 0) {
246 $maxpoints += $error->getPoints();
247 }
248 }
249 return $maxpoints;
250 }

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getOperators()

assErrorText::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

Definition at line 758 of file class.assErrorText.php.

758 : array
759 {
761 }
static getOperatorsByExpression(string $expression)

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ Here is the call graph for this function:

◆ getParsedErrorText()

assErrorText::getParsedErrorText ( )

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

681 : array
682 {
684 }

Referenced by correctDataAfterParserUpdate(), and saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getParsedErrorTextForJS()

assErrorText::getParsedErrorTextForJS ( )
private

Definition at line 686 of file class.assErrorText.php.

686 : array
687 {
688 $answers = [];
689 foreach ($this->parsed_errortext as $paragraph) {
690 foreach ($paragraph as $position => $word) {
691 $answers[] = [
692 'answertext' => $word['text'],
693 'order' => $this->getId() . '_' . $position
694 ];
695 }
696 $answers[] = [
697 'answertext' => '###'
698 ];
699 }
700 array_pop($answers);
701
702 return $answers;
703 }

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ getPointsForSelectedPositions()

assErrorText::getPointsForSelectedPositions ( array  $selected_word_positions)
protected
Parameters
list<string>|null$selected_words Positions of Selected Words Counting from 0

Definition at line 595 of file class.assErrorText.php.

595 : float
596 {
597 $points = 0;
598 $correct_positions = $this->generateArrayByPositionFromErrorData();
599
600 foreach ($correct_positions as $correct_position => $correct_position_data) {
601 $selected_word_key = array_search($correct_position, $selected_word_positions);
602 if ($selected_word_key === false) {
603 continue;
604 }
605
606 if ($correct_position_data['length'] === 1) {
607 $points += $correct_position_data['points'];
608 unset($selected_word_positions[$selected_word_key]);
609 continue;
610 }
611
612 $passage_complete = true;
613 for ($i = 1;$i < $correct_position_data['length'];$i++) {
614 $selected_passage_element_key = array_search($correct_position + $i, $selected_word_positions);
615 if ($selected_passage_element_key === false) {
616 $passage_complete = false;
617 continue;
618 }
619 unset($selected_word_positions[$selected_passage_element_key]);
620 }
621
622 if ($passage_complete) {
623 $points += $correct_position_data['points'];
624 unset($selected_word_positions[$selected_word_key]);
625 }
626 }
627
628 foreach ($selected_word_positions as $word_position) {
629 if (!array_key_exists($word_position, $correct_positions)) {
630 $points += $this->getPointsWrong();
631 continue;
632 }
633 }
634
635 return $points;
636 }

◆ getPointsWrong()

assErrorText::getPointsWrong ( )

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

724 : ?float
725 {
726 return $this->points_wrong;
727 }

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getQuestionType()

assErrorText::getQuestionType ( )

Reimplemented from assQuestion.

Definition at line 312 of file class.assErrorText.php.

312 : string
313 {
314 return 'assErrorText';
315 }

◆ getTextForPosition()

assErrorText::getTextForPosition ( int  $position,
array  $paragraph,
bool  $show_correct_solution 
)
private

Definition at line 493 of file class.assErrorText.php.

497 : string {
498 $v = $paragraph[$position];
499 if ($show_correct_solution === true
500 && ($v['error_type'] === 'in_passage'
501 || $v['error_type'] === 'passage_end')) {
502 return '';
503 }
504 if ($show_correct_solution
505 && ($v['error_type'] === 'passage_start'
506 || $v['error_type'] === 'word')) {
507 return $v['text_correct'] ?? '';
508 }
509
510 return $v['text'];
511 }

◆ getTextSize()

assErrorText::getTextSize ( )

Definition at line 710 of file class.assErrorText.php.

710 : float
711 {
712 return $this->textsize;
713 }

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getUserQuestionResult()

assErrorText::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 773 of file class.assErrorText.php.

777 $result = new ilUserQuestionResult($this, $active_id, $pass);
778
779 $data = $this->db->queryF(
780 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = (
781 SELECT MAX(step) FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s
782 )",
783 ["integer", "integer", "integer","integer", "integer", "integer"],
784 [$active_id, $pass, $this->getId(), $active_id, $pass, $this->getId()]
785 );
786
787 while ($row = $this->db->fetchAssoc($data)) {
788 $result->addKeyValue($row["value1"], $row["value1"]);
789 }
790
791 $points = $this->calculateReachedPoints($active_id, $pass);
792 $max_points = $this->getMaximumPoints();
793
794 $result->setReachedPercentage(($points / $max_points) * 100);
795
796 return $result;
797 }
calculateReachedPoints(int $active_id, ?int $pass=null, bool $authorized_solution=true)
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$data
Definition: storeScorm.php:45

◆ isComplete()

assErrorText::isComplete ( )

Reimplemented from assQuestion.

Definition at line 74 of file class.assErrorText.php.

74 : bool
75 {
76 if (mb_strlen($this->title)
77 && ($this->author)
78 && ($this->question)
79 && ($this->getMaximumPoints() > 0)) {
80 return true;
81 } else {
82 return false;
83 }
84 }

References getMaximumPoints().

+ Here is the call graph for this function:

◆ loadFromDb()

assErrorText::loadFromDb (   $question_id)

Loads the object from the database.

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

Definition at line 153 of file class.assErrorText.php.

153 : void
154 {
155 $db_question = $this->db->queryF(
156 "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",
157 ["integer"],
158 [$question_id]
159 );
160 if ($db_question->numRows() === 1) {
161 $data = $this->db->fetchAssoc($db_question);
162 $this->setId($question_id);
163 $this->setObjId($data["obj_fi"]);
164 $this->setTitle((string) $data["title"]);
165 $this->setComment((string) $data["description"]);
166 $this->setOriginalId($data["original_id"]);
167 $this->setNrOfTries($data['nr_of_tries']);
168 $this->setAuthor($data["author"]);
169 $this->setPoints($data["points"]);
170 $this->setOwner($data["owner"]);
171 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc((string) $data["question_text"], 1));
172 $this->setErrorText((string) $data["errortext"]);
173 $this->setParsedErrorText(json_decode($data['parsed_errortext'] ?? json_encode([]), true));
174 $this->setTextSize($data["textsize"]);
175 $this->setPointsWrong($data["points_wrong"]);
176
177 try {
178 $this->setLifecycle(new ilAssQuestionLifecycle($data['lifecycle']));
181 }
182
183 try {
184 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
186 }
187 }
188
189 $db_error_text = $this->db->queryF(
190 "SELECT * FROM qpl_a_errortext WHERE question_fi = %s ORDER BY sequence ASC",
191 ['integer'],
192 [$question_id]
193 );
194
195 if ($db_error_text->numRows() > 0) {
196 while ($data = $this->db->fetchAssoc($db_error_text)) {
197 $this->errordata[] = new assAnswerErrorText(
198 (string) $data['text_wrong'],
199 (string) $data['text_correct'],
200 (float) $data['points'],
201 $data['position']
202 );
203 }
204 }
205
207
208 parent::loadFromDb($question_id);
209 }
setParsedErrorText(array $parsed_errortext)
setPointsWrong($a_value)
setErrorText(?string $text)
setOriginalId(?int $original_id)
setId(int $id=-1)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setQuestion(string $question="")
setAuthor(string $author="")
setComment(string $comment="")
setObjId(int $obj_id=0)
setOwner(int $owner=-1)
setNrOfTries(int $a_nr_of_tries)
setLifecycle(ilAssQuestionLifecycle $lifecycle)
setTitle(string $title="")
setPoints(float $points)
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...

References $data, Vendor\Package\$e, ilRTE\_replaceMediaObjectImageSrc(), correctDataAfterParserUpdate(), getAdditionalTableName(), assQuestion\setAdditionalContentEditingMode(), assQuestion\setAuthor(), assQuestion\setComment(), setErrorText(), assQuestion\setId(), assQuestion\setLifecycle(), assQuestion\setNrOfTries(), assQuestion\setObjId(), assQuestion\setOriginalId(), assQuestion\setOwner(), setParsedErrorText(), assQuestion\setPoints(), setPointsWrong(), assQuestion\setQuestion(), setTextSize(), and assQuestion\setTitle().

+ Here is the call graph for this function:

◆ parseErrorText()

assErrorText::parseErrorText ( )

Definition at line 799 of file class.assErrorText.php.

799 : void
800 {
801 $text_by_paragraphs = preg_split(self::PARAGRAPH_SPLIT_REGEXP, $this->getErrorText());
802 $text_array = [];
803 $offset = 0;
804 foreach ($text_by_paragraphs as $paragraph) {
805 $text_array[] = $this->addErrorInformationToTextParagraphArray(
806 preg_split(self::WORD_SPLIT_REGEXP, trim($paragraph)),
807 $offset
808 );
809 $offset += count(end($text_array));
810 }
811 $this->setParsedErrorText($text_array);
812 }
addErrorInformationToTextParagraphArray(array $paragraph, int $offset)

Referenced by correctDataAfterParserUpdate().

+ Here is the caller graph for this function:

◆ parsePassageEndWord()

assErrorText::parsePassageEndWord ( string  $word)
private

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

878 : string
879 {
880 if (mb_substr($word, -2) === self::ERROR_PARAGRAPH_DELIMITERS['end']) {
881 return mb_substr($word, 0, -2);
882 }
883 return mb_substr($word, 0, -3) . mb_substr($word, -1);
884 }

◆ removeErrorDataWithoutPosition()

assErrorText::removeErrorDataWithoutPosition ( )

Definition at line 414 of file class.assErrorText.php.

414 : void
415 {
416 foreach ($this->getErrorData() as $index => $error) {
417 if ($error->getPosition() === null) {
418 unset($this->errordata[$index]);
419 }
420 }
421 $this->errordata = array_values($this->errordata);
422 }

◆ saveAdditionalQuestionDataToDb()

assErrorText::saveAdditionalQuestionDataToDb ( )

Saves the data for the additional data table.

This method uses the ugly DELETE-INSERT. Here, this does no harm.

Implements ilObjQuestionScoringAdjustable.

Definition at line 126 of file class.assErrorText.php.

127 {
128 $this->db->manipulateF(
129 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
130 ["integer"],
131 [$this->getId()]
132 );
133
134 $this->db->manipulateF(
135 "INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, errortext, parsed_errortext, textsize, points_wrong) VALUES (%s, %s, %s, %s, %s)",
136 ["integer", "text", "text", "float", "float"],
137 [
138 $this->getId(),
139 $this->getErrorText(),
140 json_encode($this->getParsedErrorText()),
141 $this->getTextSize(),
142 $this->getPointsWrong()
143 ]
144 );
145 }

References getAdditionalTableName(), getErrorText(), assQuestion\getId(), getParsedErrorText(), getPointsWrong(), and getTextSize().

Referenced by correctDataAfterParserUpdate(), and saveToDb().

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

◆ saveAnswerSpecificDataToDb()

assErrorText::saveAnswerSpecificDataToDb ( )

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

Returns
mixed

Implements ilObjAnswerScoringAdjustable.

Definition at line 94 of file class.assErrorText.php.

95 {
96 $this->db->manipulateF(
97 "DELETE FROM qpl_a_errortext WHERE question_fi = %s",
98 ['integer'],
99 [$this->getId()]
100 );
101
102 $sequence = 0;
103 foreach ($this->errordata as $error) {
104 $next_id = $this->db->nextId('qpl_a_errortext');
105 $this->db->manipulateF(
106 "INSERT INTO qpl_a_errortext (answer_id, question_fi, text_wrong, text_correct, points, sequence, position) VALUES (%s, %s, %s, %s, %s, %s, %s)",
107 ['integer', 'integer', 'text', 'text', 'float', 'integer', 'integer'],
108 [
109 $next_id,
110 $this->getId(),
111 $error->getTextWrong(),
112 $error->getTextCorrect(),
113 $error->getPoints(),
114 $sequence++,
115 $error->getPosition()
116 ]
117 );
118 }
119 }

References assQuestion\getId().

Referenced by correctDataAfterParserUpdate(), and saveToDb().

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

◆ savePreviewData()

assErrorText::savePreviewData ( ilAssQuestionPreviewSession  $previewSession)

Reimplemented from assQuestion.

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

298 : void
299 {
300 $selection = $this->getAnswersFromRequest();
301 $previewSession->setParticipantsSolution($selection);
302 }

References ilAssQuestionPreviewSession\setParticipantsSolution().

+ Here is the call graph for this function:

◆ saveToDb()

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

Reimplemented from assQuestion.

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

86 : void
87 {
91 parent::saveToDb();
92 }
saveQuestionDataToDb(?int $original_id=null)

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

+ Here is the call graph for this function:

◆ saveWorkingData()

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

Reimplemented from assQuestion.

Definition at line 276 of file class.assErrorText.php.

280 : bool {
281 if (is_null($pass)) {
282 $pass = ilObjTest::_getPass($active_id);
283 }
284
285 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
286 function () use ($active_id, $pass, $authorized) {
287 $selected = $this->getAnswersFromRequest();
288 $this->removeCurrentSolution($active_id, $pass, $authorized);
289 foreach ($selected as $position) {
290 $this->saveCurrentSolution($active_id, $pass, $position, null, $authorized);
291 }
292 }
293 );
294
295 return true;
296 }
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.

References ilObjTest\_getPass().

+ Here is the call graph for this function:

◆ setErrorData()

assErrorText::setErrorData ( array  $errors)
Parameters
array<assAnswerErrorText>$errors

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

403 : void
404 {
405 $this->errordata = [];
406
407 foreach ($errors as $error) {
408 $answer = $this->addPositionToErrorAnswer($error);
409 $this->errordata[] = $answer;
410 }
412 }

◆ setErrorsFromParsedErrorText()

assErrorText::setErrorsFromParsedErrorText ( )

Definition at line 327 of file class.assErrorText.php.

327 : void
328 {
329 $current_error_data = $this->getErrorData();
330 $this->errordata = [];
331
332 $has_too_long_errors = false;
333 foreach ($this->getParsedErrorText() as $paragraph) {
334 foreach ($paragraph as $position => $word) {
335 if ($word['error_type'] === 'in_passage'
336 || $word['error_type'] === 'passage_end'
337 || $word['error_type'] === 'none') {
338 continue;
339 }
340
341 $text_wrong = $word['text_wrong'];
342 if (mb_strlen($text_wrong) > self::ERROR_MAX_LENGTH) {
343 $has_too_long_errors = true;
344 continue;
345 }
346
347 list($text_correct, $points) =
348 $this->getAdditionalInformationFromExistingErrorDataByErrorText($current_error_data, $text_wrong);
349 $this->errordata[] = new assAnswerErrorText($text_wrong, $text_correct, $points, $position);
350 }
351 }
352
353 if ($has_too_long_errors) {
354 $this->tpl->setOnScreenMessage(
355 'failure',
356 $this->lng->txt('qst_error_text_too_long')
357 );
358 }
359 }
getAdditionalInformationFromExistingErrorDataByErrorText(array $current_error_data, string $text_wrong)

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ setErrorText()

assErrorText::setErrorText ( ?string  $text)

Definition at line 676 of file class.assErrorText.php.

676 : void
677 {
678 $this->errortext = $text ?? '';
679 }

References $text.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setParsedErrorText()

assErrorText::setParsedErrorText ( array  $parsed_errortext)

Definition at line 705 of file class.assErrorText.php.

705 : void
706 {
707 $this->parsed_errortext = $parsed_errortext;
708 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setPointsWrong()

assErrorText::setPointsWrong (   $a_value)

Definition at line 729 of file class.assErrorText.php.

729 : void
730 {
731 $this->points_wrong = $a_value;
732 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setTextSize()

assErrorText::setTextSize (   $a_value)

Definition at line 715 of file class.assErrorText.php.

715 : void
716 {
717 // in self-assesment-mode value should always be set (and must not be null)
718 if ($a_value === null) {
719 $a_value = 100;
720 }
721 $this->textsize = $a_value;
722 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ solutionValuesToLog()

assErrorText::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 980 of file class.assErrorText.php.

983 : string {
984 return $this->createErrorTextExport(
985 array_map(
986 static fn(array $v): string => $v['value1'],
987 $solution_values
988 )
989 );
990 }

◆ solutionValuesToText()

assErrorText::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 992 of file class.assErrorText.php.

992 : string
993 {
994 return $this->createErrorTextExport(
995 array_map(
996 static fn(array $v): string => $v['value1'],
997 $solution_values
998 )
999 );
1000 }

◆ toJSON()

assErrorText::toJSON ( )

Reimplemented from assQuestion.

Definition at line 734 of file class.assErrorText.php.

734 : string
735 {
736 $result = [];
737 $result['id'] = $this->getId();
738 $result['type'] = (string) $this->getQuestionType();
739 $result['title'] = $this->getTitleForHTMLOutput();
740 $result['question'] = $this->formatSAQuestion($this->getQuestion());
741 $result['text'] = ilRTE::_replaceMediaObjectImageSrc($this->getErrorText(), 0);
742 $result['nr_of_tries'] = $this->getNrOfTries();
743 $result['shuffle'] = $this->getShuffle();
744 $result['feedback'] = [
745 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
746 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
747 ];
748
749 $result['correct_answers'] = $this->getErrorDataAsArrayForJS();
750 $result['answers'] = $this->getParsedErrorTextForJS();
751
752 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
753 $result['mobs'] = $mobs;
754
755 return json_encode($result);
756 }
static _getMobsOfObject(string $a_type, int $a_id, int|false $a_usage_hist_nr=0, string $a_lang="-")

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

+ Here is the call graph for this function:

◆ toLog()

assErrorText::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 948 of file class.assErrorText.php.

948 : array
949 {
950 $result = [
951 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->getQuestionType(),
952 AdditionalInformationGenerator::KEY_QUESTION_TITLE => $this->getTitleForHTMLOutput(),
953 AdditionalInformationGenerator::KEY_QUESTION_TEXT => $this->formatSAQuestion($this->getQuestion()),
954 AdditionalInformationGenerator::KEY_QUESTION_ERRORTEXT_ERRORTEXT => ilRTE::_replaceMediaObjectImageSrc($this->getErrorText(), 0),
955 AdditionalInformationGenerator::KEY_QUESTION_SHUFFLE_ANSWER_OPTIONS => $additional_info
957 AdditionalInformationGenerator::KEY_FEEDBACK => [
958 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
959 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
960 ]
961 ];
962
963 $error_data = $this->getErrorData();
964 $result[AdditionalInformationGenerator::KEY_QUESTION_CORRECT_ANSWER_OPTIONS] = array_reduce(
965 array_keys($error_data),
966 static function (array $c, int $k) use ($error_data): array {
967 $c[$k + 1] = [
968 'text_wrong' => $error_data[$k]->getTextWrong(),
969 'text_correct' => $error_data[$k]->getTextCorrect(),
970 'points' => $error_data[$k]->getPoints()
971 ];
972 return $c;
973 },
974 []
975 );
976
977 return $result;
978 }

References Vendor\Package\$c, ilRTE\_replaceMediaObjectImageSrc(), and ILIAS\Test\Logging\AdditionalInformationGenerator\getTrueFalseTagForBool().

+ Here is the call graph for this function:

◆ toNormalized()

assErrorText::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 1008 of file class.assErrorText.php.

1011 : array|float|bool|int|string|null
1012 {
1013 return [
1014 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
1015 'errortext' => $this->errortext,
1016 'errortext_parsed' => $this->parsed_errortext,
1017 'errordata' => $transformations->normalize($this->errordata),
1018 'points_wrong' => $this->points_wrong,
1019 ];
1020 }

References ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\normalize().

+ Here is the call graph for this function:

Field Documentation

◆ $errordata

array< assAnswerErrorText > assErrorText::$errordata = []
protected

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

◆ $errortext

string assErrorText::$errortext = ''
protected

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

◆ $parsed_errortext

array assErrorText::$parsed_errortext = []
protected

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

◆ $points_wrong

float assErrorText::$points_wrong = null
protected

Definition at line 61 of file class.assErrorText.php.

◆ $textsize

float assErrorText::$textsize
protected

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

◆ DEFAULT_TEXT_SIZE

const assErrorText::DEFAULT_TEXT_SIZE = 100.0
protected

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

Referenced by __construct().

◆ ERROR_MAX_LENGTH

const assErrorText::ERROR_MAX_LENGTH = 150
protected

Definition at line 45 of file class.assErrorText.php.

◆ ERROR_PARAGRAPH_DELIMITERS

const assErrorText::ERROR_PARAGRAPH_DELIMITERS
protected
Initial value:
= [
'start' => '((',
'end' => '))'
]

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

◆ ERROR_TYPE_PASSAGE

const assErrorText::ERROR_TYPE_PASSAGE = 2
protected

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

◆ ERROR_TYPE_WORD

const assErrorText::ERROR_TYPE_WORD = 1
protected

Definition at line 42 of file class.assErrorText.php.

◆ ERROR_WORD_MARKER

const assErrorText::ERROR_WORD_MARKER = '#'
protected

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

◆ FIND_PUNCTUATION_REGEXP

const assErrorText::FIND_PUNCTUATION_REGEXP = '/\p{P}/'
protected

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

◆ PARAGRAPH_SPLIT_REGEXP

const assErrorText::PARAGRAPH_SPLIT_REGEXP = '/[\n\r]+/'
protected

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

◆ WORD_SPLIT_REGEXP

const assErrorText::WORD_SPLIT_REGEXP = '/\s+/'
protected

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


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