From 6ac92eba304ab83e16130f553c65ee881e0856c3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 5 May 2021 10:33:46 +0000 Subject: [PATCH] Add customer tags to customer form. #558 --- src/Entity/Customer.php | 10 ++--- src/Entity/CustomerTag.php | 38 +------------------ .../CustomerHandler/ResqCustomerHandler.php | 22 ++++++++++- templates/customer/form.html.twig | 13 +++++++ 4 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 8ee3837a..02f61842 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -619,7 +619,7 @@ class Customer public function addCustomerTag(CustomerTag $customer_tag) { - $this->customer_tags->add($customer_tag); + $this->customer_tags[$customer_tag->getID()] = $customer_tag; return $this; } @@ -631,11 +631,11 @@ class Customer public function getCustomerTags() { - $str_customer_tags = []; - foreach ($this->customer_tags as $customer_tag) - $str_customer_tags[] = $customer_tag->getID(); + $str_cust_tags = []; + foreach ($this->customer_tags as $cust_tag) + $str_cust_tags[] = $cust_tag->getID(); - return $str_customer_tags; + return $str_cust_tags; } } diff --git a/src/Entity/CustomerTag.php b/src/Entity/CustomerTag.php index f2d8f67e..aa80e2e7 100644 --- a/src/Entity/CustomerTag.php +++ b/src/Entity/CustomerTag.php @@ -15,7 +15,7 @@ class CustomerTag { /** * @ORM\Id - * @ORM\Column(type="string", length=80, nullable=false) + * @ORM\Column(type="string", length=80, nullable=false, unique=true) * @Assert\NotBlank() */ protected $id; @@ -27,18 +27,6 @@ class CustomerTag */ protected $name; - // flag for car club member - /** - * @ORM\Column(type="boolean") - */ - protected $flag_car_club_member; - - // flag for car club promo - /** - * @ORM\Column(type="boolean") - */ - protected $flag_car_club_promo; - // customers /** * @ORM\ManyToMany(targetEntity="Customer", mappedBy="customer_tags", fetch="EXTRA_LAZY") @@ -49,8 +37,6 @@ class CustomerTag { $this->date_create = new DateTime(); $this->customers = new ArrayCollection(); - $this->flag_car_club_member = false; - $this->flag_car_club_promo = false; } public function getID() @@ -97,26 +83,4 @@ class CustomerTag { return $this->customers; } - - public function setCarClubMember($flag_car_club_member = true) - { - $this->flag_car_club_member = $flag_car_club_member; - return $this; - } - - public function isCarClubMember() - { - return $this->flag_car_club_member; - } - - public function setCarClubPromo($flag_car_club_promo = true) - { - $this->flag_car_club_promo = $flag_car_club_promo; - return $this; - } - - public function isCarClubPromo() - { - return $this->flag_car_club_promo; - } } diff --git a/src/Service/CustomerHandler/ResqCustomerHandler.php b/src/Service/CustomerHandler/ResqCustomerHandler.php index 76d20054..8c48650d 100644 --- a/src/Service/CustomerHandler/ResqCustomerHandler.php +++ b/src/Service/CustomerHandler/ResqCustomerHandler.php @@ -22,6 +22,7 @@ use App\Entity\Vehicle; use App\Entity\Battery; use App\Entity\VehicleManufacturer; use App\Entity\BatteryManufacturer; +use App\Entity\CustomerTag; use DateTime; @@ -151,6 +152,9 @@ class ResqCustomerHandler implements CustomerHandlerInterface $params['obj'] = new Customer(); $params['mode'] = 'create'; + // get customer tags + $params['customer_tags'] = $this->em->getRepository(CustomerTag::class)->findAll(); + // get dropdown parameters $this->fillDropdownParameters($params); @@ -307,6 +311,9 @@ class ResqCustomerHandler implements CustomerHandlerInterface if (empty($row)) throw new NotFoundHttpException('The item does not exist'); + // get customer tags + $params['customer_tags'] = $em->getRepository(CustomerTag::class)->findAll(); + // get dropdown parameters $this->fillDropdownParameters($params); @@ -603,13 +610,26 @@ class ResqCustomerHandler implements CustomerHandlerInterface ->setPromoEmail($req->request->get('flag_promo_email', false)) ->setDpaConsent($is_dpa_checked) ->setResearchSms($req->request->get('flag_research_sms', false)) - ->setResearchEmail($req->request->get('flag_research_email', false)); + ->setResearchEmail($req->request->get('flag_research_email', false)) + ->clearCustomerTags(); // phone numbers $obj->setPhoneMobile($req->request->get('phone_mobile')) ->setPhoneLandline($req->request->get('phone_landline')) ->setPhoneOffice($req->request->get('phone_office')) ->setPhoneFax($req->request->get('phone_fax')); + + // set car club flags + $customer_tags = $req->request->get('customer_tags'); + if (!empty($customer_tags)) + { + foreach($customer_tags as $customer_tag_id) + { + $customer_tag = $this->em->getRepository(CustomerTag::class)->find($customer_tag_id); + if (!empty($customer_tag)) + $obj->addCustomerTag($customer_tag); + } + } } protected function fillDropdownParameters(&$params) diff --git a/templates/customer/form.html.twig b/templates/customer/form.html.twig index eeae4bbe..5afa777f 100644 --- a/templates/customer/form.html.twig +++ b/templates/customer/form.html.twig @@ -160,6 +160,19 @@
+
+
+
+ {% for customer_tag in customer_tags %} + + {% endfor %} +
+
+