summaryrefslogtreecommitdiff
path: root/db.php
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-03-18 11:52:54 +0000
committerTrygve Laugstøl <trygvis@inamo.no>2012-03-18 11:52:54 +0000
commite0a5561fda74908f19166844da6e08a6c02ff0e1 (patch)
tree169a7b551a6c4368ed7bfbfd39c080b8fb3121ed /db.php
parent3abcaeebf6b533c35aafbbd86a1a44246e99a572 (diff)
downloadhttp-mq-e0a5561fda74908f19166844da6e08a6c02ff0e1.tar.gz
http-mq-e0a5561fda74908f19166844da6e08a6c02ff0e1.tar.bz2
http-mq-e0a5561fda74908f19166844da6e08a6c02ff0e1.tar.xz
http-mq-e0a5561fda74908f19166844da6e08a6c02ff0e1.zip
o Adding html templates.
Diffstat (limited to 'db.php')
-rw-r--r--db.php63
1 files changed, 59 insertions, 4 deletions
diff --git a/db.php b/db.php
index 8cd8bc9..12743e8 100644
--- a/db.php
+++ b/db.php
@@ -1,13 +1,40 @@
<?php
+function url_to_a($url, $title = NULL) {
+ if(!isset($title)) {
+ $title = htmlspecialchars($url);
+ }
+ return "<a href='" . htmlspecialchars($url) . "'>$title</a>";
+}
+
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 =
+ "<h2>Queue: $this->name</h2>" .
+ "<table>" .
+ "<tr><td>Queue URL</td><td>$queue_url</td></tr>";
+ if($detail) $html .=
+ "<tr><td>Endpoint URL</td><td>$endpoint</td></tr>" .
+ "<tr><td>Enqueue</td><td>$enqueue_url</td></tr>" .
+ "<tr><td>Items</td><td>$items_url</td></tr>";
+ $html .=
+ "</table>";
+ 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 =
+ "<h2>Item</h2>" .
+ "<h3>Meta</h3>" .
+ "<ul>" .
+ "<li>Id: $this->id</li>" .
+ "<li>Created: $this->created</li>" .
+ "<li>Link: $item_url</li>" .
+ "</ul>" .
+ "<h3>Headers</h3>" .
+ "<ul>\n";
+ foreach($this->headers as $k => $v) {
+ $html .= "<li>" . $k . ": " . $v . "</li>\n";
+ }
+ return $html . "</ul>\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;
}
}