如何使用 Drupal Fivestar 平均评分对视图进行排序?

发布于 2024-08-04 09:53:50 字数 2136 浏览 6 评论 0原文

我正在使用 Drupal 6.13、Views 6.x-2.6、投票 API 6.x-2.3、Fivestar 6.x-1.18。

我有一个内容类型,其字段类型为五星级。我有一个视图,我的目的是列出具有此内容类型的所有节点,按总体平均评分降序排列。该视图有效,因为它显示了正确的信息(有投票能力的用户投票和总体平均投票)。但我一生都无法将其正确排序。

在视图中,我与“节点:投票结果”有关系,值类型=“百分比”,投票标签=“正常”,聚合函数:“平均”。

我已经尝试了很多东西,但我期望的工作是添加一个“排序标准”,其中包含“(投票结果)投票结果:值”和降序。当我这样做时,如果我查看 sql 查询,我会看到“ORDER BY node_title ASC”,这显然是不正确的。我希望看到“ORDER BY Votingapi_cache_node_percent_vote_average_value DESC”。任何指示将不胜感激。

在此查询:

SELECT node.nid AS nid,
   node.title AS node_title,
   profile_values_profile_full_name.value AS profile_values_profile_full_name_value,
   users.uid AS users_uid,
   votingapi_vote_node_percent_vote_curuser.value AS votingapi_vote_node_percent_vote_curuser_value,
   votingapi_cache_node_percent_vote_average.value AS votingapi_cache_node_percent_vote_average_value
 FROM node node 
 LEFT JOIN votingapi_cache votingapi_cache_node_percent_vote_average ON node.nid = votingapi_cache_node_percent_vote_average.content_id AND (votingapi_cache_node_percent_vote_average.content_type = 'node' AND votingapi_cache_node_percent_vote_average.value_type = 'percent' AND votingapi_cache_node_percent_vote_average.tag = 'vote' AND votingapi_cache_node_percent_vote_average.function = 'average')
 LEFT JOIN votingapi_vote votingapi_vote_node_percent_vote_curuser ON node.nid = votingapi_vote_node_percent_vote_curuser.content_id AND (votingapi_vote_node_percent_vote_curuser.content_type = 'node' AND votingapi_vote_node_percent_vote_curuser.value_type = 'percent' AND votingapi_vote_node_percent_vote_curuser.tag = 'vote' AND votingapi_vote_node_percent_vote_curuser.uid = '***CURRENT_USER***')
 LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
 LEFT JOIN users users_node_revisions ON node_revisions.uid = users_node_revisions.uid
 INNER JOIN users users ON node.uid = users.uid
 LEFT JOIN profile_values profile_values_profile_full_name ON users.uid = profile_values_profile_full_name.uid AND profile_values_profile_full_name.fid = '5'
 WHERE (node.type in ('passion_talk')) AND (node.status <> 0)
   ORDER BY node_title ASC

I am using Drupal 6.13, Views 6.x-2.6, Voting API 6.x-2.3, Fivestar 6.x-1.18.

I have a content type with field of type Fivestar Rating. I have a view where my intention is to list all of the nodes with this content type sorted in descending order by the overall average rating. The view is working in that it is showing the correct information (the user vote with ability to vote and the overall average vote). But I can't for the life of me get it to sort properly.

In the view, I have a relationship with "Node: Vote results", Value type = "Percent", Vote tag = "Normal", Aggregation function: "Average".

I've tried a bunch of things but what I expect to work is to add a "Sort criteria" with "(Vote results) Vote results: Value" and descending. When I do that if I look at the sql query and I see "ORDER BY node_title ASC" which is obviously not right. I would expect to see "ORDER BY votingapi_cache_node_percent_vote_average_value DESC". Any pointers would be most appreciated.

Query here:

SELECT node.nid AS nid,
   node.title AS node_title,
   profile_values_profile_full_name.value AS profile_values_profile_full_name_value,
   users.uid AS users_uid,
   votingapi_vote_node_percent_vote_curuser.value AS votingapi_vote_node_percent_vote_curuser_value,
   votingapi_cache_node_percent_vote_average.value AS votingapi_cache_node_percent_vote_average_value
 FROM node node 
 LEFT JOIN votingapi_cache votingapi_cache_node_percent_vote_average ON node.nid = votingapi_cache_node_percent_vote_average.content_id AND (votingapi_cache_node_percent_vote_average.content_type = 'node' AND votingapi_cache_node_percent_vote_average.value_type = 'percent' AND votingapi_cache_node_percent_vote_average.tag = 'vote' AND votingapi_cache_node_percent_vote_average.function = 'average')
 LEFT JOIN votingapi_vote votingapi_vote_node_percent_vote_curuser ON node.nid = votingapi_vote_node_percent_vote_curuser.content_id AND (votingapi_vote_node_percent_vote_curuser.content_type = 'node' AND votingapi_vote_node_percent_vote_curuser.value_type = 'percent' AND votingapi_vote_node_percent_vote_curuser.tag = 'vote' AND votingapi_vote_node_percent_vote_curuser.uid = '***CURRENT_USER***')
 LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
 LEFT JOIN users users_node_revisions ON node_revisions.uid = users_node_revisions.uid
 INNER JOIN users users ON node.uid = users.uid
 LEFT JOIN profile_values profile_values_profile_full_name ON users.uid = profile_values_profile_full_name.uid AND profile_values_profile_full_name.fid = '5'
 WHERE (node.type in ('passion_talk')) AND (node.status <> 0)
   ORDER BY node_title ASC

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新雨望断虹 2024-08-11 09:53:50

这很奇怪; VotingAPI 中包含的“top_content”视图包含一个“五星级”显示,可准确设置您所描述的关系。它有效吗,或者它是否显示您遇到的问题?

That's pretty bizarre; the 'top_content' view that's included with VotingAPI includes a 'Fivestar' display that sets up exactly the relationship you're describing. Does it work, or does it display the problem you're encountering?

当爱已成负担 2024-08-11 09:53:50

啊,我明白了。我使用的是表格样式,并且节点标题上设置了默认排序,导致所有排序条件都被忽略。

Ah, I figured it out. I was using Table style and there was a default sort set up on the node title that caused all sort criteria to be ignored.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文