Friend System Questions

Forum
Last Post
Threads / Messages

Kyttias

Super Moderator
Super Mod
Joined
Jan 26, 2014
Messages
849
Points
18
Mysidian Dollar
58,199
1) I've created a link on my user profiles to display a link to send a friend request. I'd like to prevent it from displaying on the profiles of users you're already friends with? Currently in classes/class_userprofile.php I have something like this:
PHP:
    if (($mysidia->user->username != $mysidia->input->get("user")) && ($mysidia->user->usergroup->gid < 5)){
      $member = new Member($mysidia->input->get("user"));
      $friendrequest = "<a href='../../friends/request/{$member->uid}'>Send Friend Request</a>";      
    }

2) What exactly happens when you remove from your friend list? I was unable to refriend a user I had accidentally removed because the database kept the status as 'confirmed'. It wouldn't allow me to send a request again because the entry was never removed. I had to set it back to 'pending' manually and then have the other user go into their account settings and reapprove the request. How can I go about making refriending someone possible? Perhaps just remove the original entry from adopts_friend_requests while the friend is removed?
 
Last edited:
1. For this you will need to add an if check to the location that renders 'send a friend request' link on user profile page. Look for file classes/class_userprofile.php at around line 184-185, and you will find this:

PHP:
      $document->add(new Image("templates/icons/fr.gif", "Send a Friend Request"));
      $document->add(new Link("friends/request/{$member->uid}", "Send {$mysidia->input->get("user")} a Friend Request", TRUE));

What you can do is to add an if check to this block of code, and to add friend request image/link to document only if the user is not a friend with you yet.


2. I honestly never tested the edge case when you attempt to add a friend back after you break friendship. So I think there is a chance that you cannot add him/her back since the friend request stays in database, you cannot send duplicate friend requests. If this happens, and it is not the desired behavior for you, you can simply remove the friend request from database once you remove a friend.
 
1) Yes. The question was how do I write the check itself? I already have the contents how I want them. I just don't quite understand how I would need to form that. :cfrown:

2) Hmm... Where? (In the friend class's remove function?) Also not the most familiar with calls to the database to remove entries. Only one of the friends will have been the one to initiate the request.... hmm. :ooo:

Thanks anyway, HoF! :happycbig:
 
1. You will need to check if the user is on your friendlist, and only show the 'send a friend request' image and link when the user is not a friend of yours yet. The below steps demonstrates how to check this:

PHP:
$friendlist = new Friendlist($mysidia->user); //create your own friendlist object.
$friend = new Friend(new Member($mysidia->input->get("user")), $friendlist); //create a friend object.
if(!$friend->isfriend){ //only show if the user is a friend of yours. 
    $document->add(new Image("templates/icons/fr.gif", "Send a Friend Request"));
    $document->add(new Link("friends/request/{$member->uid}", "Send {$mysidia->input->get("user")} a Friend Request", TRUE));     
}

Note the above code may need some tweaks, as if you are viewing the page as a guest you may get get a glitch. You can test it and lemme know how it goes.

2. Yeah, you can add one line to the friend class' remove method, to delete the row from table prefix_friend_requests. The code should look like this below:

PHP:
$mysidia->db->delete("friend_requests", "(fromuser='{$mysidia->user->username}' AND touser='{$this->username}') OR (touser='{$mysidia->user->username}' AND fromuser='{$this->username}')");

This above code should delete a row with friend request between you and your old friend that you dont want to maintain friendship anymore. After the friend request is deleted, you should be able to send friend request to this user again without any problems.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,122
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top