$widget = $vars['entity'];
$container = $widget->getContainerEntity();
$options = eligo_get_display_entities_options($widget);
elgg.2.2.1\mod\owner_followers_counter\views\default\profile\owner_block.php
this code are not working in file name owner_block.php
where, i have inserted owner_followers_counter plugin
My All Code Is ::
where, two lines are not working.. in bold section.
$widget = $vars['entity'];
$container = $widget->getContainerEntity();
$options = eligo_get_display_entities_options($widget);
$container_guid = $vars['entity'];
$container = $container_guid->getContainerEntity();
$options = eligo_get_display_entities_options($container_guid);
$options['annotation_names'] = array('likes');
if (elgg_instanceof($container, 'user') && $widget->my_likes !== 0) {
$options['annotation_owner_guids'] = $container->guid;
}
if (!elgg_instanceof($container, 'user') && !elgg_instanceof($container, 'group')) {
unset($options['container_guids']);
}
if ($widget->eligo_sortby == 'mostliked') {
$dbprefix = elgg_get_config('dbprefix');
$likes_metastring = get_metastring_id('likes');
$options['selects'] = array("(SELECT count(distinct l.id) FROM {$dbprefix}annotations l WHERE l.name_id = $likes_metastring AND l.entity_guid = e.guid) AS likes");
$options['order_by'] = 'likes ASC';
if ($widget->eligo_sortby_dir == 'desc') {
$options['order_by'] = 'likes DESC';
}
}
$content = elgg_list_entities_from_annotations($options);
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.
I Will uses 3 Plugins, 1.owner_followers_counter, 2.Liked_Content,3.au_widget, I will get this code from liked_content and put into the owner_block.php so its not working
The lines
is code from a widget view file, right?
In this case $vars['entity'] is a widget object and you can use widget class methods (like $widget->getContainerEntity()) on this object.
But in other views (no widget views) the object in $vars['entity'] is some other type of object (e.g. an elgg object entity or a user entity) or is $vars['entity'] is not even defined. It depends on the type of view and the context what is in the $vars array. You just can't simply use class methods and functions for arbitrary object types. You need to find another way to achieve what you want to achieve.
Btw. is eligo_get_display_entities_options() even the correct name of an existing function?
I will get code from liked_content Plugin file is elgg.2.2.1\mod\liked_content\views\default\widgets\liked_content\content.php
and paste this code in to
elgg.2.2.1\mod\profile\views\default\profile\owner_block.php
As I said, you can't take code from a widget view (as in liked_content\views\default\widgets\liked_content\content.php) and use it in a non-widget view without some modifications at least because the widget entity is not defined in non-widgets views.
You need to modify the code according to what you want to get displayed. The widget references here are used to get the widget settings and to set the query options accordingly. Just rewrite the code to use the query options for elgg_list_entities_from_annotations() by other means (e.g. based on logged in user or context) and the code should work.
In My Code Which Coding Part Has A Changeable For Me?
i have to display only most liked post..
and above code are display posts.
it display all liked post, but when i comment this 2 line ,
$container = $widget->getContainerEntity();
$options = eligo_get_display_entities_options($widget);
then it will display the all post, other wise not.
it will be display me all posts
so, What issues for that 2 Lines?
I want to display widget content into non-widget view file.
You can't refer to widget objects / use widget methods outside widgets views via the $vars['entity'] variable. Period.
Code taked from the Liked Content plugin widget view without references to widget objects displaying the most liked entities:
Take this as a starting point and modify if necessary.
I Will uses This Code.. Post are displayed but not display mostliked post
namespace AU\Widgets;
$user = elgg_get_page_owner_entity();
$user_guid = $user->guid;
//$options = eligo_get_display_entities_options($user_guid);
$options['annotation_names'] = array('likes');
$options['annotation_owner_guids'] = $user_guid;
if (elgg_instanceof($user, 'user') && $widget->my_likes !== "0") {
$options['annotation_owner_guids'] = $user->guid;
}
if (!elgg_instanceof($user, 'user') && !elgg_instanceof($user, 'group')) {
unset($options['container_guids']);
}
if ($user->eligo_sortby == 'mostliked') {
$dbprefix = elgg_get_config('dbprefix');
$likes_metastring = get_metastring_id('likes');
$options['selects'] = array("(SELECT count(distinct l.id) FROM {$dbprefix}annotations l WHERE l.name_id = $likes_metastring AND l.entity_guid = e.guid) AS likes");
$options['order_by'] = 'likes ASC';
if ($user->eligo_sortby_dir == 'desc') {
$options['order_by'] = 'likes DESC';
}
}
$content = elgg_list_entities_from_annotations($options);
Of course it won't work!
Why do you expect this to work just because you changed $widget to $user? The "eligo_sortby" metadata value in the original code referred to a widget setting and this value won't magically be created for each user entity just because you add a line of code referring it.
Try the code I've posted in my last posting. It should provide the basic functinality at least of displaying the most liked entities though without any options to change the sorting order.
- Previous
- 1
- 2
- Next
You must log in to post replies.