Closed (fixed)
Project:
User Points
Version:
7.x-1.x-dev
Component:
Code: userpoints API
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
31 Oct 2010 at 15:14 UTC
Updated:
11 Apr 2011 at 23:01 UTC
Jump to comment: Most recent file
Comments
Comment #1
berdirOk, attaching an initial patch.
This basically declares tons of tokens for two categories:
- points/maxpoints tokens for user entities. This already existed but has not been ported from D6. Note that you can choose a specific category or all for example with user:points:category-1 or user:maxpoints:all but that will currently not be displayed in the rules UI because it does not display tokens hierarchically like token.module does, see #1032356-5: Add token replacement support for non-entities.
- Defines tokens for userpoints_transaction. I haven't tested everything, but that is basically how it works. That's what the initial issue was about. I've only tested that this basically works and by far not all possible tokens. So there is a lot of testing necessary. I guess the names and descriptions can use some work too.
Comment #2
berdirNew patch, this one should work. The other one used a wrong name for the transaction tokens.
Comment #3
BenK commentedJust got done testing the latest patch. It's a lot of nice functionality. Just some bugs to work out.
To test, I set up a rule on the "User was awarded points" event. I set up an action to "Send a private message". And then I included all of the available tokens that were visible in the UI, plus the current points and max points that you suggested in your comments. I then used the regular "Add points" form to trigger the event.
Here were the notices I received after submitting the "Add points" form:
And here were the results I got in my sent private message:
I just wanted to show you my results first. I'll itemize the bugs to look at in a subsequent comment.
--Ben
Comment #4
BenK commentedSo here is my bug to-do list based on the above results:
1. The [userpoints_transaction:user] is displaying the words "Property name" instead of the actual username.
2. The [userpoints_transaction:tid] is displaying the category id instead of the actual category name. This may not be a bug. But can we have a token for the actual category name available too? Also, if the points award is in the "General" category no category id shows up (since it doesn't have one). Maybe we need a special case for this?
3. The [userpoints_transaction:time-stamp] token is completely blank. Nothing is returned.
4. If an expiration date is not set for the transaction, the [userpoints_transaction:expirydate] token is displaying a Dec. 31, 1969 date.
5. I can't get the current points and maxpoints tokens to work. I tried this: [userpoints:points:category-1] and [userpoints:maxpoints:all]. Am I entering these wrong or is this a bug?
6. All of the notices described above are appearing after submitting the "Add points" form.
7. It would nice if there were a token that specified a negative points transaction as a positive value. This way you could write a subject that says "You lost 8 points." You can't currently do this because the points will always be displayed as -8. Also, it would be nice to have a token that said either "gained" or "lost". This way, you wouldn't have to specify a rules condition for a positive or negative points award and configure separate messages for each. But just a thought... this may not be feasible.
In addition to these bugs, I also noticed the following PM additional items while doing my testing. I am reporting on this issue to be complete, but I can make some new issues in the Private Message issue queue:
PM a) On the "Private Message Author" field, can we have a "Switch to direct input mode" button? This way, the message could be from a user who serves as the site administrator.
PM b) The "Private Message Subject" field is too short in length (both visually and in the number of characters that can be included). Once we start adding tokens here, it eats up characters very fast. We should lengthen it.
--Ben
Comment #5
berdirSome preliminary feedback:
5. These are tokens on the user not on the transaction (a transaction doesn't have total/max points). So you'd need to use userpoints:user:points:category-1 but userpoints:user seems to be broken (your point 1) for some reason. I think I've tried that though, strange.
6. Should be possible to add something like userpoints:absolute-points, will investigate.
7. Not sure about that. Might result in more problems than it solves, just like the old default userpoints status message. Instead, what about providing a token that is basically the same as the one that is displayed by default when you gain points? Something like userpoints:message.
PM stuff) Yes, please open separate issues for that there. I assume for b) you just mean the field in the privatemsg rules integration form, not the actual resulting subject that is displayed?
Comment #6
berdirOk, new patch.
1. Fixed, it wasn't correctly loading the user.
2. tid is now a token of type term, meaning that you can do stuff like userpoints:tid:tid or userpoints:tid:name. userpoints:tid is the same thing as userpoints:tid:name now. Note that for the general category, only tid and name will work. The only way to implement the others would be to create a real term for the general category and that is something to think about in a separate issue. Not sure if it's worth doing that.
3. Fixed.
4. Expiry date now displays t('Never') if 0, just like the transaction view page.
5. See above.
6. Fixed.
7. Added a "points-abs" token for the absolute value. As suggested above, we can think about adding a message token but I'd like to do that in a follow-up issue.
Comment #7
berdirComment #8
BenK commentedI've begun testing of the latest patch and noticed that the new "points-abs" token is causing the following notice:
Notice: Undefined property: stdClass::$points-abs in userpoints_tokens() (line 477 of /Users/benkaplan/git/drupal-7.0/sites/all/modules/userpoints/userpoints.module).
--Ben
Comment #9
BenK commentedI've conducted more testing and confirmed that 1, 2, 3, 4, and 6 are now all fixed.
So in addition to the notice mentioned in comment #8 above, here is the one item left to do:
5. I still can't get the category points total token or maxpoints token to work. I've tried using [userpoints:user:points:category-1] and [userpoints:user:maxpoints:all] as my tokens, but they come back as an Invalid Token. Do those tokens work for you?
--Ben
Comment #10
berdir- Fixed the notice.
- You need to use [userpoints_transaction:...] just like all other tokens. There was however a bug, that should be fixed now.
Comment #11
BenK commentedI've tested the latest patch and things are working very well. The notice is gone and the [userpoints_transaction:user:points:category-1] and [userpoints_transaction:user:maxpoints:all] tokens are working well.
Just one new thing I noticed:
I tried to create a chained token to give me the uid of the user being awarded points (something very useful, for instance, for constructing a URL to the user's points summary page). To do this, I tried using the following token:
[userpoints_transaction:user:uid]
But when this token was evaulated, here is what printed in my private message:
Property uid
So am I doing this correctly? Or is this a bug? We probably need some way to get the uid for the purpose of constructing URLs.
--Ben
P.S. Also, one small typo I noticed: In the description for the display token, "Wether" should be spelled "Whether".
Comment #12
berdirThat's not our problem :) I'm just passing the user object forward, I don't deal with uid's at all. This is a rules issue. There is already an issue open about a related problem... It was #915058: Add a 'no_unwrap' option to parameters, the follow-up questions I asked there. I suggest you create a new issue there. The problem is that $user is a wrapped entity, so try creating an issue like "Token don't work with wrapped entities" and then point to this and the other linked thread. You probably want to create this issue against the entity module, actually...
Will fix the typo and then commit this later...
Comment #13
BenK commentedThanks for the explanation. I created an issue in the Entity issue queue here:
http://drupal.org/node/1108598
And will look forward to the commit when you have a chance! ;-)
--Ben
Comment #14
berdirCommited, thanks for testing.