Hi,
I award user different types of points. I would like to create a table using the views UI showing points earned by members in each category. So it will be something like this:

Username | category 1 points | category 2 points | category 3 points
xyz 100 50 20

Has anybody done this using the views UI? I am able to create a table for any one category, but don't know how to do it for multiple categories in the same block or page display.

Thank you.

Comments

rogical’s picture

seems not supported currently, I also want to create several points categories.

like one for nodes operations (crud, commenting), another for user credits (authentication for mail, mobile, personal ID etc)

berdir’s picture

Status: Active » Fixed

This should be possible by starting off with a user view and then adding multiple userpoints relationships to it, each with a different category filter.

Status: Fixed » Closed (fixed)

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

rerooting’s picture

Where do you add the category filter to the relationships? Cannot find this option.

eminencehealthcare’s picture

I also do not see a relationship for userpoints: category

eminencehealthcare’s picture

Status: Closed (fixed) » Active

I would like to re-open this issue because it is important to me.

queryblitz’s picture

Not sure if this helps anyone, but I just wrote it and it might:
Display User's Points of Specific Category in a Block on Content Profile

WorldFallz’s picture

did anyone get this sorted? I'm not seeing anywhere in any of the options (filters, fields, relationships, etc) where I can narrow down the points to a specific category.

PatchRanger’s picture

Version: 7.x-1.0 » 7.x-2.x-dev
Category: support » task
Status: Active » Needs review
StatusFileSize
new3.31 KB

I guess I've found the solution.

For example, given three userpoints categories.
Receipt:
1) Create 3 "Userpoints: User" relations.
2) Add 3 "Userpoints: Current $ in category" fields and make each of them to use different relation.
3) Add 3 "Userpoints: Points category" filters and (again) make each of them to use different relation.
4) Set each filter to filter "Is one of" of differrent userpoints categories.
5) Enable "Distinct" setting in "Query settings".
I guess it is what Berdir meant by #2.

The problem here is that if the user misses even just one single userpoints category balance - it won't be shown at all. I failed to find a way to establish LEFT JOIN with userpoints categories (terms of "Userpoints" vocabulary) as left table.
That is definitely a problem in my own use case - so let me introduce a patch that intends to fix it.
It adds 0 points to each of the existing users to each of the existing Userpoints category - and has hook to do the same each time when a user or a term of Userpoints vocabulary is created.
It makes the view to work as expected.
Please review.

Status: Needs review » Needs work
guybrush’s picture

I found the patch above (#9) didn't work in the cases where there were no entries in the userpoints_total table. The following is a slightly modified version that solved this problem for me:

function userpoints_fill_default_userpoints($uids = array(), $tids = array()) {
// Prepare uids.
if (empty($uids)) {
$uids = array_keys(user_load_multiple(FALSE));
// Skip anonymous.
unset($uids[0]);
}
// Prepare tids.
if (empty($tids)) {
$userpoints_vocabulary = taxonomy_vocabulary_machine_name_load('userpoints');
// Get all of the userpoints categories.
$userpoints_categories_wo_default = taxonomy_get_tree($userpoints_vocabulary->vid);
foreach ($userpoints_categories_wo_default as $userpoints_category) {
$tids[$userpoints_category->tid] = $userpoints_category->tid;
}
// Add default category.
$default_tid = userpoints_get_default_tid();
$tids[$default_tid] = $default_tid;
}
// Support passing just values as well as arrays.
foreach ((array)$uids as $uid) {
foreach ((array)$tids as $tid) {
$points = db_query('SELECT count(points) as points_count FROM {userpoints_total} WHERE uid = :uid', array(':uid' => $uid))->fetchField();
if (!$points) {
db_insert('userpoints_total')
->fields(array(
'uid' => $uid,
'points' => 0,
'max_points' => 0,
'last_update' => REQUEST_TIME,
))->execute();
}

$points = db_query('SELECT count(points) as points_count FROM {userpoints} WHERE uid = :uid AND tid = :tid', array(':uid' => $uid, ':tid' => $tid))->fetchField();

if (!$points) {
db_insert('userpoints')
->fields(array(
'uid' => $uid,
'tid' => $tid,
'last_update' => REQUEST_TIME,
))->execute();
}
}
}
}

PatchRanger’s picture

Status: Needs work » Needs review
StatusFileSize
new3.59 KB

@guybrush Thanks for reasonable notes.
Here is the slightly improved version of what you told.

Status: Needs review » Needs work
bsarchive’s picture

Issue summary: View changes

What would be great if the userpoints field handler in Views and the userpoints relationship handler in views asked to specify which points category was being selected, which would go into the ON part of the LEFT JOIN, rather than the WHERE clause. As in

SELECT users.name, userpoints.points
FROM {users} users
LEFT JOIN {userpoints} userpoints ON userpoints.uid = users.uid AND userpoints.tid = [specify tid here]