Skip to content
Snippets Groups Projects
Commit 306fadb2 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #12072 TIME 0:45 get shippings by res id

parent d8069841
No related branches found
No related tags found
No related merge requests found
......@@ -363,6 +363,7 @@ $app->post('/resources/{resId}/linkedResources', \Resource\controllers\LinkContr
$app->delete('/resources/{resId}/linkedResources/{id}', \Resource\controllers\LinkController::class . ':unlinkResources');
$app->put('/resources/{resId}/unsign', \SignatureBook\controllers\SignatureBookController::class . ':unsignResource');
$app->get('/resources/{resId}/acknowledgementReceipts', \AcknowledgementReceipt\controllers\AcknowledgementReceiptController::class . ':get');
$app->get('/resources/{resId}/shippings', \Shipping\controllers\ShippingController::class . ':get');
$app->get('/res/{resId}/acknowledgementReceipt/{id}', \AcknowledgementReceipt\controllers\AcknowledgementReceiptController::class . ':getAcknowledgementReceipt');
$app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus');
......
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Shipping Controller
* @author dev@maarch.org
*/
namespace Shipping\controllers;
use Attachment\models\AttachmentModel;
use Entity\models\EntityModel;
use Resource\controllers\ResController;
use Respect\Validation\Validator;
use Shipping\models\ShippingModel;
use Slim\Http\Request;
use Slim\Http\Response;
use User\models\UserModel;
class ShippingController
{
public static function get(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']);
}
$attachments = AttachmentModel::get([
'select' => ['res_id'],
'where' => ['res_id_master = ?'],
'data' => [$args['resId']]
]);
$attachments = array_column($attachments, 'res_id');
$shippingsModel = ShippingModel::get([
'select' => ['*'],
'where' => ['(document_id = ? and document_type = ?) or (document_id in (?) and document_type = ?)'],
'data' => [$args['resId'], 'resource', $attachments, 'attachment']
]);
$shippings = [];
foreach ($shippingsModel as $shipping) {
$recipientEntityLabel = EntityModel::getById(['id' => $shipping['recipient_entity_id'], 'select' => ['entity_label']]);
$recipientEntityLabel = $recipientEntityLabel['entity_label'];
$userLabel = UserModel::getLabelledUserById(['id' => $shipping['user_id']]);
$shippings[] = [
'id' => $shipping['id'],
'documentId' => $shipping['document_id'],
'documentType' => $shipping['document_type'],
'userId' => $shipping['user_id'],
'userLabel' => $userLabel,
'fee' => $shipping['fee'],
'recipientEntityId' => $shipping['recipient_entity_id'],
'recipientEntityLabel' => $recipientEntityLabel
];
}
return $response->withJson($shippings);
}
}
......@@ -41,4 +41,23 @@ class ShippingModel
return true;
}
public static function get(array $args)
{
ValidatorModel::notEmpty($args, ['select']);
ValidatorModel::arrayType($args, ['select', 'where', 'data', 'orderBy']);
ValidatorModel::intType($args, ['limit']);
$contacts = DatabaseModel::select([
'select' => $args['select'],
'table' => ['shippings'],
'where' => empty($args['where']) ? [] : $args['where'],
'data' => empty($args['data']) ? [] : $args['data'],
'order_by' => empty($args['orderBy']) ? [] : $args['orderBy'],
'offset' => empty($args['offset']) ? 0 : $args['offset'],
'limit' => empty($args['limit']) ? 0 : $args['limit']
]);
return $contacts;
}
}
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