achievements_pointless.module

Tracking 7.x-1.x branch
  1. drupal
    1. 7 contributions/achievements/achievements_pointless/achievements_pointless.module

Hides points and leaderboards for a non-competitive environment.

Functions & methods

NameDescription
achievements_pointless_achievement_user_statsRemove rank and points from the stats on user/#/achievements.
achievements_pointless_block_info_alterImplements hook_block_info_alter().
achievements_pointless_menu_alterImplements hook_menu_alter().
achievements_pointless_preprocess_achievementProcess variables for achievement.tpl.php.
achievements_pointless_preprocess_achievement_latest_unlockProcess variables for achievement-latest-unlock.tpl.php.
achievements_pointless_preprocess_achievement_notificationProcess variables for achievement-notification.tpl.php.
achievements_pointless_template_hide_variablesHide competitive elements from our achievement templates.
achievements_pointless_theme_registry_alterImplements hook_theme_registry_alter().

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Hides points and leaderboards for a non-competitive environment.
  5. */
  6. /**
  7. * Implements hook_block_info_alter().
  8. *
  9. * Disables the achievements leaderboard block.
  10. */
  11. function achievements_pointless_block_info_alter(&$blocks, $theme, $code_blocks) {
  12. $blocks['achievements']['achievements_leaderboard']['status'] = 0;
  13. }
  14. /**
  15. * Implements hook_menu_alter().
  16. *
  17. * Disables access to the achievement leaderboards.
  18. */
  19. function achievements_pointless_menu_alter(&$items) {
  20. $items['achievements/leaderboard']['access callback'] = FALSE;
  21. $items['achievements/leaderboard/%achievements']['access callback'] = FALSE;
  22. }
  23. /**
  24. * Process variables for achievement.tpl.php.
  25. */
  26. function achievements_pointless_preprocess_achievement(&$variables) {
  27. achievements_pointless_template_hide_variables(&$variables);
  28. }
  29. /**
  30. * Process variables for achievement-notification.tpl.php.
  31. */
  32. function achievements_pointless_preprocess_achievement_notification(&$variables) {
  33. achievements_pointless_template_hide_variables($variables);
  34. $variables['unlocked_rank']['#markup'] = $variables['unlocked_date']['#markup'];
  35. // The points box is now entirely empty; replace rank with the unlock timestamp.
  36. }
  37. /**
  38. * Process variables for achievement-latest-unlock.tpl.php.
  39. */
  40. function achievements_pointless_preprocess_achievement_latest_unlock(&$variables) {
  41. achievements_pointless_template_hide_variables($variables);
  42. }
  43. /**
  44. * Hide competitive elements from our achievement templates.
  45. */
  46. function achievements_pointless_template_hide_variables(&$variables) {
  47. unset($variables['image']['#path']); // no link path, no clicky clicky.
  48. unset($variables['achievement_title']['#type']); // no longer a link type.
  49. $variables['achievement_title']['#markup'] = $variables['achievement_title']['#title'];
  50. $variables['achievement']['points'] = NULL;
  51. $variables['unlocked_rank']['#markup'] = NULL;
  52. if ($variables['unlocked_date']['#markup']) { // we don't show rank or points, so we've room to make this a bit clearer.
  53. $variables['unlocked_date']['#markup'] = t('Unlocked @timestamp', array('@timestamp' => $variables['unlocked_date']['#markup']));
  54. }
  55. }
  56. /**
  57. * Implements hook_theme_registry_alter().
  58. *
  59. * Send the user stats theme function to our override instead.
  60. */
  61. function achievements_pointless_theme_registry_alter(&$theme_registry) {
  62. $theme_registry['achievement_user_stats']['function'] = 'achievements_pointless_achievement_user_stats';
  63. }
  64. /**
  65. * Remove rank and points from the stats on user/#/achievements.
  66. */
  67. function achievements_pointless_achievement_user_stats($variables) {
  68. $output = '<div class="achievement-user-stats">';
  69. $output .= t('@name has unlocked @unlocks_count of @total_count achievements.', array(
  70. '@name' => $variables['stats']['name'],
  71. '@unlocks_count' => $variables['stats']['unlocks_count'],
  72. '@total_count' => $variables['stats']['total_count'],
  73. ));
  74. $output .= '</div>';
  75. return $output;
  76. }