You are here

function user_relationships_update_relationship in User Relationships 5

Same name and namespace in other branches
  1. 5.2 user_relationships_api.inc \user_relationships_update_relationship()

Public API for updating a relationship.

Parameters

$relationship: object of the current relationship

$updated_relationship: object of the updated relationship

Return value

object of the updated relationship

2 calls to user_relationships_update_relationship()
user_relationships_pending_requested_submit in ./user_relationships_actions.inc
Approve, Disapprove, or Cancel a relationship request
user_relationship_implications_user_relationships in plugins/user_relationship_implications/user_relationship_implications.module
hook_user_relationships()

File

./user_relationships_api.inc, line 213

Code

function user_relationships_update_relationship(&$current_relationship, &$updated_relationship) {

  // ensure data that shouldn't change doesn't
  $updated_relationship->rid = $current_relationship->rid;
  $updated_relationship->created_at = $current_relationship->created_at;

  // call any hooks that might want to know about updating this relationship
  _user_relationships_invoke('update', $updated_relationship);

  // update the db
  db_query("UPDATE {user_relationships}\n               SET requester_id=%d,\n                   requestee_id=%d,\n                   rtid=%d,\n                   approved=%d\n             WHERE rid=%d", $updated_relationship->requester_id, $updated_relationship->requestee_id, $updated_relationship->rtid, $updated_relationship->approved ? 1 : 0, $current_relationship->rid);

  // clear the cache of both (all) users' list of all relationships
  // requester and requestee should be the same in the old and new relationships, but better safe than sorry
  cache_clear_all("user_relationships_relationships_{$current_relationship->requester->uid}", 'cache_user_relationships');
  cache_clear_all("user_relationships_relationships_{$current_relationship->requestee->uid}", 'cache_user_relationships');
  cache_clear_all("user_relationships_relationships_{$updated_relationship->requester->uid}", 'cache_user_relationships');
  cache_clear_all("user_relationships_relationships_{$updated_relationship->requestee->uid}", 'cache_user_relationships');
  return $updated_relationship;
}