student_priority.api.php

File

modules/student_priority/student_priority.api.php
View source
  1. <?php
  2. /**
  3. * This file defines the hooks we recognize from this module.
  4. */
  5. /**
  6. * Lets us modify an array of calculation tests, either adding to it, or altering the existing ones.
  7. * Notice that $arr is passed by reference.
  8. */
  9. function hook_define_calculation_tests(&$arr) {
  10. // METHOD ONE: A function runs for each test to get the result.
  11. $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.
  12. 'title' => 'This is the title of this test.',
  13. 'description' => 'This is a description of this test.',
  14. 'result_scores' => array( // Based on the returned 'result' value, what "score" should we use? The default can be overridden in the UI.
  15. 'Y' => 0,
  16. 'N' => 0.5
  17. ),
  18. 'file' => array('my_module', 'my_modules.calculations.inc'), // module name first, the file next (assuming it is within a module folder.
  19. 'group' => 'Custom Group A', // groups multiple tests together this way
  20. 'weight' => 1010, // lighter weights float to the top (get evaluated first).
  21. );
  22. // METHOD TWO: You specifically look at a user's attribute for the test to get the result. No need for a custom function.
  23. // In this example, it assumes there is an attribute called student_is_good, whose data is saved
  24. // in the attributes table as student_is_good__value.
  25. $arr['mymodule2__student_is_good'] = array(
  26. 'title' => 'Student is good?',
  27. 'result_scores' => array(
  28. 'Y' => 0,
  29. 'N' => 1,
  30. ),
  31. 'options' => array( // optional, but might display nicer on screen.
  32. 'Y' => 'Yes',
  33. 'N' => 'No',
  34. ),
  35. 'weight' => $w,
  36. 'result_from_user_attribute' => 'student_is_good__value',
  37. );
  38. // No need to return anything, since $arr is passed by reference.
  39. }
  40. /**
  41. * Implements hook_define_calculation_tests, "METHOD ONE" from above.
  42. * Accept an array so we can alter. Then, we are just going to add to array (or modify).
  43. */
  44. function example_define_calculation_tests(&$arr) {
  45. $arr['example__does_student_work_on_campus'] = array(
  46. 'title' => 'Does the student work on campus?',
  47. 'description' => 'If the student has a campus job, they are generally more engaged
  48. in campus life and their own success.',
  49. 'result_scores' => array( // Based on the returned 'result' value, what "score" should we use?
  50. 'Y' => 0,
  51. 'N' => 0.5
  52. ),
  53. 'file' => array('example', 'example.calculations.inc'),
  54. 'group' => 'FlightPath Core', // groups multiple tests together this way
  55. 'weight' => 100, // lighter weights float to the top (get evaluated first)
  56. );
  57. $arr['example__is_student_gpa_above_250'] = array(
  58. 'title' => "Is the student's GPA above 2.50?",
  59. 'result_scores' => array(
  60. 'Y' => 0,
  61. 'N' => 0.9
  62. ),
  63. 'file' => array('example', 'example.calculations.inc'),
  64. 'group' => 'FlightPath Core', // groups multiple tests together this way
  65. 'weight' => 110,
  66. );
  67. $arr['example__does_student_have_more_than_2_d_or_f'] = array(
  68. 'title' => "Does the student have more than 2 D's or F's?",
  69. 'result_scores' => array(
  70. 'Y' => 1,
  71. 'N' => 0,
  72. ),
  73. 'file' => array('example', 'example.calculations.inc'),
  74. 'group' => 'FlightPath Core', // groups multiple tests together this way
  75. 'weight' => 130,
  76. );
  77. $arr['example__does_student_have_more_than_2_w'] = array(
  78. 'title' => "Does the student have more than 2 W's?",
  79. 'result_scores' => array(
  80. 'Y' => 0.8,
  81. 'N' => 0,
  82. ),
  83. 'file' => array('example', 'example.calculations.inc'),
  84. 'group' => 'FlightPath Core', // groups multiple tests together this way
  85. 'weight' => 140,
  86. );
  87. $arr['example__did_student_score_below_b_on_engl_1001'] = array(
  88. 'title' => "Did the student score below a 'B' in ENGL 1001?",
  89. 'result_scores' => array(
  90. 'Y' => 0.8,
  91. 'N' => 0,
  92. 'N/A' => 'SKIP',
  93. ),
  94. 'file' => array('example', 'example.calculations.inc'),
  95. 'group' => 'FlightPath Core', // groups multiple tests together this way
  96. 'weight' => 150,
  97. );
  98. $arr['example__does_student_have_federal_financial_aid'] = array(
  99. 'title' => "Does the student have federal financial aid?",
  100. 'result_scores' => array(
  101. 'Y' => 0,
  102. 'N' => 0.2,
  103. ),
  104. 'file' => array('example', 'example.calculations.inc'),
  105. 'group' => 'FlightPath Core', // groups multiple tests together this way
  106. 'weight' => 105,
  107. );
  108. // No need to return the $arr, since it was passed by reference.
  109. } // example_define_calculation_tests()
  110. /*
  111. * Example of a particular test being run. Notice it has the same name as defined
  112. * in our hook_define_calculation_tests()
  113. *
  114. * Notice that the $student object is always passed to the function!
  115. *
  116. * Based on our hook_define_calculation_tests above, this function would appear in a file called "example.calculations.inc".
  117. * It is displayed here for simplicity. All of the tests from that hook would be similarly defined as functions.
  118. *
  119. */
  120. function example__is_student_gpa_above_250(Student $student) {
  121. $rtn = array();
  122. // For this test, we will simply examine the student's cumulative GPA
  123. if (floatval($student->gpa) > 2.5) {
  124. $rtn['result'] = 'Y';
  125. }
  126. else {
  127. $rtn['result'] = 'N';
  128. }
  129. $rtn['extra'] = 'Current cumulative GPA is ' . floatval($student->gpa);
  130. return $rtn;
  131. } // example__is_student_gpa_above_250

Functions

Namesort descending Description
example_define_calculation_tests 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).
example__is_student_gpa_above_250
hook_define_calculation_tests Lets us modify an array of calculation tests, either adding to it, or altering the existing ones. Notice that $arr is passed by reference.