ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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)
 
 resolveVariableSolutionValuesForPass (int $active_id, int $pass, array $user_solution=[])
 
 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)
 
 buildBasicUserSolutionsArray (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)
 
- 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...
 
 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

 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 34 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 42 of file class.assFormulaQuestion.php.

48 {
50 $this->variables = [];
51 $this->results = [];
52 $this->resultunits = [];
53 $this->unitrepository = new ilUnitConfigurationRepository();
54 $this->pass_presented_variables_repo = new PassPresentedVariablesRepo($this->db);
55 }
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 98 of file class.assFormulaQuestion.php.

98 : void
99 {
100 $this->results[$result->getResult()] = $result;
101 }

References assFormulaQuestionResult\getResult().

+ Here is the call graph for this function:

◆ addResultUnit()

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

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

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

◆ addResultUnits()

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

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

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

◆ addVariable()

assFormulaQuestion::addVariable ( assFormulaQuestionVariable  $variable)

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

75 : void
76 {
77 $this->variables[$variable->getVariable()] = $variable;
78 }

References assFormulaQuestionVariable\getVariable().

+ Here is the call graph for this function:

◆ buildBasicUserSolutionsArray()

assFormulaQuestion::buildBasicUserSolutionsArray ( int  $active_id,
?int  $pass 
)

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

1459 : array {
1460 return array_reduce(
1461 $this->getSolutionValues($active_id, $pass),
1462 function (array $c, array $v): array {
1463 if (preg_match('/^(\$v\d+)$/', $v['value1'], $matches)) {
1464 $c[$matches[1]] = $v['value2'];
1465 return $c;
1466 }
1467
1468 if (preg_match('/^(\$r\d+)$/', $v['value1'], $matches)) {
1469 if (!array_key_exists($matches[1], $c)) {
1470 $c[$matches[1]] = [];
1471 }
1472 $c[$matches[1]]['value'] = $v['value2'];
1473 return $c;
1474 }
1475
1476 if (preg_match('/^(\$r\d+)_unit$/', $v['value1'], $matches)) {
1477 if (!array_key_exists($matches[1], $c)) {
1478 $c[$matches[1]] = [];
1479 }
1480 $c[$matches[1]]['unit'] = $v['value2'];
1481 return $c;
1482 }
1483
1484 return $c;
1485 },
1486 [
1487 'active_id' => $active_id,
1488 'pass' => $pass
1489 ]
1490 );
1491 }
getSolutionValues(int $active_id, ?int $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.

References Vendor\Package\$c.

◆ buildResultsForLog()

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

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

1339 : array
1340 {
1341 return array_reduce(
1342 $results,
1343 function (array $c, assFormulaQuestionResult $r) use ($none_tag): array {
1344 $c[$r->getResult()] = [
1345 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_RESULT_TYPE => $r->getResultType(),
1346 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_FORMULA => $r->getFormula(),
1347 AdditionalInformationGenerator::KEY_QUESTION_REACHABLE_POINTS => $r->getPoints(),
1348 AdditionalInformationGenerator::KEY_QUESTION_LOWER_LIMIT => $r->getRangeMinTxt(),
1349 AdditionalInformationGenerator::KEY_QUESTION_UPPER_LIMIT => $r->getRangeMaxTxt(),
1350 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_TOLERANCE => $r->getTolerance(),
1351 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_PRECISION => $r->getPrecision(),
1352 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_UNIT => $r->getUnit() ?? $none_tag
1353 ];
1354 return $c;
1355 },
1356 []
1357 );
1358 }

References Vendor\Package\$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 1317 of file class.assFormulaQuestion.php.

1317 : array
1318 {
1319 return array_reduce(
1320 $variables,
1321 function (array $c, assFormulaQuestionVariable $v) use ($none_tag): array {
1322 $c[$v->getVariable()] = [
1323 AdditionalInformationGenerator::KEY_QUESTION_LOWER_LIMIT => $v->getRangeMinTxt(),
1324 AdditionalInformationGenerator::KEY_QUESTION_UPPER_LIMIT => $v->getRangeMaxTxt(),
1325 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_PRECISION => $v->getPrecision(),
1326 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_INTPRECISION => $v->getIntprecision(),
1327 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_UNIT => $v->getUnit() ?? $none_tag
1328 ];
1329 return $c;
1330 },
1331 []
1332 );
1333 }

References Vendor\Package\$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 814 of file class.assFormulaQuestion.php.

818 : float {
819 if ($pass === null) {
820 $pass = $this->getSolutionMaxPass($active_id);
821 }
822 $solutions = $this->getSolutionValues($active_id, $pass, $authorized_solution);
823 $user_solution = [];
824 foreach ($solutions as $solution_value) {
825 if (preg_match('/^(\$v\d+)$/', $solution_value['value1'], $matches)) {
826 $user_solution[$matches[1]] = $solution_value['value2'];
827 $var_obj = $this->getVariable($solution_value['value1']);
828 $var_obj->setValue($solution_value['value2']);
829 continue;
830 }
831
832 if (preg_match('/^(\$r\d+)$/', $solution_value['value1'], $matches)) {
833 if (!array_key_exists($matches[1], $user_solution)) {
834 $user_solution[$matches[1]] = [];
835 }
836 $user_solution[$matches[1]]['value'] = $solution_value['value2'];
837 continue;
838 }
839
840 if (preg_match('/^(\$r\d+)_unit$/', $solution_value['value1'], $matches)) {
841 if (!array_key_exists($matches[1], $user_solution)) {
842 $user_solution[$matches[1]] = [];
843 }
844 $user_solution[$matches[1]]['unit'] = $this->unitrepository->getUnit(
845 $this->refinery->kindlyTo()->int()->transform($solution_value['value2']),
846 );
847 }
848 }
849
850 $points = 0;
851 foreach ($this->getResults() as $result) {
852 $points += $result->getReachedPoints(
853 $this->getVariables(),
854 $this->getResults(),
855 $user_solution[$result->getResult()]['value'] ?? '',
856 $user_solution[$result->getResult()]['unit'] ?? null
857 );
858 }
859
860 return (float) $points;
861 }
getVariable(string $variable)
getSolutionMaxPass(int $active_id)

◆ calculateReachedPointsFromPreviewSession()

assFormulaQuestion::calculateReachedPointsFromPreviewSession ( ilAssQuestionPreviewSession  $previewSession)

Reimplemented from assQuestion.

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

864 {
865 $user_solution = $previewSession->getParticipantsSolution();
866
867 $points = 0;
868 foreach ($this->getResults() as $result) {
869 $result_unit = "{$result->getResult()}_unit";
870 $answer_unit_id = isset($user_solution[$result_unit]) && is_numeric($user_solution[$result_unit])
871 ? (int) $user_solution[$result_unit]
872 : null;
873
874 $points += $result->getReachedPoints(
875 $this->getVariables(),
876 $this->getResults(),
877 $user_solution[$result->getResult()] ?? '',
878 $answer_unit_id !== null ? $this->unitrepository->getUnit($answer_unit_id) : null
879 );
880 }
881 return $this->ensureNonNegativePoints($points);
882 }
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 560 of file class.assFormulaQuestion.php.

560 : bool
561 {
562 $result_units = $this->getResultUnits($result);
563 $resultunit = $result->getUnit();
564 $similar_units = 0;
565 foreach ($result_units as $unit) {
566 if (is_object($resultunit)) {
567 if ($resultunit->getId() != $unit->getId()) {
568 if ($resultunit->getBaseUnit() && $unit->getBaseUnit()) {
569 if ($resultunit->getBaseUnit() == $unit->getBaseUnit()) {
570 return false;
571 }
572 }
573 if ($resultunit->getBaseUnit()) {
574 if ($resultunit->getBaseUnit() == $unit->getId()) {
575 return false;
576 }
577 }
578 if ($unit->getBaseUnit()) {
579 if ($unit->getBaseUnit() == $resultunit->getId()) {
580 return false;
581 }
582 }
583 }
584 }
585 }
586 return true;
587 }
getResultUnits(assFormulaQuestionResult $result)

References assFormulaQuestionResult\getUnit().

+ Here is the call graph for this function:

◆ checkForDuplicateResults()

assFormulaQuestion::checkForDuplicateResults ( )

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

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

◆ checkForDuplicateVariables()

assFormulaQuestion::checkForDuplicateVariables ( )

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

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

◆ clearResults()

assFormulaQuestion::clearResults ( )

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

80 : void
81 {
82 $this->results = [];
83 }

◆ clearVariables()

assFormulaQuestion::clearVariables ( )

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

57 : void
58 {
59 $this->variables = [];
60 }

◆ cloneQuestionTypeSpecificProperties()

assFormulaQuestion::cloneQuestionTypeSpecificProperties ( \assQuestion  $target)
protected

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

796 : \assQuestion {
797 $this->unitrepository->cloneUnits($this->getId(), $target->getId());
798 return $target;
799 }

◆ deleteAnswers()

assFormulaQuestion::deleteAnswers ( int  $question_id)

Reimplemented from assQuestion.

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

1060 : void
1061 {
1062 $affectedRows = $this->db->manipulateF(
1063 "DELETE FROM il_qpl_qst_fq_var WHERE question_fi = %s",
1064 ['integer'],
1065 [$question_id]
1066 );
1067
1068 $affectedRows = $this->db->manipulateF(
1069 "DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s",
1070 ['integer'],
1071 [$question_id]
1072 );
1073
1074 $affectedRows = $this->db->manipulateF(
1075 "DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
1076 ['integer'],
1077 [$question_id]
1078 );
1079
1080 $affectedRows = $this->db->manipulateF(
1081 "DELETE FROM il_qpl_qst_fq_ucat WHERE question_fi = %s",
1082 ['integer'],
1083 [$question_id]
1084 );
1085
1086 $affectedRows = $this->db->manipulateF(
1087 "DELETE FROM il_qpl_qst_fq_unit WHERE question_fi = %s",
1088 ['integer'],
1089 [$question_id]
1090 );
1091 }

◆ fetchAllResults()

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

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

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

◆ fetchAllVariables()

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

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

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

References Vendor\Package\$c.

◆ fromNormalized()

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

Reimplemented from assQuestion.

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

1510 : static
1511 {
1512 $clone = parent::fromNormalized($normalized, $transformations);
1513
1514 foreach ($normalized['variables'] as $key => $data) {
1515 $dummy = new assFormulaQuestionVariable('', '', '');
1516 $clone->variables[$key] = $transformations->denormalize($data, $dummy);
1517 }
1518
1519 foreach ($normalized['results'] as $key => $data) {
1520 $dummy = new assFormulaQuestionResult('', '', '', 0, null, '', 0, 0);
1521 $clone->results[$key] = $transformations->denormalize($data, $dummy);
1522 }
1523
1524 return $clone;
1525 }
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)
$data
Definition: storeScorm.php:45

References $data, and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\denormalize().

+ Here is the call graph for this function:

◆ generateResultInputHTML()

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

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

540 : string
541 {
542 if ($forsolution) {
543 return '<span class="ilc_qinput_TextInput solutionbox">'
545 . '</span>';
546 }
547 $input = '<input class="ilc_qinput_TextInput" type="text"';
548 $input .= 'spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off"';
549 $input .= 'name="result_' . $result_key . '"';
550 $input .= ' value="' . $result_value . '"/>';
551 return $input;
552 }
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 1050 of file class.assFormulaQuestion.php.

1050 : string
1051 {
1052 return "";
1053 }

◆ getAllResultUnits()

assFormulaQuestion::getAllResultUnits ( )

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

153 : array
154 {
155 return $this->resultunits;
156 }

◆ getAnswerTableName()

assFormulaQuestion::getAnswerTableName ( )

Reimplemented from assQuestion.

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

1055 : string
1056 {
1057 return "";
1058 }

◆ 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 1283 of file class.assFormulaQuestion.php.

1284 {
1285 if ($index !== null) {
1286 return $this->getResult('$r' . ($index + 1));
1287 } else {
1288 return $this->getResults();
1289 }
1290 }

◆ getBestSolution()

assFormulaQuestion::getBestSolution ( array  $solutions)

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

1099 : array
1100 {
1101 $user_solution = [];
1102
1103 foreach ($solutions as $solution_value) {
1104 if (preg_match('/^(\$v\d+)$/', $solution_value['value1'], $matches)) {
1105 $user_solution[$matches[1]] = $solution_value['value2'];
1106 $varObj = $this->getVariable($matches[1]);
1107 $varObj->setValue($solution_value['value2']);
1108 } elseif (preg_match('/^(\$r\d+)$/', $solution_value['value1'], $matches)) {
1109 if (!array_key_exists($matches[1], $user_solution)) {
1110 $user_solution[$matches[1]] = [];
1111 }
1112 $user_solution[$matches[1]]['value'] = $solution_value['value2'];
1113 } elseif (preg_match('/^(\$r\d+)_unit$/', $solution_value['value1'], $matches)) {
1114 if (!array_key_exists($matches[1], $user_solution)) {
1115 $user_solution[$matches[1]] = [];
1116 }
1117 $user_solution[$matches[1]]['unit'] = (int) $solution_value['value2'];
1118 }
1119 }
1120 foreach ($this->getResults() as $result) {
1121 $resVal = $result->calculateFormula($this->getVariables(), $this->getResults(), $this->getId(), false);
1122
1123 $unit = $result->getUnit();
1124 if ($unit instanceof assFormulaQuestionUnit) {
1125 $user_solution[$result->getResult()]['unit'] = $unit->getId();
1126 $user_solution[$result->getResult()]['value'] = $resVal;
1127 } elseif ($unit === null) {
1128 $unit_factor = 1;
1129 // there is no fix result_unit, any "available unit" is accepted
1130
1131 $available_units = $result->getAvailableResultUnits($this->getId());
1132 $result_name = $result->getResult();
1133
1134 if (
1135 isset($available_units[$result_name])
1136 && in_array($user_solution[$result_name]['unit'] ?? null, $available_units[$result_name])
1137 ) {
1138 $unit_factor = assFormulaQuestionUnit::lookupUnitFactor($user_solution[$result_name]['unit']);
1139 }
1140
1141 try {
1142 $user_solution[$result->getResult()]['value'] = ilMath::_div($resVal, $unit_factor, 55);
1143 } catch (ilMathDivisionByZeroException $ex) {
1144 $user_solution[$result->getResult()]['value'] = 0;
1145 }
1146 }
1147 if ($result->getResultType() == assFormulaQuestionResult::RESULT_CO_FRAC
1148 || $result->getResultType() == assFormulaQuestionResult::RESULT_FRAC) {
1150 if (is_array($value)) {
1151 $user_solution[$result->getResult()]['value'] = $value[0];
1152 $user_solution[$result->getResult()]['frac_helper'] = $value[1];
1153 } else {
1154 $user_solution[$result->getResult()]['value'] = $value;
1155 $user_solution[$result->getResult()]['frac_helper'] = null;
1156 }
1157 } else {
1158 $user_solution[$result->getResult()]['value'] = round((float) $user_solution[$result->getResult()]['value'], $result->getPrecision());
1159 }
1160 }
1161 return $user_solution;
1162 }
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(), ILIAS\Repository\int(), 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 1415 of file class.assFormulaQuestion.php.

1415 : array
1416 {
1417 $best_solution = $this->getBestSolution($this->getSolutionValues($active_id, $pass));
1418 return array_map(
1419 function (string $v) use ($best_solution): string {
1420 $placeholder_definition = $best_solution[$v];
1421 $solution = "{$v} = " . ($placeholder_definition['value'] ?? $placeholder_definition);
1422 if (!isset($placeholder_definition['unit'])) {
1423 return $solution;
1424 }
1425
1426 $unit = $this->unitrepository->getUnit($placeholder_definition['unit']);
1427 if ($unit === null) {
1428 return $unit;
1429 }
1430
1431 return "{$solution}{$unit->getUnit()}";
1432 },
1433 array_keys($best_solution)
1434 );
1435 }
getBestSolution(array $solutions)

◆ getExpressionTypes()

assFormulaQuestion::getExpressionTypes ( )

◆ getInitialVariableSolutionValues()

assFormulaQuestion::getInitialVariableSolutionValues ( )

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

306 : array
307 {
308 foreach ($this->fetchAllResults($this->getQuestion()) as $resObj) {
309 $resObj->findValidRandomVariables($this->getVariables(), $this->getResults());
310 }
311
312 $variableSolutionValues = [];
313
314 foreach ($this->fetchAllVariables($this->getQuestion()) as $varObj) {
315 $variableSolutionValues[$varObj->getVariable()] = $varObj->getValue();
316 }
317
318 return $variableSolutionValues;
319 }
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 805 of file class.assFormulaQuestion.php.

805 : float
806 {
807 $points = 0;
808 foreach ($this->results as $result) {
809 $points += $result->getPoints();
810 }
811 return $points;
812 }

◆ getOperators()

assFormulaQuestion::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

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

1226 : array
1227 {
1229 }
static getOperatorsByExpression(string $expression)

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ Here is the call graph for this function:

◆ getQuestionType()

assFormulaQuestion::getQuestionType ( )

Reimplemented from assQuestion.

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

1045 : string
1046 {
1047 return "assFormulaQuestion";
1048 }

◆ getResult()

assFormulaQuestion::getResult ( string  $result)

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

91 {
92 if (array_key_exists($result, $this->results)) {
93 return $this->results[$result];
94 }
95 return null;
96 }

◆ getResults()

assFormulaQuestion::getResults ( )

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

85 : array
86 {
87 return $this->results;
88 }

References $results.

◆ getResultUnits()

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

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

136 : array
137 {
138 if (!isset($this->resultunits[$result->getResult()])) {
139 return [];
140 }
141
142 $result_units = $this->resultunits[$result->getResult()];
143
144 usort(
145 $result_units,
147 $a->getSequence() <=> $b->getSequence()
148 );
149
150 return $result_units;
151 }
$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 1093 of file class.assFormulaQuestion.php.

1093 : string
1094 {
1095 $text = parent::getRTETextWithMediaObjects();
1096 return $text;
1097 }
$text
Definition: xapiexit.php:21

References $text.

◆ getSolutionSubmit()

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

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

1183 : array
1184 {
1185 $solutionSubmit = [];
1186
1187 $post = $this->dic->http()->wrapper()->post();
1188
1189 foreach ($this->getResults() as $index => $a) {
1190 $key = "result_$index";
1191 if ($post->has($key)) {
1192 $value = $post->retrieve(
1193 $key,
1194 $this->dic->refinery()->kindlyTo()->string()
1195 );
1196
1197 $solutionSubmit[$key] = $value;
1198 }
1199 if ($post->has($key . "_unit")) {
1200 $value = $post->retrieve(
1201 $key . "_unit",
1202 $this->dic->refinery()->kindlyTo()->string()
1203 );
1204 $solutionSubmit[$key . "_unit"] = $value;
1205 }
1206 }
1207 return $solutionSubmit;
1208 }

References Vendor\Package\$a.

◆ getUnitrepository()

assFormulaQuestion::getUnitrepository ( )

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

1176 {
1177 return $this->unitrepository;
1178 }
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 1240 of file class.assFormulaQuestion.php.

1244 $result = new ilUserQuestionResult($this, $active_id, $pass);
1245
1246 $maxStep = $this->lookupMaxStep($active_id, $pass);
1247 if ($maxStep > 0) {
1248 $data = $this->db->queryF(
1249 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1250 ['integer', 'integer', 'integer','integer'],
1251 [$active_id, $pass, $this->getId(), $maxStep]
1252 );
1253 } else {
1254 $data = $this->db->queryF(
1255 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
1256 ['integer', 'integer', 'integer'],
1257 [$active_id, $pass, $this->getId()]
1258 );
1259 }
1260
1261 while ($row = $this->db->fetchAssoc($data)) {
1262 if (strstr($row['value1'], '$r') && $row['value2'] != null) {
1263 $result->addKeyValue(str_replace('$r', "", $row['value1']), $row['value2']);
1264 }
1265 }
1266
1267 $points = $this->calculateReachedPoints($active_id, $pass);
1268 $max_points = $this->getMaximumPoints();
1269
1270 $result->setReachedPercentage(($points / $max_points) * 100);
1271
1272 return $result;
1273 }
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 67 of file class.assFormulaQuestion.php.

68 {
69 if (array_key_exists($variable, $this->variables)) {
70 return $this->variables[$variable];
71 }
72 return null;
73 }

◆ getVariables()

assFormulaQuestion::getVariables ( )

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

62 : array
63 {
64 return $this->variables;
65 }

References $variables.

◆ getVariablesAsTextArray()

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

Reimplemented from assQuestion.

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

1437 : array
1438 {
1440 $active_id,
1441 $pass,
1442 $this->buildBasicUserSolutionsArray($active_id, $pass)
1443 );
1444 return array_map(
1445 function (string $v) use ($variables): string {
1446 $variable = "{$v} = {$variables[$v]}";
1447 if ($this->getVariable($v)->getUnit() !== null) {
1448 $variable .= $this->getVariable($v)->getUnit()->getUnit();
1449 }
1450 return $variable;
1451 },
1452 array_keys($variables)
1453 );
1454 }
buildBasicUserSolutionsArray(int $active_id, ?int $pass)
resolveVariableSolutionValuesForPass(int $active_id, int $pass, array $user_solution=[])

◆ hasRequiredVariableSolutionValues()

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

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

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

◆ hasResultUnit()

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

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

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

◆ 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 593 of file class.assFormulaQuestion.php.

593 : bool
594 {
595 if (($this->title) and ($this->author) and ($this->question) and ($this->getMaximumPoints() > 0)) {
596 return true;
597 } else {
598 return false;
599 }
600 }

◆ isValidSolutionResultValue()

assFormulaQuestion::isValidSolutionResultValue ( string  $submittedValue)
protected

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

884 : bool
885 {
886 $submittedValue = str_replace(',', '.', $submittedValue);
887
888 if (is_numeric($submittedValue)) {
889 return true;
890 }
891
892 if (preg_match('/^[-+]?\d+\/\d+$/', $submittedValue)) {
893 return true;
894 }
895
896 return false;
897 }

◆ loadFromDb()

assFormulaQuestion::loadFromDb ( int  $question_id)

Reimplemented from assQuestion.

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

698 : void
699 {
700 $result = $this->db->queryF(
701 "SELECT qpl_questions.* FROM qpl_questions WHERE question_id = %s",
702 ['integer'],
703 [$question_id]
704 );
705 if ($result->numRows() == 1) {
706 $data = $this->db->fetchAssoc($result);
707 $this->setId($question_id);
708 $this->setTitle((string) $data["title"]);
709 $this->setComment((string) $data["description"]);
710 $this->setPoints($data['points']);
711 $this->setOriginalId($data["original_id"]);
712 $this->setObjId($data["obj_fi"]);
713 $this->setAuthor($data["author"]);
714 $this->setOwner($data["owner"]);
715
716 try {
717 $this->setLifecycle(new ilAssQuestionLifecycle($data['lifecycle']));
720 }
721
722 try {
723 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
725 }
726
727 $this->unitrepository = new ilUnitConfigurationRepository($question_id);
728
729 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc((string) $data["question_text"], 1));
730
731 // load variables
732 $result = $this->db->queryF(
733 "SELECT * FROM il_qpl_qst_fq_var WHERE question_fi = %s",
734 ['integer'],
735 [$question_id]
736 );
737 if ($result->numRows() > 0) {
738 while ($data = $this->db->fetchAssoc($result)) {
739 $varObj = new assFormulaQuestionVariable(
740 $data['variable'],
741 $data['range_min_txt'],
742 $data['range_max_txt'],
743 $this->getUnitrepository()->getUnit($data['unit_fi']),
744 $data['varprecision'],
745 $data['intprecision']
746 );
747 $this->addVariable($varObj);
748 }
749 }
750 // load results
751 $result = $this->db->queryF(
752 "SELECT * FROM il_qpl_qst_fq_res WHERE question_fi = %s",
753 ['integer'],
754 [$question_id]
755 );
756 if ($result->numRows() > 0) {
757 while ($data = $this->db->fetchAssoc($result)) {
758 $resObj = new assFormulaQuestionResult(
759 $data['result'],
760 $data['range_min_txt'],
761 $data['range_max_txt'],
762 $data['tolerance'],
763 $this->getUnitrepository()->getUnit($data['unit_fi']),
764 $data['formula'],
765 $data['points'],
766 $data['resprecision'],
767 $data['rating_simple'] === 1,
768 $data['rating_sign'],
769 $data['rating_value'],
770 $data['rating_unit']
771 );
772 $resObj->setResultType($data['result_type']);
773 $this->addResult($resObj);
774 }
775 }
776
777 // load result units
778 $result = $this->db->queryF(
779 "SELECT * FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
780 ['integer'],
781 [$question_id]
782 );
783 if ($result->numRows() > 0) {
784 while ($data = $this->db->fetchAssoc($result)) {
785 $unit = $this->getUnitrepository()->getUnit($data["unit_fi"]);
786 $resObj = $this->getResult($data["result"]);
787 $this->addResultUnit($resObj, $unit);
788 }
789 }
790 }
791 parent::loadFromDb($question_id);
792 }
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(), 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 973 of file class.assFormulaQuestion.php.

973 : array
974 {
975 $return = [
976 'authorized' => false,
977 'intermediate' => false
978 ];
979
980 $query = "
981 SELECT authorized, COUNT(*) cnt
982 FROM tst_solutions
983 WHERE active_fi = " . $this->db->quote($active_id, 'integer') . "
984 AND question_fi = " . $this->db->quote($this->getId(), 'integer') . "
985 AND pass = " . $this->db->quote($pass, 'integer') . "
986 AND value1 like '\$r%'
987 AND value2 is not null
988 AND value2 <> ''
989 ";
990
991 if ($this->getStep() !== null) {
992 $query .= " AND step = " . $this->db->quote((int) $this->getStep(), 'integer') . " ";
993 }
994
995 $query .= "
996 GROUP BY authorized
997 ";
998
999 $result = $this->db->query($query);
1000
1001 while ($row = $this->db->fetchAssoc($result)) {
1002 if ($row['authorized']) {
1003 $return['authorized'] = $row['cnt'] > 0;
1004 } else {
1005 $return['intermediate'] = $row['cnt'] > 0;
1006 }
1007 }
1008 return $return;
1009 }

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ parseQuestionText()

assFormulaQuestion::parseQuestionText ( )

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

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

◆ removeExistingSolutions()

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

Reimplemented from assQuestion.

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

1011 : int
1012 {
1013 $query = "
1014 DELETE FROM tst_solutions
1015 WHERE active_fi = " . $this->db->quote($active_id, 'integer') . "
1016 AND question_fi = " . $this->db->quote($this->getId(), 'integer') . "
1017 AND pass = " . $this->db->quote($pass, 'integer') . "
1018 AND value1 like '\$r%'
1019 ";
1020
1021 if ($this->getStep() !== null) {
1022 $query .= " AND step = " . $this->db->quote((int) $this->getStep(), 'integer') . " ";
1023 }
1024
1025 return $this->db->manipulate($query);
1026 }

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ resolveVariableSolutionValuesForPass()

assFormulaQuestion::resolveVariableSolutionValuesForPass ( int  $active_id,
int  $pass,
array  $user_solution = [] 
)

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

275 : array {
276 $question_id = $this->getId();
277 $values_from_db = $this->pass_presented_variables_repo->getFor(
278 $question_id,
279 $active_id,
280 $pass
281 );
282 if ($values_from_db !== null) {
283 return $values_from_db;
284 }
285
286 $values = array_filter(
287 $user_solution,
288 fn(string $v): bool => str_starts_with($v, '$v'),
289 ARRAY_FILTER_USE_KEY
290 );
291
292 if ($values === []) {
293 $values = $this->getInitialVariableSolutionValues();
294 }
295
296 $this->pass_presented_variables_repo->store(
297 $question_id,
298 $active_id,
299 $pass,
300 $values
301 );
302
303 return $values;
304 }

◆ saveCurrentSolution()

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

Reimplemented from assQuestion.

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

321 : int
322 {
323 $init_solution_vars = $this->resolveVariableSolutionValuesForPass($active_id, $pass);
324 foreach ($init_solution_vars as $val1 => $val2) {
325 $this->db->manipulateF(
326 "DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s AND value1 = %s",
327 ['integer', 'integer','integer', 'text'],
328 [$active_id, $this->getId(), $pass, $val1]
329 );
330 parent::saveCurrentSolution($active_id, $pass, $val1, $val2, $authorized);
331 }
332 return parent::saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized, $tstamp);
333 }

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

1028 : void
1029 {
1030 $userSolution = $previewSession->getParticipantsSolution();
1031
1032 foreach ($this->getSolutionSubmit() as $key => $val) {
1033 $matches = null;
1034
1035 if (preg_match('/^result_(\$r\d+)$/', $key, $matches)) {
1036 $userSolution[$matches[1]] = $val;
1037 } elseif (preg_match('/^result_(\$r\d+)_unit$/', $key, $matches)) {
1038 $userSolution[$matches[1] . "_unit"] = $val;
1039 }
1040 }
1041
1042 $previewSession->setParticipantsSolution($userSolution);
1043 }

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

602 : void
603 {
605 // save variables
606 $affectedRows = $this->db->manipulateF(
607 "
608 DELETE FROM il_qpl_qst_fq_var
609 WHERE question_fi = %s",
610 ['integer'],
611 [$this->getId()]
612 );
613
614 foreach ($this->variables as $variable) {
615 $next_id = $this->db->nextId('il_qpl_qst_fq_var');
616 $this->db->insert(
617 'il_qpl_qst_fq_var',
618 [
619 'variable_id' => ['integer', $next_id],
620 'question_fi' => ['integer', $this->getId()],
621 'variable' => ['text', $variable->getVariable()],
622 'range_min' => ['float', $variable->getRangeMin()],
623 'range_max' => ['float', $variable->getRangeMax()],
624 'unit_fi' => ['integer', (is_object($variable->getUnit()) ? (int) $variable->getUnit()->getId() : 0)],
625 'varprecision' => ['integer', (int) $variable->getPrecision()],
626 'intprecision' => ['integer', (int) $variable->getIntprecision()],
627 'range_min_txt' => ['text', $variable->getRangeMinTxt()],
628 'range_max_txt' => ['text', $variable->getRangeMaxTxt()]
629 ]
630 );
631 }
632 // save results
633 $affectedRows = $this->db->manipulateF(
634 "DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s",
635 ['integer'],
636 [$this->getId()]
637 );
638
639 foreach ($this->results as $result) {
640 $next_id = $this->db->nextId('il_qpl_qst_fq_res');
641 if (is_object($result->getUnit())) {
642 $tmp_result_unit = $result->getUnit()->getId();
643 } else {
644 $tmp_result_unit = null;
645 }
646
647 $formula = null;
648 if ($result->getFormula() !== null) {
649 $formula = str_replace(",", ".", $result->getFormula());
650 }
651
652 $this->db->insert("il_qpl_qst_fq_res", [
653 "result_id" => ['integer', $next_id],
654 "question_fi" => ['integer', $this->getId()],
655 "result" => ["text", $result->getResult()],
656 "range_min" => ["float", $result->getRangeMin()],
657 "range_max" => ["float", $result->getRangeMax()],
658 "tolerance" => ["float", $result->getTolerance()],
659 "unit_fi" => ['integer', (int) $tmp_result_unit],
660 "formula" => ["clob", $formula],
661 "resprecision" => ['integer', $result->getPrecision()],
662 "rating_simple" => ['integer', ($result->getRatingSimple()) ? 1 : 0],
663 "rating_sign" => ["float", ($result->getRatingSimple()) ? 0 : $result->getRatingSign()],
664 "rating_value" => ["float", ($result->getRatingSimple()) ? 0 : $result->getRatingValue()],
665 "rating_unit" => ["float", ($result->getRatingSimple()) ? 0 : $result->getRatingUnit()],
666 "points" => ["float", $result->getPoints()],
667 "result_type" => ['integer', (int) $result->getResultType()],
668 "range_min_txt" => ["text", $result->getRangeMinTxt()],
669 "range_max_txt" => ["text", $result->getRangeMaxTxt()]
670
671 ]);
672 }
673 // save result units
674 $affectedRows = $this->db->manipulateF(
675 "DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
676 ['integer'],
677 [$this->getId()]
678 );
679 foreach ($this->results as $result) {
680 foreach ($this->getResultUnits($result) as $unit) {
681 $next_id = $this->db->nextId('il_qpl_qst_fq_res_unit');
682 $affectedRows = $this->db->manipulateF(
683 "INSERT INTO il_qpl_qst_fq_res_unit (result_unit_id, question_fi, result, unit_fi) VALUES (%s, %s, %s, %s)",
684 ['integer', 'integer', 'text', 'integer'],
685 [
686 $next_id,
687 $this->getId(),
688 $result->getResult(),
689 $unit->getId()
690 ]
691 );
692 }
693 }
694
695 parent::saveToDb();
696 }
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 899 of file class.assFormulaQuestion.php.

903 : bool {
904 if (is_null($pass)) {
905 $pass = ilObjTest::_getPass($active_id);
906 }
907
908 $answer = $this->getSolutionSubmit();
909 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
910 function () use ($answer, $active_id, $pass, $authorized) {
911 foreach ($answer as $key => $value) {
912 $matches = null;
913 if (preg_match('/^result_(\$r\d+)$/', $key, $matches) !== false && $matches !== []) {
914 $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]);
915
916 if ($this->getStep() !== null) {
917 $queryResult .= " AND step = " . $this->db->quote((int) $this->getStep(), 'integer') . " ";
918 }
919
920 $result = $this->db->queryF(
921 $queryResult,
922 ['integer', 'integer', 'integer', 'integer'],
923 [$active_id, $pass, $this->getId(), (int) $authorized]
924 );
925 if ($result->numRows()) {
926 while ($row = $this->db->fetchAssoc($result)) {
927 $this->db->manipulateF(
928 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
929 ['integer', 'integer'],
930 [$row['solution_id'], (int) $authorized]
931 );
932 }
933 }
934
935 $this->saveCurrentSolution($active_id, $pass, $matches[1], str_replace(",", ".", $value), $authorized);
936 continue;
937 }
938
939 if (preg_match('/^result_(\$r\d+)_unit$/', $key, $matches) !== false) {
940 $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");
941
942 if ($this->getStep() !== null) {
943 $queryResultUnit .= " AND step = " . $this->db->quote((int) $this->getStep(), 'integer') . " ";
944 }
945
946 $result = $this->db->queryF(
947 $queryResultUnit,
948 ['integer', 'integer', 'integer', 'integer'],
949 [$active_id, $pass, $this->getId(), (int) $authorized]
950 );
951 if ($result->numRows()) {
952 while ($row = $this->db->fetchAssoc($result)) {
953 $this->db->manipulateF(
954 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
955 ['integer', 'integer'],
956 [$row['solution_id'], (int) $authorized]
957 );
958 }
959 }
960
961 $this->saveCurrentSolution($active_id, $pass, $matches[1] . "_unit", $value, $authorized);
962 }
963 }
964 }
965 );
966
967 return true;
968 }
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 1164 of file class.assFormulaQuestion.php.

1164 : void
1165 {
1166 parent::setId($id);
1167 $this->unitrepository->setConsumerId($id > 0 ? $id : null);
1168 }

References $id.

◆ setUnitrepository()

assFormulaQuestion::setUnitrepository ( \ilUnitConfigurationRepository  $unitrepository)

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

1170 : void
1171 {
1172 $this->unitrepository = $unitrepository;
1173 }

◆ 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 1360 of file class.assFormulaQuestion.php.

1363 : array {
1364 return array_reduce(
1365 $solution_values,
1366 function (array $c, array $v) use ($additional_info): array {
1367 if (str_starts_with($v['value1'], '$v')) {
1368 $var = $this->getVariable($v['value1']);
1369 if ($var === null) {
1370 $c[$v['value1']] = $additional_info->getNoneTag();
1371 return $c;
1372 }
1373 if ($var->getUnit() !== null) {
1374 $c[$v['value1']] = $v['value2'] . $var->getUnit()->getUnit();
1375 return $c;
1376 }
1377 }
1378
1379 if (strpos($v['value1'], '_unit')) {
1380 $unit = $this->getUnitrepository()->getUnit($v['value2']);
1381 $c[$v['value1']] = $unit->getUnit() ?? $additional_info->getNoneTag();
1382 return $c;
1383 }
1384
1385 $c[$v['value1']] = $v['value2'];
1386 return $c;
1387 },
1388 []
1389 );
1390 }

References Vendor\Package\$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 1392 of file class.assFormulaQuestion.php.

1392 : array
1393 {
1394 ksort($solution_values);
1395 return array_reduce(
1396 $solution_values,
1397 function (array $c, array $v): array {
1398 if (!str_starts_with($v['value1'], '$r')) {
1399 return $c;
1400 }
1401 if (!strpos($v['value1'], '_unit')) {
1402 $c[$v['value1']] = "{$v['value1']} = {$v['value2']}";
1403 return $c;
1404 }
1405 $k = substr($v['value1'], 0, -5);
1406 if (array_key_exists($k, $c)) {
1407 $c[$k] .= $v['value2'];
1408 }
1409 return $c;
1410 },
1411 []
1412 );
1413 }

References Vendor\Package\$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 340 of file class.assFormulaQuestion.php.

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

1292 : array
1293 {
1294 return [
1295 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->getQuestionType(),
1296 AdditionalInformationGenerator::KEY_QUESTION_TITLE => $this->getTitleForHTMLOutput(),
1297 AdditionalInformationGenerator::KEY_QUESTION_TEXT => $this->formatSAQuestion($this->getQuestion()),
1298 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_VARIABLES => $this->buildVariablesForLog(
1299 $this->getVariables(),
1300 $additional_info->getNoneTag()
1301 ),
1302 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_RESULTS => $this->buildResultsForLog(
1303 $this->getResults(),
1304 $additional_info->getNoneTag()
1305 ),
1306 AdditionalInformationGenerator::KEY_FEEDBACK => [
1307 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1308 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1309 ]
1310 ];
1311 }
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:

◆ toNormalized()

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

1497 : array|float|bool|int|string|null
1498 {
1499 return [
1500 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
1501 'variables' => $transformations->normalize($this->variables),
1502 'results' => $transformations->normalize($this->results)
1503 ];
1504 }

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

+ Here is the call graph for this function:

◆ validateSolutionSubmit()

assFormulaQuestion::validateSolutionSubmit ( )

Reimplemented from assQuestion.

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

1210 : bool
1211 {
1212 foreach ($this->getSolutionSubmit() as $value) {
1213 if ($value && !$this->isValidSolutionResultValue($value)) {
1214 $this->tpl->setOnScreenMessage(
1215 'failure',
1216 $this->lng->txt("err_no_numeric_value"),
1217 true
1218 );
1219 return false;
1220 }
1221 }
1222
1223 return true;
1224 }
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 40 of file class.assFormulaQuestion.php.

◆ $results

array assFormulaQuestion::$results
private

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

Referenced by getResults().

◆ $resultunits

array assFormulaQuestion::$resultunits
private

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

◆ $unitrepository

ilUnitConfigurationRepository assFormulaQuestion::$unitrepository
private

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

◆ $variables

array assFormulaQuestion::$variables
private

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

Referenced by getVariables().


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