gpt4 book ai didi

php - 按具有多个标志的节点的总标志计数对 Drupal 6 View 进行排序

转载 作者:行者123 更新时间:2023-12-04 05:37:34 24 4
gpt4 key购买 nike

我正在使用 Drupal 6,并且在我的节点上有多个标志,每个标志都有一个值,例如:有趣、无聊、聪明、有趣、辱骂等。 Views 目前能够按每个单独标志的标志计数对结果进行排序,但我需要按每个音符上所有标志的总组合标志数对我的节点进行排序。 'rate' 模块非常接近于这样做,但我需要使用 flag 模块,以便我可以使用 flag solr 模块来允许按标志搜索。我真的不知道从哪里开始......关于我可以采取的方法的任何建议?

这是当前的 View 查询;

SELECT node.nid AS nid, 
flag_counts_node.count AS flag_counts_node_count,
flag_counts_node_1.count AS flag_counts_node_1_count,
flag_counts_node_2.count AS flag_counts_node_2_count,
flag_counts_node_3.count AS flag_counts_node_3_count,
flag_counts_node_4.count AS flag_counts_node_4_count FROM node node
LEFT JOIN flag_counts flag_counts_node ON node.nid = flag_counts_node.content_id AND flag_counts_node.fid = 7
LEFT JOIN flag_counts flag_counts_node_1 ON node.nid = flag_counts_node_1.content_id AND flag_counts_node_1.fid = 6
LEFT JOIN flag_counts flag_counts_node_2 ON node.nid = flag_counts_node_2.content_id AND flag_counts_node_2.fid = 4
LEFT JOIN flag_counts flag_counts_node_3 ON node.nid = flag_counts_node_3.content_id AND flag_counts_node_3.fid = 5
LEFT JOIN flag_counts flag_counts_node_4 ON node.nid = flag_counts_node_4.content_id AND flag_counts_node_4.fid = 3
WHERE (node.type in ('rpodcast', 'upodcast')) AND (node.status = 1) ORDER BY flag_counts_node_count ASC, flag_counts_node_1_count ASC, flag_counts_node_2_count ASC, flag_counts_node_3_count ASC, flag_counts_node_4_count ASC

到目前为止的模块代码;
<?php
function flagcountview_views_pre_execute(&$view){
if ($view->name == 'audio') {
$sql = $view->build_info['query'];
$flag_count = "flag_counts_node.count + flag_counts_node_1.count + flag_counts_node_2.count + flag_counts_node_3.count";
$sql .= "ORDER BY $flag_count DESC";
$view->build_info['query'] = $sql;
}
}

最佳答案

嗨,您似乎无法添加字段,因此我们可以尝试其他方法

function flagcountview_views_pre_execute(&$view){
if ($view->name == 'audio') {
$sql = $view->build_info['query'];
$search = "ORDER BY flag_counts_node_count ASC, flag_counts_node_1_count ASC, flag_counts_node_2_count ASC, flag_counts_node_3_count ASC, flag_counts_node_4_count ASC";
$replace = "ORDER BY flag_counts_node.count + flag_counts_node_1.count + flag_counts_node_2.count + flag_counts_node_3.count ASC";
$sql = str_replace($search, $replace, $sql);;
$view->build_info['query'] = $sql;
}
}

确保您在 View 中添加了所有标志计数 -> 排序标准 :)

关于php - 按具有多个标志的节点的总标志计数对 Drupal 6 View 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11728986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com