function hook_define_calculation_tests

6.x student_priority.api.php hook_define_calculation_tests(&$arr)

Lets us modify an array of calculation tests, either adding to it, or altering the existing ones. Notice that $arr is passed by reference.

1 function implements hook_define_calculation_tests()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

example_define_calculation_tests in modules/student_priority/student_priority.api.php
Implements hook_define_calculation_tests, "METHOD ONE" from above. Accept an array so we can alter. Then, we are just going to add to array (or modify).

File

modules/student_priority/student_priority.api.php, line 13

Code

function hook_define_calculation_tests(&$arr) {

  // METHOD ONE:  A function runs for each test to get the result.


  $arr ['my_module__something_test'] = array(// the key is also the callback function to call!  By convention, use module name, 2 underscores, then test name.
    'title' => 'This is the title of this test.',
    'description' => 'This is a description of this test.',
    'result_scores' => array(// Based on the returned 'result' value, what "score" should we use?  The default can be overridden in the UI.
      'Y' => 0,
      'N' => 0.5
    ),
    'file' => array('my_module', 'my_modules.calculations.inc'), // module name first, the file next (assuming it is within a module folder.        
    'group' => 'Custom Group A', // groups multiple tests together this way    
    'weight' => 1010, // lighter weights float to the top (get evaluated first).
  );



  // METHOD TWO:  You specifically look at a user's attribute for the test to get the result.  No need for a custom function.
  // In this example, it assumes there is an attribute called student_is_good, whose data is saved
  // in the attributes table as student_is_good__value.
  $arr ['mymodule2__student_is_good'] = array(
    'title' => 'Student is good?',
    'result_scores' => array(
      'Y' => 0,
      'N' => 1,
    ),
    'options' => array(// optional, but might display nicer on screen.
      'Y' => 'Yes',
      'N' => 'No',
    ),
    'weight' => $w,
    'result_from_user_attribute' => 'student_is_good__value',
  );



  // No need to return anything, since $arr is passed by reference.

}