From 4910ceb1de9fb1784026098587492df8730a14a2 Mon Sep 17 00:00:00 2001
From: andrew morton <drewish@zivtech.com>
Date: Thu, 12 Jan 2012 10:53:33 -0800
Subject: [PATCH] Issue #1402758 by drewish: Finish updating user/*/votes for D7.

---
 vud.module |   73 +++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/vud.module b/vud.module
index 65191d4..04b3121 100644
--- a/vud.module
+++ b/vud.module
@@ -123,40 +123,49 @@ function vud_permission() {
 /**
  * Menu callback; display all votes for a user.
  */
-function vud_user_votes() {
-  if ($account = user_load(array('uid' => arg(1), 'status' => 1))) {
-    if ($account->status || user_access('administer users')) {
-      $header = array(
-        array('data' => t('Node')),
-        array('data' => t('Vote')),
-        array('data' => t('Date'))
-      );
-      $sql = db_rewrite_sql("SELECT n.nid, n.title, v.value, v.timestamp FROM {node} n LEFT JOIN {votingapi_vote} v
-                             ON n.nid = v.entity_id
-                             WHERE v.uid = %d AND v.tag = '%s' AND v.entity_type = 'node' AND n.status = 1
-                             ORDER BY v.timestamp DESC");
-      $result = pager_query($sql, 25, 0, NULL, $account->uid, variable_get('vud_tag', 'vote'));
-      $rows = array();
-      while ($node = db_fetch_object($result)) {
-        $rows[] = array(
-          l($node->title, 'node/'. $node->nid),
-          $node->value,
-          t('!time ago', array('!time' => format_interval(time() - $node->timestamp)))
-        );
-      }
-      drupal_set_title(check_plain($account->name));
-      $output = theme('table', $header, $rows);
-      $output .= theme('pager', NULL, 25);
-
-      return $output;
-    }
-    else {
-      drupal_access_denied();
-    }
+function vud_user_votes($account) {
+  if ($account->status != 1 || !user_access('administer users')) {
+    drupal_access_denied();
+    drupal_exit();
   }
-  else {
-    drupal_not_found();
+
+  $query = db_select('node', 'n')
+    ->fields('n', array('nid', 'title'))
+    ->condition('n.status', 1);
+  $query->leftJoin('votingapi_vote', 'v', 'n.nid = v.entity_id');
+  $query->fields('v', array('value', 'timestamp'))
+    ->condition('v.uid', $account->uid)
+    ->condition('v.tag', variable_get('vud_tag', 'vote'))
+    ->orderBy('v.timestamp', 'DESC')
+    ->addTag('node_access')
+    ->extend('PagerDefault')
+    ->limit(25);
+
+  drupal_set_title(t("@user's votes", array('@user' => $account->name)));
+
+  $build['table'] = array(
+    '#theme' => 'table',
+    '#header' => array(
+      array('data' => t('Node')),
+      array('data' => t('Vote')),
+      array('data' => t('Date'))
+    ),
+    '#rows' => array(),
+    '#empty' => t('No votes were found.'),
+  );
+  $build['pager'] = array(
+    '#theme' => 'pager',
+    '#quantity' => 25,
+    '#weight' => 1,
+  );
+  foreach ($query->execute()->fetchAll() as $node) {
+    $build['table']['#rows'][] = array(
+      l($node->title, 'node/'. $node->nid),
+      $node->value,
+      t('!time ago', array('!time' => format_interval(time() - $node->timestamp)))
+    );
   }
+  return $build;
 }
 
 /**
-- 
1.7.0.4

