Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SignInLogController | |
0.00% |
0 / 28 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| insertLogItem | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
| lookUpCustomerIDByLicense | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\BuyerKiosk\Controllers; |
| 4 | |
| 5 | use BuyerKiosk\Core\Controllers\BaseController; |
| 6 | |
| 7 | class SignInLogController extends BaseController { |
| 8 | |
| 9 | private $store; |
| 10 | protected $_app; |
| 11 | private $log; |
| 12 | |
| 13 | public function __construct($app, \Store $store) |
| 14 | { |
| 15 | parent::__construct($app); |
| 16 | $this->store = $store; |
| 17 | $this->log = new \KLogger($_ENV['LOG_DIR']."signInLog.log", \KLogger::DEBUG); |
| 18 | } |
| 19 | public function insertLogItem(SignInLog $log) { |
| 20 | global $db_name; |
| 21 | $db = dbConnectByName($db_name); |
| 22 | $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
| 23 | try { |
| 24 | $customerID = $this->lookUpCustomerIDByLicense($log->customerID); |
| 25 | $stmt = $db->prepare("INSERT INTO signInLog (typeNum, customerID, infoTime, questionTime, wasNewCustomer, time) VALUES (:typeNum, :customerID, :infoTime, :questionTime, :wasNewCustomer, CURRENT_TIMESTAMP )"); |
| 26 | $stmt->bindValue(":typeNum", $this->store->getTypeNum()); |
| 27 | $stmt->bindValue(":customerID", $customerID); |
| 28 | $stmt->bindValue(":infoTime", $log->infoTime); |
| 29 | $stmt->bindValue(":questionTime", $log->questionTime); |
| 30 | $stmt->bindValue(":wasNewCustomer", $log->wasNewCustomer); |
| 31 | if($stmt->execute()) { |
| 32 | return true; |
| 33 | } |
| 34 | } catch (\PDOException $e) { |
| 35 | $this->log->LogError($e->getMessage()); |
| 36 | } |
| 37 | return false; |
| 38 | } |
| 39 | private function lookUpCustomerIDByLicense($license) { |
| 40 | $db = dbConnectByName($this->store->getDbName()); |
| 41 | $this->log->LogDebug("Finding Customer: ".$license); |
| 42 | $stmt = $db->prepare("SELECT customerID FROM customers WHERE driversLicense = :license"); |
| 43 | $stmt->bindValue(":license", $license); |
| 44 | if($stmt->execute()) { |
| 45 | if($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
| 46 | $this->log->LogDebug("Found Customer: ".$row['customerID']); |
| 47 | return $row['customerID']; |
| 48 | } |
| 49 | } |
| 50 | $this->log->LogDebug("Customer Not Found"); |
| 51 | return null; |
| 52 | } |
| 53 | } |