function FlightPath::assign_courses_to_groups

7.x FlightPath.php FlightPath::assign_courses_to_groups()
6.x FlightPath.php FlightPath::assign_courses_to_groups()

File

classes/FlightPath.php, line 391

Class

FlightPath

Code

function assign_courses_to_groups() {


  // This method will look at the student's courses
  // and decide which groups they should be fit into.

  // We will be going through the degree plan's master list
  // of groups to decide this.
  $student = $this->student;
  $school_id = $student->school_id;

  $this->degree_plan->list_groups->sort_priority();
  // Now, sort by the advising weight of the degree itself.    
  $this->degree_plan->list_groups->sort_degree_advising_weight();


  $this->degree_plan->list_groups->reset_counter();
  while ($this->degree_plan->list_groups->has_more()) 
   {
    $g = $this->degree_plan->list_groups->get_next();

    if ($g->group_id == DegreePlan::GROUP_ID_FOR_COURSES_ADDED) 
     {
      // Add a course group.  Skip.
      continue;
    }

    // Does the student have any group additions for this
    // group?  Technically it is a substitution.
    // We will add them in now, because we do not take additions
    // into consideration when figuring out branches.
    if ($course_list_additions = $student->list_substitutions->find_group_additions($g)) 
     {
      $course_list_additions->reset_counter();
      while ($course_list_additions->has_more()) 
       {
        $cA = $course_list_additions->get_next();
        $new_course = new Course();
        $new_course->course_id = $cA->course_id;

        if ($cA->bool_transfer == true) 
         {
          if ($cA->course_id == 0 && is_object($cA->course_transfer)) 
           { // This is a transfer course which has been added.
            $new_course->course_id = $cA->course_transfer->course_id;
          }
          $new_course->bool_transfer = true;
        }

        $new_course->assigned_to_semester_num = $g->assigned_to_semester_num;
        $new_course->requirement_type = $g->requirement_type;
        // Add this course as a requirement.
        //$new_course->load_descriptive_data();
        $g->list_courses->add($new_course, true);
        // Later on, when we do assign_courses_to_list, it
        // will automatically find this course and apply the
        // substitution.
      }
    }

    // First we see if there are any bare courses at this level.  If there
    // are, then this group has NO branches!  Otherwise, the courses must
    // always be contained in a branch!
    if (!$g->list_courses->is_empty) 
     {

      // Yes, there are courses here.  So, assign them at this level.        
      $this->assign_courses_to_list($g->list_courses, $this->student, true, $g, true);
      // Okay, if we have fulfilled our courses at this level.

      // then we can continue on to the next "top level" group.
      //continue;
    }



    if (!$g->list_groups->is_empty) 
     {
      /*
        Now we've got some trouble.  This is our first level of groups.
        If this object exists, then it means that this group branches off
        at its first level.  So, instead of actually assigning courses to
        groups, we need to find out which group has the most matches, and THEN
        we will assign them.
        */




      $g->reload_missing_courses();

      $high_count = -1;
      $best_branch = -1;

      // Sort our list of groups by student's grades, if applicable.        
      $sort_policy = variable_get_for_school("initial_student_course_sort_policy", "alpha", $school_id); // will either be "alpha" or "grade"
      if ($sort_policy == "grade") {
        $g->list_groups->sort_best_grade_first_by_student_grades($student);
      }


      $g->list_groups->reset_counter();
      while ($g->list_groups->has_more()) 
       {
        $branch_one = $g->list_groups->get_next();
        if (!$branch_one->list_courses->is_empty) 
         {
          // This does not actually assign.  Just counts.
          $count = $this->get_count_of_matches($branch_one, $this->student, $g);
          $branch_one->count_of_matches = $count;

          if ($count > $high_count) 
           {
            $high_count = $count;

            $best_branch = $g->list_groups->object_index_of($branch_one);

          }
        }

      }
      // Okay, coming out of that, we should know which branch has the best count (number
      // of matches).  So, let's assign courses to that branch.
      if ($best_branch != -1) 
       {
        $winning_branch = $g->list_groups->get_element($best_branch);
        $winning_branch->bool_winning_branch = TRUE;
        $this->assign_courses_to_list($winning_branch->list_courses, $this->student, TRUE, $g, TRUE);
      }

    }


  } // while 

}