diff --git a/src/app/note/controllers/NoteController.php b/src/app/note/controllers/NoteController.php index a1878a856c27077e20ee7cfb2eaa47fa172860a2..f4fb1ddfe287f6a606d483143195380c46cce0bd 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 bebe8f9b9415460653b78b0988c60eb2b6d67073..57ab1be4130b88cbd9a8338d670bf70179f7b448 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 736d8ba1738070b9ed23128154daaa44ac6b1197..da9765685944ff2b3951c0d61c4f65c4a205e93d 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 4084f0ee4ec131b7b993d57acceb172558c2e4c0..ddf6b1d65953a8b02c58bc0d1de58f3a3a6c82e1 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 f8928be7a31f3d6d163f4bc0ddb8ba678861050f..04442ff20dda417354df18cde70529745651034b 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');