You are here

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

Gets a list of Units keyed by id and name in value.

@todo - double check utility of this and perhaps use rooms_unit_load_multiple

File

modules/rooms_unit/rooms_unit.module, line 524
Manage units - Units are things that can be booked on a nightly basis (e.g. rooms - but also villas bungalows, etc).

Code

function rooms_unit_ids($bundle = '') {
  $units = array();
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'rooms_unit');
  if ($bundle != '') {
    $query
      ->entityCondition('bundle', $bundle);
  }
  $result = $query
    ->execute();
  if (count($result) > 0) {
    $entities = entity_load('rooms_unit', array_keys($result['rooms_unit']));
    foreach ($entities as $unit) {
      $wrapper = entity_metadata_wrapper('rooms_unit', $unit);
      $units[$wrapper->unit_id
        ->value()] = $wrapper->name
        ->value();
    }
  }
  return $units;
}