function admin_get_group_courses

6.x admin.groups.inc admin_get_group_courses(Group $group)
4.x admin.groups.inc admin_get_group_courses(Group $group)
5.x admin.groups.inc admin_get_group_courses(Group $group)

Return back the courses in a group, suitable for the edit-group form.

2 calls to admin_get_group_courses()
admin_edit_group_form in modules/admin/admin.groups.inc
This function lets the user edit a group.
admin_process_all_definitions_perform_batch_operation in modules/admin/admin.groups.inc
This actually is the batch operation for processing all of our group definitions.

File

modules/admin/admin.groups.inc, line 1204

Code

function admin_get_group_courses(Group $group) {


  // Returns a plain text list of the courses in a group's requirements
  // for use in the edit_group_form.
  $rtn = "";

  $group_sort_policy = variable_get_for_school("group_requirement_sort_policy", "alpha", $group->school_id);

  // courses not in branches...
  $courses = array();
  $c_count = 0;
  $group->list_courses->load_course_descriptive_data();

  if ($group_sort_policy == 'database') {
    $group->list_courses->sort_group_requirement_id();
  }
  else {
    // By default, sort alphabetical      
    $group->list_courses->sort_alphabetical_order();
  }

  $group->list_courses->reset_counter();
  while ($group->list_courses->has_more()) 
   {
    $course_line = "";
    $attributes = "";
    $c = $group->list_courses->get_next();
    if (strstr($c->subject_id, "&")) 
     {
      $c->subject_id = str_replace("&", "_A_", $c->subject_id);

    }

    if ($c->db_group_attributes != "") {
      $attributes = $c->db_group_attributes . " ";
    }

    $course_line .= trim("$attributes$c->subject_id $c->course_num");

    if (!$course_line) {
      // Some kind of problem, just skip this because it's blank.
      continue;
    }

    if ($c->min_grade != "" && $c->min_grade != "D") 
     {
      //$rtn .= " ($c->min_grade)";
      $course_line .= " ($c->min_grade)";
    }

    //$rtn .= "\n";
    if (!isset($courses [$course_line])) 
     {
      $courses [$course_line] = 0;
    }
    // This is to check for specified repeats.
    $courses [$course_line];

  }

  // Go through the $courses array to check for specified repeats.
  foreach (++$courses as $course => $rep_count) 
   {
    $rep_line = " [$rep_count]";
    if ($rep_count == 1) 
     {
      $rep_line = "";
    }
    $rtn .= "$course$rep_line\n";
  }



  // Now, get them branches!
  if (!$group->list_groups->is_empty) 
   {

    $group->list_groups->reset_counter();
    while ($group->list_groups->has_more()) 
     {
      $courses = array();
      $g = $group->list_groups->get_next();

      $g->list_courses->load_course_descriptive_data();
      $g->list_courses->sort_alphabetical_order();
      $g->list_courses->reset_counter();
      while ($g->list_courses->has_more()) 
       {
        $course_line = $attributes = "";
        $c = $g->list_courses->get_next();
        if (strstr($c->subject_id, "&")) 
         {
          $c->subject_id = str_replace("&", "_A_", $c->subject_id);
        }


        if ($c->db_group_attributes != "") {
          $attributes = $c->db_group_attributes . " ";
        }

        $course_line = trim("$attributes$c->subject_id $c->course_num");
        if (!$course_line) {
          // Some kind of problem, just skip this because it's blank.
          continue;
        }


        if ($c->min_grade != "" && $c->min_grade != "D") 
         {
          $course_line .= " ($c->min_grade)";
        }

        if (!isset($courses [$course_line])) 
         {
          $courses [$course_line] = 0;
        }
        // This is to check for specified repeats.
        $courses [$course_line];



      }


      // Go through the $courses array to check for specified repeats.
      foreach (++$courses as $course => $rep_count) 
       {
        $rep_line = " [$rep_count]";
        if ($rep_count == 1) 
         {
          $rep_line = "";
        }
        $rtn .= "$course$rep_line & ";
      }



      // Take off the last &.
      $rtn = trim($rtn);
      $rtn = substr($rtn, 0, -1);
      $rtn = trim($rtn);

      $rtn .= "\n";

    }
  }


  return $rtn;
}