diff -uN advpoll-orig/advpoll.install advpoll-resultdisplayONLY/advpoll.install --- advpoll-orig/advpoll.install 2007-12-03 15:41:24.000000000 -0500 +++ advpoll-resultdisplayONLY/advpoll.install 2008-06-19 16:12:42.000000000 -0400 @@ -21,6 +21,7 @@ end_date int NOT NULL default '0', writeins tinyint NOT NULL default '0', show_writeins tinyint NOT NULL default '0', + show_results tinyint NOT NULL default '1', question varchar(255) NOT NULL default '', PRIMARY KEY (nid) ) /*!40100 DEFAULT CHARACTER SET utf8 */"); @@ -56,6 +57,7 @@ end_date integer NOT NULL default '0', writeins smallint NOT NULL default '0', show_writeins smallint NOT NULL default '0', + show_results smallint NOT NULL default '1', question varchar(255) NOT NULL default '', PRIMARY KEY (nid) )"); @@ -314,3 +316,22 @@ return $ret; } +/** + * Add tables for result display. + * + * Moved here from being a hard-coded var. + */ +function advpoll_update_9() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql('ALTER TABLE {advpoll} ADD show_results tinyint NOT NULL default "1" AFTER show_writeins'); + break; + case 'pgsql': + $ret[] = update_sql('ALTER TABLE {advpoll} ADD show_results smallint NOT NULL default "1" AFTER show_writeins'); + break; + } + + return $ret; +} \ No newline at end of file diff -uN advpoll-orig/advpoll.module advpoll-resultdisplayONLY/advpoll.module --- advpoll-orig/advpoll.module 2007-12-16 10:05:08.000000000 -0500 +++ advpoll-resultdisplayONLY/advpoll.module 2008-06-19 16:03:03.000000000 -0400 @@ -15,8 +15,13 @@ define('ADVPOLL_INITIAL_CHOICES', 5); define('ADVPOLL_USE_QUESTION', 0); define('ADVPOLL_CHOICE_MAX_LENGTH', 2048); -// Options: always, aftervote, or afterclose. -define('ADVPOLL_VIEW_RESULTS', 'aftervote'); +define('ADVPOLL_SHOW_RESULTS', 1); + // Enum for showing results. + define('ADVPOLL_SHOW_RESULTS_ALWAYS', 0); + define('ADVPOLL_SHOW_RESULTS_AFTERVOTE', 1); + define('ADVPOLL_SHOW_RESULTS_AFTERCLOSE', 2); + define('ADVPOLL_SHOW_RESULTS_ADMIN', 3); + define('ADVPOLL_SHOW_RESULTS_ADMINCLOSED', 4); /** * Implementation of hook_help(). @@ -444,6 +449,7 @@ $default_show_votes = isset($node->show_votes) ? $node->show_votes : variable_get('advpoll_show_votes_'. $type->type, ADVPOLL_SHOW_VOTES); $default_writeins = isset($node->writeins) ? $node->writeins : variable_get('advpoll_writeins_'. $type->type, ADVPOLL_WRITEINS); $default_show_writeins = isset($node->show_writeins) ? $node->show_writeins : variable_get('advpoll_show_writeins_'. $type->type, ADVPOLL_SHOW_WRITEINS); + $default_show_results = isset($node->show_results) ? $node->show_results : variable_get('advpoll_show_results_'. $type->type, ADVPOLL_SHOW_RESULTS); if (user_access('administer polls')) { $form['settings']['admin_note'] = array( '#value' => '
'. t('The settings below are only available for users with the administer polls permission.') .'
', @@ -463,6 +469,13 @@ '#prefix' => '
', '#suffix' => '
', ); + $form['settings']['show_results'] = array( + '#type' => 'select', + '#title' => t('Show results of poll'), + '#description' => t('When to show the poll results, and to who.'), + '#options' => array(t('Always show'), t('Show after vote'), t('Show after close'), t('Always show (admin only)'), t('Show after close (admin only)')), + '#default_value' => $default_show_results, + ); $form['settings']['use_list'] = array( '#type' => 'checkbox', '#title' => t('Restrict voting to electoral list'), @@ -584,11 +597,11 @@ 'afterclose' => t('After voting has closed'), ); - $form['advpoll']['advpoll_view_results'] = array( + $form['advpoll']['advpoll_show_results'] = array( '#type' => 'radios', '#title' => t('Display results'), '#description' => t('Determines when users may view the results of the poll.'), - '#default_value' => variable_get('advpoll_view_results_'. $node_type, ADVPOLL_VIEW_RESULTS), + '#default_value' => variable_get('advpoll_show_results_'. $node_type, ADVPOLL_SHOW_RESULTS), '#options' => $view_results, ); $form['advpoll']['advpoll_use_question'] = array( @@ -685,7 +698,7 @@ */ function advpoll_insert($node) { $mode = _advpoll_get_mode($node->type); - db_query("INSERT INTO {advpoll} (nid, mode, use_list, active, max_choices, algorithm, show_votes, start_date, end_date, writeins, show_writeins, question) VALUES (%d, '%s', %d, %d, %d, '%s', %d, '%s', '%s', %d, %d, '%s')", $node->nid, $mode, $node->settings['use_list'], !$node->settings['close'], $node->settings['max_choices'], $node->settings['algorithm'], $node->settings['show_votes'], $node->settings['start_date'] ? strtotime($node->settings['start_date']) : 0, $node->settings['end_date'] ? strtotime($node->settings['end_date']) : 0, $node->settings['writeins'], $node->settings['show_writeins'], $node->question); + db_query("INSERT INTO {advpoll} (nid, mode, use_list, active, max_choices, algorithm, show_votes, start_date, end_date, writeins, show_writeins, show_results, question) VALUES (%d, '%s', %d, %d, %d, '%s', %d, '%s', '%s', %d, %d, %d, '%s')", $node->nid, $mode, $node->settings['use_list'], !$node->settings['close'], $node->settings['max_choices'], $node->settings['algorithm'], $node->settings['show_votes'], $node->settings['start_date'] ? strtotime($node->settings['start_date']) : 0, $node->settings['end_date'] ? strtotime($node->settings['end_date']) : 0, $node->settings['writeins'], $node->settings['show_writeins'], $node->settings['show_results'], $node->question); // Insert the choices. _advpoll_insert_choices($node->nid); @@ -698,7 +711,7 @@ */ function advpoll_update($node) { - db_query("UPDATE {advpoll} SET active = %d, max_choices = %d, algorithm = '%s', use_list = %d, show_votes = %d, start_date = '%s', end_date = '%s', writeins = %d, show_writeins = %d, question = '%s' WHERE nid = %d", !$node->settings['close'], $node->settings['max_choices'], $node->settings['algorithm'], $node->settings['use_list'], $node->settings['show_votes'], $node->settings['start_date'] ? strtotime($node->settings['start_date']) : 0, $node->settings['end_date'] ? strtotime($node->settings['end_date']) : 0, $node->settings['writeins'], $node->settings['show_writeins'], $node->question, $node->nid); + db_query("UPDATE {advpoll} SET active = %d, max_choices = %d, algorithm = '%s', use_list = %d, show_votes = %d, start_date = '%s', end_date = '%s', writeins = %d, show_writeins = %d, show_results = %d, question = '%s' WHERE nid = %d", !$node->settings['close'], $node->settings['max_choices'], $node->settings['algorithm'], $node->settings['use_list'], $node->settings['show_votes'], $node->settings['start_date'] ? strtotime($node->settings['start_date']) : 0, $node->settings['end_date'] ? strtotime($node->settings['end_date']) : 0, $node->settings['writeins'], $node->settings['show_writeins'], $node->settings['show_results'], $node->question, $node->nid); _advpoll_insert_choices($node->nid); votingapi_recalculate_results('advpoll', $node->nid); @@ -1087,10 +1100,11 @@ * Helper function to abstract view results checking. */ function _advpoll_can_view_results($node) { - $view_results = variable_get('advpoll_view_results_'. $node->type, ADVPOLL_VIEW_RESULTS); - return (!_advpoll_is_active($node) // Node is closed - || ($node->voted && $view_results == 'aftervote') // User voted - || ($view_results == 'always')); // All can view + return (($node->show_results == ADVPOLL_SHOW_RESULTS_ALWAYS) // Always. + || ($node->voted && $node->show_results == ADVPOLL_SHOW_RESULTS_AFTERVOTE) // After vote. + || (!_advpoll_is_active($node) && $node->show_results == ADVPOLL_SHOW_RESULTS_AFTERCLOSE) // After close. + || (user_access('administer polls') && $node->show_results == ADVPOLL_SHOW_RESULTS_ADMIN) // Always for admin. + || (!_advpoll_is_active($node) && user_access('administer polls') && $node->show_results == ADVPOLL_SHOW_RESULTS_ADMINCLOSED)); // After close for admin. } /** Common subdirectories: advpoll-orig/datetimepicker and advpoll-resultdisplayONLY/datetimepicker Common subdirectories: advpoll-orig/modes and advpoll-resultdisplayONLY/modes Common subdirectories: advpoll-orig/po and advpoll-resultdisplayONLY/po