コード例 #1
0
ファイル: jteam.class.php プロジェクト: joomux/jTips
 /**
  * Updates the team points based on the round passed in
  */
 static function updateLadder($jRound, $jSeason)
 {
     jTipsLogger::_log('updating team ladder for round ' . $jRound->id);
     global $database;
     $params = array('round_id' => $jRound->id);
     $jGame = new jGame($database);
     $jGames = forceArray($jGame->loadByParams($params));
     $byeTeams = array();
     foreach ($jGames as $jGame) {
         $home = new jTeam($database);
         $away = new jTeam($database);
         $homeLoaded = $awayLoaded = false;
         if ($jGame->home_id) {
             $home->load($jGame->home_id);
             $homeLoaded = true;
         }
         if ($jGame->away_id) {
             $away->load($jGame->away_id);
             $awayLoaded = true;
         }
         if (!$homeLoaded and $awayLoaded) {
             $byeTeams[] = $away;
         }
         if ($homeLoaded and !$awayLoaded) {
             $byeTeams[] = $home;
         }
         if (!$homeLoaded or !$awayLoaded) {
             continue;
         }
         // nothing to process here
         $home->wins = $home->_getNumberOfWins();
         $home->losses = $home->_getNumberOfLosses();
         $home->draws = $home->_getNumberOfDraws();
         $home->points_for = $home->_getPointsFor();
         $home->points_against = $home->_getPointsAgainst();
         $home->points = $home->_getTotalPoints();
         $away->wins = $away->_getNumberOfWins();
         $away->losses = $away->_getNumberOfLosses();
         $away->draws = $away->_getNumberOfDraws();
         $away->points_for = $away->_getPointsFor();
         $away->points_against = $away->_getPointsAgainst();
         $away->points = $away->_getTotalPoints();
         $home->save();
         $away->save();
     }
     if (!empty($byeTeams)) {
         foreach ($byeTeams as $team) {
             $team->wins = $team->_getNumberOfWins();
             $team->losses = $team->_getNumberOfLosses();
             $team->draws = $team->_getNumberOfDraws();
             $team->points_for = $team->_getPointsFor();
             $team->points_against = $team->_getPointsAgainst();
             $team->points = $team->_getTotalPoints();
             $team->points += $jSeason->team_bye;
             $team->save();
         }
     }
 }