Skip to content

Commit 7467a79

Browse files
authored
Merge pull request #26 from Developers-Options/master
Minor issues update
2 parents 9ada067 + e432f3c commit 7467a79

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/Contracts/ReviewRateable.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,11 @@ public function getCollectionByAverageRating($rating, $type = 'rating', $approve
173173
* @return mixed
174174
*/
175175
public function deleteRating($id);
176+
177+
/**
178+
*
179+
* @param $id
180+
* @return mixed
181+
*/
182+
public function getUserRatings($id, $author, $sort = 'desc');
176183
}

src/Models/Rating.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,19 @@ public function deleteRating($id)
198198
{
199199
return static::find($id)->delete();
200200
}
201+
202+
/**
203+
* @param $id
204+
*
205+
* @return mixed
206+
*/
207+
public function getUserRatings($id, $author, $sort = 'desc')
208+
{
209+
$rating = $this->where('reviewrateable_id', $id)
210+
->where('author_id', $author)
211+
->orderBy('id', $sort)
212+
->firstOrFail();
213+
214+
return $rating;
215+
}
201216
}

src/Traits/ReviewRateable.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function ratingPercent($max = 5)
221221
{
222222
$ratings = $this->ratings();
223223
$quantity = $ratings->count();
224-
$total = $ratings->selectRaw('SUM(rating) as total')->pluck('total');
224+
$total = $ratings->selectRaw('SUM(rating) as total')->get()->first()->total;
225225
return ($quantity * $max) > 0 ? $total / (($quantity * $max) / 100) : 0;
226226
}
227227

@@ -332,4 +332,14 @@ public function deleteRating($id)
332332
{
333333
return (new Rating())->deleteRating($id);
334334
}
335+
336+
/**
337+
* @param $id
338+
*
339+
* @return mixed
340+
*/
341+
public function getUserRatings($id, $author, $sort = 'desc')
342+
{
343+
return (new Rating())->getUserRatings($id, $author, $sort = 'desc');
344+
}
335345
}

0 commit comments

Comments
 (0)