function DatabaseHandler::duplicate_course_for_year

7.x DatabaseHandler.php DatabaseHandler::duplicate_course_for_year($course = NULL, $catalog_year = 0, $bool_delete_existing = TRUE)
6.x DatabaseHandler.php DatabaseHandler::duplicate_course_for_year($course = null, $catalog_year)

Note that the $course object need not be a Course object, but rather a simple stdClass() with certain properties set. Specifically, the values we see being input into draft_courses in this function.

File

classes/DatabaseHandler.php, line 556

Class

DatabaseHandler

Code

function duplicate_course_for_year($course = NULL, $catalog_year = 0, $bool_delete_existing = TRUE) 
 {
  // Duplicate the course for the given catalog_year.
  // If it already exists for that catalog_year, delete it from the
  // table.
  // In other words, copy all course data from some valid year into this
  // new year.

  $c = $course;
  $course_id = $c->course_id;



  $min_hours = $c->min_hours;
  $max_hours = $c->max_hours;

  if (@$c->bool_ghost_min_hour) {
    $min_hours = 0;
  }

  if (@$c->bool_ghost_hour) {
    $max_hours = 0;
  }


  if ($bool_delete_existing) {
    $res = $this->db_query("DELETE FROM draft_courses
                              WHERE
                              course_id = ?
                              AND catalog_year = ?
                              AND subject_id = ?
                              AND course_num = ?
                              AND school_id = ? ", $course_id, $catalog_year, $c->subject_id, $c->course_num, $c->school_id);
  }

  $res2 = $this->db_query("INSERT INTO draft_courses(course_id,
                subject_id, course_num, catalog_year,
                title, description, min_hours, max_hours,
                repeat_hours, exclude, school_id) values (
                ?,?,?,?,?,?,?,?,?,?,?)
                ", $course_id, $c->subject_id, $c->course_num, $catalog_year, $c->title, $c->description, $min_hours, $max_hours, 
  $c->repeat_hours, $c->db_exclude, $c->school_id);



}