views_natural_sort_handler_sort_text_field.inc 1.33 KB
Newer Older
1
<?php
2 3 4

/**
 * @file
5
 * Constains the views natural sort text field sorting handler.
6 7 8
 */

/**
9
 * The text field sort handler for views.
10
 */
11 12
class views_natural_sort_handler_sort_text_field extends views_natural_sort_handler_sort {

13
  /**
14
   * {@inheritdoc}
15 16
   */
  public function natural_sort_join() {
17 18 19
    $join = new views_join();
    $other_join = $this->get_join();
    $table_data = views_fetch_data($other_join->definition['left_table']);
20

21 22
    // If you look at where natural_sort_join is called, this alias will be
    // used.
23 24 25 26 27 28
    $vns_alias = 'vns_' . $this->table_alias;

    // Make the join. Can't use extra as an array because I have to join on two
    // fields and not 1 field with other fields == to a hard coded value.
    // I don't like this because it's insecure. Look for better way.
    // @see http://drupal.org/node/1090432
29 30 31 32 33
    $join->definition = array(
      'table' => 'views_natural_sort',
      'field' => 'eid',
      'left_field' => 'entity_id',
      'left_table' => $this->table_alias,
34
      'extra' => $vns_alias . '.delta = ' . $this->table_alias . '.delta AND ' .
35 36
      $vns_alias . ".entity_type = '" . $table_data['table']['entity type'] . "' AND " .
      $vns_alias . ".field = '" . preg_replace('/_value$/', '', $this->field) . "'",
37 38 39 40 41
    );
    $join->construct();
    $join->adjusted = TRUE;
    return $join;
  }
42

43
}