Advertisement
Guest User

Untitled

a guest
Sep 7th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. $poolRanking = $this->find('all', [
  2. 'limit' => $limit,
  3. 'conditions' => [
  4. 'Pools.tournament_id =' => $tournamentId,
  5. 'Predictions.tournament_id =' => $tournamentId,
  6. ],
  7. => [
  8. [
  9. 'table' => 'pools_users',
  10. 'alias' => 'PoolsUsers',
  11. 'type' => 'LEFT',
  12. 'conditions'=> ['PoolsUsers.pool_id = Pools.id']
  13. ],
  14. [
  15. 'table' => 'users',
  16. 'alias' => 'Users',
  17. 'type' => 'LEFT',
  18. 'conditions'=> ['Users.id = PoolsUsers.user_id']
  19. ],
  20. [
  21. 'table' => 'predictions',
  22. 'alias' => 'Predictions',
  23. 'type' => 'LEFT',
  24. 'conditions'=> ['Predictions.user_id = Users.id']
  25. ],
  26. ],
  27. 'fields' => [
  28. 'Pools.tournament_id',
  29. 'Pools.name',
  30. 'Pools.slug',
  31. 'Predictions.tournament_id',
  32. 'ROUND(COALESCE((SUM(Predictions.points_score) + SUM(Predictions.points_home_goals) + SUM(Predictions.points_away_goals) + SUM(Predictions.points_toto) + SUM(Predictions.points_diff) + SUM(Predictions.points_home_team) + SUM(Predictions.points_away_team))/COUNT(DISTINCT Predictions.user_id),0),1) AS score',
  33. ],
  34. 'group' => 'Pools.name',
  35. 'order' => 'score DESC, Pools.name ASC'
  36. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement