Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* @file
* Rules functions for the Affiliates Suite module.
*/
// ======================================
// CONDITIONS
// ======================================
/*
* Conditions:
* + Check if the balance is greater than X
*/
/**
* Implements hook_rules_condition_info().
*/
function ms_affiliates_rules_condition_info() {
return array(
'ms_affiliates_condition_balance_greater_than' => array(
'label' => t('Check if affiliate balance is greater than X.'),
'parameter' => array(
'account' => array('type' => 'user', 'label' => t('User')),
'amount' => array('type' => 'decimal', 'label' => t('Amount'))
),
'group' => 'Affiliates Suite',
),
);
}
/**
* Condition: Check if the balance is greater than X
*/
function ms_affiliates_condition_balance_greater_than($account, $amount) {
return $account->af_balance > $amount;
}
// ======================================
// ACTIONS
// ======================================
/*
* Actions:
* + Add an amount to the balance
* + Set the balance to an amount
* + Set or change the affiliate of a user
* + Get the affiliate of a user
*/
/**
* Implements hook_rules_action_info().
* @ingroup rules
*/
function ms_affiliates_rules_action_info() {
return array(
'ms_affiliates_action_add_balance' => array(
'label' => t('Add or subtract an amount to the balance'),
'parameter' => array(
'account' => array('type' => 'user', 'label' => t('User')),
'amount' => array('type' => 'decimal', 'label' => t('Amount')),
),
'group' => 'Affiliates Suite',
),
'ms_affiliates_action_get_affiliate' => array(
'label' => t('Load the affiliate of a user'),
'parameter' => array(
'account' => array('type' => 'user', 'label' => t('User')),
),
'provides' => array(
'affiliate' => array(
'type' => 'user',
'label' => t('Affiliate'),
),
),
'group' => 'Affiliates Suite',
),
'ms_affiliates_action_set_balance' => array(
'label' => t('Set the affiliate balance'),
'parameter' => array(
'account' => array('type' => 'user', 'label' => t('User')),
'amount' => array('type' => 'decimal', 'label' => t('Amount')),
),
'group' => 'Affiliates Suite',
),
'ms_affiliates_action_set_affiliate' => array(
'label' => t('Set the affiliate for a user'),
'parameter' => array(
'account' => array('type' => 'user', 'label' => t('User')),
'affiliate' => array('type' => 'integer', 'label' => t('Affiliate')),
),
'group' => 'Affiliates Suite',
),
);
}
/**
* Action: Get the affiliate for a user
*/
function ms_affiliates_action_get_affiliate($account) {
$affiliate = user_load(ms_affiliates_get_affiliate($account->uid));
return array('affiliate' => $affiliate);
}
/**
* Action: Add an amount to the balance
*/
function ms_affiliates_action_add_balance($account, $amount) {
return ms_affiliates_update_balance($account->uid, $amount);
}
/**
* Action: Set the balance to an amount
*/
function ms_affiliates_action_set_balance($account, $amount) {
return ms_affiliates_update_balance($account->uid, $amount, TRUE);
}
/**
* Action: Set the affiliate of a user
*/
function ms_affiliates_action_set_affiliate($account, $affiliate) {
ms_affiliates_set_affiliate($account, $affiliate);
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
}
// ======================================
// TRIGGERS
// ======================================
/*
* Triggers:
* + Commission has been granted to a user
* + User gets a new referral signup
*/
/**
* Implements hook_rules_event_info()
*/
function ms_affiliates_rules_event_info() {
$items = array(
'ms_affiliates_event_commission_granted' => array(
'label' => t('Commission Granted'),
'group' => 'Affiliates Suite',
'help' => t("Act when commission is granted to a user"),
'variables' => array(
'commission' => array('type' => 'decimal', 'label' => t('Commission Amount')),
'level' => array('type' => 'integer', 'label' => t('Level')),
'amount' => array('type' => 'decimal', 'label' => t('Order Amount')),
'account' => array('type' => 'user', 'label' => t('Account')),
),
),
'ms_affiliates_event_referral_signup' => array(
'label' => t('Referral Signup'),
'group' => 'Affiliates Suite',
'help' => t("Act when a referral signs up under an affiliate"),
'variables' => array(
'referral' => array('type' => 'user', 'label' => t('Referral')),
'affiliate' => array('type' => 'user', 'label' => t('Affiliate')),
),
),
);
return $items;
}
// ======================================
// DATA TYPES
// ======================================