You are here

function _i18n_node_references in Internationalization 6

Same name and namespace in other branches
  1. 7 i18n_node/i18n_node.pages.inc \_i18n_node_references()

Find node title matches.

Parameters

$string: String to match against node title

$match: Match mode: 'contains', 'equals', 'starts_with'

$params: Other query arguments: type, language or numeric ones

Some code from CCK's nodereference.module

2 calls to _i18n_node_references()
i18n_node_autocomplete in ./i18n.pages.inc
Node title autocomplete callback
i18n_node_autocomplete2nid in ./i18n.pages.inc
Reverse mapping from node title to nid

File

./i18n.pages.inc, line 223
User page callbacks for the translation module.

Code

function _i18n_node_references($string, $match = 'contains', $params = array(), $limit = 10) {
  $where = $args = array();
  $match_operators = array(
    'contains' => "LIKE '%%%s%%'",
    'equals' => "= '%s'",
    'starts_with' => "LIKE '%s%%'",
  );
  foreach ($params as $key => $value) {
    $type = in_array($key, array(
      'type',
      'language',
    )) ? 'char' : 'int';
    if (is_array($value)) {
      $where[] = "n.{$key} IN (" . db_placeholders($value, $type) . ') ';
      $args = array_merge($args, $value);
    }
    else {
      $where[] = "n.{$key} = " . db_type_placeholder($type);
      $args[] = $value;
    }
  }
  $where[] = 'n.title ' . (isset($match_operators[$match]) ? $match_operators[$match] : $match_operators['contains']);
  $args[] = $string;

  // Disable and reenable i18n selection mode so no language conditions are inserted
  i18n_selection_mode('off');
  $sql = db_rewrite_sql('SELECT n.nid, n.title, n.type FROM {node} n WHERE ' . implode(' AND ', $where) . ' ORDER BY n.title, n.type');
  $result = db_query_range($sql, $args, 0, $limit);
  i18n_selection_mode('reset');
  $references = array();
  while ($node = db_fetch_object($result)) {
    $references[$node->nid] = array(
      'title' => $node->title,
      'rendered' => check_plain($node->title),
    );
  }
  return $references;
}