diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php index 24552356772d7c8de8a2869381a129c5e1b58c94..744bce3efbf5f3f528c35b46e50e331c25d7a1c8 100755 --- a/src/app/resource/controllers/ResController.php +++ b/src/app/resource/controllers/ResController.php @@ -78,6 +78,10 @@ class ResController ResController::createAdjacentData(['body' => $body, 'resId' => $resId]); + if (!empty($body['followed'])) { + UsersFollowedResourcesController::followResource(['userId' => $GLOBALS['id'], 'resId' => $resId]); + } + if (!empty($body['encodedFile'])) { ConvertPdfController::convert([ 'resId' => $resId, @@ -225,8 +229,8 @@ class ResController $formattedData['attachments'] = $attachments[0]['count']; $followed = UsersFollowedResourcesModel::get([ - 'userId' => $GLOBALS['id'], - 'resId' => $args['resId'] + 'where' => ['user_id = ?', 'res_id = ?'], + 'data' => [$GLOBALS['id'], $args['resId']] ]); $formattedData['followed'] = !empty($followed); @@ -250,6 +254,14 @@ class ResController unset($body['diffusionList']); } + if (isset($body['followed'])) { + if ($body['followed']) { + UsersFollowedResourcesController::followResource(['userId' => $GLOBALS['id'], 'resId' => $args['resId']]); + } else { + UsersFollowedResourcesController::unFollowResource(['userId' => $GLOBALS['id'], 'resId' => $args['resId']]); + } + } + $control = ResController::controlUpdateResource(['body' => $body, 'resId' => $args['resId'], 'isProcessing' => $isProcessing]); if (!empty($control['errors'])) { return $response->withStatus(400)->withJson(['errors' => $control['errors']]); diff --git a/src/app/resource/controllers/UsersFollowedResourcesController.php b/src/app/resource/controllers/UsersFollowedResourcesController.php index 1eccf725caf7d320fa4b7adb86533a65fc17d719..d97130d6f06e8d7d45647fb84629f492f72de7aa 100644 --- a/src/app/resource/controllers/UsersFollowedResourcesController.php +++ b/src/app/resource/controllers/UsersFollowedResourcesController.php @@ -23,20 +23,14 @@ class UsersFollowedResourcesController { public function follow(Request $request, Response $response, array $args) { - UsersFollowedResourcesModel::create([ - 'userId' => $GLOBALS['id'], - 'resId' => $args['resId'] - ]); + UsersFollowedResourcesController::followResource($args); return $response->withStatus(204); } public function unFollow(Request $request, Response $response, array $args) { - UsersFollowedResourcesModel::delete([ - 'userId' => $GLOBALS['id'], - 'resId' => $args['resId'] - ]); + UsersFollowedResourcesController::unFollowResource($args); return $response->withStatus(204); } @@ -50,4 +44,42 @@ class UsersFollowedResourcesController return $response->withJson($followed); } + + public static function followResource(array $args) + { + $following = UsersFollowedResourcesModel::get([ + 'where' => ['user_id = ?', 'res_id = ?'], + 'data' => [$GLOBALS['id'], $args['resId']] + ]); + + if (!empty($following)) { + return true; + } + + UsersFollowedResourcesModel::create([ + 'userId' => $GLOBALS['id'], + 'resId' => $args['resId'] + ]); + + return true; + } + + public static function unFollowResource(array $args) + { + $following = UsersFollowedResourcesModel::get([ + 'where' => ['user_id = ?', 'res_id = ?'], + 'data' => [$GLOBALS['id'], $args['resId']] + ]); + + if (empty($following)) { + return true; + } + + UsersFollowedResourcesModel::delete([ + 'userId' => $GLOBALS['id'], + 'resId' => $args['resId'] + ]); + + return true; + } } diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts index 895ae2b1017b690e59602a071de4eac2fae3257c..e690fca476b327f774e43179b87ff6fcd925e35b 100644 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts @@ -307,6 +307,12 @@ export class IndexingFormComponent implements OnInit { default_value: this.indexingFormId }); } + + arrIndexingModels.push({ + identifier: 'followed', + default_value: this.arrFormControl['mailÂtracking'].value + }); + return arrIndexingModels; } @@ -575,6 +581,7 @@ export class IndexingFormComponent implements OnInit { } }); }); + this.arrFormControl['mailÂtracking'].setValue(data.followed); }), tap(() => { this.currentResourceValues = JSON.parse(JSON.stringify(this.getDatas(false)));