I get this notice message on view that shows average rating for current node.

Notice: Undefined property: stdClass::$nid in fivestar_views_value_display_handler() (line 1398 of ... \www\d7_test\sites\all\modules\fivestar\fivestar.module).

Some background:
I don't like the default method to display average score of comments proposed in http://drupal.org/node/234681 so I managed to attach view to node (using EVA module) which shows average score for current node.
I don't know if this is good or bad but it's better than hardcoding template file :)

Solution (at least in my case):
change

    if (isset($columns->node_type)) {
      $stars = variable_get('fivestar_stars_'. $columns->node_type, 5);
    }
    else {
      $node_type = db_query("SELECT type FROM {node} WHERE nid = :nid", array(':nid' => $columns->nid))->fetchField();
      $stars = variable_get('fivestar_stars_'. (!isset($node_type) ? 'default' : $node_type), 5);
    }

in fivestar_views_value_display_handler() function to

    if (isset($columns->node_type)) {
      $stars = variable_get('fivestar_stars_'. $columns->node_type, 5);
    }
    else {
      if (isset($columns->nid)) {
        $node_type = db_query("SELECT type FROM {node} WHERE nid = :nid", array(':nid' => $columns->nid))->fetchField();
      }
      $stars = variable_get('fivestar_stars_'. (!isset($node_type) ? 'default' : $node_type), 5);
    }

In my case $column variable has value
stdClass Object ( [votingapi_cache_node_percent_rating_average_value] => 66.6667 [node_created] => 1304006434 )

CommentFileSizeAuthor
#2 fivestar_views_notice-1146972.patch703 byteszambrey

Comments

ericduran’s picture

In drupal 7 you don't have to use the method describe over at http://drupal.org/node/234681

All you have to do is add a fivestar field to the comment and make sure the tag/axis is the same the node is using.

That being said this bug is really not related to that.

I'm perfectly fine with the change mention above. A patch would be great ;-)

zambrey’s picture

Status: Active » Needs review
StatusFileSize
new703 bytes

So here is the patch.
It took me some time to learn Git but hopefully it will be okay.
Thanks for encouragement :)

OldAccount’s picture

The patch worked for me, thanks!

james.elliott’s picture

Status: Needs review » Reviewed & tested by the community

The patch is simple enough

ericduran’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch and review.

This is now fixed
--
http://drupalcode.org/project/fivestar.git/commit/aa75ac44c7b0b4c1f38a37...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pcorbett’s picture

Status: Closed (fixed) » Active

I may be missing something, but I don't see this patch as included in the latest 7.x-2.x-dev release or the alpha1.

ericduran’s picture

Status: Active » Closed (fixed)

@pcorbett because this is an old issue and that code isn't on the module any more.