function CourseList::count_credit_hours

6.x CourseList.php CourseList::count_credit_hours($requirement_type = "", $bool_use_ignore_list = false, $bool_ignore_enrolled = false, $bool_qpts_grades_only = FALSE, $bool_exclude_all_transfer_credits = FALSE, $degree_id = 0)

Similar to count_hours, but this will only count courses which have been taken and have a grade.

Parameters

string $requirement_type:

  • If set, we will only look for courses matching this requirement_type.

bool $bool_use_ignore_list:

bool $bool_ignore_enrolled:

Return value

int

File

classes/CourseList.php, line 2074

Class

CourseList

Code

function count_credit_hours($requirement_type = "", $bool_use_ignore_list = false, $bool_ignore_enrolled = false, $bool_qpts_grades_only = FALSE, $bool_exclude_all_transfer_credits = FALSE, $degree_id = 0) 
 {
  // Similar to count_hours, but this will only
  // count courses which have been taken (have a grade).


  $count = 0;


  $qpts_grades = NULL;
  $retake_grades = $enrolled_grades = NULL;


  for ($t = 0; $t < $this->count; $t++) 
   {
    $course = $this->array_list [$t];

    // Does this course belong to the same degree we are interested in?  If not, skip it.
    if ($degree_id > 0) {
      if ($course->req_by_degree_id != $degree_id && $course->get_has_been_assigned_to_degree_id($degree_id) != TRUE) {
        continue;
      }
    }

    $school_id = $course->school_id;

    // Now that we have a school_id, let's figure out some variables....

    if (!$retake_grades || !$enrolled_grades) {
      $retake_grades = csv_to_array(variable_get_for_school("retake_grades", 'F,W,I', $school_id));
      $enrolled_grades = csv_to_array(variable_get_for_school("enrolled_grades", 'E', $school_id));
    }

    if (!$qpts_grades) {
      $tlines = explode("\n", variable_get_for_school("quality_points_grades", "A ~ 4\nB ~ 3\nC ~ 2\nD ~ 1\nF ~ 0\nI ~ 0", $school_id));
      foreach ($tlines as $tline) {
        $temp = explode("~", trim($tline));
        if (trim($temp [0]) != "") {
          $qpts_grades [trim($temp [0])] = trim($temp [1]);
        }
      }
    }




    if ($bool_use_ignore_list == true) 
     {
      // Do ignore some courses...
      $temp_course_name = $course->subject_id . " " . $course->course_num;
      // Check in our settings to see if we should ignore this course
      // (configured in /custom/settings.php)
      if (in_array($temp_course_name, csv_to_array(@variable_get_for_school("ignore_courses_from_hour_counts", "", $school_id)))) {
        continue;
      }

      // Also, if the course's requirement_type is "x" it means we should ignore it.
      if ($course->requirement_type == 'x') {
        continue;
      }

    }



    if ($bool_ignore_enrolled == true) 
     {
      if (in_array($course->grade, $enrolled_grades)) {
        continue;
      }
    }

    // Only allowing grades which we have quality points for?
    if ($bool_qpts_grades_only) {
      if ($course->grade != "" && !isset($qpts_grades [$course->grade])) {
        continue;
      }
    }
    else {
      // Is this grade a "retake" grade?  If so, skip it.
      if (in_array($course->grade, $retake_grades)) {
        continue;
      }
    }


    // Correct the course's requirement type, if needed (remove the "u")
    $cr_type = $course->requirement_type;
    $cr_type = str_replace("u", "", $cr_type);


    if ($course->grade != "") // || !($course->course_list_fulfilled_by->is_empty))
     {


      // Make sure we aren't trying to exclude any transfer credits.
      if ($bool_exclude_all_transfer_credits) {
        if ($course->bool_transfer) {
          continue;
        }
        // Is this a requirement which has been fulfilled by a course?  And if so, is THAT course a transfer?
        if ($course->course_list_fulfilled_by->is_empty == false) {
          $cc = $course->course_list_fulfilled_by->get_first();
          if ($cc->bool_transfer) {
            continue;
          }
        }
      }





      // If we require the grade to be a qpts_grade, then check that now.
      if ($bool_qpts_grades_only && !isset($qpts_grades [$course->grade])) {
        continue;
      }

      // Do our requirement types match?
      if ($requirement_type == "" || ($requirement_type != "" && $requirement_type == $cr_type)) 
       {
        $h = $course->get_hours();
        $count = $count + $h;
      }

    }
    else {

      // maybe it's a substitution?
      if ($requirement_type == "" || ($requirement_type != "" && $requirement_type == $cr_type)) 
       {
        if ($course->course_list_fulfilled_by->is_empty == false) 
         {
          $cc = $course->course_list_fulfilled_by->get_first();
          if ($cc->get_bool_substitution()) 
           {

            // If we require the grade to be a qpts_grade, then check that now.
            if ($bool_qpts_grades_only && !isset($qpts_grades [$cc->grade])) {
              continue;
            }


            // Make sure we aren't trying to exclude any transfer credits.
            if ($bool_exclude_all_transfer_credits && $cc->bool_transfer) {
              //fpm($requirement_type);
              //fpm($cc);   
              continue;
            }


            $h = $cc->get_substitution_hours();


            if ($cc->bool_ghost_hour) {
              $h = 0;
            }

            $count = $count + $h;
          }
        }
      }

    }
  }



  return $count;

}