--- modules/poll/poll.install.orig 2008-08-16 01:38:46.000000000 +0200 +++ modules/poll/poll.install 2008-08-16 01:29:18.000000000 +0200 @@ -18,6 +18,17 @@ } /** + * Add columns for new poll settings. + */ + +function poll_update_7000() { + $ret = array(); + db_add_field($ret, 'poll', 'pollslink', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)); + db_add_field($ret, 'poll', 'sortresult', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)); + return $ret; +} + +/** * Implementation of hook_schema(). */ function poll_schema() { @@ -44,6 +55,20 @@ 'default' => 0, 'description' => t('Boolean indicating whether or not the poll is open.'), ), + 'pollslink' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => t('When to show link to the other polls.'), + ), + 'sortresult' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => t('Sort order of choices in result display.'), + ), ), 'primary key' => array('nid'), ); --- modules/poll/poll.module.orig 2008-08-16 01:38:24.000000000 +0200 +++ modules/poll/poll.module 2008-08-16 01:37:56.000000000 +0200 @@ -249,6 +249,8 @@ // Poll attributes $_duration = array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), "format_interval"); $_active = array(0 => t('Closed'), 1 => t('Active')); + $_pollslink = array(0 => t('Always'), 1 => t('If displayed as page'), 2 => t('If displayed as block'), 3 => t('Never')); + $_sortresult = array(0 => t('No sorting'), 1 => t('Ascending (most popular choice at the bottom)'), 2 => t('Descending (most popular choice at the top)')); if ($admin) { $form['settings'] = array( @@ -265,6 +267,19 @@ '#options' => $_active, '#description' => t('When a poll is closed, visitors can no longer vote for it.') ); + $form['settings']['pollslink'] = array( + '#type' => 'radios', + '#title' => t('Show link to other polls'), + '#default_value' => isset($node->pollslink) ? $node->pollslink : 0, + '#options' => $_pollslink, + ); + $form['settings']['sortresult'] = array( + '#type' => 'radios', + '#title' => t('Sort result'), + '#default_value' => isset($node->sortresult) ? $node->sortresult : 0, + '#options' => $_sortresult, + '#description' => t('The result display can optionally be ordered by vote count.'), + ); } $form['settings']['runtime'] = array( '#type' => 'select', @@ -400,7 +415,7 @@ function poll_load($node) { global $user; - $poll = db_fetch_object(db_query("SELECT runtime, active FROM {poll} WHERE nid = %d", $node->nid)); + $poll = db_fetch_object(db_query("SELECT runtime, active, pollslink, sortresult FROM {poll} WHERE nid = %d", $node->nid)); // Load the appropriate choices into the $poll object. $result = db_query("SELECT chtext, chvotes, chorder FROM {poll_choices} WHERE nid = %d ORDER BY chorder", $node->nid); @@ -440,7 +455,7 @@ $node->active = 1; } - db_query("INSERT INTO {poll} (nid, runtime, active) VALUES (%d, %d, %d)", $node->nid, $node->runtime, $node->active); + db_query("INSERT INTO {poll} (nid, runtime, active, pollslink, sortresult) VALUES (%d, %d, %d)", $node->nid, $node->runtime, $node->active, $node->pollslink, $node->sortresult); $i = 0; foreach ($node->choice as $choice) { @@ -455,7 +470,7 @@ */ function poll_update($node) { // Update poll settings. - db_query('UPDATE {poll} SET runtime = %d, active = %d WHERE nid = %d', $node->runtime, $node->active, $node->nid); + db_query('UPDATE {poll} SET runtime = %d, active = %d, pollslink = %d, sortresult = %d WHERE nid = %d', $node->runtime, $node->active, $node->pollslink, $node->sortresult, $node->nid); // Clean poll choices. db_query('DELETE FROM {poll_choices} WHERE nid = %d', $node->nid); @@ -510,7 +525,9 @@ $node->readmore = FALSE; $links = module_invoke_all('link', 'node', $node, 1); - $links[] = array('title' => t('Older polls'), 'href' => 'poll', 'attributes' => array('title' => t('View the list of polls on this site.'))); + if ($node->pollslink == 0 || ($node->pollslink == 1 && $page) || ($node->pollslink == 2 && $block)) { + $links[] = array('title' => t('Older polls'), 'href' => 'poll', 'attributes' => array('title' => t('View the list of polls on this site.'))); + } if ($node->allowvotes && $block) { $links[] = array('title' => t('Results'), 'href' => 'node/'. $node->nid .'/results', 'attributes' => array('title' => t('View the current poll results.'))); } @@ -645,18 +662,28 @@ // Count the votes and find the maximum $total_votes = 0; $max_votes = 0; + $choices = array(); foreach ($node->choice as $choice) { if (isset($choice['chvotes'])) { $total_votes += $choice['chvotes']; $max_votes = max($max_votes, $choice['chvotes']); + $choices[$choice['chvotes']] = $choice; } } + if ($node->sortresult == 1) { + // Ascending (most voted last) + ksort($choices); + } elseif ($node->sortresult == 2) { + // Descending (most voted first) + krsort($choices); + } + $poll_results = ''; - foreach ($node->choice as $i => $choice) { + foreach ($choices as $choice) { if (!empty($choice['chtext'])) { $chvotes = isset($choice['chvotes']) ? $choice['chvotes'] : NULL; - $poll_results .= theme('poll_bar', $choice['chtext'], $chvotes, $total_votes, isset($node->vote) && $node->vote == $i, $block); + $poll_results .= theme('poll_bar', $choice['chtext'], $chvotes, $total_votes, isset($node->vote) && $node->vote == $choice['chorder'], $block); } }