function _Student::load_student_substitutions

4.x _Student.php _Student::load_student_substitutions()
5.x _Student.php _Student::load_student_substitutions()

File

classes/_Student.php, line 315

Class

_Student

Code

function load_student_substitutions() 
 {
  // Load the substitutions which have been made for
  // this student.

  // Meant to be called AFTER load_courses_taken.
  $this->list_substitutions = new SubstitutionList();

  $res = $this->db->db_query("SELECT * FROM
						student_substitutions
						WHERE student_id='?'
						AND delete_flag='0' ", $this->student_id);
  while ($cur = $this->db->db_fetch_array($res)) 
   {

    $sub_id = $cur ["id"];
    $sub_course_id = $cur ["sub_course_id"];
    $sub_term_id = $cur ["sub_term_id"];
    $sub_bool_transfer = (bool) $cur ["sub_transfer_flag"];
    $sub_hours = $cur ["sub_hours"] * 1;
    $sub_remarks = trim($cur ["sub_remarks"]);
    $faculty_id = $cur ["faculty_id"];

    if (strstr($sub_term_id, "9999")) 
     {
      // was an unknown semester.  Let's set it lower so
      // it doesn't screw up my sorting.
      $sub_term_id = 11111;
    }


    // Okay, look to see if we can find the course specified by this
    // courseSubstitution within the list of courses which the student
    // has taken.  If the subHours is less than the hours_awarded for the
    // particular course, it means the course has been split up!

    if ($taken_course = $this->list_courses_taken->find_specific_course($sub_course_id, $sub_term_id, $sub_bool_transfer, true)) 
     {


      // If this takenCourse is a transfer credit, then we want to remove
      // any automatic eqv it may have set.
      // We can do this easily by setting its course_id to 0.
      if ($sub_bool_transfer == true) 
       {
        $taken_course->temp_old_course_id = $taken_course->course_id;
        $taken_course->course_id = 0;
      }

      if ($sub_hours == 0) 
       { // If none specified, assume its the full amount.				  
        $sub_hours = $taken_course->hours_awarded;
      }


      if (($taken_course->hours_awarded > $sub_hours)) 
       {


        // Okay, now this means that the course which we are
        // using in the substitution-- the course which the student
        // has actually taken-- is being split up in the substitution.
        // We are only using a portion of its hours.
        // We MUST round, because if there is a decimal place, we might run into
        // trouble.  Because, for example, 2.001 - 2 actually gets .00009999999 instead of .001.
        // The most decimals we can have is 4, so let's round to 6 decimal places, just to give
        // us some breathing room.  That should take care of us without losing too much precision.
        $remaining_hours = round(($taken_course->hours_awarded - $sub_hours), 6);

        // Create a clone of the course with the leftover hours, and add
        // it back into the list_courses_taken.
        $new_course_string = $taken_course->to_data_string();
        $new_course = new Course();
        $new_course->load_course_from_data_string($new_course_string);

        $new_course->bool_substitution_split = true;
        $new_course->bool_substitution_new_from_split = true;

        $new_course->subject_id = $taken_course->subject_id;
        $new_course->course_num = $taken_course->course_num;

        $new_course->hours_awarded = $remaining_hours;
        if (is_object($new_course->course_transfer)) 
         {
          $new_course->course_transfer->hours_awarded = $remaining_hours;
        }

        $taken_course->bool_substitution_split = true;
        $taken_course->hours_awarded = $sub_hours;
        if (is_object($taken_course->course_transfer)) 
         {
          $taken_course->course_transfer->hours_awarded = $sub_hours;
        }


        // Add the newCourse back into the student's list_courses_taken.
        $this->list_courses_taken->add($new_course);

      }


      $taken_course->substitution_hours = $sub_hours;
      $taken_course->bool_substitution = true;
      $taken_course->display_status = "completed";
      $taken_course->db_substitution_id = $sub_id;


      $substitution = new Substitution();

      if ($cur ["required_course_id"] > 0) 
       {
        $course_requirement = new Course($cur ["required_course_id"]);

        $this->array_significant_courses [$course_requirement->course_id] = true;

      }
      else {
        // This is a group addition!
        $course_requirement = new Course($sub_course_id, $sub_bool_transfer);
        $this->array_significant_courses [$sub_course_id] = true;
        $substitution->bool_group_addition = true;
      }

      $course_requirement->assigned_to_group_id = $cur ["required_group_id"];
      $course_requirement->assigned_to_semester_num = $cur ["required_semester_num"];
      $taken_course->assigned_to_group_id = $cur ["required_group_id"];
      $taken_course->assigned_to_semester_num = $cur ["required_semester_num"];

      $substitution->course_requirement = $course_requirement;


      $substitution->course_list_substitutions->add($taken_course);


      $substitution->remarks = $sub_remarks;
      $substitution->faculty_id = $faculty_id;
      $this->list_substitutions->add($substitution);



    }

  }

}