You are here

function bat_unit_ids in Booking and Availability Management Tools for Drupal 7

Same name and namespace in other branches
  1. 8 modules/bat_unit/bat_unit.module \bat_unit_ids()

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

File

modules/bat_unit/bat_unit.module, line 917

Code

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