add /records/caption/ route to API

This commit is contained in:
Nicolas Le Goff
2012-03-08 12:17:03 +01:00
parent d18489c30e
commit fe01a6574f
2 changed files with 32 additions and 0 deletions

View File

@@ -315,6 +315,19 @@ return call_user_func(function()
return $app['response']($result); return $app['response']($result);
} }
); );
$route = '/records/{databox_id}/{record_id}/caption/';
$app->get(
$route, function($databox_id, $record_id) use ($app)
{
$result = $app['api']->caption_records($app['request'], $databox_id, $record_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
$app->get('/records/{any_id}/{anyother_id}/caption/', $bad_request_exception);
/** /**

View File

@@ -204,6 +204,25 @@ class API_V1_adapter extends API_V1_Abstract
return $result; return $result;
} }
public function caption_records(Request $request, $databox_id, $record_id)
{
$result = new API_V1_result($request, $this);
$record = $this->appbox->get_databox($databox_id)->get_record($record_id);
$fields = $record->get_caption()->get_fields();
$ret = array();
foreach ($fields as $field)
{
$ret[$field->get_meta_struct_id()] = array(
'meta_structure_id' => $field->get_meta_struct_id()
, 'name' => $field->get_name()
, 'value' => $field->get_serialized_values(";")
);
}
$result->set_datas($ret);
return $result;
}
/** /**
* Get an API_V1_result containing the results of a records search * Get an API_V1_result containing the results of a records search
* *