summaryrefslogtreecommitdiff
path: root/src/Bridge.php
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-03-21 22:18:26 +0000
committeruckelman <uckelman@nomic.net>2010-03-21 22:18:26 +0000
commit23a2d3251d88061bce9ff02ca426b1e175767d4b (patch)
treeba7c9a0f8791b946049cec8b2cb827e7c2af5a3f /src/Bridge.php
parent2645db54fe03db5c0ae82fe81717cc53ef28787d (diff)
Added class encapsulating bridge DB.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6628 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src/Bridge.php')
-rw-r--r--src/Bridge.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/Bridge.php b/src/Bridge.php
new file mode 100644
index 0000000..ab627d7
--- /dev/null
+++ b/src/Bridge.php
@@ -0,0 +1,63 @@
+<?php
+
+require_once(__DIR__ . '/BridgeConf.php');
+
+class Bridge {
+ protected $db;
+
+ public function __construct($db = FALSE) {
+ $this->db = $db ? $db :
+ new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB, DB_USER, DB_PASS);
+ }
+
+ public function getPostId($messageId) {
+ $sql = 'SELECT post_id FROM posts' .
+ 'WHERE message_id = "' . $this->db->quote($message_id) . '"';
+
+ $result = $this->db->query($sql);
+ if (!$result) {
+ trigger_error("Unknown message id: $message_id", E_USER_ERROR);
+ }
+
+ // FIXME: what to do if more than one row is returned?
+ $row = $result->fetch(PDO::FETCH_ASSOC);
+ $result->closeCursor();
+
+ return $row['post_id'];
+ }
+
+ public function registerMessage($msg, $parentId) {
+ $sql = 'INSERT INTO posts' .
+ '(post_id, message_id, parent_message_id, references)' .
+ 'VALUES(' . $msg->getPostId() . ', '
+ '"' . $this->db->quote($msg->getMessageId()) . '", '
+ '"' . $this->db->quote() . '", '
+ '"' . $this->db->quote($msg->getReferences()) . '")';
+
+ $count = $this->db->exec($sql);
+
+ if ($count != 1) {
+ trigger_error(
+ 'Failed to register message: ' . $msg->getMessageId(), E_USER_ERROR
+ );
+ }
+ }
+
+ public function getDefaultForumId($list) {
+ $sql = 'SELECT forum_id FROM bridge' .
+ 'WHERE list_name = "' . $this->db->quote($list) . '"';
+
+ $result = $this->db->query($sql);
+ if (!$result) {
+ trigger_error("Unknown list name: $list", E_USER_ERROR);
+ }
+
+ // FIXME: what to do if more than one row is returned?
+ $row = $result->fetch(PDO::FETCH_ASSOC);
+ $result->closeCursor();
+
+ return $row['forum_id'];
+ }
+}
+
+?>