示例#1
0
                $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'];
                $goals = $_POST['goals'];
                $assists = $_POST['assists'];
                $yellowCards = $_POST['yellow_cards'];
                $redCards = $_POST['red_cards'];
                $stat = new Statistics($entryId, $player, $appearances, $goals, $assists, $yellowCards, $redCards);
                $db->updatePlayerStats($stat);
                $response->setSuccesfull(true);
                $response->setMessage("Player stats have been updated.");
                $response->setValue($player);
                break;
        }
    } catch (Exception $ex) {
        $response->setSuccesfull(false);
        $response->setMessage($ex->getMessage());
    } finally {
        $json = json_encode($response);
        echo $json;
    }
}