Show the Time of a friendship in friends list

Marco Adamo Di Giuseppe Posted in General Discussion 6 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
us Rishi B Replied 6 years ago

Marco, nobody here is going to write the exact code that you want for you. We have told you more or less exactly how to implement the feature you asked about, it's now up to you to actually do it. In general, the OssnUser class contains a lot of information, including friends and relationship info. It's up to you to parse that data and extract the friendship time or any other attribute you are interested in (or just modify Arsalan's friendshiptimeprivate_function() to return the exact data you want).

German Marco Adamo Di Giuseppe Replied 6 years ago

Im confused... a pratical example it will be better also for the future to understand how to modify some function...

Indonesian Arsalan Shah Replied 6 years ago

i provided you the exact code as getFreinds() but with extra attribute since friends, now its up to you to find a way to integrate within your component. As it works exactly like existing code getFreinds() but it have extra attribute you requested.

The displaying array is a sample to get list in form of array, getFreinds() does the same.

German Marco Adamo Di Giuseppe Replied 6 years ago

Hi Arsalan,

as I previously reply the code you provide is not what im looking for... I don't need an array of friends but only the time of friendship. Thank you for all your help.

Indonesian Arsalan Shah Replied 6 years ago

Hi , i have provided the code you can now use it in your file and in loop you can display friends, please see the existing friends page(file) you can get idea instead of getFriends you can use getFriendshipTime() further you need to make changes in html that displays friendship time

German Marco Adamo Di Giuseppe Replied 6 years ago

Thank you Arsalan,

im trying to modify the page in system/plugins/default/output/users.php.

I added your component and insert the code

$user = ossnloggedinuser();
echo ossn_dump($user->getFriendshipTime())a

where I 'd like to show the friendship time, but an array of every data about every friend is show, also this for example "[timeoffriendship] => 13/04/2018"... I need only the time of friendship.
Where am I doing wrong?

Indonesian Arsalan Shah Replied 6 years ago

Hi Marco, its been sugested to upload entire code on https://gist.github.com or https://github.com/ so its easy for developers to take a look there and provide you fix.

Because on github its easier to take look the code and provide the path/fix/solution (for code file).

Below is the component i wrote it for you as example, so now when you access blow code, you'll see a time_of_friendship attribute added to the friends array

$user = ossn_loggedin_user();
echo ossn_dump($user->getFriendshipTime())

https://gist.github.com/lianglee/78fbfa10f6f52d26eeeef7959a70efa6

function ossn_friendship_time_init(){
    ossn_add_hook('ossn/class/register/method', 'OssnUser:getFriendshipTime', 'friendship_time_private_function');
}
function friendship_time_private_function($hook, $type, $user, array $params = array()){
                $freindships = new stdClass;
                if(isset($user->guid)) {
                        $user = $user->guid;
                }
                $default       = array(
                        'page_limit' => false,
                        'limit' => false,
                        'count' => false
                );
                $args          = array_merge($default, $params[0]);
                $relationships = ossn_get_relationships(array(
                        'to' => $user,
                        'type' => 'friend:request',
                        'inverse' => true,
                        'count' => $args['count'],
                        'order_by' => $args['order_by']
                ));
                if($args['count'] == true) {
                        $freindships->return = $relationships;
                        return $freindships;
                }
                if($relationships) {
                        foreach($relationships as $relation) {
                                $item      = ossn_user_by_guid($relation->relation_to);
                                $item->time_of_friendship = date('d/m/Y', $relation->time);
                                $friends[] = $item;
                        }
                        $freindships->return = $friends;
                        return $freindships;
                }
                $freindships->return = false;
                return $freindships;
}
ossn_register_callback('ossn', 'init', 'ossn_friendship_time_init');
German Marco Adamo Di Giuseppe Replied 6 years ago

What's wrong? Are you a moderator? I'm trying to solve a problem in a dedicated forum... I make a clear question with details, im editing the users.php page to show the date of a friendship below every friend in the list. It's normal to post some code and other stuff.

German Michael Zülsdorff Replied 6 years ago

Marco Adamo Di Guiseppe,

Arsalan told you already 8 months ago to use Github in order to discuss code changes or ideas you are trying to apply.
( see https://www.opensource-socialnetwork.org/discussion/view/2544/help-with-my-component-to-download-a-file )

So again: please stop posting code snippets here in this forum!

Currently, nodody is really able to follow WHERE you applied your code, WHAT exact syntax you were using and WHAT errors you got.

German Marco Adamo Di Giuseppe Replied 6 years ago

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

it 's doesn't work, errors and nothing showed.