I would like to build a flexible custom user interface for content notifications using rules. I created two rulesets with a "execute custom PHP" rule to subscribe/unsubscribe a user to/from a content type. Both rulesets accept the variables "user" and a string for "content type".
The "subscribe" ruleset works great, but "unsubscribe" doesn't. Can someone please give me a hint?? Thanks!
The code is largely copy-paste from here: http://drupal.org/node/954754
I think this would be very useful information for many people. There is a notifications_rules module, but it does't work for content type subscriptions.
Ruleset to subscribe users (this works):
// passing two variables to the ruleset: user and a arbitrary string for 'content type'
$subscription = array(
'uid' => '[user:uid]',
'type' => 'nodetype',
'event_type' => 'node',
// 'send_method' => 'mail',
// 'send_interval' => '0',
'fields' => array('type' => '[node_type_string:string]'),
);
notifications_save_subscription($subscription);
Ruleset to unsubscribe from a content type (this doesn't work):
// passing two variables to the ruleset: user and a arbitrary string for 'content type'
// get all node type subscriptions for the user
$subs = notifications_user_get_subscriptions('[user:uid]', 'node', 'type');
// determine if subscription exists
foreach ($subs as $key => $sub) {
if ($sub->value == '[string_node_type:string]') {
$typesubscription = $sub;
break;
}
}
// delete
if ($typesubscription) {
notifications_subscription_delete($typesubscription->sid);
}
Comments
Comment #1
tassaf commentedThanks a lot
but is there any way to do this in Notifications version.7 ?
Comment #2
ju.ri commentedThere should be a similar way for Drupal 7.
Anyway the above code doesn't work, users are not unsubscribed,
even if I do is exactly as in http://drupal.org/node/954754.
There must be something wrong with the call of notifications_user_get_subscriptions or notifications_subscription_delete.
Can anyone help?