function bat_api_services_units_index in Booking and Availability Management API 7
Same name and namespace in other branches
- 7.2 bat_api.module \bat_api_services_units_index()
Retrieve a list of units.
Parameters
$unit_ids:
1 string reference to 'bat_api_services_units_index'
- bat_api_services_resources in ./
bat_api.module - Implements hook_services_resources().
File
- ./
bat_api.module, line 369
Code
function bat_api_services_units_index($unit_ids, $offset, $limit) {
$return = new stdClass();
$return->sessid = session_id();
ctools_include('plugins');
$field_handlers = ctools_get_plugins('bat_api', 'rooms_unit_field_handler');
$ids = array_filter(explode(',', $unit_ids));
$query = db_select('rooms_units', 'n')
->fields('n', array(
'unit_id',
'type',
'name',
'default_state',
'bookable',
'status',
));
if (!empty($ids)) {
$query
->condition('unit_id', $ids, 'IN');
}
$query
->orderBy('unit_id');
$query
->range($offset, $limit);
$rooms_units = $query
->execute()
->fetchAll();
$units = array();
foreach ($rooms_units as $unit) {
$units[$unit->unit_id] = array(
'properties' => array(
'type' => $unit->type,
'name' => $unit->name,
'default_state' => $unit->default_state,
'bookable' => $unit->bookable,
'status' => $unit->status,
),
'fields' => array(),
);
foreach ($field_handlers as $handler) {
$class = ctools_plugin_get_class($handler, 'handler');
$object_handler = new $class(rooms_unit_load($unit->unit_id));
$field_type = $object_handler
->getFieldType();
$field_info = $object_handler
->getFieldInfo();
if (!empty($field_info)) {
$units[$unit->unit_id]['fields'][$field_type] = $field_info;
}
}
}
$return->units = $units;
return $return;
}