function Course::meets_min_grade_requirement_of

6.x Course.php Course::meets_min_grade_requirement_of(Course $course_req = NULL, $m_grade = "", $bool_exclude_W_and_F = TRUE)
7.x Course.php Course::meets_min_grade_requirement_of(Course $course_req = NULL, $m_grade = "", $bool_exclude_W_and_F = TRUE)

Does $this meed the minimum grade requirement of the supplied course requirement? You may specify either a Course object, or just enter the min_grade in the mGrade variable.


Course $course_req:

  • The Course object who has the min grade requirement. Set to NULL if using $m_grade.

string $m_grade:

  • The min grade which $this must meet. Do not use if using $course_req.

Return value



classes/Course.php, line 1024




function meets_min_grade_requirement_of(Course $course_req = NULL, $m_grade = "", $bool_exclude_W_and_F = TRUE) 
  // Does $this course meet the min grade requirement
  // of the supplied course requirement?

  // Get these grade definitions from our system settings
  // Configure them in custom/settings.php    
  $enrolled_grades = csv_to_array(variable_get_for_school("enrolled_grades", 'E', $this->school_id));
  $retake_grades = csv_to_array(variable_get_for_school("retake_grades", '', $this->school_id));
  $withdrew_grades = csv_to_array(variable_get_for_school("withdrew_grades", "W", $this->school_id));

  if ($course_req != null) {
    $min_grade = $course_req->min_grade;
  else {
    $min_grade = $m_grade;

  if ($min_grade == "") 
   { // There is no min grade requirement for this course.
    return true;

  // If the student is currently enrolled, return true.
  if (in_array($this->grade, $enrolled_grades)) 
    return true;

  if ($bool_exclude_W_and_F) {
    if (in_array($this->grade, $retake_grades) || in_array($this->grade, $withdrew_grades)) {
      return FALSE;

  // Okay, let's check those min grade requirements...
  $grade_order = csv_to_array(strtoupper(variable_get_for_school("grade_order", "E,AMID,BMID,CMID,DMID,FMID,A,B,C,D,F,W,I", $this->school_id)));

  // Make it so the indexes are the grades, their numeric values are values.    
  $grade_order = array_flip($grade_order);

  // Get the "weight" of the min_grade_requirement, and $this->grade
  $req_weight = intval(@$grade_order [$min_grade]);
  $this_weight = intval(@$grade_order [$this->grade]);

  if ($this_weight <= $req_weight) {
    return TRUE; // yay, we have the min grade!

  return false;