I am using the following code:
$post_value = 'post_likes_' . $guid;
$post_owner = get_entity($owner_guid);
$post_likes = ($post_owner->$post_value) ? maybe_unserialize($post_owner->$post_value) : array();
if (!in_array($logged_user->guid, $post_likes)) {
$post_likes[] = $logged_user->guid;
}
$data = maybe_serialize($post_likes);
create_metadata($owner_guid, $post_value, $data, '', $owner_guid, ACCESS_PUBLIC);
\Elgg\Database\MetastringsTable::_elgg_delete_orphaned_metastrings();
$post_owner->save();
If logged in id is $owner_guid then the metadata will be saved and updated easily but if other id is logged in metadata unable to save or update.
Help me related this. thanks
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 0 likes
- Prince Rajput@appricart
Prince Rajput - 0 likes
- Prince Rajput@appricart
Prince Rajput - 0 likes
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 0 likes
- iionly@iionly
iionly - 0 likes
- Prince Rajput@appricart
Prince Rajput - 0 likes
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 1 like
- Prince Rajput@appricart
Prince Rajput - 0 likes
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 1 like
- Prince Rajput@appricart
Prince Rajput - 0 likes
You must log in to post replies.That code seems a bit weird. What kind of feature are you trying to implement? Are you trying to somehow replace Elgg's own liking feature?
I am making something like views counter. Any user that is click on view button will updated the value of $post_value = 'post_likes_' . $guid; (eg met value = post_likes_128) here 128 is ElggObject guid.
Can you let me know how to allow all users to edit a particular metadata?
Why are you saving the information to the owner of the content? I would rather save it to the content itself.
BTW, it is a bad idea to save GUIDs into metadata names. If the entity gets deleted, the metadata is left behind, and soon your entities will be full of 'post_likes_<guid>' metadatas that are not used for anything.
Have you considered saving each view as an annotations?
Then you could count them with:
Tidypics has a views counter for images implemented using annotations, if you are in need of some example code.
I m using this function _elgg_delete_orphaned_metastrings(); it will delete all unused metastrings.. Actually I don't want to make any change in elgg core coding.. I only want to find the way that how all users can update particular metadata.
_elgg_delete_orphaned_metastrings() will not delete those metastrings. They are not orphaned because they are still attached to the owner.
You can look elgg_set_ignore_access() to allow other users to modify metadata http://reference.elgg.org/engine_2lib_2access_8php.html#a73ba37dd1671ae3bbab5af1c31906048
Remember to revert the access back to normal after your feature finishes:
Thanku so much @Juho Jaakkola
Now Working Fine.
But still - find a way to do it in a way that you won't have to use GUID in a metadaname name.
Yes I understand the policy of elgg but somewhere we need to make a logic with in favor that core coding not to be effected. Thanks For Help.