_Group::replace_missing_course

5.x _Group.php _Group::replace_missing_course($course_id, $db_group_requirement_id = "")
4.x _Group.php _Group::replace_missing_course($course_id, $db_group_requirement_id = "")

File

classes/_Group.php, line 263

Class

_Group

Code

function replace_missing_course($course_id, $db_group_requirement_id = "") {
  // replace course_id in this group, if it is missing.

  $this->db = new DatabaseHandler();


  $table_name = "group_requirements";
  if ($this->bool_use_draft) {
    $table_name = "draft_$table_name";
  }

  // Look for all instances of this course in the group's base list...
  $res = $this->db->db_query("SELECT * FROM $table_name
									WHERE `group_id`='?'
									AND `course_id`='?' ", $this->group_id, $course_id);
  while ($cur = $this->db->db_fetch_array($res)) {
    $id = $cur["id"];

    for ($t = 0; $t <= $cur["course_repeats"]; $t++) {
      $course = new Course($course_id, false, $db, false, "", $this->bool_use_draft);
      $use_id = $id . "_rep_$t";
      // Make sure the group does not already have this requirementID...
      if ($this->list_courses->contains_group_requirement_id($use_id)) {
        continue;
      }

      $course->assigned_to_group_id = $this->group_id;
      $course->db_group_requirement_id = $use_id;
      $course->specified_repeats = $cur["course_repeats"];
      if ($cur["course_repeats"] > 0) {
        $course->bool_specified_repeat = true;
      }

      $this->list_courses->add($course);
    }
  }

  // Now, go through all of the group's branches and
  // do the same thing.
  $this->list_groups->reset_counter();
  while ($this->list_groups->has_more()) {
    $g = $this->list_groups->get_next();
    $g->replace_missing_course($course_id);
  }




}