function DatabaseHandler::get_course_id

6.x DatabaseHandler.php DatabaseHandler::get_course_id($subject_id, $course_num, $catalog_year = "", $bool_use_draft = FALSE, $school_id = 0, $bool_check_allow_default_school = FALSE)

File

classes/DatabaseHandler.php, line 1125

Class

DatabaseHandler

Code

function get_course_id($subject_id, $course_num, $catalog_year = "", $bool_use_draft = FALSE, $school_id = 0, $bool_check_allow_default_school = FALSE) 
 {
  // Ignore the colon, if there is one.
  if (strpos($course_num, ":")) 
   {
    //$course_num = substr($course_num,0,-2);
    $temp = explode(":", $course_num);
    $course_num = trim($temp [0]);
  }

  $params = array();

  $school_line = " AND school_id = :school_id ";

  // Should we ALSO check the default school, in addition to whatever we specified?  Don't bother if what we specified was the default school.
  if ($bool_check_allow_default_school && module_enabled('schools') && variable_get('schools_allow_courses_from_default_school', 'yes') === 'yes' && $school_id != 0) {
    $school_line = " AND (school_id = :school_id OR school_id = 0) ";
  }


  // Always override if the global variable is set.
  if (@$GLOBALS ["fp_advising"]["bool_use_draft"] == true) {
    $bool_use_draft = true;
  }




  $catalog_line = "";

  if ($catalog_year != "") 
   {
    $catalog_year = intval($catalog_year);
    $catalog_line = "and catalog_year = '$catalog_year' ";
  }

  $table_name = "courses";
  if ($bool_use_draft) {
    $table_name = "draft_$table_name";
  }

  $params [':subject_id'] = $subject_id;
  $params [':course_num'] = $course_num;
  $params [':school_id'] = intval($school_id);


  $res7 = $this->db_query("SELECT course_id FROM $table_name
              WHERE subject_id = :subject_id
              AND course_num = :course_num
              $school_line
              $catalog_line
               ORDER BY catalog_year DESC LIMIT 1 ", $params);
  if ($this->db_num_rows($res7) > 0) 
   {
    $cur7 = $this->db_fetch_array($res7);
    return intval($cur7 ["course_id"]);
  }
  return FALSE;
}