/**
  * Order table and return.
  *
  * @method order
  * @private
  */
 private function order()
 {
     // Set table to return data.
     foreach ($this->table as &$user) {
         $this->table[$user['user_id']]['rating'] = EloRating::userRating($user['user_id']);
         array_push($this->return_data['table'], $user);
     }
     // Order table.
     usort($this->return_data['table'], function ($a, $b) {
         // If level on points then order by wins.
         if ($a['points'] == $b['points']) {
             return $b['wins'] > $a['wins'];
         }
         // Else order by points.
         return $b['points'] > $a['points'];
     });
 }
 /**
  * Main method.
  * If the user exists, it gets tournament data.
  *
  * @method main
  * @protected
  */
 protected function main()
 {
     if ($this->getUserData()) {
         $this->return_data['rating'] = EloRating::userRating($this->data['id']);
         $this->getPlaying();
         $this->getManaging();
     }
 }
 /**
  * Method that gets the user ratings and puts them in every fixture including the expected result for player 1.
  *
  * @method attachRatings
  * @private
  */
 private function attachRatings()
 {
     foreach ($this->return_data['fixtures'] as &$fixture) {
         $fixture['player1_rating'] = EloRating::userRating($fixture['player1_id'], $this->data['tournament_id']);
         $fixture['player2_rating'] = EloRating::userRating($fixture['player2_id'], $this->data['tournament_id']);
         $fixture['expected'] = EloRating::expected($fixture['player1_rating'], $fixture['player2_rating']);
         $fixture['expected_percent'] = round($fixture['expected'] * 100);
     }
 }