You are here

function oa_clone_batch_clone_group_memberships in Open Atrium Clone 7.2

Callback for cloning all the memberships in a group.

Parameters

object $node: Node object representing the Group we are going to popuplate.

int $original_nid: The node ID of the original Group we are cloning data from.

array &$context: A place where we can store values that need to b passed from one iteration of this batch operation to the next.

1 string reference to 'oa_clone_batch_clone_group_memberships'
oa_clone_node_insert in ./oa_clone.module
Implements hook_node_insert().

File

./oa_clone.module, line 915

Code

function oa_clone_batch_clone_group_memberships($node, $original_nid, &$context) {

  // The first time through, set up all the variables.
  if (empty($context['sandbox']['max'])) {
    $context['sandbox']['membership_ids'] = oa_clone_get_group_memberships($original_nid);
    $context['sandbox']['max'] = count($context['sandbox']['membership_ids']);
    $context['sandbox']['gid'] = $node->nid;
    $context['sandbox']['progress'] = 0;
  }

  // Get the next node.
  $next_id = array_shift($context['sandbox']['membership_ids']);
  if (!$next_id) {
    $context['sandbox']['finished'] = TRUE;
    return;
  }

  // Clone the original membership, change it to the new group and save.
  $original_membership = og_membership_load($next_id);
  $membership = clone $original_membership;
  $membership->id = NULL;
  $membership->gid = $node->nid;
  og_membership_save($membership);

  // Bump the progress indicator.
  $context['sandbox']['progress']++;

  // Report progress if not finished and run again.
  $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}