Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 75 |
|
0.00% |
0 / 18 |
CRAP | |
0.00% |
0 / 1 |
| Action | |
0.00% |
0 / 75 |
|
0.00% |
0 / 18 |
992 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| createFromRow | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| getByID | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| getReadableString | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
90 | |||
| getDateReadable | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getBinID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setBinID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getEmployeeID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setEmployeeID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTimeStamp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setTimeStamp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCategoryID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setCategoryID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Backstock; |
| 4 | |
| 5 | class Action extends Backstock |
| 6 | { |
| 7 | protected $store; |
| 8 | public $id; |
| 9 | public $binID; |
| 10 | public $employeeID; |
| 11 | public $categoryID; |
| 12 | public $action; |
| 13 | public $timeStamp; |
| 14 | public $readableString; |
| 15 | public $employeeName; |
| 16 | public $dateReadable; |
| 17 | public $dateReadableShort; |
| 18 | |
| 19 | public function __construct(\Store $store) |
| 20 | { |
| 21 | $this->store = $store; |
| 22 | parent::__construct($store); |
| 23 | } |
| 24 | |
| 25 | public function create() { |
| 26 | $stmt = $this->storeDB->prepare("INSERT INTO bsActions (binID, action, employeeID, categoryID, timePerformed) VALUES (:binID, :action, :employeeID, :categoryID, CURRENT_TIMESTAMP )"); |
| 27 | $stmt->bindValue(":binID", $this->binID); |
| 28 | $stmt->bindValue(":action", $this->action); |
| 29 | $stmt->bindValue(":employeeID", $this->employeeID); |
| 30 | // categoryID can be null for "Remove Everything" action (action 0) |
| 31 | if ($this->categoryID === null || $this->categoryID === '') { |
| 32 | $stmt->bindValue(":categoryID", null, \PDO::PARAM_NULL); |
| 33 | } else { |
| 34 | $stmt->bindValue(":categoryID", $this->categoryID); |
| 35 | } |
| 36 | if($stmt->execute()) { |
| 37 | $this->id = $this->storeDB->lastInsertId(); |
| 38 | return $this; |
| 39 | } |
| 40 | return null; |
| 41 | } |
| 42 | |
| 43 | public function createFromRow($row) { |
| 44 | $this->id = $row['id']; |
| 45 | $this->binID = $row['binID']; |
| 46 | $this->employeeID = $row['employeeID']; |
| 47 | $this->categoryID = $row['categoryID']; |
| 48 | $this->action = $row['action']; |
| 49 | $this->timeStamp = $row['timePerformed']; |
| 50 | $this->readableString = $this->getReadableString(); |
| 51 | $this->dateReadable = $this->getDateReadable(); |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | public function getByID($id) { |
| 56 | $stmt = $this->storeDB->prepare("SELECT * FROM bsActions WHERE id = :id"); |
| 57 | $stmt->bindValue(":id", $id); |
| 58 | if($stmt->execute()) { |
| 59 | if($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
| 60 | $this->createFromRow($row); |
| 61 | return $this; |
| 62 | } |
| 63 | } |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | public function getReadableString() { |
| 68 | $employees = getEmployeeNameArray($this->store); |
| 69 | $bin = new Bin($this->store); |
| 70 | $bin->readByID($this->binID); |
| 71 | $bsFactory = new BackstockFactory($this->store); |
| 72 | $categories = $bsFactory->getCategoriesArray(); |
| 73 | $output = ""; |
| 74 | if(isset($employees[$this->employeeID])) { |
| 75 | $this->employeeName = $employees[$this->employeeID]; |
| 76 | $employeeName = explode(" ", $employees[$this->employeeID]); |
| 77 | $employeeShortName = $employeeName[0]." ".substr($employeeName[1], 0,1); |
| 78 | } else { |
| 79 | $this->employeeName = "[Unknown]"; |
| 80 | $employeeShortName = "[Unknown]"; |
| 81 | } |
| 82 | |
| 83 | switch((int)$this->action) { |
| 84 | case 0: |
| 85 | $output = $employeeShortName.". removed everything from ".$bin->name; |
| 86 | break; |
| 87 | case 1: |
| 88 | $categoryName = isset($categories[$this->categoryID]['name']) ? $categories[$this->categoryID]['name'] : 'Unknown Category'; |
| 89 | $output = $employeeShortName.". added some ".$categoryName." to ".$bin->name; |
| 90 | break; |
| 91 | case 2: |
| 92 | $categoryName = isset($categories[$this->categoryID]['name']) ? $categories[$this->categoryID]['name'] : 'Unknown Category'; |
| 93 | $output = $employeeShortName.". removed some ".$categoryName." from ".$bin->name; |
| 94 | break; |
| 95 | case 3: |
| 96 | $categoryName = isset($categories[$this->categoryID]['name']) ? $categories[$this->categoryID]['name'] : 'Unknown Category'; |
| 97 | $output = $employeeShortName.". removed all of the ".$categoryName." from ".$bin->name; |
| 98 | break; |
| 99 | } |
| 100 | return $output; |
| 101 | } |
| 102 | public function getDateReadable() { |
| 103 | $date = new \DateTime($this->timeStamp, new \DateTimeZone("UTC")); |
| 104 | $date->setTimezone(new \DateTimeZone($this->store->getTimeZone())); |
| 105 | $this->timeStamp = $date->format("Y-m-d H:i:s"); |
| 106 | $this->dateReadableShort = $date->format("M jS, Y"); |
| 107 | return $date->format("M jS, Y g:i a"); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @return mixed |
| 112 | */ |
| 113 | public function getBinID() |
| 114 | { |
| 115 | return $this->binID; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @param mixed $binID |
| 120 | */ |
| 121 | public function setBinID($binID) |
| 122 | { |
| 123 | $this->binID = $binID; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @return mixed |
| 128 | */ |
| 129 | public function getEmployeeID() |
| 130 | { |
| 131 | return $this->employeeID; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @param mixed $employeeID |
| 136 | */ |
| 137 | public function setEmployeeID($employeeID) |
| 138 | { |
| 139 | $this->employeeID = $employeeID; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @return mixed |
| 144 | */ |
| 145 | public function getAction() |
| 146 | { |
| 147 | return $this->action; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * @param mixed $action |
| 152 | */ |
| 153 | public function setAction($action) |
| 154 | { |
| 155 | $this->action = $action; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * @return mixed |
| 160 | */ |
| 161 | public function getTimeStamp() |
| 162 | { |
| 163 | return $this->timeStamp; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * @param mixed $timeStamp |
| 168 | */ |
| 169 | public function setTimeStamp($timeStamp) |
| 170 | { |
| 171 | $this->timeStamp = $timeStamp; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * @return mixed |
| 176 | */ |
| 177 | public function getCategoryID() |
| 178 | { |
| 179 | return $this->categoryID; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * @param mixed $categoryID |
| 184 | */ |
| 185 | public function setCategoryID($categoryID) |
| 186 | { |
| 187 | $this->categoryID = $categoryID; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * @return mixed |
| 192 | */ |
| 193 | public function getId() |
| 194 | { |
| 195 | return $this->id; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * @param mixed $id |
| 200 | */ |
| 201 | public function setId($id) |
| 202 | { |
| 203 | $this->id = $id; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | } |