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
<?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 ResultController extends Controller {
public function __construct($name, $request) {
parent::__construct($name, $request);
}
// ==============
// Actions
// ==============
public function processRequest()
{
switch ($this->request->getHttpMethod()) {
case 'GET':
$id = $this->request->getURIParams()[0];
return $this->returnResultGameID($id);
case 'POST':
$id = $this->request->getURIParams()[0];
$data = json_decode(file_get_contents("php://input"),TRUE);
return $this->saveAwnser($id, $data);
break;
case 'DELETE':
$data = json_decode(file_get_contents("php://input"),TRUE);
return $this->deleteLine($data);
break;
case 'OPTIONS':
return Response::okresponse(json_encode("OPTIONS"));
// $data = json_decode(file_get_contents("php://input"),TRUE);
// return $this->deleteLine($data);
// break;
}
return Response::errorResponse("unsupported parameters or method in game");
}
public function saveAwnser($id, $data)
{
Result::saveAwnser(array(":id" => $id, ":user_id" => $data['USER_ID'], ":awn" => $data['value']));
return Response::okresponse(json_encode("Tout va bien"));
}
public function returnResultGameID($id)
{
$result = Result::returnResultGameID(array(":id" => $id));
return Response::okresponse(json_encode($result));
}
public function deleteLine($data)
{
Result::deleteLigne(array(":id" => $data['USER_ID']));
return Response::okresponse(json_encode("Theo"));
}
}