elgg_get_entities with custom SQL

Anyone that is much more profficient at SQL than me feel like helping me with selecting entities?

I want to select all groups where discussion is enabled, preferably ordered by the groups which have the most discussion topics.

Any help or guidence is appreciated.

  • No need to write sql. Have a look at parameters:

    • metadata_name_value_pairs - for filtering by metadata
    • order_by_metadata - for sorting by metadata

    Docs: http://reference.elgg.org/engine_2lib_2metadata_8php.html#aec4b6f0b9565e3554acb9b39ef34a2ac

  • I'm struggling to see the metadata relationship between groups and discussion topics? I can see that when a new topic is saved the group is set as its container_guid, but I don't think this helps at all.

    I'm leaning towards overriding or extending the discussion/save action, creating a relationship between the topic and the group and then searching with elgg_get_entities_from_relationship_count().

    Does this sound reasonable? Or am I missing something obvious with the metadata?

    Thanks

  • No, I think Pawel meant that you can search groups based on the "forum_enable" metadata.

    $groups = elgg_get_entities_from_metadata(array(
        'type' => 'group',
        'metadata_name_value_pairs' => array(
            'name' => "forum_enable"
            'value' => "no",
            'operand' => '!='
        ),
        'limit' => false
    ));

    This will return all groups that have group discussions enabled.

  • I see. Thanks.

    Although I still can't see how you could order the results based on the number of topics, as they are not stored as metadata? I think you may still need a JOIN (or something!) to do that? 

    I've actually done it my way now, it was quite simple and I think it makes the ordering easier. It also means that results will only show up if at least one discussion topic has been created.