function _notifications_node_references in Notifications 7
Same name and namespace in other branches
- 6.4 includes/node.inc \_notifications_node_references()
- 6 notifications.node.inc \_notifications_node_references()
- 6.2 notifications.node.inc \_notifications_node_references()
- 6.3 notifications.node.inc \_notifications_node_references()
Find node title matches.
Some code from node_reference.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 108 - 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) {
$query = db_select('node', 'n');
$node_nid_alias = $query
->addField('n', 'nid');
$node_title_alias = $query
->addField('n', 'title', 'node_title');
$node_type_alias = $query
->addField('n', 'type', 'node_type');
$query
->addTag('node_access');
if ($types) {
$query
->condition('n.type', $types, 'IN');
}
switch ($match) {
default:
// no match type or incorrect match type: use "="
case 'contains':
$query
->condition('n.title', '%' . $string . '%', 'LIKE');
break;
case 'starts_with':
$query
->condition('n.title', $string . '%', 'LIKE');
break;
case 'equals':
$query
->condition('n.title', $string);
break;
}
$query
->range(0, $limit)
->orderBy($node_title_alias)
->orderBy($node_type_alias);
$result = $query
->execute()
->fetchAll();
$references = array();
foreach ($result as $node) {
$references[$node->nid] = array(
'title' => $node->node_title,
'rendered' => check_plain($node->node_title),
);
}
return $references;
}