/[drupal]/contributions/modules/decisions/decisions.module
ViewVC logotype

Diff of /contributions/modules/decisions/decisions.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.221, Wed Aug 19 22:34:36 2009 UTC revision 1.222, Mon Oct 26 20:41:27 2009 UTC
# Line 13  Line 13 
13   * all the that was already written. (...and debugged!)   * all the that was already written. (...and debugged!)
14   */   */
15    
16  // $Id: decisions.module,v 1.220 2009/07/31 16:46:16 anarcat Exp $  // $Id: decisions.module,v 1.221 2009/08/19 22:34:36 anarcat Exp $
17    
18  define('DECISIONS_DEFAULT_ELECTORAL_LIST', 0);  define('DECISIONS_DEFAULT_ELECTORAL_LIST', 0);
19  // always, aftervote, or afterclose  // always, aftervote, or afterclose
# Line 1133  function decisions_insert($node) { Line 1133  function decisions_insert($node) {
1133    // just create an empty entry for now    // just create an empty entry for now
1134    $mode = _decisions_get_mode($node);    $mode = _decisions_get_mode($node);
1135    
1136    db_query("INSERT INTO {decisions} (nid, mode, quorum_abs, quorum_percent, uselist, active, runtime, maxchoices, algorithm, startdate) VALUES (%d, '%s', %d, %f, %d, %d, %d, %d, '%s', %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);    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']);
1137    
1138    // create the electoral list if desired    // create the electoral list if desired
1139    
# Line 1210  function decisions_update($node) { Line 1210  function decisions_update($node) {
1210      }      }
1211    }    }
1212    
1213    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 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->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 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);
1214    // XXX: should update decisions here, when it has some parameters    // XXX: should update decisions here, when it has some parameters
1215    // XXX: ... but before doing so, the code below must be factored out in a seperate function for usage in decisions_insert()    // XXX: ... but before doing so, the code below must be factored out in a seperate function for usage in decisions_insert()
1216    db_query('DELETE FROM {decisions_choices} WHERE nid = %d', $node->nid);    db_query('DELETE FROM {decisions_choices} WHERE nid = %d', $node->nid);
# Line 1502  function decisions_form(&$node, &$form_s Line 1502  function decisions_form(&$node, &$form_s
1502                                           '#default_value' => isset($node->showvotes)? $node->showvotes : 1,                                           '#default_value' => isset($node->showvotes)? $node->showvotes : 1,
1503                                           '#options' => $enabled,                                           '#options' => $enabled,
1504                                           );                                           );
1505    
1506      $form['settings']['randomize'] = array(
1507                                             '#type' => 'checkbox',
1508                                             '#title' => t('Randomize answers order'),
1509                                             '#default_value' => $node->randomize,
1510                                             '#description' => t('Display answers in a random order each time the poll is displayed.'),
1511                                            );
1512    
1513    $form['settings']['date'] = array(    $form['settings']['date'] = array(
1514      '#type' => 'fieldset',      '#type' => 'fieldset',
# Line 1657  function _decisions_date($format, $times Line 1664  function _decisions_date($format, $times
1664    $result = gmdate($format, $timestamp);    $result = gmdate($format, $timestamp);
1665    return  $result;    return  $result;
1666  }  }
1667    
1668    /*
1669     * Function to put choices in random order if option to
1670     * list poll options in random order is selected in
1671     * node create/edit form.
1672     */
1673    function _decisions_randomize_options($choices, $num_choices) {
1674      $randomized_choices = array();
1675      // Put original ordered choices in separate variable.
1676      $temp_choices = $choices;
1677      // Put array keys from ordered choices in random order.
1678      $rand_keys = array_rand($choices, $num_choices);
1679    
1680      // Use keys from randomized array to get data from temp variable.
1681      // Use key+1 because $choices is 1 based and keys in randomized array
1682      // are 0 based.
1683      foreach($rand_keys as $key => $value) {
1684        $randomized_choices[$key+1]['vote_offset'] = $temp_choices[$value]['vote_offset'];
1685        $randomized_choices[$key+1]['label'] = $temp_choices[$value]['label'];
1686      }
1687      return $randomized_choices;
1688    }

Legend:
Removed from v.1.221  
changed lines
  Added in v.1.222

  ViewVC Help
Powered by ViewVC 1.1.2