Skip to Content
 Русский Русский    English English   

 

Drupal. Как я реализовала pager в модуле FAQ (Frequently Asked Questions)

Drupal. Как я реализовала pager в модуле FAQ (Frequently Asked Questions)

Для реализации листалки страниц в модуле FAQ 6.x-1.12 (Frequently Asked Questions) я изменила функцию запроса к базе данных db_query на pager_query, которая выполняет "постраничное" обращение к базе данных, и вывела пейджер с помощью theme('pager').

Faq.module,v 1.1.4.52.2.145 2010/10/29 :

function faq_theme() {
    'faq_questions_inline' => array(
      'path' => $path,
      'file' => 'faq.questions_inline.inc',
      'template' => 'faq-questions-inline',
-     'arguments' => array('data' => NULL),
+     'arguments' => array('data' => NULL, 'pager' => NULL),
    ),
}
function faq_page($tid = 0, $faq_display = '', $category_display = '') {
    if ($default_sorting != 'DESC') {
- $result = db_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n LEFT JOIN {faq_weights} w ON w.nid = n.nid WHERE n.type='faq' AND n.status = 1 AND (w.tid = 0 OR w.tid IS NULL) ORDER BY weight, n.sticky DESC, n.created ASC", "n", "nid"), $default_weight);

+ $cnt = 'SELECT COUNT(*) FROM {node} n WHERE n.status=1 AND n.type="faq"';

+ $result = pager_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n LEFT JOIN {faq_weights} w ON w.nid = n.nid WHERE n.type='faq' AND n.status = 1 AND (w.tid = 0 OR w.tid IS NULL) ORDER BY weight, n.sticky DESC, n.created ASC", "n", "nid"), 10, 0, $cnt, $default_weight);
    }
    else {  
- $result = db_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n LEFT JOIN {faq_weights} w ON w.nid = n.nid WHERE n.type='faq' AND n.status = 1 AND (w.tid = 0 OR w.tid IS NULL) ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $default_weight);

+ $cnt = 'SELECT COUNT(*) FROM {node} n WHERE n.status=1 AND n.type="faq"';

+ $result = pager_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n LEFT JOIN {faq_weights} w ON w.nid = n.nid WHERE n.type='faq' AND n.status = 1 AND (w.tid = 0 OR w.tid IS NULL) ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), 10, 0, $cnt, $default_weight);
}

//Стандартный пейджер друпала вызываю с идентификатором листалки 0 и количеством элементов на странице 10.
//Если листалок на странице несколько, то необходимо поменять идентификатор, но в таком случае ссылки примут вид "page=0,0,0,0...", где количество 0 равно номеру идентификатора
+ $pager = theme('pager', NULL, 10, 0);

//Передаю пейджер в файл шаблона, который использую (макет страницы "Questions inline")
case 'questions_inline':
include_once($faq_path .'/faq.questions_inline.inc');
- $output = theme('faq_questions_inline', $data);      
+ $output = theme('faq_questions_inline', $data, $pager);
break;

faq-questions-inline.tpl.php,v 1.1.2.5:

//Вывод пейджера
<?php
print $pager;
?>

Аналогична реализация пейджера для списка вопросов при выборе категории.
Faq.module,v 1.1.4.52.2.145 2010/10/29 :

function _display_faq_by_category($faq_display, $category_display, $term, $display_header, &$output, &$output_answers) {
  if ($default_sorting != 'DESC') {
-    $result = db_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n INNER JOIN {term_node} tn ON (n.nid = tn.nid AND n.vid = tn.vid) LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created ASC", "n", "nid"), $default_weight, $term->tid);
+     $cnt  =  "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} tn ON (n.nid = tn.nid AND n.vid = tn.vid) LEFT JOIN {faq_weights} w ON (w.tid = tn.tid AND n.nid = w.nid) WHERE n.type='faq' AND n.status = 1 AND tn.tid = '$term->tid'";
+     $result = pager_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n INNER JOIN {term_node} tn ON (n.nid = tn.nid AND n.vid = tn.vid) LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created ASC", "n", "nid"), 10, 0, $cnt, $default_weight, $term->tid);
  }
  else {
-    $result = db_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n INNER JOIN {term_node} tn ON (n.nid = tn.nid AND n.vid = tn.vid) LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $default_weight, $term->tid);
+    $cnt  =  "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} tn ON (n.nid = tn.nid AND n.vid = tn.vid) LEFT JOIN {faq_weights} w ON (w.tid = tn.tid AND n.nid = w.nid) WHERE n.type='faq' AND n.status = 1 AND tn.tid = '$term->tid'";
+    $result = pager_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as weight, n.sticky, n.created FROM {node} n INNER JOIN {term_node} tn ON (n.nid = tn.nid AND n.vid = tn.vid) LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), 10, 0, $cnt, $default_weight, $term->tid);  
  }
+     $pager = theme('pager', NULL, 10, 0);

    case 'questions_inline':
      include_once($faq_path .'/faq.questions_inline.inc');
-      $output .= theme('faq_category_questions_inline', $data, $display_header, $category_display, $term, $faq_class, $term);
+      $output .= theme('faq_category_questions_inline', $data, $display_header, $category_display, $term, $faq_class, $term).$pager;      
      break;

Ваша оценка: Нет Средняя: 4.7 (19 голосов)