ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
assFormulaQuestion Class Reference

Class for single choice questions assFormulaQuestion is a class for single choice questions. More...

+ Inheritance diagram for assFormulaQuestion:
+ Collaboration diagram for assFormulaQuestion:

Public Member Functions

 __construct (string $title="", string $comment="", string $author="", int $owner=-1, string $question="")
 
 clearVariables ()
 
 getVariables ()
 
 getVariable (string $variable)
 
 addVariable (assFormulaQuestionVariable $variable)
 
 clearResults ()
 
 getResults ()
 
 getResult (string $result)
 
 addResult (assFormulaQuestionResult $result)
 
 addResultUnits (?assFormulaQuestionResult $result, ?array $unit_ids)
 
 addResultUnit (?assFormulaQuestionResult $result, ?assFormulaQuestionUnit $unit)
 
 getResultUnits (assFormulaQuestionResult $result)
 
 getAllResultUnits ()
 
 hasResultUnit (assFormulaQuestionResult $result, int $unit_id)
 
 parseQuestionText ()
 
 checkForDuplicateVariables ()
 
 checkForDuplicateResults ()
 
 fetchAllResults ($questionText)
 
 fetchAllVariables (string $question_text)
 
 hasRequiredVariableSolutionValues (array $userSolution)
 
 getVariableSolutionValuesForPass (int $active_id, int $pass)
 
 getInitialVariableSolutionValues ()
 
 saveCurrentSolution (int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
 
 substituteVariables (array $userdata, bool $graphicalOutput=false, bool $forsolution=false, bool $result_output=false, array $correctness_icons=[])
 
 canUseAdvancedRating ($result)
 Check if advanced rating can be used for a result. More...
 
 isComplete ()
 Returns true, if the question is complete for use. More...
 
 saveToDb (?int $original_id=null)
 
 loadFromDb (int $question_id)
 
 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 $previewSession)
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 lookupForExistingSolutions (int $active_id, int $pass)
 
 removeExistingSolutions (int $active_id, int $pass)
 
 getQuestionType ()
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 deleteAnswers (int $question_id)
 
 getRTETextWithMediaObjects ()
 
 getBestSolution (array $solutions)
 
 setId (int $id=-1)
 
 setUnitrepository (\ilUnitConfigurationRepository $unitrepository)
 
 getUnitrepository ()
 
 validateSolutionSubmit ()
 
 getOperators (string $expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. More...
 
 getUserQuestionResult (int $active_id, int $pass)
 Get the user solution for a question by active_id and the test pass. More...
 
 getAvailableAnswerOptions ($index=null)
 If index is null, the function returns an array with all anwser options Else it returns the specific answer option. More...
 
 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)
 
 getVariablesAsTextArray (int $active_id, int $pass)
 
- Public Member Functions inherited from assQuestion
 getQuestionType ()
 
 isComplete ()
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 calculateReachedPoints (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 MUST return an array of the question settings that can be stored in the log. More...
 
 getCurrentUser ()
 
 getShuffler ()
 
 setShuffler (Transformation $shuffler)
 
 setProcessLocker (ilAssQuestionProcessLocker $processLocker)
 
 getProcessLocker ()
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 toXML (bool $a_include_header=true, bool $a_include_binary=true, bool $a_shuffle=false, bool $test_output=false, bool $force_image_references=false)
 Returns a QTI xml representation of the question. More...
 
 setTitle (string $title="")
 
 setId (int $id=-1)
 
 setTestId (int $id=-1)
 
 setComment (string $comment="")
 
 setShuffle (?bool $shuffle=true)
 
 setAuthor (string $author="")
 
 setOwner (int $owner=-1)
 
 getTitle ()
 
 getTitleForHTMLOutput ()
 
 getTitleFilenameCompliant ()
 
 getId ()
 
 getShuffle ()
 
 getTestId ()
 
 getComment ()
 
 getDescriptionForHTMLOutput ()
 
 getThumbSize ()
 
 setThumbSize (int $a_size)
 
 getMinimumThumbSize ()
 
 getMaximumThumbSize ()
 
 getAuthor ()
 
 getAuthorForHTMLOutput ()
 
 getOwner ()
 
 getObjId ()
 
 setObjId (int $obj_id=0)
 
 getLifecycle ()
 
 setLifecycle (ilAssQuestionLifecycle $lifecycle)
 
 setExternalId (?string $external_id)
 
 getExternalId ()
 
 getSuggestedSolutionOutput ()
 
 getSuggestedSolutions ()
 
 getReachedPoints (int $active_id, int $pass)
 
 getMaximumPoints ()
 
 getAdjustedReachedPoints (int $active_id, int $pass, bool $authorized_solution=true)
 
 calculateResultsFromSolution (int $active_id, int $pass)
 Calculates the question results from a previously saved question solution. More...
 
 persistWorkingState (int $active_id, $pass, bool $authorized=true)
 persists the working state for current testactive and testpass More...
 
 persistPreviewState (ilAssQuestionPreviewSession $preview_session)
 persists the preview state for current user and question More...
 
 validateSolutionSubmit ()
 
 getSuggestedSolutionPath ()
 
 getImagePath ($question_id=null, $object_id=null)
 Returns the image path for web accessable images of a question. More...
 
 getSuggestedSolutionPathWeb ()
 
 getImagePathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 getTestOutputSolutions (int $activeId, int $pass)
 
 getUserSolutionPreferingIntermediate (int $active_id, ?int $pass=null)
 
 getSolutionValues (int $active_id, ?int $pass=null, bool $authorized=true)
 Loads solutions of a given user from the database an returns it. More...
 
 deleteAnswers (int $question_id)
 
 deleteAdditionalTableData (int $question_id)
 
 delete (int $question_id)
 
 getTotalAnswers ()
 
 cloneXHTMLMediaObjectsOfQuestion (int $source_question_id)
 
 createPageObject ()
 
 clonePageOfQuestion (int $a_q_id)
 
 getPageOfQuestion ()
 
 setOriginalId (?int $original_id)
 
 getOriginalId ()
 
 fixSvgToPng (string $imageFilenameContainingString)
 
 fixUnavailableSkinImageSources (string $html)
 
 loadFromDb (int $question_id)
 
 createNewQuestion (bool $a_create_page=true)
 Creates a new question without an owner when a new question is created This assures that an ID is given to the question if a file upload or something else occurs. More...
 
 saveQuestionDataToDb (?int $original_id=null)
 
 duplicate (bool $for_test=true, string $title='', string $author='', int $owner=-1, $test_obj_id=null)
 
 copyObject (int $target_parent_id, string $title='')
 
 createNewOriginalFromThisDuplicate (int $target_parent_id, string $target_question_title='')
 
 saveToDb (?int $original_id=null)
 
 deleteSuggestedSolutions ()
 
 getSuggestedSolution (int $subquestion_index=0)
 
 resolveInternalLink (string $internal_link)
 
 resolveSuggestedSolutionLinks ()
 
 getInternalLinkHref (string $target)
 
 syncWithOriginal ()
 
 getPoints ()
 
 setPoints (float $points)
 
 getSolutionMaxPass (int $active_id)
 
 isWriteable ()
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $preview_session)
 
 isPreviewSolutionCorrect (ilAssQuestionPreviewSession $preview_session)
 
 adjustReachedPointsByScoringOptions (float $points, int $active_id)
 Adjust the given reached points by checks for all special scoring options in the test container. More...
 
 buildHashedImageFilename (string $plain_image_filename, bool $unique=false)
 
 getQuestion ()
 
 getQuestionForHTMLOutput ()
 
 setQuestion (string $question="")
 
 getQuestionTypeID ()
 
 cleanupMediaObjectUsage ()
 
 getInstances ()
 
 getActiveUserData (int $active_id)
 Returns the user id and the test id for a given active id. More...
 
 hasSpecificFeedback ()
 
 getNrOfTries ()
 
 setNrOfTries (int $a_nr_of_tries)
 
 setExportImagePath (string $path)
 
 formatSAQuestion ($a_q)
 
 setPreventRteUsage (bool $prevent_rte_usage)
 
 getPreventRteUsage ()
 
 migrateContentForLearningModule (ilAssSelfAssessmentMigrator $migrator)
 
 setSelfAssessmentEditingMode (bool $selfassessmenteditingmode)
 
 getSelfAssessmentEditingMode ()
 
 setDefaultNrOfTries (int $defaultnroftries)
 
 getDefaultNrOfTries ()
 
 syncSkillAssignments (int $srcParentId, int $srcQuestionId, int $trgParentId, int $trgQuestionId)
 
 isAnswered (int $active_id, int $pass)
 
 getAdditionalContentEditingMode ()
 
 setAdditionalContentEditingMode (?string $additionalContentEditingMode)
 
 isAdditionalContentEditingModePageObject ()
 
 isValidAdditionalContentEditingMode (string $additionalContentEditingMode)
 
 getValidAdditionalContentEditingModes ()
 
 getHtmlUserSolutionPurifier ()
 
 getHtmlQuestionContentPurifier ()
 
 setLastChange (int $lastChange)
 
 getLastChange ()
 
 removeIntermediateSolution (int $active_id, int $pass)
 
 removeCurrentSolution (int $active_id, int $pass, bool $authorized=true)
 
 saveCurrentSolution (int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
 
 updateCurrentSolution (int $solutionId, $value1, $value2, bool $authorized=true)
 
 updateCurrentSolutionsAuthorization (int $activeId, int $pass, bool $authorized, bool $keepTime=false)
 
 setStep ($step)
 
 getStep ()
 
 toJSON ()
 
 intermediateSolutionExists (int $active_id, int $pass)
 
 authorizedSolutionExists (int $active_id, ?int $pass)
 
 authorizedOrIntermediateSolutionExists (int $active_id, int $pass)
 
 lookupForExistingSolutions (int $activeId, int $pass)
 Lookup if an authorized or intermediate solution exists. More...
 
 isAddableAnswerOptionValue (int $qIndex, string $answerOptionValue)
 
 addAnswerOptionValue (int $qIndex, string $answerOptionValue, float $points)
 
 removeAllExistingSolutions ()
 
 removeExistingSolutions (int $activeId, int $pass)
 
 resetUsersAnswer (int $activeId, int $pass)
 
 removeResultRecord (int $activeId, int $pass)
 
 fetchValuePairsFromIndexedValues (array $indexedValues)
 
 fetchIndexedValuesFromValuePairs (array $value_pairs)
 
 updateTimestamp ()
 
 getTestPresentationConfig ()
 
 hasWritableOriginalInQuestionPool ()
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
 getSolutionForTextOutput (int $active_id, int $pass)
 
 getCorrectSolutionForTextOutput (int $active_id, int $pass)
 
 getVariablesAsTextArray (int $active_id, int $pass)
 
 validateSolutionSubmit ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
- 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...
 

Protected Member Functions

 generateResultInputHTML (string $result_key, string $result_value, bool $forsolution)
 
 cloneQuestionTypeSpecificProperties (\assQuestion $target)
 
 isValidSolutionResultValue (string $submittedValue)
 
 savePreviewData (ilAssQuestionPreviewSession $previewSession)
 
 getSolutionSubmit ()
 
 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

PassPresentedVariablesRepo $pass_presented_variables_repo
 
- 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

 buildVariablesForLog (array $variables, string $none_tag)
 
 buildResultsForLog (array $results, string $none_tag)
 

Private Attributes

array $variables
 
array $results
 
array $resultunits
 
ilUnitConfigurationRepository $unitrepository
 

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 single choice questions assFormulaQuestion 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
Version
Id
class.assFormulaQuestion.php 1236 2010-02-15 15:44:16Z hschottm

\

Definition at line 31 of file class.assFormulaQuestion.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

45 {
47 $this->variables = [];
48 $this->results = [];
49 $this->resultunits = [];
50 $this->unitrepository = new ilUnitConfigurationRepository(0);
51 $this->pass_presented_variables_repo = new PassPresentedVariablesRepo($this->db);
52 }
Stores random-generated parts of questions in order to present the user with a fixed question during ...
Class ilUnitConfigurationRepository.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addResult()

assFormulaQuestion::addResult ( assFormulaQuestionResult  $result)

Definition at line 95 of file class.assFormulaQuestion.php.

95 : void
96 {
97 $this->results[$result->getResult()] = $result;
98 }

References assFormulaQuestionResult\getResult().

+ Here is the call graph for this function:

◆ addResultUnit()

assFormulaQuestion::addResultUnit ( ?assFormulaQuestionResult  $result,
?assFormulaQuestionUnit  $unit 
)

Definition at line 115 of file class.assFormulaQuestion.php.

118 : void {
119 if ($result === null || $unit === null) {
120 return;
121 }
122
123 if (!array_key_exists($result->getResult(), $this->resultunits) ||
124 !is_array($this->resultunits[$result->getResult()])) {
125 $this->resultunits[$result->getResult()] = [];
126 }
127 $this->resultunits[$result->getResult()][$unit->getId()] = $unit;
128 }

◆ addResultUnits()

assFormulaQuestion::addResultUnits ( ?assFormulaQuestionResult  $result,
?array  $unit_ids 
)

Definition at line 100 of file class.assFormulaQuestion.php.

103 : void {
104 $this->resultunits[$result->getResult()] = [];
105 if ($result === null || $unit_ids === null) {
106 return;
107 }
108 foreach ($unit_ids as $id) {
109 if (is_numeric($id) && ($id > 0)) {
110 $this->resultunits[$result->getResult()][$id] = $this->getUnitrepository()->getUnit($id);
111 }
112 }
113 }

◆ addVariable()

assFormulaQuestion::addVariable ( assFormulaQuestionVariable  $variable)

Definition at line 72 of file class.assFormulaQuestion.php.

72 : void
73 {
74 $this->variables[$variable->getVariable()] = $variable;
75 }

References assFormulaQuestionVariable\getVariable().

+ Here is the call graph for this function:

◆ buildResultsForLog()

assFormulaQuestion::buildResultsForLog ( array  $results,
string  $none_tag 
)
private
Parameters
array<assFormulaQuestionResult>$variables

Definition at line 1325 of file class.assFormulaQuestion.php.

1325 : array
1326 {
1327 return array_reduce(
1328 $results,
1329 function (array $c, assFormulaQuestionResult $r) use ($none_tag): array {
1330 $c[$r->getResult()] = [
1331 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_RESULT_TYPE => $r->getResultType(),
1332 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_FORMULA => $r->getFormula(),
1333 AdditionalInformationGenerator::KEY_QUESTION_REACHABLE_POINTS => $r->getPoints(),
1334 AdditionalInformationGenerator::KEY_QUESTION_LOWER_LIMIT => $r->getRangeMinTxt(),
1335 AdditionalInformationGenerator::KEY_QUESTION_UPPER_LIMIT => $r->getRangeMaxTxt(),
1336 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_TOLERANCE => $r->getTolerance(),
1337 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_PRECISION => $r->getPrecision(),
1338 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_UNIT => $r->getUnit() ?? $none_tag
1339 ];
1340 return $c;
1341 },
1342 []
1343 );
1344 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: deliver.php:25

References $c, $results, assFormulaQuestionResult\getFormula(), assFormulaQuestionResult\getPoints(), assFormulaQuestionResult\getPrecision(), assFormulaQuestionResult\getRangeMaxTxt(), assFormulaQuestionResult\getRangeMinTxt(), assFormulaQuestionResult\getResult(), assFormulaQuestionResult\getResultType(), assFormulaQuestionResult\getTolerance(), and assFormulaQuestionResult\getUnit().

+ Here is the call graph for this function:

◆ buildVariablesForLog()

assFormulaQuestion::buildVariablesForLog ( array  $variables,
string  $none_tag 
)
private
Parameters
array<assFormulaQuestionVariable>$variables

Definition at line 1303 of file class.assFormulaQuestion.php.

1303 : array
1304 {
1305 return array_reduce(
1306 $variables,
1307 function (array $c, assFormulaQuestionVariable $v) use ($none_tag): array {
1308 $c[$v->getVariable()] = [
1309 AdditionalInformationGenerator::KEY_QUESTION_LOWER_LIMIT => $v->getRangeMinTxt(),
1310 AdditionalInformationGenerator::KEY_QUESTION_UPPER_LIMIT => $v->getRangeMaxTxt(),
1311 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_PRECISION => $v->getPrecision(),
1312 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_INTPRECISION => $v->getIntprecision(),
1313 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_UNIT => $v->getUnit() ?? $none_tag
1314 ];
1315 return $c;
1316 },
1317 []
1318 );
1319 }

References $c, assFormulaQuestionVariable\getIntprecision(), assFormulaQuestionVariable\getPrecision(), assFormulaQuestionVariable\getRangeMaxTxt(), assFormulaQuestionVariable\getRangeMinTxt(), assFormulaQuestionVariable\getUnit(), and assFormulaQuestionVariable\getVariable().

+ Here is the call graph for this function:

◆ calculateReachedPoints()

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

Reimplemented from assQuestion.

Definition at line 795 of file class.assFormulaQuestion.php.

799 : float {
800 if ($pass === null) {
801 $pass = $this->getSolutionMaxPass($active_id);
802 }
803 $solutions = $this->getSolutionValues($active_id, $pass, $authorized_solution);
804 $user_solution = [];
805 foreach ($solutions as $solution_value) {
806 if (preg_match('/^(\$v\d+)$/', $solution_value['value1'], $matches)) {
807 $user_solution[$matches[1]] = $solution_value['value2'];
808 $var_obj = $this->getVariable($solution_value['value1']);
809 $var_obj->setValue($solution_value['value2']);
810 continue;
811 }
812
813 if (preg_match('/^(\$r\d+)$/', $solution_value['value1'], $matches)) {
814 if (!array_key_exists($matches[1], $user_solution)) {
815 $user_solution[$matches[1]] = [];
816 }
817 $user_solution[$matches[1]]['value'] = $solution_value['value2'];
818 continue;
819 }
820
821 if (preg_match('/^(\$r\d+)_unit$/', $solution_value['value1'], $matches)) {
822 if (!array_key_exists($matches[1], $user_solution)) {
823 $user_solution[$matches[1]] = [];
824 }
825 $user_solution[$matches[1]]['unit'] = $this->unitrepository->getUnit(
826 $this->refinery->kindlyTo()->int()->transform($solution_value['value2']),
827 );
828 }
829 }
830
831 $points = 0;
832 foreach ($this->getResults() as $result) {
833 $points += $result->getReachedPoints(
834 $this->getVariables(),
835 $this->getResults(),
836 $user_solution[$result->getResult()]['value'] ?? '',
837 $user_solution[$result->getResult()]['unit'] ?? null,
838 $this->unitrepository->getUnits()
839 );
840 }
841
842 return (float) $points;
843 }
getVariable(string $variable)
getSolutionValues(int $active_id, ?int $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
getSolutionMaxPass(int $active_id)

◆ calculateReachedPointsFromPreviewSession()

assFormulaQuestion::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $previewSession)

Reimplemented from assQuestion.

Definition at line 845 of file class.assFormulaQuestion.php.

846 {
847 $user_solution = $previewSession->getParticipantsSolution();
848
849 $points = 0;
850 foreach ($this->getResults() as $result) {
851 $result_unit = $result->getResult() . '_unit';
852 $unit_id = isset($user_solution[$result_unit]) && is_numeric($user_solution[$result_unit])
853 ? (int) $user_solution[$result_unit]
854 : null;
855
856 $points += $result->getReachedPoints(
857 $this->getVariables(),
858 $this->getResults(),
859 $user_solution[$result->getResult()] ?? '',
860 $unit_id !== null ? $this->unitrepository->getUnit($unit_id) : null,
861 $this->unitrepository->getUnits()
862 );
863 }
864 return $this->ensureNonNegativePoints($points);
865 }
ensureNonNegativePoints(float $points)

References ilAssQuestionPreviewSession\getParticipantsSolution(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ canUseAdvancedRating()

assFormulaQuestion::canUseAdvancedRating (   $result)

Check if advanced rating can be used for a result.

This is only possible if there is exactly one possible correct unit for the result, otherwise it is impossible to determine wheather the unit is correct or the value.

Returns
boolean True if advanced rating could be used, false otherwise

Definition at line 541 of file class.assFormulaQuestion.php.

541 : bool
542 {
543 $result_units = $this->getResultUnits($result);
544 $resultunit = $result->getUnit();
545 $similar_units = 0;
546 foreach ($result_units as $unit) {
547 if (is_object($resultunit)) {
548 if ($resultunit->getId() != $unit->getId()) {
549 if ($resultunit->getBaseUnit() && $unit->getBaseUnit()) {
550 if ($resultunit->getBaseUnit() == $unit->getBaseUnit()) {
551 return false;
552 }
553 }
554 if ($resultunit->getBaseUnit()) {
555 if ($resultunit->getBaseUnit() == $unit->getId()) {
556 return false;
557 }
558 }
559 if ($unit->getBaseUnit()) {
560 if ($unit->getBaseUnit() == $resultunit->getId()) {
561 return false;
562 }
563 }
564 }
565 }
566 }
567 return true;
568 }
getResultUnits(assFormulaQuestionResult $result)

References assFormulaQuestionResult\getUnit().

+ Here is the call graph for this function:

◆ checkForDuplicateResults()

assFormulaQuestion::checkForDuplicateResults ( )

Definition at line 196 of file class.assFormulaQuestion.php.

196 : bool
197 {
198 if (preg_match_all('/(\$r\d+)/im', $this->getQuestion(), $rmatches)) {
199 if ((count(array_unique($rmatches[1]))) != count($rmatches[1])) {
200 return false;
201 }
202 }
203 return true;
204 }

◆ checkForDuplicateVariables()

assFormulaQuestion::checkForDuplicateVariables ( )

Definition at line 186 of file class.assFormulaQuestion.php.

186 : bool
187 {
188 if (preg_match_all('/(\$v\d+)/im', $this->getQuestion(), $matches)) {
189 if ((count(array_unique($matches[1]))) != count($matches[1])) {
190 return false;
191 }
192 }
193 return true;
194 }

◆ clearResults()

assFormulaQuestion::clearResults ( )

Definition at line 77 of file class.assFormulaQuestion.php.

77 : void
78 {
79 $this->results = [];
80 }

◆ clearVariables()

assFormulaQuestion::clearVariables ( )

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

54 : void
55 {
56 $this->variables = [];
57 }

◆ cloneQuestionTypeSpecificProperties()

assFormulaQuestion::cloneQuestionTypeSpecificProperties ( \assQuestion  $target)
protected

Definition at line 775 of file class.assFormulaQuestion.php.

777 : \assQuestion {
778 $this->unitrepository->cloneUnits($this->getId(), $target->getId());
779 return $target;
780 }

◆ deleteAnswers()

assFormulaQuestion::deleteAnswers ( int  $question_id)

Reimplemented from assQuestion.

Definition at line 1043 of file class.assFormulaQuestion.php.

1043 : void
1044 {
1045 $affectedRows = $this->db->manipulateF(
1046 "DELETE FROM il_qpl_qst_fq_var WHERE question_fi = %s",
1047 ['integer'],
1048 [$question_id]
1049 );
1050
1051 $affectedRows = $this->db->manipulateF(
1052 "DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s",
1053 ['integer'],
1054 [$question_id]
1055 );
1056
1057 $affectedRows = $this->db->manipulateF(
1058 "DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
1059 ['integer'],
1060 [$question_id]
1061 );
1062
1063 $affectedRows = $this->db->manipulateF(
1064 "DELETE FROM il_qpl_qst_fq_ucat WHERE question_fi = %s",
1065 ['integer'],
1066 [$question_id]
1067 );
1068
1069 $affectedRows = $this->db->manipulateF(
1070 "DELETE FROM il_qpl_qst_fq_unit WHERE question_fi = %s",
1071 ['integer'],
1072 [$question_id]
1073 );
1074 }

◆ fetchAllResults()

assFormulaQuestion::fetchAllResults (   $questionText)
Parameters
string$questionText
Returns
assFormulaQuestionResult[] $resObjects

Definition at line 210 of file class.assFormulaQuestion.php.

210 : array
211 {
212 $resObjects = [];
213 $matches = null;
214
215 if (preg_match_all('/(\$r\d+)/im', $questionText, $matches)) {
216 foreach ($matches[1] as $resultKey) {
217 $resObjects[] = $this->getResult($resultKey);
218 }
219 }
220
221 return $resObjects;
222 }

◆ fetchAllVariables()

assFormulaQuestion::fetchAllVariables ( string  $question_text)
Returns
list<assFormulaQuestionVariable>

Definition at line 227 of file class.assFormulaQuestion.php.

227 : array
228 {
229 $var_objects = [];
230 $matches = null;
231
232 if (preg_match_all('/(\$v\d+)/im', $question_text, $matches)) {
233 $var_objects = array_reduce(
234 $matches[1],
235 function (array $c, string $v): array {
236 $vo = $this->getVariable($v);
237 if ($vo !== null) {
238 $c[] = $vo;
239 }
240 return $c;
241 },
242 []
243 );
244 }
245
246 return $var_objects;
247 }

References $c.

◆ generateResultInputHTML()

assFormulaQuestion::generateResultInputHTML ( string  $result_key,
string  $result_value,
bool  $forsolution 
)
protected

Definition at line 521 of file class.assFormulaQuestion.php.

521 : string
522 {
523 if ($forsolution) {
524 return '<span class="ilc_qinput_TextInput solutionbox">'
526 . '</span>';
527 }
528 $input = '<input class="ilc_qinput_TextInput" type="text"';
529 $input .= 'spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off"';
530 $input .= 'name="result_' . $result_key . '"';
531 $input .= ' value="' . $result_value . '"/>';
532 return $input;
533 }
static prepareFormOutput($a_str, bool $a_strip=false)

References ilLegacyFormElementsUtil\prepareFormOutput().

+ Here is the call graph for this function:

◆ getAdditionalTableName()

assFormulaQuestion::getAdditionalTableName ( )

Reimplemented from assQuestion.

Definition at line 1033 of file class.assFormulaQuestion.php.

1033 : string
1034 {
1035 return "";
1036 }

◆ getAllResultUnits()

assFormulaQuestion::getAllResultUnits ( )

Definition at line 150 of file class.assFormulaQuestion.php.

150 : array
151 {
152 return $this->resultunits;
153 }

◆ getAnswerTableName()

assFormulaQuestion::getAnswerTableName ( )

Reimplemented from assQuestion.

Definition at line 1038 of file class.assFormulaQuestion.php.

1038 : string
1039 {
1040 return "";
1041 }

◆ getAvailableAnswerOptions()

assFormulaQuestion::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
Returns
array|ASS_AnswerSimple

Definition at line 1269 of file class.assFormulaQuestion.php.

1270 {
1271 if ($index !== null) {
1272 return $this->getResult('$r' . ($index + 1));
1273 } else {
1274 return $this->getResults();
1275 }
1276 }

◆ getBestSolution()

assFormulaQuestion::getBestSolution ( array  $solutions)

Definition at line 1082 of file class.assFormulaQuestion.php.

1082 : array
1083 {
1084 $user_solution = [];
1085
1086 foreach ($solutions as $solution_value) {
1087 if (preg_match('/^(\$v\d+)$/', $solution_value['value1'], $matches)) {
1088 $user_solution[$matches[1]] = $solution_value['value2'];
1089 $varObj = $this->getVariable($matches[1]);
1090 $varObj->setValue($solution_value['value2']);
1091 } elseif (preg_match('/^(\$r\d+)$/', $solution_value['value1'], $matches)) {
1092 if (!array_key_exists($matches[1], $user_solution)) {
1093 $user_solution[$matches[1]] = [];
1094 }
1095 $user_solution[$matches[1]]['value'] = $solution_value['value2'];
1096 } elseif (preg_match('/^(\$r\d+)_unit$/', $solution_value['value1'], $matches)) {
1097 if (!array_key_exists($matches[1], $user_solution)) {
1098 $user_solution[$matches[1]] = [];
1099 }
1100 $user_solution[$matches[1]]['unit'] = $solution_value['value2'];
1101 }
1102 }
1103 foreach ($this->getResults() as $result) {
1104 $resVal = $result->calculateFormula($this->getVariables(), $this->getResults(), $this->getId(), false);
1105
1106 if (is_object($result->getUnit())) {
1107 $user_solution[$result->getResult()]['unit'] = $result->getUnit()->getId();
1108 $user_solution[$result->getResult()]['value'] = $resVal;
1109 } elseif ($result->getUnit() === null) {
1110 $unit_factor = 1;
1111 // there is no fix result_unit, any "available unit" is accepted
1112
1113 $available_units = $result->getAvailableResultUnits(parent::getId());
1114 $result_name = $result->getResult();
1115
1116 $check_unit = false;
1117 if (array_key_exists($result_name, $available_units) &&
1118 $available_units[$result_name] !== null) {
1119 $check_unit = in_array($user_solution[$result_name]['unit'] ?? null, $available_units[$result_name]);
1120 }
1121
1122 if ($check_unit == true) {
1123 //get unit-factor
1124 $unit_factor = assFormulaQuestionUnit::lookupUnitFactor($user_solution[$result_name]['unit']);
1125 }
1126
1127 try {
1128 $user_solution[$result->getResult()]['value'] = ilMath::_div($resVal, $unit_factor, 55);
1129 } catch (ilMathDivisionByZeroException $ex) {
1130 $user_solution[$result->getResult()]['value'] = 0;
1131 }
1132 }
1133 if ($result->getResultType() == assFormulaQuestionResult::RESULT_CO_FRAC
1134 || $result->getResultType() == assFormulaQuestionResult::RESULT_FRAC) {
1136 if (is_array($value)) {
1137 $user_solution[$result->getResult()]['value'] = $value[0];
1138 $user_solution[$result->getResult()]['frac_helper'] = $value[1];
1139 } else {
1140 $user_solution[$result->getResult()]['value'] = $value;
1141 $user_solution[$result->getResult()]['frac_helper'] = null;
1142 }
1143 } else {
1144 $user_solution[$result->getResult()]['value'] = round((float) $user_solution[$result->getResult()]['value'], $result->getPrecision());
1145 }
1146 }
1147 return $user_solution;
1148 }
static convertDecimalToCoprimeFraction($decimal_value, $tolerance=1.e-9)
static lookupUnitFactor(int $a_unit_id)
static _div($left_operand, $right_operand, int $scale=50)

References ilMath\_div(), assFormulaQuestionResult\convertDecimalToCoprimeFraction(), ILIAS\Survey\Mode\getId(), assFormulaQuestionUnit\lookupUnitFactor(), assFormulaQuestionResult\RESULT_CO_FRAC, and assFormulaQuestionResult\RESULT_FRAC.

+ Here is the call graph for this function:

◆ getCorrectSolutionForTextOutput()

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

Reimplemented from assQuestion.

Definition at line 1401 of file class.assFormulaQuestion.php.

1401 : array
1402 {
1403 $best_solution = $this->getBestSolution($this->getSolutionValues($active_id, $pass));
1404 return array_map(
1405 function (string $v) use ($best_solution): string {
1406 $solution = "{$v} = {$best_solution[$v]['value']}";
1407 if (isset($best_solution['unit'])) {
1408 $solution .= "{$this->unitrepository->getUnit($best_solution['unit'])->getUnit()}";
1409 }
1410 return $solution;
1411 },
1412 array_keys($best_solution)
1413 );
1414 }
getBestSolution(array $solutions)

◆ getExpressionTypes()

assFormulaQuestion::getExpressionTypes ( )

◆ getInitialVariableSolutionValues()

assFormulaQuestion::getInitialVariableSolutionValues ( )

Definition at line 290 of file class.assFormulaQuestion.php.

290 : array
291 {
292 foreach ($this->fetchAllResults($this->getQuestion()) as $resObj) {
293 $resObj->findValidRandomVariables($this->getVariables(), $this->getResults());
294 }
295
296 $variableSolutionValues = [];
297
298 foreach ($this->fetchAllVariables($this->getQuestion()) as $varObj) {
299 $variableSolutionValues[$varObj->getVariable()] = $varObj->getValue();
300 }
301
302 return $variableSolutionValues;
303 }
fetchAllVariables(string $question_text)

◆ getMaximumPoints()

assFormulaQuestion::getMaximumPoints ( )

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

See also
$points

Reimplemented from assQuestion.

Definition at line 786 of file class.assFormulaQuestion.php.

786 : float
787 {
788 $points = 0;
789 foreach ($this->results as $result) {
790 $points += $result->getPoints();
791 }
792 return $points;
793 }

◆ getOperators()

assFormulaQuestion::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

Definition at line 1212 of file class.assFormulaQuestion.php.

1212 : array
1213 {
1215 }
static getOperatorsByExpression(string $expression)

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ Here is the call graph for this function:

◆ getQuestionType()

assFormulaQuestion::getQuestionType ( )

Reimplemented from assQuestion.

Definition at line 1028 of file class.assFormulaQuestion.php.

1028 : string
1029 {
1030 return "assFormulaQuestion";
1031 }

◆ getResult()

assFormulaQuestion::getResult ( string  $result)

Definition at line 87 of file class.assFormulaQuestion.php.

88 {
89 if (array_key_exists($result, $this->results)) {
90 return $this->results[$result];
91 }
92 return null;
93 }

◆ getResults()

assFormulaQuestion::getResults ( )

Definition at line 82 of file class.assFormulaQuestion.php.

82 : array
83 {
84 return $this->results;
85 }

References $results.

◆ getResultUnits()

assFormulaQuestion::getResultUnits ( assFormulaQuestionResult  $result)
Returns
assFormulaQuestionUnit[]

Definition at line 133 of file class.assFormulaQuestion.php.

133 : array
134 {
135 if (!isset($this->resultunits[$result->getResult()])) {
136 return [];
137 }
138
139 $result_units = $this->resultunits[$result->getResult()];
140
141 usort(
142 $result_units,
144 $a->getSequence() <=> $b->getSequence()
145 );
146
147 return $result_units;
148 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, Vendor\Package\$b, and assFormulaQuestionResult\getResult().

+ Here is the call graph for this function:

◆ getRTETextWithMediaObjects()

assFormulaQuestion::getRTETextWithMediaObjects ( )

Reimplemented from assQuestion.

Definition at line 1076 of file class.assFormulaQuestion.php.

1076 : string
1077 {
1078 $text = parent::getRTETextWithMediaObjects();
1079 return $text;
1080 }
$text
Definition: xapiexit.php:21

References $text.

◆ getSolutionSubmit()

assFormulaQuestion::getSolutionSubmit ( )
protected
Returns
array<string>

Definition at line 1169 of file class.assFormulaQuestion.php.

1169 : array
1170 {
1171 $solutionSubmit = [];
1172
1173 $post = $this->dic->http()->wrapper()->post();
1174
1175 foreach ($this->getResults() as $index => $a) {
1176 $key = "result_$index";
1177 if ($post->has($key)) {
1178 $value = $post->retrieve(
1179 $key,
1180 $this->dic->refinery()->kindlyTo()->string()
1181 );
1182
1183 $solutionSubmit[$key] = $value;
1184 }
1185 if ($post->has($key . "_unit")) {
1186 $value = $post->retrieve(
1187 $key . "_unit",
1188 $this->dic->refinery()->kindlyTo()->string()
1189 );
1190 $solutionSubmit[$key . "_unit"] = $value;
1191 }
1192 }
1193 return $solutionSubmit;
1194 }
$post
Definition: ltitoken.php:46

References Vendor\Package\$a, and $post.

◆ getUnitrepository()

assFormulaQuestion::getUnitrepository ( )

Definition at line 1161 of file class.assFormulaQuestion.php.

1162 {
1163 return $this->unitrepository;
1164 }
ilUnitConfigurationRepository $unitrepository

◆ getUserQuestionResult()

assFormulaQuestion::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 1226 of file class.assFormulaQuestion.php.

1230 $result = new ilUserQuestionResult($this, $active_id, $pass);
1231
1232 $maxStep = $this->lookupMaxStep($active_id, $pass);
1233 if ($maxStep > 0) {
1234 $data = $this->db->queryF(
1235 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1236 ['integer', 'integer', 'integer','integer'],
1237 [$active_id, $pass, $this->getId(), $maxStep]
1238 );
1239 } else {
1240 $data = $this->db->queryF(
1241 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
1242 ['integer', 'integer', 'integer'],
1243 [$active_id, $pass, $this->getId()]
1244 );
1245 }
1246
1247 while ($row = $this->db->fetchAssoc($data)) {
1248 if (strstr($row['value1'], '$r') && $row['value2'] != null) {
1249 $result->addKeyValue(str_replace('$r', "", $row['value1']), $row['value2']);
1250 }
1251 }
1252
1253 $points = $this->calculateReachedPoints($active_id, $pass);
1254 $max_points = $this->getMaximumPoints();
1255
1256 $result->setReachedPercentage(($points / $max_points) * 100);
1257
1258 return $result;
1259 }
calculateReachedPoints(int $active_id, ?int $pass=null, bool $authorized_solution=true)
getMaximumPoints()
Returns the maximum points, a learner can reach answering the question.
lookupMaxStep(int $active_id, int $pass)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getVariable()

assFormulaQuestion::getVariable ( string  $variable)

Definition at line 64 of file class.assFormulaQuestion.php.

65 {
66 if (array_key_exists($variable, $this->variables)) {
67 return $this->variables[$variable];
68 }
69 return null;
70 }

◆ getVariables()

assFormulaQuestion::getVariables ( )

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

59 : array
60 {
61 return $this->variables;
62 }

References $variables.

◆ getVariablesAsTextArray()

assFormulaQuestion::getVariablesAsTextArray ( int  $active_id,
int  $pass 
)

Reimplemented from assQuestion.

Definition at line 1416 of file class.assFormulaQuestion.php.

1416 : array
1417 {
1418 $variables = $this->getVariableSolutionValuesForPass($active_id, $pass);
1419 return array_map(
1420 function (string $v) use ($variables): string {
1421 $variable = "{$v} = {$variables[$v]}";
1422 if ($this->getVariable($v)->getUnit() !== null) {
1423 $variable .= $this->getVariable($v)->getUnit()->getUnit();
1424 }
1425 return $variable;
1426 },
1427 array_keys($variables)
1428 );
1429 }
getVariableSolutionValuesForPass(int $active_id, int $pass)

◆ getVariableSolutionValuesForPass()

assFormulaQuestion::getVariableSolutionValuesForPass ( int  $active_id,
int  $pass 
)

Definition at line 268 of file class.assFormulaQuestion.php.

271 : array {
272 $question_id = $this->getId();
273 $values = $this->pass_presented_variables_repo->getFor(
274 $question_id,
275 $active_id,
276 $pass
277 );
278 if (is_null($values)) {
279 $values = $this->getInitialVariableSolutionValues();
280 $this->pass_presented_variables_repo->store(
281 $question_id,
282 $active_id,
283 $pass,
284 $values
285 );
286 }
287 return $values;
288 }

◆ hasRequiredVariableSolutionValues()

assFormulaQuestion::hasRequiredVariableSolutionValues ( array  $userSolution)
Parameters
array$userSolution
Returns
bool

Definition at line 253 of file class.assFormulaQuestion.php.

253 : bool
254 {
255 foreach ($this->fetchAllVariables($this->getQuestion()) as $varObj) {
256 if (!isset($userSolution[$varObj->getVariable()])) {
257 return false;
258 }
259
260 if ($userSolution[$varObj->getVariable()] === '') {
261 return false;
262 }
263 }
264
265 return true;
266 }

◆ hasResultUnit()

assFormulaQuestion::hasResultUnit ( assFormulaQuestionResult  $result,
int  $unit_id 
)

Definition at line 155 of file class.assFormulaQuestion.php.

158 : bool {
159 if (array_key_exists($result->getResult(), $this->resultunits)
160 && array_key_exists($unit_id, $this->resultunits[$result->getResult()])) {
161 return true;
162 }
163
164 return false;
165 }

◆ isComplete()

assFormulaQuestion::isComplete ( )

Returns true, if the question is complete for use.

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

Reimplemented from assQuestion.

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

574 : bool
575 {
576 if (($this->title) and ($this->author) and ($this->question) and ($this->getMaximumPoints() > 0)) {
577 return true;
578 } else {
579 return false;
580 }
581 }

◆ isValidSolutionResultValue()

assFormulaQuestion::isValidSolutionResultValue ( string  $submittedValue)
protected

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

867 : bool
868 {
869 $submittedValue = str_replace(',', '.', $submittedValue);
870
871 if (is_numeric($submittedValue)) {
872 return true;
873 }
874
875 if (preg_match('/^[-+]?\d+\/\d+$/', $submittedValue)) {
876 return true;
877 }
878
879 return false;
880 }

◆ loadFromDb()

assFormulaQuestion::loadFromDb ( int  $question_id)

Reimplemented from assQuestion.

Definition at line 679 of file class.assFormulaQuestion.php.

679 : void
680 {
681 $result = $this->db->queryF(
682 "SELECT qpl_questions.* FROM qpl_questions WHERE question_id = %s",
683 ['integer'],
684 [$question_id]
685 );
686 if ($result->numRows() == 1) {
687 $data = $this->db->fetchAssoc($result);
688 $this->setId($question_id);
689 $this->setTitle((string) $data["title"]);
690 $this->setComment((string) $data["description"]);
691 $this->setPoints($data['points']);
692 $this->setOriginalId($data["original_id"]);
693 $this->setObjId($data["obj_fi"]);
694 $this->setAuthor($data["author"]);
695 $this->setOwner($data["owner"]);
696
697 try {
701 }
702
703 try {
704 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
706 }
707
708 $this->unitrepository = new ilUnitConfigurationRepository($question_id);
709
710 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc((string) $data["question_text"], 1));
711
712 // load variables
713 $result = $this->db->queryF(
714 "SELECT * FROM il_qpl_qst_fq_var WHERE question_fi = %s",
715 ['integer'],
716 [$question_id]
717 );
718 if ($result->numRows() > 0) {
719 while ($data = $this->db->fetchAssoc($result)) {
720 $varObj = new assFormulaQuestionVariable(
721 $data['variable'],
722 $data['range_min_txt'],
723 $data['range_max_txt'],
724 $this->getUnitrepository()->getUnit($data['unit_fi']),
725 $data['varprecision'],
726 $data['intprecision']
727 );
728 $this->addVariable($varObj);
729 }
730 }
731 // load results
732 $result = $this->db->queryF(
733 "SELECT * FROM il_qpl_qst_fq_res WHERE question_fi = %s",
734 ['integer'],
735 [$question_id]
736 );
737 if ($result->numRows() > 0) {
738 while ($data = $this->db->fetchAssoc($result)) {
739 $resObj = new assFormulaQuestionResult(
740 $data['result'],
741 $data['range_min_txt'],
742 $data['range_max_txt'],
743 $data['tolerance'],
744 $this->getUnitrepository()->getUnit($data['unit_fi']),
745 $data['formula'],
746 $data['points'],
747 $data['resprecision'],
748 $data['rating_simple'] === 1,
749 $data['rating_sign'],
750 $data['rating_value'],
751 $data['rating_unit']
752 );
753 $resObj->setResultType($data['result_type']);
754 $this->addResult($resObj);
755 }
756 }
757
758 // load result units
759 $result = $this->db->queryF(
760 "SELECT * FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
761 ['integer'],
762 [$question_id]
763 );
764 if ($result->numRows() > 0) {
765 while ($data = $this->db->fetchAssoc($result)) {
766 $unit = $this->getUnitrepository()->getUnit($data["unit_fi"]);
767 $resObj = $this->getResult($data["result"]);
768 $this->addResultUnit($resObj, $unit);
769 }
770 }
771 }
772 parent::loadFromDb($question_id);
773 }
addVariable(assFormulaQuestionVariable $variable)
addResult(assFormulaQuestionResult $result)
addResultUnit(?assFormulaQuestionResult $result, ?assFormulaQuestionUnit $unit)
setOriginalId(?int $original_id)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setQuestion(string $question="")
setAuthor(string $author="")
setComment(string $comment="")
setObjId(int $obj_id=0)
setOwner(int $owner=-1)
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(), ilAssQuestionLifecycle\getDraftInstance(), ilAssQuestionLifecycle\getInstance(), and assFormulaQuestionResult\getUnit().

+ Here is the call graph for this function:

◆ lookupForExistingSolutions()

assFormulaQuestion::lookupForExistingSolutions ( int  $active_id,
int  $pass 
)
Returns
array<'authorized' => bool, 'intermediate' => bool>

Reimplemented from assQuestion.

Definition at line 956 of file class.assFormulaQuestion.php.

956 : array
957 {
958 $return = [
959 'authorized' => false,
960 'intermediate' => false
961 ];
962
963 $query = "
964 SELECT authorized, COUNT(*) cnt
965 FROM tst_solutions
966 WHERE active_fi = " . $this->db->quote($active_id, 'integer') . "
967 AND question_fi = " . $this->db->quote($this->getId(), 'integer') . "
968 AND pass = " . $this->db->quote($pass, 'integer') . "
969 AND value1 like '\$r%'
970 AND value2 is not null
971 AND value2 <> ''
972 ";
973
974 if ($this->getStep() !== null) {
975 $query .= " AND step = " . $this->db->quote((int) $this->getStep(), 'integer') . " ";
976 }
977
978 $query .= "
979 GROUP BY authorized
980 ";
981
982 $result = $this->db->query($query);
983
984 while ($row = $this->db->fetchAssoc($result)) {
985 if ($row['authorized']) {
986 $return['authorized'] = $row['cnt'] > 0;
987 } else {
988 $return['intermediate'] = $row['cnt'] > 0;
989 }
990 }
991 return $return;
992 }

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ parseQuestionText()

assFormulaQuestion::parseQuestionText ( )

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

167 : void
168 {
169 $this->clearResults();
170 $this->clearVariables();
171 if (preg_match_all('/(\$v\d+)/im', $this->getQuestion(), $matches)) {
172 foreach ($matches[1] as $variable) {
173 $varObj = new assFormulaQuestionVariable($variable, '0.0', '0.0', null, 0);
174 $this->addVariable($varObj);
175 }
176 }
177
178 if (preg_match_all('/(\$r\d+)/im', $this->getQuestion(), $rmatches)) {
179 foreach ($rmatches[1] as $result) {
180 $resObj = new assFormulaQuestionResult($result, null, null, 0, null, null, 1, 1, true);
181 $this->addResult($resObj);
182 }
183 }
184 }

◆ removeExistingSolutions()

assFormulaQuestion::removeExistingSolutions ( int  $active_id,
int  $pass 
)

Reimplemented from assQuestion.

Definition at line 994 of file class.assFormulaQuestion.php.

994 : int
995 {
996 $query = "
997 DELETE FROM tst_solutions
998 WHERE active_fi = " . $this->db->quote($active_id, 'integer') . "
999 AND question_fi = " . $this->db->quote($this->getId(), 'integer') . "
1000 AND pass = " . $this->db->quote($pass, 'integer') . "
1001 AND value1 like '\$r%'
1002 ";
1003
1004 if ($this->getStep() !== null) {
1005 $query .= " AND step = " . $this->db->quote((int) $this->getStep(), 'integer') . " ";
1006 }
1007
1008 return $this->db->manipulate($query);
1009 }

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ saveCurrentSolution()

assFormulaQuestion::saveCurrentSolution ( int  $active_id,
int  $pass,
  $value1,
  $value2,
bool  $authorized = true,
  $tstamp = 0 
)

Reimplemented from assQuestion.

Definition at line 305 of file class.assFormulaQuestion.php.

305 : int
306 {
307 $init_solution_vars = $this->getVariableSolutionValuesForPass($active_id, $pass);
308 foreach ($init_solution_vars as $val1 => $val2) {
309 $this->db->manipulateF(
310 "DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s AND value1 = %s",
311 ['integer', 'integer','integer', 'text'],
312 [$active_id, $this->getId(), $pass, $val1]
313 );
314 parent::saveCurrentSolution($active_id, $pass, $val1, $val2, $authorized);
315 }
316 return parent::saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized, $tstamp);
317 }

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ savePreviewData()

assFormulaQuestion::savePreviewData ( ilAssQuestionPreviewSession  $previewSession)
protected

Reimplemented from assQuestion.

Definition at line 1011 of file class.assFormulaQuestion.php.

1011 : void
1012 {
1013 $userSolution = $previewSession->getParticipantsSolution();
1014
1015 foreach ($this->getSolutionSubmit() as $key => $val) {
1016 $matches = null;
1017
1018 if (preg_match('/^result_(\$r\d+)$/', $key, $matches)) {
1019 $userSolution[$matches[1]] = $val;
1020 } elseif (preg_match('/^result_(\$r\d+)_unit$/', $key, $matches)) {
1021 $userSolution[$matches[1] . "_unit"] = $val;
1022 }
1023 }
1024
1025 $previewSession->setParticipantsSolution($userSolution);
1026 }

References ilAssQuestionPreviewSession\getParticipantsSolution(), and ilAssQuestionPreviewSession\setParticipantsSolution().

+ Here is the call graph for this function:

◆ saveToDb()

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

Reimplemented from assQuestion.

Definition at line 583 of file class.assFormulaQuestion.php.

583 : void
584 {
586 // save variables
587 $affectedRows = $this->db->manipulateF(
588 "
589 DELETE FROM il_qpl_qst_fq_var
590 WHERE question_fi = %s",
591 ['integer'],
592 [$this->getId()]
593 );
594
595 foreach ($this->variables as $variable) {
596 $next_id = $this->db->nextId('il_qpl_qst_fq_var');
597 $this->db->insert(
598 'il_qpl_qst_fq_var',
599 [
600 'variable_id' => ['integer', $next_id],
601 'question_fi' => ['integer', $this->getId()],
602 'variable' => ['text', $variable->getVariable()],
603 'range_min' => ['float', $variable->getRangeMin()],
604 'range_max' => ['float', $variable->getRangeMax()],
605 'unit_fi' => ['integer', (is_object($variable->getUnit()) ? (int) $variable->getUnit()->getId() : 0)],
606 'varprecision' => ['integer', (int) $variable->getPrecision()],
607 'intprecision' => ['integer', (int) $variable->getIntprecision()],
608 'range_min_txt' => ['text', $variable->getRangeMinTxt()],
609 'range_max_txt' => ['text', $variable->getRangeMaxTxt()]
610 ]
611 );
612 }
613 // save results
614 $affectedRows = $this->db->manipulateF(
615 "DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s",
616 ['integer'],
617 [$this->getId()]
618 );
619
620 foreach ($this->results as $result) {
621 $next_id = $this->db->nextId('il_qpl_qst_fq_res');
622 if (is_object($result->getUnit())) {
623 $tmp_result_unit = $result->getUnit()->getId();
624 } else {
625 $tmp_result_unit = null;
626 }
627
628 $formula = null;
629 if ($result->getFormula() !== null) {
630 $formula = str_replace(",", ".", $result->getFormula());
631 }
632
633 $this->db->insert("il_qpl_qst_fq_res", [
634 "result_id" => ['integer', $next_id],
635 "question_fi" => ['integer', $this->getId()],
636 "result" => ["text", $result->getResult()],
637 "range_min" => ["float", $result->getRangeMin()],
638 "range_max" => ["float", $result->getRangeMax()],
639 "tolerance" => ["float", $result->getTolerance()],
640 "unit_fi" => ['integer', (int) $tmp_result_unit],
641 "formula" => ["clob", $formula],
642 "resprecision" => ['integer', $result->getPrecision()],
643 "rating_simple" => ['integer', ($result->getRatingSimple()) ? 1 : 0],
644 "rating_sign" => ["float", ($result->getRatingSimple()) ? 0 : $result->getRatingSign()],
645 "rating_value" => ["float", ($result->getRatingSimple()) ? 0 : $result->getRatingValue()],
646 "rating_unit" => ["float", ($result->getRatingSimple()) ? 0 : $result->getRatingUnit()],
647 "points" => ["float", $result->getPoints()],
648 "result_type" => ['integer', (int) $result->getResultType()],
649 "range_min_txt" => ["text", $result->getRangeMinTxt()],
650 "range_max_txt" => ["text", $result->getRangeMaxTxt()]
651
652 ]);
653 }
654 // save result units
655 $affectedRows = $this->db->manipulateF(
656 "DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
657 ['integer'],
658 [$this->getId()]
659 );
660 foreach ($this->results as $result) {
661 foreach ($this->getResultUnits($result) as $unit) {
662 $next_id = $this->db->nextId('il_qpl_qst_fq_res_unit');
663 $affectedRows = $this->db->manipulateF(
664 "INSERT INTO il_qpl_qst_fq_res_unit (result_unit_id, question_fi, result, unit_fi) VALUES (%s, %s, %s, %s)",
665 ['integer', 'integer', 'text', 'integer'],
666 [
667 $next_id,
668 $this->getId(),
669 $result->getResult(),
670 $unit->getId()
671 ]
672 );
673 }
674 }
675
676 parent::saveToDb();
677 }
saveQuestionDataToDb(?int $original_id=null)

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ saveWorkingData()

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

Reimplemented from assQuestion.

Definition at line 882 of file class.assFormulaQuestion.php.

886 : bool {
887 if (is_null($pass)) {
888 $pass = ilObjTest::_getPass($active_id);
889 }
890
891 $answer = $this->getSolutionSubmit();
892 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
893 function () use ($answer, $active_id, $pass, $authorized) {
894 foreach ($answer as $key => $value) {
895 $matches = null;
896 if (preg_match('/^result_(\$r\d+)$/', $key, $matches) !== false) {
897 $queryResult = "SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND authorized = %s AND " . $this->db->like('value1', 'clob', $matches[1]);
898
899 if ($this->getStep() !== null) {
900 $queryResult .= " AND step = " . $this->db->quote((int) $this->getStep(), 'integer') . " ";
901 }
902
903 $result = $this->db->queryF(
904 $queryResult,
905 ['integer', 'integer', 'integer', 'integer'],
906 [$active_id, $pass, $this->getId(), (int) $authorized]
907 );
908 if ($result->numRows()) {
909 while ($row = $this->db->fetchAssoc($result)) {
910 $this->db->manipulateF(
911 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
912 ['integer', 'integer'],
913 [$row['solution_id'], (int) $authorized]
914 );
915 }
916 }
917
918 $this->saveCurrentSolution($active_id, $pass, $matches[1], str_replace(",", ".", $value), $authorized);
919 continue;
920 }
921
922 if (preg_match('/^result_(\$r\d+)_unit$/', $key, $matches) !== false) {
923 $queryResultUnit = "SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND authorized = %s AND " . $this->db->like('value1', 'clob', $matches[1] . "_unit");
924
925 if ($this->getStep() !== null) {
926 $queryResultUnit .= " AND step = " . $this->db->quote((int) $this->getStep(), 'integer') . " ";
927 }
928
929 $result = $this->db->queryF(
930 $queryResultUnit,
931 ['integer', 'integer', 'integer', 'integer'],
932 [$active_id, $pass, $this->getId(), (int) $authorized]
933 );
934 if ($result->numRows()) {
935 while ($row = $this->db->fetchAssoc($result)) {
936 $this->db->manipulateF(
937 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
938 ['integer', 'integer'],
939 [$row['solution_id'], (int) $authorized]
940 );
941 }
942 }
943
944 $this->saveCurrentSolution($active_id, $pass, $matches[1] . "_unit", $value, $authorized);
945 }
946 }
947 }
948 );
949
950 return true;
951 }
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
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:

◆ setId()

assFormulaQuestion::setId ( int  $id = -1)

Reimplemented from assQuestion.

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

1150 : void
1151 {
1152 parent::setId($id);
1153 $this->unitrepository->setConsumerId($this->getId());
1154 }

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

+ Here is the call graph for this function:

◆ setUnitrepository()

assFormulaQuestion::setUnitrepository ( \ilUnitConfigurationRepository  $unitrepository)

Definition at line 1156 of file class.assFormulaQuestion.php.

1156 : void
1157 {
1158 $this->unitrepository = $unitrepository;
1159 }

◆ solutionValuesToLog()

assFormulaQuestion::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 1346 of file class.assFormulaQuestion.php.

1349 : array {
1350 return array_reduce(
1351 $solution_values,
1352 function (array $c, array $v) use ($additional_info): array {
1353 if (str_starts_with($v['value1'], '$v')) {
1354 $var = $this->getVariable($v['value1']);
1355 if ($var === null) {
1356 $c[$v['value1']] = $additional_info->getNoneTag();
1357 return $c;
1358 }
1359 if ($var->getUnit() !== null) {
1360 $c[$v['value1']] = $v['value2'] . $var->getUnit()->getUnit();
1361 return $c;
1362 }
1363 }
1364
1365 if (strpos($v['value1'], '_unit')) {
1366 $unit = $this->getUnitrepository()->getUnit($v['value2']);
1367 $c[$v['value1']] = $unit->getUnit() ?? $additional_info->getNoneTag();
1368 return $c;
1369 }
1370
1371 $c[$v['value1']] = $v['value2'];
1372 return $c;
1373 },
1374 []
1375 );
1376 }

References $c, and ILIAS\Test\Logging\AdditionalInformationGenerator\getNoneTag().

+ Here is the call graph for this function:

◆ solutionValuesToText()

assFormulaQuestion::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 1378 of file class.assFormulaQuestion.php.

1378 : array
1379 {
1380 ksort($solution_values);
1381 return array_reduce(
1382 $solution_values,
1383 function (array $c, array $v): array {
1384 if (!str_starts_with($v['value1'], '$r')) {
1385 return $c;
1386 }
1387 if (!strpos($v['value1'], '_unit')) {
1388 $c[$v['value1']] = "{$v['value1']} = {$v['value2']}";
1389 return $c;
1390 }
1391 $k = substr($v['value1'], 0, -5);
1392 if (array_key_exists($k, $c)) {
1393 $c[$k] .= $v['value2'];
1394 }
1395 return $c;
1396 },
1397 []
1398 );
1399 }

References $c.

◆ substituteVariables()

assFormulaQuestion::substituteVariables ( array  $userdata,
bool  $graphicalOutput = false,
bool  $forsolution = false,
bool  $result_output = false,
array  $correctness_icons = [] 
)
Parameters
int[]$selections
string[]$correctness_icons
Returns
bool|mixed|string

Definition at line 324 of file class.assFormulaQuestion.php.

325 {
326 if ((count($this->results) == 0) && (count($this->variables) == 0)) {
327 return false;
328 }
329
330 $text = $this->getQuestion();
331
332 foreach ($this->fetchAllVariables($this->getQuestion()) as $varObj) {
333 if (isset($userdata[$varObj->getVariable()]) && $userdata[$varObj->getVariable()] !== '') {
334 $varObj->setValue($userdata[$varObj->getVariable()]);
335 }
336
337 $unit = (is_object($varObj->getUnit())) ? $varObj->getUnit()->getUnit() : "";
338
339 $val = '';
340 if ($varObj->getValue() !== null) {
341 $val = (strlen((string) $varObj->getValue()) > 8) ? strtoupper(sprintf("%e", $varObj->getValue())) : $varObj->getValue();
342 }
343
344 $text = preg_replace('/\$' . substr($varObj->getVariable(), 1) . '(?![0-9]+)/', $val . ' ' . $unit . '\1', $text);
345 }
346
348
349 if (preg_match_all('/(\$r\d+)/im', $this->getQuestion(), $rmatches)) {
350 foreach ($rmatches[1] as $result) {
351 $resObj = $this->getResult($result);
352 $value = "";
353 $frac_helper = '';
354 $userdata[$result]['result_type'] = $resObj->getResultType();
355 $is_frac = false;
356 if (
357 $resObj->getResultType() == assFormulaQuestionResult::RESULT_FRAC ||
358 $resObj->getResultType() == assFormulaQuestionResult::RESULT_CO_FRAC
359 ) {
360 $is_frac = true;
361 }
362 if (is_array($userdata) &&
363 isset($userdata[$result]) &&
364 isset($userdata[$result]['value'])) {
365 $input = $this->generateResultInputHTML($result, (string) $userdata[$result]['value'], $forsolution);
366 } elseif ($forsolution) {
367 $value = '';
368 if (!is_array($userdata)) {
369 $value = $resObj->calculateFormula($this->getVariables(), $this->getResults(), parent::getId());
370 $value = sprintf("%." . $resObj->getPrecision() . "f", $value);
371 }
372
373 if ($is_frac) {
375 if (is_array($value)) {
376 $frac_helper = $value[1];
377 $value = $value[0];
378 }
379 }
380
381 $input = $this->generateResultInputHTML($result, $value, true);
382 } else {
383 $input = $this->generateResultInputHTML($result, '', false);
384 }
385
386 $units = "";
387 $result_units = $this->getResultUnits($resObj);
388 if (count($result_units) > 0) {
389 if ($forsolution) {
390 if (is_array($userdata)) {
391 foreach ($result_units as $unit) {
392 if (isset($userdata[$result]["unit"]) && $userdata[$result]["unit"] == $unit->getId()) {
393 $units = $unit->getSanitizedUnit();
394 }
395 }
396 } elseif ($resObj->getUnit()) {
397 $units = $resObj->getUnit()->getSanitizedUnit();
398 }
399 } else {
400 $units = '<select name="result_' . $result . '_unit">';
401 $units .= '<option value="-1">' . $this->lng->txt("select_unit") . '</option>';
402 foreach ($result_units as $unit) {
403 $units .= '<option value="' . $unit->getId() . '"';
404 if (array_key_exists($result, $userdata) &&
405 is_array($userdata[$result]) &&
406 array_key_exists('unit', $userdata[$result])) {
407 if ($userdata[$result]["unit"] == $unit->getId()) {
408 $units .= ' selected="selected"';
409 }
410 }
411 $units .= '>' . $unit->getSanitizedUnit() . '</option>';
412 }
413 $units .= '</select>';
414 }
415 } else {
416 $units = "";
417 }
418 switch ($resObj->getResultType()) {
420 $units .= ' ' . $this->lng->txt('expected_result_type') . ': ' . $this->lng->txt('result_dec');
421 break;
423 if ($frac_helper !== '') {
424 $units .= ' &asymp; ' . $frac_helper . ', ';
425 } elseif (is_array($userdata) &&
426 array_key_exists($result, $userdata) &&
427 array_key_exists('frac_helper', $userdata[$result]) &&
428 is_string($userdata[$result]["frac_helper"])) {
429 if (!str_contains($value, '/')) {
430 $units .= ' &asymp; ' . $userdata[$result]["frac_helper"] . ', ';
431 }
432 }
433 $units .= ' ' . $this->lng->txt('expected_result_type') . ': ' . $this->lng->txt('result_frac');
434 break;
436 if ($frac_helper !== '') {
437 $units .= ' &asymp; ' . $frac_helper . ', ';
438 } elseif (isset($userdata[$result]["frac_helper"]) && is_array($userdata) && $userdata[$result]["frac_helper"] !== '') {
439 if (!str_contains($value, '/')) {
440 $units .= ' &asymp; ' . $userdata[$result]["frac_helper"] . ', ';
441 }
442 }
443 $units .= ' ' . $this->lng->txt('expected_result_type') . ': ' . $this->lng->txt('result_co_frac');
444 break;
446 break;
447 }
448 $checkSign = "";
449 if ($graphicalOutput) {
450 $resunit = null;
451 $user_value = '';
452 if (is_array($userdata) && is_array($userdata[$result])) {
453 if (isset($userdata[$result]["unit"]) && $userdata[$result]["unit"] > 0) {
454 $resunit = $this->getUnitrepository()->getUnit($userdata[$result]["unit"]);
455 }
456
457 if (isset($userdata[$result]["value"])) {
458 $user_value = $userdata[$result]["value"];
459 }
460 }
461
462 $template = new ilTemplate("tpl.il_as_qpl_formulaquestion_output_solution_image.html", true, true, 'components/ILIAS/TestQuestionPool');
463
464 $correctness_icon = $correctness_icons['not_correct'];
465 if ($resObj->isCorrect($this->getVariables(), $this->getResults(), $user_value, $resunit)) {
466 $correctness_icon = $correctness_icons['correct'];
467 }
468 $template->setCurrentBlock("icon_ok");
469 $template->setVariable("ICON_OK", $correctness_icon);
470 $template->parseCurrentBlock();
471
472 $checkSign = $template->get();
473 }
474 $resultOutput = "";
475 if ($result_output) {
476 $template = new ilTemplate("tpl.il_as_qpl_formulaquestion_output_solution_result.html", true, true, 'components/ILIAS/TestQuestionPool');
477
478 if (is_array($userdata) &&
479 array_key_exists($resObj->getResult(), $userdata) &&
480 array_key_exists('value', $userdata[$resObj->getResult()])) {
481 $found = $resObj->getResultInfo(
482 $this->getVariables(),
483 $this->getResults(),
484 $userdata[$resObj->getResult()]["value"],
485 $userdata[$resObj->getResult()]["unit"] ?? null,
486 $this->getUnitrepository()->getUnits()
487 );
488 } else {
489 $found = $resObj->getResultInfo(
490 $this->getVariables(),
491 $this->getResults(),
492 $resObj->calculateFormula($this->getVariables(), $this->getResults(), parent::getId()),
493 is_object($resObj->getUnit()) ? $resObj->getUnit()->getId() : null,
494 $this->getUnitrepository()->getUnits()
495 );
496 }
497 $resulttext = "(";
498 if ($resObj->getRatingSimple()) {
499 if ($frac_helper) {
500 $resulttext .= "n/a";
501 } else {
502 $resulttext .= $found['points'] . " " . (($found['points'] == 1) ? $this->lng->txt('point') : $this->lng->txt('points'));
503 }
504 } else {
505 $resulttext .= $this->lng->txt("rated_sign") . " " . (($found['sign']) ? $found['sign'] : 0) . " " . (($found['sign'] == 1) ? $this->lng->txt('point') : $this->lng->txt('points')) . ", ";
506 $resulttext .= $this->lng->txt("rated_value") . " " . (($found['value']) ? $found['value'] : 0) . " " . (($found['value'] == 1) ? $this->lng->txt('point') : $this->lng->txt('points')) . ", ";
507 $resulttext .= $this->lng->txt("rated_unit") . " " . (($found['unit']) ? $found['unit'] : 0) . " " . (($found['unit'] == 1) ? $this->lng->txt('point') : $this->lng->txt('points'));
508 }
509
510 $resulttext .= ")";
511 $template->setVariable("RESULT_OUTPUT", $resulttext);
512
513 $resultOutput = $template->get();
514 }
515 $text = preg_replace('/\$' . substr($result, 1) . '(?![0-9]+)/', $input . ' ' . $units . ' ' . $checkSign . ' ' . $resultOutput . ' ' . '\1', $text);
516 }
517 }
518 return $text;
519 }
generateResultInputHTML(string $result_key, string $result_value, bool $forsolution)
purifyAndPrepareTextAreaOutput(string $content)
special template class to simplify handling of ITX/PEAR

References $text, assFormulaQuestionResult\convertDecimalToCoprimeFraction(), ILIAS\Survey\Mode\getId(), ILIAS\Repository\lng(), assFormulaQuestionResult\RESULT_CO_FRAC, assFormulaQuestionResult\RESULT_DEC, assFormulaQuestionResult\RESULT_FRAC, and assFormulaQuestionResult\RESULT_NO_SELECTION.

+ Here is the call graph for this function:

◆ toLog()

assFormulaQuestion::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 1278 of file class.assFormulaQuestion.php.

1278 : array
1279 {
1280 return [
1281 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->getQuestionType(),
1282 AdditionalInformationGenerator::KEY_QUESTION_TITLE => $this->getTitleForHTMLOutput(),
1283 AdditionalInformationGenerator::KEY_QUESTION_TEXT => $this->formatSAQuestion($this->getQuestion()),
1284 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_VARIABLES => $this->buildVariablesForLog(
1285 $this->getVariables(),
1286 $additional_info->getNoneTag()
1287 ),
1288 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_RESULTS => $this->buildResultsForLog(
1289 $this->getResults(),
1290 $additional_info->getNoneTag()
1291 ),
1292 AdditionalInformationGenerator::KEY_FEEDBACK => [
1293 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1294 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1295 ]
1296 ];
1297 }
buildVariablesForLog(array $variables, string $none_tag)
buildResultsForLog(array $results, string $none_tag)

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

+ Here is the call graph for this function:

◆ validateSolutionSubmit()

assFormulaQuestion::validateSolutionSubmit ( )

Reimplemented from assQuestion.

Definition at line 1196 of file class.assFormulaQuestion.php.

1196 : bool
1197 {
1198 foreach ($this->getSolutionSubmit() as $value) {
1199 if ($value && !$this->isValidSolutionResultValue($value)) {
1200 $this->tpl->setOnScreenMessage(
1201 'failure',
1202 $this->lng->txt("err_no_numeric_value"),
1203 true
1204 );
1205 return false;
1206 }
1207 }
1208
1209 return true;
1210 }
isValidSolutionResultValue(string $submittedValue)

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

Field Documentation

◆ $pass_presented_variables_repo

PassPresentedVariablesRepo assFormulaQuestion::$pass_presented_variables_repo
protected

Definition at line 37 of file class.assFormulaQuestion.php.

◆ $results

array assFormulaQuestion::$results
private

Definition at line 34 of file class.assFormulaQuestion.php.

Referenced by getResults().

◆ $resultunits

array assFormulaQuestion::$resultunits
private

Definition at line 35 of file class.assFormulaQuestion.php.

◆ $unitrepository

ilUnitConfigurationRepository assFormulaQuestion::$unitrepository
private

Definition at line 36 of file class.assFormulaQuestion.php.

◆ $variables

array assFormulaQuestion::$variables
private

Definition at line 33 of file class.assFormulaQuestion.php.

Referenced by getVariables().


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