Skip to content

Commit 135a0b7

Browse files
author
LDFOUR\luisd
committed
WN-174,
I updated the stages structure in the response.
1 parent 72bb353 commit 135a0b7

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

app/Classes/Transformers/WhatNowEntityTransformer.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class WhatNowEntityTransformer extends TransformerAbstract
2727
* @param WhatNowTranslationRepositoryInterface $repo
2828
* @param array $configuration
2929
*/
30+
3031
function __construct(WhatNowTranslationRepositoryInterface $repo, $configuration = [])
3132
{
3233
if(isset($configuration['unpublished']) && is_bool($configuration['unpublished'])) {
@@ -60,7 +61,7 @@ public function transform(WhatNowEntity $model)
6061
'url' => $model->organisation->attribution_url,
6162
'imageUrl' => $model->organisation->attribution_file_name ? $model->organisation->getAttributionImageUrl() : null,
6263
'translations' => null
63-
]
64+
],
6465
];
6566

6667
if ($model->organisation->details->count()) {
@@ -78,9 +79,9 @@ public function transform(WhatNowEntity $model)
7879
}
7980

8081
if ($this->unpublished) {
81-
$translations = $this->wnTransRepo->getLatestTranslations($model->id);
82+
$translations = $this->wnTransRepo->getLatestTranslations($model->id) ?? [];
8283
} else {
83-
$translations = $this->wnTransRepo->getLatestPublishedTranslations($model->id);
84+
$translations = $this->wnTransRepo->getLatestPublishedTranslations($model->id) ?? [];
8485
}
8586

8687
$defaultStages = [];
@@ -89,14 +90,28 @@ public function transform(WhatNowEntity $model)
8990
}
9091

9192
if ($translations) {
92-
93+
$response['translations'] = [];
9394
/** @var WhatNowEntityTranslation $trans */
9495
foreach ($translations as $trans) {
9596

9697
$stages = $defaultStages;
9798
if($trans->stages){
9899
foreach ($trans->stages as $stage) {
99-
$stages[$stage->stage] = json_decode($stage['content']);
100+
$stage->load('keyMessages');
101+
$keyMessages = $stage->keyMessages;
102+
103+
foreach ($keyMessages as $keyMessage) {
104+
$keyMessage->load('supportingMessages');
105+
}
106+
107+
$stages[$stage->stage] = $keyMessages->map(function($keyMessage) {
108+
return [
109+
'title' => $keyMessage->title,
110+
'content' => $keyMessage->supportingMessages->map(function($supportingMessage) {
111+
return $supportingMessage->content;
112+
})->toArray()
113+
];
114+
})->toArray();
100115
}
101116
}
102117

0 commit comments

Comments
 (0)