Skip to content
Snippets Groups Projects
Commit a1c81d09 authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #10633 TIME 0:15 back send doc to recommendation

parent f513b763
No related branches found
No related tags found
No related merge requests found
......@@ -576,93 +576,81 @@ class ActionMethodController
public static function sendToParallelOpinion(array $args)
{
$currentUser = UserModel::getById(['select' => ['user_id'], 'id' => $args['userId']]);
if (empty($args['resId'])) {
return ['errors' => ['resId is empty']];
}
DatabaseModel::beginTransaction();
if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) {
return ['errors' => ['Document out of perimeter']];
}
foreach ($args['data'] as $ListInstanceByRes) {
if (empty($ListInstanceByRes['resId'])) {
DatabaseModel::rollbackTransaction();
return ['errors' => ['resId is empty']];
}
if (empty($args['data']['opinionLimitDate'])) {
return ["errors" => ["Opinion limit date is missing"]];
}
if (!Validator::intVal()->validate($ListInstanceByRes['resId']) || !ResController::hasRightByResId(['resId' => [$ListInstanceByRes['resId']], 'userId' => $GLOBALS['id']])) {
DatabaseModel::rollbackTransaction();
return ['errors' => ['Document out of perimeter']];
}
$opinionLimitDate = new \DateTime($args['data']['opinionLimitDate']);
$today = new \DateTime('today');
if ($opinionLimitDate < $today) {
return ['errors' => "Opinion limit date is not a valid date"];
}
if (empty($ListInstanceByRes['listInstances'])) {
return ['errors' => ['listInstances is empty']];
}
if (empty($args['data']['opinionCircuit'])) {
return ['errors' => "opinionCircuit is empty"];
}
$listInstances = ListInstanceModel::get([
'select' => ['*'],
'where' => ['res_id = ?', 'difflist_type = ?', 'item_mode in (?)'],
'data' => [$ListInstanceByRes['resId'], 'entity_id', ['avis', 'avis_copy', 'avis_info']]
]);
ListInstanceModel::delete([
'where' => ['res_id = ?', 'difflist_type = ?', 'item_mode in (?)'],
'data' => [$ListInstanceByRes['resId'], 'entity_id', ['avis', 'avis_copy', 'avis_info']]
]);
foreach ($args['data']['opinionCircuit'] as $instance) {
if (!in_array($instance['item_mode'], ['avis', 'avis_copy', 'avis_info'])) {
return ['errors' => ['item_mode is different from avis, avis_copy or avis_info']];
}
foreach ($ListInstanceByRes['listInstances'] as $instance) {
if (!in_array($instance['item_mode'], ['avis', 'avis_copy', 'avis_info'])) {
return ['errors' => ['item_mode is different from avis, avis_copy or avis_info']];
$listControl = ['item_id', 'item_type'];
foreach ($listControl as $itemControl) {
if (empty($instance[$itemControl])) {
return ['errors' => ["ListInstance {$itemControl} is not set or empty"]];
}
}
}
foreach ($ListInstanceByRes['listInstances'] as $key => $instance) {
$listControl = ['item_id', 'item_type', 'item_mode'];
foreach ($listControl as $itemControl) {
if (empty($instance[$itemControl])) {
return ['errors' => ["ListInstance {$itemControl} is not set or empty"]];
}
}
$currentUser = UserModel::getById(['select' => ['user_id'], 'id' => $args['userId']]);
if (in_array($instance['item_type'], ['user_id', 'user'])) {
if ($instance['item_type'] == 'user_id') {
$user = UserModel::getByLogin(['login' => $instance['item_id'], 'select' => ['id']]);
} else {
$user = UserModel::getById(['id' => $instance['item_id'], 'select' => ['id', 'user_id']]);
$instance['item_id'] = $user['user_id'] ?? null;
$instance['item_type'] = 'user_id';
}
if (empty($user)) {
DatabaseModel::rollbackTransaction();
return ['errors' => ['User not found']];
}
} else {
DatabaseModel::beginTransaction();
ListInstanceModel::delete([
'where' => ['res_id = ?', 'difflist_type = ?', 'item_mode in (?)'],
'data' => [$args['resId'], 'entity_id', ['avis', 'avis_copy', 'avis_info']]
]);
foreach ($args['data']['opinionCircuit'] as $key => $instance) {
if (in_array($instance['item_type'], ['user_id', 'user'])) {
$user = UserModel::getById(['id' => $instance['item_id'], 'select' => ['id', 'user_id']]);
$instance['item_id'] = $user['user_id'] ?? null;
$instance['item_type'] = 'user_id';
if (empty($user)) {
DatabaseModel::rollbackTransaction();
return ['errors' => ['item_type does not exist']];
return ['errors' => ['User not found']];
}
ListInstanceModel::create([
'res_id' => $ListInstanceByRes['resId'],
'sequence' => $key,
'item_id' => $instance['item_id'],
'item_type' => $instance['item_type'],
'item_mode' => $instance['item_mode'],
'added_by_user' => $currentUser['user_id'],
'difflist_type' => 'entity_id',
'process_date' => null,
'process_comment' => null,
'requested_signature' => false,
'viewed' => empty($instance['viewed']) ? 0 : $instance['viewed']
]);
} else {
DatabaseModel::rollbackTransaction();
return ['errors' => ['item_type does not exist']];
}
}
DatabaseModel::commitTransaction();
if (empty($args['data']['opinionLimitDate'])) {
return ["errors" => ["Opinion limit date is missing"]];
ListInstanceModel::create([
'res_id' => $args['resId'],
'sequence' => $key,
'item_id' => $instance['item_id'],
'item_type' => $instance['item_type'],
'item_mode' => $instance['item_mode'],
'added_by_user' => $currentUser['user_id'],
'difflist_type' => 'entity_id',
'process_date' => null,
'process_comment' => null,
'requested_signature' => false,
'viewed' => empty($instance['viewed']) ? 0 : $instance['viewed']
]);
}
$opinionLimitDate = new \DateTime($args['data']['opinionLimitDate']);
$today = new \DateTime('today');
if ($opinionLimitDate < $today) {
return ['errors' => "Opinion limit date is not a valid date"];
}
DatabaseModel::commitTransaction();
ResModel::update([
'set' => ['opinion_limit_date' => $args['data']['opinionLimitDate']],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment