From 0bc38c9dd2802b78c29ca87c0025f2760bc2ba1f Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Sat, 2 Jul 2016 14:35:47 +0200 Subject: [PATCH] Include caption metadatas in search type 2 --- .../Phrasea/Controller/Api/V1Controller.php | 3 +++ .../Phrasea/Search/StoryTransformer.php | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index 4514e084db..f1a74b1830 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -1420,6 +1420,9 @@ class V1Controller extends Controller 'results.stories.records.status' ]); } + else { + $includes[] = 'results.stories.caption_metadata'; + } $includes = array_merge($includes, [ 'results.records.subdefs', diff --git a/lib/Alchemy/Phrasea/Search/StoryTransformer.php b/lib/Alchemy/Phrasea/Search/StoryTransformer.php index 8f195c24a2..192d8e3687 100644 --- a/lib/Alchemy/Phrasea/Search/StoryTransformer.php +++ b/lib/Alchemy/Phrasea/Search/StoryTransformer.php @@ -18,7 +18,7 @@ class StoryTransformer extends TransformerAbstract /** * @var array */ - protected $availableIncludes = ['thumbnail', 'metadatas', 'records']; + protected $availableIncludes = ['thumbnail', 'metadatas', 'records', 'caption_metadatas']; /** * @var array @@ -77,6 +77,22 @@ class StoryTransformer extends TransformerAbstract return $this->collection($storyView->getChildren(), $this->recordTransformer); } + public function includeCaptionMetadatas(StoryView $storyView) + { + return $this->collection($storyView->getStory()->get_caption()->get_fields(), $this->getCaptionRecordTransformer()); + } + + private function getCaptionRecordTransformer() + { + return function (\caption_field $captionField) { + return [ + 'meta_structure_id' => $captionField->get_meta_struct_id(), + 'name' => $captionField->get_name(), + 'value' => $captionField->get_serialized_values(';') + ]; + }; + } + /** * @return \Closure */