Skip to content
Snippets Groups Projects
Commit ba397a17 authored by Pegane Nestor's avatar Pegane Nestor
Browse files

FEAT #7475 update status on multiple mail at once

parent 4789f695
Branches
Tags
No related merge requests found
...@@ -124,35 +124,65 @@ class ResController ...@@ -124,35 +124,65 @@ class ResController
$data['historyMessage'] = _UPDATE_STATUS; $data['historyMessage'] = _UPDATE_STATUS;
} }
$check = Validator::stringType()->notEmpty()->validate($data['chrono']) || Validator::intVal()->notEmpty()->validate($data['resId']); $check = Validator::stringType()->notEmpty()->validate($data['chrono']) || Validator::intVal()->notEmpty()->validate($data['resId']) || Validator::stringType()->notEmpty()->validate($data['resId']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['status']); $check = $check && Validator::stringType()->notEmpty()->validate($data['status']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['historyMessage']); $check = $check && Validator::stringType()->notEmpty()->validate($data['historyMessage']);
if (!$check) { if (!$check) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
} }
if (!empty($data['chrono'])) { if(strpos($data['resId'],',')!==false){
$document = ResModel::getResIdByAltIdentifier(['altIdentifier' => $data['chrono']]); $resIds = explode(',', $data['resId']);
} else { foreach($resIds as $resId){
$document = ResModel::getById(['resId' => $data['resId'], 'select' => ['res_id']]); if (!empty($data['chrono'])) {
} $document = ResModel::getResIdByAltIdentifier(['altIdentifier' => $data['chrono']]);
if (empty($document)) { } else {
return $response->withStatus(400)->withJson(['errors' => _DOCUMENT_NOT_FOUND]); $document = ResModel::getById(['resId' => $resId, 'select' => ['res_id']]);
} }
if (!ResController::hasRightByResId(['resId' => $document['res_id'], 'userId' => $GLOBALS['userId']])) { if (empty($document)) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); return $response->withStatus(400)->withJson(['errors' => _DOCUMENT_NOT_FOUND]);
} }
if (!ResController::hasRightByResId(['resId' => $document['res_id'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
ResModel::update(['set' => ['status' => $data['status']], 'where' => ['res_id = ?'], 'data' => [$document['res_id']]]);
ResModel::update(['set' => ['status' => $data['status']], 'where' => ['res_id = ?'], 'data' => [$resId]]);
HistoryController::add([
'tableName' => 'res_letterbox',
'recordId' => $document['res_id'],
'eventType' => 'UP',
'info' => $data['historyMessage'],
'moduleId' => 'apps',
'eventId' => 'resup',
]);
}
} else {
if (!empty($data['chrono'])) {
$document = ResModel::getResIdByAltIdentifier(['altIdentifier' => $data['chrono']]);
} else {
$document = ResModel::getById(['resId' => $data['resId'], 'select' => ['res_id']]);
}
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => _DOCUMENT_NOT_FOUND]);
}
if (!ResController::hasRightByResId(['resId' => $document['res_id'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
HistoryController::add([ ResModel::update(['set' => ['status' => $data['status']], 'where' => ['res_id = ?'], 'data' => [$document['res_id']]]);
'tableName' => 'res_letterbox',
'recordId' => $document['res_id'], HistoryController::add([
'eventType' => 'UP', 'tableName' => 'res_letterbox',
'info' => $data['historyMessage'], 'recordId' => $document['res_id'],
'moduleId' => 'apps', 'eventType' => 'UP',
'eventId' => 'resup', 'info' => $data['historyMessage'],
]); 'moduleId' => 'apps',
'eventId' => 'resup',
]);
}
return $response->withJson(['success' => 'success']); return $response->withJson(['success' => 'success']);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment