Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[T] OssnUser::getFriends() #2149

Closed
lianglee opened this issue Apr 21, 2022 · 12 comments
Closed

[T] OssnUser::getFriends() #2149

lianglee opened this issue Apr 21, 2022 · 12 comments

Comments

@lianglee
Copy link
Member

No description provided.

@lianglee
Copy link
Member Author

Verify the use on all places where getFriends() used

@githubertus
Copy link
Contributor

used on my 6.2dev without issues at:

./libraries/ossn.lib.users.php:138:
./libraries/ossn.lib.users.php:218:
./libraries/ossn.lib.users.php:223:
./components/bio/classes/Bio.php:68:
./components/DisplayUsername/ossn_com.php:99:
./components/LatestMembers/widgets/friends_widget.php:17:
./components/OssnChat/classes/OssnChat.php:91:
./components/OssnChat/classes/OssnChat.php:139:
./components/OssnProfile/plugins/default/profile/pages/friends.php:12:
./components/OssnProfile/plugins/default/profile/pages/friends.php:15:
./components/OssnProfile/plugins/default/profile/modules/friends.php:11:
./components/OssnWall/classes/OssnWall.php:181:
./components/OssnWall/classes/OssnWall.php:322:
./components/OssnWall/classes/OssnWall.php:384:
./components/OssnWall/classes/OssnWall.php:435:
./components/OssnWall/ossn_com.php:112:
./themes/Flexi/plugins/default/flexi/friends_widget.php:16:

@lianglee
Copy link
Member Author

lianglee commented May 2, 2022

@githubertus ❤️

@lianglee lianglee changed the title [TEST] OssnUser::getFriends() [T] OssnUser::getFriends() May 15, 2022
@githubertus
Copy link
Contributor

i just noticed that it's no longer easy to get a list of latest friends ... because the relationships_id isn't part of the new query result
any idea of what attributes to pass in order to get this back working again?

@lianglee
Copy link
Member Author

Latest friends isn't ORDER BY u.guid DESC (limit 10, 20 etc) ?

getFriends(id, ['order_by' => 'u.guid DESC']); ?

@lianglee
Copy link
Member Author

I think you are right and I understand about relation id. Let me check.

@lianglee
Copy link
Member Author

One of the way is :

<?php
$r = ossn_get_relationships(array(
		'to'       => ossn_loggedin_user()->guid,
		'type'     => 'friend:request',
		'order_by' => 'r.relation_id DESC',
		'inverse'  => true,
));
if($r) {
		$guids          = implode(',', array_column((array) $r, 'relation_to'));
		$user           = new OssnUser();
		$latest_friends = $user->searchUsers(array(
				'wheres'   => "(u.guid IN ($guids))",
				'order_by' => "FIELD(u.guid, {$guids})",
		));
		echo ossn_dump($latest_friends);
}

@lianglee
Copy link
Member Author

Other method

<?php
<?php
$user           = new OssnUser();
$latest_friends = $user->searchUsers(array(
		'joins'    => array(
				'JOIN ossn_relationships AS r1 ON r1.relation_to = u.guid AND r1.type = "friend:request"',
				'JOIN ossn_relationships AS r2 ON r2.relation_from = r1.relation_to AND r2.type = "friend:request"',
		),
		'wheres'   => '(r1.relation_from = 1)', //replace with loggedin user ID
		'order_by' => 'r1.relation_id DESC',
));
echo ossn_dump($latest_friends);

@lianglee
Copy link
Member Author

I believe I need to replace latest getFriends with above method so it returns relation.* in field list as it works same. I will update method soon and test

@githubertus
Copy link
Contributor

thank you! and I'm sorry I didn't become aware earlier of this. It's a little strange, I thought I tested it with the changes you did, but maybe my users class wasn't really up-to-date that time.... :(

@githubertus
Copy link
Contributor

last one is working almost fine
i have added 'distinct' => true
because otherwise you may get duplicates

@lianglee
Copy link
Member Author

lianglee commented Jul 12, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants