? decisions_override_results.patch
Index: decisions.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/decisions.install,v
retrieving revision 1.29
diff -u -p -r1.29 decisions.install
--- decisions.install	26 Oct 2009 20:41:27 -0000	1.29
+++ decisions.install	15 Dec 2009 19:43:43 -0000
@@ -6,7 +6,7 @@
  * .install file for decisions module
  */
 
-// $Id: decisions.install,v 1.29 2009/10/26 20:41:27 anarcat Exp $
+// $Id: decisions.install,v 1.28 2008/12/05 03:48:02 anarcat Exp $
 
 /**
  * Implementation of hook_install().
@@ -124,6 +124,17 @@ function decisions_update_6000() {
   return $items;
 }
 
+function decisions_update_6001() {
+  switch ($GLOBALS['db_type']) {
+  case 'mysql':
+  case 'mysqli':
+    $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN `override_results_yn` tinyint default '0'");
+    $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN `override_results_text` text");
+    break;
+  }
+  return $items;
+}
+
 /**
  * Implementation of hook_uninstall().
  */
Index: decisions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/decisions.module,v
retrieving revision 1.222
diff -u -p -r1.222 decisions.module
--- decisions.module	26 Oct 2009 20:41:27 -0000	1.222
+++ decisions.module	15 Dec 2009 19:43:43 -0000
@@ -13,7 +13,7 @@
  * all the that was already written. (...and debugged!)
  */
 
-// $Id: decisions.module,v 1.222 2009/10/26 20:41:27 anarcat Exp $
+// $Id: decisions.module,v 1.221 2009/08/19 22:34:36 anarcat Exp $
 
 define('DECISIONS_DEFAULT_ELECTORAL_LIST', 0);
 // always, aftervote, or afterclose
@@ -240,6 +240,7 @@ function decisions_theme($existing, $typ
     'decisions_status' => array('arguments' => array('message' => NULL)),
     'decisions_morechoices' => array('arguments' => array(), 'decisions_morechoices' => NULL),
     'decisions_view_own_result' => array(),
+    'decisions_override_text' => array('arguments' => array('node')),
     );
 }
 
@@ -331,6 +332,17 @@ function theme_decisions_status($message
   return '<div class="error">'. $message .'</div>';
 }
 
+/**
+ * Theme the override text
+ */
+function theme_decisions_override_text($override_text) {
+  $output = '';
+  $output .= '<div class="decisions-override-text">';
+  $output .= check_plain($override_text);
+  $output .= '</div>';
+  
+  return $output;
+}
 
 /****************************/
 /* Electoral list functions */
@@ -1086,6 +1098,7 @@ function decisions_load($node) {
   while ($choice = db_fetch_array($result)) {
     $decision->choice[$choice['vote_offset']] = $choice;
   }
+  
   $decision->choices = count($decision->choice);
 
   // See if user has voted
@@ -1133,7 +1146,7 @@ function decisions_insert($node) {
   // just create an empty entry for now
   $mode = _decisions_get_mode($node);
 
-  db_query("INSERT INTO {decisions} (nid, mode, quorum_abs, quorum_percent, uselist, active, runtime, maxchoices, algorithm, startdate, randomize) VALUES (%d, '%s', %d, %f, %d, %d, %d, %d, '%s', %d, %d)", $node->nid, $mode, $node->settings['quorum']['quorum_abs'], $node->settings['quorum']['quorum_percent'], $node->settings['uselist'], $node->settings['active'], $node->settings['runtime'], $node->settings['maxchoices'], $node->settings['algorithm'], $startdate, $node->settings['randomize']);
+  db_query("INSERT INTO {decisions} (nid, mode, quorum_abs, quorum_percent, uselist, active, runtime, maxchoices, algorithm, startdate, randomize, override_results_yn, override_results_text) VALUES (%d, '%s', %d, %f, %d, %d, %d, %d, '%s', %d, %d, %d,'%s')", $node->nid, $mode, $node->settings['quorum']['quorum_abs'], $node->settings['quorum']['quorum_percent'], $node->settings['uselist'], $node->settings['active'], $node->settings['runtime'], $node->settings['maxchoices'], $node->settings['algorithm'], $startdate, $node->settings['randomize'], $node->settings['override_results_yn'], $node->settings['override_results_text']);
 
   // create the electoral list if desired
 
@@ -1210,7 +1223,7 @@ function decisions_update($node) {
     }
   } 
 
-  db_query("UPDATE {decisions} SET quorum_abs=%d, quorum_percent=%f, active=%d, runtime=%d, maxchoices=%d, algorithm='%s', uselist=%d, showvotes=%d, startdate=%d, randomize=%d WHERE nid = %d", $node->settings['quorum']['quorum_abs'], $node->settings['quorum']['quorum_percent'], $node->settings['active'], $runtime, $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['uselist'], $node->settings['showvotes'], $startdate, $node->settings['randomize'], $node->nid);
+  db_query("UPDATE {decisions} SET quorum_abs=%d, quorum_percent=%f, active=%d, runtime=%d, maxchoices=%d, algorithm='%s', uselist=%d, showvotes=%d, startdate=%d, randomize=%d, override_results_yn=%d, override_results_text='%s' WHERE nid = %d", $node->settings['quorum']['quorum_abs'], $node->settings['quorum']['quorum_percent'], $node->settings['active'], $runtime, $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['uselist'], $node->settings['showvotes'], $startdate, $node->settings['randomize'], $node->settings['override_results_yn'], $node->settings['override_results_text'], $node->nid);
   // XXX: should update decisions here, when it has some parameters
   // XXX: ... but before doing so, the code below must be factored out in a seperate function for usage in decisions_insert()
   db_query('DELETE FROM {decisions_choices} WHERE nid = %d', $node->nid);
@@ -1286,49 +1299,55 @@ function decisions_add_choices_js() {
  * Implementation of hook_view().
  */
 function decisions_view(&$node, $teaser = FALSE, $page = FALSE) {
-  $mode = _decisions_get_mode($node);
+  $mode = _decisions_get_mode($node);  
 
-  // Since we have a body (the decision's description), we need to
-  // include that in the $node->content array, too.
+    // Since we have a body (the decision's description), we need to
+    // include that in the $node->content array, too.
   $node = node_prepare($node, $teaser);
-  $node->content['body']['#weight'] = -1;
-
-  // print status messages
-  $status_messages = "";
-  if (!_decisions_meets_quorum($node)) {
-    $status_messages .= theme('decisions_status', t("This decision is not valid. You will not be able to see it until the quorum is met. The quorum is set at @quorum.", array('@quorum' => _decisions_get_quorum($node))));
-  }
-  if (!$node->active) {
-    $status_messages .= theme('decisions_status', t("This decision is currently closed."));
+  
+  // If results override has been set for this node, display text
+  if($node->override_results_yn) {
+      $node->content['override_text']['#value'] = theme('decisions_override_text',$node->override_results_text);
   }
-  else {
-    $time = time();
-    if ($time < $node->startdate) {
-      $status_messages .= theme('decisions_status', t("This decision is not yet opened."));
+  else { //otherwse display results as normal   
+    $node->content['body']['#weight'] = -1;
+  
+    // print status messages
+    $status_messages = "";
+    if (!_decisions_meets_quorum($node)) {
+      $status_messages .= theme('decisions_status', t("This decision is not valid. You will not be able to see it until the quorum is met. The quorum is set at @quorum.", array('@quorum' => _decisions_get_quorum($node))));
     }
-    else if ($node->runtime != DECISIONS_RUNTIME_INFINITY && $time >= $node->startdate + $node->runtime) {
-      $status_messages .= theme(decisions_status, t("This decision is now closed."));
+    if (!$node->active) {
+      $status_messages .= theme('decisions_status', t("This decision is currently closed."));
+    }
+    else {
+      $time = time();
+      if ($time < $node->startdate) {
+        $status_messages .= theme('decisions_status', t("This decision is not yet opened."));
+      }
+      else if ($node->runtime != DECISIONS_RUNTIME_INFINITY && $time >= $node->startdate + $node->runtime) {
+        $status_messages .= theme(decisions_status, t("This decision is now closed."));
+      }
+    }
+    $node->content['decisions']['status']['#value'] = $status_messages;
+    $node->content['decisions']['#weight'] = 1;  
+  
+    if (arg(2) != 'results' && _decisions_can_vote($node)) {
+      // User hasn't voted and we're not on the results tab
+      $node->content['decisions']['form']['#value'] = drupal_get_form('decisions_voting_form', $node, $teaser, $page);
+      $node->content['decisions']['list']['#value'] = theme('decisions_view_header', $node, $teaser);
+    }
+    elseif (_decisions_can_view_results($node)) {
+      // show results only if the user has voted or decision is closed
+      $node->content['decisions']['results']['#value'] = decisions_view_results($node, $teaser, $page);
+      $node->content['decisions']['list']['#value'] = theme('decisions_view_header', $node, $teaser);
+    } else {
+      $node->content['decisions']['#value'] = theme('decisions_view_own_result');
+    }
+    if (isset($node->voted) && $node->voted && user_access('cancel own vote') && $node->active) {
+      $node->content['decisions']['cancel']['#value'] = drupal_get_form('decisions_cancel_form', $node->nid);
     }
   }
-  $node->content['decisions']['status']['#value'] = $status_messages;
-  $node->content['decisions']['#weight'] = 1;  
-
-  if (arg(2) != 'results' && _decisions_can_vote($node)) {
-    // User hasn't voted and we're not on the results tab
-    $node->content['decisions']['form']['#value'] = drupal_get_form('decisions_voting_form', $node, $teaser, $page);
-    $node->content['decisions']['list']['#value'] = theme('decisions_view_header', $node, $teaser);
-  }
-  elseif (_decisions_can_view_results($node)) {
-    // show results only if the user has voted or decision is closed
-    $node->content['decisions']['results']['#value'] = decisions_view_results($node, $teaser, $page);
-    $node->content['decisions']['list']['#value'] = theme('decisions_view_header', $node, $teaser);
-  } else {
-    $node->content['decisions']['#value'] = theme('decisions_view_own_result');
-  }
-  if (isset($node->voted) && $node->voted && user_access('cancel own vote') && $node->active) {
-    $node->content['decisions']['cancel']['#value'] = drupal_get_form('decisions_cancel_form', $node->nid);
-  }
-
   return $node;
 }
 
@@ -1509,6 +1528,18 @@ function decisions_form(&$node, &$form_s
                                          '#default_value' => $node->randomize,
                                          '#description' => t('Display answers in a random order each time the poll is displayed.'),
                                         );
+    $form['settings']['override_results_yn'] = array(
+                                         '#type' => 'checkbox',
+                                         '#title' => t('Override results with editor text'),
+                                         '#default_value' => $node->override_results_yn,
+                                         '#description' => t('Override display of results with text entered by editor.'),
+                                        );
+    $form['settings']['override_results_text'] = array(
+                                         '#type' => 'textarea',
+                                         '#title' => t('Override results with editor text'),
+                                         '#default_value' => $node->override_results_text,
+                                         '#description' => t('Text to be displayed in place of results.'),
+                                        );
 
   $form['settings']['date'] = array(
     '#type' => 'fieldset',
