function student_search_get_majors_for_fapi

6.x student_search.module student_search_get_majors_for_fapi()

Returns an array of majors from the database, suitable for use with our Form API.

1 call to student_search_get_majors_for_fapi()

File

modules/student_search/student_search.module, line 461

Code

function student_search_get_majors_for_fapi() {
  global $user;
  $rtn = array();

  $extra_line = "";

  // Get all the school ids this user is allowed to search.
  $school_ids = student_search_get_school_ids_user_is_allowed_to_search();
  $school_id_list = join(",", $school_ids);



  $params = array();


  // Removing "group by major_code" line, as duplicate major codes in more than one school were not showing correctly in the select list.
  $res = db_query("SELECT * FROM degrees
                   WHERE exclude = 0
                   AND school_id IN ($school_id_list)                   
                   $extra_line                   
                   ORDER BY school_id, title
                   ", $params);
  while ($cur = db_fetch_object($res)) {


    $degree_class_details = fp_get_degree_classification_details($cur->degree_class);


    // Exclude major codes if they are "degree options", meaning, the code has an
    // underscore in it.
    if (strpos($cur->major_code, "_")) {
      continue;
    }

    // If the title is risking being too long, let's truncate it
    $title = $cur->title;
    $max_chars = 50;
    if (strlen($title) > $max_chars) {
      $title = trim(substr($title, 0, $max_chars)) . "...";
    }

    $school_name = "";
    if (module_enabled("schools")) {
      $school_name = schools_get_school_name_for_id($cur->school_id);
      // Getting fancy.  We are going to have optgroup in this set of options.
      $rtn [$school_name][$cur->major_code . "~~school_" . $cur->school_id] = "$cur->major_code : $title ({$degree_class_details ["title"]})";
    }
    else {
      $rtn [$cur->major_code . "~~school_" . $cur->school_id] = "$cur->major_code : $title ({$degree_class_details ["title"]})";
    }






  }

  return $rtn;
}