public ManyToOneHelper::ensureMyTable()
Override ensureMyTable so we can control how this joins in. The operator actually has influence over joining.
File
- core/modules/views/src/ManyToOneHelper.php, line 154
Class
- ManyToOneHelper
- This many to one helper object is used on both arguments and filters.
Namespace
Drupal\views
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | public function ensureMyTable() { if (!isset( $this ->handler->tableAlias)) { // Case 1: Operator is an 'or' and we're not reducing duplicates. // We hence get the absolute simplest: $field = $this ->handler->relationship . '_' . $this ->handler->table . '.' . $this ->handler->field; if ( $this ->handler->operator == 'or' && empty ( $this ->handler->options[ 'reduce_duplicates' ])) { if ( empty ( $this ->handler->options[ 'add_table' ]) && empty ( $this ->handler->view->many_to_one_tables[ $field ])) { // query optimization, INNER joins are slightly faster, so use them // when we know we can. $join = $this ->getJoin(); if (isset( $join )) { $join ->type = 'INNER' ; } $this ->handler->tableAlias = $this ->handler->query->ensureTable( $this ->handler->table, $this ->handler->relationship, $join ); $this ->handler->view->many_to_one_tables[ $field ] = $this ->handler->value; } else { $join = $this ->getJoin(); $join ->type = 'LEFT' ; if (! empty ( $this ->handler->view->many_to_one_tables[ $field ])) { foreach ( $this ->handler->view->many_to_one_tables[ $field ] as $value ) { $join ->extra = array ( array ( 'field' => $this ->handler->realField, 'operator' => '!=' , 'value' => $value , 'numeric' => ! empty ( $this ->handler->definition[ 'numeric' ]), ), ); } } $this ->handler->tableAlias = $this ->addTable( $join ); } return $this ->handler->tableAlias; } // Case 2: it's an 'and' or an 'or'. // We do one join per selected value. if ( $this ->handler->operator != 'not' ) { // Clone the join for each table: $this ->handler->tableAliases = array (); foreach ( $this ->handler->value as $value ) { $join = $this ->getJoin(); if ( $this ->handler->operator == 'and' ) { $join ->type = 'INNER' ; } $join ->extra = array ( array ( 'field' => $this ->handler->realField, 'value' => $value , 'numeric' => ! empty ( $this ->handler->definition[ 'numeric' ]), ), ); // The table alias needs to be unique to this value across the // multiple times the filter or argument is called by the view. if (!isset( $this ->handler->view->many_to_one_aliases[ $field ][ $value ])) { if (!isset( $this ->handler->view->many_to_one_count[ $this ->handler->table])) { $this ->handler->view->many_to_one_count[ $this ->handler->table] = 0; } $this ->handler->view->many_to_one_aliases[ $field ][ $value ] = $this ->handler->table . '_value_' . ( $this ->handler->view->many_to_one_count[ $this ->handler->table]++); } $this ->handler->tableAliases[ $value ] = $this ->addTable( $join , $this ->handler->view->many_to_one_aliases[ $field ][ $value ]); // Set tableAlias to the first of these. if ( empty ( $this ->handler->tableAlias)) { $this ->handler->tableAlias = $this ->handler->tableAliases[ $value ]; } } } // Case 3: it's a 'not'. // We just do one join. We'll add a where clause during // the query phase to ensure that $table.$field IS NULL. else { $join = $this ->getJoin(); $join ->type = 'LEFT' ; $join ->extra = array (); $join ->extraOperator = 'OR' ; foreach ( $this ->handler->value as $value ) { $join ->extra[] = array ( 'field' => $this ->handler->realField, 'value' => $value , 'numeric' => ! empty ( $this ->handler->definition[ 'numeric' ]), ); } $this ->handler->tableAlias = $this ->addTable( $join ); } } return $this ->handler->tableAlias; } |
Please login to continue.