From a2ff244904ff6234189ef5b02cd0552f4a1fb431 Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Fri, 30 Jun 2017 16:54:49 +0100 Subject: [PATCH] FEAT #5661 start status administration MVC --- .../status-administration.component.html | 4 +- core/Controllers/StatusController.php | 38 +++++++++++-------- core/Models/StatusModelAbstract.php | 4 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/apps/maarch_entreprise/Views/status-administration.component.html b/apps/maarch_entreprise/Views/status-administration.component.html index a6e3ebf811a..49b19727b74 100644 --- a/apps/maarch_entreprise/Views/status-administration.component.html +++ b/apps/maarch_entreprise/Views/status-administration.component.html @@ -46,7 +46,7 @@ </span> <label class="form-control" for="can_be_searched">{{lang.can_be_searched}}</label> <span class="input-group-addon"> - <input [(ngModel)]="status.can_be_searched" [checked]="status.can_be_searched == 'Y'" name="can_be_searched" id="can_be_searched" type="checkbox"> + <input [(ngModel)]="status.can_be_searched" name="can_be_searched" id="can_be_searched" type="checkbox"> </span> </div> </div> @@ -57,7 +57,7 @@ </span> <label class="form-control" for="can_be_modified">{{lang.can_be_modified}}</label> <span class="input-group-addon"> - <input [(ngModel)]="status.can_be_modified" [checked]="status.can_be_modified == 'Y'" type="checkbox" name="can_be_modified" id="can_be_modified"> + <input [(ngModel)]="status.can_be_modified" type="checkbox" name="can_be_modified" id="can_be_modified"> </span> </div> </div> diff --git a/core/Controllers/StatusController.php b/core/Controllers/StatusController.php index 222f5991ce8..15b113bf93c 100644 --- a/core/Controllers/StatusController.php +++ b/core/Controllers/StatusController.php @@ -70,7 +70,11 @@ class StatusController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $this->control($request, 'create'); + $errors = $this->control($request, 'create'); + + if (!empty($errors)) { + return $response->withStatus(500)->withJson(['errors' => $errors]); + } $aArgs = $request->getParams(); @@ -94,7 +98,11 @@ class StatusController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $this->control($request, 'update'); + $errors = $this->control($request, 'update'); + + if (!empty($errors)) { + return $response->withStatus(500)->withJson(['errors' => $errors]); + } $aArgs = $request->getParams(); @@ -166,59 +174,57 @@ class StatusController } if (!Validator::regex('/^[\w.-]*$/')->validate($request->getParam('id')) || - !Validator::length(null, 10)->validate($request->getParam('id'))) { - array_push($errors, _ID . ' ' . _NOT . ' ' . _VALID); + !Validator::length(1, 10)->validate($request->getParam('id'))) { + array_push($errors, 'id not valid'); } if (!Validator::notEmpty()->validate($request->getParam('label_status')) || - !Validator::length(null, 50)->validate($request->getParam('label_status'))) { - array_push($errors, _LABEL_STATUS . ' ' . _IS_EMPTY); + !Validator::length(1, 50)->validate($request->getParam('label_status'))) { + array_push($errors, 'label_status not valid'); } 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); + 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); + 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'))) + !Validator::length(1, 255)->validate($request->getParam('img_filename'))) ) { - array_push($errors, _IMG_FILENAME . ' ' . _NOT . ' ' . _VALID); + 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); + 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); + 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); + array_push($errors, 'can_be_modified'); } - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } + return $errors; } } diff --git a/core/Models/StatusModelAbstract.php b/core/Models/StatusModelAbstract.php index 608453954ff..d7e81c83b90 100644 --- a/core/Models/StatusModelAbstract.php +++ b/core/Models/StatusModelAbstract.php @@ -51,7 +51,7 @@ class StatusModelAbstract extends \Apps_Table_Service public static function create(array $aArgs = []) { - static::checkRequired($aArgs, ['id']); + static::checkRequired($aArgs, ['id', 'label_status']); static::checkString($aArgs, ['id']); $aReturn = static::insertInto($aArgs, 'status'); @@ -61,7 +61,7 @@ class StatusModelAbstract extends \Apps_Table_Service public static function update(array $aArgs = []) { - static::checkRequired($aArgs, ['id']); + static::checkRequired($aArgs, ['id', 'label_status']); static::checkString($aArgs, ['id']); $where['id'] = $aArgs['id']; -- GitLab