Skip to content
Snippets Groups Projects
Commit 79f8b54c authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #11403 TIME 1:30 follow/un-follow resource in process and index

parent 5da54118
No related branches found
No related tags found
No related merge requests found
...@@ -78,6 +78,10 @@ class ResController ...@@ -78,6 +78,10 @@ class ResController
ResController::createAdjacentData(['body' => $body, 'resId' => $resId]); ResController::createAdjacentData(['body' => $body, 'resId' => $resId]);
if (!empty($body['followed'])) {
UsersFollowedResourcesController::followResource(['userId' => $GLOBALS['id'], 'resId' => $resId]);
}
if (!empty($body['encodedFile'])) { if (!empty($body['encodedFile'])) {
ConvertPdfController::convert([ ConvertPdfController::convert([
'resId' => $resId, 'resId' => $resId,
...@@ -225,8 +229,8 @@ class ResController ...@@ -225,8 +229,8 @@ class ResController
$formattedData['attachments'] = $attachments[0]['count']; $formattedData['attachments'] = $attachments[0]['count'];
$followed = UsersFollowedResourcesModel::get([ $followed = UsersFollowedResourcesModel::get([
'userId' => $GLOBALS['id'], 'where' => ['user_id = ?', 'res_id = ?'],
'resId' => $args['resId'] 'data' => [$GLOBALS['id'], $args['resId']]
]); ]);
$formattedData['followed'] = !empty($followed); $formattedData['followed'] = !empty($followed);
...@@ -250,6 +254,14 @@ class ResController ...@@ -250,6 +254,14 @@ class ResController
unset($body['diffusionList']); 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]); $control = ResController::controlUpdateResource(['body' => $body, 'resId' => $args['resId'], 'isProcessing' => $isProcessing]);
if (!empty($control['errors'])) { if (!empty($control['errors'])) {
return $response->withStatus(400)->withJson(['errors' => $control['errors']]); return $response->withStatus(400)->withJson(['errors' => $control['errors']]);
......
...@@ -23,20 +23,14 @@ class UsersFollowedResourcesController ...@@ -23,20 +23,14 @@ class UsersFollowedResourcesController
{ {
public function follow(Request $request, Response $response, array $args) public function follow(Request $request, Response $response, array $args)
{ {
UsersFollowedResourcesModel::create([ UsersFollowedResourcesController::followResource($args);
'userId' => $GLOBALS['id'],
'resId' => $args['resId']
]);
return $response->withStatus(204); return $response->withStatus(204);
} }
public function unFollow(Request $request, Response $response, array $args) public function unFollow(Request $request, Response $response, array $args)
{ {
UsersFollowedResourcesModel::delete([ UsersFollowedResourcesController::unFollowResource($args);
'userId' => $GLOBALS['id'],
'resId' => $args['resId']
]);
return $response->withStatus(204); return $response->withStatus(204);
} }
...@@ -50,4 +44,42 @@ class UsersFollowedResourcesController ...@@ -50,4 +44,42 @@ class UsersFollowedResourcesController
return $response->withJson($followed); 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;
}
} }
...@@ -307,6 +307,12 @@ export class IndexingFormComponent implements OnInit { ...@@ -307,6 +307,12 @@ export class IndexingFormComponent implements OnInit {
default_value: this.indexingFormId default_value: this.indexingFormId
}); });
} }
arrIndexingModels.push({
identifier: 'followed',
default_value: this.arrFormControl['mail­tracking'].value
});
return arrIndexingModels; return arrIndexingModels;
} }
...@@ -575,6 +581,7 @@ export class IndexingFormComponent implements OnInit { ...@@ -575,6 +581,7 @@ export class IndexingFormComponent implements OnInit {
} }
}); });
}); });
this.arrFormControl['mail­tracking'].setValue(data.followed);
}), }),
tap(() => { tap(() => {
this.currentResourceValues = JSON.parse(JSON.stringify(this.getDatas(false))); this.currentResourceValues = JSON.parse(JSON.stringify(this.getDatas(false)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment