Skip to content

Commit

Permalink
Merge branch 'develop' into USH-867
Browse files Browse the repository at this point in the history
  • Loading branch information
Mh-Asmi authored Nov 6, 2024
2 parents 5a83780 + b83cb07 commit 6d5c63c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/Ushahidi/Modules/V5/Actions/Post/HandlePostOnlyParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,17 @@ public function addHydrateRelationships(Post $post, array $hydrates)
$relations['enabled_languages'] = true;
break;
case 'post_media':
$post->post_media = $post->valuesPostMedia;
$post->post_media = $post->post_media->map(function ($media) {
$media = $media->toArray();
unset($media['post']); // Remove the 'post' property
return $media;
});
$post->post_media = $post->valuesPostMedia->first();
if ($post->post_media) {
$media = $post->post_media->toArray();
unset($media['post']);
// convert it to field structure
$media_field = $media['attribute'];
unset($media['attribute']);
unset($media['translations']);
$media_field['value'] = $media;
$post->post_media = $media_field;
}
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Ushahidi/Modules/V5/Models/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,10 @@ public function valuesPostsMedia()
public function valuesPostMedia()
{
return $this->hasMany('Ushahidi\Modules\V5\Models\PostValues\PostMedia', 'post_id', 'id')
->select('post_media.*');
->select('post_media.*')->with('attribute')->whereHas('attribute', function ($query) {
$query->where('input', 'image')
->orWhere('input', 'upload'); // for old uploaded images
});
}
public function valuesPostsSet()
{
Expand Down

0 comments on commit 6d5c63c

Please sign in to comment.