You are here

function user_relationships_user in User Relationships 5

Same name and namespace in other branches
  1. 5.2 user_relationships_hooks.inc \user_relationships_user()

User

File

./user_relationships_hooks.inc, line 186

Code

function user_relationships_user($type, &$edit, &$account, $category = NULL) {
  switch ($type) {
    case 'login':
      if (user_access('maintain relationships')) {
        _user_relationships_set_notifications($account);
      }
      break;
    case 'view':
      global $user;
      $viewer = user_load(array(
        'uid' => $user->uid,
      ));
      if ($account->uid == $user->uid && user_access('maintain relationships')) {
        _user_relationships_set_notifications($account);
      }
      $output = array();
      if ($viewer != $account && ($list = _user_relationships_between($viewer, $account))) {
        $output[] = array(
          'title' => t('Your relationships to this user'),
          'value' => theme('item_list', $list),
          'class' => 'user_relationships',
        );
      }
      if ($actions = _user_relationships_actions_between($viewer, $account)) {
        $output[] = array(
          'title' => t('Relationship actions'),
          'value' => theme('item_list', $actions),
          'class' => 'user_relationships_actions',
        );
      }
      if (sizeof($output)) {
        return array(
          t('Relationships') => $output,
        );
      }
      break;
    case 'delete':
      db_query("DELETE FROM {user_relationships} WHERE requester_id = %d OR requestee_id = %d", $account->uid, $account->uid);
      cache_clear_all("user_relationships", 'cache_user_relationships', TRUE);
      break;
    case 'form':
      if ($category == 'account' && variable_get('user_relationships_require_approval', TRUE) && user_access('maintain relationships', $account)) {
        $form['user_relationships_settings'] = array(
          '#type' => 'fieldset',
          '#title' => t('Relationship settings'),
          '#weight' => 5,
        );
        if (variable_get('user_relationships_allow_auto_approve', FALSE) && ($relationships = user_relationships_relationship_types_load())) {
          $options = array();
          foreach ($relationships as $relationship) {
            if ($relationship->requires_approval) {
              $options[$relationship->rtid] = $relationship->name;
            }
          }
          $form['user_relationships_settings']['user_relationships_auto_approve'] = array(
            '#type' => 'checkboxes',
            '#title' => t('Automatically approve the following relationship requests'),
            '#options' => $options,
            '#default_value' => $edit['user_relationships_auto_approve'],
            '#description' => t("Check off the types of relationships you'd like to automatically approve."),
          );
        }
      }

      // No options have been set so don't display it
      if (sizeof($form['user_relationships_settings']) == 3) {
        unset($form['user_relationships_settings']);
      }
      return $form;
  }
}