db_rewrite_sql

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/database.inc, строка 263

Версии
5 – 6
db_rewrite_sql($query, $primary_table = 'n', $primary_field = 'nid', $args = array())

Изменяет первоначальные запросы нод, таксономии и комментариев. Часто используется для формирования списков.

Параметры

$query Запрос, который будет перезаписан.

$primary_table Имя или псевдоним таблицы, которая имеет первичный ключ для этого запроса. Хотя обычные имена таблиц такие: '{blocks}', '{comments}', '{forum}', '{node}', '{menu}', '{term_data}' или '{vocabulary}'. Но не смотря на это, обычно используются псевдонимы таблиц, например: 'b', 'c', 'f', 'n', 'm', 't' или 'v'.

$primary_field Имя основного поля.

$args Массив аргументов, которые передаются реализациями хука hook_db_rewrite_sql().

Возвращаемое значение

Исходный запрос с конструкциями JOIN и WHERE и со вставками из хука hook_db_rewrite_sql().

Связанные темы

▾ 48 функции вызывают db_rewrite_sql()

blogapi_mt_validate_terms in modules/blogapi/blogapi.module
Blogging API helper - find allowed taxonomy terms for a node type.
blog_block in modules/blog/blog.module
Реализация hook_block().
blog_feed_last in modules/blog/blog.module
Displays an RSS feed containing recent blog entries of all users.
blog_feed_user in modules/blog/blog.module
Displays an RSS feed containing recent blog entries of a given user.
blog_page_last in modules/blog/blog.module
Коллбэк меню. Показывает страницу Друпал с последними записями в блогах пользователей.
blog_page_user in modules/blog/blog.module
Показывает страницу Друпал с последними записями в блоге данного пользователя.
book_admin_orphan in modules/book/book.module
Коллбэк меню. Отображает список всех страниц книг (book), не имеющих родителя.
book_admin_overview in modules/book/book.module
Возвращает административный краткий обзор всех книг.
book_block in modules/book/book.module
Реализация hook_block().
book_export in modules/book/book.module
Menu callback; Generates various representation of a book page with all descendants and prints the requested representation to output.
book_location in modules/book/book.module
Given a node, this function returns an array of 'book node' objects representing the path in the book tree from the root to the parent of the given node.
book_location_down in modules/book/book.module
Given a node, this function returns an array of 'book node' objects representing the path in the book tree from the given node down to the last sibling of it.
book_menu in modules/book/book.module
Реализация hook_menu().
book_next in modules/book/book.module
Fetches the node object of the next page of the book.
book_prev in modules/book/book.module
Fetches the node object of the previous page of the book.
book_recurse in modules/book/book.module
Traverses the book tree. Applies the $visit_pre() callback to each node, is called recursively for each child of the node (in weight, title order). Finally appends the output of the $visit_post() callback to the output before returning the generated...
book_render in modules/book/book.module
Menu callback; prints a listing of all books.
book_toc in modules/book/book.module
Returns an array of titles and nid entries of book pages in table of contents order.
book_tree in modules/book/book.module
Returns an HTML nested list (wrapped in a menu-class div) representing the book nodes as a tree.
comment_get_recent in modules/comment/comment.module
Find a number of recent comments. This is done in two steps. 1. Find the n (specified by $number) nodes that have the most recent comments. This is done by querying node_comment_statistics which has an index on last_comment_timestamp, and is thus a...
forum_block in modules/forum/forum.module
Реализация hook_block().
forum_get_forums in modules/forum/forum.module
Returns a list of all forums for a given taxonomy id
forum_get_topics in modules/forum/forum.module
node_feed in modules/node/node.module
A generic function for generating RSS feeds from a set of nodes.
node_page_default in modules/node/node.module
Menu callback; Generate a listing of promoted nodes.
poll_block in modules/poll/poll.module
Реализация hook_block().
poll_page in modules/poll/poll.module
statistics_title_list in modules/statistics/statistics.module
Returns all time or today top or last viewed node(s).
taxonomy_autocomplete in modules/taxonomy/taxonomy.module
Helper function for autocompletion
taxonomy_form_alter in modules/taxonomy/taxonomy.module
Implementation of hook_form_alter(). Generate a form for selecting terms to associate with a node.
taxonomy_get_children in modules/taxonomy/taxonomy.module
Находит все дочерние термины данного термина.
taxonomy_get_parents in modules/taxonomy/taxonomy.module
Находит всех родителей данного идентификатора термина по его ID.
taxonomy_get_term_by_name in modules/taxonomy/taxonomy.module
Try to map a string to an existing term, as for glossary use.
taxonomy_get_tree in modules/taxonomy/taxonomy.module
Создает иерархическое представление словаря.
taxonomy_get_vocabularies in modules/taxonomy/taxonomy.module
Возвращает массив объектов всех словарей.
taxonomy_node_get_terms in modules/taxonomy/taxonomy.module
Находит все термины, которые связаны с данной нодой, и сортирует их по словарю и весу термина.
taxonomy_node_get_terms_by_vocabulary in modules/taxonomy/taxonomy.module
Находит все термины, которые связаны с данной нодой, в одном словаре.
taxonomy_overview_terms in modules/taxonomy/taxonomy.module
Display a tree of all the terms in a vocabulary, with options to edit each one.
taxonomy_select_nodes in modules/taxonomy/taxonomy.module
Находит все ноды, которые соответствуют выбранным условиям таксономии.
taxonomy_term_count_nodes in modules/taxonomy/taxonomy.module
Считает число опубликованных нод, содержащих терм.
taxonomy_term_page in modules/taxonomy/taxonomy.module
Menu callback; displays all nodes associated with a term.
theme_forum_topic_navigation in modules/forum/forum.module
Format the next/previous forum topic navigation links.
tracker_page in modules/tracker/tracker.module
Menu callback. Prints a listing of active nodes on the site.
_book_admin_table_tree in modules/book/book.module
_forum_new in modules/forum/forum.module
Finds the first unread node for a given forum.
_forum_topics_unread in modules/forum/forum.module
Calculate the number of nodes the user has not yet read and are newer than NODE_NEW_LIMIT.
_menu_build in includes/menu.inc
Build the menu by querying both modules and the database.
_node_types_build in modules/node/node.module
Builds and returns the list of available node types.

Код

<?php
function db_rewrite_sql($query, $primary_table = 'n', $primary_field = 'nid',  $args = array()) {
  list($join, $where, $distinct) = _db_rewrite_sql($query, $primary_table, $primary_field, $args);

  if ($distinct) {
    $query = db_distinct_field($primary_table, $primary_field, $query);
  }

  if (!empty($where) || !empty($join)) {
    if (!empty($where)) {
      $new = "WHERE $where ";
    }
    $new = " $join $new";
    if (strpos($query, 'WHERE')) {
      $query = str_replace('WHERE', $new .'AND (', $query);
      $insert = ') ';
    }
    else {
      $insert = $new;
    }
    if (strpos($query, 'GROUP')) {
      $replace = 'GROUP';
    }
    elseif (strpos($query, 'HAVING')) {
      $replace = 'HAVING';
    }
    elseif (strpos($query, 'ORDER')) {
      $replace = 'ORDER';
    }
    elseif (strpos($query, 'LIMIT')) {
      $replace = 'LIMIT';
    }
    else {
      $query .= $insert;
    }
    if (isset($replace)) {
      $query = str_replace($replace, $insert . $replace, $query);
    }
  }

  return $query;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему