/** * * @param stdClass $input * @param stdClass $parentInput * @param GameAction $oGameAction * @return GameAction */ public static function mapGameActionFromAPI($input, $parentInput, GameAction $oOutput = null) { $oGameActionType = NefubTypeMapper::mapTypeFromAPI($input->Type, 'GameActionType'); $time = date('H:i:s', '00:' . strtotime($input->Time)); if (!$oOutput) { $where = array('game_nefub_id' => $parentInput->ID, 'team_nefub_id' => $input->Team->ID, 'game_action_type_id' => $oGameActionType->getId(), 'period' => $input->Period, 'time' => $time); $oOutput = GameAction::getSingle($where); if (!$oOutput) { $oOutput = new GameAction(); } } // Mapping $oOutput->time = $time; $oOutput->period = $input->Period; $oOutput->game_nefub_id = $parentInput->ID; $oOutput->team_nefub_id = $input->Team->ID; $oOutput->game_action_type_id = $oGameActionType->getId(); $oOutput->code = $input->Code; $oOutput->description = $input->Description; if ($input->Person) { $oOutput->person_nefub_id = $input->Person->ID; } if ($input->Assist) { $oOutput->assist_person_nefub_id = $input->Assist->ID; } $oOutput->save(); self::log('GameAction toegevoegd aan Game ' . $oOutput->game_nefub_id); return $oOutput; }
/** * * @param stdClass $gameAction * @param Team $oTeam * @param Game $oGame */ private function convertGameAction(stdClass $gameAction, Game $oGame, $team1_score, $team2_score) { $oGameAction = new GameAction(); $oGameAction->period = $gameAction->Period; $oGameAction->time = '00:' . str_pad(str_replace('.', ':', $gameAction->Time), 5, '0', STR_PAD_LEFT); $oGameAction->game_nefub_id = $oGame->nefub_id; $oGameAction->team_nefub_id = $gameAction->Team->ID; $oGameAction->person_nefub_id = $gameAction->Person->ID; if ($gameAction->Assist) { $oGameAction->assist_person_nefub_id = $gameAction->Assist->ID; } // add new unkown type $oType = GameActionType::getByNefubName($gameAction->Type); if (!$oType) { self::put('Wedstrijdactietype ' . $gameAction->Type . ' toegevoegd'); $oType = new GameActionType(); $oType->name = $gameAction->Type; $oType->nefub_name = $gameAction->Type; $oType->use = true; $oType->save(); $this->addedNefubObject($oType); } $oGameAction->game_action_type_id = $oType->getId(); if ($gameAction->Code) { $oGameAction->code = $gameAction->Code; $oGameAction->description = $gameAction->Description; } // add a point to the assigned team is needed if ($oType->is_goal) { if ($oGameAction->team_nefub_id == $oGame->team1_nefub_id) { $team1_score++; } else { $team2_score++; } } $oGameAction->team1_score = $team1_score; $oGameAction->team2_score = $team2_score; $oGameAction->save(); $this->addedNefubObject($oGameAction); return $oGameAction; }