function DatabaseHandler::load_course_descriptive_data

7.x DatabaseHandler.php DatabaseHandler::load_course_descriptive_data($course = null, $course_id = 0)
6.x DatabaseHandler.php DatabaseHandler::load_course_descriptive_data($course = null, $course_id = 0)

File

classes/DatabaseHandler.php, line 427

Class

DatabaseHandler

Code

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

  $school_id = 0;
  if ($course == NULL) {
    $school_id = $this->get_school_id_for_course_id($course_id);
  }
  else {
    $school_id = $this->get_school_id_for_course_id($course->course_id);
  }

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

  $array_valid_names = array();



  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"]));
    $cache_catalog_year = $cur ['catalog_year'];

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


    $db_exclude = $cur ["exclude"];
    $db_school_id = $cur ['school_id'];
    $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
                    AND delete_flag = 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]["school_id"] = $db_school_id;
  $GLOBALS ["fp_course_inventory"][$course_id][$cache_catalog_year]["array_valid_names"] = $array_valid_names;

  $cache_catalog_year = 0;

  $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]["school_id"] = $db_school_id;
  $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?







}