Esempio n. 1
0
 protected function updatePoules()
 {
     $aPoules = Poule::getAll(array(), 'competition_nefub_id', null, 'ASC', 5);
     foreach ($aPoules as $oPoule) {
         $url = NEFUB_API . '/poule.php?id=' . $oPoule->nefub_id;
         $poule = $this->getNefubContentsParsed($url, MAX_AGE_POULE_DETAILS);
         $oPouleType = NefubTypeMapper::mapTypeFromAPI($poule->Type, 'PouleType');
         $oPoule->poule_type_id = $oPouleType->getId();
         if (isset($poule->Ranking)) {
             $pouleRankings = $poule->Ranking;
             foreach ($pouleRankings as $pouleRanking) {
                 $team = $pouleRanking->Team;
                 $oPouleTeam = PouleTeam::getByNefubId($team->ID, $oPoule->nefub_id);
                 if (!$oPouleTeam) {
                     $oPouleTeam = new PouleTeam();
                     $this->retrieveTeam($team);
                     $oPouleTeam->team_nefub_id = $team->ID;
                     $oPouleTeam->poule_nefub_id = $oPoule->nefub_id;
                     self::put('Team ' . $team->Name . ' aan poule ' . $oPoule->name . ' toegevoegd');
                 } else {
                     $aPouleTeams = PouleTeam::getAll(array('poule_nefub_id' => $oPouleTeam->poule_nefub_id, 'team_nefub_id' => $oPouleTeam->team_nefub_id));
                     if (count($aPouleTeams) > 1) {
                         $amountDeleted = 0;
                         // delete dubbelen
                         foreach ($aPouleTeams as $oDeletePouleTeam) {
                             if ($oDeletePouleTeam->getId() != $oPouleTeam->getId()) {
                                 $oDeletePouleTeam->delete();
                                 $amountDeleted++;
                             }
                         }
                         self::put($amountDeleted . ' dubbele koppeling(en) tussen ' . $team->Name . ' en poule ' . $oPoule->name . ' verwijderd');
                     }
                 }
                 $oPouleTeam->ranking = $pouleRanking->Position;
                 $oPouleTeam->game_points = $pouleRanking->Points;
                 $numberOfGames = $pouleRanking->{'Number of Games'};
                 $oPouleTeam->games_won = $numberOfGames->Won;
                 $oPouleTeam->games_lost = $numberOfGames->Lost;
                 $oPouleTeam->games_tied = $numberOfGames->Draw;
                 $oPouleTeam->games_played = $numberOfGames->Played;
                 $numberOfGoals = $pouleRanking->{'Number of Goals'};
                 $oPouleTeam->score_total = $numberOfGoals->Difference;
                 $oPouleTeam->score_plus = $numberOfGoals->Scored;
                 $oPouleTeam->score_minus = $numberOfGoals->Conceded;
                 $oPouleTeam->save();
             }
         } else {
             self::put('Standen voor poule ' . $oPoule->name . ' niet gevonden');
         }
         self::put('Statistieken poule ' . $oPoule->name . ' geupdatet');
     }
 }
Esempio n. 2
0
 /**
  * 
  * @param Poul $poule
  * @param Team $oTeam
  * @return PouleTeam
  */
 private function convertPouleTeam(stdClass $poule, Team $oTeam)
 {
     $oPoule = Poule::getByNefubID($poule->ID);
     if (!$oPoule) {
         $oPoule = new Poule();
         $oPoule->nefub_id = $poule->ID;
         self::put('Fout: poule ' . $oPoule->nefub_id . ' toegevoegd:' . $oPoule->name . ' bij toevoegen van personen');
     }
     $oPoule->name = $poule->Name;
     // copy info from team
     $oPoule->competition_nefub_id = $oTeam->competition_nefub_id;
     $oPoule->season_nefub_id = Season::getInstance()->nefub_id;
     $oPoule->save();
     $oPouleTeam = PouleTeam::getByNefubID($oTeam->nefub_id, $oPoule->nefub_id);
     if (!$oPouleTeam) {
         $oPouleTeam = new PouleTeam();
         $oPouleTeam->poule_nefub_id = $oPoule->nefub_id;
         $oPouleTeam->team_nefub_id = $oTeam->nefub_id;
         $oPouleTeam->save();
         self::put('Team ' . $oTeam->name . ' aan poule ' . $oPoule->nefub_id . ' toegevoegd:' . $oPoule->name);
     }
     return $oPouleTeam;
 }