-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathog.rules.inc
More file actions
executable file
·169 lines (158 loc) · 4.93 KB
/
Copy pathog.rules.inc
File metadata and controls
executable file
·169 lines (158 loc) · 4.93 KB
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
123
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
<?php
// $Id$
/**
* @file
* Rules module functionality for the Organic groups module.
*/
/**
* Implementation of hook_rules_action_info().
*/
function og_rules_action_info() {
return array(
'og_rules_action_subscribe_user' => array(
'label' => t('Subscribe user to group'),
'arguments' => array(
'user' => array(
'type' => 'user',
'label' => t('User who will be subscribed'),
),
'group' => array(
'type' => 'node',
'label' => t('Group that user will be subscribed to'),
),
'state' => array(
'type' => 'string',
'label' => t('The subscription state'),
),
'replace' => array(
'type' => 'boolean',
'label' => t('Replace <em>all</em> the user subscription with this one'),
),
),
'module' => 'Organic groups',
),
'og_rules_action_remove_user' => array(
'label' => t('Unsubscribe user from group'),
'arguments' => array(
'user' => array('type' => 'user',
'label' => t('User who will be unsubscribed'),
),
'group' => array(
'type' => 'node',
'label' => t('Group that user will be unsubscribed from'),
),
),
'module' => 'Organic groups',
),
'og_rules_action_add_group_node' => array(
'label' => t('Add group node settings to content'),
'arguments' => array(
'node' => array(
'type' => 'node',
'label' => t('Content that will become a group node'),
),
),
'help' => t("When creating a group node organic groups module requires some group settings. This action should be used after 'Add new content' action, that adds a <a href=\"@group-node-type\">group node type</a> content, and will result with a new group node.", array('@group-node-type' => url('admin/og/og'))),
'module' => 'Organic groups',
),
);
}
/**
* Action: Subscribe user to group.
*/
function og_rules_action_subscribe_user($user, $node, $state, $replace, $settings) {
$groups = array('value' => $node->nid, 'state' => $state);
og_set_association('user', $user, $groups, $replace);
}
/**
* Action: Unsubscribe user from group.
*/
function og_rules_action_remove_user($user, $node, $settings) {
og_delete_association('user', $user, array($node->nid));
}
/**
* Action:Add group node settings to content.
*/
function og_rules_action_add_group_node($node, $settings) {
if (og_is_group_type($node->type)) {
// Add og keys to the node.
foreach ($settings['og_fieldset']['og_settings'] as $key => $value){
$node->$key = $value;
}
return array('node' => $node);
}
}
/**
* Action:Add group node settings to content form.
*/
function og_rules_action_add_group_node_form($settings, &$form) {
$node = !empty($settings['og_fieldset']['og_settings']) ? $settings['og_fieldset']['og_settings'] : array();
$og_form = og_group_form($node, array());
$form['settings']['og_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Organic groups form settings'),
);
$form['settings']['og_fieldset']['og_settings'] = $og_form;
}
/**
* Implementation of hook_rules_condition_info().
*/
function og_rules_condition_info() {
return array(
'og_rules_condition_user_in_group' => array(
'label' => t('User is group member'),
'arguments' => array(
'user' => array(
'type' => 'user',
'label' => t('User'),
),
'group' => array(
'type' => 'node',
'label' => t('Group'),
),
),
'help' => t('Evaluates to TRUE if the user is an approved member of the group. If the user is a pending member this condition will return FALSE.'),
'module' => 'Organic groups',
),
'og_rules_condition_content_is_group' => array(
'label' => t('Content is a group'),
'arguments' => array(
'group' => array(
'type' => 'node',
'label' => t('Group'),
),
),
'help' => t('Evaluates to TRUE if the content is a group.'),
'module' => 'Organic groups',
),
'og_rules_condition_content_is_group_post' => array(
'label' => t('Content is a group post'),
'arguments' => array(
'group' => array(
'type' => 'node',
'label' => t('Group post'),
),
),
'help' => t('Evaluates to TRUE if the content is a group post.'),
'module' => 'Organic groups',
),
);
}
/**
* Condition: User is a group member.
*/
function og_rules_condition_user_in_group($user, $node, $states, $settings) {
return in_array($node->nid, $groups, og_get_object_groups('user', $user, $states));
}
/**
* Condition: Content is a group node.
*/
function og_rules_condition_content_is_group($node, $settings) {
return og_is_group_type($node->type);
}
/**
* Condition: Content is a group post.
*/
function og_rules_condition_content_is_group_post($node, $settings) {
return og_is_group_post_type($node->type);
}