You are here

function bat_api_services_types_index in Booking and Availability Management API 7.2

Retrieve a list of types.

Parameters

string $type_ids:

string $offset:

string $limit:

1 string reference to 'bat_api_services_types_index'
bat_api_services_resources in ./bat_api.module
Implements hook_services_resources().

File

./bat_api.module, line 1309
API access to booking data for BAT.

Code

function bat_api_services_types_index($type_ids, $offset, $limit) {
  $return = new stdClass();
  $return->sessid = session_id();
  ctools_include('plugins');
  $field_handlers = ctools_get_plugins('bat_api', 'bat_type_field_handler');
  $ids = array_filter(explode(',', $type_ids));
  $query = db_select('bat_types', 'n')
    ->fields('n', array(
    'type_id',
    'type',
    'name',
    'language',
    'status',
    'uid',
  ));
  if (!empty($ids)) {
    $query
      ->condition('type_id', $ids, 'IN');
  }
  $query
    ->orderBy('type_id');
  $query
    ->range($offset, $limit);
  $bat_types = $query
    ->execute()
    ->fetchAll();
  $types = array();
  foreach ($bat_types as $type) {
    $types[$type->type_id] = array(
      'properties' => array(
        'name' => $type->name,
        'type' => $type->type,
        'language' => $type->language,
        'status' => $type->status,
        'uid' => $type->uid,
      ),
      'fields' => array(),
    );
    foreach ($field_handlers as $handler) {
      $class = ctools_plugin_get_class($handler, 'handler');
      $object_handler = new $class(bat_type_load($type->type_id));
      $field_type = $object_handler
        ->getFieldType();
      $field_info = $object_handler
        ->getFieldInfo();
      if (!empty($field_info)) {
        $types[$type->type_id]['fields'][$field_type] = $field_info;
      }
    }
  }
  $return->types = $types;
  return $return;
}