function user_relationships_ui_actions_between in User Relationships 7
List of possible relationship actions with between two users.
Parameters
$viewer: User object for the visitor.
$viewed: User object for the user being looked at.
action_types: Associative array of kinds of links to show (all by default). Only the existence of specific array keys is needed: add, remove, requested, received.
$rtids: Associative array of relationships type ids to show (all by default). Row values must be rtids of relationship types.
Return value
An array with actions as strings.
4 calls to user_relationships_ui_actions_between()
- template_preprocess_user_relationships_actions_block in user_relationship_blocks/
user_relationship_blocks.module - Template pre processor for the relationship actions block
- user_relationships_ui_user_view in user_relationships_ui/
user_relationships_ui.module - user_relationship_invites_invite_form_validate in user_relationship_invites/
user_relationship_invites.module - Custom form validation handler for the 'invite_form' form from Invite module This custom handler acts to store the User Relationships relationship type ID so that it can be used in the hook_invite implementation as it is not otherwise…
- views_handler_field_user_relationships_action::render in user_relationship_views/
views_handler_field_user_relationships_action.inc - Render the field.
File
- user_relationships_ui/
user_relationships_ui.module, line 56 - UI components of user_relationships @author Jeff Smick (creator) @author Alex Karshakevich (maintainer) http://drupal.org/user/183217 @author Darren Ferguson (contributor) http://drupal.org/user/70179
Code
function user_relationships_ui_actions_between($viewer, $viewed, $action_types = array(
'add' => 1,
'remove' => 1,
'requested' => 1,
'received' => 1,
), $rtids = array()) {
if ($viewer->uid == $viewed->uid) {
return array();
}
$list = array();
$from_us = user_relationships_load(array(
'requester_id' => $viewer->uid,
'requestee_id' => $viewed->uid,
));
if (isset($action_types['requested'])) {
foreach ($from_us as $relationship) {
if (!$relationship->approved && (empty($rtids) || in_array($relationship->rtid, $rtids))) {
$list[] = t('You have sent a new @rel_name request to this user. (!pending_requests)', array(
'!pending_requests' => l(t('pending requests'), "relationships/sent"),
) + user_relationships_type_translations($relationship));
}
}
}
if (isset($action_types['received'])) {
$to_us = user_relationships_load(array(
'requester_id' => $viewed->uid,
'requestee_id' => $viewer->uid,
));
foreach ($to_us as $relationship) {
if (!$relationship->approved && (empty($rtids) || in_array($relationship->rtid, $rtids)) && user_relationships_user_access('maintain @relationship relationships', $relationship)) {
$list[] = t('This user has requested to be your @rel_name. (!pending_requests)', array(
'!pending_requests' => l(t('pending requests'), "user/{$viewer->uid}/relationships/received"),
) + user_relationships_type_translations($relationship));
}
}
}
if (isset($action_types['add'])) {
$relationships = user_relationships_get_requestable_rtypes($viewer, $viewed, 'full');
if ($relationships) {
// If configured, create direct links.
if (variable_get('user_relationships_show_direct_links', 1)) {
// Create a single link, or one for each relationship type.
foreach ($relationships as $relationship_type) {
if (empty($rtids) || in_array($relationship_type->rtid, $rtids)) {
$list[] = theme('user_relationships_request_relationship_direct_link', array(
'relate_to' => $viewed,
'relationship_type' => $relationship_type,
));
}
}
}
else {
$list[] = theme('user_relationships_request_relationship_link', array(
'relate_to' => $viewed,
));
}
}
}
if (isset($action_types['remove'])) {
foreach ($from_us as $relationship) {
if ($relationship->approved && (empty($rtids) || in_array($relationship->rtid, $rtids)) && !isset($list[$relationship->rid]) && user_relationships_ui_check_access('view', NULL, $relationship)) {
if (user_relationships_ui_check_access('delete', NULL, $relationship)) {
$list[] = t('@rel_name (!remove_link)', array(
'@rel_name' => user_relationships_type_get_name($relationship) . ($relationship->is_oneway ? $relationship->requester_id == $viewer->uid ? t(' (You to Them)') : t(' (Them to You)') : NULL),
'!remove_link' => theme('user_relationships_remove_link', array(
'uid' => $viewer->uid,
'rid' => $relationship->rid,
)),
));
}
else {
$list[] = user_relationships_type_get_name($relationship) . ($relationship->is_oneway ? $relationship->requester_id == $viewer->uid ? t(' (You to Them)') : t(' (Them to You)') : NULL);
}
}
}
}
return $list;
}