You are here

function _userreference_potential_references in Content Construction Kit (CCK) 6.3

Same name and namespace in other branches
  1. 5 userreference.module \_userreference_potential_references()
  2. 6 modules/userreference/userreference.module \_userreference_potential_references()
  3. 6.2 modules/userreference/userreference.module \_userreference_potential_references()

Fetch an array of all candidate referenced users.

This info is used in various places (aloowed values, autocomplete results, input validation...). Some of them only need the uids, others nid + names, others yet uid + names + rendered row (for display in widgets). The array we return contains all the potentially needed information, and lets consumers use the parts they actually need.

Parameters

$field: The field description.

$string: Optional string to filter usernames on (used by autocomplete)

$match: Operator to match filtered name against, can be any of: 'contains', 'equals', 'starts_with'

$ids: Optional user ids to lookup (the $string and $match arguments will be ignored).

$limit: If non-zero, limit the size of the result set.

Return value

An array of valid users in the form: array( uid => array( 'title' => The user name, 'rendered' => The text to display in widgets (can be HTML) ), ... )

4 calls to _userreference_potential_references()
userreference_allowed_values in modules/userreference/userreference.module
Implementation of hook_allowed_values().
userreference_autocomplete in modules/userreference/userreference.module
Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users
userreference_autocomplete_validate in modules/userreference/userreference.module
Validate an autocomplete element.
userreference_field in modules/userreference/userreference.module
Implementation of hook_field().

File

modules/userreference/userreference.module, line 673
Defines a field type for referencing a user from a node.

Code

function _userreference_potential_references($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) {
  static $results = array();

  // Create unique id for static cache.
  $cid = $field['field_name'] . ':' . $match . ':' . ($string !== '' ? $string : implode('-', $ids)) . ':' . $limit;
  if (!isset($results[$cid])) {
    $references = FALSE;
    if (module_exists('views') && !empty($field['advanced_view']) && $field['advanced_view'] != '--') {
      $references = _userreference_potential_references_views($field, $string, $match, $ids, $limit);
    }

    // If the view doesn't exist, we got FALSE, and fallback to the regular 'standard mode'.
    if ($references === FALSE) {
      $references = _userreference_potential_references_standard($field, $string, $match, $ids, $limit);
    }

    // Store the results.
    $results[$cid] = !empty($references) ? $references : array();
  }
  return $results[$cid];
}