0

I have user relationship, statuses and views installed. I created a view which shows "users online". I need to add a link to the view, that would allow other users to "create a relationship" with other online users via the view.

The user relationship I created is a one way relationship and there is no need for approval.

Thank you.

3
  • Hello. Is your problem on the link generation side, or relationship creation in code side?
    – Mołot
    Commented Jul 15, 2013 at 9:46
  • I have not done any custom coding. I assumed this was taken care of via the user relationship module. Based on your question, I believe I need help with both. Thanks.
    – seyi
    Commented Jul 15, 2013 at 12:17
  • Looks like answer below shows that 1) it is already partially provided by relationships (how did I miss that?) and 2) how to code missing parts :) Try it, but looks solid on first glance or two.
    – Mołot
    Commented Jul 15, 2013 at 12:22

1 Answer 1

1

Hope this will help you,

In Drupal 7, after configuration User relationship

  • Create a php field using views php module and after enabling, add below code in OUTPUT CODE within PHP tags.

      global $user;
      $opt = '';
      $requestee_id = $row->uid;
      $requester_id = $user->uid;
      if (user_is_logged_in()) {
        if ($requestee_id != $requester_id) {
          //for friend request button
          $relationships = user_relationships_load(array('between' => array($requester_id, $requestee_id)));
          if (empty($relationships)) {
            $opt = l(t('Add Friend') , "relationship/$requestee_id/request/2", array('html' => TRUE, 'absolute' => TRUE, 'query' => array('destination' => 'user/' . $requestee_id), 'attributes' => array('class' => array('ur-link add-friend-btn user_relationships_popup_link'))));
          }
          else {
            foreach ($relationships as $relationship) {
              if ($relationship->approved == 1 && user_relationships_ui_check_access('view', NULL, $relationship)) {
                $opt = t('<span class="already-frnd">Friends</span>');
              }
            }
          }
        }
      }
      print $opt;
    

Note

  • 2 is the default USER relationship.
  • Requester ID - Who requested and Requestee ID - to whome the user is requested.

Make changes as per your requirement.

6
  • Thanks. I will need time to digest and implement this. (Not yet proficient at coding).
    – seyi
    Commented Jul 15, 2013 at 12:20
  • OK, ill give a brief explanation, user_relationships_load is a function which is used to load the relationship between requester and the Requestee. If relationship exist means there is a relationship between. If there is a relationship then outputting the FRIEND text else returning the ADD FRIEND link.
    – Inizio
    Commented Jul 15, 2013 at 15:19
  • For some reason, the actual code is being output. Am thinking its because nothing related to relationship is among the "available variables". Kindly assist further.
    – seyi
    Commented Jul 16, 2013 at 11:13
  • Hello, am still not able to get it to work. Please can you walk me through the steps? I added the above code as directed but did not get the desired result. Thanks.
    – seyi
    Commented Jul 19, 2013 at 4:22
  • First check the default relationship(friend) ID is 2 or not. Go to admin/config/people/relationships and hover edit link you will get the default relationship(friend) ID. And remove * from the "Add friend" link, I have given it for highlighting the default relationship ID. And also check the USER IDs($row->uid).
    – Inizio
    Commented Jul 19, 2013 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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