|
Moodle
2.2.1
http://www.collinsharper.com
|

Public Member Functions | |
| __construct ($units, $unitsbefore=false, $decsep=null, $thousandssep=null) | |
| set_characters ($decsep, $thousandssep) | |
| get_point () | |
| get_separator () | |
| contains_thousands_seaparator ($value) | |
| apply_units ($response, $separateunit=null) | |
| get_default_unit () | |
| add_unit ($answer, $unit=null) | |
| is_known_unit ($unit) | |
| are_units_before () | |
| get_unit_options () | |
Protected Member Functions | |
| build_regex () | |
| parse_response ($response) | |
Protected Attributes | |
| $units | |
| $decsep | |
| $thousandssep | |
| $unitsbefore | |
| $regex = null | |
This class processes numbers with units.
Definition at line 490 of file questiontype.php.
| __construct | ( | $ | units, |
| $ | unitsbefore = false, |
||
| $ | decsep = null, |
||
| $ | thousandssep = null |
||
| ) |
Definition at line 502 of file questiontype.php.
| add_unit | ( | $ | answer, |
| $ | unit = null |
||
| ) |
| string | $answer | a response. |
| string | $unit | a unit. |
Definition at line 684 of file questiontype.php.

| apply_units | ( | $ | response, |
| $ | separateunit = null |
||
| ) |
Takes a number in almost any localised form, and possibly with a unit after it. It separates off the unit, if present, and converts to the default unit, by using the given unit multiplier.
| string | $response | a value, optionally with a unit. |
Definition at line 626 of file questiontype.php.


| are_units_before | ( | ) |
Whether the units go before or after the number.
Definition at line 713 of file questiontype.php.
| build_regex | ( | ) | [protected] |
Create the regular expression that parse_response() requires.
Definition at line 556 of file questiontype.php.

| contains_thousands_seaparator | ( | $ | value | ) |
Definition at line 544 of file questiontype.php.
| get_default_unit | ( | ) |
Definition at line 675 of file questiontype.php.

| get_point | ( | ) |
Definition at line 530 of file questiontype.php.
| get_separator | ( | ) |
Definition at line 535 of file questiontype.php.
| get_unit_options | ( | ) |
Get the units as an array suitably for passing to html_writer::select.
Definition at line 721 of file questiontype.php.
| is_known_unit | ( | $ | unit | ) |
Is this unit recognised.
| string | $unit | the unit |
Definition at line 705 of file questiontype.php.

| parse_response | ( | $ | response | ) | [protected] |
This method can be used for more locale-strict parsing of repsonses. At the moment we don't use it, and instead use the more lax parsing in apply_units. This is just a note that this funciton was used in the past, so if you are intersted, look through version control history.
Take a string which is a number with or without a decimal point and exponent, and possibly followed by one of the units, and split it into bits.
| string | $response | a value, optionally with a unit. |
Reimplemented in testable_qtype_numerical_answer_processor.
Definition at line 590 of file questiontype.php.

| set_characters | ( | $ | decsep, |
| $ | thousandssep | ||
| ) |
Set the decimal point and thousands separator character that should be used.
| string | $decsep | |
| string | $thousandssep |
Definition at line 523 of file questiontype.php.
$decsep [protected] |
Definition at line 494 of file questiontype.php.
$regex = null [protected] |
Definition at line 500 of file questiontype.php.
$thousandssep [protected] |
Definition at line 496 of file questiontype.php.
$units [protected] |
Definition at line 492 of file questiontype.php.
$unitsbefore [protected] |
Definition at line 498 of file questiontype.php.