1

I have an Organic Groups / subgroups structure where an Organisation is a group, a Property is a child group of an Organisation, and a claim is a child group of a property. So: Organisation > Property > Claim Each subgroup is set to inherit its parents users

When a new Property is created, I can use rules to 'Get group members from group audience' to email all of the members of the group: enter image description here

However when a new Claim is created the same rule only emails the user who created the Claim. I think that this might be because inherited users are handled differently from normal users. You can see this by going into the 'group' tab on the claim and then clicking on people:

enter image description here

We can see in the screenshot above that there are three inherited users, but only the user who created the node will be emailed, the other two will not.

How should I email the inherited users when subgroups like Claim are created?

-- Addition --

og_subgroups.views.inc is used to create the view shown above. The contents of this file are:

function og_subgroups_views_pre_render(&$view) {
  if ($view->name == 'og_members_admin') {
    // Add an overview of the users that are inherited from parent groups.
    $inherited_users = _og_subgroups_get_inherited_users($view->args[0], $view->args[1]);
    $header = array('Name', 'Inherited from');
    $rows = array();
    $membership_states = og_group_content_states();
    if (!empty($inherited_users)) {
      foreach ($inherited_users as $inherited_uid => $data) {
        $row = array();
        $row[] = l($data[0]['user']->name, 'user/' . $inherited_uid);
        $inherited_from = array();
        foreach ($data as $inheritance) {
          $inherited_from[] = t('!parent (@roles)', array(
            '!parent' => l(entity_label($inheritance['inherited_from']['type'], $inheritance['inherited_from']['entity']), 'group/' . $inheritance['inherited_from']['type'] . '/' . $inheritance['inherited_from']['id'] . '/admin/people'),
        '@roles' => implode(', ', $inheritance['roles']),
      ));
    }
    $row[] = implode(', ', $inherited_from);
    $rows[] = $row;
  }
}
$view->attachment_after = theme('table', array(
  'caption' => t('Inherited users'),
  'header' => $header,
  'rows' => $rows,
  'empty' => t('No inherited users.'),
));
  }
}

It would be great if someone could suggest how I might be able to use the above code in rules. It would be great if I could use'Execute custom PHP code' and use something like

$inherited_users = _og_subgroups_get_inherited_users($view->args[0], $view->args[1]);

but that doesn't work in a custom PHP block in Rules. I can see the function _og_subgroups_get_inherited_users in og_subgroups.common.inc and am not sure if I can use this code to help.

Using Organic Groups 7.x-2.7 and Organic groups subgroups 7.x-2.0-beta1

4
  • Have you tried Views Rules to create a view that lists all the people you want to send an email to?
    – Turion
    Commented Feb 13, 2016 at 10:57
  • I am considering doing that, but am struggling so far to create a view of all the users. The issue is that on a property the view of user would only show the creating author as the other users are inherited from the parent group rather than associated with the current group Commented Feb 15, 2016 at 11:36
  • sorry, I didn't really understand your comment. Do you want to expand it into a separate question, and link it here? Also, I advise not using "Execute custom PHP code". It's one of the ways of quickly creating security loopholes.
    – Turion
    Commented Feb 18, 2016 at 9:55
  • Good suggestion @Turion. Here is a sperate question on the difficulty of creating a view that shows users inherited from the parent group: drupal.stackexchange.com/questions/191881/… Commented Feb 18, 2016 at 14:31

1 Answer 1

0

I managed to use make a custom rules file for OG Subgroups that achieves what I need it to. It adds the rule 'Get subgroup group members from group audience' to a 'Custom' rule group:

screenshot

This makes the users of the subgroup available to rules. You can then loop through the users and send an email to each of them:

enter image description here

In order to do this I created custom 'og_subgroups.rules.inc' file in the root of the OG subgroups module. This is the code I used inside it:

<?php

/****************
Adds the ability to get the members of the parent group from a subgroup using rules
/****************


/**
 * Implements hook_rules_action_info().
 */
function og_subgroups_rules_action_info() {
  $items = array();

  $items['og_subgroups_get_members'] = array(
    'label' => t('Get subgroup group members from group audience'),
    'group' => t('Custom'),
    'parameter' => array(
      'group_content' => array(
        'type' => 'entity',
        'label' => t('Group content'),
        'description' => t('The group content determining the group audience.'),
      ),
    ),
    'provides' => array(
      'group_members' => array('type' => 'list<user>', 'label' => t('List of subgroup members')),
    ),
    'base' => 'og_subgroups_rules_get_members',
    'access callback' => 'og_subgroups_rules_integration_access',
  );

  return $items;
}


/* NEW FUNCTION ************************************************/

// This callback creates the hashed string by using the parameters provided through rules' UI
function og_subgroups_rules_get_members($group_content) {

// get the nid from the passed value of the content being added
$nid = $group_content->nid->value();

// trying to manually call the get inherited users function from og_subgroups.common.inc
$inherited_users = _og_subgroups_get_inherited_users("node", $nid);

$members = array();

foreach ($inherited_users as $inherited_uid => $data) {
  // Get the group members the group content belongs to.

  $user=user_load($inherited_uid);

  // push the returned user to the array of members
  array_push($members, $user);

}



// return the users  
  return array('group_members' => $members);

}

/**
 * OG Rules integration access callback.
 */
function og_subgroups_rules_integration_access($type, $name) {
  // Grant everyone access to conditions.
  return $type == 'condition' || user_access('administer group');
}

For those of you who prefer patches here is the patch I created: Patch on drupal.org

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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