function _DatabaseHandler::load_course_descriptive_data

4.x _DatabaseHandler.php _DatabaseHandler::load_course_descriptive_data($course = null, $course_id = 0)
5.x _DatabaseHandler.php _DatabaseHandler::load_course_descriptive_data($course = null, $course_id = 0)

File

classes/_DatabaseHandler.php, line 439

Class

_DatabaseHandler

Code

function load_course_descriptive_data($course = null, $course_id = 0) 
 {

  $current_catalog_year = variable_get("current_catalog_year", "2006");
  $catalog_year = $current_catalog_year; // currentCatalogYear.
  if ($course != null) 
   {
    $course_id = $course->course_id;
    $catalog_year = $course->catalog_year;
  }


  $cache_catalog_year = $catalog_year;

  $cache_catalog_year = 0;

  $array_valid_names = array();
  // First-- is this course in our GLOBALS cache for courses?
  // If it is, then load from that.
  if ($bool_load_from_global_cache == true && 
    $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["subject_id"] != "") 
   {
    $subject_id = $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["subject_id"];
    $course_num = $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["course_num"];
    $title = $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["title"];
    $description = $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["description"];
    $min_hours = $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["min_hours"];
    $max_hours = $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["max_hours"];
    $repeat_hours = $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["repeat_hours"];
    $db_exclude = $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["db_exclude"];
    $array_valid_names = $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["array_valid_names"];
    // load this into the course object, if not null.

    return;
  }


  if ($course_id != 0) 
   {
    $res = $this->db_query("SELECT * FROM courses
							WHERE course_id = '?' 
							AND catalog_year = '?'
							AND catalog_year <= '?' 
							AND delete_flag = '0' 
							AND exclude = '0' ", $course_id, $catalog_year, $current_catalog_year);
    $cur = $this->db_fetch_array($res);

    if ($this->db_num_rows($res) < 1) 
     {

      // No results found, so instead pick the most recent
      // catalog year that is not excluded (keeping below the
      // current catalog year from the settings)

      //$this2 = new DatabaseHandler();
      $res2 = $this->db_query("SELECT * FROM courses
							WHERE `course_id`='?' 
							AND `subject_id`!='' 
							AND `delete_flag` = '0' 
							AND `exclude`='0'
							AND `catalog_year` <= '?'
							ORDER BY `catalog_year` DESC LIMIT 1", $course_id, $current_catalog_year);
      $cur = $this->db_fetch_array($res2);

      if ($this->db_num_rows($res2) < 1) 
       {

        // Meaning, there were no results found that didn't have
        // the exclude flag set.  So, as a last-ditch effort,
        // go ahead and try to retrieve any course, even if it has
        // been excluded. (keeping below the
        // current catalog year from the settings)

        //$this3 = new DatabaseHandler();
        //
        $res3 = $this->db_query("SELECT * FROM courses
							WHERE course_id = '?' 
							AND subject_id != '' 
							AND delete_flag = '0' 
						  AND catalog_year <= '?'	
							ORDER BY catalog_year DESC LIMIT 1", $course_id, $current_catalog_year);
        $cur = $this->db_fetch_array($res3);

      }

    }


    $title = $cur ["title"];
    $description = trim($cur ["description"]);
    $subject_id = trim(strtoupper($cur ["subject_id"]));
    $course_num = trim(strtoupper($cur ["course_num"]));



    if ($min_hours < 1) 
     {
      $min_hours = $cur ["min_hours"];
      $max_hours = $cur ["max_hours"];
      $repeat_hours = $cur ["repeat_hours"];
      if ($repeat_hours * 1 < 1) 
       {
        $repeat_hours = $max_hours;
      }
    }

    $db_exclude = $cur ["exclude"];
    $data_entry_comment = $cur ["data_entry_comment"];

    // Now, lets get a list of all the valid names for this course.
    // In other words, all the non-excluded names.  For most
    // courses, this will just be one name.  But for cross-listed
    // courses, this will be 2 or more (probably just 2 though).
    // Example: MATH 373 and CSCI 373 are both valid names for that course.
    $res = $this->db_query("SELECT * FROM courses
										WHERE course_id = '?'
										AND exclude = '0' ", $course_id);
    while ($cur = $this->db_fetch_array($res)) 
     {
      $si = $cur ["subject_id"];
      $cn = $cur ["course_num"];
      if (in_array("$si~$cn", $array_valid_names)) 
       {
        continue;
      }
      $array_valid_names [] = "$si~$cn";
    }


  }





  if ($description == "") 
   {
    $description = "There is no course description available at this time.";
  }

  if ($title == "") 
   {
    $title = "$subject_id $course_num";
  }


  // Now, to reduce the number of database calls in the future, save this
  // to our GLOBALS cache...

  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["subject_id"] = $subject_id;
  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["course_num"] = $course_num;
  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["title"] = $title;
  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["description"] = $description;
  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["min_hours"] = $min_hours;
  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["max_hours"] = $max_hours;
  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["repeat_hours"] = $repeat_hours;
  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["db_exclude"] = $db_exclude;
  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["array_valid_names"] = $array_valid_names;

  $GLOBALS ["cache_course_inventory"] = true; //  rebuild this cache before it closes.


  // Should we put all this into our course object?







}