Esempio n. 1
0
 /**
  * @param mixed $input
  * @param NefubObject
  */
 protected static function handleMapping($input, NefubObject $oOutput)
 {
     $oOutput->nefub_id = $input->ID;
     $oOutput->season_nefub_id = Season::getInstance()->nefub_id;
     $oOutput->field = $input->Field;
     $oOutput->team1_nefub_id = $input->Home->ID;
     $oOutput->team2_nefub_id = $input->Away->ID;
     if (count($input->{'Match Officials'})) {
     }
     $referee = $input->{'Match Officials'}[0];
     $oOutput->ref_team_nefub_id = $referee->Team->ID;
     foreach ($input->{'Match Officials'} as $referee) {
         RefereeMapper::mapRefereeFromAPI($referee, $input);
     }
     if ($input->Location) {
         $oLocation = LocationMapper::mapFromAPI($input->Location);
         $oOutput->location_nefub_id = $oLocation->nefub_id;
     }
     list($inputDay, $inputMonth, $inputYear) = explode('-', $input->Date);
     $oOutput->date = $inputYear . '-' . $inputMonth . '-' . $inputDay;
     $oOutput->time = $input->Time;
     $oOutput->finished = is_object($input->Result);
     if ($oOutput->finished) {
         $oOutput->team1_score = $input->Result->Home;
         $oOutput->team2_score = $input->Result->Away;
         $oOutput->team1_shots = $input->Shots->Home;
         $oOutput->team2_shots = $input->Shots->Away;
         // At least every goal should be an event
         if (is_array($input->Events) && count($input->Events) >= $oOutput->team1_score + $oOutput->team2_score) {
             foreach ($input->Events as $gameAction) {
                 $oGameAction = GameActionMapper::mapGameActionFromAPI($gameAction, $input);
             }
             $oOutput->actions_retrieved = true;
         }
     }
     return $oOutput;
 }
Esempio n. 2
0
 /**
  * 
  * @param stdClass $game
  * @param int $teamNefubId
  * @param Game $oGame
  * @return Game
  */
 protected function convertGame(stdClass $game)
 {
     $oGame = Game::getByNefubId($game->ID);
     if (!$oGame) {
         $oGame = new Game();
         $oGame->nefub_id = $game->ID;
         $this->addedNefubObject($oGame);
     }
     if ($oGame->actions_retrieved == 1) {
         return $oGame;
     }
     if (count($game->{'Match Officials'})) {
         $referees = $game->{'Match Officials'};
         // Backwards compatability
         if ($referees[0]->Team) {
             $oGame->ref_team_nefub_id = $referees[0]->Team->ID;
         }
         foreach ($referees as $referee) {
             $this->convertReferee($oGame, $referee);
         }
     }
     $oGame->team1_nefub_id = $game->Home->ID;
     $oGame->team2_nefub_id = $game->Away->ID;
     $oLocation = LocationMapper::mapFromAPI($game->Location);
     $oGame->location_nefub_id = $oLocation->nefub_id;
     $oGame->field = $game->Field;
     list($gameDay, $gameMonth, $gameYear) = explode('-', $game->Date);
     $oGame->date = $gameYear . '-' . $gameMonth . '-' . $gameDay;
     $oGame->time = $game->Time;
     $oGame->finished = isset($game->Result) && is_object($game->Result);
     $oCompetition = CompetitionMapper::mapFromAPI($game->Competition);
     $oGame->competition_nefub_id = $oCompetition->nefub_id;
     $oGame->season_nefub_id = $oCompetition->season_nefub_id;
     if ($oGame->finished) {
         $oGame->team1_score = $game->Result->Home;
         $oGame->team2_score = $game->Result->Away;
         $oGame->team1_shots = $game->Shots->Home;
         $oGame->team2_shots = $game->Shots->Away;
         if (!$oGame->actions_retrieved) {
             $this->convertGamePersons($game->Formation->Home, $game->Home->ID, $oGame);
             $this->convertGamePersons($game->Formation->Away, $game->Away->ID, $oGame);
             Database::delete_rows('GameAction', array('game_nefub_id' => $oGame->nefub_id));
             $this->convertGameActions($game->Events, $oGame);
             Game::updateActionsRetrieved($oGame);
         }
     }
     $oGame->save();
     $this->retrievedScheduledGameNefubIds[$oGame->nefub_id] = $oGame;
     return $oGame;
 }