You are here

function user_relationshipsactivity_user_relationships in Activity 6

Same name and namespace in other branches
  1. 5.4 contrib/user_relationshipsactivity/user_relationshipsactivity.module \user_relationshipsactivity_user_relationships()
  2. 5.3 contrib/user_relationshipsactivity/user_relationshipsactivity.module \user_relationshipsactivity_user_relationships()

Implementation of hook_user_relationships().

Parameters

$op: The action taken on a user relationship

Is one of the following:

$op | Description ---------------------------------------------------------------------- load | When a relationship's details are loaded presave | Before a new relationship is requested or approved request | When a request for a new relationship is made remove | When an existing relationship is deleted by the requester or requestee approved | When a relationship request is approved by the requestee disapprove | When a relationship request is disapproved by the requestee cancel | When a relationship request is canceled by the requester

$relationship: The relationship object.

File

contrib/user_relationshipsactivity/user_relationshipsactivity.module, line 131

Code

function user_relationshipsactivity_user_relationships($op, $relationship) {
  if ($op == 'load' || $op == 'presave') {
    return;
  }
  $relationship = array_merge((array) $relationship, (array) user_relationships_type_load($relationship->rtid));
  $type = preg_replace('/\\s/', '_', drupal_strtolower($relationship['name']));
  switch ($op) {
    case 'request':
      if ($relationship['approved'] && !$relationship['requires_approval']) {
        $operation = 'approved';
        $target_users_roles[ACTIVITY_ALL] = 'all';
      }
      else {
        if ($relationship['requires_approval']) {
          $operation = 'requested';
        }
      }
      break;
    case 'approve':
      if ($relationship['approved'] && $relationship['requires_approval']) {
        $operation = 'approved';
        $target_users_roles[ACTIVITY_ALL] = 'all';
      }
      break;
    case 'disapprove':
      if (!$relationship['approved'] && $relationship['requires_approval']) {
        $operation = 'denied';
        $target_users_roles[ACTIVITY_ALL] = 'all';
      }
      break;
    case 'cancel':
      if (!$relationship['approved'] && $relationship['requires_approval']) {
        $operation = 'canceled';
        $target_users_roles[ACTIVITY_ALL] = 'all';
      }
      break;
    case 'remove':
      $operation = 'deleted';
      $target_users_roles[ACTIVITY_ALL] = 'all';
      break;
  }

  // Check if both type and operation are
  // enabled for activity. If not then stop here
  if (!in_array($type, variable_get('user_relationshipsactivity_token_types', array(
    $type,
  )), TRUE) || !in_array($operation, variable_get('user_relationshipsactivity_op_types', array(
    $operation,
  )), TRUE)) {
    return FALSE;
  }
  $user = user_load(array(
    'uid' => $relationship['requester_id'],
  ));

  // Privacy setting check for user voting
  if (activity_user_privacy_optout($user)) {
    return FALSE;
  }

  // User hide activity permission check
  if (user_access('hide activity', $user)) {
    return FALSE;
  }
  $data = array(
    'requestee-uid' => $relationship['requestee_id'],
    'relationship-type-id' => $relationship['rtid'],
  );
  $target_users_roles[$relationship['requester_id']] = 'requester';
  $target_users_roles[$relationship['requestee_id']] = 'requestee';
  activity_insert($user->uid, 'user_relationshipsactivity', $type, $operation, $data, $target_users_roles);
}