Hello.
I'm trying to rewrite the code for Elgg 3.
The code on Elgg 2 is:
$guid = elgg_get_logged_in_user_guid();
$options = [
'type' => 'user',
'limit' => 10,
'joins' => "JOIN {$dbprefix}entity_relationships er ON er.guid_one = $guid
AND er.relationship = 'member'",
'wheres' => "er.guid_two IN (SELECT guid_two FROM {$dbprefix}entity_relationships
WHERE guid_one = e.guid
AND relationship = 'member')",
];
return elgg_get_entities($options);
$alias = 'er';
$guid = elgg_get_logged_in_user_guid();
$relationship = 'member';
$options = [
'types' => 'user',
'limit' => 10,
];
$options['wheres'][] = function(QueryBuilder $qb, $table_alias) use ($alias, $guid, $relationship) {
$joins = [];
$joins[] = $qb->compare("$alias.guid_one", '=', $guid, ELGG_VALUE_GUID);
$joins[] = $qb->compare("$alias.relationship", '=', $relationship, ELGG_VALUE_STRING);
$qb->join($table_alias, 'entity_relationships', $alias, $qb->merge($joins));
$sub = $qb->subquery('entity_relationships', $alias);
$sub->select('guid_two')
->where($qb->compare('guid_one', '=', "$table_alias.guid", ELGG_VALUE_GUID))
->andWhere($qb->compare('relationship', '=', $relationship, ELGG_VALUE_STRING));
//return $qb->compare("$alias.guid_two", 'IN', $sub->getSQL());
return $qb->where($qb->compare("$alias.guid_two", 'IN', $sub->getSQL()));
};
var_dump(elgg_get_entities($options));
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- ronnim@ronnim
ronnim - 0 likes
- Nikolai Shcherbin@rivervanrain
Nikolai Shcherbin - 0 likes
- rjcalifornia@rjcalifornia
rjcalifornia - 0 likes
- Nikolai Shcherbin@rivervanrain
Nikolai Shcherbin - 0 likes
You must log in to post replies.Where can I read Querybuilder documentation?
https://www.doctrine-project.org/projects/doctrine-dbal/en/2.10/reference/query-builder.html#sql-query-builder
Wait, elgg 3 finally uses Doctrine?
Suprise ;)