Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
Category
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 12
272
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 create
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 getByName
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
 getById
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
 update
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 delete
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getColor
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setColor
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BuyerKiosk\Backstock;
4
5class Category extends Backstock
6{
7
8    public $id;
9    public $name;
10    public $color;
11
12
13    public function __construct(\Store $store)
14    {
15        parent::__construct($store);
16    }
17
18    public function create()
19    {
20        $stmt = $this->storeDB->prepare("INSERT INTO bsCategories(name, color) VALUES (:name, :color)");
21        $stmt->bindValue(":name", $this->name);
22        $stmt->bindValue(":color", $this->color);
23        $stmt->execute();
24        $this->id = $this->storeDB->lastInsertId();
25        return $this;
26    }
27
28    public function getByName($name)
29    {
30        $stmt = $this->storeDB->prepare("SELECT id, color FROM bsCategories WHERE name = :name");
31        $stmt->bindValue(":name", $name);
32        if ($stmt->execute()) {
33            $row = $stmt->fetch(\PDO::FETCH_ASSOC);
34            if ($row) {
35                $this->name = $name;
36                $this->id = $row['id'];
37                $this->color = $row['color'];
38            }
39        }
40        return $this;
41    }
42
43    public function getById($id)
44    {
45        $stmt = $this->storeDB->prepare("SELECT name, color FROM bsCategories WHERE id = :id");
46        $stmt->bindValue(":id", $id);
47        if ($stmt->execute()) {
48            $row = $stmt->fetch(\PDO::FETCH_ASSOC);
49            if ($row) {
50                $this->name = $row['name'];
51                $this->id = $id;
52                $this->color = $row['color'];
53            }
54        }
55        return $this;
56    }
57
58    public function update()
59    {
60        $stmt = $this->storeDB->prepare("UPDATE bsCategories SET name=:name, color = :color WHERE id = :id");
61        $stmt->bindValue(":name", $this->name);
62        $stmt->bindValue(":color", $this->color);
63        $stmt->bindValue(":id", $this->id);
64        $stmt->execute();
65        return $this;
66    }
67
68    public function delete()
69    {
70        $stmt = $this->storeDB->prepare("DELETE FROM bsCategories WHERE id = :id");
71        $stmt->bindValue(":id", $this->id);
72        $stmt->execute();
73        return $this;
74    }
75
76    /**
77     * @return int
78     */
79    public function getId()
80    {
81        return $this->id;
82    }
83
84    /**
85     * @param int $id
86     */
87    public function setId($id)
88    {
89        $this->id = $id;
90    }
91
92    /**
93     * @return mixed
94     */
95    public function getName()
96    {
97        return $this->name;
98    }
99
100    /**
101     * @param mixed $name
102     */
103    public function setName($name)
104    {
105        $this->name = $name;
106    }
107
108    /**
109     * @return mixed
110     */
111    public function getColor()
112    {
113        return $this->color;
114    }
115
116    /**
117     * @param mixed $color
118     */
119    public function setColor($color)
120    {
121        $this->color = $color;
122    }
123
124
125}