Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $allStars = User::find()->select('id')->where(['star' => true])->orderBy('id');
- $allNonStars = User::find()->select('id')->where(['star' => false])->orderBy('id');
- $stars = $allStars->limit($limit /2)->offset($offset /2)->count();
- $nonStars = $allNonStars->limit($limit /2)->offset($offset /2)->count();
- if ($stars < $limit/2) {
- if ($stars === 0) {
- $nonStars = $allNonStars->limit($limit - $stars)->offset($offset - $allStars->count())->all();
- } else {
- $nonStars = $allNonStars->limit($limit - $stars)->offset($offset /2)->all();
- }
- }
- if ($nonStars < $limit/2) {
- if ($nonStars === 0) {
- $stars = $allNonStars->limit($limit - $nonStars)->offset($offset - $allNonStars->count())->all();
- } else {
- $stars = $allStars->limit($limit - $nonStars)->offset($offset/2)->all();
- }
- }
- $count = $allStars->count() + $allNonStars->count();
- $result = [
- 'stars' => $stars,
- 'nonStars' => $nonStars,
- 'count' => $count
- ];
- return $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement