Skip to content

Commit

Permalink
Merge pull request #126 from vanderbilt/jt/pd61-enforce-order-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jt2k authored Mar 13, 2017
2 parents 870949c + b59da9a commit 55b1043
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Pmi/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ public function orderPdfAction($type, $participantId, $orderId, Application $app
if ($order->get('finalized_ts')) {
$app->abort(403);
}
if (!in_array('print', $order->getAvailableSteps())) {
$app->abort(404);
}
if ($app->getConfig('ml_mock_order')) {
if ($type == 'labels') {
return $app->redirect($request->getBaseUrl() . '/assets/SampleLabels.pdf');
Expand Down Expand Up @@ -228,6 +231,10 @@ public function orderPrintAction($participantId, $orderId, Application $app, Req
if ($order->get('finalized_ts')) {
$app->abort(403);
}
if (!in_array('print', $order->getAvailableSteps())) {
// 404 because print is not a valid route for kit orders regardless of state
$app->abort(404);
}
if (!$order->get('printed_ts')) {
$app->log(Log::ORDER_EDIT, $orderId);
$app['em']->getRepository('orders')->update($orderId, [
Expand Down Expand Up @@ -268,6 +275,12 @@ public function orderCollectAction($participantId, $orderId, Application $app, R
public function orderProcessAction($participantId, $orderId, Application $app, Request $request)
{
$order = $this->loadOrder($participantId, $orderId, $app);
if (!in_array('process', $order->getAvailableSteps())) {
return $app->redirectToRoute('order', [
'participantId' => $participantId,
'orderId' => $orderId
]);
}
$processForm = $order->createOrderForm('processed', $app['form.factory']);
$processForm->handleRequest($request);
if ($processForm->isValid() && !$order->get('finalized_ts')) {
Expand Down Expand Up @@ -305,6 +318,12 @@ public function orderProcessAction($participantId, $orderId, Application $app, R
public function orderFinalizeAction($participantId, $orderId, Application $app, Request $request)
{
$order = $this->loadOrder($participantId, $orderId, $app);
if (!in_array('finalize', $order->getAvailableSteps())) {
return $app->redirectToRoute('order', [
'participantId' => $participantId,
'orderId' => $orderId
]);
}
$finalizeForm = $order->createOrderForm('finalized', $app['form.factory']);
$finalizeForm->handleRequest($request);
if ($finalizeForm->isValid()) {
Expand Down
21 changes: 21 additions & 0 deletions src/Pmi/Order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,27 @@ public function getCurrentStep()
return $step;
}

public function getAvailableSteps()
{
$columns = [
'print' => 'printed',
'collect' => 'collected',
'process' => 'processed',
'finalize' => 'finalized'
];
if ($this->order['type'] === 'kit') {
unset($columns['print']);
}
$steps = [];
foreach ($columns as $name => $column) {
$steps[] = $name;
if (!$this->order["{$column}_ts"]) {
break;
}
}
return $steps;
}

public function getOrderUpdateFromForm($set, $form)
{
$updateArray = [];
Expand Down

0 comments on commit 55b1043

Please sign in to comment.