Exemple #1
0
    $playerStatisticStatisticId = filter_input(INPUT_GET, "statisticId", FILTER_SANITIZE_NUMBER_INT);
    $playerStatisticValue = 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 playerStatistic based on the given field
    }
    if (empty($playerStatisticGameId) === false) {
        $playerStatistic = PlayerStatistic::getPlayerStatisticByPlayerStatisticGameId($pdo, $playerStatisticGameId);
        $reply->data = $playerStatistic;
    } else {
        if (empty($playerStatisticPlayerId) === false) {
            $playerStatistics = PlayerStatistic::getPlayerStatisticByPlayerStatisticPlayerId($pdo, $playerStatisticPlayerId)->toArray();
            $reply->data = $playerStatistics;
        } else {
            if (empty($playerStatisticStatisticId) === false) {
                $playerStatistic = PlayerStatistic::getPlayerStatisticByPlayerStatisticStatisticId($pdo, $playerStatisticStatisticId);
                $reply->data = $playerStatistic;
            }
        }
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
}
header("Content-type: application/json");
if ($reply->data === null) {
    unset($reply->data);
}
echo json_encode($reply);
 /**
  * test inserting a valid PlayerStatistic and verify that the actual mySQL data matches
  **/
 public function testInsertValidPlayerStatistic()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("playerStatistic");
     // create a new PlayerStatistics and insert to into mySQL
     $playerStatistic = new PlayerStatistic(null, $this->plsayerStatistic->getPlayerStatisticId(), $this->VALID_PLAYERSTATISTIC);
     $playerStatistic->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoPlayerStatistic = PlayerStatistic::getPlayerStatisticByPlayerStatisticStatisticId();
     $this->getPDO();
     $playerStatistic->getPlayerStatisticId();
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("playerStatistic"));
     $this->assertEquals($pdoPlayerStatistic->getPlayerStatisticId(), $this->playerstatistic->getPlayerStatisticId());
 }