_DatabaseHandler::get_advising_session_id

5.x _DatabaseHandler.php _DatabaseHandler::get_advising_session_id($faculty_id = "", $student_id = "", $term_id = "", $degree_id = "", $bool_what_if = false, $bool_draft = true, $bool_load_any_active_if_faculty_id_not_found = TRUE)
4.x _DatabaseHandler.php _DatabaseHandler::get_advising_session_id($faculty_id = 0, $student_id = "", $term_id = "", $degree_id = "", $bool_what_if = false, $bool_draft = true)

File

classes/_DatabaseHandler.php, line 1041

Class

_DatabaseHandler

Code

function get_advising_session_id($faculty_id = "", $student_id = "", $term_id = "", $degree_id = "", $bool_what_if = false, $bool_draft = true, $bool_load_any_active_if_faculty_id_not_found = TRUE) {
  $is_what_if = "0";
  $is_draft = "0";
  $draft_line = " and `is_draft`='$is_draft' ";
  $faculty_line = " and `faculty_id`='$faculty_id' ";

  $advising_session_id = 0; // init

  if ($faculty_id == 0 || $faculty_id == "") { // If no faculty is specified, just get the first one to come up.
    $faculty_line = "";
  }

  if ($bool_what_if == true) {
    $is_what_if = "1";
  }
  if ($bool_draft == true) {
    $is_draft = "1";
    $draft_line = "";
    // If we are told to pull up draft, we can safely
    // assume we just want the most recent save, whether it
    // is saved as a draft or not.
  }



  $query = "select * from advising_sessions
                where
                    student_id = ?
                $faculty_line
                and term_id = ?
                and degree_id = ?
                and is_whatif = ?
                $draft_line
                order by `posted` desc limit 1";
  $result = $this->db_query($query, array($student_id, $term_id, $degree_id, $is_what_if));
  if ($this->db_num_rows($result) > 0) {
    $cur = $this->db_fetch_array($result);
    $advising_session_id = $cur["advising_session_id"];
    return $advising_session_id;
  }


  if (intval($advising_session_id) < 1 && $bool_load_any_active_if_faculty_id_not_found) {
    // Meaning, we couldn't find a record for the supplied faculty_id.  Let's just load the most recent active one, regardless
    // of faculty_id.  Meaning, we need to make sure that is_draft = 0      
    $query = "select * from advising_sessions
                  where
                      student_id = ?                  
                  and term_id = ?
                  and degree_id = ?
                  and is_whatif = ?                  
                  and is_draft = 0
                  order by `posted` desc limit 1";
    $result = $this->db_query($query, array($student_id, $term_id, $degree_id, $is_what_if));
    if ($this->db_num_rows($result) > 0) {
      $cur = $this->db_fetch_array($result);
      $advising_session_id = $cur["advising_session_id"];
      return $advising_session_id;
    }

  }




  return 0;

}