mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-07 01:54:27 +00:00
PHRAS-4151_stories-reference-in-api (#4602)
* add `include[]=results.records.stories` to searchV3 api * cleanup * cleanup * doc
This commit is contained in:
@@ -403,7 +403,33 @@ paths:
|
||||
|
||||
_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.
|
||||
|
@@ -446,7 +446,33 @@ paths:
|
||||
|
||||
_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.
|
||||
|
@@ -69,6 +69,7 @@ class V3SearchController extends Controller
|
||||
$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 @@ class V3SearchController extends Controller
|
||||
'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,
|
||||
|
@@ -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 @@ class RecordTransformer extends TransformerAbstract
|
||||
});
|
||||
}
|
||||
|
||||
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 @@ class RecordTransformer extends TransformerAbstract
|
||||
{
|
||||
return $this->resourceIdResolver;
|
||||
}
|
||||
|
||||
public function setStoryTransformer(V3StoryTransformer $storyTransformer)
|
||||
{
|
||||
$this->storyTransformer = $storyTransformer;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user