It would be great if this module can integrate with userpoints. The idea is instead of the number of posts, the number of points will be used. This gives a broader picture of the user, for example, voting, inviting others, or the million other things that can award points.
So, I am posting here what needs to be done if someone is interested in this feature, so they can roll a patch, test it, and then submit it to this issue for merlinofchaos' review.
Example code is here:
if (module_exists('userpoints') {
$points = userpoints_get_current_points($uid)
}
// Do with $points what you want, have thresholds, create
// formulas, or what have you ...
Comments
Comment #1
merlinofchaos commentedThere's two things we have to do to make this work, but theoretically it's not that difficult, over all.
This module stores the total number of points separately so that it doesn't always have to count. This means that when an event happens that increases the number of points a user has, it has to reflect that in its counting. Is there a hook that I can respond to whenever a user gains points?
At that point, it becomes quite easy to have a checkbox to use userpoints, and if it's checked and userpoints is enabled, add those to the count as well.
Comment #2
michelleThis is the API from the readme... Will either of these work to hook into? I'd love to see this work with userpoints fo rmy site. :)
Michelle
Comment #3
dmitrig01 commentedwe'd probably want to rip out a) nodeapi and comment hooks, b) remove database tables, c) removing the node type settings, d) when checking for the # of points, use userpoints_get_current_points($uid).
Comment #4
merlinofchaos commenteddmitrig01: nonono. Just let userpoints add to the existing mechanism.
Set a flag "use userpoints". Then it's just another source. No ripping stuff out.
Comment #5
michelleChanging settings. There is no patch and also bumping the version.
Michelle
Comment #6
webchickThis is now a GHOP task: http://code.google.com/p/google-highly-open-participation-drupal/issues/...
Comment #7
ezyang commented(rm duplicate post)
Comment #8
ezyang commentedAssigning to self. Recon report coming soon.
Comment #9
ezyang commentedI'm disagreeing merlinofchaos's assessment that we need to hook with userpoints. Indeed, userpoints stores post counts so it doesn't have to recalculate them (by summing up the number of nodes the user has created), but this maps cleanly with userpoints' user point count. In fact, changing this "post count" would be undesirable because it would corrupt the previous data and make it impossible to revert back without truncating the cache table.
Patch is actually very simple. Extra credit, I suppose, would be making these changes extensible, so any backend can be substituted for post count.
Comment #10
ezyang commentedUpdated patch with JavaScript usability enhancements
Comment #11
ezyang commentedRevamped patch that implements an extensible interface using hooks. API.txt explains hook format.
Comment #12
ezyang commentedTypo-fix API.txt.
Comment #13
ezyang commentedUpdated patch that fixes a bug that crept back in during one of the revisions (namely, node count settings destruction).
Comment #14
michelleI haven't examined the code but, from a user's perspective, it works great. My only nit was it would be nice to change "posts" to "points" in the adding title section but ezyang said that would be difficult to do with translating. Otherwise, it works as advertised.
Michelle
Comment #15
webchickI haven't tested the patch itself, but I've been told Michelle did, so for now I'm just doing a code review.
Would be a bit more readable as:
...and would also conform to coding standards.
function user_titles_hook_module()is missing PHPDoc, and kind of needs it, since it's not quite obvious what's going on here at first glance. Maybe also rename it to something likeuser_titles_has_module_override()or something a bit more descriptive?Let's do something like:
Right now, it looks like if I had a malicious module that returned
<script>alert('st33lin j00r c00ki3z!')</script>as its name, the admin would be in big trouble on this page.$form_values['types-disabled']and the like... using a hyphen here looks odd to me. I believe everywhere in core these are underscores. I don't think there's anything particularly "wrong" about the hyphens, but there are API functions in 6 that anticipate this ID possibly being part of a function name, so I'd do underscores for consistency.Those look like interface strings, and if so they ought to be wrapped in t() so they can be translated.
Comment #16
webchickComment #17
ezyang commentedUpdated patch, addressing webchick's concerns.
Comment #18
webchickOk, one more *super* minor revision round, and then I'm marking this RTBC:
-$form['hook-module'] -> please change those to underscores rather than hyphens.
I changed my mind. ;) How about:
... and just have it return NULL if there's nothing found? This is a bit more succinct.
Then I'd do..
Finally,
Can't that be written as:
?
Ok, I'm seriously done nit-picking now.
Comment #19
ezyang commentedFinal revision. Really. :-)
Comment #20
ezyang commentedOk, I redact my previous statement. Fix broken help link bug.
Comment #21
ezyang commentedTwo more fixes: units is now hookable, and userpoints needs to implement the hook on their own so that we can get rid of our implementation.
Comment #22
webchick*Awesome* work, ezyang! Way to go above and beyond. :)
Comment #23
Flying Drupalist commentedCan someone commit this please so that those of us who can't patch have access to it.
Comment #24
agileware commentedThanks for the great patch.
This has been added to 5.x-1.0