Hi all,
I'm new here, so sorry if this isn't the right place or if the answer was easy to find.
I'm looking for all objects of a certains subtype, say JrobinssSubtype, that belong to a given user. Here's how I proceed:
$objects = $user->getObjects('JrobinssSubtype', 0); // 0: no limit
There's no result, even though I know that there should be (I created the object and checked its owner guid). By going into Elgg's source code and tracing the SQL request, I found that the request tested for owner_id and also for container_id. Here's an extract of the (longish) request (let's say that user->guid=2):
[...] AND (e.owner_guid IN (2)) AND (e.container_guid IN (2))[...]
The result is empty, because the objects are contained in something else than the user.
I found this code in entities.php:
01573 if (is_null($container_guid)) { 01574 $container_guid = $owner_array; 01575 }
If I run the SQL request without the container, I get exactly the result I want.
Question 1: I don't understand why container_guid should default to owner_guid. I thought container was a fairly straightforward concept.
Question 2: assuming this is not a bug, how can I get all objects for this user and this subtype?
My current workaround is going to be: write my own SQL request. X-p
thanks for any help!
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.
- Brett@brett.profitt

Brett - 0 likes
- jrobinss@jrobinss

jrobinss - 0 likes
You must log in to post replies.Is this in 1.7? The functions used for the OO methods are very outdated and have been deprecated for 1.8. I opened a ticket to address the OO methods themselves: http://trac.elgg.org/ticket/3785
Use elgg_get_entities() to grab the objects instead.
$objects = elgg_get_entities(array(
'type' => 'object',
'subtype' => 'JRobinssSubtype',
'owner_guid' => $user->getGUID(),
'container_guid' => 1234
));
Here are some code snippets from users.php
public function getObjects($subtype="", $limit = 10, $offset = 0) {
return get_user_objects($this->getGUID(), $subtype, $limit, $offset);
}
function get_user_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10, $offset = 0, $timelower = 0, $timeupper = 0) {
$ntt = elgg_get_entities(array(
'type' => 'object',
'subtype' => $subtype,
'owner_guid' => $user_guid,
'limit' => $limit,
'offset' => $offset,
'container_guid' => $user_guid,
'created_time_lower' => $timelower,
'created_time_upper' => $timeupper
));
return $ntt;
}
I seems that you're right and there's a bug in there, container_guid is set to user_guid.
Thanks for the tip. Apparently I hadn't checked that, which is strange (I thought I had), probably because I thought I found the bug elsewhere. Live and learn.
Many thanks!