Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projet-cdaw
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thibaut Felten
projet-cdaw
Commits
7a3492af
Commit
7a3492af
authored
Dec 01, 2020
by
Robin Borgogno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ajout Game et UserGame au MVC
parent
2fbd94d1
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
316 additions
and
5 deletions
+316
-5
GameController.class.php
backend/MVC/controller/GameController.class.php
+100
-0
GamesController.class.php
backend/MVC/controller/GamesController.class.php
+36
-0
GameuserController.class.php
backend/MVC/controller/GameuserController.class.php
+79
-0
LoginController.class.php
backend/MVC/controller/LoginController.class.php
+1
-1
Game.class.php
backend/MVC/model/Game.class.php
+59
-0
User.class.php
backend/MVC/model/User.class.php
+10
-4
Game.sql.php
backend/MVC/sql/Game.sql.php
+28
-0
User.sql.php
backend/MVC/sql/User.sql.php
+3
-0
No files found.
backend/MVC/controller/GameController.class.php
0 → 100644
View file @
7a3492af
<?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
GameController
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
->
getGame
(
$id
);
break
;
case
'POST'
:
$data
=
json_decode
(
file_get_contents
(
"php://input"
),
TRUE
);
return
$this
->
createGame
(
$data
);
break
;
case
'PUT'
:
$id
=
$this
->
request
->
getURIParams
()[
0
];
$data
=
json_decode
(
file_get_contents
(
"php://input"
),
TRUE
);
return
$this
->
updateGame
(
$id
,
$data
);
break
;
case
'DELETE'
:
$id
=
$this
->
request
->
getURIParams
()[
0
];
return
$this
->
deleteGame
(
$id
);
break
;
}
return
Response
::
errorResponse
(
"unsupported parameters or method in game"
);
}
public
function
getGame
(
$id
)
{
$game
=
Game
::
getGame
(
$id
);
if
(
$game
==
Array
()){
$response
=
Response
::
errorInParametersResponse
(
"Game not found"
);
}
else
{
$response
=
new
Response
(
200
,
json_encode
(
$game
));
}
return
$response
;
}
public
function
createGame
(
$data
)
{
if
(
array_key_exists
(
"GAME_DESC"
,
$data
)){
$game
=
Game
::
createGame
(
array
(
":GAME_DESC"
=>
$data
[
'GAME_DESC'
]));
$response
=
new
Response
(
200
,
json_encode
(
$game
));
}
else
{
$response
=
Response
::
errorInParametersResponse
(
"Parameters missing"
);
}
return
$response
;
}
public
function
updateGame
(
$id
,
$data
)
{
$gameValues
=
Game
::
getGame
(
$id
);
$gameValues
=
(
$gameValues
[
0
]);
if
(
$gameValues
==
[]){
$response
=
Response
::
errorResponse
(
"Game not found"
);
return
$response
;
}
else
{
if
(
array_key_exists
(
'GAME_DESC'
,
$data
)){
$desc
=
$data
[
'GAME_DESC'
];
}
else
{
$desc
=
$gameValues
->
GAME_DESC
;
}
$game
=
Game
::
updateGame
(
array
(
":GAME_ID"
=>
$id
,
":GAME_DESC"
=>
$desc
));
$response
=
new
Response
(
200
,
json_encode
(
$game
));
return
$response
;
}
}
public
function
deleteGame
(
$id
)
{
$game
=
Game
::
getGame
(
$id
);
if
(
$game
==
Array
()){
$response
=
Response
::
errorInParametersResponse
(
json_encode
(
"Game not found"
));
}
else
{
$res
=
Game
::
deleteGame
(
$id
);
$response
=
Response
::
okResponse
(
json_encode
(
$res
));
}
return
$response
;
}
}
backend/MVC/controller/GamesController.class.php
0 → 100644
View file @
7a3492af
<?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
GamesController
extends
Controller
{
public
function
__construct
(
$name
,
$request
)
{
parent
::
__construct
(
$name
,
$request
);
}
// ==============
// Actions
// ==============
public
function
processRequest
()
{
switch
(
$this
->
request
->
getHttpMethod
())
{
case
'GET'
:
return
$this
->
getList
();
break
;
}
return
Response
::
errorResponse
(
"unsupported parameters or method in game"
);
}
public
function
getList
()
{
$games
=
Game
::
getList
();
$response
=
new
Response
(
200
,
json_encode
(
$games
));
return
$response
;
}
}
backend/MVC/controller/GameuserController.class.php
0 → 100644
View file @
7a3492af
<?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
;
}
}
backend/MVC/controller/LoginController.class.php
View file @
7a3492af
backend/MVC/model/Game.class.php
0 → 100644
View file @
7a3492af
<?php
class
Game
extends
Model
{
// ===========
// = Statics =
// ===========
protected
static
$table_name
=
'GAME'
;
public
static
function
getList
()
{
$stm
=
parent
::
exec
(
'GAME_LIST'
);
return
$stm
->
fetchAll
();
}
public
static
function
getGame
(
$id
)
{
$stm
=
parent
::
exec
(
'GAME_BY_ID'
,
array
(
':game_id'
=>
$id
));
return
$stm
->
fetchAll
();
}
public
static
function
createGame
(
$values
)
{
$stm
=
parent
::
exec
(
'GAME_CREATE'
,
$values
);
$stmbis
=
parent
::
exec
(
'GAME_ID_MAX'
);
return
$stmbis
->
fetchAll
();
}
public
static
function
updateGame
(
$values
)
{
$stm
=
parent
::
exec
(
'GAME_UPDATE'
,
$values
);
return
"La game a été uploader"
;
}
public
static
function
deleteGame
(
$id
)
{
$stm
=
parent
::
exec
(
'GAME_DELETE'
,
array
(
":GAME_ID"
=>
$id
));
return
"Game deleted"
;
}
public
static
function
getUsers
(
$id
)
{
$stm
=
parent
::
exec
(
'GAME_GET_USERS'
,
array
(
":GAME_ID"
=>
$id
));
return
$stm
->
fetchAll
();
}
public
static
function
addUserGame
(
$values
)
{
$stm
=
parent
::
exec
(
'GAME_ADD_USER'
,
$values
);
return
$stm
;
}
public
static
function
deleteUserGame
(
$values
)
{
$stm
=
parent
::
exec
(
'GAME_DELETE_USER'
,
$values
);
return
$stm
;
}
}
\ No newline at end of file
backend/MVC/model/User.class.php
View file @
7a3492af
...
...
@@ -50,4 +50,10 @@ class User extends Model {
return
$users
[
0
];
}
public
static
function
getGames
(
$id
)
{
$stm
=
parent
::
exec
(
'USER_GET_GAMES'
,
array
(
':USER_ID'
=>
$id
));
return
$stm
->
fetchAll
();
}
}
\ No newline at end of file
backend/MVC/sql/Game.sql.php
0 → 100644
View file @
7a3492af
<?php
Game
::
addSqlQuery
(
'GAME_LIST'
,
"SELECT * FROM GAME ORDER BY GAME_ID"
);
Game
::
addSqlQuery
(
'GAME_BY_ID'
,
"SELECT * FROM GAME WHERE GAME_ID=:game_id"
);
Game
::
addSqlQuery
(
'GAME_CREATE'
,
"INSERT INTO GAME (GAME_ID, GAME_DESC) VALUES (NULL, :GAME_DESC)"
);
Game
::
addSqlQuery
(
'GAME_ID_MAX'
,
"SELECT MAX(GAME_ID) FROM GAME"
);
Game
::
addSqlQuery
(
'GAME_UPDATE'
,
"UPDATE GAME SET GAME_DESC=:GAME_DESC WHERE GAME_ID=:GAME_ID"
);
Game
::
addSqlQuery
(
'GAME_DELETE'
,
"DELETE FROM GAME WHERE GAME_ID=:GAME_ID"
);
Game
::
addSqlQuery
(
'GAME_GET_USERS'
,
"SELECT USER_ID FROM GAME_HISTO WHERE GAME_ID=:GAME_ID"
);
Game
::
addSqlQuery
(
'GAME_ADD_USER'
,
"INSERT INTO GAME_HISTO (GAME_HISTO_ID, GAME_ID, USER_ID) VALUES (NULL, :GAME_ID, :USER_ID)"
);
Game
::
addSqlQuery
(
'GAME_DELETE_USER'
,
"DELETE FROM GAME_HISTO WHERE (GAME_ID=:GAME_ID AND USER_ID=:USER_ID)"
);
\ No newline at end of file
backend/MVC/sql/User.sql.php
View file @
7a3492af
...
...
@@ -20,3 +20,6 @@ User::addSqlQuery('USER_DELETE',
User
::
addSqlQuery
(
'USER_CREATE'
,
"INSERT INTO USER (USER_ID, USER_LOGIN, USER_EMAIL, USER_ROLE, USER_PASSWORD, USER_FIRSTNAME, USER_LASTNAME) VALUES (NULL, :login, :email, :role, :password, :firstname, :lastname)"
);
User
::
addSqlQuery
(
'USER_GET_GAMES'
,
"SELECT GAME_ID FROM GAME_HISTO WHERE USER_ID=:USER_ID"
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment