You are here

function workflow_notify_og_workflow_notify in Workflow 7.2

Same name and namespace in other branches
  1. 7 workflow_notify/workflow_notify_og/workflow_notify_og.module \workflow_notify_og_workflow_notify()

Implements hook_workflow_notify().

Parameters

$op - The operation (columns, users).:

$args - The arguments for this call.:

  • may be: 'columns' - the current list of table headings. 'users' - The current list of users. 'node' - The current node for getting groups focus. 'state' - The state the node is moving to.

Return value

none - Modify the list by reference.

File

workflow_notify/workflow_notify_og/workflow_notify_og.module, line 21
Notify roles by OG Groups for Workflow state transitions.

Code

function workflow_notify_og_workflow_notify($op, &$args) {
  switch ($op) {
    case 'columns':

      // Add the column heading for this module.
      $args['columns']['limit_by_group'] = t('Limit by group');
      break;
    case 'users':
      $limit = variable_get('workflow_notify_og', array());

      // Is this a state we care about?
      if (isset($limit[$args['state']]) && $limit[$args['state']]) {

        // Yes, so get the node's groups and make sure it has some.
        $groups = field_get_items('node', $args['node'], 'og_group_ref');
        if ($groups) {

          // Get the list of user accounts and check each one.
          $accounts = $args['users'];
          foreach ($accounts as $uid => $account) {
            $keep = FALSE;

            // Check each group for user's membership.
            foreach ($groups as $group) {
              if (og_is_member('node', $group['target_id'], 'user', $account)) {
                $keep = TRUE;
                break;
              }
            }

            // Do we find a group?
            if ($keep == FALSE) {

              // No, so remove them from the list.
              unset($args['users'][$uid]);
            }
          }
        }
      }
      break;
    case 'tokens':
      $groups = field_get_items('node', $args['node'], 'og_group_ref');
      $query = "SELECT g.entity_id AS gid, n.title AS name " . "FROM {field_data_group_group} g " . "INNER JOIN {node} n ON n.nid = g.entity_id " . "WHERE g.deleted = 0 ";
      $group_names = db_query($query)
        ->fetchAllKeyed();
      if (!empty($groups)) {
        $list = array();
        foreach ($groups as $group) {
          $list[] = $group_names[$group['target_id']];
        }
        $args['tokens']['@groups'] = implode(', ', $list);
      }
      break;
  }
}