function _Student::load_student_substitutions
Search API
4.x _Student.php | _Student::load_student_substitutions() |
5.x _Student.php | _Student::load_student_substitutions() |
File
- classes/
_Student.php, line 322
Class
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"];
$req_by_degree_id = $cur ["required_degree_id"];
$db_required_degree_id = $req_by_degree_id;
$db_required_group_id = $cur ["required_group_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 = Course::COURSE_UNKNOWN_TERM_ID;
}
// 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, null, $req_by_degree_id))
{
// 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;
$taken_course->course_id = 0;
}
if ($sub_hours == 0)
{ // If none specified, assume its the full amount.
$sub_hours = $taken_course->get_hours_awarded($req_by_degree_id);
}
if (($taken_course->get_hours_awarded($req_by_degree_id) > $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->get_hours_awarded($req_by_degree_id) - $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->random_id = mt_rand(1, 9999);
$new_course->set_details_by_degree($req_by_degree_id, "bool_substitution_split", TRUE);
$new_course->set_details_by_degree($req_by_degree_id, "bool_substitution_new_from_split", TRUE);
$new_course->subject_id = $taken_course->subject_id;
$new_course->course_num = $taken_course->course_num;
$new_course->set_hours_awarded($req_by_degree_id, $remaining_hours);
$new_course->req_by_degree_id = $req_by_degree_id;
if (is_object($new_course->course_transfer))
{
$new_course->course_transfer->set_hours_awarded($req_by_degree_id, $remaining_hours);
}
//$taken_course->bool_substitution_split = true;
$taken_course->set_details_by_degree($req_by_degree_id, "bool_substitution_split", TRUE);
$taken_course->set_hours_awarded($req_by_degree_id, $sub_hours);
if (is_object($taken_course->course_transfer))
{
$taken_course->course_transfer->set_hours_awarded($req_by_degree_id, $sub_hours);
}
// Add the newCourse back into the student's list_courses_taken.
$this->list_courses_taken->add($new_course);
}
// Place in details_by_degree_array...
//$taken_course->substitution_hours = $sub_hours;
$taken_course->set_details_by_degree($req_by_degree_id, "substitution_hours", $sub_hours);
$taken_course->set_bool_substitution($req_by_degree_id, TRUE);
$taken_course->display_status = "completed";
$taken_course->db_substitution_id_array [$req_by_degree_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_group_ids_array [$cur ["required_group_id"]] = $cur ["required_group_id"];
$course_requirement->assigned_to_semester_num = $cur ["required_semester_num"];
$course_requirement->req_by_degree_id = $req_by_degree_id;
//$taken_course->assigned_to_group_id = $cur["required_group_id"];
$taken_course->assigned_to_group_ids_array [$cur ["required_group_id"]] = $cur ["required_group_id"];
$taken_course->assigned_to_semester_num = $cur ["required_semester_num"];
$taken_course->req_by_degree_id = $req_by_degree_id;
$substitution->course_requirement = $course_requirement;
$substitution->course_list_substitutions->add($taken_course);
$substitution->remarks = $sub_remarks;
$substitution->faculty_id = $faculty_id;
$substitution->db_substitution_id = $sub_id;
$substitution->assigned_to_degree_id = $req_by_degree_id;
$substitution->db_required_degree_id = $req_by_degree_id;
$substitution->db_required_group_id = $db_required_group_id;
$this->list_substitutions->add($substitution);
}
}
}