You are here

function user_relationship_views_ajax_autocomplete_relationships_type in User Relationships 6

Same name and namespace in other branches
  1. 7 user_relationship_views/user_relationship_views.module \user_relationship_views_ajax_autocomplete_relationships_type()

Page callback for views user relationship types autocomplete

1 string reference to 'user_relationship_views_ajax_autocomplete_relationships_type'
user_relationship_views_menu in user_relationship_views/user_relationship_views.module
Implementation of hook_menu().

File

user_relationship_views/user_relationship_views.module, line 37
User Relationships Views integration. @author Alex Karshakevich http://drupal.org/user/183217

Code

function user_relationship_views_ajax_autocomplete_relationships_type($string = '') {

  // The same implementation as in admin/views/ajax/autocomplete/user
  // The user enters a comma-separated list of tags. We only autocomplete the last tag.
  $array = drupal_explode_tags($string);

  // Fetch last tag
  $last_string = trim(array_pop($array));
  $matches = array();
  if ($last_string != '') {
    $prefix = count($array) ? implode(', ', $array) . ', ' : '';
    $result = db_query_range("SELECT rtid, name FROM {user_relationship_types} WHERE LOWER(name) LIKE LOWER('%s%%')", $last_string, 0, 10);
    while ($rtype = db_fetch_object($result)) {
      $n = $rtype->name;

      // Commas and quotes in terms are special cases, so encode 'em.
      if (strpos($rtype->name, ',') !== FALSE || strpos($rtype->name, '"') !== FALSE) {
        $n = '"' . str_replace('"', '""', $rtype->name) . '"';
      }
      $matches[$prefix . $n] = check_plain(ur_tt("user_relationships:rtid:{$rtype->rtid}:name", $rtype->name));
    }
  }
  drupal_json($matches);
}