This thread is in follow-up to our discussion here: http://drupal.org/node/637584.

Here are the current userpoints_views integration bugs I noticed:

Trying to add Userpoints-related fields to views doesn't work yet. In particular, trying to add fields like "Userpoints: Points," "Userpoints: Max points," and "Userpoints: Userpoints Category" to a view results in the following fatal error:

PHP Fatal error: Call to undefined function vpr() in /Users/benkaplan/git/drupal/sites/all/modules/views/handlers/views_handler_field.inc on line 99

Also, I'm getting the following warning message within the Views admin area when adding the above fields:

Debug: 'Missing join: node users' in views_get_table_join() (line 95 of /Users/benkaplan/git/drupal/sites/all/modules/views/includes/handlers.inc).

However, a few fields do seem to be working. These are mostly ones in the "Userpoints Transactions" group including:

* (Users) Userpoints Transactions: Description
* (Users) Userpoints Transactions: Changed
* (Users) Userpoints Transactions: Points
* (Users) Userpoints Transactions: Timestamp

Some other Userpoints Transaction fields, however, are reporting "Broken/missing handler" in the Views UI.

--Ben

Comments

BenK’s picture

Here is a response from Berdir that was posted on the other thread:

At least the category field wrongly re-uses term_node views handler, that obviously doesn't work. And vpr() seems to be an internal views debug function that was removed and that call has been forgotten to remove. I suggest you open a bug report for Views 7.x-1.x. If that line is commented out, then at least the Userpoints (Haven't tested transactions) points work except category which is empty.

BenK’s picture

In follow-up to Berdir's comment about vpr(), I created a new Views 7.x-3.x-dev bug report here:

http://drupal.org/node/871134

--Ben

BenK’s picture

Just saw that the vpr() bug in Views 7.x-3.x-dev was fixed and committed here: http://drupal.org/cvs?commit=401330

Thanks, Berdir, for suggesting that I file the issue!

--Ben

BenK’s picture

I upgraded to the latest Views 7.x-3.x-dev release and can confirm that I can now add fields like "Userpoints: Points" and "Userpoints: Max points". As expected, category still doesn't work.

--Ben

berdir’s picture

Status: Active » Needs review
StatusFileSize
new7.37 KB

Try the attached patch. Make sure to empty the cache and submit admin/modules.

Field display, filter and argument seems to be working. By choosing the taxonomy term validator, you can even convert the term name to an id and use the category name instead of the id in URL's.

BenK’s picture

Status: Needs review » Needs work

I tried out the patch in #5 and things are working a lot better! I created views of various types, including userpoints views, node views, user views, and userpoints transaction views. They all worked well.

Here are the outstanding bugs/issues I noticed:

A. When creating a "User" view type, there is still a bug with the Userpoints category field. The category is not displaying and the following error are displayed at the top of the page:

Debug: 'Missing join: taxonomy_term_data users' in views_get_table_join() (line 95 of /Users/benkaplan/git/drupal/sites/all/modules/views/includes/handlers.inc).

Debug: 'Handler userpoints_views_handler_field_category tried to add additional_field name but taxonomy_term_data could not be added!' in views_handler_field->add_additional_fields() (line 99 of /Users/benkaplan/git/drupal/sites/all/modules/views/handlers/views_handler_field.inc).

Notice: Undefined property: stdClass::$broken in views_handler_field->render() (line 462 of /Users/benkaplan/git/drupal/sites/all/modules/views/handlers/views_handler_field.inc).

Note that the errors don't occur is you do a "userpoints" view type. The errors only seem to be occurring if you do a "user" or "node" type view.

B. When creating a "Userpoints" view type, I noticed that the "Last update" and "Userpoints category fields are not sortable (the option is missing in the Views config). Is it possible to make these sortable?

C. When creating a "Userpoints" view type, any data comparison besides "is equal to" is not working. For example, if you try to filter by the "points" field being greater or equal to 10, it won't work. It looks like you can enter it initially, but then it won't save and the field to enter the number becomes missing. I'm not sure if this is a bug in the code or a bug with Views. (If it's the latter, let me know and I can report it.)

D. Is is possible to have 'total approved userpoints' (total points across all categories) and 'net userpoints' (total approved points plus points in moderation) available as fields in all view types (especially user and node views)? These are displayed on a user's points page and it would be nice to have them available in a view. I think the 'total approved userpoints' would be, perhaps, the most widely used field in many use cases.

E. The anonymous user is showing up as a user with points. To remove it via views config, you have to filter against it. Not a big deal but I thought I'd mention it in case there is any way to suppress the anonymous user.

F. When creating a "Userpoints transaction" view, the only field that is sortable is the "points" field. Is it possible to make the other available fields sortable? Currently, those fields do not have a "sortable" option in the Views config.

G. When creating a "Userpoints transaction" view, is there any way to have the description field evaluate as HTML rather than plain text? The reason I ask is that I have HTML tags in the Description from when points are generated by rules. This works great on native Userpoints tables (the HTML is properly evaluated), but on userpoints transaction views the HTML tags are displayed. I even tried the views option to "strip HTML tags," but this option didn't seem to work. This might be a views module issue, but I thought I'd mention it.

We're getting close here... probably one more patch/testing pass and we'll be done with this! :-)

--Ben

P.S. I'm not exactly sure how to configure the "taxonomy term validator" that you mentioned in #5. I haven't previously used validators in views and I'm not exactly sure what they do. If you let me know how to configure this, I can test. ;-)

BenK’s picture

Bumping this so I don't lost track of it....

BenK’s picture

Bumping this because it's one of the few remaining issues before a 7.x-alpha1 release of Userpoints...

BenK’s picture

Here is an update to bug A in comment #6 above:

When making a view of type "Userpoints Transactions"), the "Userpoints Transactions: Userpoints Category" field also isn't working properly. In the Views config, the following message is displaying: "Broken handler userpoints_txn.tid"

And then when actually displaying the view, the following errors are appearing:

Debug: 'Missing handler: userpoints_txn tid field' in views_get_handler() (line 733 of /Users/benkaplan/git/drupal-dev/sites/all/modules/views-DRUPAL-7--3/views.module).

Notice: Undefined property: stdClass::$unknown in views_handler_field->render() (line 462 of /Users/benkaplan/git/drupal-dev/sites/all/modules/views-DRUPAL-7--3/handlers/views_handler_field.inc).

--Ben

BenK’s picture

One of the last few issues remaining before a 7.x-alpha1 release...

robby.smith’s picture

subscribing

robby.smith’s picture

I'm looking for the views category field fix for d6 version. Will this patch possibly be back ported in the future?
Regards

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new4.45 KB

@robby.smith: Looks like the fix for d6 is simple, see #990620: UP Views: Broken/missing handler: userpoints_txn > tid

A. The patches fixes this. No idea why it's necessary, this all seems strange.

B. Can't reproduce, works for me. They fields are displayed and they work.

C. Confirmed, that seems to work sometimes and then it's broken again. But it has nothing to do with userpoints, it happens in all views and with alll integer fields. I looked for a existing views bug but didn't find one, I suggest you open one.

D. There is a separate feature request for that already existing.

E. That's something that you need to take care of when building the view, I don't think we should add any special cases and I wouldn't know how to anyway :)

F. Another issue that seems to work sometimes and doesn't anymore right now. No idea why that is, the all the fields can be sorted on with a static sort...

Term Validator: Add Category argument, Validator: Taxonomy Term, select Userpoints vocabulary, Argument type: Taxonomy name/synonym converted to Term ID. Note that it will for example not work for everything, for example General because that's not actually a term.
Attaching a new patch.

PS: Remember to clear the cache..

Status: Needs review » Needs work

The last submitted patch, views_category2.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new1.01 KB

Can't create a proper patch, cvs is messing around.

Unzip this into the userpoints folder, clear cache and try again.

BenK’s picture

Status: Needs review » Reviewed & tested by the community

Hey Berdir,

Just got done testing the latest patch (including what you posted in #15). Everything is working great (except for things that are Views module bugs). I was able to add the Category as a field without any errors. So nice work! This is RTBC.

--Ben

berdir’s picture

Status: Reviewed & tested by the community » Fixed

Commited!

gausarts’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Fixed » Active

Sorry to set it back active. Should I create a new post to request a 6.x backport? The title applies, but changing version to reflect a request for backport if allowed.

Thanks

berdir’s picture

For what exactly do you want a backport?

Did you see #990620: UP Views: Broken/missing handler: userpoints_txn > tid which seems to solve the broken/missing handler error for 6.x-1.x?

gausarts’s picture

Status: Active » Fixed

Ah, I must have missed the obvious. Setting it back to fixed now. Sorry for interruption.

Thanks.

Status: Fixed » Closed (fixed)

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

berdir’s picture

Status: Closed (fixed) » Patch (to be ported)

Looks like this needs to be backported, the referenced issue does not seem to actually fix the problem.

soulfroys’s picture

This backport will save the world! (http://drupal.org/node/1018984#comment-3976896)

Thanks in advance!

MasterChief’s picture

Subscribe.

angelammi’s picture

Also subscribing.

berdir’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new6.76 KB

Ok, please test the attached patch.

Remember to clear the cache.

YK85’s picture

Status: Needs review » Reviewed & tested by the community

No one else is using this? This is great! Many many fixes!
You guys make a great team BenK and Berdir!

berdir’s picture

I only posted the patch 24h ago, so it's not surprising that nobody else is using it yet (or at least reported back).

Anyway, thanks for testing!

soulfroys’s picture

I will test it today or tomorrow... I will report asap.

Thanks for this patch!

berdir’s picture

Status: Reviewed & tested by the community » Fixed

Commited.

soulfroys’s picture

StatusFileSize
new4.18 KB

@Berdir, I still can't show categories in this simple view... please, did I miss something?

Versions:
Drupal 6.14
Views 6.x-2.11
Userpoints 6.x-1.x-dev (February 21, 2011)

berdir’s picture

Status: Fixed » Active

It looks like it always shows the default category, will have to investigate.

Setting back to active.

NaX’s picture

I have just run into the same problem with the latest dev.

It looks to me like views_handler_field_term_node_tid.inc joins are not working correctly.

If I comment out query() function I get a users_userpoints__userpoints_txn.tid AS users_userpoints__userpoints_txn_tid field in my SQL, with the query() function in I don't get a tid field.

I think the joins need to be re-looked.

NaX’s picture

I am not very good at views development and have very little experience but I played around with things a little and I think maybe the tid fields (userpoints and userpoints_txn) should have a relationship added to their filed definition.

EG:

  // Describe the tid column of the userpoints table.
  $data['userpoints']['tid'] = array(
    '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' => 'userpoints_views_handler_field_category',
    ),
    'argument' => array(
      'handler' => 'userpoints_views_handler_argument_category',
      'numeric' => TRUE,
      'name field' => 'category', // display this field in the summary
    ),
    'filter' => array(
      'handler' => 'userpoints_views_handler_filter_category',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'relationship' => array(
      'handler' => 'views_handler_relationship',
      'base' => 'term_data',
      'field' => 'tid',
      'label' => t('Userpoints Taxonomy Category'),
    ),
  );

I also removed the query() function from views_handler_field_term_node_tid.inc.

All this only started having an effect once I added the Category/Taxonomy relationship to my view and then setting the fields to use the relationship and in some configurations the category worked. In other configurations I also got errors for many of the userpoints_txn fields.

EG: "Column 'entity_id' in field list is ambiguous query" and "Column 'expired' in field list is ambiguous query".

I also tried adding the Entity id relationship but for some reason I could not use it as expected.

I feel like this views integration is so close to being complete/usable, but unfortunately I don't have skills or knowledge to complete it.
Hopefully somebody else will have better luck.

rbayliss’s picture

StatusFileSize
new2.82 KB

I think you need to add the term_data join to the actual term_data table, since userpoints is the base table. I could be wrong, but adding:

function userpoints_views_data_alter(&$data) {
  $data['term_data']['table']['join']['userpoints'] = array(
    'field' => 'tid',
    'left_field' => 'tid',
    'left_table' => 'userpoints'
  );
}

to the patch above worked perfectly for me. Rerolled patch from #26 to incorporate this change.

berdir’s picture

Status: Active » Needs work

Yeah, that's what I had to do for the in the 7.x patch too.

Note that you can also define this in hook_views_data(), it will automatically be merged.

Also please add the same for the userpoints_txn table.

NaX’s picture

I have had another look at this and here are some of the changes I have made.
I wanted to submit a patch, but WinMerge and I are having issues, I think its an encoding issue (creating patches on Windows is retarded compared to Linux/BSD), so here are my changes the stupid way.

In userpoints.views.inc I added the a join on userpoints.uid, I don't know if this was needed but I was getting some SQL errors.

  $data['userpoints_txn']['table']['join'] = array(
    'userpoints' => array(
      'left_field' => 'uid',
      'field' => 'uid',
    ),
    'users' => 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',
    ),
  );

In userpoints.views.inc I added a join on userpoints_txn as suggested.

/**
 * Implements hook_views_data_alter().
 */
function userpoints_views_data_alter(&$data) {
  $data['term_data']['table']['join']['userpoints'] = array(
    'field' => 'tid',
    'left_field' => 'tid',
    'left_table' => 'userpoints'
  );
  $data['term_data']['table']['join']['userpoints_txn'] = array(
    'field' => 'tid',
    'left_field' => 'tid',
    'left_table' => 'userpoints_txn'
  );
}

In userpoints_views_handler_field_category.inc I removed the init() function and altered my query() function to added the txn name field. I dont know why the init() function additional fields was not working, but moving it to query() fixed my problems. Maybe its because I am using views2.

  /**
   * Add this term to the query
   */
  function query() {
    $this->additional_fields['name'] = array('table' => 'term_data', 'field' => 'name');
    $this->ensure_my_table();
    $this->add_additional_fields();   
  }  

I hope that helps.

EmanueleQuinto’s picture

Well, I found the bug working with:

  • Userpoints (userpoints) - 6.x-1.2
  • Views (views) - 6.x-2.12

I solved redefining 'tid' with a simple relationship to term_data in userpoints.views.inc and using the fields from the new relationship ('Terms') :

  $data['userpoints']['tid'] = array(
    'title' => t('Userpoints Category', userpoints_translation()),
    'help' => t('The categories (terms) of userpoints used', userpoints_translation()), // The help that appears on the UI,
    'relationship' => array(
      'base' => 'term_data',
      'field' => 'tid',
      'label' => t('Terms'),
      'handler' => 'views_handler_relationship',
    ),
  );

I'm wondering if this could be a better approach: less code, less problems...

brunorios1’s picture

subscribing...

marcn’s picture

Category: bug » support

I apologize in advance for making this posting in the middle of what appears to be a hot and heavy search for a fix, but I am confused trying to follow all these comments. I don't write php code and am just trying to get the userpoints module to work with views.

I need to get the Points Category to display (using a userpoint transactions view as my starter) and only the default category seems to show no matter what I try. It's hard to tell from all the chatter here but has this been fixed through a patch or something? I am using Drupal 6.22, PHP 5.2.17, userpoints 6.x-1.x-dev and views 6.x-2.12.

Is there something about the 'relationships' settings under view that I need to do to make the categories work?

If this has not been fixed yet, I'll wait patiently but if it has been addressed, please let me know where to look to apply a patch or whatever.

Thanks,

Marc

NaX’s picture

@marcn
I got it working using the code posted at #37. The files were these changes are is userpoints_views_handler_field_category.inc and userpoints.views.inc.

It looks like the suggestion at #38 could work but I did not try it. With the code from #38 you will need to add a relationship for it to work. In this case the suggested code is changing the $data['userpoints']['tid'] tid field array definition.

There is no consensus on what would be best yet. I would try #38 first because it is simpler.

berdir’s picture

We can't just make it a relationship. Because that breaks the default category, that is not actually a term and will therefor not display anything.

avatxus’s picture

Hi, Any updates on a D6 working patch?

Thanks!
Alejandro

avatxus’s picture

Hi,

Just my 2 cents. Not a fix, but workaround for those who need this to work.
I needed to show the points splitted into categories, and any user could see each other points. I couldn't make this work through views and the category relationship after applying the patches and code above.

I could show categories and points per category in views by using the http://drupal.org/project/views_php module and executing the code below.
Steps:
1) add a relationship or a field that includes the uid so you get the uid variable available
2) add a Global: PHP field
3) In the Output code, added this code

$uid = $row->sender; //check for your available variables to get the uid
$up_categories = userpoints_get_categories();
$total_points = userpoints_get_current_points($uid, 'all');
print "Total points: " .$total_points. "<br />";

foreach ($up_categories as $category => $value){
  // don't show uncategorized points
  if ($category != '0'){ 	
    $points = userpoints_get_current_points($uid, $category);
    print $value . " " . $points . "<br />";
  }
} 

I know this doesn't fix the bug in any way, but it might help someone needing this now.

teinomana’s picture

Any news regarding this bug?? I'm not a coder, but I really need the categories to work in views under Drupal 6.2. Is there anyone who could find a more or less clean solution? I've tried the code patches in the thread, and I get this message when trying to create a category field:
"Error: handler for userpoints > tid doesn't exist!"

Really, any help would be appreciated!

manuel.adan’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Closing this as outdated, 6.x version is no longer maintained.