2

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

这是当前的视图查询;

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;
}
}
4

2 回答 2

2

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

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;
  }
}

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

于 2012-08-09T04:30:05.353 回答
1

考虑到您已经在视图中添加了所有标志关系和标志计数,最好使用视图预执行来添加所有计数和排序

更新

希望您已经在关系和字段中添加了所有标志计数。现在在代码中添加'

function MODULENAME_views_pre_execute(&$view){
  $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 + flag_counts_node_4_count; 
  $sql .= " ORDER BY $flag_count ASC"; 
  $view->build_info['query'] = $sql;
}

重要的

  • 确保您从“排序标准”中删除了所有内容
  • 确保您在“字段”中添加了所有标志计数
于 2012-07-31T06:47:26.820 回答