function Group::load_group

7.x Group.php Group::load_group($bool_load_significant_only = true, $array_significant_courses = false, $bool_reload_missing_only = false)
6.x Group.php Group::load_group($bool_load_significant_only = true, $array_significant_courses = false, $bool_reload_missing_only = false)
2 calls to Group::load_group()

File

classes/Group.php, line 208

Class

Group

Code

function load_group($bool_load_significant_only = true, $array_significant_courses = false, $bool_reload_missing_only = false) 
 {
  $this->load_descriptive_data();
  if ($this->db_delete_flag == 1) 
   {
    return;
  }

  $bool_significant_courses_empty = true;
  if (is_array($array_significant_courses)) 
   {
    $bool_significant_courses_empty = false;
  }

  if ($bool_reload_missing_only == true) 
   {
    // We are only going to load the *missing* courses from
    // this group.  So, begin by getting an array of what is
    // not missing.

    $array_group_requirement_ids = $this->list_courses->get_group_requirement_id_array();

  }

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

  $res = db_query("SELECT * FROM `$table_name`
							WHERE group_id = ?	", $this->get_db_group_id());
  while ($cur = db_fetch_array($res)) 
   {

    $id = $cur ["id"];
    $course_id = intval($cur ["course_id"]);

    // The group requirements table doesn't have a school_id.
    //$this->school_id = intval($cur['school_id']);

    if ($cur ["course_id"] * 1 > 0) 
     {
      if ($bool_load_significant_only == true && $bool_significant_courses_empty == false) 
       {
        // If this course_id is NOT in the array of significant courses
        // (that the student took or has transfer credit or subs for)
        // then skip it.  Never add it to the group.					
        if (isset($array_significant_courses [$cur ["course_id"]]) && $array_significant_courses [$cur ["course_id"]] != true) 
         { // course was not in there, so skip!
          continue;
        }


      }


      // A course is the next requirement.

      // Is this more than XX repeats?  If so, we consider it "infinite"
      if ($cur ['course_repeats'] <= Group::GROUP_COURSE_INFINITE_REPEATS_THRESHOLD) {
        // Less than XX repeats, so treat it like a normal course.
        for ($t = 0; $t <= $cur ["course_repeats"]; $t++) 
         { // Add in the specified repeats for this group...
          // This will usually only go through the loop once.

          $use_id = $id . "_rep_$t";

          if ($bool_reload_missing_only == true) 
           {
            // Only load this course if it is missing from the group.
            // Read the reload_missing_courses() method for an explanation
            // of why we should want to do this.
            // Basically, check all the courses in the current
            // list_courses object for a db_group_requirement_id of $id.
            // Only proceed if $id was NOT found.

            if (@$array_group_requirement_ids [$use_id] == true) 
             {
              continue;
            }
          }

          $course_c = new Course();
          $course_c->bool_use_draft = $this->bool_use_draft;
          $course_c->course_id = $cur ["course_id"];
          $course_c->db_group_attributes = $cur ['attributes'];
          $course_c->db_group_requirement_id = $use_id;
          $course_c->db = $this->db;
          $course_c->catalog_year = $this->catalog_year;
          $course_c->assigned_to_group_id = $this->group_id;
          $course_c->assigned_to_semester_num = $this->assigned_to_semester_num;


          $course_c->specified_repeats = $cur ["course_repeats"];
          if ($cur ["course_repeats"] > 0) 
           {
            $course_c->bool_specified_repeat = true;
          }

          $course_c->min_grade = trim(strtoupper($cur ["course_min_grade"]));
          if ($course_c->min_grade == "") 
           { // By default, all courses have a
            // min grade requirement of D.
            $course_c->min_grade = "D";
          }


          $this->list_courses->add($course_c);
        } // for t <= cur['course_repeats']
      }
      else {
        // We are dealing with a course with "infinite" repeats.
        $use_id = $id . "_rep_999";

        if ($bool_reload_missing_only == true) 
         {
          // Only load this course if it is missing from the group.
          // Read the reload_missing_courses() method for an explanation
          // of why we should want to do this.
          // Basically, check all the courses in the current
          // list_courses object for a db_group_requirement_id of $id.
          // Only proceed if $id was NOT found.
          if (@$array_group_requirement_ids [$use_id] == true) 
           {
            continue;
          }
        }

        $course_c = new Course();
        $course_c->bool_use_draft = $this->bool_use_draft;
        $course_c->course_id = $cur ["course_id"];
        $course_c->db_group_attributes = $cur ['attributes'];
        $course_c->db_group_requirement_id = $use_id;
        $course_c->db = $this->db;
        $course_c->catalog_year = $this->catalog_year;
        $course_c->assigned_to_group_id = $this->group_id;
        $course_c->assigned_to_semester_num = $this->assigned_to_semester_num;


        $course_c->specified_repeats = Group::GROUP_COURSE_INFINITE_REPEATS;
        $course_c->bool_specified_repeat = true;

        $course_c->min_grade = trim(strtoupper($cur ["course_min_grade"]));
        if ($course_c->min_grade == "") 
         { // By default, all courses have a
          // min grade requirement of D.
          $course_c->min_grade = "D";
        }


        $this->list_courses->add($course_c);

      }



    } // if cur['course_id']


    if ($cur ["child_group_id"] * 1 > 0) 
     {

      $temp_add_as_new_group = FALSE;

      // Another group is the next requirement (its a branch)
      if ($bool_reload_missing_only == true) 
       { // Since we are reloading courses, this subgroup is (probably) already
        // part of this group, so do not re-create it, just find it
        // and reload it's missing courses.
        $temp_g = new Group();
        $temp_g->school_id = $this->school_id;
        $temp_g->bool_use_draft = $this->bool_use_draft;
        $temp_g->group_id = $cur ["child_group_id"] . '_' . $this->req_by_degree_id;
        $temp_g->requirement_type = $this->requirement_type;
        if ($group_g = $this->list_groups->find_match($temp_g)) {
          $group_g->reload_missing_courses();
        }
        else {
          // We didn't find the child group, possibly because this is the first time we are loading it.  If that is
          // the case, then we should just add it fresh.   
          $temp_add_as_new_group = TRUE;
        }
      }
      else {
        $temp_add_as_new_group = TRUE;
      }


      if ($temp_add_as_new_group) {
        // Add this as a brand-new sub group, so create it
        // and add it to this group.
        $group_g = new Group($cur ["child_group_id"] . "_" . $this->req_by_degree_id, null, $this->assigned_to_semester_num, $array_significant_courses, $this->bool_use_draft);
        $group_g->requirement_type = $this->requirement_type;
        $this->list_groups->add($group_g);
      }


    } // if child_group_id > 0

  } // while cur = db_fetch_array(res)


  // When we load this group, let's also check for any hooks.
  // Since this class might be used outside of FP, only do this if we know
  // that the bootstrap.inc file has been executed.
  if ($GLOBALS ["fp_bootstrap_loaded"] == TRUE) {
    invoke_hook("group_load", array(&$this));
  }




}