Add better support for stories

This commit is contained in:
Romain Neutron
2012-12-19 19:58:07 +01:00
parent 664fb2d8cf
commit 52a7f58a31
5 changed files with 45 additions and 7 deletions

View File

@@ -596,7 +596,7 @@ return call_user_func(function() {
$route = '/stories/{databox_id}/{story_id}/embed/';
$app->get(
$route, function($databox_id, $story_id) use ($app) {
$result = $app['api']->get_record_embed($app['request'], $databox_id, $story_id);
$result = $app['api']->get_story_embed($app['request'], $databox_id, $story_id);
return $result->get_response();
}

View File

@@ -117,8 +117,11 @@ class Tooltip implements ControllerProviderInterface
$controllers->post('/tc_datas/{sbas_id}/{record_id}/'
, function(Application $app, $sbas_id, $record_id) {
$record = new \record_adapter($sbas_id, $record_id);
try {
$document = $record->get_subdef('document');
} catch(\Exception $e) {
$document = null;
}
/* @var $twig \Twig_Environment */
$twig = $app['Core']->getTwig();

View File

@@ -1026,7 +1026,7 @@ class API_V1_adapter extends API_V1_Abstract
$stories = array_map(function ($story) use ($that) {
return $that->list_story($story);
}, $record->get_grouping_parents()->get_elements());
}, array_values($record->get_grouping_parents()->get_elements()));
$result->set_datas(array(
"baskets" => $baskets,
@@ -1120,6 +1120,36 @@ class API_V1_adapter extends API_V1_Abstract
return $result;
}
/**
* Get an API_V1_result containing the story embed files
*
* @param Request $request
* @param int $databox_id
* @param int $record_id
* @param string $response_type
* @return API_V1_result
*/
public function get_story_embed(Request $request, $databox_id, $record_id)
{
$result = new API_V1_result($request, $this);
$record = $this->appbox->get_databox($databox_id)->get_record($record_id);
$ret = array();
$devices = $request->get('devices', array());
$mimes = $request->get('mimes', array());
foreach ($record->get_embedable_medias($devices, $mimes) as $name => $media) {
$ret[] = $this->list_embedable_media($media, $this->appbox->get_registry());
}
$result->set_datas(array("embed" => $ret));
return $result;
}
public function set_record_metadatas(Request $request, $databox_id, $record_id)
{
$result = new API_V1_result($request, $this);

View File

@@ -371,7 +371,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
*/
public function get_embedable_medias($devices = null, $mimes = null)
{
return $this->getSubdfefByDeviceAndMime($devices, $mimes);
}
@@ -707,9 +706,11 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$searchDevices = array_merge((array) $devices, (array) databox_subdef::DEVICE_ALL);
$type = $this->is_grouping() ? 'image' : $this->get_type();
foreach ($this->databox->get_subdef_structure() as $group => $databoxSubdefs) {
if ($this->get_type() != $group) {
if ($type != $group) {
continue;
}

View File

@@ -1,4 +1,8 @@
{% trans 'Record_id' %} : {{ record.get_record_id() }}<br/>
{% if record.is_grouping() %}
{% trans 'Story_id' %} : {{ record.get_record_id() }}<br/>
{% else %}
{% trans 'Record_id' %} : {{ record.get_record_id() }}<br/>
{% endif %}
{% if record.is_grouping() == false %}