Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 115 |
|
0.00% |
0 / 37 |
CRAP | |
0.00% |
0 / 1 |
| Customer | |
0.00% |
0 / 115 |
|
0.00% |
0 / 37 |
2550 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getCustomer | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
6 | |||
| create | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
42 | |||
| update | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
20 | |||
| getBuyerRating | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| getAddedToEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAddedToEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAddedToSMS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAddedToSMS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAddress | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAddress | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCity | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setCity | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCustomerID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setCustomerID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDateAdded | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDateAdded | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDriversLicense | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDriversLicense | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFirstName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setFirstName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOnEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLastName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setLastName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setOnEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOnSMS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setOnSMS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPhone | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setPhone | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getReferralCode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setReferralCode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getState | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setState | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getZipcode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setZipcode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Core; |
| 4 | |
| 5 | class Customer extends Store { |
| 6 | |
| 7 | public $customerID; |
| 8 | public $dateAdded; |
| 9 | public $firstName; |
| 10 | public $lastName; |
| 11 | public $email; |
| 12 | public $address; |
| 13 | public $city; |
| 14 | public $state; |
| 15 | public $phone; |
| 16 | public $onSMS; |
| 17 | public $onEmail; |
| 18 | public $driversLicense; |
| 19 | public $referralCode; |
| 20 | public $addedToSMS; |
| 21 | public $addedToEmail; |
| 22 | public $zipcode; |
| 23 | private $db; |
| 24 | |
| 25 | public function __construct($custID, $typeNum) { |
| 26 | parent::__construct(); |
| 27 | $this->createStore($typeNum); |
| 28 | $this->db = dbConnectByName($this->getDbName()); |
| 29 | |
| 30 | if($this->getCustomer($custID)) { |
| 31 | } |
| 32 | } |
| 33 | private function getCustomer($custID) { |
| 34 | |
| 35 | $query = $this->db->query("SELECT * FROM customers WHERE customerID = ".$custID); |
| 36 | if($query) { |
| 37 | $row = $query->fetch(\PDO::FETCH_ASSOC); |
| 38 | $this->setCustomerID($row['customerID']); |
| 39 | $this->setDateAdded($row['dateAdded']); |
| 40 | $this->setFirstName($row['firstName']); |
| 41 | $this->setLastName($row['lastName']); |
| 42 | $this->setEmail($row['email']); |
| 43 | $this->setAddress($row['address']); |
| 44 | $this->setCity($row['city']); |
| 45 | $this->setState($row['state']); |
| 46 | $this->setPhone($row['phone']); |
| 47 | $this->setZipcode($row['zipcode']); |
| 48 | $this->setOnSMS($row['onSMS']); |
| 49 | $this->setOnEmail($row['onEmail']); |
| 50 | $this->setDriversLicense($row['driversLicense']); |
| 51 | $this->setReferralCode($row['referralCode']); |
| 52 | $this->setAddedToSMS($row['addedToSMS']); |
| 53 | $this->setAddedToEmail($row['addedToEmail']); |
| 54 | return true; |
| 55 | } |
| 56 | return false; |
| 57 | } |
| 58 | public function create($data) { |
| 59 | try { |
| 60 | // Check for required fields |
| 61 | $requiredFields = ['firstName', 'lastName', 'phone']; |
| 62 | foreach ($requiredFields as $field) { |
| 63 | if (!isset($data[$field])) { |
| 64 | throw new \Exception("Missing required field for customer creation: {$field}"); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | $sql = "INSERT INTO customers |
| 69 | (firstName, lastName, email, phone, onSMS, onEmail, driversLicense) |
| 70 | VALUES |
| 71 | (:firstName, :lastName, :email, :phone, :onSMS, :onEmail, :driversLicense)"; |
| 72 | |
| 73 | $stmt = $this->db->prepare($sql); |
| 74 | $result = $stmt->execute([ |
| 75 | ':firstName' => $data['firstName'], |
| 76 | ':lastName' => $data['lastName'], |
| 77 | ':email' => $data['email'] ?? null, |
| 78 | ':phone' => $data['phone'], |
| 79 | ':onSMS' => $data['textMe'] ?? 0, |
| 80 | ':onEmail' => $data['onEmail'] ?? 0, |
| 81 | ':driversLicense' => $data['driversLicense'] ?? null |
| 82 | ]); |
| 83 | |
| 84 | if (!$result) { |
| 85 | $errorInfo = $stmt->errorInfo(); |
| 86 | $errorMessage = "MySQL error [{$errorInfo[0]}]: {$errorInfo[2]}"; |
| 87 | throw new \PDOException($errorMessage); |
| 88 | } |
| 89 | |
| 90 | return $this->db->lastInsertId(); |
| 91 | |
| 92 | } catch (\PDOException $e) { |
| 93 | error_log("[CREATE_CUSTOMER] SQL Error: " . $e->getMessage()); |
| 94 | throw $e; |
| 95 | } catch (\Exception $e) { |
| 96 | error_log("[CREATE_CUSTOMER] General Error: " . $e->getMessage()); |
| 97 | throw $e; |
| 98 | } |
| 99 | } |
| 100 | public function update() { |
| 101 | try { |
| 102 | $sql = "UPDATE customers SET |
| 103 | firstName = :firstName, |
| 104 | lastName = :lastName, |
| 105 | email = :email, |
| 106 | phone = :phone, |
| 107 | onSMS = :onSMS, |
| 108 | onEmail = :onEmail, |
| 109 | driversLicense = :driversLicense |
| 110 | WHERE customerID = :customerID"; |
| 111 | |
| 112 | $stmt = $this->db->prepare($sql); |
| 113 | $result = $stmt->execute([ |
| 114 | ':firstName' => $this->getFirstName(), |
| 115 | ':lastName' => $this->getLastName(), |
| 116 | ':email' => $this->getEmail(), |
| 117 | ':phone' => $this->getPhone(), |
| 118 | ':onSMS' => $this->getOnSMS(), |
| 119 | ':onEmail' => $this->getOnEmail(), |
| 120 | ':driversLicense' => $this->getDriversLicense(), |
| 121 | ':customerID' => $this->getCustomerID() |
| 122 | ]); |
| 123 | |
| 124 | if (!$result) { |
| 125 | $errorInfo = $stmt->errorInfo(); |
| 126 | $errorMessage = "MySQL error [{$errorInfo[0]}]: {$errorInfo[2]}"; |
| 127 | throw new \PDOException($errorMessage); |
| 128 | } |
| 129 | |
| 130 | } catch (\PDOException $e) { |
| 131 | error_log("[UPDATE_CUSTOMER] SQL Error: " . $e->getMessage()); |
| 132 | throw $e; |
| 133 | } catch (\Exception $e) { |
| 134 | error_log("[UPDATE_CUSTOMER] General Error: " . $e->getMessage()); |
| 135 | throw $e; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | public function getBuyerRating() { |
| 140 | try { |
| 141 | $stmt = $this->db->prepare("SELECT ROUND(ROUND(AVG(rating) / 2, 1)) as BuyerAvgRating, COUNT(customerID) as NumRatings FROM customerRatings WHERE customerID = :customerID GROUP BY customerID"); |
| 142 | $stmt->bindValue(":customerID", $this->customerID); |
| 143 | if($stmt->execute()) { |
| 144 | if($row = $stmt->fetch(\PDO::FETCH_ASSOC)) |
| 145 | return array("AvgRating" => $row['BuyerAvgRating'], "NumRatings" => $row['NumRatings']); |
| 146 | } |
| 147 | } catch (\PDOException $e) { |
| 148 | error_log($e->getMessage()); |
| 149 | } |
| 150 | return null; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @return mixed |
| 155 | */ |
| 156 | public function getAddedToEmail() |
| 157 | { |
| 158 | return $this->addedToEmail; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * @param mixed $addedToEmail |
| 163 | */ |
| 164 | public function setAddedToEmail($addedToEmail) |
| 165 | { |
| 166 | $this->addedToEmail = $addedToEmail; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * @return mixed |
| 171 | */ |
| 172 | public function getAddedToSMS() |
| 173 | { |
| 174 | return $this->addedToSMS; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * @param mixed $addedToSMS |
| 179 | */ |
| 180 | public function setAddedToSMS($addedToSMS) |
| 181 | { |
| 182 | $this->addedToSMS = $addedToSMS; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * @return mixed |
| 187 | */ |
| 188 | public function getAddress() |
| 189 | { |
| 190 | return $this->address; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * @param mixed $address |
| 195 | */ |
| 196 | public function setAddress($address) |
| 197 | { |
| 198 | $this->address = $address; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * @return mixed |
| 203 | */ |
| 204 | public function getCity() |
| 205 | { |
| 206 | return $this->city; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * @param mixed $city |
| 211 | */ |
| 212 | public function setCity($city) |
| 213 | { |
| 214 | $this->city = $city; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * @return mixed |
| 219 | */ |
| 220 | public function getCustomerID() |
| 221 | { |
| 222 | return $this->customerID; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * @param mixed $customerID |
| 227 | */ |
| 228 | public function setCustomerID($customerID) |
| 229 | { |
| 230 | $this->customerID = $customerID; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @return mixed |
| 235 | */ |
| 236 | public function getDateAdded() |
| 237 | { |
| 238 | return $this->dateAdded; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * @param mixed $dateAdded |
| 243 | */ |
| 244 | public function setDateAdded($dateAdded) |
| 245 | { |
| 246 | $this->dateAdded = $dateAdded; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * @return mixed |
| 251 | */ |
| 252 | public function getDriversLicense() |
| 253 | { |
| 254 | return $this->driversLicense; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * @param mixed $driversLicense |
| 259 | */ |
| 260 | public function setDriversLicense($driversLicense) |
| 261 | { |
| 262 | $this->driversLicense = $driversLicense; |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * @return mixed |
| 267 | */ |
| 268 | public function getEmail() |
| 269 | { |
| 270 | return $this->email; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * @param mixed $email |
| 275 | */ |
| 276 | public function setEmail($email) |
| 277 | { |
| 278 | $this->email = $email; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * @return mixed |
| 283 | */ |
| 284 | public function getFirstName() |
| 285 | { |
| 286 | return $this->firstName; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * @param mixed $firstName |
| 291 | */ |
| 292 | public function setFirstName($firstName) |
| 293 | { |
| 294 | $this->firstName = $firstName; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | /** |
| 299 | * @return mixed |
| 300 | */ |
| 301 | public function getOnEmail() |
| 302 | { |
| 303 | return $this->onEmail; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * @return mixed |
| 308 | */ |
| 309 | public function getLastName() |
| 310 | { |
| 311 | return $this->lastName; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * @param mixed $lastName |
| 316 | */ |
| 317 | public function setLastName($lastName) |
| 318 | { |
| 319 | $this->lastName = $lastName; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * @param mixed $onEmail |
| 324 | */ |
| 325 | public function setOnEmail($onEmail) |
| 326 | { |
| 327 | $this->onEmail = $onEmail; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * @return mixed |
| 332 | */ |
| 333 | public function getOnSMS() |
| 334 | { |
| 335 | return $this->onSMS; |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * @param mixed $onSMS |
| 340 | */ |
| 341 | public function setOnSMS($onSMS) |
| 342 | { |
| 343 | $this->onSMS = $onSMS; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * @return mixed |
| 348 | */ |
| 349 | public function getPhone() |
| 350 | { |
| 351 | return $this->phone; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * @param mixed $phone |
| 356 | */ |
| 357 | public function setPhone($phone) |
| 358 | { |
| 359 | $this->phone = $phone; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * @return mixed |
| 364 | */ |
| 365 | public function getReferralCode() |
| 366 | { |
| 367 | return $this->referralCode; |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * @param mixed $referralCode |
| 372 | */ |
| 373 | public function setReferralCode($referralCode) |
| 374 | { |
| 375 | $this->referralCode = $referralCode; |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * @return mixed |
| 380 | */ |
| 381 | public function getState() |
| 382 | { |
| 383 | return $this->state; |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * @param mixed $state |
| 388 | */ |
| 389 | public function setState($state) |
| 390 | { |
| 391 | $this->state = $state; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * @return mixed |
| 396 | */ |
| 397 | public function getZipcode() |
| 398 | { |
| 399 | return $this->zipcode; |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * @param mixed $zipcode |
| 404 | */ |
| 405 | public function setZipcode($zipcode) |
| 406 | { |
| 407 | $this->zipcode = $zipcode; |
| 408 | } |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | } |