function user_relationships_request_relationship in User Relationships 5.3
Same name and namespace in other branches
- 5 user_relationships_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 or ID of the requester
$requestee: object or ID of the requestee
$type: object or ID of the relationship type
$approved: boolean status of the relationship
Return value
object of the newly created relationship
1 call to user_relationships_request_relationship()
- user_relationships_ui_request_submit in user_relationships_ui/
user_relationships_ui.actions.inc - Process relationship request.
File
- user_relationships_api/
user_relationships_api.api.inc, line 157
Code
function user_relationships_request_relationship($requester, $requestee, $type, $approved = FALSE) {
// translate an ID into an object
foreach (array(
'requester' => $requester,
'requestee' => $requestee,
'type' => $type,
) as $key => $value) {
if (!is_object($value)) {
${$key} = $key == 'type' ? user_relationships_type_load($value) : user_load($value);
}
}
if (!user_relationships_load(array(
'between' => array(
$requester->uid,
$requestee->uid,
),
'rtid' => $type->rtid,
), array(
'count' => TRUE,
))) {
$relationship = (object) array(
'requester_id' => $requester->uid,
'requestee_id' => $requestee->uid,
'approved' => $approved || !$type->requires_approval,
'rtid' => $type->rtid,
);
return user_relationships_save_relationship($relationship);
}
}