From 6398c58b3205924bb833f7df67c6eef21a14390f Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 27 Aug 2019 06:10:36 +0000 Subject: [PATCH 1/4] Add privacy policy field to warranty. Add getter and setter and method to check for privacy policy in Warranty. #256 --- src/Entity/Warranty.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index 1cfa242c..49fa7f30 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -127,6 +127,13 @@ class Warranty */ protected $flag_activated; + // privacy policy + /** + * @ORM\OneToOne(targetEntity="PrivacyPolicy") + * @ORM\JoinColumn(name="warranty_privacy_policy", referencedColumnName="id", nullable=true) + */ + protected $privacy_policy; + public function __construct() { $this->date_create = new DateTime(); @@ -366,4 +373,23 @@ class Warranty { return $this->flag_activated; } + + public function hasPrivacyPolicy() + { + if ($this->privacy_policy == null) + return false; + + return true; + } + + public function setPrivacyPolicy(PrivacyPolicy $privacy_policy) + { + $this->privacy_policy = $privacy_policy; + return $this; + } + + public function getPrivacyPolicy() + { + return $this->privacy_policy; + } } From 9efc347a7fa2384761d1758eb9de1b06334d58b3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 27 Aug 2019 07:49:10 +0000 Subject: [PATCH 2/4] Add setPrivacyPolicy method to APIController. Add route and acl for setting of privacy policy for warranty. Allow null to be set for setPrivacyPolicy in Warranty entity. Modify the checking for missing parameters, from empty to isset. #256 --- config/api_acl.yaml | 2 ++ config/routes/api.yaml | 5 +++ src/Controller/APIController.php | 54 +++++++++++++++++++++++++++++++- src/Entity/Warranty.php | 2 +- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/config/api_acl.yaml b/config/api_acl.yaml index b677f99d..c3834bf9 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -18,6 +18,8 @@ access_keys: label: Cancel - id: warranty.delete label: Delete + - id: warranty.set.privacypolicy + label: Set Privacy Policy - id: batterybrand label: Battery Brand Access acls: diff --git a/config/routes/api.yaml b/config/routes/api.yaml index f55b0d83..1cf3b829 100644 --- a/config/routes/api.yaml +++ b/config/routes/api.yaml @@ -149,3 +149,8 @@ api_partner_review: path: /api/partners/{pid}/review controller: App\Controller\APIController:reviewPartner methods: [POST] + +api_warranty_privacy_policy: + path: /api/warranty/{wid}/privacy_policy + controller: App\Controller\APIController::setPrivacyPolicy + methods: [POST] diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index fcd49749..2ef7f3cb 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -81,7 +81,8 @@ class APIController extends Controller else if ($req->getMethod() == 'POST') { $check = $req->request->get($param); - if (empty($check)) + //if (empty($check)) + if (!isset($check)) $missing[] = $param; } else @@ -2182,4 +2183,55 @@ class APIController extends Controller return $res->getReturnResponse(); } + + public function setPrivacyPolicy($wid, Request $req, EntityManagerInterface $em) + { + $required_params = [ + 'privacy_policy_id', + ]; + + error_log($req->request->get('privacy_policy_id')); + + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + $policy_id = $req->request->get('privacy_policy_id'); + + // check if warranty exists + $warranty = $em->getRepository(Warranty::class)->find($wid); + if ($warranty == null) + { + $res->setError(true) + ->setErrorMessage('No warranty found.'); + return $res->getReturnResponse(); + } + + if ($policy_id == 0) + { + $warranty->setPrivacyPolicy(null); + } + else + { + // find the privacy policy + $privacy_policy = $em->getRepository(PrivacyPolicy::class)->find($policy_id); + if ($privacy_policy == null) + { + $res->setError(true) + ->setErrorMessage('No privacy policy found.'); + return $res->getReturnResponse(); + } + + $warranty->setPrivacyPolicy($privacy_policy); + } + + // save to db + $em->persist($warranty); + $em->flush(); + + $data = []; + $res->setData($data); + + return $res->getReturnResponse(); + } } diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index 49fa7f30..c65286ef 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -382,7 +382,7 @@ class Warranty return true; } - public function setPrivacyPolicy(PrivacyPolicy $privacy_policy) + public function setPrivacyPolicy($privacy_policy) { $this->privacy_policy = $privacy_policy; return $this; From ff1e634cdce39cfe262e5a8fee2361f7910fc301 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 27 Aug 2019 08:05:34 +0000 Subject: [PATCH 3/4] Remove error_log line from setPrivacyPolicy method. #256 --- src/Controller/APIController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 2ef7f3cb..0ec6eee2 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -2190,8 +2190,6 @@ class APIController extends Controller 'privacy_policy_id', ]; - error_log($req->request->get('privacy_policy_id')); - $res = $this->checkParamsAndKey($req, $em, $required_params); if ($res->isError()) return $res->getReturnResponse(); From b8504c37018ef45d5ef43a789990641c52f3da8d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 28 Aug 2019 00:32:48 +0000 Subject: [PATCH 4/4] Modify the assocation between PrivacyPolicy and Warranty to ManyToOne. #256 --- src/Entity/PrivacyPolicy.php | 5 +++++ src/Entity/Warranty.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Entity/PrivacyPolicy.php b/src/Entity/PrivacyPolicy.php index b59ee551..4015d193 100644 --- a/src/Entity/PrivacyPolicy.php +++ b/src/Entity/PrivacyPolicy.php @@ -48,6 +48,11 @@ class PrivacyPolicy */ protected $cust_promo; + /** + * @ORM\OneToMany(targetEntity="Warranty", mappedBy="privacy_policy") + */ + protected $warranties; + public function getID() { return $this->id; diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index c65286ef..49e3b0a4 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -129,7 +129,7 @@ class Warranty // privacy policy /** - * @ORM\OneToOne(targetEntity="PrivacyPolicy") + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="warranties") * @ORM\JoinColumn(name="warranty_privacy_policy", referencedColumnName="id", nullable=true) */ protected $privacy_policy;