/[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.220, Fri Jul 31 16:46:16 2009 UTC revision 1.221, Wed Aug 19 22:34:36 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.219 2009/07/30 23:13:45 anarcat Exp $  // $Id: decisions.module,v 1.220 2009/07/31 16:46:16 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 663  function decisions_votes_tab() { Line 663  function decisions_votes_tab() {
663      $header[] = array('data' => t('Visitor'), 'field' => 'u.name');      $header[] = array('data' => t('Visitor'), 'field' => 'u.name');
664      $header[] = array('data' => t('Vote'), '');      $header[] = array('data' => t('Vote'), '');
665    
666      $result = pager_query('SELECT v.value, v.uid, v.vote_source, v.tag, u.name FROM {votingapi_vote} v LEFT JOIN {users} u ON v.uid = u.uid WHERE v.content_id = %d'. tablesort_sql($header), 20, 0, NULL, $node->nid);      /* this query will group all the vote of a user in one record so that the pager can deal with it
667         *
668         * the "votes" column will look something like:
669         *
670         *  v1=>t1,v2=>t2
671         *
672         * for a table like this:
673         *
674         * uid | v1 | t1
675         * uid | v2 | t2
676         *
677         * where vN are values and tN are tags (tags being the choice being made and values the score given to it)
678         *
679         * XXX: highly MySQL specific
680         */
681        $query = 'SELECT u.name, v.uid, v.vote_source, GROUP_CONCAT(DISTINCT CONCAT(v.value,"=>",v.tag) ORDER BY v.value) as votes FROM {votingapi_vote} v LEFT JOIN {users} u ON v.uid = u.uid WHERE v.content_id = %d GROUP BY v.uid' . tablesort_sql($header) . '';
682        $query_count = 'SELECT COUNT(DISTINCT v.uid) FROM {votingapi_vote} v LEFT JOIN {users} u ON v.uid = u.uid WHERE v.content_id = %d GROUP BY content_id'. tablesort_sql($header);
683        $result = pager_query($query, variable_get('decisions_votes_per_page', 20), 0, $query_count, $node->nid);
684      $votes = array();      $votes = array();
685      $names = array();      $names = array();
686      while ($vote = db_fetch_object($result)) {      while ($vote = db_fetch_object($result)) {
687        $key = $vote->uid? $vote->uid : $vote->vote_source;        $key = $vote->uid? $vote->uid : $vote->vote_source;
688        $votes[$key][] = $vote;        $choices = explode(',', $vote->votes);
689          foreach ($choices as $choice) {
690            $choice = explode("=>", $choice);
691            $votes[$key][] = (object) array('value' => $choice[0], 'tag' => $choice[1]);
692          }
693        $names[$key] = $vote->name ? theme('username', $vote) : check_plain($vote->vote_source);        $names[$key] = $vote->name ? theme('username', $vote) : check_plain($vote->vote_source);
694      }      }
695    
# Line 686  function decisions_votes_tab() { Line 707  function decisions_votes_tab() {
707      }      }
708    
709      $output .= theme('table', $header, $rows);      $output .= theme('table', $header, $rows);
710      $output .= theme('pager', NULL, 20, 0);      $output .= theme('pager', array(), variable_get('decisions_votes_per_page', 20), 0);
711      print theme('page', $output);      print theme('page', $output);
712    }    }
713    else {    else {

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

  ViewVC Help
Powered by ViewVC 1.1.2