Dispaly the groups which the user not member of the group

Hi...

I want to Dispaly the groups which the user not member of the group..

is ti possible?

  • yes ,again it still shows all group...........

  • check_entity_relationship() is not working why?

  • If it still shows all groups and doesn't remove the groups the user is a member of, then there is probably and issue with the check_entity_relationship running a check the wrong way. Depends who owns that relationship.

    read the documentation on how to use that function, and find an example of it in the groups plugin.

  • @BEN Trajan's solution should work for you, but it's actually more effective if you pull all these groups in a single query, rather than post-processing all groups and calling the check_entity_relationship for each one. You can do this by adding custom JOIN and WHERE clauses to your elgg_get_entities query. Here is the full code:

        $options = array(
            "type" => "group",
            "joins" => array(
                "LEFT JOIN {$CONFIG->dbprefix}entity_relationships r ON (r.relationship = 'member' AND r.guid_two = e.guid AND r.guid_one = {$user_guid})"
            ),
            "wheres" => array(
                "r.id IS NULL"
            )
        );
       
        $count = elgg_get_entities(array_merge($options, array("count" => true)));
        $options['limit'] = $count;
        $groups = elgg_get_entities($options);

    Make sure to have a reference of the $CONFIG variable (global $CONFIG;) and to pass your current user's guid in the $user_guid variable.

  • @Andras: very slick coding there mate. You've given me a direction to further my coding development. Cheers

  • @Andras:i tried as u said first it shows database error.

    when i correct joins to join and wheres to where. its working

    but still it shows all groups...

  • @BEN: is the user you're logged in as actually a member of any groups?

    try logging in as a normal (non-admin) user and join a group then look and see if that group shows up.

  • yes iam sure,,

    iam loginned as normal user.

  • @Trajan Glad you liked that :)

    @BEN This code, as it is, was tested on Elgg 1.7.10+ and gave me only those groups that the current user was not a member of. What Elgg version are you using? What was the error message that you got before modifying "joins" and "wheres" to "join" and "where"?

  • Thanks every body..............

    when i run upgrade.php its working fine with "joins" and "wheres"..

    Thanks a lot...