function DegreePlan::get_max_course_appears_in_degrees_count

7.x DegreePlan.php DegreePlan::get_max_course_appears_in_degrees_count($test_group_id)
6.x DegreePlan.php DegreePlan::get_max_course_appears_in_degrees_count($test_group_id)

Given a group_id, find out if this group contains a course which appears in other degrees. Return the max number.

File

classes/DegreePlan.php, line 109

Class

DegreePlan

Code

function get_max_course_appears_in_degrees_count($test_group_id) {

  // array is sectioned like:  course_id | degree_id | group_id.    Group id = 0 means "on the bare degree plan"
  // ex:  $this->required_course_id_array[$course_c->course_id][$this->degree_id][0] = TRUE;      

  $exclude_degree_ids = system_get_exclude_degree_ids_from_appears_in_counts($this->school_id);

  $courses = array();

  foreach ($this->required_course_id_array as $course_id => $temp1) {
    foreach ($this->required_course_id_array [$course_id] as $degree_id => $temp2) {

      // Is this an excluded degree?  If so, skip it.
      if (in_array($degree_id, $exclude_degree_ids)) {
        continue;
      }

      foreach ($this->required_course_id_array [$course_id][$degree_id] as $group_id => $val) {

        // Is this the group we are looking for?
        if ($group_id != $test_group_id) {
          continue;
        }

        // Otherwise, yes, we are in the right group.  Let's keep track of what courses we have in this group:                    
        $courses [$course_id] = TRUE;

      }
    }
  }

  $course_count = array();

  // Okay, now what we want to do is find out, how many different degrees do these courses appear in?
  foreach ($this->required_course_id_array as $course_id => $temp1) {

    if (!isset($courses [$course_id])) {
      continue; // wasn't in our list, so skip.
    }
    $course_count [$course_id] = 0;

    foreach ($this->required_course_id_array [$course_id] as $degree_id => $temp2) {

      $course_count [$course_id];

    }
  }



  // Okay, coming out of this, we can sort the courses_degrees array, and return the highest number.
  ++rsort($course_count);

  //fpm($course_count);

  return @$course_count [0]; // first element should be the highest value.

}