From be5a66e68a4bc55a189474472e38312b7dbe6968 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Wed, 23 May 2018 22:40:44 +0800 Subject: [PATCH] Add mobile api privacy settings call #130 --- src/Controller/APIController.php | 29 ++++++++++++++++++++++++++ src/Entity/Customer.php | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index e36bb41f..9616035e 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1428,4 +1428,33 @@ class APIController extends Controller return $res->getReturnResponse(); } + + public function privacySettings(Request $req) + { + $required_params = [ + 'priv_third_party', + 'priv_promo', + ]; + $em = $this->getDoctrine()->getManager(); + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // get customer + $cust = $this->session->getCustomer(); + if ($cust == null) + { + $res->setError(true) + ->setErrorMessage('No customer information found'); + return $res->getReturnResponse(); + } + + // set privacy settings + $cust->setPrivacyThirdParty($req->request->get('priv_third_party')) + ->setPrivacyPromo($req->request->get('priv_promo')); + + $em->flush(); + + return $res->getReturnResponse(); + } } diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 641b188c..3390064d 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -131,6 +131,16 @@ class Customer */ protected $email; + /** + * @ORM\Column(type="boolean") + */ + protected $priv_third_party; + + /** + * @ORM\Column(type="boolean") + */ + protected $priv_promo; + public function __construct() { $this->numbers = new ArrayCollection(); @@ -152,6 +162,9 @@ class Customer $this->phone_fax = ''; $this->email = ''; + + $this->priv_third_party = 0; + $this->priv_promo = 0; } public function getID() @@ -379,4 +392,26 @@ class Customer { return $this->email; } + + public function setPrivacyThirdParty($bool = true) + { + $this->priv_third_party = $bool; + return $this; + } + + public function getPrivacyThirdParty() + { + return $this->priv_third_party; + } + + public function setPrivacyPromo($bool = true) + { + $this->priv_promo = $bool; + return $this; + } + + public function getPrivacyPromo() + { + return $this->priv_promo; + } }