Drupal Upgrade ::需要将pagerquery重写为版本7

时间:2012-05-23 12:09:05

标签: drupal

我需要重写pagerquery,我已经尝试了几个选项添加标签,扩展(PagerDefault),但没有任何对我有用: 请帮忙。

我的第6版代码是:

$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;

$ sql_count ='SELECT COUNT(DISTINCT(n.nid))FROM {node} n WHERE n.uid =%d AND n.type =“case”AND n.status = 1';

$args = array('uid' => $user->uid);

$sql = db_rewrite_sql($sql);

$sql_count = db_rewrite_sql($sql_count);

if ($pager) {

$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
dsm($result);

}

else {

$result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
}


$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows = TRUE;
}

2 个答案:

答案 0 :(得分:0)

在不知道您的联接表名称的情况下,这是不完整的,但应该让您入门:

$query = db_select('node', 'n')
  ->fields('n', array('nid', 'sticky', 'title', 'created'))
  ->condition('n.uid', $user->uid)
  ->condition('n.type', 'case')
  ->condition('n.status', 1)
  ->extend('PagerDefault')
  ->limit(variable_get('default_nodes_main', 10))
  ->addTag('node_access')
  ->orderBy('col_name');

$query->join('table_to_join', 'table_alias', 'table_alias.nid = n.nid');

foreach ($query->execute() as $row) {
  // Do what you need to
}

答案 1 :(得分:0)

if ($vidw == 'my_cases' or $vidw == 'my') {                   // including private
    switch ($sort_by) {
        case 'rated':
            $order = 'n.sticky DESC, vc.value DESC';
            $sort_join = 'LEFT OUTER JOIN {votingapi_cache} vc ON n.nid = vc.content_id AND vc.content_type = "node" AND vc.function = "average"';
            break;
        case 'discussed':
            $order = 'n.sticky DESC, nc.comment_count DESC';
            $sort_join = 'LEFT OUTER JOIN {node_comment_statistics} nc ON n.nid = nc.nid';
            break;
        case 'viewed':
            $order = 'n.sticky DESC, nc.totalcount DESC';
            $sort_join = 'LEFT OUTER JOIN {node_counter} nc ON n.nid = nc.nid';
            break;
        case 'recent':
        default:
            $order = 'n.sticky DESC, n.created DESC';
            $sort_join = '';
            break;
    }
    // from taxonomy_select_nodes
    $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;
    $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.uid = %d AND n.type = "case" AND n.status = 1';
    $args = array('uid' => $user->uid);
    $sql = db_rewrite_sql($sql);
    $sql_count = db_rewrite_sql($sql_count);
    if ($pager) {
        $result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
    }
    else {
        $result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
    }
    // $output .= taxonomy_render_nodes($result);
    $num_rows = FALSE;
    while ($node = db_fetch_object($result)) {
        $output .= node_view(node_load($node->nid), 1);
        $num_rows = TRUE;dsm($output);
    }
    if ($num_rows) {
        $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
    }
    else {
        $output .= '<p>'. t('There are currently no visible cases in this category.') .'</p>';
    }
}

在上面的drupal 6代码中,我更新了查询,它给出了结果,但node_view()和theme()不起作用。