Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions doc/API_documentation/v3/_compiled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
32 changes: 29 additions & 3 deletions doc/API_documentation/v3/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
Expand Down
29 changes: 28 additions & 1 deletion lib/Alchemy/Phrasea/Search/RecordTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class RecordTransformer extends TransformerAbstract
'metadata',
// 'metadatas',
'status',
'caption'
'caption',
'stories'
];

protected $defaultIncludes = [
Expand All @@ -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)
{
Expand Down Expand Up @@ -171,11 +176,33 @@ 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
*/
public function getResourceIdResolver(): callable
{
return $this->resourceIdResolver;
}

public function setStoryTransformer(V3StoryTransformer $storyTransformer)
{
$this->storyTransformer = $storyTransformer;
}
}
Loading