Hi,

I am showing a list nodes / corresponding users/ points and noticed by results were not distinct due to having two userpoints categories : 'points' and 'store credit' .

The $tid is not taken into account because there is no filter set :)
Editting the userpoints.views.inc is obviously the way to go, but i'm not sure how to reference the tid and fetch the different points taxonomy terms (categories_ from the db.

Any help? Think this is missing from the contrib!

Thanks

Comments

Milan0’s picture

Status: Active » Needs review

Uhm, actually that was quite simple. Just needed the correct views handler and a join that's it.
I'm not sure if this is the way to do it, and also not sure if its the correct way to contribute. (dont have a CVS acc (yet))

userpoints.views.inc

// $Id: userpoints.views.inc,v 1.1.2.4 2009/04/08 01:11:33 kbahey Exp $

/**
 *  @file
 *  This defines views hooks for the Userpoints module. It will be loaded automatically as needed by the Views module.
 */

/**
 * Implementation of hook_views_data()
 */
function userpoints_views_data() {
  // ----------------------------------------------------------------
  // userpoints table

  // Describe the userpoints table.
  // Define the base group of this table. Fields that don't
  // have a group defined will go into this field by default.
  $data['userpoints']['table']['group']  = t('Userpoints');

  $data['userpoints']['table']['base'] = array(
    'field' => 'uid',
    'title' => t('Userpoints'),
    'help' => t('!Points accumulated by users on your site.', userpoints_translation()),
  );

  $data['userpoints']['table']['join'] = array(
    'users' => array(
      'left_field' => 'uid',
      'field' => 'uid',
    ),
    'node' => array(
      'left_field' => 'uid',
      'field' => 'uid',
    ),
    'term_data' => array(
      'left_field' => 'tid',
      'field' => 'tid',
    ),
    // This goes to the node so that we have consistent authorship.
    'node_revisions' => array(
      'left_table' => 'node',
      'left_field' => 'uid',
      'field' => 'uid',
    ),
  );

  // Describe the points column of the userpoints table.
  $data['userpoints']['points'] = array(
    'title' => t('!Points', userpoints_translation()),
    'help' => t("A User's current !points.", userpoints_translation()), // The help that appears on the UI,
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
      'numeric' => TRUE,
      'name field' => 'points', // display this field in the summary
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  
    // Describe the points column of the userpoints table.
  $data['userpoints']['tid'] = array(
    'title' => t('!Userpoints Category', userpoints_translation()),
    'help' => t('The names of the points categories used', userpoints_translation()), // The help that appears on the UI,
    'field' => array(
      'handler' => 'views_handler_filter_term_node_tid',
    ),
    'argument' => array(
      'handler' => 'views_handler_filter_term_node_tid',
      'numeric' => TRUE,
      'name field' => 'category', // display this field in the summary
    ),
    'filter' => array(
  	    'handler' => 'views_handler_filter_term_node_tid',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // Add relationship to user table.
  $data['userpoints']['uid'] = array(
    'title' => t('User'),
    'help' => t('Relate the userpoints table to the user table.'),
    'relationship' => array(
      'base' => 'users',
      'field' => 'uid',
      'label' => t('Users'),
      'handler' => 'views_handler_relationship',
    ),
  );

  return $data;
}
kbahey’s picture

Status: Needs review » Needs work

Please create it as a patch against 6.x-1.x-dev, as described here http://drupal.org/patch

Milan0’s picture

StatusFileSize
new5.73 KB

Note: using diff ( -up), and seems to remove everything then add everything+ changes again.
Is it just diff, whitespace thing, or me ?:)

Milan0’s picture

StatusFileSize
new5.73 KB
Milan0’s picture

Status: Needs work » Needs review
kbahey’s picture

Status: Needs review » Fixed

Committed.

Should be in the tarball in about 5 hours from now.

Thank you.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.