_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 753

Class

_DatabaseHandler

Code

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

  if ($faculty_id == 0) { // 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`='$student_id'
								$faculty_line
								and `term_id`='$term_id'
								and `degree_id`='$degree_id'
								and `is_whatif`='$is_what_if'
								$draft_line
								order by `posted` desc limit 1";
  $result = $this->db_query($query);
  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;

}