Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

56 lines (47 sloc) 1.55 KB
<?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");
}
}
}
You can’t perform that action at this time.