function student_search_ajax_autocomplete_student

6.x student_search.module student_search_ajax_autocomplete_student($output_format = "default")

Meant to return results of the ajax autocomplete field, for selecting a student by name or cwid. Code inspiration from: https://www.drupal.org/node/854216

Output format can be: default, cwid_pound_name default = First Last (CWID) cwid_pound_name = CWID # First Last

1 string reference to 'student_search_ajax_autocomplete_student'
student_search_menu in modules/student_search/student_search.module

File

modules/student_search/student_search.module, line 18

Code

function student_search_ajax_autocomplete_student($output_format = "default") {

  $term = $_GET ['term']; // this is what the user is starting to type.

  // actually search based on this term.  make use of the studentsearch module


  // Use the student_search module to query based on what we've typed so far. 
  $_REQUEST ["search_for"] = $term;
  $form = student_search_search_form(5); // limit to only 5 results.
  $matches = array();

  // Result will be in $form['adv_array']['value'];
  //watchdog('debug', pretty_print($form['adv_array']['value'], TRUE));
  $adv_array = $form ['adv_array']['value'];
  if (is_array($adv_array)) {
    foreach ($adv_array as $cwid => $details) {
      $line = "";
      if ($output_format == 'cwid_pound_name') {
        // Output like:  12345 # first last
        $line = "$cwid # " . $details ['first_name'] . " " . $details ['last_name'];
      }
      else {
        // default
        $line = $details ['first_name'] . " " . $details ['last_name'] . " ($cwid)";
      }


      $matches [] = $line;
    }
  }






  header('Content-Type: application/json');
  print json_encode($matches);
  die;

}