function _views_natural_sort_store_node in Views Natural Sort 6
Same name and namespace in other branches
- 7 views_natural_sort.module \_views_natural_sort_store_node()
Helper function for writing node data to our sort index.
Parameters
$node: A drupal node object containing at least a nid and title.
2 calls to _views_natural_sort_store_node()
- views_natural_sort_nodeapi in ./
views_natural_sort.module - Implementation of hook_nodeapi().
- views_natural_sort_rebuild_index in ./
views_natural_sort.admin.inc - Batch API callback for rebuild_index.
File
- ./
views_natural_sort.module, line 93 - Provides a views filter that sorts titles by a more natural manner by ignoring articles like "The" and "A."
Code
function _views_natural_sort_store_node($node) {
$record = new stdClass();
$record->nid = $node->nid;
$record->field = 'title';
$record->content = views_natural_sort_encode($node->title);
// Try to update. On fail, try inserting.
$exists = db_result(db_query("SELECT 1 FROM {views_natural_sort} WHERE nid = %d AND field = '%s'", array(
$record->nid,
$record->field,
)));
if ($exists) {
$return = drupal_write_record('views_natural_sort', $record, array(
'nid',
'field',
));
}
else {
$return = drupal_write_record('views_natural_sort', $record);
}
return $return;
}