Create a filter for the model.

@return void
322934
protected function createFilter()
    {
        $model = Str::studly(class_basename($this->argument('name')));

        $this->call('make:filter', [
            'name' => $model.'Filter',
        ]);
    }
1233853
public function filters() {

		global $wpdb;

		if ( self::get_current_post_type() !== $this->cpt->post_type ) {
			return;
		}

		$pto = get_post_type_object( $this->cpt->post_type );

		foreach ( $this->args['admin_filters'] as $filter_key => $filter ) {

			if ( isset( $filter['cap'] ) && ! current_user_can( $filter['cap'] ) ) {
				continue;
			}

			if ( isset( $filter['taxonomy'] ) ) {

				$tax = get_taxonomy( $filter['taxonomy'] );

				if ( empty( $tax ) ) {
					continue;
				}

				require_once __DIR__ . '/class-walker-extendedtaxonomydropdown.php';

				$walker = new Walker_ExtendedTaxonomyDropdown( [
					'field' => 'slug',
				] );

				# If we haven't specified a title, use the all_items label from the taxonomy:
				if ( ! isset( $filter['title'] ) ) {
					$filter['title'] = $tax->labels->all_items;
				}

				# Output the dropdown:
				wp_dropdown_categories( [
					'show_option_all' => $filter['title'],
					'hide_empty'      => false,
					'hide_if_empty'   => true,
					'hierarchical'    => true,
					'show_count'      => false,
					'orderby'         => 'name',
					'selected_cats'   => get_query_var( $tax->query_var ),
					'id'              => 'filter_' . $filter_key,
					'name'            => $tax->query_var,
					'taxonomy'        => $filter['taxonomy'],
					'walker'          => $walker,
				] );

			} elseif ( isset( $filter['meta_key'] ) ) {

				# If we haven't specified a title, generate one from the meta key:
				if ( ! isset( $filter['title'] ) ) {
					$filter['title'] = str_replace( [
						'-',
						'_',
					], ' ', $filter['meta_key'] );
					$filter['title'] = ucwords( $filter['title'] ) . 's';
					$filter['title'] = sprintf( 'All %s', $filter['title'] );
				}

				if ( ! isset( $filter['options'] ) ) {
					# Fetch all the values for our meta key:
					# @TODO AND m.meta_value != null ?
					// @codingStandardsIgnoreStart
					$filter['options'] = $wpdb->get_col( $wpdb->prepare( "
						SELECT DISTINCT meta_value
						FROM {$wpdb->postmeta} as m
						JOIN {$wpdb->posts} as p ON ( p.ID = m.post_id )
						WHERE m.meta_key = %s
						AND m.meta_value != ''
						AND p.post_type = %s
						ORDER BY m.meta_value ASC
					", $filter['meta_key'], $this->cpt->post_type ) );
					// @codingStandardsIgnoreEnd
				} elseif ( is_callable( $filter['options'] ) ) {
					$filter['options'] = call_user_func( $filter['options'] );
				}

				if ( empty( $filter['options'] ) ) {
					continue;
				}

				$selected = wp_unslash( get_query_var( $filter_key ) );

				$use_key = false;

				foreach ( $filter['options'] as $k => $v ) {
					if ( ! is_numeric( $k ) ) {
						$use_key = true;
						break;
					}
				}

				# Output the dropdown:
				?>
				<select name="<?php echo esc_attr( $filter_key ); ?>" id="filter_<?php echo esc_attr( $filter_key ); ?>">
					<option value=""><?php echo esc_html( $filter['title'] ); ?></option>
					<?php
					foreach ( $filter['options'] as $k => $v ) {
						$key = ( $use_key ? $k : $v );
						?>
						<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $selected, $key ); ?>><?php echo esc_html( $v ); ?></option>
					<?php } ?>
				</select>
				<?php

			} elseif ( isset( $filter['meta_search_key'] ) ) {

				# If we haven't specified a title, generate one from the meta key:
				if ( ! isset( $filter['title'] ) ) {
					$filter['title'] = str_replace( [
						'-',
						'_',
					], ' ', $filter['meta_search_key'] );
					$filter['title'] = ucwords( $filter['title'] );
				}

				$value = wp_unslash( get_query_var( $filter_key ) );

				# Output the search box:
				?>
				<label><?php printf( '%s:', esc_html( $filter['title'] ) ); ?>&nbsp;<input type="text" name="<?php echo esc_attr( $filter_key ); ?>" id="filter_<?php echo esc_attr( $filter_key ); ?>" value="<?php echo esc_attr( $value ); ?>" /></label>
				<?php

			} elseif ( isset( $filter['meta_exists'] ) ) {

				# If we haven't specified a title, use the all_items label from the post type:
				if ( ! isset( $filter['title'] ) ) {
					$filter['title'] = $pto->labels->all_items;
				}

				$selected = wp_unslash( get_query_var( $filter_key ) );

				if ( 1 === count( $filter['meta_exists'] ) ) {

					# Output a checkbox:
					foreach ( $filter['meta_exists'] as $v => $t ) {
						?>
						<label><input type="checkbox" name="<?php echo esc_attr( $filter_key ); ?>" id="filter_<?php echo esc_attr( $filter_key ); ?>" value="<?php echo esc_attr( $v ); ?>" <?php checked( $selected, $v ); ?>>&nbsp;<?php echo esc_html( $t ); ?></label>
						<?php
					}
				} else {

					# Output a dropdown:
					?>
					<select name="<?php echo esc_attr( $filter_key ); ?>" id="filter_<?php echo esc_attr( $filter_key ); ?>">
						<option value=""><?php echo esc_html( $filter['title'] ); ?></option>
						<?php foreach ( $filter['meta_exists'] as $v => $t ) { ?>
							<option value="<?php echo esc_attr( $v ); ?>" <?php selected( $selected, $v ); ?>><?php echo esc_html( $t ); ?></option>
						<?php } ?>
					</select>
					<?php

				}
			}
		}

	}
851894
public function buildFilters()
    {
        $builder = $this->getFilterBuilder();
        $builder->add('created', new DateFilterType('created'), 'Date')
                ->add('lang', new StringFilterType('lang'), 'Language')
                ->add('ipAddress', new StringFilterType('ipAddress'), 'IP Address');
    }
226701
public function initialize()
    {
        static::addFilterDefinition('required', array($this, 'filterRequired'));
        static::addFilterDefinition('string', array($this, 'filterString'));
        static::addFilterDefinition('boolean', array($this, 'filterBoolean'));
        static::addFilterDefinition('confirm', array($this, 'filterConfirm'));
        static::addFilterDefinition('validate_regexp', array($this, 'filterValidateRegexp'));
        static::addFilterDefinition('validate_url', array($this, 'filterValidateUrl'));
        static::addFilterDefinition('validate_date', array($this, 'filterValidateDate'));
        static::addFilterDefinition('php', array($this, 'filterPHP'));
        static::addFilterDefinition('max_length', array($this, 'filterMaxLength'));
        static::addFilterDefinition('min_length', array($this, 'filterMinLength'));
        static::$isInitialized = TRUE;
    }
34137
protected function createFilterManager()
    {
        $manager = new FilterManager();
        $filters = Config::get($this->namespace.'::filters', array());
        foreach ($filters as $name => $filter) {
            $manager->set($name, $this->createFilter($filter));
        }

        return $this->filters = $manager;
    }
1186719
public function createFormModel()
    {
        $this->formModel = new FilteringModel();
        if ($this->formModel->load(Cii::$app->request->post(), $this->formModelName) || $this->formModel->load(Cii::$app->getSession()->get($this->formModelName), '')) {
            if(!$this->formModel->validate()){
                return;
            }
            if ($this->formModel->resetall == '1') {
                Cii::$app->getSession()->remove($this->formModelName);
                $this->formModel = new FilteringModel();
                return;
            }
            Cii::$app->getSession()->set($this->formModelName, $this->formModel->getAttributes());
            foreach ($this->formModel->column as $i => $column) {
                $condition = false;
                if (in_array($i, ['{baseindex}'])) continue;
                $op = $this->formModel->op[$i];
                $value = $this->formModel->value[$i];
                if (strtoupper($value) === 'NULL') {
                    $value = NULL;
                }

                if($op === 'IN'){
                    $value = explode(',',$value);

                    if($this->tableSchema->columns[$column]->type === 'integer'){
                        $value=array_map('intval',$value);
                    }
                }
                elseif($op === 'BETWEEN'){
                    $this->formModel->value[$i] = Cii::t('codeup', '(dev)');
                    continue;
                }
                elseif($op === 'IS NULL'){
                    $op = 'IS';
                    $value = NULL;
                }
                elseif($op === 'IS NOT NULL'){
                    $op = 'IS NOT';
                    $value = NULL;
                }
                if(!$condition) {
                    $column = $this->modelClass::tableName().'.'.$column;
                    $condition = [$op, $column, $value];
                }
                if (!isset($this->formModel->andor[$i])) {
                    $this->_query->andWhere($condition);
                } else {
                    $andor = $this->formModel->andor[$i];
                    if (strtolower($andor) == 'and') {
                        $this->_query->andWhere($condition);
                    } elseif (strtolower($andor) == 'or') {
                        $this->_query->orWhere($condition);
                    }
                }
            }
            $this->_query->andWhere($this->baseWhere);

            foreach ($this->formModel->order as $i => $order) {
                if (in_array($i, ['{baseindex}'])) continue;
                $this->_query->addOrderBy($order['column'] . ' ' . $order['val']);
            }
            $this->_hasQuery = true;
        }
    }
519343
protected function initFilters()
    {
        $initColumnSearch = $this->initColumnSearch;
        foreach ($this->columns as $c) {
            if (isset($c['sqlFilter'])) {
                $where_condition = $this->generateSQLColumnFilter($this->toSQLColumn($c, 2), $c['sqlFilter']);
                if (!$this->setHaving($where_condition, $c)) {
                    $initColumnSearch[] = $this->generateSQLColumnFilter($this->toSQLColumn($c, 2), $c['sqlFilter']);
                }
            }
        }

        return implode(' AND ', $initColumnSearch);
    }
672322
protected function setupFilterShortcuts()
    {
        foreach (self::$filters as $filterSubject => $availableFilters) {
            $filterArrayName = $filterSubject . 'Filter';
            $this->$filterArrayName = [];
            $tempArr = &$this->$filterArrayName;
            foreach ($availableFilters as $type) {
                $funcName = 'make' . ucfirst($filterSubject) . 'Filter' . $type;
                $tempArr[$type] = function () use ($funcName) {
                    return call_user_func_array([$this, $funcName], func_get_args());
                };
            }
        }
    }
279360
protected function makeFiltersForAllAttributes()
    {
        $filters = [];

        foreach ($this->info->attributes as $attribute) {

            if ($attribute->hidden || ! $this->shouldAttributeBeFilterable($attribute)) {
                continue;
            }

            $filterData = $this->makeModelListFilterDataForAttributeData($attribute, $this->info);

            if ( ! $filterData) continue;

            $filters[$attribute->name] = $filterData;
        }

        return $filters;
    }
1299331
private function createQueryFilter()
    {
        if (count($this->queryFilter()) > 0) {
            foreach ($this->queryFilter() as $filter => $parameters) {
                if (!is_array($parameters)) {
                    $parameters = [$parameters];
                }
                $this->query = call_user_func_array([$this->query, $filter], $parameters);
            }
        }
    }
97314
public function addFilter(Filter $filter)
    {
        $key = $filter->getKey();
        $this->filters[$key] = $filter;
    }
319884
public function buildFilters()
    {
        $this->addFilter('name', new ORM\StringFilterType('name'), 'media.adminlist.configurator.filter.name');
        $this->addFilter('contentType', new ORM\StringFilterType('contentType'), 'media.adminlist.configurator.filter.type');
        $this->addFilter('updatedAt', new ORM\NumberFilterType('updatedAt'), 'media.adminlist.configurator.filter.updated_at');
        $this->addFilter('filesize', new ORM\NumberFilterType('filesize'), 'media.adminlist.configurator.filter.filesize');
    }
555357
private function applyQueryFilters()
    {
        if (is_array($this->queryFilter())) {
            $this->createQueryFilter();
        } else {
            $this->queryFilter();
        }

        $this->queryFilterRequest();
    }
600065
public function filter($condition)
    {
        $items = $this->find()->where($condition)->all();
        $this->_filter = $this->_getTreeNodesIds($items);
    }
43839
protected function applyFiltersTo()
    {
        $searchValue = request('search')['value'];

        if ($searchValue) {
            $this->queryHandler->applyFilters($this->columnManager->getSearchColumns(), $searchValue);
        }
    }
1036177
protected function _createFilter()
    {
        $config = array();
        $config['separator'] = $this->_separator;

        if (!isset($this->_length)) {
            $config['length'] = $this->getTable()->getColumn('slug')->length;
        } else {
            $config['length'] = $this->_length;
        }

        return $this->getObject('filter.factory')->createChain($this->_filter, $config);
    }
926835
def addFilter(self, filterclass):
        """"""
        if filterclass not in self.filters:
            self.filters.append(filterclass)