function user_relationships_request_relationship in User Relationships 5
Same name and namespace in other branches
- 5.3 user_relationships_api/user_relationships_api.api.inc \user_relationships_request_relationship()
- 5.2 user_relationships_api.inc \user_relationships_request_relationship()
- 6 user_relationships_api/user_relationships_api.api.inc \user_relationships_request_relationship()
- 7 user_relationships.module \user_relationships_request_relationship()
Public API for creating a relationship.
Parameters
$requester: object of the requester
$requestee: object of the requestee
$relationship_type: object of the relationship type
$status: string status of the relationship
Return value
object of the newly created relationship
4 calls to user_relationships_request_relationship()
- user_relationships_request_submit in ./
user_relationships_actions.inc - Process relationship request.
- user_relationship_defaults_user in plugins/
user_relationship_defaults/ user_relationship_defaults.module - hook_user()
- user_relationship_implications_user_relationships in plugins/
user_relationship_implications/ user_relationship_implications.module - hook_user_relationships()
- user_relationship_invites_user in plugins/
user_relationship_invites/ user_relationship_invites.module - Implements hook_user()
File
- ./
user_relationships_api.inc, line 153
Code
function user_relationships_request_relationship(&$requester, &$requestee, &$relationship_type, $approved = FALSE) {
if (!variable_get('user_relationships_allow_multiple', TRUE)) {
if (user_relationships_count_relationships(array(
'uid1' => $requester->uid,
'uid2' => $requestee->uid,
)) > 0) {
return t('Users are not allowed to have multiple relationships');
}
}
$existing = db_result(db_query(" SELECT 1 \n FROM {user_relationships} ur, {user_relationship_types} urt\n WHERE ur.rtid = %d\n AND ur.rtid = urt.rtid\n AND ((requester_id = %d AND requestee_id = %d)\n OR (is_oneway = 0 AND requestee_id = %d AND requester_id = %d)\n )", $relationship_type->rtid, $requester->uid, $requestee->uid, $requester->uid, $requestee->uid));
if ($existing) {
return t('This relationship already exists');
}
$user_auto_approve = is_array($requestee->user_relationships_auto_approve) && $requestee->user_relationships_auto_approve[$relationship_type->rtid];
if ($user_auto_approve || !$relationship_type->requires_approval) {
$approved = TRUE;
}
$rid = db_next_id('{user_relationships}_id');
db_query("INSERT INTO {user_relationships} (rid, requester_id, requestee_id, rtid, approved, created_at)\n VALUES (%d, %d, %d, %d, %d, NOW())", $rid, $requester->uid, $requestee->uid, $relationship_type->rtid, $approved ? 1 : 0);
cache_clear_all("user_relationships_relationships_{$requester->uid}", 'cache_user_relationships');
cache_clear_all("user_relationships_relationships_{$requestee->uid}", 'cache_user_relationships');
$relationship = user_relationships_relationship_load($rid);
_user_relationships_invoke('insert', $relationship);
return $relationship;
}