本文整理匯總了PHP中Game::getGameByGameFirstTeamId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Game::getGameByGameFirstTeamId方法的具體用法?PHP Game::getGameByGameFirstTeamId怎麽用?PHP Game::getGameByGameFirstTeamId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Game
的用法示例。
在下文中一共展示了Game::getGameByGameFirstTeamId方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getTeams
/**
* @param string $league
* @param int $teamSportId
*/
function getTeams(string $league, int $teamSportId)
{
try {
// grab the db connection
$pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/sprots.ini");
$config = readConfig("/etc/apache2/capstone-mysql/sprots.ini");
$apiKeys = json_decode($config["fantasyData"]);
$opts = array('http' => array('method' => "GET", 'header' => "Content-Type: application/json\r\nOcp-Apim-Subscription-key: " . $apiKeys->{$league}, 'content' => "{body}"));
$context = stream_context_create($opts);
// response from api
$response = file_get_contents("https://api.fantasydata.net/{$league}/v2/JSON/teams", false, $context);
$data = json_decode($response);
// Places team in designated sport, and populates teams in team db with response from api
$sport = Sport::getSportBySportLeague($pdo, $league);
foreach ($data as $team) {
$team = new Team(null, $sport->getSportId(), $team->TeamID, $team->City, $team->Name);
$team->insert($pdo);
// get team statistics by game
$game = Game::getGameByGameFirstTeamId($pdo, $team->getTeamId());
if ($game === null) {
$game = Game::getGameByGameSecondTeamId($pdo, $team->getTeamId());
if ($game === null) {
continue;
}
}
$gameDate = $game->getGameTime()->format("Y-m-d");
// response from api
$response = file_get_contents("https://api.fantasydata.net/{$league}/v2/JSON/TeamGameStatsByDate/{$gameDate}");
$statisticData = json_decode($response);
// adds statistics to database
foreach ($GLOBALS['stats'] as $statisticName) {
$statistic = Statistic::getStatisticByStatisticName($pdo, $statisticName);
if ($statistic === null || $statistic->getSize() <= 0) {
$statistic = new Statistic(null, $statisticName);
$statistic->insert($pdo);
} else {
$statistic = $statistic[0];
}
$statisticValue = null;
if (empty($statisticData->{$statisticName}) === false) {
$statisticValue = $statisticData->{$statisticName};
}
if ($statisticValue !== null) {
// $statisticValue = "";
$teamStatisticToInsert = new TeamStatistic($game->getGameId(), $team->getTeamId(), $statistic->getTeamStatisticStatisticId(), $statisticValue);
$teamStatisticToInsert->insert($pdo);
} else {
echo "<p> team statistics isn't working </p>" . PHP_EOL;
}
}
}
} catch (Exception $exception) {
echo "Something went wrong: " . $exception->getMessage() . PHP_EOL;
} catch (TypeError $typeError) {
echo "Something went wrong: " . $typeError->getMessage() . PHP_EOL;
}
}
示例2: connectToEncryptedMySQL
$pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/sprots.ini");
$config = readConfig("/etc/apache2/capstone-mysql/sprots.ini");
$apiKeys = json_decode($config["fantasyData"]);
$opts = array('http' => array('method' => "GET", 'header' => "Content-Type: application/json\r\nOcp-Apim-Subscription-key: " . $apiKeys->NFL, 'content' => "{body}"));
$context = stream_context_create($opts);
//response from Api
$response = file_get_contents("https://api.fantasydata.net/nfl/v2/JSON/Players/{$season}", false, $context);
$data = json_decode($response);
$stats = ["PlayerID ", "Team", "Number ", "FirstName ", "LastName", "Status ", "Height ", "Weight", "BirthDate ", "College ", "Experience ", "Active ", "PositionCategory ", "Name", "Age ", "ExperienceString ", "BirthDateString", "PhotoUrl ", "ByeWeek ", "UpcomingGameOpponent ", "UpcomingGameWeek", "ShortName ", "AverageDraftPosition ", "DepthPositionCategory ", "DepthPosition ", "DepthOrder ", "DepthDisplayOrder ", "CurrentTeam ", "HeightFeet ", "UpcomingOpponentRank ", "UpcomingOpponentPositionRank ", "CurrentStatus"];
$sport = Sport::getSportBySportLeague($pdo, "NFL");
foreach ($data as $player) {
$team = Team::getTeamByTeamApiId($pdo, $player->TeamID);
if ($team !== null) {
$playerToInsert = new Player(null, $player->PlayerID, $team->getTeamId(), $sport->getSportId(), $player->FirstName . " " . $player->LastName);
$playerToInsert->insert($pdo);
$game = Game::getGameByGameFirstTeamId($pdo, $team->getTeamId());
if ($game === null) {
$game = Game::getGameByGameSecondTeamId($pdo, $team->getTeamId());
}
//get player statistic by game
//response from api
for ($week = 1; $week <= 21; $week++) {
$response = file_get_contents("https://api.fantasydata.net/nfl/v2/JSON/PlayerGameStatsByPlayerID/{$season}/{$week}/{$player->PlayerID}", false, $context);
$statisticData = json_decode($response);
//adds statistic to database
foreach ($stats as $statisticName) {
$statistic = Statistic::getStatisticByStatisticName($pdo, $statisticName);
if ($statistic === null || $statistic->getSize() <= 0) {
$statistic = new Statistic(null, $statisticName);
$statistic->insert($pdo);
} else {
示例3: InvalidArgumentException
throw new InvalidArgumentException("id can not be empty or negitive", 405);
}
//sanitize and trim other fields
$gameId = filter_input(INPUT_GET, "gameId", FILTER_VALIDATE_INT);
$gameFirstTeamId = filter_input(INPUT_GET, "gameFirstTeamId", FILTER_VALIDATE_INT);
$gameSecondTeamId = filter_input(INPUT_GET, "gameSecondTeamID", FILTER_VALIDATE_INT);
$gameTime = filter_input(INPUT_GET, "gameTime", FILTER_VALIDATE_INT);
$gameTime /= 1000;
$gameTime = DateTime::createFromFormat("U", strval($gameTime));
// get the Game based on the given field
if (empty($id) === false) {
$game = Game::getGameByGameId($pdo, $id);
$reply->data = $game;
} else {
if (empty($gameFirstTeamId) === false) {
$game = Game::getGameByGameFirstTeamId($pdo, $id);
if ($game !== null && $game->getGameId() === $_SESSION["Game"]->getGameId()) {
$reply->data = $game;
}
} else {
if (empty($gameSecondTeamId) === false) {
$game = Game::getGameByGameSecondTeamId($pdo, $id);
if ($game !== null && $game->getGameId() === $_SESSION["Game"]->getGameId()) {
$reply->data = $game;
}
} else {
if (empty($gameTime) === false) {
$game = Game::getGameByGameTime($pdo, $gameTime);
if ($game !== null && $game->getGameTime() === $_SESSION["Game"]->getGameTime()) {
$reply->data = $game;
} else {