diff --git a/modules/notes/notes_ajax_content.php b/modules/notes/notes_ajax_content.php index f6d94fee3d272ba0794c57d8bdc95264023a6b5c..84b17cdfc22d08d911fd12ef052f67a6b18e94b3 100755 --- a/modules/notes/notes_ajax_content.php +++ b/modules/notes/notes_ajax_content.php @@ -234,6 +234,9 @@ switch ($mode) { case 'added': if (strlen(trim($_REQUEST['notes'])) > 0) { //Identifier? + + // var_dump($_REQUEST, $_SESSION, $table ); + // exit; if (empty($identifier)) { $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!','NONE'); $status = 1; diff --git a/rest/index.php b/rest/index.php index c7094e3b3ab087d49aa423bba8b808eb202488a0..d563786b4a6b433aaa115cffd1210c4773ce15e9 100755 --- a/rest/index.php +++ b/rest/index.php @@ -201,6 +201,7 @@ $app->put('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplat //Notes $app->get('/res/{resId}/notes', \Note\controllers\NoteController::class . ':getByResId'); +$app->post('/res/{resId}/notes', \Note\controllers\NoteController::class . ':create'); //Parameters $app->get('/parameters', \Parameter\controllers\ParameterController::class . ':get'); diff --git a/src/app/note/controllers/NoteController.php b/src/app/note/controllers/NoteController.php index a911257c49bb19f5783a09256b16c084bb4b1f94..8fcf3c4a4e114bbf3d1df6142488d24e495e39aa 100755 --- a/src/app/note/controllers/NoteController.php +++ b/src/app/note/controllers/NoteController.php @@ -16,13 +16,15 @@ namespace Note\controllers; use Note\models\NoteModel; +use Note\models\NoteEntitieModel; use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; +use History\controllers\HistoryController; class NoteController { - public function getByResId(Request $request, Response $response, $aArgs) + public function getByResId(Request $request, Response $response) { $check = Validator::intVal()->validate($aArgs['resId']); if (!$check) { @@ -33,4 +35,46 @@ class NoteController return $response->withJson($aNotes); } + + public function create(Request $request, Response $response) + { + $data = $request->getParams(); + + //Insert note in notes table and recover last insert ID + $check_note = Validator::stringType()->notEmpty()->validate($data['note_text']); + $check_note = $check_note && Validator::intVal()->notEmpty()->validate($data['identifier']); //correspond to res_id + $check_note = $check_note && Validator::stringType()->notEmpty()->validate($data['user_id']); + + if (!$check_note) { + return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); + } + + $data['note_id'] = NoteModel::create($data); + + //Insert relation note with entities in note_entities_table + $check_entities = Validator::intVal()->notEmpty()->validate($data['note_id']); + $check_entities = $check_entities && Validator::arrayType()->notEmpty()->validate($data['entities_chosen']); + + if (!$check_entities) { + return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); + } else { + for ($i=0; $i<count($data['entities_chosen']); $i++) + { + $data['note_entities_id'][$i] = NoteEntitieModel::create( ['item_id' => $data['entities_chosen'][$i], 'note_id' => $data['note_id'] ]); + } + } + + //Insert in history + HistoryController::add( [ + 'tableName' => "notes", + 'recordId' => $data['note_id'], + 'eventType' => "ADD", + 'userId' => $data['user_id'], + 'info' => "Annotation ajoutée (" . $data['note_id'] . ")", + 'moduleId' => 'notes', + 'eventId' => 'nateadd'] + ); + + return true; + } } diff --git a/src/app/note/models/NoteEntitieModel.php b/src/app/note/models/NoteEntitieModel.php new file mode 100644 index 0000000000000000000000000000000000000000..6c3c49b11b9382ceaef3d5b8bf36cfd624e4e61c --- /dev/null +++ b/src/app/note/models/NoteEntitieModel.php @@ -0,0 +1,19 @@ +<?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 Note Model + * @author dev@maarch.org + */ + +namespace Note\models; + +class NoteEntitieModel extends NoteEntitieModelAbstract +{ +} \ No newline at end of file diff --git a/src/app/note/models/NoteEntitieModelAbstract.php b/src/app/note/models/NoteEntitieModelAbstract.php new file mode 100644 index 0000000000000000000000000000000000000000..c8ce3d1dc055a417282505e8de555cd2febf7d87 --- /dev/null +++ b/src/app/note/models/NoteEntitieModelAbstract.php @@ -0,0 +1,41 @@ +<?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 Note Model + * @author dev@maarch.org + */ + +namespace Note\models; + +use SrcCore\models\DatabaseModel; +use SrcCore\models\ValidatorModel; + +abstract class NoteEntitieModelAbstract +{ + public static function create(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['note_id', 'item_id']); + ValidatorModel::intVal($aArgs, ['note_id']); + ValidatorModel::stringType($aArgs, ['item_id']); + + $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'notes_entities_id_seq']); + + DatabaseModel::insert([ + 'table' => 'note_entities', + 'columnsValues' => [ + 'id' => $nextSequenceId, + 'note_id' => $aArgs['note_id'], + 'item_id' => $aArgs['item_id'] + ] + ]); + + return $nextSequenceId; + } +} diff --git a/src/app/note/models/NoteModelAbstract.php b/src/app/note/models/NoteModelAbstract.php index 75d7539328e91e198eac9ad48eb9ec26b06c561a..276267f30ba17b0a06694df5994cc7c362b2947a 100755 --- a/src/app/note/models/NoteModelAbstract.php +++ b/src/app/note/models/NoteModelAbstract.php @@ -68,22 +68,26 @@ abstract class NoteModelAbstract public static function create(array $aArgs) { - ValidatorModel::notEmpty($aArgs, ['identifier', 'tablename', 'user_id', 'coll_id', 'note_text']); + //ValidatorModel::notEmpty($aArgs, ['identifier', 'tablename', 'user_id', 'coll_id', 'note_text']); + ValidatorModel::notEmpty($aArgs, ['identifier', 'user_id', 'note_text']); ValidatorModel::intVal($aArgs, ['identifier']); + $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'notes_seq']); + DatabaseModel::insert([ 'table' => 'notes', 'columnsValues' => [ + 'id' => $nextSequenceId, 'identifier' => $aArgs['identifier'], - 'tablename' => $aArgs['tablename'], + 'tablename' => 'res_letterbox', //$aArgs['tablename'], 'user_id' => $aArgs['user_id'], 'date_note' => 'CURRENT_TIMESTAMP', 'note_text' => $aArgs['note_text'], - 'coll_id' => $aArgs['coll_id'], + 'coll_id' => 'letterbox_coll' //$aArgs['coll_id'], ] ]); - return true; + return $nextSequenceId; } public static function getByResId(array $aArgs = [])