Пример #1
0
        echo $json;
        $db->closeConnection();
    }
}
if (isset($_POST['func'])) {
    $db = new DatabaseBroker();
    $response = new Response();
    try {
        $db->openConnection();
        switch ($_POST['func']) {
            case 'savePlayer':
                // create club object
                $clubId = $_POST['clubId'];
                $club = $db->getClubById($clubId);
                // create player object
                $playerId = $db->getLastPlayerId();
                $playerName = $_POST['playerName'];
                $birthDate = $_POST['birthDate'];
                $position = $_POST['position'];
                $squadNumber = $_POST['squadNumber'];
                $player = new Player($playerId, $playerName, $birthDate, $position, $squadNumber, $club);
                // save player in database
                $db->savePlayer($player);
                // set json response value
                $response->setSuccesfull(true);
                $response->setMessage('Player has been saved.');
                break;
            case 'updatePlayerStats':
                $entryId = $_POST['entryId'];
                $player = $db->getPlayerById($_POST['playerId']);
                $appearances = $_POST['appearances'];