I am trying to adapt Miguel Montes' rate plugin into another plugin. I am having an issue (Fatal Error) with the getAnnotationsAvg:
Fatal error: Call to a member function getAnnotationsAvg() on a non-object in /home/xxxxx/public_html/mysite.com/mod/rate/views/default/rate/rate.php on line 15
Here is the rate file (error occurs where it is underlined and bolded below):
<?php
/**
* RATE PLUGIN
* @package rate
* @author Miguel Montes mmontesp@gmail.com
* @license GNU General Public License (GPL) version 2
* @copyright (c) Miguel Montes 2008
* @link http://community.elgg.org/pg/profile/mmontesp
**/
$opt = array(elgg_echo("rate:0")=>1, elgg_echo("rate:1")=>2, elgg_echo("rate:2")=>3, elgg_echo("rate:3")=>4, elgg_echo("rate:4")=>5, elgg_echo("rate:5")=>6);
$rate = $vars['entity']->getAnnotationsAvg('generic_rate');
$image = round($rate*2);
$rate = $image/2;
echo "<img src='{$CONFIG->wwwroot}mod/rate/_graphics/$image.gif' alt='$rate' title='$rate'/> (".$vars['entity']->countAnnotations('generic_rate')." ".elgg_echo("rate:rates").")";
//Solo mostramos el formulario para usuarios logueados que no hayan votado aun
//We show the form if the user is legged in and it hasn't rate yet
gatekeeper();
//if (!count_annotations($vars['entity']->guid, $vars['entity']->getType(), $vars['entity']->getSubtype(), 'generic_rate', "", "", $_SESSION['guid'])){
if (allow_rate($vars['entity'])){
$form_body = "<p><label>".elgg_echo("rate:text")."</label></p>";
$form_body .= "<p>" . elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $vars['entity']->getGUID()));
$form_body .= "<p>" . elgg_view('input/rate', array('internalname' => 'rate', 'options' => $opt));
$form_body .= elgg_view('input/submit', array('value' => elgg_echo("rate:rateit"))) . "</p>";
echo elgg_view('input/form', array('body' => $form_body, 'action' => "{$vars['url']}action/rate/add"));
}
?>
Is the function used improperly? I have read ElggEntity Class Reference here but cannot seem to find an error in the above usage. Can any bright PHP'ers out there shed some light on this?
Regards,
Crusader
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.
- Crusader@crusader

Crusader - 0 likes
- DhrupDeScoop@Dhrup2000

DhrupDeScoop - 0 likes
- elgg_view('rate/rate', array('entity'=> $vars['entity']));
- Crusader@crusader

Crusader - 0 likes
You must log in to post replies.Still working on this, to no avail. Any ideas?
Just tested - works OK in v1.5
You have miscoded or misplaced the
I plugged in into a group display page
groupprofile.php
echo elgg_view('rate/rate', array('entity'=> $vars['entity']));
?>
</div><!-- end of groups_info_column_left -->
<div id="groups_info_wide">
Thanks again Dhrup. I had placed the echo elgg_view in the wrong display page. All is well now.