-
Notifications
You must be signed in to change notification settings - Fork 49
/
TicketMapper.php
55 lines (47 loc) · 1.55 KB
/
TicketMapper.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
<?php
class TicketMapper extends Mapper
{
public function getTickets() {
$sql = "SELECT t.id, t.title, t.description, c.component
from tickets t
join components c on (c.id = t.component_id)";
$stmt = $this->db->query($sql);
$results = [];
while($row = $stmt->fetch()) {
$results[] = new TicketEntity($row);
}
return $results;
}
/**
* Get one ticket by its ID
*
* @param int $ticket_id The ID of the ticket
* @return TicketEntity The ticket
*/
public function getTicketById($ticket_id) {
$sql = "SELECT t.id, t.title, t.description, c.component
from tickets t
join components c on (c.id = t.component_id)
where t.id = :ticket_id";
$stmt = $this->db->prepare($sql);
$result = $stmt->execute(["ticket_id" => $ticket_id]);
if($result) {
return new TicketEntity($stmt->fetch());
}
}
public function save(TicketEntity $ticket) {
$sql = "insert into tickets
(title, description, component_id) values
(:title, :description,
(select id from components where component = :component))";
$stmt = $this->db->prepare($sql);
$result = $stmt->execute([
"title" => $ticket->getTitle(),
"description" => $ticket->getDescription(),
"component" => $ticket->getComponent(),
]);
if(!$result) {
throw new Exception("could not save record");
}
}
}