Created
May 22, 2018 18:23
-
-
Save lianglee/78fbfa10f6f52d26eeeef7959a70efa6 to your computer and use it in GitHub Desktop.
A way to add new OssnUser method allowing to show friendship time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment