--- advpoll_orig.install 2007-08-11 23:19:22.000000000 -0400 +++ advpoll.install 2007-08-16 12:47:22.156250000 -0400 @@ -19,6 +19,7 @@ maxchoices int unsigned NOT NULL default '0', algorithm VARCHAR(100), showvotes tinyint, + viewresults VARCHAR(255), startdate int unsigned, PRIMARY KEY (nid) ) /*!40100 DEFAULT CHARACTER SET utf8 */"); @@ -49,6 +50,7 @@ maxchoices integer NOT NULL DEFAULT '0', algorithm varchar(100), showvotes smallint, + viewresults VARCHAR(255), startdate integer, PRIMARY KEY (nid) )"); @@ -143,3 +145,12 @@ } return $ret; } + +/** + * Add ability to set "view results" per poll. + */ +function advpoll_update_3() { + $ret = array(); + db_add_column($ret, 'advpoll', 'viewresults', 'varchar(255)'); + return $ret; +} --- advpoll_orig.module 2007-08-11 16:58:26.000000000 -0400 +++ advpoll.module 2007-08-16 13:35:41.046875000 -0400 @@ -269,7 +269,8 @@ '#description' => t('When a poll is closed users may no longer vote on it.'), ); - $_duration = array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), 'format_interval'); +//********** Nancy W. added 3 weeks. + $_duration = array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 1814400, 2419200, 4838400, 9676800, 31536000), 'format_interval'); $form['settings']['usestart'] = array( '#type' => 'checkbox', @@ -311,6 +312,23 @@ '#default_value' => isset($node->uselist) ? $node->uselist : variable_get('advpoll_electoral_list_'. $type->type, ADVPOLL_ELECTORAL_LIST), ); +//********* Nancy W. added "view results". The array is duplicated from below and should be defined only once. + $view_results = array( + 'always' => t('Always'), + 'aftervote' => t('After user has voted'), + 'afterclose' => t('After voting has closed'), + 'bypermission' => t('By view results permission') + ); + + $form['settings']['viewresults'] = array( + '#type' => 'radios', + '#title' => t('Display results'), + '#description' => t('Determines when users may view the results of the poll.'), + '#default_value' => isset($node->viewresults) ? $node->viewresults : variable_get('advpoll_view_results_'. $type->type, ADVPOLL_VIEW_RESULTS), + '#options' => $view_results, + ); +//********* + $form['settings']['showvotes'] = array( '#type' => 'checkbox', '#title' => t('Show individual votes'), @@ -368,7 +386,7 @@ '#type' => 'select', '#title' => t('Default duration'), '#default_value' => variable_get('advpoll_runtime_'. $node_type, ADVPOLL_RUNTIME), - '#options' => array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), 'format_interval'), + '#options' => array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 1814400, 2419200, 4838400, 9676800, 31536000), 'format_interval'), '#description' => t('The date the poll was created is used as start date for the default duration. This setting can be overridden on the poll edit page.'), ); @@ -385,11 +403,13 @@ '#description' => t('Let users with appropriate permissions see how each person voted by default for new polls. Users with the administer polls permission will be able to override this setting.'), '#default_value' => variable_get('advpoll_showvotes_'. $node_type, ADVPOLL_SHOWVOTES), ); - + +//********* Nancy W. added 'bypermission'. $view_results = array( 'always' => t('Always'), 'aftervote' => t('After user has voted'), 'afterclose' => t('After voting has closed'), + 'bypermission' => t('By view results permission') ); $form['advpoll']['advpoll_view_results'] = array( @@ -812,9 +832,11 @@ */ function _advpoll_can_view_results($node) { $view_results = variable_get('advpoll_view_results_'. $node->type, ADVPOLL_VIEW_RESULTS); +//********** Nancy W. added 'by permission' check. return (!$node->active // Node is closed - || ($node->voted && $view_results == 'aftervote') // User voted - || ($view_results == 'always')); // All can view + || ($node->voted && $node->viewresults == 'aftervote') // User voted + || ($node->viewresults == 'bypermission' && user_access('view results')) //user has permission + || ($node->viewresults == 'always')); // All can view } /** @@ -839,7 +861,8 @@ * Implementation of hook_perm(). */ function advpoll_perm() { - return array('create polls', 'delete polls', 'view polls', 'vote on polls', 'cancel own vote', 'administer polls', 'inspect all votes'); +//********** Nancy W. added 'view results'. + return array('create polls', 'delete polls', 'view polls', 'vote on polls', 'cancel own vote', 'administer polls', 'inspect all votes', 'view results'); } /** @@ -861,7 +884,8 @@ $node->settings['active'] = _advpoll_calculate_active($node); } - db_query("UPDATE {advpoll} SET active=%d, runtime=%d, maxchoices=%d, algorithm='%s', uselist=%d, showvotes=%d, startdate='%s' WHERE nid = %d", $node->settings['active'], $node->settings['runtime'], $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['uselist'], $node->settings['showvotes'], $node->settings['usestart'] ? _advpoll_create_startdate($node) : 'NULL', $node->nid); +//*********** Nancy W. add view results + db_query("UPDATE {advpoll} SET active=%d, runtime=%d, maxchoices=%d, algorithm='%s', uselist=%d, showvotes=%d, startdate='%s', viewresults='%s' WHERE nid = %d", $node->settings['active'], $node->settings['runtime'], $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['uselist'], $node->settings['showvotes'], $node->settings['usestart'] ? _advpoll_create_startdate($node) : 'NULL', $node->settings['viewresults'], $node->nid); _advpoll_insert_choices($node->nid); votingapi_recalculate_results('advpoll', $node->nid); @@ -930,8 +954,8 @@ if ($node->settings['usestart']) { $node->settings['active'] = _advpoll_calculate_active($node); } - - db_query("INSERT INTO {advpoll} (nid, mode, uselist, active, runtime, maxchoices, algorithm, showvotes, startdate) VALUES (%d, '%s', %d, %d, %d, %d, '%s', %d, '%s')", $node->nid, $mode, $node->settings['uselist'], $node->settings['active'], $node->settings['runtime'], $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['showvotes'], $node->settings['usestart'] ? _advpoll_create_startdate($node) : 'NULL'); +//********** Nancy W. add view results + db_query("INSERT INTO {advpoll} (nid, mode, uselist, active, runtime, maxchoices, algorithm, showvotes, startdate, viewresults) VALUES (%d, '%s', %d, %d, %d, %d, '%s', %d, '%s', '%s')", $node->nid, $mode, $node->settings['uselist'], $node->settings['active'], $node->settings['runtime'], $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['showvotes'], $node->settings['usestart'] ? _advpoll_create_startdate($node) : 'NULL', $node->settings['viewresults']); // Insert the choices _advpoll_insert_choices($node->nid);