|
Moodle
2.2.1
http://www.collinsharper.com
|
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 | |
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.
| __construct | ( | array $ | values, |
| $ | decimalpoint | ||
| ) |
Constructor
| array | $values | variable name => value. |
Definition at line 287 of file question.php.

| calculate | ( | $ | expression | ) |
Evaluate an expression using the variable values.
| string | $expression | the expression. A PHP expression with placeholders like {a} for where the variables need to go. |
Definition at line 343 of file question.php.

| calculate_raw | ( | $ | expression | ) | [protected] |
Evaluate an expression after the variable values have been substituted.
| string | $expression | the expression. A PHP expression with placeholders like {a} for where the variables need to go. |
Definition at line 353 of file question.php.

| format_float | ( | $ | x, |
| $ | length = null, |
||
| $ | format = null |
||
| ) |
Display a float properly formatted with a certain number of decimal places.
| number | $x | the number to format |
| int | $length | restrict to this many decimal places or significant figures. If null, the number is not rounded. |
| int | format 1 => decimalformat, 2 => significantfigures. |
Definition at line 316 of file question.php.

| get_formula_errors | ( | $ | formula | ) |
Return an array describing any problems there are with an expression. Returns false if the expression is fine.
| string | $formula | an expression. |
Definition at line 405 of file question.php.
| get_values | ( | ) |
Return an array of the variables and their values.
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.
| string | $text | the text to process. |
Definition at line 390 of file question.php.

| substitute_values_for_eval | ( | $ | expression | ) | [protected] |
Substitute variable placehodlers like {a} with their value wrapped in ().
| string | $expression | the expression. A PHP expression with placeholders like {a} for where the variables need to go. |
Definition at line 368 of file question.php.

| substitute_values_pretty | ( | $ | text | ) | [protected] |
Substitute variable placehodlers like {a} with their value without wrapping the value in anything.
| string | $text | some content with placeholders like {a} for where the variables need to go. |
Definition at line 380 of file question.php.

$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.