Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 92 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| LoyaltyMassSMS | |
0.00% |
0 / 92 |
|
0.00% |
0 / 6 |
506 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| read | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
30 | |||
| create | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
12 | |||
| update | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
12 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setTimeFrame | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
72 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Core\Loyalty; |
| 4 | |
| 5 | class LoyaltyMassSMS extends LoyaltyGroup { |
| 6 | |
| 7 | private $db; |
| 8 | private $log; |
| 9 | public $id; |
| 10 | public $typeNum; |
| 11 | /////////////////////////// |
| 12 | // References the LoyaltySMSMessages table |
| 13 | /////////////////////////// |
| 14 | public $messageID; |
| 15 | /////////////////////////// |
| 16 | // What customers should we send this message to? (Assumes only opted-in customers) |
| 17 | // 'just_buyers' All customers who have bought from the store before |
| 18 | // 'just_sellers' All customers who have sold to the store before |
| 19 | // 'recent_buyers' All customers who have bought from the store in the last ($lastDays) days |
| 20 | // 'recent_sellers' All customers who have sold to the store in the last ($lastDays) days |
| 21 | // 'recent_both' All customers who have visited (buy or sale) the store in the last ($lastDays) days |
| 22 | // 'full_list' All customers on the list who have visited the store at any time in the past |
| 23 | public $listType; |
| 24 | /////////////////////////// |
| 25 | // If $listType is a "recent" type how many days since the type of event should we look for? |
| 26 | // Ex. if $listType = "recent_buyers" |
| 27 | // $lastDays = 90 would be all the customers that had a sale with the store in the last 90 days |
| 28 | // After some thought this variable name is ominous |
| 29 | /////////////////////////// |
| 30 | public $lastDays; |
| 31 | /////////////////////////// |
| 32 | // timeframe is the time where the text should be sent during the day // |
| 33 | // 0 = Random |
| 34 | // 1 = 10am local time |
| 35 | // 2 = 12pm local time |
| 36 | // 3 = 2pm local time |
| 37 | // 4 = 4pm local time |
| 38 | // 5 = 6pm local time |
| 39 | // 6 = 8pm local time |
| 40 | /////////////////////////// |
| 41 | public $timeFrame; |
| 42 | /////////////////////////// |
| 43 | // Mysql date type that the message should be sent out |
| 44 | /////////////////////////// |
| 45 | public $date; |
| 46 | /////////////////////////// |
| 47 | // If we have processed this message already and its been added to loyaltyOutgoing |
| 48 | /////////////////////////// |
| 49 | public $processed; |
| 50 | /////////////////////////// |
| 51 | // Coupon ID from the loyaltyCoupons table |
| 52 | /////////////////////////// |
| 53 | public $couponID; |
| 54 | |
| 55 | public function __construct($id = null, $groupID = null, $typeNum = null) |
| 56 | { |
| 57 | global $logDir; |
| 58 | $this->log = new \KLogger($_ENV['LOG_DIR']."dev_log.txt", \KLogger::DEBUG); |
| 59 | parent::__construct($groupID, $typeNum); |
| 60 | $this->db = parent::getDb(); |
| 61 | $this->typeNum = $typeNum; |
| 62 | |
| 63 | if($id !== null) { |
| 64 | $this->id = $id; |
| 65 | $this->read(); |
| 66 | } |
| 67 | } |
| 68 | public function read() { |
| 69 | if($this->id !== null) { |
| 70 | try { |
| 71 | $stmt = $this->db->prepare("SELECT * FROM loyaltyMassSMS WHERE id = :id"); |
| 72 | $stmt->bindValue(":id", $this->id); |
| 73 | if($stmt->execute()) { |
| 74 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 75 | if($row['id'] > -1) { |
| 76 | $this->id = $row['id']; |
| 77 | $this->storeGroup = $row['storeGroup']; |
| 78 | $this->typeNum = $row['typeNum']; |
| 79 | $this->messageID = $row['messageID']; |
| 80 | $this->listType = $row['listType']; |
| 81 | $this->lastDays = $row['lastDays']; |
| 82 | $this->timeFrame = $row['timeFrame']; |
| 83 | $this->date = $row['date']; |
| 84 | $this->processed = $row['processed']; |
| 85 | $this->couponID = $row['couponID']; |
| 86 | return true; |
| 87 | } |
| 88 | } |
| 89 | } catch (\PDOException $e) { |
| 90 | $this->log->LogError($e->getMessage()); |
| 91 | } |
| 92 | } |
| 93 | return false; |
| 94 | } |
| 95 | public function create() { |
| 96 | try { |
| 97 | $stmt = $this->db->prepare("INSERT INTO loyaltyMassSMS (storeGroup, typeNum, messageID, listType, timeFrame, date, lastDays, processed, couponID) VALUES (:storeGroup, :typeNum, :messageID, :listType, :timeFrame, :date, :lastDays, 0, :couponID)"); |
| 98 | $this->log->LogDebug("StoreGroup: ".$this->groupID); |
| 99 | $this->log->LogDebug("typeNum: ".$this->typeNum); |
| 100 | $this->log->LogDebug("MessageID: ".$this->messageID); |
| 101 | $this->log->LogDebug("ListType: ".$this->listType); |
| 102 | $this->log->LogDebug("ListDays: ".$this->lastDays); |
| 103 | $this->log->LogDebug("TimeFrame: ".$this->timeFrame); |
| 104 | $this->log->LogDebug("date: ".$this->date); |
| 105 | $this->log->LogDebug("couponID: ".$this->couponID); |
| 106 | $stmt->bindValue(":storeGroup", $this->groupID); |
| 107 | $stmt->bindValue(":typeNum", $this->typeNum); |
| 108 | $stmt->bindValue(":messageID", $this->messageID); |
| 109 | $stmt->bindValue(":listType", $this->listType); |
| 110 | $stmt->bindValue(":timeFrame", $this->timeFrame); |
| 111 | $stmt->bindValue(":lastDays", $this->lastDays); |
| 112 | $stmt->bindValue(":date", $this->date); |
| 113 | $stmt->bindValue(":couponID", $this->couponID); |
| 114 | if($stmt->execute()) { |
| 115 | $this->id = $this->db->lastInsertId(); |
| 116 | return true; |
| 117 | } else { |
| 118 | $this->log->LogError(print_r($this->db->errorInfo())); |
| 119 | } |
| 120 | |
| 121 | } catch (\PDOException $e) { |
| 122 | $this->log->LogError($e->getMessage()); |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | public function update() { |
| 127 | $this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
| 128 | try { |
| 129 | $stmt = $this->db->prepare("UPDATE loyaltyMassSMS SET storeGroup = :storeGroup, typeNum = :typeNum, messageID = :messageID, listType = :listType, timeFrame = :timeFrame, date = :date, lastDays = :lastDays, processed = :processed, couponID = :couponID WHERE id = :id"); |
| 130 | $stmt->bindValue(":id", $this->id); |
| 131 | $stmt->bindValue(":storeGroup", $this->groupID); |
| 132 | $stmt->bindValue(":typeNum", $this->typeNum); |
| 133 | $stmt->bindValue(":messageID", $this->messageID); |
| 134 | $stmt->bindValue(":listType", $this->listType); |
| 135 | $stmt->bindValue(":date", $this->date); |
| 136 | $stmt->bindValue(":lastDays", $this->lastDays); |
| 137 | $stmt->bindValue(":processed", $this->processed); |
| 138 | $stmt->bindValue(":couponID", $this->couponID); |
| 139 | $stmt->bindValue(":timeFrame", $this->timeFrame); |
| 140 | if($stmt->execute()) { |
| 141 | return true; |
| 142 | } else { |
| 143 | $this->log->LogError(print_r($this->db->errorCode())); |
| 144 | } |
| 145 | } catch (\PDOException $e) { |
| 146 | $this->log->LogError($e->getMessage()); |
| 147 | } |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @return mixed |
| 153 | */ |
| 154 | public function getId() |
| 155 | { |
| 156 | return $this->id; |
| 157 | } |
| 158 | public function setTimeFrame($timeFrame) { |
| 159 | switch ($timeFrame) { |
| 160 | case "00": |
| 161 | $this->timeFrame = 0; |
| 162 | break; |
| 163 | case "10": |
| 164 | $this->timeFrame = 1; |
| 165 | break; |
| 166 | case "12": |
| 167 | $this->timeFrame = 2; |
| 168 | break; |
| 169 | case "14": |
| 170 | $this->timeFrame = 3; |
| 171 | break; |
| 172 | case "16": |
| 173 | $this->timeFrame = 4; |
| 174 | break; |
| 175 | case "18": |
| 176 | $this->timeFrame = 5; |
| 177 | break; |
| 178 | case "20": |
| 179 | $this->timeFrame = 6; |
| 180 | break; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | } |