-
Notifications
You must be signed in to change notification settings - Fork 0
/
garageTableGateway.php
136 lines (100 loc) · 3.54 KB
/
garageTableGateway.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
<?php
/**
* Created by IntelliJ IDEA.
* User: rorypb
* Date: 26/11/2015
* Time: 3:32 PM
*/
class garageTableGateway
{
private $connection;
public function __construct($conn)
{
$this->connection = $conn;
}
public function getGarages()
{
$sqlQuery = "SELECT * FROM Web_Garage";
$statement = $this->connection->prepare($sqlQuery);
$exec = $statement->execute();
if (!$exec) {
die("Could not get Garages");
}
return $statement;
}
public function getGarageByID($garageID)
{
$sqlQuery = "SELECT * FROM Web_Garage WHERE garageID = :garageID";
$statement = $this->connection->prepare($sqlQuery);
$parameters = array("garageID" => $garageID);
$exec = $statement->execute($parameters);
if (!$exec) {
die("Could not get Garages");
}
return $statement;
}
public function insertGarage($garage)
{
$sqlQuery = "INSERT INTO Web_Garage(garageAddress, phoneNo, managerName, nameofGarage, garageID, dateService, managerEmail, garageURL, overNight)" .
"VALUES (:garageAddress, :phoneNo, :managerName, :nameofGarage, :garageID, :dateService, :managerEmail, :garageURL, :overNight)";
$statement = $this->connection->prepare($sqlQuery);
$parameters = array(
"garageAddress" => $garage->getAddress(),
"phoneNo" => $garage->getPhone(),
"managerName" => $garage->getManagerName(),
"nameofGarage" => $garage->getGarageName(),
"garageID" => $garage->getGarageID(),
"dateService" => $garage->getServiceDate(),
"managerEmail" => $garage->getManagerEmail(),
"garageURL" => $garage->getGarageURL(),
"overNight" => $garage->getOvernight()
);
$exec = $statement->execute($parameters);
if (!$exec) {
die("Could not insert garage");
}
$id = $this->connection->lastInsertId();
return $id;
}
public function removeGarage($id)
{
$sqlQuery = "DELETE FROM Web_Garage WHERE garageID= :garageID";
$statement = $this->connection->prepare($sqlQuery);
$parameters = array(
"garageID" => $id
);
$status = $statement->execute($parameters);
if (!$status) {
die("Could not delete the garage");
}
}
public function updateGarage($add, $phone, $manager_name, $garage_name, $service_date, $manager_email, $garage_url, $overnight)
{
$sqlQuery = "UPDATE Web_Garage SET " .
"garageAddress = :address, " .
"phoneNo = :phone, " .
"managerName = :manager_name, " .
"nameofGarage = :garage_name, " .
"dateService = :service_date, " .
"managerEmail = :manager_email," .
"garageURL = :garage_url, " .
"overNight = :overnight";
$statement = $this->connection->prepare($sqlQuery);
$parameters = array(
"address" => $add,
"phone" => $phone,
"manager_name" => $manager_name,
"garage_name" => $garage_name,
"service_date" => $service_date,
"manager_email" => $manager_email,
"garage_url" => $garage_url,
"overnight" => $overnight
);
$status = $statement->execute($parameters);
if (!$status){
die("Could not insert garage");
}
$id = $this->connection->lastInsertId();
return $id;
}
}