How does Relationship_Created_Time_Lower work?

Using the code below, I am trying to find the amount of users who have joined the specific group between two days (essentially in the last month exactly)

$monthSpan = (30 * 24 * 60 * 60);
$startTime = time() - $monthSpan;

 

$MemberDifference = elgg_get_entities_from_relationship(array(
'relationship' => 'member', //get Members
'relationship_guid' => $Reports->guid, //get individual guid for use
'inverse_relationship' => true,
'type' => 'user', //users are returned
'limit' => 20,
'joins' => array("JOIN {$db_prefix}users_entity u ON e.guid=u.guid"),
'order_by' => 'u.name ASC',
'relationship_created_time_lower' => $startTime, //the furthest back it will reach
'relationship_created_time_upper' => time(), //possibly unneeded, but ensures the closest date is today
'count' => true,
));

 

However, using this seems to instead just give me back my exact total members of the group, rather than that ones who have joined in the last month.

What must I be doing wrong? From what the documentation says, using created time lower should be more than enough to do that.

Thanks!

  • $group = elgg_get_page_owner_entity();
    
    $dbprefix = elgg_get_config('dbprefix');
    
    $options = [
        'type' => 'group',
        'relationship' => 'member',
        'relationship_guid' => $group->getGUID(),
        'inverse_relationship' => false,
        'count' => true,
        'joins' => array("JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"),
        'relationship_created_time_lower' => $startTime,
        'relationship_created_time_upper' => time(),
    ];
    echo elgg_get_entities_from_relationship($options));

    Returns 'count'.

    Offtopic: Please, don't use your colored snippet here. My eyes are broken ;)

    Use Code block button on the text editor like me in this post.

     

  • Thank you, that was wonderful help! And my apologies.

  • I must rescind that unfortunately. It appears that nothing is actually cataloged with these joins and leaves. The value is currently hard stuck at 0, and fiddling around with the code doesnt seem to help fix anything at the moment. 

    Do you mind helping me a bit more to figure this out?

  • $group = elgg_get_page_owner_entity();
    $start = mktime(0, 0, 0, date("m") , date("d")-2, date("Y"));
    $dbprefix = elgg_get_config('dbprefix');
    $options = [
        'type' => 'user',
        'relationship' => 'member',
        'relationship_guid' => $group->getGUID(),
        'inverse_relationship' => true,
        'count' => true,
        'relationship_created_time_lower' => $start,
        'relationship_created_time_upper' => time(),
    ];
    echo elgg_get_entities_from_relationship($options);

    Returns a count of the group' members which joined to group in last 2 days

  • Still nothing unfortunately. Do the relationship created time functions exist within elgg 1.8? my team and I are using that version, and building upon the code you gave us always seems to either capture 100% of the members of that group, or none of them. So it could be because that isnt actually available to do in our version?

  • It's works very well on Elgg 2.x.

    I forgot about Elgg 1.8 long time ago but seems it's not work there.

    My advice: start to migrate on actual Elgg version now until you have gone too far  with old code.

  • If you are still using Elgg 1.8 you should always tell this right from the start. Then you won't waste the time of others who don't know this and give you advice that works on newer versions of Elgg but not on Elgg 1.8.

    As far as I know elgg_get_entities_from_relationship() of Elgg 1.8 has no 'relationship_created_time_lower' and 'relationship_created_time_upper' options yet.

    Maybe it works with the following (you need to assign the desired values to $group and $startTime variables before):

    $recent_members = elgg_get_entities_from_relationship(array(
        'type' => 'group',
        'relationship' => 'member',
        'relationship_guid' => $group->guid,
        'inverse_relationship' => false,
        'wheres' => array("r.time_created >= $startTime"),
    ));

    (not tested the code and I'm not sure if Elgg uses the r variable internally in the mysql query - if it fails, the fatal error output should reveal the query code and you should be able to adjust the wheres clause)

  • A member of our team actually just discovered this the second I began reading this post. Thank you for your help, and I apologize that I failed to mention that at the beginning but I often forget how out of date we really are. 

     

    Still, you guys were great helps, and I thank you very much for taking the time to help me with this!