You are here

function rooms_availability_reference_potential_references in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Retrieves an array of candidate referenceable booking units.

This info is used in various places (allowed values, autocomplete results, input validation...). Some of them only need the nids, others nid + titles, others yet nid + titles + 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

array $field: The field definition.

array $options: An array of options to limit the scope of the returned list. The following key/value pairs are accepted:

  • string: string to filter unit names on (used by autocomplete).
  • match: operator to match the above string against, can be any of: 'contains', 'equals', 'starts_with'. Defaults to 'contains'.
  • ids: array of specific unit ids to lookup.
  • limit: maximum size of the the result set. Defaults to 0 (no limit).

Return value

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

2 calls to rooms_availability_reference_potential_references()
rooms_availability_reference_autocomplete in modules/rooms_availability_reference/rooms_availability_reference.module
Menu callback for the autocomplete results.
rooms_availability_reference_autocomplete_validate in modules/rooms_availability_reference/rooms_availability_reference.module
Validation callback for a node_reference autocomplete element.

File

modules/rooms_availability_reference/rooms_availability_reference.module, line 241
Defines a field type for referencing availability information

Code

function rooms_availability_reference_potential_references($field, $options = array()) {

  // Fill in default options.
  $options += array(
    'string' => '',
    'match' => 'contains',
    'ids' => array(),
    'limit' => 0,
  );
  $results =& drupal_static(__FUNCTION__, array());

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

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