I created a rate widget with tag "user_rating". In views when I try to create a Vote results relationship, the only selections under vote tag are 'No filtering' and 'Normal vote'. The widget does not display in the view. I'm sure I'm missing something, but tried to follow the readme...what am I doing wrong? thanks a million in advance for any help.

Comments

restyler’s picture

Status: Active » Needs review

I got the same problem. it looks like rate module authors forgot to register new tags in votingapi.
To fix it, add this code to the end of rate.module:

function rate_votingapi_metadata_alter(&$data) {
  $widgets = variable_get(RATE_VAR_WIDGETS, array());
  
  foreach ($widgets as $w) {
    if (!isset($data['tags'][$w->tag])) {
      $data['tags'][$w->tag] = array('name' => $w->tag, 'description' => $w->tag);
    }
  }
}
TimelessDomain’s picture

Title: Five star widget tag not showing up in views relationship » widget tag not showing up in views relationship
Category: support » task
Status: Needs review » Reviewed & tested by the community

it works (#1)! thanks

TimelessDomain’s picture

Status: Reviewed & tested by the community » Needs work

#1 seems to work for everything except for "options" Values Type

I tried every possible setup & have narrowed it down to the fact that "Options" cannot be selected in the "Value: Type" drop-down of the "Relationship: Content: Vote results"

restyler’s picture

Here is the code to fix options (replace the whole function with new code)

function rate_votingapi_metadata_alter(&$data) {
  $widgets = variable_get(RATE_VAR_WIDGETS, array());
  
  foreach ($widgets as $w) {
    if (!isset($data['tags'][$w->tag])) {
      //var_dump($w);
      $data['tags'][$w->tag] = array(
        'name' => $w->tag,
        'description' => t('Used in %widget', array('%widget' => $w->name))
      );
    }
    
    if ($w->value_type == 'option') {
      foreach ($w->options as $opt) {
        $data['functions']['option-' . $opt[0]] = array(
          'name' => $opt[1] . ' (' . $w->name . ')',
          'description' => t('Used in %widget', array('%widget' => $w->name))
        );
      }
    }
  }
  
  
}
TimelessDomain’s picture

Thanks restyler.

This brought up the different options within an option rate widget under the aggregation function, but the "Value Type" is still missing "Options". Thus the options widget still won't display in views

craspouille’s picture

Hi!
Has anyone managed to display the options widget in views?
thanks :-)

leewoodman’s picture

not yet...

rogical’s picture

this features is very important, hope to see this soon!

nyoz’s picture

+1 For now, no Views integration is possible without this issue being fixed... :(

nyoz’s picture

Priority: Normal » Major
msypes’s picture

subscribing.
Actually, I'm not seeing any integration with views. I'd like to be able set up the ability to vote on a node via a view rather than needing to get to the node display itself.

Sylense’s picture

+1

Sylense’s picture

I've applied the patch but I think I'm in need of the same thing mentioned in #11. I can embed a widget on the node page with no problem using the php embed code or views. But what I need is the ability to display the widget on a views display, e.g...

Node A has a rate widget displayed on itself
Node B has a rate widget displayed on itself
Node C has a rate widget displayed on itself

View 1 has a listing of all nodes (A, B, C)

I need the ability to print the rate widget on the View as a field so you can vote not only from the actual node but from the view. Am I just missing something? This is a MAJOR necessity for a site I'm working on and I'd be willing to offer a bounty to have the Rate module for D7 fully functional with maybe Field UI support

Sylense’s picture

Update, in case anyone else might need to accomplish something similar:

I've been able to achieve alot of what I want using the patch/code above in combination with views and entity views attachment. I am also using the fivestar module in addition to the rate module and everything so far seems to work ok.

msypes’s picture

Sylense,
Your goal in comment #13 is exactly what I'm trying to do as well. I'd certainly appreciate you posting any other details on how you accomplished this.
Thanks.

Sylense’s picture

I just created an "Entity Content" view using the entity views module. In the view I have my Rate/vote relationship set up and added Vote results field using that relationship. Entity views then allows you to use the view as a field in the content type so I just placed it where I wanted using Display suite. Seems to work perfectly thus far.

dangko’s picture

#13 and #15

+1

I'm trying exactly the same thing.

I'm using thumbs up with the rate-widget and I'm trying to display the rate-widget to enable voting on a node in a slider-view.

Something similar: the Service_links-module appears as a field-option when I'm creating the view. And whenever a different item(node) is being dispIayed, the servicelinks change change accordingly with the main-item in the slider.

I'm trying something similar for the rate-widget, but I'm only able to fetch results in a view. Not the ability to vote itself.

any help would be appreciated

Regards

dangko’s picture

I think I actually managed to create this with a bit of coding:

I installed views_php module: http://drupal.org/project/views_php
Which enables PHP code for fields in the Views module.

I added the following code in rate.module

function rate_embed_fromID($nodeid, $machine_name, $mode = RATE_FULL) {
  // Adding the form to the node view
  $widgets = rate_get_active_widgets('node', 'your_content_type_you_have_used', 'full');
  foreach ($widgets as $widget_id => $widget) {
    if ($widget->name != $machine_name) {
      continue;
    }
    return rate_generate_widget($widget_id, 'node', $nodeid, $mode);
  }
  return FALSE;
}

Which is a slight variation of the rate_embed function.
In Views-fields we can't pass on entire $node objects, but we HAVE access to the $row->nid (node_id). if we have a hidden field with content:node-id.
So basically instead of using the $node object (to pass on the id) I wrote the code in rate.module to directly use the nodeid.

So we can now create a PHP field in the viewsmodule. In the output field you can use the following code:

print rate_embed_fromID($row->nid, 'system_name_of_ratewidget');

Where the systemname is the system name of the widget you've created.

Another thing I've noticed is that you should order all fields containing data you want to use BEFORE the php-field.

Hope this helps for those who were struggling with the same problem I had.

mauritsl’s picture

Status: Needs work » Fixed

VotingAPI 6.x had the possibility to fill in your own tag, but D7 doesn't. Rate indeed doesn't register this tag like restyler said in comment #1. I've added this to Rate now. This makes the option value type showing too.

Commited to GIT.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

nafmarcus’s picture

To clarify:
Any idea when to expect the next official release for D7?
Will this release have widget integration with views without needing a patch or will the patch still be necessary?

mauritsl’s picture

This is already in the 7.x-1.2 release. There is no need for a patch anymore.

Status: Fixed » Closed (fixed)

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