/** * Filter a query by the value of a * field using this field type. * * @param Builder $query * @param FilterInterface $filter */ public function filter(Builder $query, FilterInterface $filter) { $stream = $filter->getStream(); $assignment = $stream->getAssignment($filter->getField()); $column = $this->fieldType->getColumnName(); $table = $stream->getEntryTableName(); $translations = $stream->getEntryTranslationsTableName(); $modifier = $this->fieldType->getModifier(); if ($assignment->isTranslatable()) { $query->join($translations, $translations . '.entry_id', '=', $table . '.id')->where($translations . '.' . $column, $modifier->modify($filter->getValue()))->where('locale', config('app.locale')); } else { $query->where($column, $modifier->modify($filter->getValue())); } }
/** * Handle the filter. * * @param Builder $query * @param FilterInterface $filter */ public function handle(Builder $query, FilterInterface $filter) { $stream = $filter->getStream(); if ($stream && ($fieldType = $stream->getFieldType($filter->getField()))) { $fieldTypeQuery = $fieldType->getQuery(); $this->container->call([$fieldTypeQuery, 'filter'], compact('query', 'filter', 'builder')); return; } if ($stream && ($fieldType = $stream->getFieldType($filter->getSlug()))) { $fieldTypeQuery = $fieldType->getQuery(); $this->container->call([$fieldTypeQuery, 'filter'], compact('query', 'filter', 'builder')); return; } if ($filter->isExact()) { $query->where($filter->getSlug(), $filter->getValue()); } else { $query->where($filter->getSlug(), 'LIKE', "%{$filter->getValue()}%"); } }
/** * Filter a query by the value of a * field using this field type. * * @param Builder $query * @param FilterInterface $filter */ public function filter(Builder $query, FilterInterface $filter) { $stream = $filter->getStream(); $assignment = $stream->getAssignment($filter->getField()); $column = $this->fieldType->getColumnName(); $translations = $stream->getEntryTranslationsTableName(); if ($assignment->isTranslatable()) { if ($query instanceof EloquentQueryBuilder && !$query->hasJoin($translations)) { $query->leftJoin($stream->getEntryTranslationsTableName(), $stream->getEntryTableName() . '.id', '=', $stream->getEntryTranslationsTableName() . '.entry_id'); } $query->addSelect($translations . '.locale'); $query->addSelect($translations . '.' . $column); $query->{$this->where()}(function (Builder $query) use($stream, $filter, $column) { $query->where($stream->getEntryTranslationsTableName() . '.locale', config('app.locale')); $query->where($stream->getEntryTranslationsTableName() . '.' . $column, 'LIKE', "%" . $filter->getValue() . "%"); }); } else { $query->{$this->where()}(function (Builder $query) use($stream, $filter, $column) { $query->where($stream->getEntryTableName() . '.' . $column, 'LIKE', "%" . $filter->getValue() . "%"); }); } }
/** * Handle the filter query. * * @param Builder $query * @param FilterInterface $filter * @param TableBuilder $builder */ public function filter(Builder $query, FilterInterface $filter, TableBuilder $builder) { $stream = $builder->getTableStream(); $table = $stream->getEntryTableName() . '_' . $filter->getField(); $query->join($table . ' AS filter_' . $filter->getField(), $stream->getEntryTableName() . '.id', '=', 'filter_' . $filter->getField() . '.entry_id')->where('filter_' . $filter->getField() . '.entry_id', $filter->getValue()); }