Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 77 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| LoyaltyUUID | |
0.00% |
0 / 77 |
|
0.00% |
0 / 7 |
420 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
56 | |||
| addView | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| setClicked | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| setUsed | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| setDiscount | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| setSale | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| updateOutgoingTable | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Core\Loyalty; |
| 4 | |
| 5 | use BuyerKiosk\Core\Store; |
| 6 | |
| 7 | class LoyaltyUUID { |
| 8 | public $coupon; |
| 9 | public $loyaltyCustomer; |
| 10 | public $expireDate; |
| 11 | /* @var LoyaltyGroup $storeGroup */ |
| 12 | public $storeGroup; |
| 13 | public $originStore; |
| 14 | public $discount; |
| 15 | public $sale; |
| 16 | public $uuid; |
| 17 | public $used; |
| 18 | public $usedOn; |
| 19 | public $viewed; |
| 20 | public $clicked; |
| 21 | public $storeUsed; |
| 22 | private $db; |
| 23 | |
| 24 | public function __construct($uuid = null) { |
| 25 | global $db_name; |
| 26 | $this->db = dbConnectByName($db_name); |
| 27 | if(isset($uuid)) { |
| 28 | $this->uuid = $uuid; |
| 29 | $stmt = $this->db->prepare("SELECT couponID, loyaltyID, expireDate, storeGroup, discount, sale,viewed,used,usedOn,clicked,storeUsed FROM loyaltyCouponUUID WHERE UUID = :uuid"); |
| 30 | $stmt->bindValue(":uuid", $uuid); |
| 31 | if($stmt->execute()) { |
| 32 | if($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
| 33 | if(isset($row['couponID']) && isset($row['loyaltyID'])) { |
| 34 | $this->coupon = new LoyaltyCoupon(null, null, $row['couponID']); |
| 35 | $this->loyaltyCustomer = new LoyaltyCustomer($row['loyaltyID']); |
| 36 | //$this->storeGroup = new LoyaltyGroup($row['storeGroup']); |
| 37 | $store = new Store(); |
| 38 | $store->createStore($this->loyaltyCustomer->getOriginStore()); |
| 39 | $this->originStore = $store; |
| 40 | $date = \DateTime::createFromFormat("Y-m-d", $row['expireDate']); |
| 41 | $this->expireDate = $date->format("m-d-Y"); |
| 42 | $this->discount = $row['discount']; |
| 43 | $this->sale = $row['sale']; |
| 44 | $this->viewed = $row['viewed']; |
| 45 | $this->used = $row['used']; |
| 46 | $this->clicked = $row['clicked']; |
| 47 | $this->storeGroup = $row['storeGroup']; |
| 48 | $this->storeUsed = $row['storeUsed']; |
| 49 | if($row['usedOn'] !== null) { |
| 50 | $usedOn = \DateTime::createFromFormat("Y-m-d H:i:s", $row['usedOn']); |
| 51 | $this->usedOn = $usedOn->format("m-d-Y"); |
| 52 | } else { |
| 53 | $this->usedOn = null; |
| 54 | } |
| 55 | return true; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | public function addView() { |
| 65 | $stmt = $this->db->prepare("UPDATE loyaltyCouponUUID SET viewed = viewed+1 WHERE UUID = :uuid"); |
| 66 | $stmt->bindValue(":uuid", $this->uuid); |
| 67 | $this->viewed = 1; |
| 68 | $this->updateOutgoingTable(); |
| 69 | if($stmt->execute()) { |
| 70 | return true; |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | public function setClicked() { |
| 76 | $stmt = $this->db->prepare("UPDATE loyaltyCouponUUID SET clicked = 1 WHERE UUID = :uuid"); |
| 77 | $stmt->bindValue(":uuid", $this->uuid); |
| 78 | if($stmt->execute()) { |
| 79 | return true; |
| 80 | } |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | public function setUsed($store, $discount,$sale) { |
| 85 | $stmt = $this->db->prepare("UPDATE loyaltyCouponUUID SET used = 1, usedOn = CURRENT_TIMESTAMP, storeUsed = :storeUsed, discount = :discount, sale = :sale WHERE UUID = :uuid"); |
| 86 | $stmt->bindValue(":uuid", $this->uuid); |
| 87 | $stmt->bindValue(":storeUsed", $store); |
| 88 | $stmt->bindValue(":discount", $discount); |
| 89 | $stmt->bindValue(":sale", $sale); |
| 90 | $this->used = 1; |
| 91 | $this->storeUsed = $store; |
| 92 | $this->discount = $discount; |
| 93 | $this->sale = $sale; |
| 94 | if($stmt->execute()) { |
| 95 | return true; |
| 96 | } |
| 97 | return false; |
| 98 | } |
| 99 | public function setDiscount($discount) { |
| 100 | $stmt = $this->db->prepare("UPDATE loyaltyCouponUUID SET discount = :discount WHERE UUID = :uuid"); |
| 101 | $stmt->bindValue(":uuid", $this->uuid); |
| 102 | $stmt->bindValue(":discount", $discount); |
| 103 | $this->discount = $discount; |
| 104 | if($stmt->execute()) { |
| 105 | return true; |
| 106 | } |
| 107 | return false; |
| 108 | } |
| 109 | public function setSale($sale) { |
| 110 | $stmt = $this->db->prepare("UPDATE loyaltyCouponUUID SET sale = :sale WHERE UUID = :uuid"); |
| 111 | $stmt->bindValue(":uuid", $this->uuid); |
| 112 | $stmt->bindValue(":sale", $sale); |
| 113 | $this->sale = $sale; |
| 114 | if($stmt->execute()) { |
| 115 | return true; |
| 116 | } |
| 117 | return false; |
| 118 | } |
| 119 | public function updateOutgoingTable() { |
| 120 | $stmt = $this->db->prepare("SELECT * FROM loyaltyOutgoing WHERE couponUUID = :uuid LIMIT 1"); |
| 121 | $stmt->bindValue(":uuid", $this->uuid); |
| 122 | if($stmt->execute()) { |
| 123 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 124 | if($row['id']) { |
| 125 | $outgoing = new LoyaltyOutgoing($this->db, $row['id']); |
| 126 | $outgoing->setCouponUsed($this->used); |
| 127 | $outgoing->setViewed($this->viewed); |
| 128 | return $outgoing->update(); |
| 129 | } |
| 130 | } |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | } |