Moodle  2.2.1
http://www.collinsharper.com
qtype_numerical_answer_processor Class Reference
Inheritance diagram for qtype_numerical_answer_processor:

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

Detailed Description

This class processes numbers with units.

Definition at line 490 of file questiontype.php.


Constructor & Destructor Documentation

__construct ( units,
unitsbefore = false,
decsep = null,
thousandssep = null 
)

Definition at line 502 of file questiontype.php.


Member Function Documentation

add_unit ( answer,
unit = null 
)
Parameters:
string$answera response.
string$unita unit.

Definition at line 684 of file questiontype.php.

Here is the call graph for this function:

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$responsea value, optionally with a unit.
Returns:
array(numeric, sting) the value with the unit stripped, and normalised by the unit multiplier, if any, and the unit string, for reference.

Definition at line 626 of file questiontype.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Whether the units go before or after the number.

Returns:
true = before, false = after.

Definition at line 713 of file questiontype.php.

build_regex ( ) [protected]

Create the regular expression that parse_response() requires.

Returns:
string

Definition at line 556 of file questiontype.php.

Here is the caller graph for this function:

Returns:
book 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.

Definition at line 544 of file questiontype.php.

Returns:
string the default unit.

Definition at line 675 of file questiontype.php.

Here is the caller graph for this function:

get_point ( )
Returns:
string the decimal point character used.

Definition at line 530 of file questiontype.php.

Returns:
string the thousands separator character used.

Definition at line 535 of file questiontype.php.

Get the units as an array suitably for passing to html_writer::select.

Returns:
array of unit choices.

Definition at line 721 of file questiontype.php.

is_known_unit ( unit)

Is this unit recognised.

Parameters:
string$unitthe unit
Returns:
bool whether this is a unit we recognise.

Definition at line 705 of file questiontype.php.

Here is the caller graph for this function:

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$responsea value, optionally with a unit.
Returns:
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.

Reimplemented in testable_qtype_numerical_answer_processor.

Definition at line 590 of file questiontype.php.

Here is the call graph for this function:

set_characters ( decsep,
thousandssep 
)

Set the decimal point and thousands separator character that should be used.

Parameters:
string$decsep
string$thousandssep

Definition at line 523 of file questiontype.php.


Field Documentation

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


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