-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProduct.php
158 lines (117 loc) · 4.09 KB
/
Product.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
class Product{
private $idProduct;
private $descProduct;
private $valueProduct;
private $qtdeProduct;
private $photoProduct;
private $namePhotoProduct;
private $genreProduct;
private $consoleProduct;
public function getIdProduct(){
return $this->idProduct;
}
public function getDescProduct(){
return $this->descProduct;
}
public function getValueProduct(){
return $this->valueProduct;
}
public function getQtdeProduct(){
return $this->qtdeProduct;
}
public function getPhotoProduct(){
return $this->photoProduct;
}
public function getGenreProduct(){
return $this->genreProduct;
}
public function getNamePhotoProduct(){
return $this->namePhotoProduct;
}
public function getConsoleProduct(){
return $this->consoleProduct;
}
public function setIdProduct($id){
$this->idProduct = $id;
}
public function setDescProduct($desc){
$this->descProduct = $desc;
}
public function setValueProduct($value){
$this->valueProduct = $value;
}
public function setQtdeProduct($qtde){
$this->qtdeProduct = $qtde;
}
public function setPhotoProduct($photo){
$this->photoProduct = $photo;
}
public function setNamePhotoProduct($namePhoto){
$this->namePhotoProduct = $namePhoto;
}
public function setGenreProduct($genre){
$this->genreProduct = $genre;
}
public function setConsoleProduct($console){
$this->consoleProduct = $console;
}
public function register($product){
$connection = Connection::getConnection();
//statement
$stmt = $connection->prepare("INSERT INTO tbproduto
(descproduto, valorproduto, qtdeproduto, generoproduto, consoleproduto)
VALUES (?, ?, ?, ?, ?)");
$stmt->bindParam(1, $product->descProduct);
$stmt->bindParam(2, $product->valueProduct);
$stmt->bindParam(3, $product->qtdeProduct);
$stmt->bindParam(4, $product->genreProduct);
$stmt->bindParam(5, $product->consoleProduct);
$stmt->execute();
return 'Produto cadastrado com sucesso';
}
public function consultId($product){
$connection = Connection::getConnection();
$querySelect = "SELECT MAX(idproduto) as id FROM tbproduto";
$result = $connection->query($querySelect);
while($row = $result->fetch(PDO::FETCH_OBJ))
$product->idProduct = $row->id;
return $product;
}
public function registerPhoto($product){
$connection = Connection::getConnection();
$stmt = $connection->prepare("UPDATE tbproduto SET fotoproduto = ?
WHERE idproduto = ?");
$stmt->bindParam(1, $product->namePhotoProduct);
$stmt->bindParam(2, $product->idProduct);
$stmt->execute();
return 'Foto cadastrada com sucesso';
}
public function list(){
$connection = Connection::getConnection();
$stmt = $connection->prepare("SELECT * FROM `tbproduto`");
$stmt->execute();
return $stmt;
}
public function totalStock(){
$connection = Connection::getConnection();
$stmt = $connection->prepare("SELECT SUM(qtdeproduto) as 'totalStock' FROM `tbproduto`");
$stmt->execute();
return $stmt->fetch(PDO::FETCH_ASSOC);
}
public function searchGenreConsoleProducts($search){
$connection = Connection::getConnection();
$querySelect = "SELECT * FROM tbproduto where generoproduto
= '$search' or consoleproduto = '$search'";
$result = $connection->query($querySelect);
$list = $result->fetchAll();
return $list;
}
public function searchGame($search){
$connection = Connection::getConnection();
$querySelect = "SELECT * FROM tbproduto where descproduto like '%$search%'";
$result = $connection->query($querySelect);
$list = $result->fetchAll();
return $list;
}
}