Useful functions for writing question types and behaviours.  
 More...
|  | 
| static | arrays_have_same_keys_and_values (array $array1, array $array2) | 
|  | Tests to see whether two arrays have the same keys, with the same values (as compared by ===) for each key. 
 | 
|  | 
| static | arrays_same_at_key (array $array1, array $array2, $key) | 
|  | Tests to see whether two arrays have the same value at a particular key. 
 | 
|  | 
| static | arrays_same_at_key_integer (array $array1, array $array2, $key) | 
|  | Tests to see whether two arrays have the same value at a particular key. 
 | 
|  | 
| static | arrays_same_at_key_missing_is_blank (array $array1, array $array2, $key) | 
|  | Tests to see whether two arrays have the same value at a particular key. 
 | 
|  | 
| static | clean_param_mark ($mark) | 
|  | Typically, $mark will have come from optional_param($name, null, PARAM_RAW_TRIMMED). 
 | 
|  | 
| static | get_editor_options ($context) | 
|  | Get editor options for question related text areas. 
 | 
|  | 
| static | get_filepicker_options ($context, $draftitemid) | 
|  | Get filepicker options for question related text areas. 
 | 
|  | 
| static | int_to_letter ($number) | 
|  | Convert an integer to a letter of alphabet. 
 | 
|  | 
| static | int_to_roman ($number) | 
|  | Convert an integer to roman numerals. 
 | 
|  | 
| static | optional_param_mark ($parname) | 
|  | Get a sumitted variable (from the GET or POST data) that is a mark. 
 | 
|  | 
| static | to_plain_text ($text, $format, $options=array('noclean'=> 'true')) | 
|  | Convert part of some question content to plain text. 
 | 
|  | 
|  | 
| float const | MARK_TOLERANCE = 0.00000005 | 
|  | tolerance to use when comparing question mark/fraction values. 
 | 
|  | 
Useful functions for writing question types and behaviours. 
- Copyright
- 2010 The Open University 
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
◆ arrays_have_same_keys_and_values()
  
  | 
        
          | static question_utils::arrays_have_same_keys_and_values | ( | array | $array1, |  
          |  |  | array | $array2 ) |  | static | 
 
Tests to see whether two arrays have the same keys, with the same values (as compared by ===) for each key. 
However, the order of the arrays does not have to be the same. 
- Parameters
- 
  
    | array | $array1 | the first array. |  | array | $array2 | the second array. |  
 
- Return values
- 
  
    | bool | whether the two arrays have the same keys with the same corresponding values. |  
 
 
 
◆ arrays_same_at_key()
  
  | 
        
          | static question_utils::arrays_same_at_key | ( | array | $array1, |  
          |  |  | array | $array2, |  
          |  |  |  | $key ) |  | static | 
 
Tests to see whether two arrays have the same value at a particular key. 
This method will return true if:
- Neither array contains the key; or
- Both arrays contain the key, and the corresponding values compare identical when cast to strings and compared with ===. - Parameters
- 
  
    | array | $array1 | the first array. |  | array | $array2 | the second array. |  | string | $key | an array key. |  
 
 - Return values
- 
  
    | bool | whether the two arrays have the same value (or lack of one) for a given key. |  
 
 
 
 
◆ arrays_same_at_key_integer()
  
  | 
        
          | static question_utils::arrays_same_at_key_integer | ( | array | $array1, |  
          |  |  | array | $array2, |  
          |  |  |  | $key ) |  | static | 
 
Tests to see whether two arrays have the same value at a particular key. 
Missing values are replaced by 0, and then the values are cast to integers and compared with ===. 
- Parameters
- 
  
    | array | $array1 | the first array. |  | array | $array2 | the second array. |  | string | $key | an array key. |  
 
- Return values
- 
  
    | bool | whether the two arrays have the same value (or lack of one) for a given key. |  
 
 
 
◆ arrays_same_at_key_missing_is_blank()
  
  | 
        
          | static question_utils::arrays_same_at_key_missing_is_blank | ( | array | $array1, |  
          |  |  | array | $array2, |  
          |  |  |  | $key ) |  | static | 
 
Tests to see whether two arrays have the same value at a particular key. 
Missing values are replaced by '', and then the values are cast to strings and compared with ===. 
- Parameters
- 
  
    | array | $array1 | the first array. |  | array | $array2 | the second array. |  | string | $key | an array key. |  
 
- Return values
- 
  
    | bool | whether the two arrays have the same value (or lack of one) for a given key. |  
 
 
 
◆ clean_param_mark()
  
  | 
        
          | static question_utils::clean_param_mark | ( |  | $mark | ) |  |  | static | 
 
Typically, $mark will have come from optional_param($name, null, PARAM_RAW_TRIMMED). 
This method copes with:
- keeping null or '' input unchanged - important to let teaches set a question back to requries grading.
- numbers that were typed as either 1.00 or 1,00 form.
- invalid things, which get turned into null.
- Parameters
- 
  
    | string | null | $mark | raw use input of a mark. |  
 
- Return values
- 
  
    | float|string|null | cleaned mark as a float if possible. Otherwise '' or null. |  
 
 
 
◆ get_editor_options()
  
  | 
        
          | static question_utils::get_editor_options | ( |  | $context | ) |  |  | static | 
 
Get editor options for question related text areas. 
- Parameters
- 
  
    | context | $context | the context. |  
 
- Return values
- 
  
  
 
 
◆ get_filepicker_options()
  
  | 
        
          | static question_utils::get_filepicker_options | ( |  | $context, |  
          |  |  |  | $draftitemid ) |  | static | 
 
Get filepicker options for question related text areas. 
- Parameters
- 
  
    | context | $context | the context. |  | int | $draftitemid | the draft area item id. |  
 
- Return values
- 
  
  
 
 
◆ int_to_letter()
  
  | 
        
          | static question_utils::int_to_letter | ( |  | $number | ) |  |  | static | 
 
Convert an integer to a letter of alphabet. 
- Parameters
- 
  
    | int | $number | an integer between 1 and 26 inclusive. Anything else will throw an exception. |  
 
- Return values
- 
  
    | string | the number converted to upper case letter of alphabet. |  
 
 
 
◆ int_to_roman()
  
  | 
        
          | static question_utils::int_to_roman | ( |  | $number | ) |  |  | static | 
 
Convert an integer to roman numerals. 
- Parameters
- 
  
    | int | $number | an integer between 1 and 3999 inclusive. Anything else will throw an exception. |  
 
- Return values
- 
  
    | string | the number converted to lower case roman numerals. |  
 
 
 
◆ optional_param_mark()
  
  | 
        
          | static question_utils::optional_param_mark | ( |  | $parname | ) |  |  | static | 
 
Get a sumitted variable (from the GET or POST data) that is a mark. 
- Parameters
- 
  
    | string | $parname | the submitted variable name. |  
 
- Return values
- 
  
    | float|string|null | cleaned mark as a float if possible. Otherwise '' or null. |  
 
 
 
◆ specific_filepicker_options()
  
  | 
        
          | static question_utils::specific_filepicker_options | ( |  | $acceptedtypes, |  
          |  |  |  | $draftitemid, |  
          |  |  |  | $context ) |  | staticprotected | 
 
Get the options required to configure the filepicker for one of the editor toolbar buttons. 
- Parameters
- 
  
    | mixed | $acceptedtypes | array of types of '*'. |  | int | $draftitemid | the draft area item id. |  | context | $context | the context. |  
 
- Return values
- 
  
    | object | the required options. |  
 
 
 
◆ to_plain_text()
  
  | 
        
          | static question_utils::to_plain_text | ( |  | $text, |  
          |  |  |  | $format, |  
          |  |  |  | $options = array('noclean' => 'true') ) |  | static | 
 
Convert part of some question content to plain text. 
- Parameters
- 
  
    | string | $text | the text. |  | int | $format | the text format. |  | array | $options | formatting options. Passed to format_text. |  
 
- Return values
- 
  
    | float|string|null | cleaned mark as a float if possible. Otherwise '' or null. |  
 
 
 
◆ MARK_TOLERANCE
      
        
          | float const question_utils::MARK_TOLERANCE = 0.00000005 | 
      
 
tolerance to use when comparing question mark/fraction values. 
When comparing floating point numbers in a computer, the representation is not necessarily exact. Therefore, we need to allow a tolerance. Question marks are stored in the database as decimal numbers with 7 decimal places. Therefore, this is the appropriate tolerance to use. 
 
 
The documentation for this class was generated from the following file: