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

FEAT #11691 TIME 0:35 Get attachments count + refactoring

parent c194faee
No related branches found
No related tags found
No related merge requests found
...@@ -279,7 +279,7 @@ class AttachmentController ...@@ -279,7 +279,7 @@ class AttachmentController
$attachments = AttachmentModel::get([ $attachments = AttachmentModel::get([
'select' => [ 'select' => [
'res_id as "resId"', 'identifier as chrono', 'title', 'typist', 'modified_by as "modifiedBy"', 'creation_date as "creationDate"', 'modification_date as "modificationDate"', 'res_id as "resId"', 'identifier as chrono', 'title', 'typist', 'modified_by as "modifiedBy"', 'creation_date as "creationDate"', 'modification_date as "modificationDate"',
'relation', 'status', 'attachment_type as type', 'origin_id as "originId"', 'in_signature_book as "inSignatureBook"', 'in_send_attach as "inSendAttach"' 'relation', 'status', 'attachment_type as type', 'in_signature_book as "inSignatureBook"', 'in_send_attach as "inSendAttach"'
], ],
'where' => ['res_id_master = ?', 'status not in (?)', 'attachment_type not in (?)'], 'where' => ['res_id_master = ?', 'status not in (?)', 'attachment_type not in (?)'],
'data' => [$args['resId'], ['DEL', 'OBS'], $excludeAttachmentTypes], 'data' => [$args['resId'], ['DEL', 'OBS'], $excludeAttachmentTypes],
...@@ -301,17 +301,6 @@ class AttachmentController ...@@ -301,17 +301,6 @@ class AttachmentController
$attachments[$key]['typeLabel'] = $attachmentsTypes[$attachment['type']]['label']; $attachments[$key]['typeLabel'] = $attachmentsTypes[$attachment['type']]['label'];
} }
$oldVersions = [];
if (!empty($attachment['originId'])) {
$oldVersions = AttachmentModel::get([
'select' => ['res_id as "resId"'],
'where' => ['(origin_id = ? OR res_id = ?)', 'res_id != ?', 'status not in (?)', 'attachment_type not in (?)'],
'data' => [$attachment['originId'], $attachment['originId'], $attachment['resId'], ['DEL'], $excludeAttachmentTypes],
'orderBy' => ['relation DESC']
]);
}
$attachments[$key]['versions'] = $oldVersions;
if ($attachment['status'] == 'SIGN') { if ($attachment['status'] == 'SIGN') {
$signedResponse = AttachmentModel::get([ $signedResponse = AttachmentModel::get([
'select' => ['creation_date', 'typist'], 'select' => ['creation_date', 'typist'],
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
namespace Resource\controllers; namespace Resource\controllers;
use AcknowledgementReceipt\models\AcknowledgementReceiptModel; use AcknowledgementReceipt\models\AcknowledgementReceiptModel;
use Attachment\models\AttachmentModel;
use Basket\models\BasketModel; use Basket\models\BasketModel;
use Basket\models\GroupBasketModel; use Basket\models\GroupBasketModel;
use Basket\models\RedirectBasketModel; use Basket\models\RedirectBasketModel;
...@@ -186,6 +187,9 @@ class ResController ...@@ -186,6 +187,9 @@ class ResController
$formattedData['priorityColor'] = $priority['color']; $formattedData['priorityColor'] = $priority['color'];
} }
$attachments = AttachmentModel::get(['select' => ['count(1)'], 'where' => ['res_id_master = ?', 'status in (?)'], 'data' => [$args['resId'], ['TRA', 'A_TRA', 'FRZ']]]);
$formattedData['attachments'] = $attachments[0]['count'];
return $response->withJson($formattedData); return $response->withJson($formattedData);
} }
......
...@@ -50,7 +50,7 @@ class UserControllerTest extends TestCase ...@@ -50,7 +50,7 @@ class UserControllerTest extends TestCase
$response = $userController->create($fullRequest, new \Slim\Http\Response()); $response = $userController->create($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody()); $responseBody = json_decode((string)$response->getBody());
self::$id = $responseBody->user->id; self::$id = $responseBody->id;
$this->assertInternalType('int', self::$id); $this->assertInternalType('int', self::$id);
...@@ -88,7 +88,8 @@ class UserControllerTest extends TestCase ...@@ -88,7 +88,8 @@ class UserControllerTest extends TestCase
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $userController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); $response = $userController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]);
$responseBody = json_decode((string)$response->getBody()); $this->assertSame(204, $response->getStatusCode());
// READ // READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
......
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