Commit 526ac35a authored by Steven Wittens's avatar Steven Wittens
Browse files

- Clean up some db queries in poll.module

parent ea5e9704
......@@ -76,7 +76,7 @@ function poll_block($op = 'list', $delta = 0) {
function poll_cron() {
$result = db_query('SELECT p.nid FROM {poll} p INNER JOIN {node} n ON p.nid = n.nid WHERE (n.created + p.runtime) < '. time() .' AND p.active = 1 AND p.runtime != 0');
while ($poll = db_fetch_object($result)) {
db_query("UPDATE {poll} SET active='0' WHERE nid = %d", $poll->nid);
db_query("UPDATE {poll} SET active = 0 WHERE nid = %d", $poll->nid);
}
}
......@@ -84,7 +84,7 @@ function poll_cron() {
* Implementation of hook_delete().
*/
function poll_delete($node) {
db_query("DELETE FROM {poll} WHERE nid=%d", $node->nid);
db_query("DELETE FROM {poll} WHERE nid = %d", $node->nid);
db_query("DELETE FROM {poll_choices} WHERE nid = %d", $node->nid);
}
......@@ -241,7 +241,7 @@ function poll_load($node) {
// Load the appropriate choices into the $node object
$poll = db_fetch_object(db_query("SELECT runtime, polled, active FROM {poll} WHERE nid = %d", $node->nid));
$result = db_query("SELECT chtext, chvotes, chorder FROM {poll_choices} WHERE nid=%d ORDER BY chorder", $node->nid);
$result = db_query("SELECT chtext, chvotes, chorder FROM {poll_choices} WHERE nid = %d ORDER BY chorder", $node->nid);
while ($choice = db_fetch_array($result)) {
$poll->choice[$choice['chorder']] = $choice;
}
......@@ -265,7 +265,7 @@ function poll_node_name($node) {
function poll_page() {
// List all polls
$sql = "SELECT n.nid, n.title, p.active, n.created, SUM(c.chvotes) AS votes FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid INNER JOIN {poll_choices} c ON n.nid = c.nid WHERE type = 'poll' AND status = 1 AND moderate = 0 GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC";
$sql = "SELECT n.nid, n.title, p.active, n.created, SUM(c.chvotes) AS votes FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid INNER JOIN {poll_choices} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC";
$sql = db_rewrite_sql($sql);
$result = pager_query($sql, 15);
$output = '<ul>';
......@@ -382,7 +382,7 @@ function poll_vote(&$node) {
if ($node->allowvotes) {
$id = poll_uid();
$node->polled = $node->polled ? ($node->polled .' '. $id) : $id;
db_query("UPDATE {poll} SET polled='%s' WHERE nid = %d", $node->polled, $node->nid);
db_query("UPDATE {poll} SET polled = '%s' WHERE nid = %d", $node->polled, $node->nid);
db_query("UPDATE {poll_choices} SET chvotes = chvotes + 1 WHERE nid = %d AND chorder = %d", $node->nid, $choice);
$node->allowvotes = false;
$node->choice[$choice]['chvotes']++;
......
......@@ -76,7 +76,7 @@ function poll_block($op = 'list', $delta = 0) {
function poll_cron() {
$result = db_query('SELECT p.nid FROM {poll} p INNER JOIN {node} n ON p.nid = n.nid WHERE (n.created + p.runtime) < '. time() .' AND p.active = 1 AND p.runtime != 0');
while ($poll = db_fetch_object($result)) {
db_query("UPDATE {poll} SET active='0' WHERE nid = %d", $poll->nid);
db_query("UPDATE {poll} SET active = 0 WHERE nid = %d", $poll->nid);
}
}
......@@ -84,7 +84,7 @@ function poll_cron() {
* Implementation of hook_delete().
*/
function poll_delete($node) {
db_query("DELETE FROM {poll} WHERE nid=%d", $node->nid);
db_query("DELETE FROM {poll} WHERE nid = %d", $node->nid);
db_query("DELETE FROM {poll_choices} WHERE nid = %d", $node->nid);
}
......@@ -241,7 +241,7 @@ function poll_load($node) {
// Load the appropriate choices into the $node object
$poll = db_fetch_object(db_query("SELECT runtime, polled, active FROM {poll} WHERE nid = %d", $node->nid));
$result = db_query("SELECT chtext, chvotes, chorder FROM {poll_choices} WHERE nid=%d ORDER BY chorder", $node->nid);
$result = db_query("SELECT chtext, chvotes, chorder FROM {poll_choices} WHERE nid = %d ORDER BY chorder", $node->nid);
while ($choice = db_fetch_array($result)) {
$poll->choice[$choice['chorder']] = $choice;
}
......@@ -265,7 +265,7 @@ function poll_node_name($node) {
function poll_page() {
// List all polls
$sql = "SELECT n.nid, n.title, p.active, n.created, SUM(c.chvotes) AS votes FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid INNER JOIN {poll_choices} c ON n.nid = c.nid WHERE type = 'poll' AND status = 1 AND moderate = 0 GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC";
$sql = "SELECT n.nid, n.title, p.active, n.created, SUM(c.chvotes) AS votes FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid INNER JOIN {poll_choices} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC";
$sql = db_rewrite_sql($sql);
$result = pager_query($sql, 15);
$output = '<ul>';
......@@ -382,7 +382,7 @@ function poll_vote(&$node) {
if ($node->allowvotes) {
$id = poll_uid();
$node->polled = $node->polled ? ($node->polled .' '. $id) : $id;
db_query("UPDATE {poll} SET polled='%s' WHERE nid = %d", $node->polled, $node->nid);
db_query("UPDATE {poll} SET polled = '%s' WHERE nid = %d", $node->polled, $node->nid);
db_query("UPDATE {poll_choices} SET chvotes = chvotes + 1 WHERE nid = %d AND chorder = %d", $node->nid, $choice);
$node->allowvotes = false;
$node->choice[$choice]['chvotes']++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment