Closed (won't fix)
Project:
Voting API
Version:
6.x-2.3
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
5 Jan 2010 at 06:41 UTC
Updated:
7 Dec 2017 at 09:25 UTC
Jump to comment: Most recent
Comments
Comment #1
Scott Reynolds commenteddo so in a hook_votingapi_results_alter($cache, $content_type, $content_id)
Comment #2
Starvin15 commentedI greatly appreciate this feedback. When using the hook_votingapi_results_alter, do you know if I be able to access this custom calculation as a field to add it to a view or will I need to make another changes to the Voting API code?
Comment #3
Scott Reynolds commentedI actually did a book page for the Reddit algorithm here: http://drupal.org/node/683090
It address your votingapi views question.
Comment #4
Starvin15 commentedThanks again, this looks like a great way to add calculations to views. My only issue is when I add your hood to the code in Voting API module then I add the relationship to my view, none of my votes show up. In addition, I am unable to add in reddit as a value to be displayed. Do you know why would this be?
Comment #5
Scott Reynolds commentedThat actually made 0 sense to me. could you try explaining again?
Comment #6
Starvin15 commentedApologies for the confusion. So I followed your book page on the Reddit algorithm. I've created a hook module and enabled it through Admin > Site building > Modules. I have created a custom view, which is displaying the fields that I want (including vote results). When I add in the reddit relationship and require it on Node: Vote Results all of my content disappears and the view can't find any data to display. In addition, I cannot find a field associated with the reddit calculation to add to my view.
My initial thought is that I am missing the relationships hook outlined in the API.txt. (providing the Views Relationship connection for votes being cast). In summary, the book page just describing the code for the calculation and not necessarily the code to build the relationship for views. Does this sound accurate or am I off base?
I am trying to get up to speed on the voting API so I do appreciate your patience.
Comment #7
Scott Reynolds commentedHave you cast any votes sense creating your module?
Comment #8
Starvin15 commentedCorrect, I have cast multiple votes on various nodes to test. In addition, as soon as I take of "require this relationship" all of my nodes show up with votes.
Doubt it is helpful, but here is the query being run:
SELECT node.nid AS nid,
node.title AS node_title,
node_data_field_rating.field_rating_rating AS node_data_field_rating_field_rating_rating,
node_data_field_rating.field_rating_target AS node_data_field_rating_field_rating_target,
node.type AS node_type,
node.vid AS node_vid,
node_data_field_rating.field_cons_value AS node_data_field_rating_field_cons_value,
node_data_field_rating.field_pros_value AS node_data_field_rating_field_pros_value,
node_data_field_rating.field_ratingstotal_rating AS node_data_field_rating_field_ratingstotal_rating,
node_data_field_rating.field_ratingstotal_target AS node_data_field_rating_field_ratingstotal_target
FROM node node
INNER JOIN votingapi_cache votingapi_cache_node_points_vote_reddit ON node.nid = votingapi_cache_node_points_vote_reddit.content_id AND (votingapi_cache_node_points_vote_reddit.content_type = 'node' AND votingapi_cache_node_points_vote_reddit.value_type = 'points' AND votingapi_cache_node_points_vote_reddit.tag = 'vote' AND votingapi_cache_node_points_vote_reddit.function = 'reddit')
LEFT JOIN content_type_review node_data_field_rating ON node.vid = node_data_field_rating.vid
WHERE node.status <> 0
ORDER BY node_data_field_rating_field_ratingstotal_rating ASC
Comment #9
Scott Reynolds commentedmy guess would be that you arn't doing a 'points' calculation. Are you using Fivestar? That would be percent.
My next guess would be that the 'tag' isn't 'vote' but something else
Edit: The reddit function will only work with points voting style for obvious reasons.
Comment #10
Starvin15 commentedI have switched to the vote up/down module which I believe is based off points. I have now activated the module and required the relationship. My data is now showing up which is great so it appears the reddit module is working correctly, however, I cannot add it to the fields to show up as data. I believe the calculation is working correctly so this isn't so much of an issue - but it would be helpful to pull this data into a view but not display it. If I add a relationship hook would that allow me to add the reddit result as a field?
Comment #11
Scott Reynolds commentedyou already have it, just use the Vote results: Value and use your relationship you already set up.
Comment #12
Starvin15 commentedYou seems to have a pretty good understanding of the voting API module. I am trying to create a custom calc to only count those votes from today. I created the following which is giving me a parse error. Could you take a quick look and let me know what my problem is:
/**
* @file
* Custom functions for this site.
* Implementation of hook_votingapi_results_alter().
*/
function mymodule_votingapi_results_alter(&$results, $content_type, $content_id) {
// Calc for generating the votes for that day.
$sql = "SELECT v.tag, SUM(v.value) AS todays_votes ";
$sql .= "FROM {votingapi_vote} v ";
$sql .= "WHERE v.content_type = '%s' AND v.content_id = %d AND v.value_type = 'points' AND v.timestamp > DATE_FORMAT(NOW(),'%Y')-DATE_FORMAT(NOW(),'%m')-DATE_FORMAT(NOW(),'%d') 00:00:00 ";
$sql .= "GROUP BY v.tag";
$results = db_query($sql, $content_type, $content_id);
// VotingAPI wants the data in the following format:
// $cache[$tag][$value_type][$math_function] = $value;
while ($result = db_fetch_array($results)) {
$cache[$result['tag']]['points']['todays_votes'] = $result['todays_votes'];
}
}
Comment #13
legolasboDrupal 6 is no longer supported. Closing old issues to clean up the issue queue.
Please reopen and update this issue if this is still an issue in the D7 or D8 version.