Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. $allStars = User::find()->select('id')->where(['star' => true])->orderBy('id');
  2. $allNonStars = User::find()->select('id')->where(['star' => false])->orderBy('id');
  3.  
  4. $stars = $allStars->limit($limit /2)->offset($offset /2)->count();
  5. $nonStars = $allNonStars->limit($limit /2)->offset($offset /2)->count();
  6.  
  7. if ($stars < $limit/2) {
  8. if ($stars === 0) {
  9. $nonStars = $allNonStars->limit($limit - $stars)->offset($offset - $allStars->count())->all();
  10. } else {
  11. $nonStars = $allNonStars->limit($limit - $stars)->offset($offset /2)->all();
  12. }
  13. }
  14.  
  15. if ($nonStars < $limit/2) {
  16. if ($nonStars === 0) {
  17. $stars = $allNonStars->limit($limit - $nonStars)->offset($offset - $allNonStars->count())->all();
  18. } else {
  19. $stars = $allStars->limit($limit - $nonStars)->offset($offset/2)->all();
  20. }
  21. }
  22. $count = $allStars->count() + $allNonStars->count();
  23.  
  24. $result = [
  25. 'stars' => $stars,
  26. 'nonStars' => $nonStars,
  27. 'count' => $count
  28. ];
  29. return $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement