Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add post media nad fis issue of order column #5007

Merged
merged 3 commits into from
Oct 29, 2024
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
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 @@ -756,9 +757,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
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,13 @@ public function paginate(
array $with = []
): LengthAwarePaginator {
$fields = $this->addPostsTableNamePrefix($fields);
// add the order field if not found
if (!in_array('posts.'.$paging->getOrderBy(), $fields)) {
$fields[] = 'posts.'.$paging->getOrderBy();
}
$query = Post::take($paging->getLimit())
//->skip($paging->getSkip())
->orderBy($paging->getOrderBy(), $paging->getOrder());
->orderBy('posts.'.$paging->getOrderBy(), $paging->getOrder());

$query = $this->setSearchCondition($search_fields, $query);
$query = $this->setGuestConditions($query);
Expand Down
Loading