Any chance there are plans for Views support? Would be great to be able to create views based off the Top Contrib tables -- particularly creating a variety of different blocks/pages based on time ranges, as well as adding user picture support.

Comments

glitz’s picture

any update on this?

YK85’s picture

subscribing

BeaPower’s picture

Sub

aaronbauman’s picture

+1

frognation’s picture

I thought I'd post here what I did with views to display points of last week and last month from the current date in Views 2 without using userpoints_top_contributors in case the subscribers of this thread would be interested.

  1. Create new users view
  2. Add a custom field that executes PHP (I used views_customfield, views_php works too)
  3. Input this PHP code for the value:
    <?php
    $result = db_query("select points from userpoints_txn where unix_timestamp(date_sub(curdate(), interval 1 week)) < time_stamp and uid = '%d'", $data->uid);
    
    while ($row = db_fetch_array($result)) {
      $points = $points + $row['points'];
    }
    
    return $points;
    ?>
    

    Change interval 1 week to 1 month if you want the previous month's points. Also this is for the views_customfield module, so you might have to replace $data->uid with something else if you're using the views_php module.

  4. If you're sorting by this custom field, you need to use the table view!

aaronbauman’s picture

Instead of creating an additional SQL query for each item returned from the view, I used a hook_views_query_alter() like so:

function my_module_views_query_alter(&$view, &$query) {
  if ($view->name == 'my_view_name' && $view->current_display == 'applicable_display') {
      $table = $query->ensure_table('userpoints_txn');
      $alias = 'my_module_user_activity_weekly';
      $fieldname = $query->add_field(NULL, "SUM($table.points)", $alias);
      $query->orderby[] = $alias . ' DESC';
      $where = "$table.time_stamp > UNIX_TIMESTAMP(CURDATE() - INTERVAL 1 WEEK)";
      $query->add_where(NULL, $where);
  }
}

Replace "my_module", "my_view_name" and "applicable_display" with the appropriate values.
You can adjust the timeframe however you'd like.

mrwhizkid’s picture

Hi --- thanks for this but I'm a bit confused. I made a custom module with this and activated it.

But this is where I get lost:

Should I use this in conjunction with the code in #5?

OR with a specific field in my views display?

Thanks in advance.