| Conditions | 6 |
| Paths | 16 |
| Total Lines | 32 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function scopeListFrontend($query, array $options = []) |
||
| 22 | { |
||
| 23 | if (in_array($options['sort'], array_keys(self::$sortingOptions))) { |
||
| 24 | if ($options['sort'] == 'random') { |
||
| 25 | $query->inRandomOrder(); |
||
| 26 | } else { |
||
| 27 | list($sortField, $sortDirection) = explode(' ', $options['sort']); |
||
| 28 | |||
| 29 | if ($sortField == 'posts_count') { |
||
| 30 | $query->withCount('posts'); |
||
| 31 | } |
||
| 32 | |||
| 33 | $query->orderBy($sortField, $sortDirection); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | if (empty($options['displayEmpty'])) { |
||
| 38 | $query->has('posts'); |
||
| 39 | } |
||
| 40 | |||
| 41 | // Limit the number of results |
||
| 42 | if (!empty($options['limit'])) { |
||
| 43 | $query->take($options['limit']); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $query->with([ |
||
| 47 | 'posts' => function($query){ |
||
| 48 | $query->isPublished(); |
||
| 49 | } |
||
| 50 | ] |
||
| 51 | )->get(); |
||
| 52 | } |
||
| 53 | } |