metadata question

I create an input form like below:

Data for 2010-03:

Name | sell | pv | month
John  | 300 |20 | 2010-03
Simon| 500 |60 | 2010-03

Data for 2010-02:

Name | sell | pv | month
John  | 100 |10 | 2010-02
Simon| 200 |20 | 2010-02

the above two example only one will show, it changes when the month dropdown selection changes. The name are read from objects-enity, so I also get its guid. I use create_metadata_from_array() to insert the data. and it does.

but now I have no idea how to read them out by a specified month, for example, I want to get the data of month "2010-03". Which function can do this?

Thank you very much!

  • Under Elgg 1.7, that would be:

    elgg_get_entities_from_metadata
  • @Kevin, this function returns the object's infomation only,

    [guid] => 23
    [type] => object
    [subtype] => 4
    [owner_guid] => 2
    [container_guid] => 2
    [site_guid] => 1
    [access_id] => 0
    [time_created] => 1268813007
    [time_updated] => 1268813007
    [enabled] => yes
    [tables_split] => 2
    [tables_loaded] => 2
    [title] => John
    [description] => 10464239
    [last_action] => 0

    What I want is:
    John's data in month 2010-03

    Did I make anything wrong when inserting data via create_metadata_from_array()?
  • Metadata doesn't show up in a var_dump() of the entity.  It uses the __get() magic method to supply it when accessed.  Once you have that entity say 

    var_dump($entity->month);

    Also, how are you saving this?  Whatever name you use to save the metadata is the name you have to use to retrieve it.

  • Hello

    I  have been trying to figure out how to pull information stored on a users page as well, to use with another plugin.

    For instance using a plugin like profile manager where the user would input a custom profile type then list information such as which state they are from.

    I know the guid #s are 3 & 6 for the two profile types and the metadate names are p_type & b_type.

    What would be the best way to get this information into another plugin?

  • If you know the entity guids and the metadata names, all you have to do is say:

    $entity = get_entity($guid);

    var_dump($entity->p_type, $entity->b_type);

    There's pretty decent documentation for this on the docs page: http://docs.elgg.org/wiki/Engine/DataModel/Metadata

  • So the line

    $entity = get_entity($guid);

    declares the page owners guid # ?

    Right?

  • sorry to seem so dense here...

    $entity = get_entity($guid);

    var_dump($entity->p_type, $entity->b_type);

    returns NULL, Null

    so I tried

    $entity = get_entity(3);

    guid #3 is the guid # for p_type

    var_dump($entity->p_type, $entity->b_type);

    and it still returned NULL, Null

     

    What am I not getting here lol

  • ok I got to thinking profile manager saves the profile types as custom_profile_type and I am using 1.7

    so if I say:

    $entity = elgg_get_entities_from_metadata($custom_profile_type);

    echo $entity;

    it does retrun ARRAY

    yet the var_dump statement still returns NULL, NULL

    and an If statement of $entity == 3 returns False????

    I amy trying to find out if the user has declared his profile type is type = "p_type" or if he is using the profile type = "b_type"

  • You have to define $custom_profile_type before you can use it in that call.  In this case it needs to be an array as described in the elgg_get_entities_from_metadata() documentation.

    $entity won't == 3 at this point because it's an array of ElggEntity objects or FALSE.  If you var_dump($entity) after that call you'll probably see a list of 10 entities, but none of them will be what you want because $custom_profile_type isn't defined :-X

    $entity = get_entity(3) will return the entity with GUID 3.  I don't think this is what you want either because it looks like 3 is the metadata ID of p_type (maybe)...