Skip to content

Commit

Permalink
add post media
Browse files Browse the repository at this point in the history
  • Loading branch information
Mh-Asmi committed Oct 29, 2024
1 parent 54d057f commit 55e99f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Ushahidi/Modules/V5/Actions/Post/HandlePostOnlyParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ 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;
});
break;
}
}
return $post;
Expand Down Expand Up @@ -113,6 +121,8 @@ public function hideUnwantedRelationships(Post $post, array $hydrates)
$post->makeHidden('valuesPostsMedia');
$post->makeHidden('valuesPostsSet');
$post->makeHidden('valuesPostTag');
$post->makeHidden('valuesPostMedia');


// hide source relationships
if (!in_array('message', $hydrates)) {
Expand Down
8 changes: 7 additions & 1 deletion src/Ushahidi/Modules/V5/Models/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Post extends BaseModel
];

public const ALLOWED_RELATIONSHIPS = [
'post_media' => ['fields' => [], 'relationships' => ["valuesPostMedia"]],
'locks' => ['fields' => [], 'relationships' => ["locks"]],
'categories' => ['fields' => [], 'relationships' => ["categories"]],
'color' => ['fields' => [], 'relationships' => ["survey"]],
Expand Down Expand Up @@ -754,9 +755,14 @@ public function valuesRelation()
public function valuesPostsMedia()
{
return $this->hasMany('Ushahidi\Modules\V5\Models\PostValues\PostsMedia', 'post_id', 'id')
->select('posts_media.*');
->selectRaw('posts_media.*');
}

public function valuesPostMedia()
{
return $this->hasMany('Ushahidi\Modules\V5\Models\PostValues\PostMedia', 'post_id', 'id')
->select('post_media.*');
}
public function valuesPostsSet()
{
return $this->hasMany('Ushahidi\Modules\V5\Models\PostValues\PostsSet', 'post_id', 'id')
Expand Down

0 comments on commit 55e99f1

Please sign in to comment.