Skip to content
Snippets Groups Projects
Verified Commit 6905a9d6 authored by Damien's avatar Damien
Browse files

[REFACTORING] Session is not welcome on src

parent 14f4cdac
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ class HistoryController ...@@ -44,7 +44,7 @@ class HistoryController
'WHERE' => $aArgs['tableName'], 'WHERE' => $aArgs['tableName'],
'ID' => $aArgs['recordId'], 'ID' => $aArgs['recordId'],
'HOW' => $aArgs['eventType'], 'HOW' => $aArgs['eventType'],
'USER' => $_SESSION['user']['UserId'], 'USER' => $GLOBALS['userId'],
'WHAT' => $aArgs['eventId'], 'WHAT' => $aArgs['eventId'],
'ID_MODULE' => $aArgs['moduleId'], 'ID_MODULE' => $aArgs['moduleId'],
'REMOTE_IP' => $_SERVER['REMOTE_ADDR'], 'REMOTE_IP' => $_SERVER['REMOTE_ADDR'],
...@@ -75,7 +75,7 @@ class HistoryController ...@@ -75,7 +75,7 @@ class HistoryController
'tableName' => $aArgs['tableName'], 'tableName' => $aArgs['tableName'],
'recordId' => $aArgs['recordId'], 'recordId' => $aArgs['recordId'],
'eventType' => $aArgs['eventType'], 'eventType' => $aArgs['eventType'],
'userId' => $_SESSION['user']['UserId'], 'userId' => $GLOBALS['userId'],
'info' => $aArgs['info'], 'info' => $aArgs['info'],
'moduleId' => $aArgs['moduleId'], 'moduleId' => $aArgs['moduleId'],
'eventId' => $aArgs['eventId'], 'eventId' => $aArgs['eventId'],
......
...@@ -27,7 +27,7 @@ class StatusController ...@@ -27,7 +27,7 @@ class StatusController
{ {
public function get(Request $request, Response $response) public function get(Request $request, Response $response)
{ {
if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $_SESSION['user']['UserId'], 'location' => 'apps', 'type' => 'admin'])) { if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
} }
...@@ -38,7 +38,7 @@ class StatusController ...@@ -38,7 +38,7 @@ class StatusController
public function getNewInformations(Request $request, Response $response) public function getNewInformations(Request $request, Response $response)
{ {
if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $_SESSION['user']['UserId'], 'location' => 'apps', 'type' => 'admin'])) { if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
} }
...@@ -49,7 +49,7 @@ class StatusController ...@@ -49,7 +49,7 @@ class StatusController
public function getByIdentifier(Request $request, Response $response, $aArgs) public function getByIdentifier(Request $request, Response $response, $aArgs)
{ {
if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $_SESSION['user']['UserId'], 'location' => 'apps', 'type' => 'admin'])) { if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
} }
...@@ -71,7 +71,7 @@ class StatusController ...@@ -71,7 +71,7 @@ class StatusController
public function create(Request $request, Response $response) public function create(Request $request, Response $response)
{ {
if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $_SESSION['user']['UserId'], 'location' => 'apps', 'type' => 'admin'])) { if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
} }
...@@ -83,26 +83,24 @@ class StatusController ...@@ -83,26 +83,24 @@ class StatusController
return $response->withStatus(500)->withJson(['errors' => $errors]); return $response->withStatus(500)->withJson(['errors' => $errors]);
} }
if (StatusModel::create($aArgs)) { StatusModel::create($aArgs);
$return['status'] = StatusModel::getById(['id' => $aArgs['id']])[0];
HistoryController::add([ $return['status'] = StatusModel::getById(['id' => $aArgs['id']])[0];
'tableName' => 'status',
'recordId' => $return['status']['id'],
'eventType' => 'ADD',
'eventId' => 'statusup',
'info' => _STATUS_ADDED . ' : ' . $return['status']['id']
]);
return $response->withJson($return); HistoryController::add([
} else { 'tableName' => 'status',
return $response->withStatus(500)->withJson(['errors' => _NOT_CREATE]); 'recordId' => $return['status']['id'],
} 'eventType' => 'ADD',
'eventId' => 'statusup',
'info' => _STATUS_ADDED . ' : ' . $return['status']['id']
]);
return $response->withJson($return);
} }
public function update(Request $request, Response $response, $aArgs) public function update(Request $request, Response $response, $aArgs)
{ {
if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $_SESSION['user']['UserId'], 'location' => 'apps', 'type' => 'admin'])) { if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
} }
...@@ -116,28 +114,24 @@ class StatusController ...@@ -116,28 +114,24 @@ class StatusController
return $response->withStatus(500)->withJson(['errors' => $errors]); return $response->withStatus(500)->withJson(['errors' => $errors]);
} }
if (StatusModel::update($aArgs)) { StatusModel::update($aArgs);
$return['status'] = StatusModel::getByIdentifier(['identifier' => $aArgs['identifier']])[0];
HistoryController::add([ $return['status'] = StatusModel::getByIdentifier(['identifier' => $aArgs['identifier']])[0];
'tableName' => 'status',
'recordId' => $return['status']['id'], HistoryController::add([
'eventType' => 'UP', 'tableName' => 'status',
'eventId' => 'statusup', 'recordId' => $return['status']['id'],
'info' => _MODIFY_STATUS . ' : ' . $return['status']['id'] 'eventType' => 'UP',
]); 'eventId' => 'statusup',
'info' => _MODIFY_STATUS . ' : ' . $return['status']['id']
return $response->withJson($return); ]);
} else {
return $response return $response->withJson($return);
->withStatus(500)
->withJson(['errors' => _NOT_UPDATE]);
}
} }
public function delete(Request $request, Response $response, $aArgs) public function delete(Request $request, Response $response, $aArgs)
{ {
if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $_SESSION['user']['UserId'], 'location' => 'apps', 'type' => 'admin'])) { if (!ServiceModel::hasService(['id' => 'admin_status', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
} }
...@@ -159,11 +153,7 @@ class StatusController ...@@ -159,11 +153,7 @@ class StatusController
->withJson(['errors' => 'identifier not valid']); ->withJson(['errors' => 'identifier not valid']);
} }
return $response->withJson( return $response->withJson(['statuses' => StatusModel::get()]);
[
'statuses' => StatusModel::get()
]
);
} }
protected function manageValue($request) protected function manageValue($request)
......
...@@ -61,20 +61,20 @@ class StatusModelAbstract ...@@ -61,20 +61,20 @@ class StatusModelAbstract
return $aReturn; return $aReturn;
} }
public static function create(array $aArgs = []) public static function create(array $aArgs)
{ {
ValidatorModel::notEmpty($aArgs, ['id', 'label_status']); ValidatorModel::notEmpty($aArgs, ['id', 'label_status']);
ValidatorModel::stringType($aArgs, ['id', 'label_status']); ValidatorModel::stringType($aArgs, ['id', 'label_status']);
$aReturn = DatabaseModel::insert([ DatabaseModel::insert([
'table' => 'status', 'table' => 'status',
'columnsValues' => $aArgs 'columnsValues' => $aArgs
]); ]);
return $aReturn; return true;
} }
public static function update(array $aArgs = []) public static function update(array $aArgs)
{ {
ValidatorModel::notEmpty($aArgs, ['label_status', 'identifier']); ValidatorModel::notEmpty($aArgs, ['label_status', 'identifier']);
ValidatorModel::intVal($aArgs, ['identifier']); ValidatorModel::intVal($aArgs, ['identifier']);
...@@ -83,27 +83,27 @@ class StatusModelAbstract ...@@ -83,27 +83,27 @@ class StatusModelAbstract
unset($aArgs['id']); unset($aArgs['id']);
unset($aArgs['identifier']); unset($aArgs['identifier']);
$aReturn = DatabaseModel::update([ DatabaseModel::update([
'table' => 'status', 'table' => 'status',
'set' => $aArgs, 'set' => $aArgs,
'where' => ['identifier = ?'], 'where' => ['identifier = ?'],
'data' => [$where['identifier']] 'data' => [$where['identifier']]
]); ]);
return $aReturn; return true;
} }
public static function delete(array $aArgs = []) public static function delete(array $aArgs)
{ {
ValidatorModel::notEmpty($aArgs, ['identifier']); ValidatorModel::notEmpty($aArgs, ['identifier']);
ValidatorModel::intVal($aArgs, ['identifier']); ValidatorModel::intVal($aArgs, ['identifier']);
$aReturn = DatabaseModel::delete([ DatabaseModel::delete([
'table' => 'status', 'table' => 'status',
'where' => ['identifier = ?'], 'where' => ['identifier = ?'],
'data' => [$aArgs['identifier']] 'data' => [$aArgs['identifier']]
]); ]);
return $aReturn; return true;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment