Exemple #1
0
 if (($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) {
     throw new InvalidArgumentException("id can not be empty or negitive", 405);
 }
 //sanitize and trim other fields
 $teamStatisticGameId = filter_input(INPUT_GET, "gameId", FILTER_SANITIZE_NUMBER_INT);
 $teamStatisticTeamId = filter_input(INPUT_GET, "teamId", FILTER_SANITIZE_NUMBER_INT);
 $teamStatisticStatisticId = filter_input(INPUT_GET, "statisticId", FILTER_SANITIZE_NUMBER_INT);
 $teamStatisticValue = filter_input(INPUT_GET, "statisticValue", FILTER_SANITIZE_NUMBER_INT);
 //handle REST calls, while only allowing administrators to access database-modifying methods
 if ($method === "GET") {
     //set XSRF cookie
     setXsrfCookie("/");
     //get the teamStatistic based on the given field
 }
 if (empty($teamStatisticGameId) === false) {
     $teamStatistic = TeamStatistic::getTeamStatisticByTeamStatisticGameId($pdo, $teamStatisticGameId);
     $reply->data = $teamStatistic;
 } else {
     if (empty($teamStatisticTeamId) === false) {
         $teamStatistics = TeamStatistic::getTeamStatisticByTeamStatisticTeamId($pdo, $teamStatisticTeamId)->toArray();
         $reply->data = $teamStatistics;
         //	if($teamStatistic !== null && $teamStatistic->getPlayerId() === $_SESSION["teamStatistic"]->getTeamId()) {
         //		$reply->data = $teamStatistic;
         //	}
     } else {
         if (empty($teamStatisticStatisticId) === false) {
             $teamStatistic = TeamStatistic::getTeamStatisticByTeamStatisticStatisticId($pdo, $teamStatisticStatisticId);
             $reply->data = $teamStatistic;
             //	if($teamStatistic !== null && $teamStatistic->getStatisticId() === $_SESSION["teamStatistic"]->getStatisticId()) {
             //		$reply->data = $teamStatistic;
             //		}
 /**
  * test inserting a valid PlayerStatistic and verify that the actual mySQL data matches
  **/
 public function testInsertValidTeamStatisticByTeamStatisticGameId()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("teamStatistic");
     // create a new PlayerStatistics and insert to into mySQL
     $teamStatistic = new TeamStatistic($this->game->getGameId(), $this->team->getTeamId(), $this->statistic->getStatisticId(), $this->VALID_TEAMSTATISTICVALUE);
     $teamStatistic->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoTeamStatistic = TeamStatistic::getTeamStatisticByTeamStatisticGameId($this->getPDO(), $this->game->getGameId(), $this->team->getTeamId(), $this->statistic->getStatisticId());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("teamStatistic"));
     $this->assertEquals($pdoTeamStatistic->getTeamStatisticGameId(), $this->game->getGameId());
     $this->assertEquals($pdoTeamStatistic->getTeamStatisticTeamId(), $this->team->getTeamId());
     $this->assertEquals($pdoTeamStatistic->getTeamStatisticStatisticId(), $this->statistic->getStatisticId());
     $this->assertEquals($pdoTeamStatistic->getTeamStatisticValue(), $this->VALID_TEAMSTATISTICVALUE);
 }