I have been trying to create views with voting results but without result. No matter what relationship I add I cannot retrieve any actual data.

I have found many issues on the subject. I don't know if the View integration worked for 6.x version but it does not work with the 7.x. Almost all issues report that advance poll saves the votes in a way not recognized by the voting api.

Reference:
#1517110: Views cannot retrieve poll results
#553350: Views Relationship / VotingAPI integration seems incorrect due to content_type

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

perisdr’s picture

After playing around a lot I found a workaround for making advpoll work with views. I added some code in voting api to achieve this, so hopefully this can be implemented with a hook. Here 's how I created a table with the time my users voted along with their ip address.

Add this code in sites\all\modules\votingapi\views\votingapi.views.inc

  • Search for function votingapi_views_data_alter(&$views_data) and add this:
      $default_relationships[] = array(
        'description' => t('Advanced Poll'),
        'entity_type' => 'advpoll',
        'base_table' => 'node',
        'entity_id_column' => 'nid',
        'pseudo_vote' => 'votingapi_vote', // for legacy compatability w/RC1.
        'pseudo_cache' => 'votingapi_cache', // for legacy compatability w/RC1.
      );
    
  • Clear your caches
  • Go create a new view (Show: Content of type:Advanced Poll, Display format: Table)
  • Add Relationship: Content: Votes (Votes cast by users on Advanced Poll.). For the data filters don't select anything as it messes up the query created.
  • Add fields: Votes: User, Votes: IP Address. You should now have a table with the uid of the user and the time him voted.
  • If you and add the Relationship: Votes: User(The user who cast the vote.) you will be able to retrieve more info about your user.

If you know a better workaround please share.

Michele Wickham’s picture

Assigned: Unassigned » Michele Wickham
Category: support » feature

I'll go ahead and mark this as a feature request and see what I can come up with over the week. It should be pretty simple to implement your solution.

perisdr’s picture

It may be pretty simple but not sure if it is correct. The problem for sure is that Voting API looks for votes with entity_type either saved as "node" or "comment". Advanced Poll saves the votes with entity_type "advpoll". In the previous issues the developer states two ways to resolve this. Tried to follow his way of thinking but not sure if my way has taken in mind all the possible scenarios (e.g in my way you cannot add data filters like points,percent,normal) Don't know if those were working in the 6.x version though.

Michele Wickham’s picture

Could you check the latest version of the 7.x-3.x build and see if the way I integrated hook_views_data_alter correctly added your desired fix? If I'm not mistaken, you may need to do a full cache clear to get the view api call to kick in.

If this doesn't work, is it possible for you to export the view and send me a copy of it so that I can see how you're trying to build it?

Thanks!

perisdr’s picture

FileSize
23.55 KB
7.28 KB

Couldn't make it work.

I only have one advpoll node.
Created a view with relationship "Content: Votes (Votes cast by users on nodes.)".
Added fields

  • (Votes) Votes: Timestamp (Timestamp)
  • (Votes) Votes: IP Address (IP Address)
  • (Votes) Votes: User (User)

I can see the query to the database is not correct.

SELECT votingapi_vote_node.timestamp AS votingapi_vote_node_timestamp, votingapi_vote_node.vote_source AS votingapi_vote_node_vote_source, votingapi_vote_node.uid AS votingapi_vote_node_uid, node.created AS node_created
FROM
{node} node
LEFT JOIN {votingapi_vote} votingapi_vote_node ON node.nid = votingapi_vote_node.entity_id AND votingapi_vote_node.entity_type = 'node'
WHERE (( (node.status = '1') AND (node.type IN ('advpoll')) ))
ORDER BY node_created DESC
LIMIT 10 OFFSET 0

So the hook to add another enity type 'advpoll' didn't work. Same problem for the "Content: Vote results (Aggregate results of votes cast on nodes.)" relationship. Only in this relationship the query is done to the votinapi_cache table and the entity type is still set to 'node' instead of 'advpoll'.
I am attaching the export of the view. Don't know if you can find something useful there to help you fix the problem.

Michele Wickham’s picture

Thanks - I'll get on this over the weekend - sorry for the delay.

catya’s picture

Did this fix get added? I'm not seeing it.

drclaw’s picture

The problem, I'm finding with the fix that was added in http://drupal.org/node/1540674#comment-5896192 is that it overrides the default relationships provided by the voting api entirely. It makes it impossible to relate votes back to the node table. I'm not sure what the correct solution is, but I've attached a patch as a first attempt. I haven't had the chance to test it fully yet, however. I only noticed this issue because I needed the old votingapi relationships back. If someone could test it that would be great.

Thanks!

skylord’s picture

Current code in advpoll.views.inc has no sense - this file can be deleted at all... Try this patch (basically the same as in #553350: Views Relationship / VotingAPI integration seems incorrect due to content_type but withour formatter - choices labels can be gathered with i.e. "Views PHP" from the same query without additional ones) - with it advpoll integrates with views like a charm for me:

diff -urN /home/skylord/drupal/advpoll/advpoll.module /home/skylord/regions/meeting/sites/all/modules/contrib/advpoll/advpoll.module
--- advpoll.module      2012-07-19 10:09:33.000000000 +0400
+++ advpoll.module      2012-12-02 15:20:34.000000000 +0400
@@ -1140,12 +1140,13 @@
 }

 /**
- * Implementation of hook_views_api().
+ * Implementation of hook_votingapi_relationships().
  */
-function advpoll_views_api() {
-  return array(
-    'api' => 3,
-    'path' => drupal_get_path('module', 'advpoll') . '/views',
-  );
+function advpoll_votingapi_relationships() {
+  return array(0 => array(
+    'description' => t('Advanced Poll'),
+    'entity_type' => 'advpoll',
+    'base_table' => 'node',
+    'entity_id_column' => 'nid',
+  ));
 }
-

Anonymous’s picture

Made a patch file so we can download it more easily in our projects .make file.

Anonymous’s picture

Status: Active » Needs review

Status update.

lukus’s picture

Issue summary: View changes

Hey - I've hit this issue. Wondering if others in the thread ever came to a satisfactory conclusion.

Thanks

L

adamazou’s picture

Thanks Perisd, solution #1 worked for me. I tried everything from patching to using Voting Rules and etc..
FYI: I'm using
Drupal 7.32
Advanced Poll : 7.x-3.x-dev
Views : 7.x-3.8
Voting API : 7.x-2.12

joseph.olstad’s picture

patch 10 needed a reroll

Road Kill’s picture

Has anybody been able to produce any poll results in views? I just don't see the Content: Votes relationship with advanced poll.

mikhailkrainiuk’s picture

mikhailkrainiuk’s picture

Assigned: mikhailkrainiuk » Unassigned
Status: Needs review » Fixed

Ok. The patch committed.

Status: Fixed » Closed (fixed)

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