diff --git a/composer.json b/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..d26c3313e0ca6ab5d1ff77828ca230e0c9a87187 --- /dev/null +++ b/composer.json @@ -0,0 +1,13 @@ +{ + "autoload": { + "psr-4": { + "Core\\": "core/", + "Apps\\": "apps/maarch_entreprise/", + "Visa\\": "modules/visa/" + } + }, + "require": { + "slim/slim": "^3.7", + "respect/validation": "^1.1" + } +} diff --git a/core/Controllers/StatusController.php b/core/Controllers/StatusController.php new file mode 100644 index 0000000000000000000000000000000000000000..06e3f1932003dca34b469f98f8ee72e01f19b23a --- /dev/null +++ b/core/Controllers/StatusController.php @@ -0,0 +1,267 @@ +<?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 diff --git a/core/Models/StatusModel.php b/core/Models/StatusModel.php new file mode 100644 index 0000000000000000000000000000000000000000..8b6044bbcd2d2e51acca12db379af0cad26b51e3 --- /dev/null +++ b/core/Models/StatusModel.php @@ -0,0 +1,15 @@ +<?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 +} diff --git a/core/Models/StatusModelAbstract.php b/core/Models/StatusModelAbstract.php new file mode 100644 index 0000000000000000000000000000000000000000..53fe8da172035c29343a7a259abd44ab1e719e33 --- /dev/null +++ b/core/Models/StatusModelAbstract.php @@ -0,0 +1,79 @@ +<?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; + } +} diff --git a/rest/index.php b/rest/index.php index ea707c6254fea78f5aebbeb647f6ce37a2ddb571..99740c90a1d5432d8aeeb0fc681f2962ca2eaa1a 100644 --- a/rest/index.php +++ b/rest/index.php @@ -1,4 +1,21 @@ <?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'; header('Content-Type: text/html; charset=utf-8'); @@ -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->run(); \ No newline at end of file +$app->run();