Skip to content
Snippets Groups Projects
Commit be7d9fe0 authored by Giovannoni Laurent's avatar Giovannoni Laurent
Browse files

Merge branch 'lgi-feat-admin-status' into develop

parents 2fce8288 5c1ee6f1
No related branches found
No related tags found
No related merge requests found
{
"autoload": {
"psr-4": {
"Core\\": "core/",
"Apps\\": "apps/maarch_entreprise/",
"Visa\\": "modules/visa/"
}
},
"require": {
"slim/slim": "^3.7",
"respect/validation": "^1.1"
}
}
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Status Controller
* @author dev@maarch.org
* @ingroup core
*/
namespace Core\Controllers;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Respect\Validation\Validator;
require_once 'core/Models/StatusModel.php';
class StatusController
{
public function getList(RequestInterface $request, ResponseInterface $response)
{
$status = \StatusModel::getList();
$datas = [
[
'status' => $status,
]
];
return $response->withJson($datas);
}
public function getById(RequestInterface $request, ResponseInterface $response, $aArgs)
{
if (isset($aArgs['id'])) {
$id = $aArgs['id'];
$status = \StatusModel::getById([
'id' => $id
]);
} else {
return $response
->withStatus(500)
->withJson(['errors' => _ID . ' ' . _IS_EMPTY]);
}
$datas = [
[
'status' => $status,
]
];
return $response->withJson($datas);
}
public function create(RequestInterface $request, ResponseInterface $response, $aArgs)
{
$errors = [];
$errors = $this->control($request, 'create');
if (!empty($errors)) {
return $response
->withStatus(500)
->withJson(['errors' => $errors]);
}
$aArgs = $request->getQueryParams();
$return = \StatusModel::create($aArgs);
if ($return) {
$id = $aArgs['id'];
$status = \StatusModel::getById([
'id' => $id
]);
} else {
return $response
->withStatus(500)
->withJson(['errors' => _NOT_CREATE]);
}
$datas = [
[
'status' => $status,
]
];
return $response->withJson($datas);
}
public function update(RequestInterface $request, ResponseInterface $response, $aArgs)
{
$errors = [];
$errors = $this->control($request, 'update');
if (!empty($errors)) {
return $response
->withStatus(500)
->withJson(['errors' => $errors]);
}
$aArgs = $request->getQueryParams();
$return = \StatusModel::update($aArgs);
if ($return) {
$id = $aArgs['id'];
$status = \StatusModel::getById([
'id' => $id
]);
} else {
return $response
->withStatus(500)
->withJson(['errors' => _NOT_UPDATE]);
}
$datas = [
[
'status' => $status,
]
];
return $response->withJson($datas);
}
public function delete(RequestInterface $request, ResponseInterface $response, $aArgs)
{
if (isset($aArgs['id'])) {
$id = $aArgs['id'];
$status = \StatusModel::delete([
'id' => $id
]);
} else {
return $response
->withStatus(500)
->withJson(['errors' => _NOT_DELETE]);
}
$datas = [
[
'status' => $status,
]
];
return $response->withJson($datas);
}
protected function control($request, $mode)
{
$errors = [];
if($mode == 'update') {
$status = \StatusModel::getById([
'id' => $request->getParam('id')
]);
if (empty($status)) {
array_push(
$errors,
_ID . ' ' . $request->getParam('id') . ' ' . _NOT_EXISTS
);
}
}
if (!Validator::notEmpty()->validate($request->getParam('id'))) {
array_push($errors, _ID . ' ' . _IS_EMPTY);
} elseif($mode == 'create') {
$status = \StatusModel::getById([
'id' => $request->getParam('id')
]);
if (!empty($status)) {
array_push(
$errors,
_ID . ' ' . $status[0]['id'] . ' ' . _ALREADY_EXISTS
);
}
}
if (!Validator::regex('/^[\w.-]*$/')->validate($request->getParam('id'))) {
array_push($errors, _ID . ' ' . _NOT . ' ' . _VALID);
}
if (!Validator::notEmpty()->validate($request->getParam('label_status'))) {
array_push($errors, _LABEL_STATUS . ' ' . _IS_EMPTY);
}
if (
Validator::notEmpty()
->validate($request->getParam('is_system')) &&
!Validator::contains('Y')
->validate($request->getParam('is_system')) &&
!Validator::contains('N')
->validate($request->getParam('is_system'))
) {
array_push($errors, _IS_SYSTEM . ' ' . _NOT . ' ' . _VALID);
}
if (
Validator::notEmpty()
->validate($request->getParam('is_folder_status')) &&
!Validator::contains('Y')
->validate($request->getParam('is_folder_status')) &&
!Validator::contains('N')
->validate($request->getParam('is_folder_status'))
) {
array_push($errors, _IS_FOLDER_STATUS . ' ' . _NOT . ' ' . _VALID);
}
if (
Validator::notEmpty()
->validate($request->getParam('img_filename')) &&
(!Validator::regex('/^[\w-.]+$/')
->validate($request->getParam('img_filename')) ||
!Validator::length(null, 255)
->validate($request->getParam('img_filename')))
) {
array_push($errors, _IMG_FILENAME . ' ' . _NOT . ' ' . _VALID);
}
if (
Validator::notEmpty()
->validate($request->getParam('maarch_module')) &&
!Validator::length(null, 255)
->validate($request->getParam('maarch_module'))
) {
array_push($errors, _MAARCH_MODULE . ' ' . _NOT . ' ' . _VALID);
}
if (
Validator::notEmpty()
->validate($request->getParam('can_be_searched')) &&
!Validator::contains('Y')
->validate($request->getParam('can_be_searched')) &&
!Validator::contains('N')
->validate($request->getParam('can_be_searched'))
) {
array_push($errors, _CAN_BE_SEARCHED . ' ' . _NOT . ' ' . _VALID);
}
if (
Validator::notEmpty()
->validate($request->getParam('can_be_modified')) &&
!Validator::contains('Y')
->validate($request->getParam('can_be_modified')) &&
!Validator::contains('N')
->validate($request->getParam('can_be_modified'))
) {
array_push($errors, _CAN_BE_MODIFIED . ' ' . _NOT . ' ' . _VALID);
}
return $errors;
}
}
\ No newline at end of file
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
require_once 'core/Models/StatusModelAbstract.php';
class StatusModel extends StatusModelAbstract
{
// Do your stuff in this class
}
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
require_once 'apps/maarch_entreprise/services/Table.php';
class StatusModelAbstract extends Apps_Table_Service
{
public static function getList()
{
$aReturn = static::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['status'],
]);
return $aReturn;
}
public static function getById(array $aArgs = [])
{
static::checkRequired($aArgs, ['id']);
static::checkString($aArgs, ['id']);
$aReturn = static::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['status'],
'where' => ['id = ?'],
'data' => [$aArgs['id']]
]);
return $aReturn;
}
public static function create(array $aArgs = [])
{
static::checkRequired($aArgs, ['id']);
static::checkString($aArgs, ['id']);
$aReturn = static::insertInto($aArgs, 'status');
return $aReturn;
}
public static function update(array $aArgs = [])
{
static::checkRequired($aArgs, ['id']);
static::checkString($aArgs, ['id']);
$where['id'] = $aArgs['id'];
$aReturn = static::updateTable(
$aArgs,
'status',
$where
);
return $aReturn;
}
public static function delete(array $aArgs = [])
{
static::checkRequired($aArgs, ['id']);
static::checkString($aArgs, ['id']);
$aReturn = static::deleteFrom([
'table' => 'status',
'where' => ['id = ?'],
'data' => [$aArgs['id']]
]);
return $aReturn;
}
}
<?php <?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Maarch rest root file
*
* @file
* @author dev@maarch.org
* @date $date$
* @version $Revision$
* @ingroup core
*/
require '../vendor/autoload.php'; require '../vendor/autoload.php';
header('Content-Type: text/html; charset=utf-8'); header('Content-Type: text/html; charset=utf-8');
...@@ -57,6 +74,13 @@ $app = new \Slim\App([ ...@@ -57,6 +74,13 @@ $app = new \Slim\App([
] ]
]); ]);
//status
$app->get('/status', \Core\Controllers\StatusController::class . ':getList');
$app->get('/status/{id}', \Core\Controllers\StatusController::class . ':getById');
$app->post('/status', \Core\Controllers\StatusController::class . ':create');
$app->put('/status', \Core\Controllers\StatusController::class . ':update');
$app->delete('/status/{id}', \Core\Controllers\StatusController::class . ':delete');
$app->get('/signatureBook/{resId}', \Visa\Controllers\VisaController::class . ':getSignatureBook'); $app->get('/signatureBook/{resId}', \Visa\Controllers\VisaController::class . ':getSignatureBook');
$app->run(); $app->run();
\ No newline at end of file
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