You are here

function commons_trusted_contacts_approve_trust in Drupal Commons 7.3

Menu callback; Approving a Trusted-Contact Invitation by setting each user's membership state to 'Active'.

Parameters

$og_membership: The membership in which the logged-in user is the group and the requesting user is the member.

1 string reference to 'commons_trusted_contacts_approve_trust'
commons_trusted_contacts_menu in modules/commons/commons_trusted_contacts/commons_trusted_contacts.module
Implements hook_menu().

File

modules/commons/commons_trusted_contacts/commons_trusted_contacts.module, line 727

Code

function commons_trusted_contacts_approve_trust(OgMembership $og_membership) {
  global $user;
  if ($og_membership->gid != $user->uid) {

    // Users can only approve their requests.
    return;
  }

  // Get approving user.
  $account = user_load($og_membership->gid);
  if (!commons_trusted_contacts_check_limit($account, $og_membership->etid)) {
    return;
  }

  // This actually changes both OG memberships - one for each user.
  $wrapper = entity_metadata_wrapper('og_membership', $og_membership);
  $wrapper->state
    ->set(OG_STATE_ACTIVE);
  $wrapper
    ->save();

  // Notify.
  $message = message_create('trusted_contact_request_approved', array(
    'uid' => $og_membership->etid,
  ));
  $wrapper = entity_metadata_wrapper('message', $message);
  $wrapper->field_approving_user
    ->set($account);
  $wrapper
    ->save();
  message_notify_send_message($message);

  // Redirect to Invitations screen.
  drupal_goto('user/' . $user->uid . '/contacts', array(
    'query' => array(
      'qt-commons_trusted_contacts' => 'invitations',
    ),
  ));
}