/**
 * @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;
    }
}
 $seasoning = ["2015", "2016"];
 foreach ($seasoning as $season) {
     $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 = file_get_contents("https://api.fantasydata.net/nfl/v2/JSON/Teams/{$season}", false, $context);
     $data = json_decode($response);
     $stats = ["TeamID", "PlayerID", "City", "Name", "Conference", "Division", "FullName", "StadiumID", "ByeWeek", "AverageDraftPosition", "AverageDraftPositionPPR", "HeadCoach", "OffensiveCoordinator", "DefensiveCoordinator", "SpecialTeamsCoach", "OffensiveScheme", "DefensiveScheme", "UpcomingOpponent", "UpcomingOpponentRank ", "UpcomingOpponentPositionRank"];
     $sport = Sport::getSportBySportLeague($pdo, "NFL");
     foreach ($data as $teamData) {
         $team = Team::getTeamByTeamApiId($pdo, $teamData->Key);
         if ($team === null) {
             $team = new Team(null, $sport->getSportId(), $teamData->Key, $teamData->City, $teamData->Name);
             $team->insert($pdo);
             $game = Game::getGameByGameFirstTeamId($pdo, $team->getTeamId());
             if ($game === null) {
                 $game = Game::getGameByGameSecondTeamId($pdo, $team->getTeamId());
             }
             // response from api
             //get team statistics by game
             for ($week = 1; $week <= 21; $week++) {
                 $response = file_get_contents("https://api.fantasydata.net/nfl/v2/JSON/GameStatsByWeek/{$season}/{$week}", 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);
示例#3
0
<?php

require __DIR__ . '/../../autoload.php';
$name = $_POST['name'];
$position = $_POST['position'];
$description = $_POST['description'];
$file = $_FILES['image'];
$uploaddir = __DIR__ . "/../../img";
/*upload img*/
$name_file = 'image';
if (!empty($file) && !empty($name) && !empty($position) && !empty($description)) {
    $uploads = new Uploader($name_file);
    $uploads->upload($uploaddir);
    $team = new Team();
    $team->insert($name, $position, $description, $_FILES['image']['name']);
}
header("Location: ../../admin.php");