function _Course::load_descriptive_data

4.x _Course.php _Course::load_descriptive_data($bool_load_from_global_cache = true, $bool_ignore_catalog_year_in_cache = true, $bool_limit_current_catalog_year = true, $bool_force_catalog_year = false, $bool_ignore_exclude = false)
5.x _Course.php _Course::load_descriptive_data($bool_load_from_global_cache = true, $bool_ignore_catalog_year_in_cache = true, $bool_limit_current_catalog_year = true, $bool_force_catalog_year = false, $bool_ignore_exclude = false, $bool_reset_ghost_hours = TRUE)

This function will load $this will all sorts of descriptive data from the database. For example, hours, title, description, etc.

It must be called before any attempts at sorting (by alphabetical order) are made on lists of courses.

It will by default try to load this information from cache. If it cannot find it in the cache, it will query the database, and then add what it finds to the cache.

Parameters

bool $bool_load_from_global_cache:

  • If set to TRUE, this will attempt to load the course data from the "global cache", that is, the cache which is held in the GLOBALS array. This should usually be set to TRUE, since this is much faster than querying the database.

bool $bool_ignore_catalog_year_in_cache:

  • If set to TRUE, we will grab whatever is in the cache for this course's course_id, regardless of if the catalog years match. If set to FALSE, we will try to match the course's catalog year in the cache as well.

bool $bool_limit_current_catalog_year:

  • If set to TRUE, then we will only *query* for the course's catalog_year in the db, and those before it (if we do not find the exact catalog_year). We will not look for any catalog years after it. If set to FALSE, we will look through any valid catalog year.

bool $bool_force_catalog_year:

  • If set to TRUE, we will only look for the course's catalog year in the database.

bool $bool_ignore_exclude:

  • If set to TRUE, we will ignore courses marked as "exclude" in the database.
2 calls to _Course::load_descriptive_data()
_Course::load_course in classes/_Course.php
Loads $this as a new course, based on course_id.
_Course::to_string in classes/_Course.php
This is the to_string method for Course. Because we want to pass it values, we are not using the magic method of "__to_string". So, to use, invoke this method directly. Ex:

File

classes/_Course.php, line 928

Class

_Course

Code

function load_descriptive_data($bool_load_from_global_cache = true, $bool_ignore_catalog_year_in_cache = true, $bool_limit_current_catalog_year = true, $bool_force_catalog_year = false, $bool_ignore_exclude = false) 
 {

  if ($this->db == null) 
   {
    $this->db = get_global_database_handler();
  }

  $db = $this->db;

  if ($this->catalog_year == "") 
   {
    $this->catalog_year = variable_get("current_catalog_year", 2006); // current catalog_year.
  }

  $setting_current_catalog_year = variable_get("current_catalog_year", 2006) * 1;
  if ($this->bool_use_draft) {
    $setting_current_catalog_year = variable_get("current_catalog_draft_year", 2006) * 1;
  }

  $earliest_catalog_year = variable_get("earliest_catalog_year", 2006);


  if ($setting_current_catalog_year < $earliest_catalog_year) 
   { // If it has not been set, assume the default.
    $setting_current_catalog_year = $earliest_catalog_year;
  }

  if ($bool_limit_current_catalog_year == true && $setting_current_catalog_year > $earliest_catalog_year) 
   {
    if ($this->catalog_year * 1 > $setting_current_catalog_year) 
     {

      $this->catalog_year = $setting_current_catalog_year; // current catalog_year.
    }
  }

  if ($this->catalog_year < $earliest_catalog_year && $this->catalog_year != 1900) 
   {
    // Out of range, so set to default
    $this->catalog_year = $earliest_catalog_year;
  }

  $cat_line = "";
  if ($bool_force_catalog_year == true) 
   {
    $cat_line = " AND catalog_year = '$this->catalog_year' ";
  }


  $cache_catalog_year = $this->catalog_year;
  if ($bool_ignore_catalog_year_in_cache == true) 
   {
    $cache_catalog_year = 0;
  }

  if (!isset($this->array_valid_names)) 
   {
    $this->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 && $this->course_id != 0 && 
    $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["subject_id"] != "") 
   {
    $this->subject_id = $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["subject_id"];
    $this->course_num = $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["course_num"];
    $this->title = $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["title"];
    $this->description = $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["description"];
    $this->min_hours = $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["min_hours"];

    // Reset the ghosthours to default.
    $this->bool_ghost_hour = $this->bool_ghost_min_hour = FALSE;

    if ($this->min_hours <= 0) {
      $this->min_hours = 1;
      $this->bool_ghost_min_hour = TRUE;
    }

    $this->max_hours = $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["max_hours"];

    if ($this->max_hours <= 0) {
      $this->max_hours = 1;
      $this->bool_ghost_hour = TRUE;
    }


    $this->repeat_hours = $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["repeat_hours"];
    $this->db_exclude = $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["db_exclude"];
    $this->array_valid_names = $GLOBALS ["fp_course_inventory"][$this->course_id][$cache_catalog_year]["array_valid_names"];
    return;
  }


  if ($this->course_id != 0) 
   {

    $exclude_line = " AND exclude = '0' ";
    if ($bool_ignore_exclude) {
      $exclude_line = "";
    }

    $table_name = "courses";
    if ($this->bool_use_draft) {
      $table_name = "draft_$table_name";
    }
    $res = $this->db->db_query("SELECT * FROM $table_name
      							WHERE course_id = '?' 
      							AND catalog_year = '?' 
      							AND delete_flag = '0' 
      							$exclude_line ", $this->course_id, $this->catalog_year);
    $cur = $this->db->db_fetch_array($res);


    if ($this->db->db_num_rows($res) < 1) 
     {
      // No results found, so instead pick the most recent
      // entry.

      $table_name = "courses";
      if ($this->bool_use_draft) {
        $table_name = "draft_$table_name";
      }
      $res2 = $db->db_query("SELECT * FROM $table_name
							WHERE course_id = '?' 
							AND subject_id != '' 
							AND delete_flag = '0' 
							$exclude_line
							AND catalog_year <= '$setting_current_catalog_year'
							$cat_line
							ORDER BY `catalog_year` DESC LIMIT 1", $this->course_id);
      $cur = $db->db_fetch_array($res2);

      if ($db->db_num_rows($res2) < 1) 
       {
        // Meaning, there were no results found that didn't have
        // the exclude flag set.
        // So, try to retrieve any course, even if it has
        // been excluded (but within our catalog year range)
        //$db3 = new DatabaseHandler();
        $table_name = "courses";
        if ($this->bool_use_draft) {
          $table_name = "draft_$table_name";
        }
        $res3 = $db->db_query("SELECT * FROM $table_name
							WHERE course_id = '?' 
							AND subject_id != '' 
							AND delete_flag = '0'
							AND catalog_year <= '$setting_current_catalog_year'
							$cat_line
							ORDER BY `catalog_year` DESC LIMIT 1", $this->course_id);
        $cur = $db->db_fetch_array($res3);

      }

    }


    $this->title = $this->fix_title($cur ["title"]);
    $this->description = trim($cur ["description"]);
    $this->subject_id = trim(strtoupper($cur ["subject_id"]));
    $this->course_num = trim(strtoupper($cur ["course_num"]));


    $this->min_hours = $cur ["min_hours"] * 1; //*1 will trim extra zeros from end of decimals
    $this->max_hours = $cur ["max_hours"] * 1;

    // Reset the ghosthours to default.
    $this->bool_ghost_hour = $this->bool_ghost_min_hour = FALSE;

    if ($this->min_hours <= 0) {
      $this->min_hours = 1;
      $this->bool_ghost_min_hour = TRUE;
    }
    if ($this->max_hours <= 0) {
      $this->max_hours = 1;
      $this->bool_ghost_hour = TRUE;
    }


    $this->repeat_hours = $cur ["repeat_hours"] * 1;
    if ($this->repeat_hours <= 0) 
     {
      $this->repeat_hours = $this->max_hours;
    }

    $this->db_exclude = $cur ["exclude"];
    $this->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.
    $table_name = "courses";
    if ($this->bool_use_draft) {
      $table_name = "draft_$table_name";
    }

    $res = $this->db->db_query("SELECT * FROM $table_name
										WHERE course_id = '?'
										AND exclude = '0' ", $this->course_id);
    while ($cur = $this->db->db_fetch_array($res)) 
     {
      $si = $cur ["subject_id"];
      $cn = $cur ["course_num"];
      if (in_array("$si~$cn", $this->array_valid_names)) 
       {
        continue;
      }
      $this->array_valid_names [] = "$si~$cn";
    }


  }
  else if ($this->bool_transfer == true) 
   {
    // This is a transfer credit which did not have a local
    // course eqv.  At the moment, the subject_id and
    // course_num are empty.  So, let's fill them in with the
    // transfer credit's information.
    if ($this->course_transfer != null) 
     {

      $this->subject_id = $this->course_transfer->subject_id;
      $this->course_num = $this->course_transfer->course_num;
      if ($this->course_transfer->hours_awarded > 0) 
       {
        $this->hours_awarded = $this->course_transfer->hours_awarded;
      }
    }


  }


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

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


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

  // We do need to go back and correct the ghost hours, setting them
  // back to 0 hrs, or else this will be a problem.
  $min_hours = $this->min_hours;
  $max_hours = $this->max_hours;
  if ($this->bool_ghost_min_hour) {
    $min_hours = 0;
  }
  if ($this->bool_ghost_hour) {
    $max_hours = 0;
  }


  // Since we may have trouble characters in the description (like smart quotes) let's
  // do our best to try to clean it up a little.
  $this->description = utf8_encode($this->description);


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

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


}