Editable metadata?

Hi!

I'm trying to develope a plugin for counting and listing entities in ELGG (yes, i know, there are a lot of stuff done, and so far better than mine, but its for an university project).

I just did the votation, and now, when i want to add a global counter, i have a problem.

 

Even If i make a public metadata ( "create_metadata($ent->guid, "Total", $points, 'integer', 2,2);" ) this metadata its not editable/updatable by anyone (excluding the admin).

I mean, if i try to push a new value with a normal-user account, the value stay statics. If i try it with an admin acount, the value changes itself.

I'm really new to elgg, and i think that i'm doing something wrong, but what? I read the API and the DM, but i cant resolve this issue.

Can you help me please?

PS:Sorry about my english. Spanish dev.

 

Thanks.

  • Hello,

    If I am correct, you can try a plugin hook to override permission to edit metadata from an normal user,

    It was something like this :

       
               
            /**
             * Override the canEdit function to return true within a particular context.
             *
             */
            function urfunction_metadata_can_edit($hook_name, $entity_type, $return_value, $parameters) {
    // a global variable to ensure only used by ur function           
                global $metadataflag;
               
                if ($metadataflag== 1) {
                    $entity = $parameters['entity'];

    // your subtype to ensure only used by this plugin
                    if ($entity->getSubtype() == "subtype") {
                        return true;
                    }
                }
               
                return $return_value;
               
            }

     

    and then extend it using the plugin hook function:

    register_plugin_hook('permissions_check:metadata','object','urfunction_metadata_can_edit');

     

    I think this should do what you want !

     

    Regards,

    Muhammad Aimash

  • The access level for a piece of metadata is locked to the access level for the associated entity by default (even if you try changing it to something else).

    You can change that behaviour using the register_metadata_as_independent() function as is used in mod/profile/start.php, for example.

    Personally I find independent metadata access levels confusing and would rather associate public metadata with a public entity but the feature can be useful sometimes.

  • Iff you are in need of a counter function only, you can also think about annotations as an alternative.

  • One of the simplest solutions for counters would be to use:

    $counter = get_plugin_setting('counter','my_plugin');

    //make calculations for counter if required

    set_plugin_setting('counter',$counter,'my_plugin');