Skip to content
Snippets Groups Projects
Verified Commit 0145c8b0 authored by Damien's avatar Damien
Browse files

FEAT #12074 TIME 0:40 Get resource by id

parent 9de1a197
No related branches found
No related tags found
No related merge requests found
......@@ -315,6 +315,7 @@ $app->put('/reports/groups/{groupId}', \Report\controllers\ReportController::cla
//Resources
$app->post('/resources', \Resource\controllers\ResController::class . ':create');
$app->get('/resources/{resId}', \Resource\controllers\ResController::class . ':getById');
$app->get('/resources/{resId}/content', \Resource\controllers\ResController::class . ':getFileContent');
$app->get('/resources/{resId}/originalContent', \Resource\controllers\ResController::class . ':getOriginalFileContent');
$app->get('/resources/{resId}/thumbnail', \Resource\controllers\ResController::class . ':getThumbnailContent');
......
......@@ -107,6 +107,66 @@ class ResController
return $response->withJson(['resId' => $resId]);
}
public function getById(Request $request, Response $response, array $args)
{
if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$document = ResModel::getById([
'select' => [
'model_id', 'category_id', 'type_id', 'subject', 'alt_identifier', 'typist',
'status', 'destination', 'initiator', 'confidentiality', 'doc_date', 'admission_date',
'departure_date', 'process_limit_date', 'priority', 'barcode', 'creation_date', 'modification_date'
],
'resId' => $args['resId']
]);
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']);
}
$formattedData = [
'modelId' => $document['model_id'],
'categoryId' => $document['category_id'],
'doctype' => $document['type_id'],
'subject' => $document['subject'],
'chrono' => $document['alt_identifier'],
'typist' => $document['typist'],
'labelledTypist' => UserModel::getLabelledUserById(['id' => $document['typist']]),
'status' => $document['status'],
'destination' => $document['destination'],
'initiator' => $document['initiator'],
'confidentiality' => $document['confidentiality'] == 'Y',
'documentDate' => $document['doc_date'],
'arrivalDate' => $document['admission_date'],
'departureDate' => $document['departure_date'],
'processLimitDate' => $document['process_limit_date'],
'priority' => $document['priority'],
'barcode' => $document['barcode'],
'creationDate' => $document['creation_date'],
'modificationDate' => $document['modification_date']
];
if (!empty($formattedData['destination'])) {
$entity = EntityModel::getByEntityId(['entityId' => $formattedData['destination'], 'select' => ['entity_label']]);
$formattedData['labelledDestination'] = $entity['entity_label'];
}
if (!empty($formattedData['initiator'])) {
$entity = EntityModel::getByEntityId(['entityId' => $formattedData['initiator'], 'select' => ['entity_label']]);
$formattedData['labelledInitiator'] = $entity['entity_label'];
}
if (!empty($formattedData['status'])) {
$status = StatusModel::getById(['id' => $formattedData['status'], 'select' => ['label_status']]);
$formattedData['labelledStatus'] = $status['label_status'];
}
if (!empty($formattedData['priority'])) {
$priority = PriorityModel::getById(['id' => $formattedData['priority'], 'select' => ['label']]);
$formattedData['labelledPriority'] = $priority['label'];
}
return $response->withJson($formattedData);
}
public function updateStatus(Request $request, Response $response)
{
$data = $request->getParams();
......
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