0

I want to, for example, use rules to notify all users in a particular section that an item of content in their section is 'awaiting moderation'. Is there a way in Rules to get access to a node's Workbench section?

I can get access to the workbench access term id/menu id, depending on the scheme I'm using, but how can you find the users in that section from there...

1

If you use workbench access with a taxonomy scheme you could try this

In rules, add an event After moderation transition. Add the conditions (previous state moderation, current state moderation) according to yours states in workbench moderation Add the condition Entity has field and then select the field of your workbench access section (field_section for example : should be the field of your taxonomy vocabulary)

Add an action : send an email.

Then in the field TO of the email , you could use this snippet php wich return the user's email wich have access to the section (specified in Editorial assignments by editor in Workbench Access) and have a specific role id. This snippet return too all the users who have been assigned by their role to the section by their role (Editorial assignments by role in Workbench Access)

<?php


$sections = $node->workbench_access;

$terms=taxonomy_term_load_multiple($sections);

foreach ($terms as $term) {

$parents=taxonomy_get_parents_all($term->tid);

  if (!empty($parents)) {

    foreach ($parents as $parent) {

    $tid=$parent->tid;

    $voc_name=$parent->vocabulary_machine_name;
      if (!in_array($tid, $sections)) {
        $sections[$tid]=$tid;
      } 
    }

  $sections[$voc_name]="'".$voc_name."'";
  }
};

// Only the users who have the role id [ROLE_ID]
$role_id=[ROLE_ID];
$emails = array();


foreach ($sections as $section) {
$result = db_query("SELECT user.mail AS mail FROM users user, workbench_access_user workbench, users_roles roles WHERE roles.rid=$role_id AND user.uid=roles.uid AND user.uid=workbench.uid AND access_id=$section");


  foreach($result as $record) {
    $mail=$record->mail;
    if (!in_array($mail,$emails)) { $emails[] = $mail; }
  }
}


foreach ($sections as $section) {
$result = db_query("SELECT user.mail AS mail FROM users user, workbench_access_role workbench, users_roles roles WHERE user.uid=roles.uid AND roles.rid=workbench.rid AND access_id=$section");

  foreach($result as $record) {
    $mail=$record->mail;
    if (!in_array($mail,$emails)) { $emails[] = $mail; }
  }
}

print implode($emails, ",");

?>

And you complete the others email's field with the token available.

This sandbox project Workbench Notify implement this snippet

0

The query would be improved with joins. My version:

SELECT u.mail AS mail
FROM users u
INNER JOIN workbench_access_user w
ON w.uid  = u.uid
INNER JOIN users_roles ur
ON ur.uid = u.uid
WHERE ur.rid = $role_id
AND access_id = $section;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.