diff options
author | uckelman <uckelman@nomic.net> | 2010-04-07 20:41:24 +0000 |
---|---|---|
committer | uckelman <uckelman@nomic.net> | 2010-04-07 20:41:24 +0000 |
commit | 15ddec7e5e81c290a780076ef5520e402a147cae (patch) | |
tree | 6995c48f25554d64bbc90eca23bb9530a2fb03c3 /src/Bridge.php | |
parent | 202da8020dc63cc0f12fb782ba7deb618029ca3b (diff) |
Refactored.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6631 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src/Bridge.php')
-rw-r--r-- | src/Bridge.php | 64 |
1 files changed, 23 insertions, 41 deletions
diff --git a/src/Bridge.php b/src/Bridge.php index 81f80b6..1e37910 100644 --- a/src/Bridge.php +++ b/src/Bridge.php @@ -16,46 +16,16 @@ class Bridge { $sql = 'SELECT post_id FROM posts ' . 'WHERE message_id = ' . $this->db->quote($messageId); - $result = $this->db->query($sql); - - $rows = $result->fetchAll(PDO::FETCH_ASSOC); - $result->closeCursor(); - - switch (count($rows)) { - case 0: - trigger_error("Unknown message id: $messageId", E_USER_ERROR); - break; - - case 1: - return $rows[0]['post_id']; - - default: - trigger_error("Too many rows returned: $messageId", E_USER_ERROR); - break; - } + $row = get_exactly_one_row($sql); + return $row['post_id']; } public function getMessageId($postId) { $sql = 'SELECT message_id FROM posts ' . 'WHERE post_id = ' . $this->db->quote($postId); - $result = $this->db->query($sql); - - $rows = $result->fetchAll(PDO::FETCH_ASSOC); - $result->closeCursor(); - - switch (count($rows)) { - case 0: - trigger_error("Unknown post id: $postId", E_USER_ERROR); - break; - - case 1: - return $rows[0]['message_id']; - - default: - trigger_error("Too many rows returned: $postId", E_USER_ERROR); - break; - } + $row = get_exactly_one_row($sql); + return $row['message_id']; } public function registerMessage($msg, $parentId) { @@ -76,19 +46,31 @@ class Bridge { } public function getDefaultForumId($list) { - $sql = 'SELECT forum_id FROM bridge ' . + $sql = 'SELECT forum_id FROM forums ' . 'WHERE list_name = ' . $this->db->quote($list); + $row = get_exactly_one_row($sql); + return $row['forum_id']; + } + + protected function get_exactly_one_row($sql) { $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); + $rows = $result->fetchAll(PDO::FETCH_ASSOC); $result->closeCursor(); + + switch (count($rows)) { + case 0: + trigger_error("No rows returned: $sql", E_USER_ERROR); + break; - return $row['forum_id']; + case 1: + return $rows[0]; + + default: + trigger_error("Too many rows returned: $sql", E_USER_ERROR); + break; + } } } |