diff --git a/config/acl.yaml b/config/acl.yaml index f876e866..9d9fba7c 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -156,6 +156,8 @@ access_keys: label: Update - id: customer.delete label: Delete + - id: customer.dpa + label: Display DPA - id: location diff --git a/src/Service/CustomerHandler/ResqCustomerHandler.php b/src/Service/CustomerHandler/ResqCustomerHandler.php index e27399e3..0618a4ed 100644 --- a/src/Service/CustomerHandler/ResqCustomerHandler.php +++ b/src/Service/CustomerHandler/ResqCustomerHandler.php @@ -163,17 +163,31 @@ class ResqCustomerHandler implements CustomerHandlerInterface // add new customer and customer vehicle, if any public function addCustomer(Request $req) { - // create new row - $em = $this->em; - $row = new Customer(); - - $this->setObject($row, $req); - // initialize error lists $error_array = []; $nerror_array = []; $verror_array = []; + // create new row + $em = $this->em; + $row = new Customer(); + + // check if dpa consent is unticked + $is_dpa_checked = $req->request->get('flag_dpa_consent'); + if (!$is_dpa_checked) + $error_array['flag_dpa_consent'] = 'DPA consent should be checked.'; + + // check if email marketing promo is checked + $is_email_promo_checked = $req->request->get('flag_promo_email'); + if ($is_email_promo_checked) + { + // check email field + if (empty($req->request->get('email'))) + $error_array['email'] = 'Email address required.'; + } + + $this->setObject($row, $req); + // custom validation for vehicles $vehicles = json_decode($req->request->get('vehicles')); @@ -325,6 +339,21 @@ class ResqCustomerHandler implements CustomerHandlerInterface $nerror_array = []; $verror_array = []; + // check if dpa consent is unticked + $is_dpa_checked = $req->request->get('flag_dpa_consent'); + if (!$is_dpa_checked) + $error_array['flag_dpa_consent'] = 'DPA consent should be checked.'; + + // check if email marketing promo is checked + $is_email_promo_checked = $req->request->get('flag_promo_email'); + if ($is_email_promo_checked) + { + // check email field + if (empty($req->request->get('email'))) + $error_array['email'] = 'Email address required.'; + } + + // TODO: validate mobile numbers // TODO: validate vehicles diff --git a/templates/customer/form.html.twig b/templates/customer/form.html.twig index cb07b5a3..97b80884 100644 --- a/templates/customer/form.html.twig +++ b/templates/customer/form.html.twig @@ -80,6 +80,7 @@ E-mail +
@@ -122,9 +123,11 @@
- - -
+ {% if is_granted('customer.dpa') %} + + +
+ {% endif %}