Exemple #1
0
<?php

header('Content-type: application/json;');
include_once 'domain/Club.php';
include_once 'domain/Player.php';
include_once 'domain/Statistics.php';
include_once 'util/Response.php';
include_once 'database/DatabaseBroker.php';
$json = "{\n\t\t\"cols\":[\n\t\t{\"label\":\"Player\", \"type\":\"string\"},\n\t\t{\"label\":\"Appearances\", \"type\":\"number\"},\n\t\t{\"label\":\"Goals\", \"type\":\"number\"} \n\t\t],\n\t\t\"rows\":[\n\t\t";
$db = new DatabaseBroker();
$db->openConnection();
$club_id = $_GET['club_id'];
$stats = $db->generateChartStatistics($club_id);
$db->closeConnection();
foreach ($stats as $s) {
    $json .= "{\"c\":[{\"v\":\"{$s->getPlayer()->getPlayerName()}\"},{\"v\":{$s->getAppearances()}}, {\"v\":{$s->getGoals()}}]},";
}
$json = substr($json, 0, -1);
$json .= "]}";
echo $json;
Exemple #2
0
<?php

include_once 'database/DatabaseBroker.php';
$db = new DatabaseBroker();
$db->openConnection();
$players = $db->getPlayers(1);
$db->closeConnection();
foreach ($players as $player) {
    echo $player . '<br>';
}
                $response->setSuccesfull(true);
                $response->setValue($statistics);
                break;
        }
    } catch (Exception $e) {
        // set json response value
        $response->setSuccesfull(false);
        $response->setMessage('Error! ' . $e->getMessage());
    } finally {
        $json = json_encode($response);
        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);