Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 60 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Task | |
0.00% |
0 / 60 |
|
0.00% |
0 / 5 |
420 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| get | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| create | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |||
| update | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |||
| delete | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Core; |
| 4 | |
| 5 | class Task |
| 6 | { |
| 7 | private $db; |
| 8 | private $log; |
| 9 | private $store; |
| 10 | |
| 11 | public $id; |
| 12 | public $taskName; |
| 13 | public $comment; |
| 14 | public $taskGroup; |
| 15 | public $recurOn; |
| 16 | public $priority = 2; // 1=High, 2=Normal, 3=Low |
| 17 | public $sortOrder = 0; |
| 18 | public $startDate; // DATE - when task should start appearing |
| 19 | public $endDate; // DATE - when task should stop appearing |
| 20 | public $timeOfDay; // TIME - recommended time for task |
| 21 | |
| 22 | public function __construct($typeNum) |
| 23 | { |
| 24 | $storeController = new \BuyerKiosk\StoreController($typeNum); |
| 25 | $this->store = $storeController->getStore(); |
| 26 | $this->log = new \KLogger($_ENV['LOG_DIR'] . "dev_log.txt", \KLogger::DEBUG); |
| 27 | $this->db = dbConnectByName($this->store->getDbName()); |
| 28 | } |
| 29 | |
| 30 | public function get($id) |
| 31 | { |
| 32 | try { |
| 33 | $stmt = $this->db->prepare("SELECT * FROM tasks WHERE id = :id"); |
| 34 | $stmt->bindValue(":id", $id); |
| 35 | if ($stmt->execute()) { |
| 36 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 37 | $this->taskName = $row['taskName']; |
| 38 | $this->comment = $row['comment']; |
| 39 | $this->taskGroup = $row['taskGroup']; |
| 40 | $this->id = $row['id']; |
| 41 | $this->recurOn = $row['recurOn']; |
| 42 | $this->priority = $row['priority'] ?? 2; |
| 43 | $this->sortOrder = $row['sortOrder'] ?? 0; |
| 44 | $this->startDate = $row['startDate'] ?? null; |
| 45 | $this->endDate = $row['endDate'] ?? null; |
| 46 | $this->timeOfDay = $row['timeOfDay'] ?? null; |
| 47 | return true; |
| 48 | } |
| 49 | } catch (\PDOException $e) { |
| 50 | |
| 51 | } |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | public function create() |
| 56 | { |
| 57 | if (isset($this->taskName) && isset($this->comment) && isset($this->taskGroup)) { |
| 58 | try { |
| 59 | $stmt = $this->db->prepare("INSERT INTO tasks (taskName, comment, taskGroup, recurOn, priority, sortOrder, startDate, endDate, timeOfDay) VALUES (:taskName, :comment, :taskGroup, :recurOn, :priority, :sortOrder, :startDate, :endDate, :timeOfDay)"); |
| 60 | $stmt->bindValue(":taskName", $this->taskName); |
| 61 | $stmt->bindValue(":comment", $this->comment); |
| 62 | $stmt->bindValue(":taskGroup", $this->taskGroup); |
| 63 | $stmt->bindValue(":recurOn", $this->recurOn); |
| 64 | $stmt->bindValue(":priority", $this->priority); |
| 65 | $stmt->bindValue(":sortOrder", $this->sortOrder); |
| 66 | $stmt->bindValue(":startDate", $this->startDate); |
| 67 | $stmt->bindValue(":endDate", $this->endDate); |
| 68 | $stmt->bindValue(":timeOfDay", $this->timeOfDay); |
| 69 | if ($stmt->execute()) { |
| 70 | $this->id = $this->db->lastInsertId(); |
| 71 | return $this->id; |
| 72 | } |
| 73 | } catch (\PDOException $e) { |
| 74 | |
| 75 | } |
| 76 | } |
| 77 | return null; |
| 78 | } |
| 79 | |
| 80 | public function update() |
| 81 | { |
| 82 | if (isset($this->taskName) && isset($this->taskGroup) && isset($this->recurOn)) { |
| 83 | try { |
| 84 | $stmt = $this->db->prepare("UPDATE tasks SET taskName = :taskName, comment = :comment, taskGroup = :taskGroup, recurOn = :recurOn, priority = :priority, sortOrder = :sortOrder, startDate = :startDate, endDate = :endDate, timeOfDay = :timeOfDay WHERE id = :id"); |
| 85 | $stmt->bindValue(":taskName", $this->taskName); |
| 86 | $stmt->bindValue(":comment", $this->comment); |
| 87 | $stmt->bindValue(":taskGroup", $this->taskGroup); |
| 88 | $stmt->bindValue(":recurOn", $this->recurOn); |
| 89 | $stmt->bindValue(":priority", $this->priority); |
| 90 | $stmt->bindValue(":sortOrder", $this->sortOrder); |
| 91 | $stmt->bindValue(":startDate", $this->startDate); |
| 92 | $stmt->bindValue(":endDate", $this->endDate); |
| 93 | $stmt->bindValue(":timeOfDay", $this->timeOfDay); |
| 94 | $stmt->bindValue(":id", $this->id); |
| 95 | if ($stmt->execute()) { |
| 96 | return true; |
| 97 | } else { |
| 98 | //error_log("No Execute"); |
| 99 | } |
| 100 | } catch (\PDOException $e) { |
| 101 | //error_log("PDO Exception"); |
| 102 | } |
| 103 | } else { |
| 104 | //error_log("Task Name: ".$this->taskName); |
| 105 | } |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | public function delete() |
| 110 | { |
| 111 | if (isset($this->id)) { |
| 112 | try { |
| 113 | $stmt = $this->db->prepare("DELETE FROM tasks WHERE id = :id"); |
| 114 | $stmt->bindValue(":id", $this->id); |
| 115 | if($stmt->execute()) { |
| 116 | return true; |
| 117 | } |
| 118 | } catch (\PDOException $e) { |
| 119 | |
| 120 | } |
| 121 | } |
| 122 | return false; |
| 123 | } |
| 124 | } |