Skip to content

Commit e432f3c

Browse files
author
alvinz97
committed
Minor issues update
1 parent aaea8e7 commit e432f3c

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
@@ -154,4 +154,11 @@ public function getRecentUserRatings($id, $limit = 5, $approved = true, $sort =
154154
* @return mixed
155155
*/
156156
public function deleteRating($id);
157+
158+
/**
159+
*
160+
* @param $id
161+
* @return mixed
162+
*/
163+
public function getUserRatings($id, $author, $sort = 'desc');
157164
}

src/Models/Rating.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,19 @@ public function deleteRating($id)
159159
{
160160
return static::find($id)->delete();
161161
}
162+
163+
/**
164+
* @param $id
165+
*
166+
* @return mixed
167+
*/
168+
public function getUserRatings($id, $author, $sort = 'desc')
169+
{
170+
$rating = $this->where('reviewrateable_id', $id)
171+
->where('author_id', $author)
172+
->orderBy('id', $sort)
173+
->firstOrFail();
174+
175+
return $rating;
176+
}
162177
}

src/Traits/ReviewRateable.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function ratingPercent($max = 5)
210210
{
211211
$ratings = $this->ratings();
212212
$quantity = $ratings->count();
213-
$total = $ratings->selectRaw('SUM(rating) as total')->pluck('total');
213+
$total = $ratings->selectRaw('SUM(rating) as total')->get()->first()->total;
214214
return ($quantity * $max) > 0 ? $total / (($quantity * $max) / 100) : 0;
215215
}
216216

@@ -303,4 +303,14 @@ public function deleteRating($id)
303303
{
304304
return (new Rating())->deleteRating($id);
305305
}
306+
307+
/**
308+
* @param $id
309+
*
310+
* @return mixed
311+
*/
312+
public function getUserRatings($id, $author, $sort = 'desc')
313+
{
314+
return (new Rating())->getUserRatings($id, $author, $sort = 'desc');
315+
}
306316
}

0 commit comments

Comments
 (0)