diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index ff8764b0d9..00564fae53 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -29,6 +29,7 @@ use Alchemy\Phrasea\Border\Visa; use Alchemy\Phrasea\Cache\Cache; use Alchemy\Phrasea\Collection\Reference\CollectionReference; use Alchemy\Phrasea\Controller\Controller; +use Alchemy\Phrasea\ControllerProvider\Api\V1; use Alchemy\Phrasea\Core\Event\RecordEdit; use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\Version; @@ -1178,7 +1179,8 @@ class V1Controller extends Controller $searchView = $this->buildSearchView( $result, $includeResolver->resolve($fractal), - $this->resolveSubdefUrlTTL($request) + $this->resolveSubdefUrlTTL($request), + $request ); $ret = $fractal->createData(new Item($searchView, $searchTransformer))->toArray(); @@ -1233,9 +1235,10 @@ class V1Controller extends Controller * @param SearchEngineResult $result * @param string[] $includes * @param int $urlTTL + * @param Request $request * @return SearchResultView */ - private function buildSearchView(SearchEngineResult $result, array $includes, $urlTTL) + private function buildSearchView(SearchEngineResult $result, array $includes, $urlTTL, Request $request) { $references = new RecordReferenceCollection($result->getResults()); @@ -1253,6 +1256,12 @@ class V1Controller extends Controller $resultView = new SearchResultView($result); if ($stories->count() > 0) { + $storie_max_items = null; + + if($request->getAcceptableContentTypes() == V1::$extendedContentTypes['json']){ + $storie_max_items = (int)$request->get('storie_max_items')?:10; + } + $user = $this->getAuthenticatedUser(); $children = []; @@ -1261,7 +1270,7 @@ class V1Controller extends Controller $selections = $this->findDataboxById($databoxId) ->getRecordRepository() - ->findChildren($storyIds, $user); + ->findChildren($storyIds, $user,0, $storie_max_items); $children[$databoxId] = array_combine($storyIds, $selections); } @@ -1631,6 +1640,15 @@ class V1Controller extends Controller return Result::createError($request, 404, 'Story not found')->createResponse(); } + $offset = 0; + $max_items = null; + if($request->getAcceptableContentTypes() == V1::$extendedContentTypes['json']){ + $max_items = (int)$request->get('max_items')?:10; + $page = (int)$request->get('page')?:1; + + $offset = $max_items * ($page - 1); + } + $caption = $story->get_caption(); $format = function (\caption_record $caption, $dcField) { @@ -1672,7 +1690,7 @@ class V1Controller extends Controller 'dc:title' => $format($caption, \databox_Field_DCESAbstract::Title), 'dc:type' => $format($caption, \databox_Field_DCESAbstract::Type), ], - 'records' => $this->listRecords($request, array_values($story->getChildren()->get_elements())), + 'records' => $this->listRecords($request, array_values($story->getChildren($offset, $max_items)->get_elements())), ]; } diff --git a/lib/Alchemy/Phrasea/Databox/Record/LegacyRecordRepository.php b/lib/Alchemy/Phrasea/Databox/Record/LegacyRecordRepository.php index 522d49baae..933cdbd6af 100644 --- a/lib/Alchemy/Phrasea/Databox/Record/LegacyRecordRepository.php +++ b/lib/Alchemy/Phrasea/Databox/Record/LegacyRecordRepository.php @@ -120,7 +120,7 @@ class LegacyRecordRepository implements RecordRepository return $this->mapRecordsFromResultSet($result); } - public function findChildren(array $storyIds, $user = null) + public function findChildren(array $storyIds, $user = null, $offset = 0, $max_items = null) { if (!$storyIds) { return []; @@ -147,6 +147,12 @@ class LegacyRecordRepository implements RecordRepository $this->addUserFilter($builder, $user); } + if($max_items){ + $builder->addOrderBy('s.ord', 'ASC') + ->setFirstResult($offset) + ->setMaxResults($max_items); + } + $data = $connection->fetchAll($builder->getSQL(), $builder->getParameters(), $builder->getParameterTypes()); $records = $this->mapRecordsFromResultSet($data); diff --git a/lib/Alchemy/Phrasea/Databox/Record/RecordRepository.php b/lib/Alchemy/Phrasea/Databox/Record/RecordRepository.php index 0da49bb00f..fb91e05f1f 100644 --- a/lib/Alchemy/Phrasea/Databox/Record/RecordRepository.php +++ b/lib/Alchemy/Phrasea/Databox/Record/RecordRepository.php @@ -43,9 +43,11 @@ interface RecordRepository * * @param int[] $storyIds * @param null|int|User $user + * @param int $offset + * @param null|int $max_items * @return \set_selection[] */ - public function findChildren(array $storyIds, $user = null); + public function findChildren(array $storyIds, $user = null, $offset = 0, $max_items = null); /** diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index b647927717..33a9c7989e 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -1677,17 +1677,20 @@ class record_adapter implements RecordInterface, cache_cacheableInterface } /** + * @param int $offset + * @param null|int $max_items + * * @return set_selection|record_adapter[] * @throws Exception * @throws \Doctrine\DBAL\DBALException */ - public function getChildren() + public function getChildren($offset = 0, $max_items = null) { if (!$this->isStory()) { throw new Exception('This record is not a grouping'); } - $selections = $this->getDatabox()->getRecordRepository()->findChildren([$this->getRecordId()]); + $selections = $this->getDatabox()->getRecordRepository()->findChildren([$this->getRecordId()], null, $offset, $max_items); return reset($selections); }