Projet

Général

Profil

Paste
Télécharger (3,13 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / user_stats / user_stats.rules.inc @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Functions for integrating the Rules module with User Stats.
6
 */
7

    
8
/**
9
 * Implements hook_rules_event_info().
10
 * @ingroup rules
11
 */
12
function user_stats_rules_event_info() {
13
  $defaults = array(
14
    'group' => t('User Stats'),
15
    'module' => 'user_stats',
16
  );
17
  return array(
18
    'user_stats_login_count_increment' => $defaults + array(
19
      'label' => t('User login count increased'),
20
      'variables' => user_stats_rules_events_variables(),
21
    ),
22
    'user_stats_login_count_decrement' => $defaults + array(
23
      'label' => t('User login count decreased'),
24
      'variables' => user_stats_rules_events_variables(),
25
    ),
26
    'user_stats_login_count_reset' => $defaults + array(
27
      'label' => t('User login count reset'),
28
      'variables' => user_stats_rules_events_variables(),
29
    ),
30
    'user_stats_post_count_increment' => $defaults + array(
31
      'label' => t('User post count increased'),
32
      'variables' => user_stats_rules_events_variables(),
33
    ),
34
    'user_stats_post_count_decrement' => $defaults + array(
35
      'label' => t('User post count decreased'),
36
      'variables' => user_stats_rules_events_variables(),
37
    ),
38
    'user_stats_post_count_reset' => $defaults + array(
39
      'label' => t('User post count reset'),
40
      'variables' => user_stats_rules_events_variables(),
41
    ),
42
    'user_stats_ip_address_insert' => $defaults + array(
43
      'label' => t('User has a new IP address'),
44
      'variables' => user_stats_rules_events_variables(),
45
    ),
46
    'user_stats_day_older' => $defaults + array(
47
      'label' => t('User is a day older'),
48
      'variables' => user_stats_rules_events_variables_day_older(),
49
    ),
50
  );
51
}
52

    
53
/**
54
 * Defines variables for user_stats_rules_event_info().
55
 */
56
function user_stats_rules_events_variables() {
57
  return array(
58
    'uid' => array(
59
      'type' => 'number',
60
      'hidden' => TRUE,
61
    ),
62
    'statistic_value' => array(
63
      'type' => 'number',
64
      'label' => t('Value of the statistic'),
65
    ),
66
    'user' => array(
67
      'type' => 'user',
68
      'label' => t("User who's statistics have changed"),
69
      'handler' => 'user_stats_events_argument_user',
70
    ) //+ rules_events_global_user_argument(),
71
    // ^ Do we need to set the acting user?
72
  );
73
}
74

    
75
/**
76
 * Defines variables for user_stats_rules_event_info().
77
 *
78
 * The variables for a day_older event are slightly different to other items.
79
 */
80
function user_stats_rules_events_variables_day_older() {
81
  // Get the default variables.
82
  $variables = user_stats_rules_events_variables();
83
  $variables['statistic_value']['handler'] = 'user_stats_events_argument_day_older';
84

    
85
  return $variables;
86
}
87

    
88
/**
89
 * Handler to load user object on event.
90
 *
91
 * @param $uid
92
 *   Unique user ID used to load the user object.
93
 * @param $value
94
 *   Value of the statistic, not relevant to loading the user object,
95
 *   but passed through by Rules engine.
96
 *
97
 * @return
98
 *   Loaded user object.
99
 */
100
function user_stats_events_argument_user($uid, $value) {
101
  return user_load($uid);
102
}
103

    
104
/**
105
 * Handler to load number of days user has been registered on event.
106
 */
107
function user_stats_events_argument_day_older($uid, $value) {
108
  return user_stats_get_stats('reg_days', $uid);
109
}