function _FlightPath::assign_courses_to_list

4.x _FlightPath.php _FlightPath::assign_courses_to_list(ObjList $list_requirements, Student $student, $bool_perform_assignment = true, Group $group = null, $bool_check_significant_courses = false)
5.x _FlightPath.php _FlightPath::assign_courses_to_list(ObjList $list_requirements, Student $student, $bool_perform_assignment = true, Group $group = null, $bool_check_significant_courses = false)

File

classes/_FlightPath.php, line 419

Class

_FlightPath

Code

function assign_courses_to_list(ObjList $list_requirements, Student $student, $bool_perform_assignment = true, Group $group = null, $bool_check_significant_courses = false) 
 {
  $count = 0;

  if ($group == null) 
   {
    $group = new Group();
    $group->group_id = 0;
  }

  $group_id = $group->group_id;
  // If the group_id == 0, we may be talking about the bare degree plan.

  $hours_required = $group->hours_required * 1;
  $hours_assigned = $group->hours_assigned;

  if ($hours_required * 1 <= 0 || $hours_required == "") 
   {
    $hours_required = 999999;
  }

  //print_pre($list_requirements->to_string());
  $list_requirements->sort_smallest_hours_first();
  $list_requirements->sort_substitutions_first($student->list_substitutions, $group_id);
  $list_requirements->reset_counter();
  while ($list_requirements->has_more()) 
   {
    $course_requirement = $list_requirements->get_next();

    if ($bool_check_significant_courses == true) 
     {
      // Only look for the course_requirement if it is in the student's
      // array_significant_courses array.
      if ($student->array_significant_courses [$course_requirement->course_id] != true) 
       { // course was not in there, so skip!
        continue;
      }
    }




    if ($course_requirement->bool_specified_repeat == true) 
     {
      // Since this requirement has specified repeats, we want
      // to make all of the student's taken courses (for this course)
      // also have specified repeats.
      $student->list_courses_taken->set_specified_repeats($course_requirement, $course_requirement->specified_repeats);
    }

    // Does the student have any substitutions for this requirement?
    if ($substitution = $student->list_substitutions->find_requirement($course_requirement, true, $group_id)) 
     {

      // Since the substitution was made, I don't really care about
      // min grades or the like.  Let's just put it in.

      // Make sure this isn't a group addition and we are *currently*
      // NOT looking at the group it is being added to.  This is to
      // correct a bug.
      if ($substitution->bool_group_addition == true) 
       {

        if ($substitution->course_requirement->assigned_to_group_id != $group_id) 
         {
          continue;
        }

      }



      if ($bool_perform_assignment == true) 
       {
        // If the course_requirement's min_hours are greater than
        // the substitution's hours, then we have to split the
        // coureRequirement into 2 pieces, and add the second piece just
        // after this one in the list.
        $course_sub = $substitution->course_list_substitutions->get_first();
        if ($course_requirement->min_hours * 1 > $course_sub->hours_awarded * 1) 
         {

          // Because float math can create some very strange results, we must
          // perform some rounding.  We will round to 6 decimal places, which should
          // provide us the accuracy w/o losing precision (since we can only represent a max
          // of 4 decimals in the database anyway.
          $remaining_hours = round($course_requirement->min_hours - $course_sub->hours_awarded, 6);

          $new_course_string = $course_requirement->to_data_string();
          $new_course = new Course();
          $new_course->load_course_from_data_string($new_course_string);
          $new_course->min_hours = $new_course->max_hours = $remaining_hours;
          $new_course->bool_substitution_split = true;
          $new_course->bool_substitution_new_from_split = true;
          $new_course->requirement_type = $course_requirement->requirement_type;

          $course_requirement->bool_substitution_split = true;

          // I am commenting this out-- if we split up a sub multiple times, then we shouldn't
          // set the old course requirement to say it WASN'T from a split.  This was causing a bug
          // where the pie charts got weird if you did more than 1 split.  Was counting total
          // hours as more, in CourseList->count_hours().
          //$course_requirement->bool_substitution_new_from_split = false;

          // Now, add this into the list, right after the course_requirement.
          $current_i = $list_requirements->i;
          $list_requirements->insert_after_index($current_i, $new_course);

        }

        $course_requirement->course_list_fulfilled_by = $substitution->course_list_substitutions;

        $substitution->course_list_substitutions->assign_group_id($group_id);
        $substitution->course_list_substitutions->set_has_been_assigned(true);
        $substitution->course_list_substitutions->set_bool_substitution(true);
        $substitution->course_list_substitutions->set_course_substitution($course_requirement, $substitution->remarks);
        $substitution->bool_has_been_applied = true;


      }
      $count++;
      continue;
    }


    // Has the student taken this course requirement?
    if ($c = $student->list_courses_taken->find_best_match($course_requirement, $course_requirement->min_grade, true)) 
     {

      $h_get_hours = $c->get_hours();
      if ($c->bool_ghost_hour) {
        // If this is a ghost hour, then $h_get_hours would == 0 right now,
        // instead, use the the adjusted value (probably 1).
        $h_get_hours = $c->hours_awarded;
      }

      // Can we assign any more hours to this group?  Are we
      // out of hours, and should stop?
      if ($hours_assigned >= $hours_required) 
       {
        continue;
      }

      // Will the hours of this course put us over the hours_required limit?
      if ($hours_assigned + $c->hours_awarded > $hours_required) 
       {
        continue;
      }

      // Do not apply substitutionSplit courses to anything automatically.
      // They must be applied by substitutions.
      if ($c->bool_substitution_new_from_split == true) 
       {
        continue;
      }


      // Make sure the course meets min grade requirements.
      if (!$c->meets_min_grade_requirement_of($course_requirement)) 
       {

        continue;
      }


      // Has the course been unassigned from this group?
      if ($c->group_list_unassigned->find_match($group)) 
       {

        continue;
      }

      // Prereq checking would also go here.

      // Make sure $c is not being used in a substitution.
      if ($c->bool_substitution == true) 
       {

        continue;
      }

      if ($c->bool_has_been_assigned != true) 
       { //Don't count courses which have already been placed in other groups.

        // Has another version of this course already been
        // assigned?  And if so, are repeats allowed for this
        // course?  And if so, then how many hours of the
        // repeat_hours have I used up?  If I cannot do any more
        // repeats, then quit.  Otherwise, let it continue...

        $course_list_repeats = $student->list_courses_taken->get_previous_assignments($c->course_id);


        if ($course_list_repeats->get_size() > 0) 
         {
          // So, a copy of this course has been assigned more than once...
          // Get the total number of hours taken up by this course.
          $cc = $course_list_repeats->count_hours();
          // have we exceeded the number of available repeat_hours
          // for this course?
          if ($course_requirement->repeat_hours <= 0) 
           {
            $course_requirement->load_descriptive_data();
          }

          if ($cc + $h_get_hours > $course_requirement->repeat_hours * 1) 
           {
            // Do not allow the repeat.
            continue;
          }



        }

        // Basically--- if the most recent attempt fails
        // a min grade check, then tag all attempts as "unuseable"
        // so that they can't be used in other groups.  --
        // unless they are able to be repeated.  BARF!

        // Inc hours_assigned, even if we aren't actually
        // performing an assignment.  This helps us accurately
        // calculate the count.

        $hours_assigned = $hours_assigned + $h_get_hours;

        if ($bool_perform_assignment == true) 
         {
          $course_requirement->course_list_fulfilled_by->add($c);
          $course_requirement->grade = $c->grade;
          $course_requirement->hours_awarded = $c->hours_awarded;
          $course_requirement->bool_ghost_hour = $c->bool_ghost_hour;

          $c->bool_has_been_assigned = true;
          $c->requirement_type = $course_requirement->requirement_type;
          $c->assigned_to_group_id = $group_id;
          $group->hours_assigned = $hours_assigned;
          // Should check for:
          // Can it be assigned, based on the number of allowed course repeats?
          if ($course_requirement->bool_specified_repeat == true) 
           {
            // $c is what they actually took.
            $c->bool_specified_repeat = true;
            $c->specified_repeats = $course_requirement->specified_repeats;
            $list_requirements->dec_specified_repeats($c);
          }
        }


        $count++;
      }
    }

  }


  return $count;
}