mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 21:13:26 +00:00
max_items depends on header application/vnd.phraseanet.story-paginate
This commit is contained in:
@@ -51,7 +51,8 @@ class ApiApplicationLoader extends BaseApplicationLoader
|
|||||||
['application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript'],
|
['application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript'],
|
||||||
V1::$extendedContentTypes['json'],
|
V1::$extendedContentTypes['json'],
|
||||||
V1::$extendedContentTypes['jsonp'],
|
V1::$extendedContentTypes['jsonp'],
|
||||||
V1::$extendedContentTypes['yaml']
|
V1::$extendedContentTypes['yaml'],
|
||||||
|
[V1::HEADER_ACCEPT_STORY_PAGINATE]
|
||||||
);
|
);
|
||||||
|
|
||||||
$app['phraseanet.content-negotiation.custom_formats'] = [
|
$app['phraseanet.content-negotiation.custom_formats'] = [
|
||||||
|
@@ -1217,12 +1217,18 @@ class V1Controller extends Controller
|
|||||||
$fractal->setSerializer(new TraceableArraySerializer($this->app['dispatcher']));
|
$fractal->setSerializer(new TraceableArraySerializer($this->app['dispatcher']));
|
||||||
$fractal->parseIncludes($this->resolveSearchIncludes($request));
|
$fractal->parseIncludes($this->resolveSearchIncludes($request));
|
||||||
|
|
||||||
|
$story_max_items = null;
|
||||||
|
// if the header accept story paginate, take account story_max_items parameter
|
||||||
|
if (in_array(V1::HEADER_ACCEPT_STORY_PAGINATE, $request->getAcceptableContentTypes())) {
|
||||||
|
$story_max_items = (int)$request->get('story_max_items') ?: 10;
|
||||||
|
}
|
||||||
|
|
||||||
$result = $this->doSearch($request);
|
$result = $this->doSearch($request);
|
||||||
$searchView = $this->buildSearchView(
|
$searchView = $this->buildSearchView(
|
||||||
$result,
|
$result,
|
||||||
$includeResolver->resolve($fractal),
|
$includeResolver->resolve($fractal),
|
||||||
$this->resolveSubdefUrlTTL($request),
|
$this->resolveSubdefUrlTTL($request),
|
||||||
(int)$request->get('story_max_items')?:10
|
$story_max_items
|
||||||
);
|
);
|
||||||
|
|
||||||
$ret = $fractal->createData(new Item($searchView, $searchTransformer))->toArray();
|
$ret = $fractal->createData(new Item($searchView, $searchTransformer))->toArray();
|
||||||
@@ -1676,10 +1682,13 @@ class V1Controller extends Controller
|
|||||||
return Result::createError($request, 404, 'Story not found')->createResponse();
|
return Result::createError($request, 404, 'Story not found')->createResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
$max_items = (int)$request->get('max_items')?:10;
|
$offset = 1;
|
||||||
$page = (int)$request->get('page')?:1;
|
$max_items = null;
|
||||||
|
if (in_array(V1::HEADER_ACCEPT_STORY_PAGINATE, $request->getAcceptableContentTypes())) {
|
||||||
$offset = $max_items * ($page - 1) + 1;
|
$max_items = (int)$request->get('max_items')?:10;
|
||||||
|
$page = (int)$request->get('page')?:1;
|
||||||
|
$offset = ($max_items * ($page - 1)) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
$caption = $story->get_caption();
|
$caption = $story->get_caption();
|
||||||
|
|
||||||
|
@@ -25,6 +25,8 @@ class V1 extends Api implements ControllerProviderInterface, ServiceProviderInte
|
|||||||
{
|
{
|
||||||
const VERSION = '2.0.0';
|
const VERSION = '2.0.0';
|
||||||
|
|
||||||
|
const HEADER_ACCEPT_STORY_PAGINATE = 'application/vnd.phraseanet.story-paginate';
|
||||||
|
|
||||||
public static $extendedContentTypes = [
|
public static $extendedContentTypes = [
|
||||||
'json' => ['application/vnd.phraseanet.record-extended+json'],
|
'json' => ['application/vnd.phraseanet.record-extended+json'],
|
||||||
'yaml' => ['application/vnd.phraseanet.record-extended+yaml'],
|
'yaml' => ['application/vnd.phraseanet.record-extended+yaml'],
|
||||||
|
@@ -47,7 +47,7 @@ interface RecordRepository
|
|||||||
* @param null|int $max_items
|
* @param null|int $max_items
|
||||||
* @return \set_selection[]
|
* @return \set_selection[]
|
||||||
*/
|
*/
|
||||||
public function findChildren(array $storyIds, $user = null, $offset = 0, $max_items = null);
|
public function findChildren(array $storyIds, $user = null, $offset = 1, $max_items = null);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user