-
Notifications
You must be signed in to change notification settings - Fork 0
/
wants_to_buy.php
101 lines (94 loc) · 3.52 KB
/
wants_to_buy.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
<?php
function getUserShoppingList($userID){
global $db;
$query = "select * from wants_to_buy w join Food f on w.foodID = f.id where userID=:userID";
$statement = $db->prepare($query);
$statement->bindValue(':userID', $userID);
$statement->execute();
$results = $statement->fetchAll();
$statement->closeCursor();
return $results;
}
function boughtFood($userID, $foodID){
global $db;
$query = "DELETE FROM wants_to_buy WHERE userID=:userID AND foodID=:foodID";
$statement = $db->prepare($query);
$statement->bindValue(':userID', $userID);
$statement->bindValue(':foodID', $foodID);
$statement->execute();
$statement->closeCursor();
}
function deleteFoodFromShoppingList($userID, $foodID){
global $db;
$query = "DELETE FROM wants_to_buy WHERE userID=:userID AND foodID=:foodID";
$statement = $db->prepare($query);
$statement->bindValue(':userID', $userID);
$statement->bindValue(':foodID', $foodID);
$statement->execute();
$statement->closeCursor();
}
function addFoodToShoppingList($userID, $foodID, $quantity){
global $db;
$query = "insert into wants_to_buy (userID, foodID, quantity) values (:userID, :foodID, :quantity)";
$statement = $db->prepare($query);
$statement->bindValue(':userID', $userID);
$statement->bindValue(':foodID', $foodID);
$statement->bindValue(':quantity', $quantity);
$statement->execute();
$statement->closeCursor();
}
function addFoodToDB($foodName, $cookedStatus){
global $db;
$query = "insert into Food (name, cooked) values (:foodName, :cooked)";
$statement = $db->prepare($query);
$statement->bindValue(':foodName', $foodName);
if($cookedStatus == "cooked"){
$cookedStatusBool = true;
}else if($cookedStatus == "notCooked"){
$cookedStatusBool = false;
}else{
$cookedStatusBool = NULL;
}
$statement->bindValue(':cooked', $cookedStatusBool, PDO::PARAM_BOOL);
$statement->execute();
$statement->closeCursor();
}
function checkFoodInShoppingList($userID, $foodID){
global $db;
$query = "select count(*) from wants_to_buy where userID=:userID and foodID=:foodID";
$statement = $db->prepare($query);
$statement->bindValue(':userID', $userID);
$statement->bindValue(':foodID', $foodID);
$statement->execute();
$results = $statement->fetch();
$statement->closeCursor();
return $results['count(*)'];
}
function updateUserShoppingList($userID, $foodID, $quantity){
global $db;
$query = "update wants_to_buy set quantity=:quan + quantity where userID=:userID and foodID=:foodID";
$statement = $db->prepare($query);
$statement->bindValue(':userID', $userID);
$statement->bindValue(':foodID', $foodID);
$statement->bindValue(':quan', $quantity);
$statement->execute();
$statement->closeCursor();
}
function addFoodToDBAndShoppingList($userID, $foodName, $cookedStatus, $quantity){
global $db;
$query = "call addFoodToDBAndShoppingList(:userID, :foodName, :cooked, :quantity)";
$statement = $db->prepare($query);
$statement->bindValue(':userID', $userID);
$statement->bindValue(':foodName', $foodName);
if($cookedStatus == "cooked"){
$cookedStatusBool = true;
}else if($cookedStatus == "notCooked"){
$cookedStatusBool = false;
}else{
$cookedStatusBool = NULL;
}
$statement->bindValue(':cooked', $cookedStatusBool, PDO::PARAM_BOOL);
$statement->bindValue(':quantity', $quantity);
$statement->execute();
$statement->closeCursor();
}