diff --git a/doc/API_documentation/v3/_compiled.yaml b/doc/API_documentation/v3/_compiled.yaml index 4836c6fa7e..a1c595ad89 100644 --- a/doc/API_documentation/v3/_compiled.yaml +++ b/doc/API_documentation/v3/_compiled.yaml @@ -400,10 +400,36 @@ paths: ### results.records.technical_informations always included - + _nb:_ since stories are not related to a document, there is no technical_informations for stories. - - ### results.records.children + + ### results.records.stories + Include a list of stories that contains the record + + stories is an array of small objects containing only the `story_id` (= `record_id`) of the story. + ``` + "response": { + "results": { + "records": [ + { + "stories": [ + { + "story_id": 100 + }, + { + "story_id": 102 + }, + ... + ], + ... + }, + ... + ] + } + } + ``` + + ### results.stories.children In story search mode, will publish a children[] array for each result. See _story_children_limit_ parameter. children is an array of records, with same structure as a result record. diff --git a/doc/API_documentation/v3/api.yaml b/doc/API_documentation/v3/api.yaml index 457c48655d..537f605b94 100644 --- a/doc/API_documentation/v3/api.yaml +++ b/doc/API_documentation/v3/api.yaml @@ -443,10 +443,36 @@ paths: ### results.records.technical_informations always included - + _nb:_ since stories are not related to a document, there is no technical_informations for stories. - - ### results.records.children + + ### results.records.stories + Include a list of stories that contains the record + + stories is an array of small objects containing only the `story_id` (= `record_id`) of the story. + ``` + "response": { + "results": { + "records": [ + { + "stories": [ + { + "story_id": 100 + }, + { + "story_id": 102 + }, + ... + ], + ... + }, + ... + ] + } + } + ``` + + ### results.stories.children In story search mode, will publish a children[] array for each result. See _story_children_limit_ parameter. children is an array of records, with same structure as a result record. diff --git a/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php b/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php index 6cfd6bd682..11914add1b 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php @@ -69,6 +69,7 @@ public function searchAction(Request $request) $technicalDataTransformer = new TechnicalDataTransformer(); $recordTransformer = new RecordTransformer($subdefTransformer, $technicalDataTransformer, $this->getResourceIdResolver()); $storyTransformer = new V3StoryTransformer($recordTransformer); + $recordTransformer->setStoryTransformer($storyTransformer); $compositeTransformer = new V3SearchCompositeResultTransformer($recordTransformer, $storyTransformer); $searchTransformer = new V3SearchResultTransformer($compositeTransformer); @@ -79,6 +80,9 @@ public function searchAction(Request $request) 'suggestions' => new CallbackTransformer(), 'results.stories' => $storyTransformer, 'results.stories.children' => $recordTransformer, + 'results.records.stories' => $storyTransformer, + 'results.records.stories.thumbnail' => $subdefTransformer, + 'results.records.stories.metadata' => new CallbackTransformer(), 'results.stories.children.thumbnail' => $subdefTransformer, 'results.stories.children.technical_informations' => $technicalDataTransformer, 'results.stories.children.subdefs' => $subdefTransformer, diff --git a/lib/Alchemy/Phrasea/Search/RecordTransformer.php b/lib/Alchemy/Phrasea/Search/RecordTransformer.php index 51fecf87de..143f90ae30 100644 --- a/lib/Alchemy/Phrasea/Search/RecordTransformer.php +++ b/lib/Alchemy/Phrasea/Search/RecordTransformer.php @@ -22,7 +22,8 @@ class RecordTransformer extends TransformerAbstract 'metadata', // 'metadatas', 'status', - 'caption' + 'caption', + 'stories' ]; protected $defaultIncludes = [ @@ -45,6 +46,10 @@ class RecordTransformer extends TransformerAbstract * @var callable */ private $resourceIdResolver; + /** + * @var V3StoryTransformer + */ + private $storyTransformer; public function __construct(SubdefTransformer $subdefTransformer, TechnicalDataTransformer $technicalDataTransformer, callable $resourceIdResolver) { @@ -171,6 +176,23 @@ public function includeCaption(RecordView $recordView) }); } + public function includeStories(RecordView $recordView) + { + $data = []; + + /** @var record_adapter $story */ + foreach($recordView->getRecord()->get_grouping_parents() as $story) { + $data[] = [ + // 'title' => $story->get_title(), + 'story_id' => $story->getRecordId(), + ]; + } + + return $this->collection($data, function (array $storyData) { + return $storyData; + }); + } + /** * @return callable */ @@ -178,4 +200,9 @@ public function getResourceIdResolver(): callable { return $this->resourceIdResolver; } + + public function setStoryTransformer(V3StoryTransformer $storyTransformer) + { + $this->storyTransformer = $storyTransformer; + } }