_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)

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

@todo ignore list should be db-based, in the settings.

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 1545

Class

_CourseList

Code

function count_credit_hours($requirement_type = "", $bool_use_ignore_list = false, $bool_ignore_enrolled = false, $bool_qpts_grades_only = FALSE) {
  // 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];

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

    }



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

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

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


      if ($requirement_type == "") {
        $h = $course->get_hours();
        $count = $count + $h;
      }
      else {

        if ($course->requirement_type == $requirement_type) {
          $count = $count + $course->get_hours();
          continue;
        }

        // For specifically "university capstone" courses...
        if ($course->requirement_type == "uc" && $requirement_type == "c") {
          $count = $count + $course->get_hours();
        }

        if ($course->requirement_type == "um" && $requirement_type == "m") {
          $count = $count + $course->get_hours();
        }


      }
    }
    else {

      // maybe it's a substitution?
      if ($requirement_type == "" || ($requirement_type != "" && $requirement_type == $course->requirement_type)) {
        if ($course->course_list_fulfilled_by->is_empty == false) {
          $cc = $course->course_list_fulfilled_by->get_first();
          if ($cc->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;
            }


            $h = $cc->substitution_hours;


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

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

    }
  }


  return $count;

}