You are here

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

Returns a JSON output for autocomplete user profiles.

Parameters

string $profile_string: The customer profile seed to look for.

1 string reference to 'rooms_booking_get_client_profiles'
rooms_booking_menu in modules/rooms_booking/rooms_booking.module
Implements hook_menu().

File

modules/rooms_booking/rooms_booking.module, line 910
Manage Bookings - Bookings are tied to a customer profile and possible a Unit ID and Order ID.

Code

function rooms_booking_get_client_profiles($profile_string = '') {
  $matches = array();
  if ($profile_string) {
    if (module_exists('commerce_customer')) {
      $result = db_select('field_data_commerce_customer_address')
        ->fields('field_data_commerce_customer_address', array(
        'commerce_customer_address_name_line',
        'commerce_customer_address_thoroughfare',
        'entity_id',
      ))
        ->condition('commerce_customer_address_name_line', '%' . db_like($profile_string) . '%', 'LIKE')
        ->condition('entity_type', 'commerce_customer_profile')
        ->condition('bundle', 'billing')
        ->range(0, 10)
        ->execute();
      foreach ($result as $customer) {
        $matches[$customer->commerce_customer_address_name_line . ':' . $customer->entity_id] = check_plain($customer->commerce_customer_address_name_line) . '<br />(' . $customer->commerce_customer_address_thoroughfare . ')';
      }
    }
    else {
      $result = db_select('rooms_customers')
        ->fields('rooms_customers', array(
        'name',
        'id',
      ))
        ->condition('name', '%' . db_like($profile_string) . '%', 'LIKE')
        ->range(0, 10)
        ->execute();
      foreach ($result as $customer) {
        $matches[$customer->name . ':' . $customer->id] = check_plain($customer->name);
      }
    }
  }
  drupal_json_output($matches);
}