You are here

function views_natural_sort_store in Views Natural Sort 7.2

Save an entry to the database that represents a views_natural_sort index.

Parameters

array $index_entry: Mirrors the views_natural_sort table $eid - Entity Id of the item referenced $entity_type - The Entity Type. Ex. node $field - reference to the property or field name $delta - the item number in that field or property $content - The transformed data that a field will be sorted by.

3 calls to views_natural_sort_store()
views_natural_sort_entity_insert in ./views_natural_sort.module
Implements hook_entity_insert().
views_natural_sort_rebuild_index in ./views_natural_sort.admin.inc
Batch API callback for rebuild_index.
views_natural_sort_store_multiple in ./views_natural_sort.module
Store Multiple views_natural_sort entries.

File

./views_natural_sort.module, line 222
Views Natural Sort module.

Code

function views_natural_sort_store(array $index_entry) {

  // This should take a formatted object and store it into the
  // views_natural_sort table.
  $string = views_natural_sort_transform($index_entry);

  // The size limit on the content field for views_natual_sort is sometimes not
  // enough. Lets truncate all data down to that size. I personally feel the
  // inaccuracy is an acceptable loss, as the bigger the string gets, the less
  // permanent the sort.
  //
  // TODO: Have this pick up off of the schema so if someone does a
  // hook_schema_alter() on me.
  return db_merge('views_natural_sort')
    ->key(array(
    'eid' => $index_entry['eid'],
    'entity_type' => $index_entry['entity_type'],
    'field' => $index_entry['field'],
    'delta' => $index_entry['delta'],
  ))
    ->fields(array(
    'eid' => $index_entry['eid'],
    'entity_type' => $index_entry['entity_type'],
    'field' => $index_entry['field'],
    'delta' => $index_entry['delta'],
    'content' => drupal_substr($string, 0, 255),
  ))
    ->execute();
}