I have a D7 site running with Organic groups, rules, VBO, panels, badges, private-message modules ... and a bootstrap sub-theme (js, jQuery update, ...) working in all browsers, ios & android, i need to alert users with a beep sound when new OG content is created (or any rules reaction) by a custom module named beepsound module.
What I have:
• Rules event: create new content
• Rules condition: my contentype with some fields.
• Rules action: Loop: all OG group members, loop action: see code below
"beepsound module" must have UID variable to target a specific OG member.
I have manage to have my beepsound as an action in rules, it targets UID, it display a personalised message corectly, also, message is displayed 5 times (when tiggered when mycontentype is being viewed), meaning rule is triggered 5 times, here are my-module code files, dot module file exist but is empty (and not displayed here), If i run this rule with current-user, it works (makes a beep), but not in my OG loop, what it is wrong?
beepsound.info MODULE
name = Beep sound by rules module
description = Module to add a beep sound action in rules
package = Custom
version = 7.01
core = 7.x
dependencies[] = rules
beepsound.rules.inc MODULE
/**
* Implement hook_rules_action_info()
* Declare any meta data about actions for Rules
*/
function beepsound_rules_action_info() {
$actions = array(
'beepsound_action_beepsound_user' => array(
'label' => t('Make a beep sound'),
'group' => t('sound'),
'parameter' => array(
'account' => array(
'type' => 'user',
'label' => t('User to beep'),
),
),
),
);
return $actions;
}
/**
* The action function for produce sound
*/
function beepsound_action_beepsound_user($account) {
drupal_set_message(t('Hello @username',
array('@username' => $account->name)));
?><audio autoplay="autoplay">
<source src="/sites/all/modules/beepsound/A-tone.ogg" type="audio/ogg">
<source src="/sites/all/modules/beepsound/A-Tone.mp3" type="audio/mp3">
</audio><?php
}
here is my rule
{ "og_og_new_content_notification_message" : {
"LABEL" : "OG new content notification message",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "OG" ],
"REQUIRES" : [ "og", "rules", "privatemsg_rules", "beepsound" ],
"ON" : { "node_insert" : [] },
"IF" : [ { "og_entity_is_group_content" : { "entity" : [ "node" ] } } ],
"DO" : [
{ "og_get_members" : {
"USING" : { "group_content" : [ "node" ] },
"PROVIDE" : { "group_members" : { "group_members" : "List of group members" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "group-members" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : [
{ "privatemsg_rules_new" : {
"USING" : {
"recipient" : [ "list-item" ],
"author" : [ "node:author" ],
"subject" : "\u0022[node:title]\u0022 a sido creado. ",
"body" : "\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E Por favor haz clic aqu\u00ed para ver su contenido\u003C\/a\u003E"
},
"PROVIDE" : { "thread_id" : { "thread_id" : "ID of new thread" } }
}
},
{ "beepsound_action_beepsound_user" : { "account" : [ "list-item" ] } },
{ "drupal_message" : { "message" : "beep beep, usuario: \u0022[list-item:uid]\u0022" } }
]
}
},
{ "drupal_message" : { "message" : "Se ha enviado un mensaje a todos los miembros del departamento." } }
]
} }