array( 'title' => t('Posted 50 comments!'), 'description' => t("We no longer think you're a spam bot. Maybe."), 'storage' => 'comment-count', 'points' => 50, ), 'comment-count-100' => array( 'title' => t('Posted 100 comments!'), 'description' => t('But what about the children?!'), 'storage' => 'comment-count', 'points' => 100, 'images' => array( 'unlocked' => '/sites/default/files/example1.png', // 'hidden' and 'locked' will use the defaults. ), ), // An example of achievement groups: 'node-creation' is the group ID, // "Article creation" is the group title, and all relevant achievements are // placed in an 'achievements' array. The ungrouped comment achievements // above will be automatically pushed into a "Miscellany" group. 'article-creation' => array( 'title' => t('Article creation'), 'achievements' => array( 'node-mondays' => array( 'title' => t('Published some content on a Monday'), 'description' => t("Go back to bed: it's still the weekend!"), 'points' => 5, 'images' => array( 'unlocked' => '/sites/default/files/example1.png', 'locked' => '/sites/default/files/example2.png', 'hidden' => '/sites/default/files/example3.png', // all default images have been replaced. ), ), ), ), ); return $achievements; } /** * Implements hook_comment_insert(). */ function example_comment_insert($comment) { // Most achievements measure some kind of statistical data that must be // aggregated over time. To ease the storage of this data, the achievement // module ships with achievement_storage_get() and _set(), which allow you // to store custom data on a per-user basis. In most cases, the storage // location is the same as your achievement ID but in situations where you // have progressive achievements (1, 2, 50 comments etc.), it's better to // share a single place like we do below. If you don't use the achievement // ID for the storage location, you must specify the new location in the // 'storage' key of hook_achievements_info(). // // Here we're grabbing the number of comments that the current commenter has // left in the past (which might be 0), adding 1 (for the current insert), // and then saving the count back to the database. The saved data is // serialized so can be as simple or as complex as you need it to be. $current_count = achievements_storage_get('comment-count', $comment->uid) + 1; achievements_storage_set('comment-count', $current_count, $comment->uid); // Note that we're not checking if the user has previously earned any of the // commenting achievements yet. There are two reasons: first, we might want // to add another commenting achievement for, say, 250 comments, and if we // had stopped the storage counter above at 100, someone who currently has // 300 comments wouldn't unlock the achievement until they added another 150 // nuggets of wisdom to the site. Generally speaking, if you need to store // incremental data for an achievement, you should continue to store it even // after the achievement has been unlocked - you never know if you'll want // to add a future milestone that will unlock on higher increments. // // Secondly, the achievements_unlocked() function below automatically checks // if the user has unlocked the achievement already, and will not reward it // again if they have. This saves you a small bit of repetitive coding but // you're welcome to use achievements_unlocked_already() as needed. // // Knowing that we currently have 50 and 100 comment achievements, we simply // loop through each milestone and check if the current count value matches. foreach (array(50, 100) as $count) { if ($current_count == $count) { achievements_unlocked('comment-count-' . $count, $comment->uid); } } } /** * Implements hook_node_insert(). */ function example_node_insert($node) { // Sometimes, we don't need any storage at all. if (format_date(REQUEST_TIME, 'custom', 'D') == 'Mon') { achievements_unlocked('node-mondays', $node->uid); } }