You are here

function units_unit_by_measure_load_multiple in Units of Measurement 7

Same name and namespace in other branches
  1. 7.2 units.module \units_unit_by_measure_load_multiple()

Load all units of the supplied measure.

Parameters

mixed $measure: Either ID of the measure, or machine-readable name of the measure or fully loaded 'units_measure' entity object

Return value

array Array of fully loaded 'units_unit' entity objects that belong to the supplied $measure

2 calls to units_unit_by_measure_load_multiple()
UnitsWebTestCase::testCrud in ./units.test
Conduct testing of CRUD operations.
units_units_measure_delete in ./units.module
Implements hook_ENTITY_TYPE_delete().

File

./units.module, line 272
Provide API for managing and converting units of measurement.

Code

function units_unit_by_measure_load_multiple($measure) {

  // Trying to load entity object of $measure, if we were not supplied with one.
  if (is_numeric($measure)) {
    $measure = units_measure_load($measure);
  }
  elseif (!is_object($measure)) {
    $measure = units_measure_machine_name_load($measure);
  }
  if (!is_object($measure)) {

    // Probably we were supplied with bad parameter $measure, because at this
    // point we are already supposed to have fully loaded 'units_measure' entity
    // object.
    return array();
  }
  $bundle = field_extract_bundle('units_unit', $measure);
  $efq = new EntityFieldQuery();
  $result = $efq
    ->entityCondition('entity_type', 'units_unit')
    ->entityCondition('bundle', $bundle)
    ->execute();
  return isset($result['units_unit']) ? units_unit_load_multiple(array_keys($result['units_unit'])) : array();
}