Show the Time of a friendship in friends list

Marco Adamo Di Giuseppe Posted in General Discussion 7 years ago

Hello,

can somebody tell if it possible show the date when a friendship is started? Something like "Friends since 02/15/2017"

Thanks

Replies
gb Rishi B Replied 7 years ago

get the logged in user in the way that I told you and call the getFriends() function, like Arsalan said.

$loggedInUser = ossnloggedinuser();
$friends
arr = $loggedInUser->getFriends();
vardump($friendsarr);

I'm not sure exactly where the timestamp is, but you should be able to find it if you look through what shows up in $friends_arr above. You shouldn't need to modify anything in OssnUser.php or any other classes if the timestamp for friendship is already there, as Arsalan said.

German Marco Adamo Di Giuseppe Replied 7 years ago

Arsalan I need to edit the public function in OssnUser.php? Can you help me with practical example please?

gb Rishi B Replied 7 years ago

also, in case it wasn't clear, you are supposed to replace UserA-GUID and UserB-GUID with the actual guid's of the users between whom you are checking the time that friendship was established. You can figure out the GUID of the currently logged in user on any OSSN page like this:

$loggedInUser = ossn_loggedin_user();
$loggedInGuid = $loggedInUser->guid;

When entries are stored in the database, the value of the field called owner-guid (or something along those lines) is what corresponds to $loggedInGuid above.

gb Rishi B Replied 7 years ago

Arsalan is right, you should use the built in interface if possible, but the code you pasted is not correctly looping over the mysql $results object. You can't just echo it, you have to do something like this:

while ($row = mysqli_fetch_array($result))
{
   echo $row[0]; // this will output the first column of the first row of your result. you can access subsequent cols as $row[1], etc.
}
Indonesian Arsalan Shah Replied 7 years ago

running the self sql queries are not recomended you should take a look OssnUser:getFriends()
It is using ossngetrelationships() , which already have a timestamp.
while looping you can store the time $relation->time in any place. then using date() function you can convert the time stamp to readable date.

German Marco Adamo Di Giuseppe Replied 7 years ago

Thanks for reply.

I wrote this:
////////////////////////////// $link = mysqliconnect("connectdb", "namedb", "userdb", "passdb");
$sql = "SELECT MAX(time) FROM ossn
relationships WHERE (relationto = UserAGUID AND relationfrom = UserBGUID) OR (relationto=UserBGUID and relationfrom=UserAGUID)";
$results = mysqliquery($link, $sql);
echo $results;
mysqli
close($link);
//////////////////////////////
But nothing happen...is it right?

gb Rishi B Replied 7 years ago

sorry, the 2nd to last sentence of my post should say, "that query will give you the time in the form of a unix timestamp that the friendship became complete." If you want a more human readable form, like mm/dd/yy you could use a PHP function like date() or a MySQL function like FROM_UNIXTIME().

gb Rishi B Replied 7 years ago

yes, you just need to check the table called ossn-relationships (underscore not hyphen, but this control interprets an underscore differently). basically the way friendship works in OSSN is that there must be 2 entries of type "friend:request" in the "type" column - going both to and from UserAGUID. If you want the time that the friendship between UserAGUID and UserB_GUID became official, you need to check for the later of the 2 values in the "time" column in either of these 2 rows. This can be done with the SQL query:

SELECT MAX(time) FROM ossn_relationships WHERE (relation_to = UserA_GUID AND relation_from = UserB_GUID) OR (relation_to=UserB_GUID and relation_from=UserA_GUID)

that query will give you the time that the friendship became complete. On other hand, if you want the time that the friendship request was first initiated, for example, you could just change MAx() to MIN().

Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions