Esempio n. 1
0
File: Cron.php Progetto: vincium/lot
 private function rankingTour()
 {
     // tour ranking
     if (count($this->tourPlayerIds) > 0) {
         \Own\Bus\TournamentPlayer\Data::updatePlayerPoints($this->tourPlayerIds, $this->app->site()->getCreatedDate());
         $options = [];
         $options['clearSelect'] = true;
         $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'tour_ranking', 'tour_point', 'tour_diff', 'race_ranking', 'race_point', 'race_diff']);
         $options['where'][] = 'player.active = 1';
         $players = \Own\Bus\Player\Data::loadAll($options);
         $count = count($players);
         usort($players, function ($p1, $p2) {
             return $p1->getTourPoint() < $p2->getTourPoint();
         });
         for ($i = 0; $i < $count; $i++) {
             $players[$i]->setTourDiff($players[$i]->getTourDiff() + $players[$i]->getTourRanking() - ($i + 1));
             $players[$i]->setTourRanking($i + 1);
         }
         usort($players, function ($p1, $p2) {
             return $p1->getRacePoint() < $p2->getRacePoint();
         });
         for ($i = 0; $i < $count; $i++) {
             $players[$i]->setRaceDiff($players[$i]->getRaceDiff() + $players[$i]->getRaceRanking() - ($i + 1));
             $players[$i]->setRaceRanking($i + 1);
         }
         foreach ($players as $player) {
             $player->save();
         }
         $this->log('ranking (tour & race): ' . $count);
     }
 }