| @@ -165,10 +165,25 @@ | ||
| 165 | 165 | { |
| 166 | 166 | return $postId ? $query->where('post_id', (int) $postId) : $query; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | + /** | |
| 170 | + * Reviews with exactly this star rating, or any of a list of them (the | |
| 171 | + * storefront's star chips can be combined). | |
| 172 | + * | |
| 173 | + * @param \FluentCart\Framework\Database\Orm\Builder $query | |
| 174 | + * @param int|int[]|null $rating | |
| 175 | + */ | |
| 169 | 176 | public function scopeOfRating($query, $rating) |
| 170 | 177 | { |
| 178 | + if (is_array($rating)) { | |
| 179 | + $ratings = array_values(array_filter(array_map('intval', array_slice($rating, 0, 5)), function ($value) { | |
| 180 | + return $value >= 1 && $value <= 5; | |
| 181 | + })); | |
| 182 | + | |
| 183 | + return $ratings ? $query->whereIn('rating', $ratings) : $query; | |
| 184 | + } | |
| 185 | + | |
| 171 | 186 | if (!$rating || !is_numeric($rating)) { |
| 172 | 187 | return $query; |
| 173 | 188 | } |
| 174 | 189 | return $query->where('rating', (int) $rating); |