get entities from lack of metadata?

Anyone have a good elgg-ish way I can get an array of entities that don't have a specific peice of metadata? Not metadata equal to 0 or NULL, but metadata that hasn't yet been created?

  • sql -- entity left join meta -> fetch on right meta = null

  • Dhrup is right, here is a working example from another topic. This checks for lack of relationship instead of lack of meta, but principle is the same. This will get all groups that the current user is not member of.

    $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);

    As for a pure Elgg-ish way, I'm afraid that's not possible with the current 1.8 API. Maybe something the core team is willing to consider and add for 1.9?

  • Yes, I would love to see some functions that allow to search for things that don't have something.

    This would make things such as reminding users about profile icons, missing profile fields etc. much simpler and quicker.

  • Thanks everyone, that should do just fine.

    Indeed core functions for such things would be nice, is it a fairly common task?  Not that I've encountered.  Once added to core though, unless the db structure changes I don't imagine there's much maintenance involved so maybe is worth while?

  • @Matt: the other idea that popped into my head with this is the facebook style system of reminding other users (friends) about things they are missing. Long distance, could even turn that into a rward scheme for getting other users active.

    (A little off topic but based on my earlier comment)

  • @T:

    Might as well start a new topic in 'Features' or whatever group.. What you described sounds like it might lead to some serious & original new features. I like the sound of '..things.. missing... reward scheme..... "

    @M:

    Looking forward to soon reading yr finished code for the no-metadata situation. The Trac item does have some sql samples in there.

     

  • It's a private plugin I'm making that requires this, and it's very specific to their site that it's not really going to be useful anywhere else (it calculates statistics on a number of functions that are specific and custom made for their site).  But the general idea is, the calculation has to be done for each user at least once every 24 hours.  I'm using a number of event hooks to distribute the load, so the calculation happens when they log in, or when someone creates an annotation on an entity they own (as annotations are part of the stats).  But if that doesn't happen in 24 hours, the calculation still needs to be done, so I'm using an hourly cron that will get 1/24 of the population of uncalculated users and process them, then offset and repeat the next hour, and on and on.  But I don't want to calculate on someone that has already logged in, so when the calculation occurs, it creates metadata on the user to essentially flag it as complete for the day.  On cron then, I need to get 1/24 of all users that don't have that metadata.  I hope that makes sense.

    The JOIN listed in the trac ticket is perfect for my needs.  A convenience function would be nice, but I'm certainly not going to nag the core team for it.

    @Trajan - the uses you've mentioned are interesting, I like the ideas

  • matt,  "private plugin.. very specific to.. not really going to be useful..."  me ± 5.75% bilked ∵ you post @ free open gratis elgg comm for techie pointers for your $project ≅  <: {ℙ} → so how do professionals give congruent reciprocals in such situation ? you've taken.. what you offer in return ? for {π 2011.. } ∴ {elgg comm} ⋈ ⇔ ⊢ {matt} □

  • Dhrup - are you really serious?

    We want the community site to be a place that people feel comfortable discussing plugin ideas and getting technical advice. That's a two way street. We want people to both give and receive. Matt is clearly involved on both sides of that (helping people in the forums, posting plugins, reporting bugs). Consider this, Matt has opened 6 tickets in the bug tracker over 7 months. You have opened 5 tickets over 3 years.