1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
include_once __ROOT_DIR . '/libs/php-jwt/src/BeforeValidException.php';
include_once __ROOT_DIR . '/libs/php-jwt/src/ExpiredException.php';
include_once __ROOT_DIR . '/libs/php-jwt/src/SignatureInvalidException.php';
include_once __ROOT_DIR . '/libs/php-jwt/src/JWT.php';
use \Firebase\JWT\JWT;
class GameuserController extends Controller {
public function __construct($name, $request) {
parent::__construct($name, $request);
}
// ==============
// Actions
// ==============
public function processRequest()
{
switch ($this->request->getHttpMethod()) {
case 'GET':
switch($this->request->getURIParams()[0])
{
case 'user':
$id = $this->request->getURIParams()[1];
return $this->getGamesByUser($id);
break;
case 'game':
$id = $this->request->getURIParams()[1];
return $this->getUsersbyGame($id);
break;
}
break;
case 'POST':
$data = json_decode(file_get_contents("php://input"),TRUE);
return $this->addUserGame($data);
break;
case 'DELETE':
$data = json_decode(file_get_contents("php://input"),TRUE);
return $this->deleteUserGame($data);
break;
}
return Response::errorResponse("unsupported parameters or method in game");
}
public function getGamesByUser($id)
{
$games = User::getGames($id);
$response = new Response(200,json_encode($games));
return $response;
}
public function getUsersbyGame($id)
{
$users = Game::getUsers($id);
$response = new Response(200,json_encode($users));
return $response;
}
public function addUserGame($data)
{
$idLigne = Game::addUserGame(array(":GAME_ID" => $data['GAME_ID'], ":USER_ID" => $data['USER_ID']));
$response = new Response(200,json_encode("Joueur ajouté"));
return $response;
}
public function deleteUserGame($data)
{
$game = Game::deleteUserGame(array(":GAME_ID" => $data['GAME_ID'], ':USER_ID' => $data['USER_ID']));
$response = new Response(200, json_encode("Ligne supprimé"));
return $response;
}
}