Moodle  2.2.1
http://www.collinsharper.com
qtype_calculated_variable_substituter Class Reference

Public Member Functions

 __construct (array $values, $decimalpoint)
 format_float ($x, $length=null, $format=null)
 get_values ()
 calculate ($expression)
 replace_expressions_in_text ($text, $length=null, $format=null)
 get_formula_errors ($formula)

Protected Member Functions

 calculate_raw ($expression)
 substitute_values_for_eval ($expression)
 substitute_values_pretty ($text)

Protected Attributes

 $values
 $decimalpoint
 $search
 $safevalue
 $prettyvalue

Detailed Description

This class holds the current values of all the variables used by a calculated question.

It can compute formulae using those values, and can substitute equations embedded in text.

Definition at line 261 of file question.php.


Constructor & Destructor Documentation

__construct ( array values,
decimalpoint 
)

Constructor

Parameters:
array$valuesvariable name => value.

Definition at line 287 of file question.php.

Here is the call graph for this function:


Member Function Documentation

calculate ( expression)

Evaluate an expression using the variable values.

Parameters:
string$expressionthe expression. A PHP expression with placeholders like {a} for where the variables need to go.
Returns:
float the computed result.

Definition at line 343 of file question.php.

Here is the call graph for this function:

calculate_raw ( expression) [protected]

Evaluate an expression after the variable values have been substituted.

Parameters:
string$expressionthe expression. A PHP expression with placeholders like {a} for where the variables need to go.
Returns:
float the computed result.

Definition at line 353 of file question.php.

Here is the caller graph for this function:

format_float ( x,
length = null,
format = null 
)

Display a float properly formatted with a certain number of decimal places.

Parameters:
number$xthe number to format
int$lengthrestrict to this many decimal places or significant figures. If null, the number is not rounded.
intformat 1 => decimalformat, 2 => significantfigures.
Returns:
string formtted number.

Definition at line 316 of file question.php.

Here is the caller graph for this function:

get_formula_errors ( formula)

Return an array describing any problems there are with an expression. Returns false if the expression is fine.

Parameters:
string$formulaan expression.
Returns:
array|false list of problems, or false if the exression is OK.

Definition at line 405 of file question.php.

Return an array of the variables and their values.

Returns:
array name => value.

Definition at line 333 of file question.php.

replace_expressions_in_text ( text,
length = null,
format = null 
)

Replace any embedded variables (like {a}) or formulae (like {={a} + {b}}) in some text with the corresponding values.

Parameters:
string$textthe text to process.
Returns:
string the text with values substituted.

Definition at line 390 of file question.php.

Here is the call graph for this function:

substitute_values_for_eval ( expression) [protected]

Substitute variable placehodlers like {a} with their value wrapped in ().

Parameters:
string$expressionthe expression. A PHP expression with placeholders like {a} for where the variables need to go.
Returns:
string the expression with each placeholder replaced by the corresponding value.

Definition at line 368 of file question.php.

Here is the caller graph for this function:

substitute_values_pretty ( text) [protected]

Substitute variable placehodlers like {a} with their value without wrapping the value in anything.

Parameters:
string$textsome content with placeholders like {a} for where the variables need to go.
Returns:
string the expression with each placeholder replaced by the corresponding value.

Definition at line 380 of file question.php.

Here is the caller graph for this function:


Field Documentation

$decimalpoint [protected]

Definition at line 266 of file question.php.

$prettyvalue [protected]

Definition at line 281 of file question.php.

$safevalue [protected]

Definition at line 275 of file question.php.

$search [protected]

Definition at line 269 of file question.php.

$values [protected]

Definition at line 263 of file question.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations