The new condition and the existing one will be joined using the 'AND' operator.
public andFilterWhere ( array $condition ) | ||
$condition | array | the new WHERE condition. Please refer to [[where()]] on how to specify this parameter. |
/** * * @param QueryInterface $query * @param string $attribute name of defined public property * @param string $fieldName related table's field name * @param string $tableName table name or alias (if defined in `joinWithRelation()` method) * @param string $operator defaults to 'like' */ public function addRelationFilter(&$query, $attribute, $fieldName, $tableName, $operator = 'like') { $query->andFilterWhere([$operator, $this->getRelationSearchTableName($tableName, $attribute) . '.' . $fieldName, $this->{$attribute}]); }
private function filterByInfractionDate(QueryInterface &$query, $filter, $days_ago) { if (!array_key_exists($filter, $this->getCreatedAtFilters())) { return false; } switch ($filter) { case self::CREATED_AT_TODAY: return $query->andFilterWhere(['>', 'record.created_at', strtotime('midnight')]); case self::CREATED_AT_LAST_3_DAYS: return $query->andFilterWhere(['>', 'record.created_at', strtotime('-3 days')]); case self::CREATED_AT_LAST_X_DAYS: if (!is_numeric($days_ago) || $days_ago <= 0 || $days_ago > 366) { return false; } return $query->andFilterWhere(['>', 'record.created_at', strtotime('-' . $days_ago . ' days')]); } }
/** * @param QueryInterface $query * @param array $filter */ public function defaultFilter($query, $filter) { $field = $filter['field']; if (isset($this->fieldMap[$field])) { $field = $this->fieldMap[$field]; } $op = isset($filter['op']) ? $filter['op'] : 'contains'; $value = isset($filter['value']) ? $filter['value'] : ''; if ($value === '' && $op != 'equal') { return; } switch ($op) { case 'contains': $query->andFilterWhere([$field => $value]); break; case 'equal': $query->andWhere([$field => $value]); break; case 'notequal': $query->andWhere(['<>', $field, $value]); break; case 'beginwith': $query->andWhere(['like', $field, $value . '%']); break; case 'endwith': $query->andWhere(['like', $field, '%' . $value]); break; case 'less': $query->andWhere(['<', $field, $value]); break; case 'lessorequal': $query->andWhere(['<=', $field, $value]); break; case 'greater': $query->andWhere(['>', $field, $value]); break; case 'greaterorequal': $query->andWhere(['>=', $field, $value]); break; } }
/** * Default filter for search * @param QueryInterface $query * */ public function filters($query) { $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'id', $this->id]); }