Closed (fixed)
Project:
User Points Contributed modules
Version:
7.x-1.x-dev
Component:
Code: userpoints_cap
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
20 Apr 2011 at 21:30 UTC
Updated:
21 Jul 2011 at 21:02 UTC
Jump to comment: Most recent file
Comments
Comment #1
Bastlynn commentedFirst round attached.
Comment #2
berdirLooks good, just some minor issues...
The break should be intended two spaces, on the same level as the code inside the switch, I think.
The == TRUE part is unecessary. What happens is that the return value of the variable_get() call is casted to a boolean value, compared with TRUE which again results in a boolean value which is then checked by the if(). So that part is unecessary.
The problem with ucfirst/lcfirst is that it might not work so well in non-english languages. Not sure how to do it better, though. And they can always directly use the category name directly.
Also, the text should probably not be translated at all. Instead, multi-lang variables should be used with help of i18n.module.
Powered by Dreditor.
Comment #3
berdirComment #4
Bastlynn commentedI'm very hesitant to introduce a dependency on another module where it's a string that the end user can just change arbitrarily, especially when that behavior isn't reflected in the other sub modules as well. I'd like to be consistent with these. Is i18n something all of the sub modules will be picking up as well?
Comment #5
berdirYou do not need to add any dependency. I18n can be configured to make any variable translatable and will automatically display the string depending on the user language. All you need to do is not calling t() (t() should never be called with dynamic strings anyway, it is just not designed for that).
If users only have a single language, they can enter the text in whatever language they want. And for a multisite, they can configure i18n.
Comment #6
Bastlynn commentedHm. As things stand the way the message goes into t() doesn't take advantage of the XSS security t() offers, so just dumping the message directly to drupal_set_message() isn't any worse in those regards. And the admin can set the message to be properly point branded and include the cap information, so we're not losing anything there either.
I'm not familiar with the i18n module - is there anything I would need to do to make use of it other than just replacing the call to t() and drupal_set_message() with:
drupal_set_message(variable_get('userpoints_cap_message_' . $params['tid'], 'Points are limited to a maximum number. You must spend points to earn more.'));
Comment #7
berdirHm, yeah, I forgot about the parameters. One solution would be to use strtr() for the replacement, just like t() does if locale.module is not enabled. See http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/t/7
Something like this (translatable, configurable strings, especially with placeholders) is currently a real issue, there is no nice solution for it that I know of.
Comment #8
Bastlynn commentedstrtr() works for me, it'll allow the admin to rebrand without much worry about the configurations. Since we aren't getting any of the other advantages of t(), I see no reason not to use strtr().
Comment #9
Bastlynn commentedUpdated patch.
Comment #10
BenK commentedHey Bastlynn,
The functionality of the module works well. I didn't notice any obvious bugs when testing.
I'd just suggest the following string changes:
a) For the field labels in the settings, I think it may be better to put the category first and keep them shorter (since there's a description for each setting anyway). I'd suggest:
"General category cap"
"General category message"
b) Here's a suggestion for a more direct default message for each category:
"You may not have more than !cap !points in the !Category category. You must use !points to earn more."
c) The description for each message settings seems kind of long (3 lines in Seven theme), which doesn't look great. To shorten, I'd suggest:
"The message a user will see if they exceed the cap. Available replacement values include !Points, !points, !Point, !point !Category, !category, and !cap."
Thanks for your work on this,
Ben
Comment #11
Bastlynn commentedThanks muchly. I'll get this set up in the morning as well. :)
Comment #12
Bastlynn commentedUpdated with new messages (thank you) - and fixed the uninstall function name.
Comment #13
berdirMinor: Please move comments on a separate line, always start with // and then an uppercase character and end with a .
Also, another idea that I just had. Say the cap is at 5000 points, someone has 4997 points, is granted 5 points. Instead of simply denying the points transaction, we could change it to 3 points and only grant that so that he exactly reaches the cap. $points can be per reference now, so that should be possible to do.
And yet another idea from #985948-6: Create a "Flood control" sub-module to limit points that can be added/deducted over a configurable amount of time, we might want to make the action configurable, so that instead of just blocking, you could also insert the points, but with status pending or declined.
Powered by Dreditor.
Comment #14
berdirFixed the comments, tested it and commited.
My ideas in the last comment could be done as follow-up issues.
Comment #15
Bastlynn commentedThank you Berdir - I've been getting swamped at work and haven't gotten a chance to put attention on these that I wanted to.