You are here

function _notifications_node_references in Notifications 6.4

Same name and namespace in other branches
  1. 6 notifications.node.inc \_notifications_node_references()
  2. 6.2 notifications.node.inc \_notifications_node_references()
  3. 6.3 notifications.node.inc \_notifications_node_references()
  4. 7 includes/node.inc \_notifications_node_references()

Find node title matches.

Some code from CCK's nodereference.module

3 calls to _notifications_node_references()
notifications_node_autocomplete_title in includes/node.inc
Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users
notifications_node_autocomplete_type in includes/node.inc
Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing nodes
notifications_node_title2nid in includes/node.inc
Reverse mapping from node title to nid

File

includes/node.inc, line 120
Notifications node API for use by plug-in modules providing node related features

Code

function _notifications_node_references($string, $match = 'contains', $types = array(), $limit = 10) {
  $match_operators = array(
    'contains' => "LIKE '%%%s%%'",
    'equals' => "= '%s'",
    'starts_with' => "LIKE '%s%%'",
  );
  if (!empty($types)) {
    $where[] = 'n.type IN (' . db_placeholders($types, 'char') . ') ';
    $args = $types;
  }
  $where[] = 'n.title ' . (isset($match_operators[$match]) ? $match_operators[$match] : $match_operators['contains']);
  $args[] = $string;
  $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);
  $references = array();
  while ($node = db_fetch_object($result)) {
    $references[$node->nid] = array(
      'title' => $node->title,
      'rendered' => check_plain($node->title),
    );
  }
  return $references;
}