No way to retrieve an entity based on type, subtype and "title"?

I've been trying to find a method to retrieve an entity based on type, subtype, and "title". 

One would think that get_entities_from_metadata() would be perfect for this, however the "title" field is actually stored in the elggobjects_entity table and not the elggmetadata table, so that function doesn't work.

Then I tried search_for_object() but it's also useless because it will return *any* object that has a match for your criteria on either "title" or "description", regardless of subtype.

So it's almost a detriment to use the "title" and "description" fields of an object, if there's no good method to search for entities based on them.  I'm almost inclined to use real metadata like "meta_title" and "meta_description" to overcome this deficiency.

But I'm hoping I'm wrong and there's some super-awesome-kickass function that I'm unable to find! ;)

  • Elgg needs more functions for finding ElggObjects. I recently had to find objects by description (and I knew each description was unique). Here is the function I quickly wrote:

     

        function get_object_by_description($descr)
        {
            global $CONFIG;
           
            $query = "SELECT e.* from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}objects_entity o on e.guid=o.guid where description=\"{$descr}\" limit 0, 1";
            $row = get_data_row($query);
            if ($row)
                return new ElggObject($row);
            else
                return false;
        }

  • @Cash.. that is wicked.

    @Kane.. what do you intend to do with that data..? echo..?? or, bundle and save..?

     

    -Carlos

  • Nice...that's likely what I'll have to do, thanks Cash!

    @Carlos, I have two objects that are related.  A piece of metadata for object A = the "title" of object B.  So while doing a FOREACH on an array of object A's, I want to find the related object B and use some of its metadata.  The end result will be echoed in a widget.

    I should add that I haven't yet taken advantage of the elggentity_relationships table.  I'm not sure what the purpose of this table is or what functions can be used with it.  Is there any good tutorial or doc available?

  • My new function based on Cash's:

    function get_object_by_title($subtype,$title)
        {
            global $CONFIG;
           
            $query ="SELECT e.* from {$CONFIG->dbprefix}entities e ".
        "JOIN {$CONFIG->dbprefix}objects_entity o ON e.guid=o.guid ".
        "WHERE e.subtype={$subtype} ".
        "AND o.title=\"{$title}\" ".
        "LIMIT 0, 1";
            $row = get_data_row($query);
            if ($row)
                return new ElggObject($row);
            else
                return false;
        }

  • Ok Kane.. I see what you're trying to do from that code and it looks like you sorted it smart. Nice.

  • Any thoughts of making this part of the Elgg engine ?  I realised there may be work to generalize the function etc.

  • Shouldn't this function do what we're trying to do here? It's pretty flexible.

  • @Mahmoudimus...I don't see it hitting the elggobjects_entity table which is where the title and description fields are stored, so I doubt it...

  • @Kane, Ah. yes. I see what you mean. Well stated.