PHRAS-2927_optimize-feedback-process_4.1

add route "lightbox/ajax/GET_ELEMENTS/{{basket_id}}/" to get counts of elements validated as "yes", "no" or "nul".
Will allow front to display alert before submitting
This commit is contained in:
Jean-Yves Gaulier
2020-02-13 18:22:54 +01:00
parent 7a2a6c7f50
commit a8c19de4d3
2 changed files with 50 additions and 0 deletions

View File

@@ -450,6 +450,51 @@ class LightboxController extends Controller
return $this->app->json($data);
}
/**
* @param Basket $basket
* @return Response
*/
public function ajaxGetElementsAction(Basket $basket)
{
$ret = [
'error' => false,
'datas' => [
'counts' => [
'yes' => 0,
'no' => 0,
'nul' => 0,
'total' => 0
]
]
];
try {
if (!$basket->getValidation()) {
throw new Exception('There is no validation session attached to this basket');
}
foreach ($basket->getElements() as $element) {
$vd = $element->getUserValidationDatas($this->getAuthenticatedUser());
if($vd->getAgreement() === true) {
$ret['datas']['counts']['yes']++;
}
elseif($vd->getAgreement() === false) {
$ret['datas']['counts']['no']++;
}
elseif($vd->getAgreement() === null) {
$ret['datas']['counts']['nul']++;
}
$ret['datas']['counts']['total']++;
}
}
catch (Exception $e) {
$ret = [
'error' => true,
'datas' => $e->getMessage()
];
}
return $this->app->json($ret);
}
/**
* @param Basket $basket
* @throws Exception

View File

@@ -105,6 +105,11 @@ class Lightbox implements ControllerProviderInterface, ServiceProviderInterface
->assert('basket', '\d+')
;
$controllers->get('/ajax/GET_ELEMENTS/{basket}/', 'controller.lightbox:ajaxGetElementsAction')
->bind('lightbox_ajax_get_elements')
->assert('basket', '\d+')
;
return $controllers;
}