From e0a5561fda74908f19166844da6e08a6c02ff0e1 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 18 Mar 2012 11:52:54 +0000 Subject: o Adding html templates. --- db.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) (limited to 'db.php') diff --git a/db.php b/db.php index 8cd8bc9..12743e8 100644 --- a/db.php +++ b/db.php @@ -1,13 +1,40 @@ $title"; +} + class Queue { public $name; public $endpoint_url; function toPlainText($url_generator) { return "Name: " . $this->name . "\n" . + "Queue URL: " . $url_generator->queue($this->name) . "\n" . "Endpoint URL: " . (isset($this->endpoint_url) ? $this->endpoint_url : "Not set") . "\n" . - "Enqueue: " . $url_generator->enqueue($this->name) . "\n"; + "Enqueue: " . $url_generator->enqueue($this->name) . "\n" . + "Items: " . $url_generator->queue_items($this->name) . "\n"; + } + + function toHtml($url_generator, $detail) { + $queue_url = url_to_a($url_generator->queue($this->name)); + $endpoint = !isset($this->endpoint_url) ? "Not set" : htmlspecialchars($this->endpoint_url); + $enqueue_url = url_to_a($url_generator->enqueue($this->name)); + $items_url = url_to_a($url_generator->queue_items($this->name)); + $html = + "

Queue: $this->name

" . + "" . + ""; + if($detail) $html .= + "" . + "" . + ""; + $html .= + "
Queue URL$queue_url
Endpoint URL$endpoint
Enqueue$enqueue_url
Items$items_url
"; + return $html; } static function valid_name($str) { @@ -39,6 +66,24 @@ class Item { } return "Headers:\n" . $headers; } + + function toHtml($url_generator) { + $item_url = url_to_a($url_generator->item($this->queue_name, $this->id)); + $html = + "

Item

" . + "

Meta

" . + "" . + "

Headers

" . + "\n"; + } } class DB { @@ -100,7 +145,15 @@ class DB { $stmt->setFetchMode(PDO::FETCH_CLASS, "Queue"); $stmt->bindParam(":name", $queue); $stmt->execute(); - return $stmt->fetch(PDO::FETCH_CLASS); + $x = $stmt->fetch(PDO::FETCH_CLASS); + return $x === FALSE ? NULL : $x; + } + + function delete_item($queue_name, $id) { + $stmt = $this->db->prepare("DELETE FROM item WHERE queue_name = :queue_name AND id = :id"); + $stmt->bindParam(":queue_name", $queue_name); + $stmt->bindParam(":id", $id); + $stmt->execute(); } function select_item($queue_name, $id) { @@ -108,7 +161,8 @@ class DB { $stmt->bindParam(":queue_name", $queue_name); $stmt->bindParam(":id", $id); $stmt->execute(); - return $stmt->fetchAll(PDO::FETCH_FUNC, 'item_from_db'); + $x = $stmt->fetchAll(PDO::FETCH_FUNC, 'item_from_db'); + return count($x) > 0 ? $x[0] : NULL; } function select_items($queue_name, $limit = 10, $offset = 0) { @@ -117,7 +171,8 @@ class DB { $stmt->bindParam(":limit", $limit); $stmt->bindParam(":offset", $offset); $stmt->execute(); - return $stmt->fetchAll(PDO::FETCH_FUNC, 'item_from_db'); + $x = $stmt->fetchAll(PDO::FETCH_FUNC, 'item_from_db'); + return $x; } } -- cgit v1.2.3