? .git
? views_category.patch
Index: userpoints.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints.info,v
retrieving revision 1.11.4.1
diff -u -p -r1.11.4.1 userpoints.info
--- userpoints.info	30 Jul 2010 11:20:22 -0000	1.11.4.1
+++ userpoints.info	3 Aug 2010 10:34:51 -0000
@@ -6,3 +6,6 @@ core = 7.x
 files[]=userpoints.views.inc
 files[]=userpoints.module
 files[]=tests/userpoints_api.test
+files[]=userpoints_views_handler_field_category.inc
+files[]=userpoints_views_handler_filter_category.inc
+files[]=userpoints_views_handler_argument_category.inc
Index: userpoints.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints.views.inc,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 userpoints.views.inc
--- userpoints.views.inc	30 Jul 2010 11:20:22 -0000	1.2.2.1
+++ userpoints.views.inc	3 Aug 2010 10:34:52 -0000
@@ -33,7 +33,7 @@ function userpoints_views_data() {
           'left_field' => 'uid',
           'field' => 'uid',
       ),
-      'term_data' => array(
+      'taxonomy_term_data' => array(
           'left_field' => 'tid',
           'field' => 'tid',
       ),
@@ -71,15 +71,15 @@ function userpoints_views_data() {
       'title' => t('Userpoints Category', userpoints_translation()),
       'help' => t('The categories (terms) of userpoints used', userpoints_translation()), // The help that appears on the UI,
       'field' => array(
-          'handler' => 'views_handler_field_term_node_tid',
+          'handler' => 'userpoints_views_handler_field_category',
       ),
       'argument' => array(
-          'handler' => 'views_handler_argument_term_node_tid',
+          'handler' => 'userpoints_views_handler_argument_category',
           'numeric' => TRUE,
           'name field' => 'category', // display this field in the summary
       ),
       'filter' => array(
-          'handler' => 'views_handler_filter_term_node_tid',
+          'handler' => 'userpoints_views_handler_filter_category',
       ),
       'sort' => array(
           'handler' => 'views_handler_sort',
@@ -152,7 +152,7 @@ function userpoints_views_data() {
           'left_field' => 'uid',
           'field' => 'uid',
       ),
-      'term_data' => array(
+      'taxonomy_term_data' => array(
           'left_field' => 'tid',
           'field' => 'tid',
       ),
@@ -190,15 +190,15 @@ function userpoints_views_data() {
       'title' => t('Userpoints Category', userpoints_translation()),
       'help' => t('The categories (terms) of userpoints used for this transaction', userpoints_translation()), // The help that appears on the UI,
       'field' => array(
-          'handler' => 'views_handler_field_term_node_tid	',
+          'handler' => 'userpoints_views_handler_field_category',
       ),
       'argument' => array(
-          'handler' => 'views_handler_argument_term_node_tid',
+          'handler' => 'userpoints_views_handler_argument_category',
           'numeric' => TRUE,
           'name field' => 'category', // display this field in the summary
       ),
       'filter' => array(
-          'handler' => 'views_handler_filter_term_node_tid',
+          'handler' => 'userpoints_views_handler_filter_category',
       ),
       'sort' => array(
           'handler' => 'views_handler_sort',
@@ -359,5 +359,17 @@ function userpoints_views_data() {
       ),
   );
 
+  // Reverse join information.
+  $data['taxonomy_term_data']['table']['join'] = array(
+    'userpoints' => array(
+      'left_field' => 'tid',
+      'field' => 'tid',
+    ),
+    'userpoints_txn' => array(
+      'left_field' => 'tid',
+      'field' => 'tid',
+    ),
+  );
+
   return $data;
 }
Index: userpoints_views_handler_argument_category.inc
===================================================================
RCS file: userpoints_views_handler_argument_category.inc
diff -N userpoints_views_handler_argument_category.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ userpoints_views_handler_argument_category.inc	3 Aug 2010 10:34:52 -0000
@@ -0,0 +1,35 @@
+<?php
+// $Id$
+
+/**
+ * Argument handler to accept a userpoints category.
+ */
+class userpoints_views_handler_argument_category extends views_handler_argument {
+  function construct() {
+    parent::construct('category');
+  }
+
+  /**
+   * Override the behavior of summary_name(). Get the user friendly version
+   * of the node type.
+   */
+  function summary_name($data) {
+    return $this->category($data->{$this->name_alias});
+  }
+
+  /**
+   * Override the behavior of title(). Get the user friendly version of the
+   * node type.
+   */
+  function title() {
+    return $this->category($this->argument);
+  }
+
+  function category($id) {
+    $output = userpoints_get_categories();
+    if (empty($output[$id])) {
+      $output = t('Unknown category');
+    }
+    return check_plain($output[$id]);
+  }
+}
\ No newline at end of file
Index: userpoints_views_handler_field_category.inc
===================================================================
RCS file: userpoints_views_handler_field_category.inc
diff -N userpoints_views_handler_field_category.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ userpoints_views_handler_field_category.inc	3 Aug 2010 10:34:52 -0000
@@ -0,0 +1,42 @@
+<?php
+// $Id$
+
+/**
+ * Field handler for categories.
+ *
+ * Copied from views_handler_field_term_node_tid.inc
+ */
+class userpoints_views_handler_field_category extends views_handler_field {
+
+  function init(&$view, $options) {
+    parent::init($view, $options);
+
+    $this->additional_fields['name'] = array('table' => 'taxonomy_term_data', 'field' => 'name');
+  }
+
+  /**
+   * Add this term to the query
+   */
+  function query() {
+    $this->add_additional_fields();
+  }
+
+  function pre_render($values) {
+    $this->field_alias = $this->aliases['name'];
+  }
+
+  function document_self_tokens(&$tokens) {
+    $tokens['[' . $this->options['id'] . '-tid' . ']'] = t('The taxonomy term ID for the term.');
+    $tokens['[' . $this->options['id'] . '-name' . ']'] = t('The taxonomy term name for the term.');
+    $tokens['[' . $this->options['id'] . '-vid' . ']'] = t('The vocabulary ID for the vocabulary the term belongs to.');
+    $tokens['[' . $this->options['id'] . '-vocabulary' . ']'] = t('The name for the vocabulary the term belongs to.');
+  }
+
+  function add_self_tokens(&$tokens, $item) {
+    $tokens['[' . $this->options['id'] . '-tid' . ']'] = $item['tid'];
+    $tokens['[' . $this->options['id'] . '-name' . ']'] = $item['name'];
+    $tokens['[' . $this->options['id'] . '-vid' . ']'] = $item['vid'];
+    $tokens['[' . $this->options['id'] . '-vocabulary' . ']'] = $item['vocabulary'];
+  }
+}
+
Index: userpoints_views_handler_filter_category.inc
===================================================================
RCS file: userpoints_views_handler_filter_category.inc
diff -N userpoints_views_handler_filter_category.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ userpoints_views_handler_filter_category.inc	3 Aug 2010 10:34:52 -0000
@@ -0,0 +1,13 @@
+<?php
+// $Id$
+/**
+ * Filter by category
+ */
+class userpoints_views_handler_filter_category extends views_handler_filter_in_operator {
+  function get_value_options() {
+    if (!isset($this->value_options)) {
+      $this->value_title = t('Category');
+      $this->value_options = userpoints_get_categories();
+    }
+  }
+}
\ No newline at end of file
