user_stats.rules.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @file
  4. * Functions for integrating the Rules module with User Stats.
  5. */
  6. /**
  7. * Implements hook_rules_event_info().
  8. * @ingroup rules
  9. */
  10. function user_stats_rules_event_info() {
  11. $defaults = array(
  12. 'group' => t('User Stats'),
  13. 'module' => 'user_stats',
  14. );
  15. return array(
  16. 'user_stats_login_count_increment' => $defaults + array(
  17. 'label' => t('User login count increased'),
  18. 'variables' => user_stats_rules_events_variables(),
  19. ),
  20. 'user_stats_login_count_decrement' => $defaults + array(
  21. 'label' => t('User login count decreased'),
  22. 'variables' => user_stats_rules_events_variables(),
  23. ),
  24. 'user_stats_login_count_reset' => $defaults + array(
  25. 'label' => t('User login count reset'),
  26. 'variables' => user_stats_rules_events_variables(),
  27. ),
  28. 'user_stats_post_count_increment' => $defaults + array(
  29. 'label' => t('User post count increased'),
  30. 'variables' => user_stats_rules_events_variables(),
  31. ),
  32. 'user_stats_post_count_decrement' => $defaults + array(
  33. 'label' => t('User post count decreased'),
  34. 'variables' => user_stats_rules_events_variables(),
  35. ),
  36. 'user_stats_post_count_reset' => $defaults + array(
  37. 'label' => t('User post count reset'),
  38. 'variables' => user_stats_rules_events_variables(),
  39. ),
  40. 'user_stats_ip_address_insert' => $defaults + array(
  41. 'label' => t('User has a new IP address'),
  42. 'variables' => user_stats_rules_events_variables(),
  43. ),
  44. 'user_stats_day_older' => $defaults + array(
  45. 'label' => t('User is a day older'),
  46. 'variables' => user_stats_rules_events_variables_day_older(),
  47. ),
  48. );
  49. }
  50. /**
  51. * Defines variables for user_stats_rules_event_info().
  52. */
  53. function user_stats_rules_events_variables() {
  54. return array(
  55. 'uid' => array(
  56. 'type' => 'number',
  57. 'hidden' => TRUE,
  58. ),
  59. 'statistic_value' => array(
  60. 'type' => 'number',
  61. 'label' => t('Value of the statistic'),
  62. ),
  63. 'user' => array(
  64. 'type' => 'user',
  65. 'label' => t("User who's statistics have changed"),
  66. 'handler' => 'user_stats_events_argument_user',
  67. ) //+ rules_events_global_user_argument(),
  68. // ^ Do we need to set the acting user?
  69. );
  70. }
  71. /**
  72. * Defines variables for user_stats_rules_event_info().
  73. *
  74. * The variables for a day_older event are slightly different to other items.
  75. */
  76. function user_stats_rules_events_variables_day_older() {
  77. // Get the default variables.
  78. $variables = user_stats_rules_events_variables();
  79. $variables['statistic_value']['handler'] = 'user_stats_events_argument_day_older';
  80. return $variables;
  81. }
  82. /**
  83. * Handler to load user object on event.
  84. *
  85. * @param $uid
  86. * Unique user ID used to load the user object.
  87. * @param $value
  88. * Value of the statistic, not relevant to loading the user object,
  89. * but passed through by Rules engine.
  90. *
  91. * @return
  92. * Loaded user object.
  93. */
  94. function user_stats_events_argument_user($uid, $value) {
  95. return user_load($uid);
  96. }
  97. /**
  98. * Handler to load number of days user has been registered on event.
  99. */
  100. function user_stats_events_argument_day_older($uid, $value) {
  101. return user_stats_get_stats('reg_days', $uid);
  102. }