2

I am using the User Relationships module on Drupal 7. I have a relationship, let's call it "Best friends," which requires the mutual approval of both users involved. However, sometimes users send way too many requests, and I would like to delete these manually from an admin account.

I tried creating a view that shows all pending relationships of type Best friends and adding Status link as a field-- however, the Status link returns empty. I also couldn't find any option to list user relationships on the admin screen.

Is there any way to quickly manually delete pending user relationship requests from an admin account?

  • Is it possible to generate a list of relationships using Views? – Citricguy Aug 20 '12 at 9:23
  • Yes, I succeeded in creating a view that shows the pending relationships. I just don't have a way to cancel them. – Patrick Kenny Aug 20 '12 at 13:39
  • 1
    It looks like User Relationships has Rules integration. It may be worth checking into Views Bulk Operations. drupal.org/project/views_bulk_operations – Citricguy Aug 20 '12 at 14:18
1
+50

Here is a Rules/Views heavy solution without any custom code.


Modules Used

  • Views
  • Views Bulk Operations
  • Rules
  • User Relationships
  • User Relationship Rules

What To Do

The User Relationships module ships with an addon module called User Relationship Rules. This will need to be enabled along with the other modules listed above.

Using the Rules module, create a component that removes a pending user relationship. (See additional resources below.)

Next create a View that lists the pending User Relationships as you have done as noted in your comments.

Next you will need to add the Views Bulk Operations field to your view and configure it to use the rules component you created earlier.


Additional Resources

Johan Falk has several videos you may find useful in setting up your VBO view.

He has also put together a fantastic introduction to the Rules module.

Views Resources

Enable the bundled UR-Views module (User Relationship Views) and enable the view titled user_relationships_browser at admin/structure/views

This enables an example view that has a relationship added for both the Requester and Requestee accounts. You should be able to use these to populate both user fields for your Rules component.

RequesterAndRequestee


You should end up with a list of pending user relationships with checkboxes. Views Bulk Operations will run each selected item through the Rules component you created allowing an Administrator to delete pending user relationship requests between users.


Exported View - Retrieves Both Requester and Requestee UID's

$view = new view();
$view->name = 'user_relationships_browser';
$view->description = 'Shows someone\'s related users';
$view->tag = '';
$view->base_table = 'user_relationships';
$view->human_name = '';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['title'] = 'Relationships';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'plural_name' => 'plural_name',
  'name' => 'name',
  'changed' => 'changed',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'plural_name' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'name' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'changed' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Relationship: User relationships: Requestee user */
$handler->display->display_options['relationships']['requestee_id']['id'] = 'requestee_id';
$handler->display->display_options['relationships']['requestee_id']['table'] = 'user_relationships';
$handler->display->display_options['relationships']['requestee_id']['field'] = 'requestee_id';
/* Relationship: User relationships: Requester user */
$handler->display->display_options['relationships']['requester_id']['id'] = 'requester_id';
$handler->display->display_options['relationships']['requester_id']['table'] = 'user_relationships';
$handler->display->display_options['relationships']['requester_id']['field'] = 'requester_id';
/* Relationship: User relationships: RTID */
$handler->display->display_options['relationships']['rtid']['id'] = 'rtid';
$handler->display->display_options['relationships']['rtid']['table'] = 'user_relationships';
$handler->display->display_options['relationships']['rtid']['field'] = 'rtid';
/* Field: User: Uid */
$handler->display->display_options['fields']['uid']['id'] = 'uid';
$handler->display->display_options['fields']['uid']['table'] = 'users';
$handler->display->display_options['fields']['uid']['field'] = 'uid';
$handler->display->display_options['fields']['uid']['relationship'] = 'requestee_id';
$handler->display->display_options['fields']['uid']['label'] = 'Requestee User ID';
/* Field: User: Uid */
$handler->display->display_options['fields']['uid_1']['id'] = 'uid_1';
$handler->display->display_options['fields']['uid_1']['table'] = 'users';
$handler->display->display_options['fields']['uid_1']['field'] = 'uid';
$handler->display->display_options['fields']['uid_1']['relationship'] = 'requester_id';
$handler->display->display_options['fields']['uid_1']['label'] = 'Requester UID';
/* Sort criterion: User relationship types: Plural name */
$handler->display->display_options['sorts']['plural_name']['id'] = 'plural_name';
$handler->display->display_options['sorts']['plural_name']['table'] = 'user_relationship_types';
$handler->display->display_options['sorts']['plural_name']['field'] = 'plural_name';
$handler->display->display_options['sorts']['plural_name']['relationship'] = 'rtid';
/* Contextual filter: User relationships: Requester user */
$handler->display->display_options['arguments']['requester_id']['id'] = 'requester_id';
$handler->display->display_options['arguments']['requester_id']['table'] = 'user_relationships';
$handler->display->display_options['arguments']['requester_id']['field'] = 'requester_id';
$handler->display->display_options['arguments']['requester_id']['default_action'] = 'default';
$handler->display->display_options['arguments']['requester_id']['exception']['title_enable'] = TRUE;
$handler->display->display_options['arguments']['requester_id']['default_argument_type'] = 'user';
$handler->display->display_options['arguments']['requester_id']['default_argument_options']['user'] = FALSE;
$handler->display->display_options['arguments']['requester_id']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['requester_id']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['requester_id']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['requester_id']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['requester_id']['validate']['type'] = 'numeric';
/* Filter criterion: User relationships: Relationship status */
$handler->display->display_options['filters']['approved']['id'] = 'approved';
$handler->display->display_options['filters']['approved']['table'] = 'user_relationships';
$handler->display->display_options['filters']['approved']['field'] = 'approved';
$handler->display->display_options['filters']['approved']['value'] = '1';
$handler->display->display_options['filters']['approved']['group'] = '0';
$handler->display->display_options['filters']['approved']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['path'] = 'admin/manage-relationships/%';
$handler->display->display_options['menu']['type'] = 'normal';
$handler->display->display_options['menu']['title'] = 'All Relationships';
$handler->display->display_options['menu']['weight'] = '0';
  • Great idea, as I already have VBO and Rules installed for other reasons. Unfortunately, there are two snags which combined together I don't know how to get around: 1. The rules component to delete a relationship requires both the "requester" and "requestee" users to be provided. 2. With a view showing "user relationships," which is how I got the pending relationships to display, the bulk operations provided by VBO are not available (they are available for views of users, content, etc.) – Patrick Kenny Aug 21 '12 at 15:13
  • Addedum: By adding "User relationships: requestee/requester" user as relationships, I can then add the bulk operations to the view. However, I can only get one user at a time, but I need to provide both users to cancel the relationship. – Patrick Kenny Aug 21 '12 at 15:49
  • I've not used this module yet, but after playing with it I've installed it on a few of my own sites. Very cool module. That aside I've updated my answer to try and include details on creating the View (See additional resources). I've also included the Ctools exported view. – Citricguy Aug 21 '12 at 23:04
2

No, there is no special administrative pages for managing other people's relationships, but this would be a useful feature.

Have a look at user_relationships_load in user_relationships.module. You could use that to create a list of all of the pending relationships site wide by passing in user_relationships_load(array('approved' => FALSE));. You can further filter that by passing in additional information such as the relationship type. UR's views integration doesn't really take an administrators needs into account but you could build this list with views as well.

Once you have that list you can generate delete links that call user_relationships_delete_relationship. Calling that function with the proper RID (relationship ID) will delete those pending relationships for you.

If you don't want to build an admin page to come back to, there is nothing wrong with doing a little clean up directly in the database as long as you're careful and back up everything first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.