Newer
Older
if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
}
$body['resources'] = array_slice($body['resources'], 0, 500);
if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]);
$signableAttachmentsTypes = [];
$attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML();
foreach ($attachmentsTypes as $key => $type) {
if ($type['sign']) {
$signableAttachmentsTypes[] = $key;
}
}
$resourcesInformations = [];
foreach ($body['resources'] as $resId) {
$resource = ResModel::getById(['resId' => $resId, 'select' => ['alt_identifier']]);
if (empty($resource['alt_identifier'])) {
$resource['alt_identifier'] = _UNDEFINED;
}
$isSignatory = ListInstanceModel::get(['select' => ['signatory', 'requested_signature'], 'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'], 'data' => [$resId, 'VISA_CIRCUIT'], 'orderBy' => ['listinstance_id'], 'limit' => 1]);
if (empty($isSignatory[0])) {
$hasCircuit = ListInstanceModel::get(['select' => [1], 'where' => ['res_id = ?', 'difflist_type = ?'], 'data' => [$resId, 'VISA_CIRCUIT']]);
if (!empty($hasCircuit)) {
$resourcesInformations['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'endedCircuit'];
} else {
$resourcesInformations['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noCircuitAvailable'];
}
} elseif ($isSignatory[0]['requested_signature'] && !$isSignatory[0]['signatory']) {
$resourcesInformations['warning'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'userHasntSigned'];
} else {
$attachments = AttachmentModel::get([
'select' => ['status'],
'where' => ['res_id_master = ?', 'attachment_type in (?)', 'in_signature_book = ?', 'status not in (?)'],
'data' => [$resId, $signableAttachmentsTypes, true, ['OBS', 'DEL', 'FRZ']]
]);
$mailing = false;
if (!empty($attachments)) {
$statuses = array_column($attachments, 'status');
$mailing = in_array('SEND_MASS', $statuses);
}
$resourcesInformations['success'][] = ['res_id' => $resId, 'alt_identifier' => $resource['alt_identifier'], 'mailing' => $mailing];
}
}
return $response->withJson(['resourcesInformations' => $resourcesInformations]);
}
Guillaume Heurtier
committed
public function checkRejectVisa(Request $request, Response $response, array $args)
{
$body = $request->getParsedBody();
if (!Validator::arrayType()->notEmpty()->validate($body['resources'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body resources is empty or not an array']);
}
$errors = ResourceListController::listControl(['groupId' => $args['groupId'], 'userId' => $args['userId'], 'basketId' => $args['basketId'], 'currentUserId' => $GLOBALS['id']]);
if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
}
$body['resources'] = array_slice($body['resources'], 0, 500);
if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]);
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
$signableAttachmentsTypes = [];
$attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML();
foreach ($attachmentsTypes as $key => $type) {
if ($type['sign']) {
$signableAttachmentsTypes[] = $key;
}
}
$resourcesInformation = [];
foreach ($body['resources'] as $resId) {
$resource = ResModel::getById(['resId' => $resId, 'select' => ['alt_identifier']]);
if (empty($resource['alt_identifier'])) {
$resource['alt_identifier'] = _UNDEFINED;
}
$isSignatory = ListInstanceModel::get(['select' => ['signatory', 'requested_signature'], 'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'], 'data' => [$resId, 'VISA_CIRCUIT'], 'orderBy' => ['listinstance_id'], 'limit' => 1]);
if (empty($isSignatory[0])) {
$hasCircuit = ListInstanceModel::get(['select' => [1], 'where' => ['res_id = ?', 'difflist_type = ?'], 'data' => [$resId, 'VISA_CIRCUIT']]);
if (!empty($hasCircuit)) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'endedCircuit'];
} else {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noCircuitAvailable'];
}
} else {
$hasPrevious = ListInstanceModel::get([
'select' => [1],
'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is not null'],
'data' => [$resId, 'VISA_CIRCUIT'],
'orderBy' => ['listinstance_id'],
'limit' => 1
]);
if (!empty($hasPrevious)) {
$resourcesInformation['success'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId];
} else {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'circuitNotStarted'];
}
}
}
return $response->withJson(['resourcesInformations' => $resourcesInformation]);
}
Guillaume Heurtier
committed
public function checkInterruptResetVisa(Request $request, Response $response, array $args)
{
$body = $request->getParsedBody();
if (!Validator::arrayType()->notEmpty()->validate($body['resources'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body resources is empty or not an array']);
}
$errors = ResourceListController::listControl(['groupId' => $args['groupId'], 'userId' => $args['userId'], 'basketId' => $args['basketId'], 'currentUserId' => $GLOBALS['id']]);
if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
}
$body['resources'] = array_slice($body['resources'], 0, 500);
if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]);
Guillaume Heurtier
committed
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
$signableAttachmentsTypes = [];
$attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML();
foreach ($attachmentsTypes as $key => $type) {
if ($type['sign']) {
$signableAttachmentsTypes[] = $key;
}
}
$resourcesInformation = [];
foreach ($body['resources'] as $resId) {
$resource = ResModel::getById(['resId' => $resId, 'select' => ['alt_identifier']]);
if (empty($resource['alt_identifier'])) {
$resource['alt_identifier'] = _UNDEFINED;
}
$isSignatory = ListInstanceModel::get(['select' => ['signatory', 'requested_signature'], 'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'], 'data' => [$resId, 'VISA_CIRCUIT'], 'orderBy' => ['listinstance_id'], 'limit' => 1]);
if (empty($isSignatory[0])) {
$hasCircuit = ListInstanceModel::get(['select' => [1], 'where' => ['res_id = ?', 'difflist_type = ?'], 'data' => [$resId, 'VISA_CIRCUIT']]);
if (!empty($hasCircuit)) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'endedCircuit'];
} else {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noCircuitAvailable'];
}
} else {
$resourcesInformation['success'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId];
}
}
return $response->withJson(['resourcesInformations' => $resourcesInformation]);
}
public function checkValidateParallelOpinion(Request $request, Response $response, array $args)
{
$body = $request->getParsedBody();
if (!Validator::arrayType()->notEmpty()->validate($body['resources'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body resources is empty or not an array']);
}
$errors = ResourceListController::listControl(['groupId' => $args['groupId'], 'userId' => $args['userId'], 'basketId' => $args['basketId'], 'currentUserId' => $GLOBALS['id']]);
if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
}
$body['resources'] = array_slice($body['resources'], 0, 500);
if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]);
$resources = ResModel::get(['select' => ['opinion_limit_date', 'alt_identifier', 'res_id'], 'where' => ['res_id in (?)'], 'data' => [$body['resources']]]);
foreach ($resources as $resource) {
if (empty($resource['opinion_limit_date'])) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resource['res_id'], 'reason' => 'noOpinionLimitDate'];
continue;
}
$opinionLimitDate = new \DateTime($resource['opinion_limit_date']);
$today = new \DateTime('today');
if ($opinionLimitDate < $today) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resource['res_id'], 'reason' => 'opinionLimitDateOutdated'];
$opinionNote = NoteModel::get([
'select' => ['note_text', 'user_id', 'creation_date'],
'where' => ['identifier in (?)', 'note_text like (?)'],
'data' => [$resource['res_id'], '['._TO_AVIS.']%'],
'order_by' => ['creation_date desc'],
'limit' => 1
]);
if (empty($opinionNote)) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resource['res_id'], 'reason' => 'noOpinionNote'];
continue;
}
$note = str_replace('['._TO_AVIS.'] ', '', $opinionNote[0]['note_text']);
$userInfo = UserModel::getLabelledUserById(['id' => $opinionNote[0]['user_id']]);
$resourcesInformation['success'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resource['res_id'], 'avisUserAsk' => $userInfo, 'note' => $note, 'opinionLimitDate' => $resource['opinion_limit_date']];
return $response->withJson(['resourcesInformations' => $resourcesInformation]);
public function checkGiveParallelOpinion(Request $request, Response $response, array $args)
{
$body = $request->getParsedBody();
if (!Validator::arrayType()->notEmpty()->validate($body['resources'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body resources is empty or not an array']);
}
$errors = ResourceListController::listControl(['groupId' => $args['groupId'], 'userId' => $args['userId'], 'basketId' => $args['basketId'], 'currentUserId' => $GLOBALS['id']]);
if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
}
$body['resources'] = array_slice($body['resources'], 0, 500);
if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]);
$currentUser = UserModel::getById(['select' => ['user_id'], 'id' => $GLOBALS['id']]);
$resourcesInformation = [];
foreach ($body['resources'] as $resId) {
$resource = ResModel::getById(['resId' => $resId, 'select' => ['alt_identifier', 'opinion_limit_date']]);
if (empty($resource['alt_identifier'])) {
$resource['alt_identifier'] = _UNDEFINED;
}
if (empty($resource['opinion_limit_date'])) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noOpinionLimitDate'];
$opinionLimitDate = new \DateTime($resource['opinion_limit_date']);
$today = new \DateTime('today');
if ($opinionLimitDate < $today) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'opinionLimitDateOutdated'];
$opinionNote = NoteModel::get([
'select' => ['user_id', 'note_text'],
'where' => ['identifier = ?', "note_text like ?"],
'data' => [$resId, '['._TO_AVIS.']%'],
'order_by' => ['creation_date desc'],
'limit' => 1
]);
if (empty($opinionNote)) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noOpinionNote'];
continue;
}
$isInCircuit = ListInstanceModel::get([
'select' => [1],
'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null', 'item_id = ?', 'item_mode = ?'],
'data' => [$resId, 'entity_id', $currentUser['user_id'], 'avis']
]);
if (empty($isInCircuit)) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'userNotInDiffusionList'];
} else {
$userInfo = UserModel::getLabelledUserById(['id' => $opinionNote[0]['user_id']]);
Guillaume Heurtier
committed
$resourcesInformation['success'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'avisUserAsk' => $userInfo, 'note' => $opinionNote[0]['note_text'], 'opinionLimitDate' => $resource['opinion_limit_date']];
}
}
return $response->withJson(['resourcesInformations' => $resourcesInformation]);
}
public function checkContinueOpinionCircuit(Request $request, Response $response, array $args)
{
$body = $request->getParsedBody();
if (!Validator::arrayType()->notEmpty()->validate($body['resources'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body resources is empty or not an array']);
}
$errors = ResourceListController::listControl(['groupId' => $args['groupId'], 'userId' => $args['userId'], 'basketId' => $args['basketId'], 'currentUserId' => $GLOBALS['id']]);
if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
}
$body['resources'] = array_slice($body['resources'], 0, 500);
if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]);
$resourcesInformation = [];
foreach ($body['resources'] as $resId) {
Guillaume Heurtier
committed
$resource = ResModel::getById(['resId' => $resId, 'select' => ['alt_identifier', 'opinion_limit_date']]);
if (empty($resource['alt_identifier'])) {
$resource['alt_identifier'] = _UNDEFINED;
}
Guillaume Heurtier
committed
if (empty($resource['opinion_limit_date'])) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noOpinionLimitDate'];
Guillaume Heurtier
committed
}
$opinionLimitDate = new \DateTime($resource['opinion_limit_date']);
$today = new \DateTime('today');
if ($opinionLimitDate < $today) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'opinionLimitDateOutdated'];
Guillaume Heurtier
committed
$opinionNote = NoteModel::get([
'select' => ['note_text', 'user_id'],
'where' => ['identifier = ?', "note_text like '[" . _TO_AVIS . "]%'"],
'data' => [$resId]
Guillaume Heurtier
committed
]);
if (empty($opinionNote)) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noOpinionNote'];
continue;
Guillaume Heurtier
committed
}
$isInCircuit = ListInstanceModel::get([
'select' => [1],
'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'],
'data' => [$resId, 'AVIS_CIRCUIT'],
'orderBy' => ['listinstance_id'],
'limit' => 1
]);
$hasCircuit = ListInstanceModel::get(['select' => [1], 'where' => ['res_id = ?', 'difflist_type = ?'], 'data' => [$resId, 'AVIS_CIRCUIT']]);
if (!empty($hasCircuit)) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'endedCircuit'];
} else {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noCircuitAvailable'];
}
} else {
$userInfo = UserModel::getLabelledUserById(['id' => $opinionNote[0]['user_id']]);
Guillaume Heurtier
committed
$resourcesInformation['success'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'avisUserAsk' => $userInfo, 'note' => $opinionNote[0]['note_text'], 'opinionLimitDate' => $resource['opinion_limit_date']];
}
}
return $response->withJson(['resourcesInformations' => $resourcesInformation]);
}
public function isDestinationChanging(Request $request, Response $response, array $args)
{
if (!ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$user = UserModel::getById(['id' => $args['userId'], 'select' => ['user_id']]);
if (empty($user)) {
return $response->withStatus(400)->withJson(['errors' => 'User does not exist']);
}
$changeDestination = true;
$entities = UserEntityModel::get(['select' => ['entity_id'], 'where' => ['user_id = ?'], 'data' => [$user['user_id']]]);
$resource = ResModel::getById(['select' => ['destination'], 'resId' => $args['resId']]);
foreach ($entities as $entity) {
if ($entity['entity_id'] == $resource['destination']) {
$changeDestination = false;
}
}
return $response->withJson(['isDestinationChanging' => $changeDestination]);
}
public static function checkCloseWithFieldsAction(Request $request, Response $response, array $args)
{
$body = $request->getParsedBody();
if (!Validator::arrayType()->notEmpty()->validate($body['resources'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body resources is empty or not an array']);
}
$errors = ResourceListController::listControl(['groupId' => $args['groupId'], 'userId' => $args['userId'], 'basketId' => $args['basketId'], 'currentUserId' => $GLOBALS['id']]);
if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
}
$body['resources'] = array_slice($body['resources'], 0, 500);
if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]);
$action = ActionModel::getById(['id' => $args['actionId'], 'select' => ['parameters']]);
if (empty($action)) {
return $response->withStatus(400)->withJson(['errors' => 'Action does not exist']);
}
$parameters = json_decode($action['parameters'], true);
$actionRequiredFields = $parameters['requiredFields'] ?? [];
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
$canClose = [];
$emptyFields = [];
foreach ($body['resources'] as $resId) {
if (!empty($actionRequiredFields)) {
$resource = ResModel::getById(['resId' => $resId, 'select' => ['model_id', 'custom_fields', 'alt_identifier']]);
$model = $resource['model_id'];
$resourceCustomFields = json_decode($resource['custom_fields'], true);
$modelFields = IndexingModelFieldModel::get([
'select' => ['identifier'],
'where' => ['model_id = ?', "identifier LIKE 'indexingCustomField_%'"],
'data' => [$model]
]);
$modelFields = array_column($modelFields, 'identifier');
$emptyList = [];
foreach ($actionRequiredFields as $actionRequiredField) {
$idCustom = explode("_", $actionRequiredField)[1];
if (in_array($actionRequiredField, $modelFields) && empty($resourceCustomFields[$idCustom])) {
$emptyList[] = $idCustom;
}
}
if (!empty($emptyList)) {
$fieldsList = [];
$customs = CustomFieldModel::get([
'select' => ['label'],
'where' => ['id in (?)'],
'data' => [$emptyList]
]);
foreach ($customs as $custom) {
$fieldsList[] = $custom['label'];
}
$emptyFields[] = [
'chrono' => $resource['alt_identifier'],
'fields' => !empty($fieldsList) ? implode(", ", $fieldsList) : ''
];
} else {
$canClose[] = $resId;
}
} else {
$canClose[] = $resId;
}
}
return $response->withJson(['errors' => $emptyFields, 'success' => $canClose]);
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
public function checkReconcile(Request $request, Response $response, array $args)
{
$body = $request->getParsedBody();
if (!Validator::arrayType()->notEmpty()->validate($body['resources'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body resources is empty or not an array']);
}
$errors = ResourceListController::listControl(['groupId' => $args['groupId'], 'userId' => $args['userId'], 'basketId' => $args['basketId'], 'currentUserId' => $GLOBALS['id']]);
if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
}
$body['resources'] = array_slice($body['resources'], 0, 500);
if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]);
$resourcesInformation = [];
foreach ($body['resources'] as $resId) {
$resource = ResModel::getById(['resId' => $resId, 'select' => ['alt_identifier', 'filename']]);
if (empty($resource['alt_identifier'])) {
$resource['alt_identifier'] = _UNDEFINED;
}
if (empty($resource['filename'])) {
$resourcesInformation['error'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noFilename'];
continue;
}
$targetResource = ResModel::getById(['select' => ['category_id', 'filename'], 'resId' => $body['data']['resId']]);
if (empty($targetResource)) {
return ['errors' => ['Target resource does not exist']];
} elseif ($targetResource['category_id'] == 'outgoing' && empty($targetResource['filename'])) {
return ['errors' => ['Target resource has no file']];
}
$resourcesInformation['success'][] = ['alt_identifier' => $resource['alt_identifier'], 'res_id' => $resId];
}
return $response->withJson(['resourcesInformations' => $resourcesInformation]);
}
private static function getNonLockedResources(array $args)
{
ValidatorModel::notEmpty($args, ['resources', 'userId']);
ValidatorModel::arrayType($args, ['resources']);
ValidatorModel::intVal($args, ['userId']);
$resources = ResModel::get([
'select' => ['res_id', 'locker_user_id', 'locker_time'],
'where' => ['res_id in (?)'],
'data' => [$args['resources']]
]);
$resourcesForProcess = [];
foreach ($resources as $resource) {
$lock = true;
if (empty($resource['locker_user_id'] || empty($resource['locker_time']))) {
$lock = false;
} elseif ($resource['locker_user_id'] == $args['userId']) {
$lock = false;
} elseif (strtotime($resource['locker_time']) < time()) {
$lock = false;
}
if (!$lock) {
$resourcesForProcess[] = $resource['res_id'];
}
}