diff --git a/lib/Alchemy/Phrasea/Controller/LightboxController.php b/lib/Alchemy/Phrasea/Controller/LightboxController.php index 30d7c81f65..19c7378c1f 100644 --- a/lib/Alchemy/Phrasea/Controller/LightboxController.php +++ b/lib/Alchemy/Phrasea/Controller/LightboxController.php @@ -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 diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php b/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php index c1485b862c..7e18fff788 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php @@ -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; }