Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 65 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
| TaskGroup | |
0.00% |
0 / 65 |
|
0.00% |
0 / 11 |
992 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| get | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 | |||
| create | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| update | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| delete | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
| getAll | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| getTaskCount | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Core; |
| 4 | |
| 5 | class TaskGroup extends Store { |
| 6 | private $db; |
| 7 | private $log; |
| 8 | |
| 9 | public $id; |
| 10 | public $groupName; |
| 11 | |
| 12 | public function __construct($typeNum) |
| 13 | { |
| 14 | parent::createStore($typeNum); |
| 15 | $this->log = new \KLogger($_ENV['LOG_DIR']."dev_log.txt", \KLogger::DEBUG); |
| 16 | $this->db = dbConnectByName($this->getDbName()); |
| 17 | } |
| 18 | |
| 19 | //Basic CRUD Tasks |
| 20 | |
| 21 | public function get($id = null, $groupName = null) |
| 22 | { |
| 23 | try { |
| 24 | if (isset($id)) { |
| 25 | $stmt = $this->db->prepare("SELECT * FROM taskGroups WHERE id = :id"); |
| 26 | $stmt->bindValue(":id", $this->id); |
| 27 | } else { |
| 28 | if (isset($groupName)) { |
| 29 | $stmt = $this->db->prepare("SELECT * FROM taskGroups WHERE groupName = :groupName"); |
| 30 | $stmt->bindValue(":groupName", $this->groupName); |
| 31 | } |
| 32 | } |
| 33 | if ($stmt->execute()) { |
| 34 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 35 | $this->id = $row['id']; |
| 36 | $this->groupName = $row['groupName']; |
| 37 | return true; |
| 38 | } |
| 39 | } catch (\PDOException $e) { |
| 40 | |
| 41 | } |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | public function create() |
| 46 | { |
| 47 | if (isset($this->groupName)) { |
| 48 | try { |
| 49 | $stmt = $this->db->prepare("INSERT INTO taskGroups (groupName) VALUES (:groupName)"); |
| 50 | $stmt->bindValue(":groupName", $this->groupName); |
| 51 | if ($stmt->execute()) { |
| 52 | $this->id = $this->db->lastInsertId(); |
| 53 | return $this->id; |
| 54 | } |
| 55 | |
| 56 | } catch (\PDOException $e) { |
| 57 | |
| 58 | } |
| 59 | } |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | public function update() |
| 64 | { |
| 65 | if (isset($this->groupName)) { |
| 66 | try { |
| 67 | $stmt = $this->db->prepare("UPDATE taskGroups SET groupName = :groupName WHERE id = :id"); |
| 68 | $stmt->bindValue(":groupName", $this->groupName); |
| 69 | $stmt->bindValue(":id", $this->id); |
| 70 | if ($stmt->execute()) { |
| 71 | return true; |
| 72 | } |
| 73 | } catch (\PDOException $e) { |
| 74 | |
| 75 | } |
| 76 | } |
| 77 | return false; |
| 78 | } |
| 79 | public function delete() { |
| 80 | if (isset($this->id)) { |
| 81 | try { |
| 82 | // Check if there are tasks in this group |
| 83 | $taskCount = $this->getTaskCount(); |
| 84 | if ($taskCount > 0) { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | $stmt = $this->db->prepare("DELETE FROM taskGroups WHERE id = :id"); |
| 89 | $stmt->bindValue(":id", $this->id); |
| 90 | if ($stmt->execute()) { |
| 91 | return true; |
| 92 | } |
| 93 | } catch (\PDOException $e) { |
| 94 | |
| 95 | } |
| 96 | } |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | public function getAll() |
| 101 | { |
| 102 | try { |
| 103 | $stmt = $this->db->query("SELECT * FROM taskGroups ORDER BY groupName ASC"); |
| 104 | if ($stmt) { |
| 105 | $groups = []; |
| 106 | while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
| 107 | $groups[] = [ |
| 108 | 'id' => $row['id'], |
| 109 | 'groupName' => $row['groupName'] |
| 110 | ]; |
| 111 | } |
| 112 | return $groups; |
| 113 | } |
| 114 | } catch (\PDOException $e) { |
| 115 | |
| 116 | } |
| 117 | return []; |
| 118 | } |
| 119 | |
| 120 | public function getTaskCount() |
| 121 | { |
| 122 | if (isset($this->id)) { |
| 123 | try { |
| 124 | $stmt = $this->db->prepare("SELECT COUNT(*) as count FROM tasks WHERE taskGroup = :groupID"); |
| 125 | $stmt->bindValue(":groupID", $this->id); |
| 126 | if ($stmt->execute()) { |
| 127 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 128 | return (int)$row['count']; |
| 129 | } |
| 130 | } catch (\PDOException $e) { |
| 131 | |
| 132 | } |
| 133 | } |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | // Getters and Setters |
| 139 | |
| 140 | public function getId() |
| 141 | { |
| 142 | return $this->id; |
| 143 | } |
| 144 | |
| 145 | public function setId($id) |
| 146 | { |
| 147 | $this->id = $id; |
| 148 | } |
| 149 | |
| 150 | public function getGroupName() |
| 151 | { |
| 152 | return $this->groupName; |
| 153 | } |
| 154 | |
| 155 | public function setGroupName($groupName) |
| 156 | { |
| 157 | $this->groupName = $groupName; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | } |