Hi all,
Is there a way to NOT remove all storage data when an achievement is taken away?
I'm asking this because I've encountered an issue as described in the following:
USE CASE EXAMPLE:
- users gain achievements after 5, 50 and 100 comments
- suppose a user has already gained the "posted 5 comments"
- suppose a moderator, for any reason, have to delete last (the fifth) comment
- the "posted 5 comments" achievement should be automatically removed, but the total comment count should not be resetted (in this way, user can re-take the achievement posting another "fifth" comment)
To do so I've implemented hook_comment_delete:
function mymodule_comment_delete($comment) {
// decrease comment count
$current_count = achievements_storage_get('comment-count', $comment->uid) - 1;
achievements_storage_set('comment-count', $current_count, $comment->uid);
foreach ( array(5, 50, 100) as $count ) {
if ( $current_count == $count - 1 ) {
// re-lock achievement:
achievements_locked('comment-count-' . $count, $comment->uid);
}
}
}
but the code above doesn't work because achievements_locked() removes all storage data and "comment-count" is resetted. All user's previous comment count is lost.
Please give me some advice to reach the goal (or is this a feature request?)
Thank you very much
MXT
Comments
Comment #1
morbus iffEasier than you think, actually - just move your
to after you run achievements_locked().
Comment #2
morbus iffStill, it's a valid feature request, I think.
I'd do with a $reset pattern.
Comment #3
mxtThank you Morbuss Iff, I've applied your workaround: thanks!
And yes, an optional "reset" parameter would allow us to manage more efficiently this kind of tasks.
I think that something like:
function achievements_locked($achievement_id, $uid = NULL, $reset = TRUE) {
...
}
could do the trick.
Thank you for considering this! And thank you for your fantastic module!
MXT
Comment #4
morbus iffYep, that's exactly the pattern I'd implement.