function tripal_core_chado_ws_api_expand_object

2.x tripal_core.ws_hal.inc tripal_core_chado_ws_api_expand_object($var, $query)

Parameters

unknown $object:

unknown $query:

1 call to tripal_core_chado_ws_api_expand_object()

File

tripal_core/includes/tripal_core.ws_hal.inc, line 183

Code

function tripal_core_chado_ws_api_expand_object($var, $query) {

  $page_limit = 25;
  $pager_id = 0;
  $options = array(
    'return_array' => 1,
    'pager' => array(
      'limit' => $page_limit,
      'element' => $pager_id
    ),
  );

  // If the user has requested to expand any fields then do that
  if (array_key_exists('table', $query)) {
    $expand_tables = explode(',', $query['table']);
    foreach ($expand_tables as $table) {
      // Does the table exist?
      if (!chado_table_exists($table)) {
        throw new Exception("Table, '$table', is not a valid table and thus cannot be expanded.");
      }

      // Expand the variable.
      $var = chado_expand_var($var, 'table', $table, $options);

      // if the table could not be expanded then the chado_expand_var
      // function just returns an empty record but sets the table name
      // in the object. For the JSON, we still want to create an _embedded
      // record so we have to create a stdClass object and set the
      // table name.
      if (property_exists($var, $table) and !isset($var->$table)) {
        $var->$table = new stdClass();
        $var->$table->tablename = $table;
      }
    }
  }
  if (array_key_exists('field', $query)) {
    $expand_fields = explode(',', $query['field']);
    foreach ($expand_fields as $field) {
      // TODO: check to make sure the field exists
      $var = chado_expand_var($var, 'field', $field);
    }
  }
  if (array_key_exists('fkey', $query)) {
    $expand_fkeys = explode(',', $query['fkey']);
    foreach ($expand_fkeys as $fkey) {
      // TODO: check to make sure the fkey exists
      $var = chado_expand_var($var, 'foreign_key', $fkey);
    }
  }

  return $var;
}