This class processes numbers with units.
More...
|
string | $decsep |
| character used as decimal point.
|
|
| $regex = null |
|
string | $thousandssep |
| character used as thousands separator.
|
|
array | $units |
| unit name => multiplier.
|
|
boolean | $unitsbefore |
| whether the units come before or after the number.
|
|
This class processes numbers with units.
- Copyright
- 2010 The Open University
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ add_unit()
qtype_numerical_answer_processor::add_unit |
( |
| $answer, |
|
|
| $unit = null ) |
- Parameters
-
string | $answer | a response. |
string | $unit | a unit. |
◆ apply_units()
qtype_numerical_answer_processor::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.
- Parameters
-
string | $response | a value, optionally with a unit. |
- Return values
-
array(numeric,string,multiplier) | the value with the unit stripped, and normalised by the unit multiplier, if any, and the unit string, for reference. |
◆ are_units_before()
qtype_numerical_answer_processor::are_units_before |
( |
| ) |
|
Whether the units go before or after the number.
- Return values
-
true | = before, false = after. |
◆ build_regex()
qtype_numerical_answer_processor::build_regex |
( |
| ) |
|
|
protected |
◆ contains_thousands_seaparator()
qtype_numerical_answer_processor::contains_thousands_seaparator |
( |
| $value | ) |
|
- Return values
-
bool | If the student's response contains a '.' or a ',' that matches the thousands separator in the current locale. In this case, the parsing in apply_unit can give a result that the student did not expect. |
◆ get_default_unit()
qtype_numerical_answer_processor::get_default_unit |
( |
| ) |
|
◆ get_point()
qtype_numerical_answer_processor::get_point |
( |
| ) |
|
- Return values
-
string | the decimal point character used. |
◆ get_separator()
qtype_numerical_answer_processor::get_separator |
( |
| ) |
|
- Return values
-
string | the thousands separator character used. |
◆ get_unit_options()
qtype_numerical_answer_processor::get_unit_options |
( |
| ) |
|
Get the units as an array suitably for passing to html_writer\select.
- Return values
-
◆ is_known_unit()
qtype_numerical_answer_processor::is_known_unit |
( |
| $unit | ) |
|
Is this unit recognised.
- Parameters
-
- Return values
-
bool | whether this is a unit we recognise. |
◆ parse_response()
qtype_numerical_answer_processor::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.
- Parameters
-
string | $response | a value, optionally with a unit. |
- Return values
-
array | four strings (some of which may be blank) the digits before and after the decimal point, the exponent, and the unit. All four will be null if the response cannot be parsed. |
◆ set_characters()
qtype_numerical_answer_processor::set_characters |
( |
| $decsep, |
|
|
| $thousandssep ) |
Set the decimal point and thousands separator character that should be used.
- Parameters
-
string | $decsep | |
string | $thousandssep | |
The documentation for this class was generated from the following file:
- question/type/numerical/questiontype.php