function admin_process_catalog_repeats_for_group_courses_text

7.x admin.groups.inc admin_process_catalog_repeats_for_group_courses_text($courses, $catalog_year, $school_id = 0)
6.x admin.groups.inc admin_process_catalog_repeats_for_group_courses_text($courses, $catalog_year, $school_id = 0)
5.x admin.groups.inc admin_process_catalog_repeats_for_group_courses_text($courses, $catalog_year)

This function will accept the $courses text (textarea) from a group, which spells out all of the courses, and then assign specified repeats based on what is set for that course in the course catalog.

2 calls to admin_process_catalog_repeats_for_group_courses_text()
admin_edit_group_form_submit in modules/admin/admin.groups.inc
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 482

Code

function admin_process_catalog_repeats_for_group_courses_text($courses, $catalog_year, $school_id = 0) {
  $rtn = "";

  // Okay, now we look at the actual "courses" box and assemble the group
  // in the database.
  $lines = explode("\n", $courses);
  for ($t = 0; $t < count($lines); $t++) {
    $line = trim($lines [$t]);
    if ($line == "") {
      continue;
    }
    // Get rid of extra whitespace.
    $line = str_replace("  ", " ", $line);
    $line = str_replace("  ", " ", $line);
    $line = str_replace("  ", " ", $line);

    $new_line = "";

    // Does this line contain at least one & symbol?  If it does,
    // then this is a subgroup (branch), and we need to look at all the courses
    // on that branch.
    if (strstr($line, "&")) {

      // If this branch contains an ampersand, I don't think I should attempt to process it at all.
      $new_line = $line;


    }
    else {
      // Did NOT contain an ampersand (&), so this goes in the
      // regular course requirements.
      $tokens = explode(" ", $line);
      $subject_id = @trim($tokens [0]);
      $course_num = @trim($tokens [1]);
      $min_grade = @trim($tokens [2]);
      $course_repeats = @trim($tokens [3]);

      if (strstr($min_grade, "[")) {
        // This is actually a specified repeat, not a min grade.
        $course_repeats = $min_grade;
        $min_grade = "";
      }

      $min_grade = str_replace("(", "", $min_grade);
      $min_grade = strtoupper(str_replace(")", "", $min_grade));

      $course_repeats = str_replace("[", "", $course_repeats);
      $course_repeats = str_replace("]", "", $course_repeats);
      $course_repeats--;
      if ($course_repeats < 0) {
        $course_repeats = 0;
      }

      // If the subject_id had a _A_ in it, convert this back
      // to an ampersand.
      $subject_id = str_replace("_A_", "&", $subject_id);

      // Okay, we now have a subject_id and course_number.  Let's find out how many times
      // it can be repeated for credit.
      $max_cat_repeats = fp_get_max_catalog_repeats_for_course($subject_id, $course_num, $catalog_year, TRUE, $school_id);

      // Okay, now, let's rebuild this line.        
      $subject_id = str_replace("&", "_A_", $subject_id);

      $new_line .= "$subject_id $course_num";
      // Was there a min grade?
      if ($min_grade != "") {
        $new_line .= " ($min_grade)";
      }
      // Specified repeats?
      if ($max_cat_repeats > 0) {
        $new_line .= " [$max_cat_repeats]";
      }




    } // else (does not contain &)

    // Add to our $rtn
    $rtn .= $new_line . "\n";

  } // for lines...



  return $rtn;
}