function fp_get_max_catalog_repeats_for_course

6.x fp_get_max_catalog_repeats_for_course($subject_id, $course_num, $catalog_year, $bool_draft = TRUE, $school_id = 0)
7.x fp_get_max_catalog_repeats_for_course($subject_id, $course_num, $catalog_year, $bool_draft = TRUE, $school_id = 0)
5.x fp_get_max_catalog_repeats_for_course($subject_id, $course_num, $catalog_year, $bool_draft = TRUE)

Figure out the maximum number of times this course can be repeated for credit, based on what is stored in the course catalog.

We will do this by directly querying the database, for speed reasons.

1 call to fp_get_max_catalog_repeats_for_course()
admin_process_catalog_repeats_for_group_courses_text in modules/admin/
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.


includes/, line 86
This file contains mostly db shortcuts.


function fp_get_max_catalog_repeats_for_course($subject_id, $course_num, $catalog_year, $bool_draft = TRUE) {
  $table_name = "courses";
  if ($bool_draft) {
    $table_name = "draft_courses";

  $res = db_query("SELECT * FROM $table_name WHERE subject_id = ? AND course_num = ? AND catalog_year = ?", $subject_id, $course_num, $catalog_year);
  $cur = db_fetch_array($res);

  $min_hours = $cur ['min_hours'];
  $max_hours = $cur ['max_hours'];
  $repeat_hours = $cur ['repeat_hours'];

  if ($repeat_hours <= $min_hours) {
    // Meaning, this course cannot be repeated for anything.  So, just return 1, meaning, it can be taken only once.
    return 1;

  // Okay, so what we want to do is figure out, if this is a 3 hour course, and it can be repeated for 9 hours, that means it
  // can be taken (repeats) 3 times.

  // We will use the min_hours for this calculation.  If zero, then change it to 1.
  if ($min_hours < 1) {
    $min_hours = 1;

  // Use intval so we don't have decimals.  Whole attempts only.
  $repeats = intval($repeat_hours / $min_hours);

  return $repeats;