function _CourseList::count_credit_hours

4.x _CourseList.php _CourseList::count_credit_hours($requirement_type = "", $bool_use_ignore_list = false, $bool_ignore_enrolled = false, $bool_qpts_grades_only = FALSE)
5.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 2054

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;

  // Let's find out what our quality point grades & values are...
  $qpts_grades = array();
  $tlines = explode("\n", variable_get("quality_points_grades", "A ~ 4\nB ~ 3\nC ~ 2\nD ~ 1\nF ~ 0\nI ~ 0"));
  foreach ($tlines as $tline) {
    $temp = explode("~", trim($tline));
    if (trim($temp [0]) != "") {
      $qpts_grades [trim($temp [0])] = trim($temp [1]);
    }
  }



  $enrolled_grades = csv_to_array($GLOBALS ["fp_system_settings"]["enrolled_grades"]);
  $retake_grades = csv_to_array($GLOBALS ["fp_system_settings"]["retake_grades"]);

  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;
      }
    }


    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(@$GLOBALS ["fp_system_settings"]["ignore_courses_from_hour_counts"]))) {
        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;
      }

      /*
				if ($course->is_completed() == false)
				{
  
					if ($course->course_list_fulfilled_by->is_empty)
					{
						continue;
					} else {
						if ($course->course_list_fulfilled_by->get_first()->is_completed() == false)
						{
							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;

}