Example #1
0
 public function update(Player $object)
 {
     $q = "UPDATE " . self::TABLE . " SET `name`='" . Singleton::create("NullConverter")->fromDOMtoDB($object->getName()) . "', `teamId`='" . Singleton::create("NullConverter")->fromDOMtoDB($object->getTeamId()) . "' WHERE playerId='" . addslashes($object->getPlayerId()) . "'";
     $pk = $object->getPlayerId();
     if ($object->isNew()) {
         if (empty($pk)) {
             $q = "INSERT INTO " . self::TABLE . " (`name`, `teamId`) VALUES ('" . Singleton::create("NullConverter")->fromDOMtoDB($object->getName()) . "', '" . Singleton::create("NullConverter")->fromDOMtoDB($object->getTeamId()) . "')";
         } else {
             $q = "INSERT INTO " . self::TABLE . " (`name`, `teamId`) VALUES ('" . Singleton::create("NullConverter")->fromDOMtoDB($object->getPlayerId()) . "', '" . Singleton::create("NullConverter")->fromDOMtoDB($object->getName()) . "', '" . Singleton::create("NullConverter")->fromDOMtoDB($object->getTeamId()) . "')";
         }
     }
     $this->db->updateQuery($q);
     if (empty($pk)) {
         $pk = $this->db->selectQuery("SELECT playerId from " . self::TABLE . " ORDER BY playerId DESC limit 1")->getSingleton();
     }
     $result = $this->findByPrimaryKey($pk);
     parent::$dbCache->resetEntity("Player");
     parent::$dbCache->setSingle("Player", $pk, $result);
     return $result;
 }
Example #2
0
 public function __construct()
 {
     $this->arrErrors = parse_ini_file('INI/Errors.ini', true);
     $this->arrRooms = parse_ini_file('INI/Rooms.ini', true);
     $this->arrServers = parse_ini_file('INI/Servers.ini', true);
     $this->addListener('e', function ($arrPacket) {
         $intError = $arrPacket[3];
         echo 'Received error: ', $intError, '!', chr(10);
     });
     $this->addListener('lp', function ($arrPacket) {
         $arrPlayer = XTParser::ParseVertical($arrPacket[3]);
         $this->objPlayer = new Player($arrPlayer);
     });
     $this->addListener('jr', function ($arrPacket) {
         $intInternal = $arrPacket[2];
         $intRoom = $arrPacket[3];
         $this->intInternalRoom = $intInternal;
         $this->intExternalRoom = $intRoom;
         $this->arrRoom = array();
         array_shift($arrPacket);
         array_shift($arrPacket);
         array_shift($arrPacket);
         foreach ($arrPacket as $strPenguin) {
             $arrPlayer = XTParser::ParseVertical($strPenguin);
             if (!empty($arrPlayer)) {
                 if ($arrPlayer[0] != $this->intPlayerId) {
                     $objPlayer = new Player($arrPlayer);
                     $this->arrRoom[$objPlayer->getPlayerId()] = $objPlayer;
                 }
             }
         }
     });
     $this->addListener('ap', function ($arrPacket) {
         $arrPlayer = XTParser::ParseVertical($arrPacket[3]);
         if ($arrPlayer[0] != $this->intPlayerId) {
             $objPlayer = new Player($arrPlayer);
             $this->arrRoom[$objPlayer->getPlayerId()] = $objPlayer;
         }
     });
     $this->addListener('rp', function ($arrPacket) {
         $intPlayer = $arrPacket[3];
         unset($this->arrRoom[$intPlayer]);
     });
 }
                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 {
                            $statistic = $statistic[0];
                        }
                        if (empty($statisticData->{$statisticName}) === false) {
                            $playerStatisticToInsert = new PlayerStatistic($game->getGameId(), $playerToInsert->getPlayerId(), $team->getTeamId(), $statistic->getStatisticId(), $statisticData->{$statisticName});
                            $playerStatisticToInsert->insert($pdo);
                        }
                    }
                }
            }
        }
    }
} catch (Exception $exception) {
    echo "Something went wrong: " . $exception->getMessage() . PHP_EOL;
} catch (TypeError $typeError) {
    echo "Something went wrong: " . $typeError->getMessage() . PHP_EOL;
}
 public function savePlayer(Player $player)
 {
     $playerId = $player->getPlayerId();
     $playerName = $player->getPlayerName();
     $birthDate = $player->getBirthDate();
     $position = $player->getPosition();
     $squadNumber = $player->getSquadNumber();
     $clubId = $player->getClub()->getClubId();
     $query = "INSERT INTO players VALUES ({$playerId}, '{$playerName}', '{$birthDate}', '{$position}', {$squadNumber}, {$clubId})";
     $rs = $this->connection->query($query);
     if (!$rs) {
         throw new Exception('Could not save player!');
     }
 }
Example #5
0
 private function history()
 {
     $current_player = new Player($this->getPlayerId());
     $current_player->build();
     db_insert('player_history')->fields(array('playerid' => $current_player->getPlayerId(), 'first_name' => $current_player->getFirstName(), 'last_name' => $current_player->getLastName(), 'player_positionid' => $current_player->getPlayerPositionId(), 'secondary_player_positionid' => $current_player->getSecondaryPlayerPositionId(), 'active_yn' => $current_player->getActiveYN(), 'saved_userid' => $current_player->getSavedUserID(), 'saved_datetime' => $current_player->getSavedDateTime(), 'history_userid' => $this->getSavedUserID(), 'history_datetime' => $this->getSavedDateTime()))->execute();
 }
function getPlayers(string $league)
{
    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/Players", false, $context);
        $data = json_decode($response);
        $sport = Sport::getSportBySportLeague($pdo, $league);
        /*todo
        
        		Get Teams
        		Get Game
        		Use the player's team key to get team IDs from your database
        		Use team ID to get games
        		Use game date time + player api ID to get game stats
        
        		*/
        // Adds players to database
        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());
                }
                $gameDate = $game->getGameTime()->format("Y-m-d");
                // Get player statistics by game
                // response from api
                $response = file_get_contents("https://api.fantasydata.net/{$league}/v2/JSON/PlayerGameStatsByPlayer/{$gameDate}/{$player->PlayerID}", false, $context);
                $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];
                    }
                    if (empty($statisticData->{$statisticName}) === false) {
                        $playerStatisticToInsert = new PlayerStatistic($game->getGameId(), $playerToInsert->getPlayerId(), $team->getTeamId(), $statistic->getStatisticId(), $statisticData->{$statisticName});
                        $playerStatisticToInsert->insert($pdo);
                    }
                    //					var_dump($statisticData);
                    //					var_dump($statisticName);
                    //					var_dump($statistic);
                    //					var_dump($statisticValue);
                }
            } else {
                echo "<p>* * * SIX OF THIRTEEN IS NOT A TEAM PLAYER * * *</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;
    }
}
 /**
  * test inserting a valid Player and regrabbing it from mySQL
  **/
 public function testGetValidPlayerByPlayerId()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("player");
     // create a new Player and insert to into mySQL
     $player = new Player(null, $this->player->getPlayerId(), $this->VALID_PLAYER);
     $player->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoPlayer = Player::getPlayerByPlayerId($this->getPDO(), $player->getPlayerId());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("player"));
     $this->assertEquals($pdoPlayer->getPlayerId(), $this->game->getPlayerId());
 }