Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 77 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ShiftNotes | |
0.00% |
0 / 77 |
|
0.00% |
0 / 7 |
306 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| readFromRow | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| readFromJSON | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
| readByID | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| create | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| update | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
| delete | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Core\ShiftNotes; |
| 4 | |
| 5 | use BuyerKiosk\Core\Store; |
| 6 | |
| 7 | class ShiftNotes extends Store { |
| 8 | private $db; |
| 9 | private $log; |
| 10 | private $read; |
| 11 | |
| 12 | public $id; |
| 13 | public $timeStamp; |
| 14 | public $itemType; |
| 15 | public $itemPriority; |
| 16 | public $itemSubmitter; |
| 17 | public $itemTitle; |
| 18 | public $itemComment; |
| 19 | public $itemCloser; |
| 20 | public $timeClosed; |
| 21 | public $itemStatus; |
| 22 | |
| 23 | public function __construct($typeNum = null) |
| 24 | { |
| 25 | if($typeNum !== null) { |
| 26 | parent::createStore($typeNum); |
| 27 | $this->db = dbConnectByName($this->getDbName()); |
| 28 | $this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
| 29 | $this->db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); |
| 30 | $this->log = new \KLogger($_ENV['LOG_DIR']."debug.log", \KLogger::DEBUG); |
| 31 | $this->read = 0; |
| 32 | } |
| 33 | } |
| 34 | public function readFromRow($row) { |
| 35 | $this->id = $row['id']; |
| 36 | $this->timeStamp = $row['timeStamp']; |
| 37 | $this->itemType = $row['itemType']; |
| 38 | $this->itemSubmitter = $row['itemSubmitter']; |
| 39 | $this->itemPriority = $row['itemPriority']; |
| 40 | $this->itemTitle = $row['itemTitle']; |
| 41 | $this->itemComment = $row['itemComment']; |
| 42 | $this->itemCloser = $row['itemCloser']; |
| 43 | $this->timeClosed = $row['timeClosed']; |
| 44 | $this->itemStatus = $row['itemStatus']; |
| 45 | $this->read = 1; |
| 46 | } |
| 47 | public function readFromJSON($json) { |
| 48 | $this->id = $json->ID; |
| 49 | $this->timeStamp = $json->timeStamp; |
| 50 | $this->itemType = $json->itemType; |
| 51 | $this->itemPriority = $json->itemPriority; |
| 52 | $this->itemSubmitter = $json->itemSubmitter; |
| 53 | $this->itemTitle = $json->itemTitle; |
| 54 | $this->itemComment = $json->itemComment; |
| 55 | $this->itemCloser = $json->itemCloser; |
| 56 | $this->timeClosed = $json->timeClosed; |
| 57 | if($this->timeClosed == '') { |
| 58 | $this->timeClosed = null; |
| 59 | } |
| 60 | $this->itemStatus = $json->itemStatus; |
| 61 | $this->read = 1; |
| 62 | } |
| 63 | public function readByID($id) { |
| 64 | $stmt = $this->db->prepare("SELECT * FROM shiftNotes WHERE id = :id"); |
| 65 | $stmt->bindValue(":id", $id); |
| 66 | if($stmt->execute()) { |
| 67 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 68 | if($row['id'] == $id) { |
| 69 | $this->readFromRow($row); |
| 70 | return true; |
| 71 | } |
| 72 | } |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | public function create() { |
| 77 | if($this->timeClosed == '') { |
| 78 | $this->timeClosed = null; |
| 79 | } |
| 80 | $stmt = $this->db->prepare("INSERT INTO shiftNotes (id, timeStamp, itemType, itemPriority, itemSubmitter, itemTitle, itemComment, itemCloser, itemStatus, timeClosed) VALUES (:id, :timeStamp, :itemType, :itemPriority, :itemSubmitter, :itemTitle, :itemComment, :itemCloser, :itemStatus, :timeClosed)"); |
| 81 | $stmt->bindValue(":id", $this->id); |
| 82 | $stmt->bindValue(":timeStamp", $this->timeStamp); |
| 83 | $stmt->bindValue(":itemType", $this->itemType); |
| 84 | $stmt->bindValue(":itemPriority", $this->itemPriority); |
| 85 | $stmt->bindValue(":itemSubmitter", $this->itemSubmitter); |
| 86 | $stmt->bindValue(":itemTitle", $this->itemTitle); |
| 87 | $stmt->bindValue(":itemComment", $this->itemComment); |
| 88 | $stmt->bindValue(":itemCloser", $this->itemCloser); |
| 89 | $stmt->bindValue(":itemStatus", $this->itemStatus); |
| 90 | $stmt->bindValue(":timeClosed", $this->timeClosed); |
| 91 | if($stmt->execute()) { |
| 92 | return true; |
| 93 | } else { |
| 94 | $this->log->LogError($this->db->errorInfo()); |
| 95 | } |
| 96 | return false; |
| 97 | } |
| 98 | public function update() { |
| 99 | if($this->read == 1) { |
| 100 | $stmt = $this->db->prepare("UPDATE shiftNotes SET timeStamp = :timeStamp, itemType = :itemType, itemPriority = :itemPriority, itemSubmitter = :itemSubmitter, itemTitle = :itemTitle, itemComment = :itemComment, itemCloser = :itemCloser, itemStatus = :itemStatus, timeClosed = :timeClosed WHERE id = :id"); |
| 101 | $stmt->bindValue(":id", $this->id); |
| 102 | $stmt->bindValue(":timeStamp", $this->timeStamp); |
| 103 | $stmt->bindValue(":itemType", $this->itemType); |
| 104 | $stmt->bindValue(":itemPriority", $this->itemPriority); |
| 105 | $stmt->bindValue(":itemSubmitter", $this->itemSubmitter); |
| 106 | $stmt->bindValue(":itemTitle", $this->itemTitle); |
| 107 | $stmt->bindValue(":itemComment", $this->itemComment); |
| 108 | $stmt->bindValue(":itemCloser", $this->itemCloser); |
| 109 | $stmt->bindValue(":timeClosed", $this->timeClosed); |
| 110 | $stmt->bindValue(":itemStatus", $this->itemStatus); |
| 111 | if($stmt->execute()) { |
| 112 | return true; |
| 113 | } |
| 114 | } |
| 115 | return false; |
| 116 | } |
| 117 | public function delete() { |
| 118 | if($this->read == 1) { |
| 119 | $stmt = $this->db->prepare("DELETE FROM shiftNotes WHERE id = :id"); |
| 120 | $stmt->bindValue(":id", $this->id); |
| 121 | if($stmt->execute()) { |
| 122 | return true; |
| 123 | } |
| 124 | } |
| 125 | return false; |
| 126 | } |
| 127 | } |