function _FlightPath::load_advising_session_from_database

4.x _FlightPath.php _FlightPath::load_advising_session_from_database($faculty_id = 0, $term_id = "", $bool_what_if = false, $bool_draft = true, $advising_session_id = 0)
5.x _FlightPath.php _FlightPath::load_advising_session_from_database($faculty_id = 0, $term_id = "", $bool_what_if = false, $bool_draft = true, $advising_session_id = 0, $duplicate_for_faculty_id = 0)

File

classes/_FlightPath.php, line 1266

Class

_FlightPath

Code

function load_advising_session_from_database($faculty_id = 0, $term_id = "", $bool_what_if = false, $bool_draft = true, $advising_session_id = 0) 
 {
  // This method will load an advising session for a particular
  // student, and modify the degree plan object to reflect
  // the advisings.
  $db = new DatabaseHandler();
  $is_what_if = "0";
  $is_draft = "0";
  if ($bool_what_if == true) {
    $is_what_if = "1";
  }
  if ($bool_draft == true) {
    $is_draft = "1";
  }

  $degree_id = $this->degree_plan->degree_id;
  $student_id = $this->student->student_id;
  $available_terms = variable_get("available_advising_term_ids", "0");

  $advising_session_line = " `advising_session_id`='$advising_session_id' ";
  // First, find the advising session id...
  if ($advising_session_id < 1 && $available_terms == "") 
   {
    $advising_session_id = $this->db->get_advising_session_id($faculty_id, $student_id, $term_id, $degree_id, $bool_what_if, $bool_draft);
    $advising_session_line = " `advising_session_id`='$advising_session_id' ";


  }
  else if ($advising_session_id < 1 && $available_terms != "") 
   {
    // Meaning, we are looking for more than one term.
    $advising_session_line = "(";
    $temp = explode(",", $available_terms);
    for ($t = 0; $t < count($temp); $t++) 
     {
      $t_id = trim($temp [$t]);

      $asid = $this->db->get_advising_session_id($faculty_id, $student_id, $t_id, $degree_id, $bool_what_if, $bool_draft);
      if ($asid != 0) 
       {
        $advising_session_line .= " advising_session_id='$asid' || ";
      }
    }
    // Take off the last 3 chars...
    $advising_session_line = substr($advising_session_line, 0, -3);
    $advising_session_line .= ")";
    if ($advising_session_line == ")") 
     { // Found NO previously advised semesters, so just
      // use a dummy value which guarantees it pulls up nothing.
      $advising_session_line = " advising_session_id='-99999'";
    }

  }

  // Now, look up the courses they were advised to take.
  $query = "SELECT * FROM advised_courses
								WHERE 
								 $advising_session_line
								ORDER BY `id` ";
  //fpm($query);
  $result = $db->db_query($query);
  while ($cur = $db->db_fetch_array($result)) 
   {
    $course_id = trim($cur ["course_id"]);
    $semester_num = trim($cur ["semester_num"]);
    $group_id = trim($cur ["group_id"]);
    $var_hours = trim($cur ["var_hours"]);
    $advised_term_id = trim($cur ["term_id"]);
    $id = trim($cur ["id"]);
    //fpm("course $course_id sem:$semester_num group:$group_id $var_hours");

    // Add this course to the generic list of advised courses.  Useful
    // if we are using this to pull up an advising summary.
    $temp_course = new Course($course_id);
    $temp_course->advised_hours = $var_hours;
    $this->course_list_advised_courses->add($temp_course);

    if ($semester_num == -88) 
     {
      // This was a courses added by the advisor.
      $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
      continue;
    }

    // Now, we need to modify the degree_plan object to
    // show these advisings.
    if ($course_list = $this->degree_plan->find_courses($course_id, $group_id, $semester_num)) 
     {
      //fpm("I found course $course_id sem:$semester_num group:$group_id $var_hours");
      //fpm($course_list);
      // This course may exist in several different branches of a group, so we need
      // to mark all the branches as having been advised to take.  Usually, this CourseList
      // will probably only have 1 course object in it.  But, better safe than sorry.
      $course_list->reset_counter();
      if ($course = $course_list->get_next()) 
       {
        // make sure the hour count has been loaded correctly.
        if ($course->get_catalog_hours() < 1) 
         {
          $course->load_descriptive_data();
        }

        // Let's start by looking at the first course.  Is it
        // supposed to be repeated?
        if ($course->bool_specified_repeat == true
         && $course->specified_repeats >= 0) 
         {
          // This is a course which is supposed to be repeated.
          // We need to cycle through and find an instance
          // of this course which has not been advised yet.


          $course_list->reset_counter();
          while ($course_list->has_more()) 
           {
            $course = $course_list->get_next();

            // make sure the hour count has been loaded correctly.
            if ($course->get_catalog_hours() < 1) 
             {
              $course->load_descriptive_data();
            }

            //if ($course->bool_advised_to_take != true && !is_object($course->courseFulfilledBy))
            if ($course->bool_advised_to_take != true && $course->course_list_fulfilled_by->is_empty == true) 
             {
              // Okay, this course is supposed to be taken/advised
              // more than once.  So, I will mark this one as
              // advised, and then break out of the loop, since
              // I don't want to mark all occurances as advised.
              $course->bool_advised_to_take = true;
              $course->assigned_to_semester_num = $semester_num;
              $course->assigned_to_group_id = $group_id;

              // Make sure we assign the hours to the group, so this
              // advised courses takes up a spot in the group.  Otherwise
              // it may be missed in later logic.
              if ($g = $this->degree_plan->find_group($group_id)) {
                $h = $var_hours;
                if ($h == 0) {
                  $h = $course->get_catalog_hours();
                  if ($h == 0) {
                    $h = 1; // some problem occured. Just give it a token hour so it doesn't
                    // horribly break.
                  }
                }
                $g->hours_assigned += $h;
              }


              $course->advised_hours = $var_hours;
              $course->advised_term_id = $advised_term_id;
              $course->db_advised_courses_id = $id;
              $course_list->dec_specified_repeats($course);
              break;
            }
          }
          continue; // Go to the next advised course.
        }
      }

      //////////////////////////////
      // We're here, because it was not a repeatable course.
      // ** We should only go through THIS loop once!  So,
      // we will break after we make our assignment.
      $course_list->reset_counter();
      while ($course_list->has_more()) 
       {
        $course = $course_list->get_next();
        // make sure the hour count has been loaded correctly.
        if ($course->get_catalog_hours() < 1) 
         {
          $course->load_descriptive_data();
        }

        // make sure it has not already been advised to take.
        // Would occur if the same course is specified more
        // than once in a semester.
        if ($course->bool_advised_to_take == true) 
         {
          continue;
        }

        // Has this course already been fulfilled by something?
        // If so, we cannot attempt to say it's been advised!
        if (!$course->course_list_fulfilled_by->is_empty) 
         {
          // meaning, this course HAS been fulfilled.
          // So, let's move this advising to the "added by advisor"
          // spot.
          $this->assign_course_to_courses_added_list($course_id, $var_hours, $id, $advised_term_id);
          break;
        }

        //fpm($course);
        $course->bool_advised_to_take = true;
        $course->assigned_to_semester_num = $semester_num;
        $course->assigned_to_group_id = $group_id;

        // Make sure we assign the hours to the group, so this
        // advised courses takes up a spot in the group.  Otherwise
        // it may be missed in later logic.
        if ($g = $this->degree_plan->find_group($group_id)) {
          $h = $var_hours;
          if ($h == 0) {
            $h = $course->get_catalog_hours();
            if ($h == 0) {
              $h = 1; // some problem occured. Just give it a token hour so it doesn't
              // horribly break.
            }
          }
          $g->hours_assigned += $h;

        }

        $course->advised_hours = $var_hours;
        $course->advised_term_id = $advised_term_id;
        $course->db_advised_courses_id = $id;
        if ($course->required_on_branch_id > 0) 
         {
          // In other words, this course was found on a branch, so we need
          // to increment that branch's count_of_matches.
          if ($branch = $this->degree_plan->find_group($course->required_on_branch_id)) 
           {
            $branch->count_of_matches++;
          }
          else {
            fpm("Error: Could not find branch.");
          }

        }

        // We should only be in this loop once, so let's
        // break after we make our assignment.
        break;

      }

    }

  }

  // Now, what we need to do is tell the DegreePlan to re-sort its
  // group's course lists, so that the advised courses are lower
  // than the fulfilled courses.

  //$this->degree_plan->sortGroupsFulfilledFirst();
  //print_pre($this->degree_plan->list_groups->toString());

}