public ManyToOneHelper::addFilter()
File
- core/modules/views/src/ManyToOneHelper.php, line 255
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 | public function addFilter() { if ( empty ( $this ->handler->value)) { return ; } $this ->handler->ensureMyTable(); // Shorten some variables: $field = $this ->getField(); $options = $this ->handler->options; $operator = $this ->handler->operator; $formula = ! empty ( $this ->formula); $value = $this ->handler->value; if ( empty ( $options [ 'group' ])) { $options [ 'group' ] = 0; } // add_condition determines whether a single expression is enough(FALSE) or the // conditions should be added via an db_or()/db_and() (TRUE). $add_condition = TRUE; if ( $operator == 'not' ) { $value = NULL; $operator = 'IS NULL' ; $add_condition = FALSE; } elseif ( $operator == 'or' && empty ( $options [ 'reduce_duplicates' ])) { if ( count ( $value ) > 1) { $operator = 'IN' ; } else { $value = is_array ( $value ) ? array_pop ( $value ) : $value ; $operator = '=' ; } $add_condition = FALSE; } if (! $add_condition ) { if ( $formula ) { $placeholder = $this ->placeholder(); if ( $operator == 'IN' ) { $operator = "$operator IN($placeholder)" ; } else { $operator = "$operator $placeholder" ; } $placeholders = array ( $placeholder => $value , ); $this ->handler->query->addWhereExpression( $options [ 'group' ], "$field $operator" , $placeholders ); } else { $placeholder = $this ->placeholder(); if ( count ( $this ->handler->value) > 1) { $placeholder .= '[]' ; if ( $operator == 'IS NULL' ) { $this ->handler->query->addWhereExpression(0, "$field $operator" ); } else { $this ->handler->query->addWhereExpression(0, "$field $operator($placeholder)" , array ( $placeholder => $value )); } } else { if ( $operator == 'IS NULL' ) { $this ->handler->query->addWhereExpression(0, "$field $operator" ); } else { $this ->handler->query->addWhereExpression(0, "$field $operator $placeholder" , array ( $placeholder => $value )); } } } } if ( $add_condition ) { $field = $this ->handler->realField; $clause = $operator == 'or' ? db_or() : db_and(); foreach ( $this ->handler->tableAliases as $value => $alias ) { $clause ->condition( "$alias.$field" , $value ); } // implode on either AND or OR. $this ->handler->query->addWhere( $options [ 'group' ], $clause ); } } |
Please login to continue.