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
1
Issues
1
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
Quentin Vrel
projet-cdaw
Commits
ba9156dc
Commit
ba9156dc
authored
Nov 23, 2020
by
quentin.vrel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tp3 update réparé
parent
44702c15
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
38 deletions
+9
-38
UserController.class.php
BackEnd/tp3/controller/UserController.class.php
+4
-28
User.class.php
BackEnd/tp3/model/User.class.php
+2
-8
User.sql.php
BackEnd/tp3/sql/User.sql.php
+1
-1
Request.class.php
BackEnd/tp4/classes/Request.class.php
+2
-1
No files found.
BackEnd/tp3/controller/UserController.class.php
View file @
ba9156dc
...
...
@@ -20,8 +20,7 @@ class UserController extends Controller {
return
$this
->
getAllUsers
();
break
;
case
'PUT'
:
if
(
$this
->
request
->
getUriParams
())
return
$this
->
updateUser
(
$this
->
request
->
getUriParams
()[
0
],
$this
->
request
->
getData
());
return
$this
->
updateUser
(
$this
->
request
->
getData
());
break
;
}
return
Response
::
errorResponse
(
"unsupported parameters or method in users"
);
...
...
@@ -41,32 +40,9 @@ class UserController extends Controller {
$response
=
Response
::
okResponse
(
json_encode
(
$user
));
return
$response
;
}
protected
function
updateUser
(
$id
,
$data
){
$sets
=
[];
if
(
isset
(
$data
[
'login'
])){
$sets
[]
=
[
'USER_LOGIN'
,
$data
[
'login'
]];
}
if
(
isset
(
$data
[
'email'
])){
$sets
[]
=
[
'USER_EMAIL'
,
$data
[
'email'
]];
}
if
(
isset
(
$data
[
'role'
])){
$sets
[]
=
[
'USER_ROLE'
,
$data
[
'role'
]];
}
if
(
isset
(
$data
[
'pwd'
])){
$sets
[]
=
[
'USER_PWD'
,
$data
[
'pwd'
]];
}
if
(
isset
(
$data
[
'name'
])){
$sets
[]
=
[
'USER_NAME'
,
$data
[
'name'
]];
}
if
(
isset
(
$data
[
'surname'
])){
$sets
[]
=
[
'USER_SURNAME'
,
$data
[
'surname'
]];
}
//$sets = implode(', ', $sets);
$success
=
true
;
foreach
(
$sets
as
$set
)
{
$success
&=
User
::
update
(
$id
,
$set
);
}
$response
=
$success
?
Response
::
okResponse
(
"Updated"
)
:
Response
::
errorResponse
(
"failed"
);
protected
function
updateUser
(
$array
){
User
::
updateUser
(
$array
);
$response
=
Response
::
okResponse
(
'User succesfully updated !'
);
return
$response
;
}
}
\ No newline at end of file
BackEnd/tp3/model/User.class.php
View file @
ba9156dc
...
...
@@ -17,14 +17,8 @@ class User extends Model {
return
$stm
->
fetchAll
();
}
public
static
function
update
(
$id
,
$set
)
{
$stm
=
parent
::
exec
(
'USER_UPDATE'
,
[
'id'
=>
$id
,
'set_field'
=>
$set
[
0
],
'set_value'
=>
$set
[
1
]]);
try
{
return
true
;
}
catch
(
\Throwable
$th
)
{
die
(
"dommage, fromage"
);
}
public
static
function
updateUser
(
$array
)
{
$stm
=
parent
::
exec
(
'USER_UPDATE'
,
$array
);
}
...
...
BackEnd/tp3/sql/User.sql.php
View file @
ba9156dc
...
...
@@ -16,4 +16,4 @@ User::addSqlQuery('USER_CONNECT',
'SELECT * FROM USER WHERE USER_LOGIN=:login and USER_PWD=:password'
);
User
::
addSqlQuery
(
'USER_UPDATE'
,
'UPDATE `USER` SET :set_field = :set_value WHERE `USER_ID` = :id'
);
\ No newline at end of file
'UPDATE USER SET USER_EMAIL = :email WHERE USER_ID = :id'
);
\ No newline at end of file
BackEnd/tp4/classes/Request.class.php
View file @
ba9156dc
...
...
@@ -70,7 +70,8 @@ class Request {
public
function
initData
()
{
if
(
$this
->
getHttpMethod
()
===
'PUT'
||
$this
->
getHttpMethod
()
===
'POST'
){
$this
->
data
=
json_decode
(
file_get_contents
(
"php://input"
),
true
);
$jsondata
=
file_get_contents
(
"php://input"
);
$this
->
data
=
json_decode
(
$jsondata
,
true
);
}
}
...
...
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