From d9e01634d9a0da9ceb66ecf8d90fb6a3bb95145c Mon Sep 17 00:00:00 2001 From: Vinciane <vinciane.bizet@maarch.org> Date: Thu, 27 Dec 2018 15:33:22 +0100 Subject: [PATCH] FEAT #9207 NoteController correction + add lang --- src/app/note/controllers/NoteController.php | 25 ++++++++++--------- .../note/models/NoteEntityModelAbstract.php | 2 ++ src/core/lang/lang-en.php | 1 + src/core/lang/lang-fr.php | 1 + src/core/lang/lang-nl.php | 1 + 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/app/note/controllers/NoteController.php b/src/app/note/controllers/NoteController.php index a1878a856c2..f4fb1ddfe28 100755 --- a/src/app/note/controllers/NoteController.php +++ b/src/app/note/controllers/NoteController.php @@ -41,16 +41,12 @@ class NoteController { $data = $request->getParams(); - if (!Validator::intVal()->validate($data['identifier']) || !ResController::hasRightByResId(['resId' => $data['identifier'], 'userId' => $GLOBALS['userId']])) { - return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); - } - - //Insert note in notes table and recover last insert ID + //Check data $check = Validator::stringType()->notEmpty()->validate($data['note_text']); $check = $check && Validator::intVal()->notEmpty()->validate($data['identifier']); //correspond to res_id $check = $check && Validator::stringType()->notEmpty()->validate($GLOBALS['userId']); - if(isset($data['entities_chosen'])) { + if (isset($data['entities_chosen'])) { $check = $check && Validator::arrayType()->validate($data['entities_chosen']); } @@ -58,26 +54,31 @@ class NoteController return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } - $data['note_id'] = NoteModel::create($data); + if (!ResController::hasRightByResId(['resId' => $data['identifier'], 'userId' => $GLOBALS['userId']])) { + return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); + } + + //Insert note in notes table and recover last insert ID + $noteId = NoteModel::create($data); //Insert relation note with entities in note_entities_table - if (!empty($data['note_id']) && !empty($data['entities_chosen'])) { + if (!empty($noteId) && !empty($data['entities_chosen'])) { foreach($data['entities_chosen'] as $entity) { - $entity = NoteEntityModel::create( ['item_id' => $entity, 'note_id' => $data['note_id'] ]); + NoteEntityModel::create( ['item_id' => $entity, 'note_id' => $noteId ]); } } //Insert in history HistoryController::add( [ 'tableName' => "notes", - 'recordId' => $data['note_id'], + 'recordId' => $noteId, 'eventType' => "ADD", 'userId' => $GLOBALS['userId'], - 'info' => "Annotation ajoutée (" . $data['note_id'] . ")", + 'info' => _NOTE_ADDED . " (" . $noteId . ")", 'moduleId' => 'notes', 'eventId' => 'noteadd'] ); - return $response->withJson(['noteId' => $data['note_id']]); + return $response->withJson(['noteId' => $noteId]); } } diff --git a/src/app/note/models/NoteEntityModelAbstract.php b/src/app/note/models/NoteEntityModelAbstract.php index bebe8f9b941..57ab1be4130 100644 --- a/src/app/note/models/NoteEntityModelAbstract.php +++ b/src/app/note/models/NoteEntityModelAbstract.php @@ -32,5 +32,7 @@ abstract class NoteEntityModelAbstract 'item_id' => $aArgs['item_id'] ] ]); + + return true; } } diff --git a/src/core/lang/lang-en.php b/src/core/lang/lang-en.php index 736d8ba1738..da976568594 100755 --- a/src/core/lang/lang-en.php +++ b/src/core/lang/lang-en.php @@ -132,6 +132,7 @@ define('_BACK_FROM_VACATION', 'back from vacation'); define('_DOC_DISPLAYING', 'Displaying document'); define('_DOC_ADDED', 'Document added'); define('_ATTACH_DISPLAYING', 'Displaying attachment'); +define('_NOTE_ADDED', 'Note added'); // LISTS define('_DOCUMENTS_LIST_WITH_ATTACHMENTS', 'List with filters and responses'); diff --git a/src/core/lang/lang-fr.php b/src/core/lang/lang-fr.php index 4084f0ee4ec..ddf6b1d6595 100755 --- a/src/core/lang/lang-fr.php +++ b/src/core/lang/lang-fr.php @@ -132,6 +132,7 @@ define('_BACK_FROM_VACATION', 'de retour de son absence'); define('_DOC_DISPLAYING', 'Visualisation du document'); define('_DOC_ADDED', 'Document ajouté'); define('_ATTACH_DISPLAYING', 'Visualisation de la pièce jointe'); +define('_NOTE_ADDED', 'Annotation ajoutée'); // LISTS define('_DOCUMENTS_LIST_WITH_ATTACHMENTS', 'Liste avec filtres et réponses'); diff --git a/src/core/lang/lang-nl.php b/src/core/lang/lang-nl.php index f8928be7a31..04442ff20dd 100644 --- a/src/core/lang/lang-nl.php +++ b/src/core/lang/lang-nl.php @@ -408,3 +408,4 @@ define('_REDACTOR', 'Opsteller'); define('_ASSIGNEE', 'Toegekende persoon'); define('_SENDMAIL_PARAM', '_TO_TRANSLATE'); define('_SENDMAIL_PARAM_DESC', '_TO_TRANSLATE'); +define('_NOTE_ADDED', 'note added _TO_TRANSLATE'); -- GitLab