I have a content type called "A" and content type called "B". When a user creates node "A" other users can create node "B" referenced to node "A". How can i notify user which created node "A" about newly created nodes of type "B" referenced to his node "A"? I've tried notifications module but as i can understand there's no such options for that.. Tried this solution: how to create rules to send email notification for node reference content? but it's not working on D7
2 Answers
I think you can accomplish it by creating a custom module. Whenever users create nodes of type B, you can mail and notify those users who created nodes of type A.
You can get the list of users who created nodes of type A with a SQL query like the following.
SELECT DISTINCT uid FROM node WHERE type = 'goals'
In order to send mails when users create nodes of type B, you will have to implement hook_node_insert()
, so that you can send notifications after nodes are successfully created. You could also use hook_node_presave()
; the only difference is that the latter will send mails before nodes are created.
function MODULE_NAME_node_insert($node) {
if ($node->type == "B") {
$params = array();
$from = variable_get('site_mail', '[email protected]');
$send = TRUE;
$language = language_default();
// It is assumed that array od users who created node of type "A" is returned
// by the following function.
$users = _list_of_user_created_A_node();
foreach ($users as $key => $value) {
$uid = $key;
$mail = $value;
$params['node_title'] = $node->title;// The node title of the created node B
$params['userID_A'] = $uid;
$params['mail_of_user_A'] = $mail;
drupal_mail('MODULE_NAME', 'notify_mail', $mail, $language, $params, $from, $send);
}
}
}
See hook_mail()
on how sending mails.
You could also save the node titles in a database table, and send mails during cron task's execution.
you can use my module for this Total Subscription.
Total Subscription provides functionality which would allow the user to subscribe to node pages, taxonomy terms, etc. The main feature which distinguishes it from other subscription modules is that it allows subscription for Anonymous along with Authenticated users.
-
How does this module help the user, considering the specific use case being described in the question?– avpaderno ♦Commented Mar 8, 2014 at 17:37