@param string     $type
@param array|null $filter
@param array|null $sortOrder
@param array|null $limit

@return \BiberLtd\Bundle\CoreBundle\Responses\ModelResponse
@throws \BiberLtd\Bundle\FileManagementBundle\Exception\InvalidFileTypeException
493803
public function listFilesWithType(string $type, array $filter = null, array $sortOrder = null, array $limit = null) {
		$timeStamp = microtime(true);
	    $typeOpts = array('a', 'i', 'v', 'f', 'd', 'p', 's', 'c');
        if(!in_array($type, $typeOpts)){
	        throw new InvalidFileTypeException($type);
		}
        $filter[] = array(
            'glue' => ' and',
            'condition' => array(
                'column' => $this->entity['f']['alias'] . '.type',
                'comparison' => '=',
                'value' => $type)
        );
        $response = $this->listFiles($filter, $sortOrder, $limit);

		$response->stats->execution->start = $timeStamp;
		$response->stats->execution->end = microtime(true);

		return $response;
    }
320454
public function post($name = null, $default = null, $filter = true, $type = null)
    {
        $post = $this->request['post'];

        if ($filter !== 'raw') {
            gplcart_array_trim($post, (bool) $filter);
        }

        if (isset($name)) {
            $result = gplcart_array_get($post, $name);
            $return = isset($result) ? $result : $default;
        } else {
            $return = $post;
        }

        gplcart_settype($return, $type, $default);
        return $return;
    }
49453
public function withFilter(Filter $filter)
    {
        if ($this->value->isNull()) {
            return null;
        }

        return $this->applyFilter($filter);
    }
1619
protected function buildFilter($field, $type, $filter, $value)
    {
        if (strlen($field) == 0)
            throw new \Exception("Empty 'field'");
        if (strlen($type) == 0)
            throw new \Exception("Empty 'type'");

        if ($type == Table::TYPE_DATETIME) {
            if ($filter == Table::FILTER_BETWEEN
                    && is_array($value) && count($value) == 2) {
                $value = [
                    $value[0] ? new \DateTime('@' . $value[0]) : null,
                    $value[1] ? new \DateTime('@' . $value[1]) : null,
                ];
                if ($value[0] && $this->getDbTimezone())
                    $value[0]->setTimezone(new \DateTimeZone($this->getDbTimezone()));
                if ($value[1] && $this->getDbTimezone())
                    $value[1]->setTimezone(new \DateTimeZone($this->getDbTimezone()));
            } else if ($filter != Table::FILTER_BETWEEN
                    && !is_array($value)) {
                $value = new \DateTime('@' . $value);
                if ($this->getDbTimezone())
                    $value->setTimezone(new \DateTimeZone($this->getDbTimezone()));
            } else {
                return false;
            }
        } else {
            if ($filter == Table::FILTER_BETWEEN) {
                if (!is_array($value) || count($value) != 2)
                    return false;
            } else if (is_array($value)) {
                return false;
            }
        }

        if (!isset($this->sqlAnds[$field]))
            $this->sqlAnds[$field] = [];

        $paramBaseName = 'dt_' . str_replace('.', '_', $field);
        switch ($filter) {
            case Table::FILTER_LIKE:
                $param = ':' . $paramBaseName . '_like';
                $this->sqlAnds[$field][] = "$field LIKE $param";
                $this->sqlParams[$param] = '%' . $value . '%';
                break;
            case Table::FILTER_EQUAL:
                $param = ':' . $paramBaseName . '_equal';
                $this->sqlAnds[$field][] = "$field = $param";
                $this->sqlParams[$param] = $value;
                break;
            case Table::FILTER_BETWEEN:
                $ands = [];
                if ($value[0] !== null) {
                    $param = ':' . $paramBaseName . '_begin';
                    $ands[] = "$field >= $param";
                    $this->sqlParams[$param] = $value[0];
                }
                if ($value[1] !== null) {
                    $param = ':' . $paramBaseName . '_end';
                    $ands[] = "$field <= $param";
                    $this->sqlParams[$param] = $value[1];
                }
                $this->sqlAnds[$field][] = join(' AND ', $ands);
                break;
            case Table::FILTER_NULL:
                $this->sqlAnds[$field][] = "$field IS NULL";
                break;
            default:
                throw new \Exception("Unknown filter: $filter");
        }

        return true;
    }
802420
protected function loadLastObject($type, $sortkeyName, $sortDirection) {
    $query = new ObjectQuery($type);
    $pagingInfo = new PagingInfo(1, true);
    $invSortDir = $sortDirection == 'ASC' ? 'DESC' : 'ASC';
    $objects = $query->execute(BuildDepth::SINGLE, [$sortkeyName." ".$invSortDir], $pagingInfo);
    return sizeof($objects) > 0 ? $objects[0] : null;
  }
667936
public function addSorting($column, $type)
    {
        $availableSortTypes = [self::SORT_ASC, self::SORT_DESC];
        if (!in_array($type, $availableSortTypes)) {
            throw new \Exception(sprintf('Wrong sort type: "%s". Supported types: [%s]', $type, implode(',', $availableSortTypes)));
        }

        $this->sortParams[$column] = $type;

        return $this;
    }
545912
protected function filter($type, $offset = null, $filter = FILTER_DEFAULT)
    {
        if (services()->has('xssProtection')) {
            if ( ! services()->get('xssProtection')->verify()) {
                $string = parent::filter($type, $offset, $filter);

                if (is_string($string)) {
                    return Xss::clean($string);
                }
            }
        }

        return parent::filter($type, $offset, $filter);
    }
963536
protected function getContentInfoList(
        Criterion $filter,
        $sort,
        $offset,
        $limit,
        array $languageFilter
    ) {
        $query = $this->handler->createSelectQuery();
        $query->selectDistinct(
            'ezcontentobject.*',
            $this->handler->aliasedColumn($query, 'main_node_id', 'main_tree')
        );

        if ($sort !== null) {
            $this->sortClauseConverter->applySelect($query, $sort);
        }

        $query->from(
            $this->handler->quoteTable('ezcontentobject')
        )->innerJoin(
            'ezcontentobject_version',
            'ezcontentobject.id',
            'ezcontentobject_version.contentobject_id'
        )->leftJoin(
            $this->handler->alias(
                $this->handler->quoteTable('ezcontentobject_tree'),
                $this->handler->quoteIdentifier('main_tree')
            ),
            $query->expr->lAnd(
                $query->expr->eq(
                    $this->handler->quoteColumn('contentobject_id', 'main_tree'),
                    $this->handler->quoteColumn('id', 'ezcontentobject')
                ),
                $query->expr->eq(
                    $this->handler->quoteColumn('main_node_id', 'main_tree'),
                    $this->handler->quoteColumn('node_id', 'main_tree')
                )
            )
        );

        if ($sort !== null) {
            $this->sortClauseConverter->applyJoin($query, $sort, $languageFilter);
        }

        $query->where(
            $this->getQueryCondition($filter, $query, $languageFilter)
        );

        if ($sort !== null) {
            $this->sortClauseConverter->applyOrderBy($query);
        }

        $query->limit($limit, $offset);

        $statement = $query->prepare();
        $statement->execute();

        return $statement->fetchAll(PDO::FETCH_ASSOC);
    }
682464
public function search(SearchCondition\SearchConditionInterface $filter, SelectOrder\SelectOrderInterface $order = null)
	{
		$qb = $this->createSearchQueryBuilder($filter, $order);

		$result = $qb->getQuery()
				->getResult();
		
		return $result;
	}
336671
public function addFilter($filter)
    {
        if (!$filter instanceof FilterInterface) {
            if (!is_callable($filter)) {
                throw new \InvalidArgumentException('Filter should be callable or ' . FilterInterface::class);
            }

            $filter = new CallbackFilter($filter);
        }

        $this->filters[] = $filter;

        return $this;
    }
1184107
public function visitFilter(FilterInterface $filter)
    {
        if ($filter instanceof DummyFilter) {
            $type = 'dummy';
        } elseif ($filter instanceof SelectFilter) {
            $type = 'select';
        } elseif ($filter instanceof SearchFilter) {
            $type = 'search';
        } elseif ($filter instanceof SortFilter) {
            $type = 'sort';
        } elseif ($filter instanceof PaginationFilter) {
            $type = "{$filter->getType()}-pagination";
        } elseif (method_exists($filter, 'getType') === true) {
            $type = $filter->getType();
        } else {
            $type = 'dummy';
        }
        $template = "filter/$type.twig";

        return $this
            ->loadTemplate($template)
            ->render(
                [
                    "id" => $filter->getId(),
                    "options" => $filter->getOptions(),
                ]
            );
    }
1051985
public function getSearchRequest($filter, $limit = 1, $conditions = [])
    {
        $self = $this;
        $knownFilters = $this->_getSearchFilters();
        $request = new StorageDataRequest(
            [$filter, $limit, $conditions],
            function ($filter, $limit, $conditions) use ($self, $knownFilters) {
                $items = $self->getAllItems();
                $results = [];
                $filterRules = [];
                
                foreach ($filter as $filterRequest) {
                    if (\count($filterRequest) === 3) {
                        list ($key, $compare, $compareValue) = $filterRequest;
                        
                        if (isset($knownFilters[$compare])) {
                            $filterRules[] = [$key, $knownFilters[$compare], $compareValue];
                        } else {
                            trigger_error('Comparator not found for filter: '.json_encode($filterRequest).'');
                        }
                    } else {
                        trigger_error('Strange filter: less than 3 parameters, '.json_encode($filterRequest));
                    }
                }
                
                foreach ($items as $id) {
                    $pointer = $self->getPointer($id);
                    $isOk = true;
                    if ($pointer) {
                        $record = json_decode(stream_get_contents($pointer), true);
                        
                        if (isset($record[self::F_DATA])) {
                            foreach ($filterRules as $filterRule) {
                                list ($key, $function, $filterRequest) = $filterRule;
        
                                $isOk = $isOk && call_user_func($function, $record[self::F_DATA][$key] ?? null, $filterRequest);
        
                                if (!$isOk) {
                                    break;
                                }
                            }
    
                            if ($isOk) {
                                $results[$id] = [$this->primaryKey => $id] + $record[self::F_DATA];
                            }    
                        }
                        
                        $self->closePointer($pointer);
                        
                        if (count($results) >= $limit) {
                            break;
                        }
                    }
                }
                
                if ($results && $conditions) {
                    $self->applyConditions($results, $conditions);
                }
            
                return $results;
            }
        );
    
        return $request;
    }
1253794
protected function checkFilter($filter, $type, $test, $real)
    {
        if ($type == Table::TYPE_DATETIME) {
            if ($filter == Table::FILTER_BETWEEN
                    && is_array($test) && count($test) == 2) {
                $test = [
                    $test[0] ? new \DateTime('@' . $test[0]) : null,
                    $test[1] ? new \DateTime('@' . $test[1]) : null,
                ];
                if ($test[0] && $this->getDbTimezone())
                    $test[0]->setTimezone(new \DateTimeZone($this->getDbTimezone()));
                if ($test[1] && $this->getDbTimezone())
                    $test[1]->setTimezone(new \DateTimeZone($this->getDbTimezone()));
            } else if ($filter != Table::FILTER_BETWEEN
                    && is_scalar($test)) {
                $test = new \DateTime('@' . $test);
                if ($this->getDbTimezone())
                    $test->setTimezone(new \DateTimeZone($this->getDbTimezone()));
            } else {
                return null;
            }
        } else {
            if ($filter == Table::FILTER_BETWEEN) {
                if (!is_array($test) || count($test) != 2)
                    return null;
            } else if (!is_scalar($test)) {
                return null;
            }
        }

        switch ($filter) {
            case Table::FILTER_LIKE:
                return $real !== null && strpos($real, $test) !== false;
            case Table::FILTER_EQUAL:
                return $real !== null && $test == $real;
            case Table::FILTER_BETWEEN:
                if ($real === null)
                    return false;
                if ($test[0] !== null && $real < $test[0])
                    return false;
                if ($test[1] !== null && $real > $test[1])
                    return false;
                return true;
            case Table::FILTER_NULL:
                return $real === null;
            default:
                throw new \Exception("Unknown filter: $filter");
        }

        return false;
    }
510667
public function addFilter(FilterInterface $filter, $priority = 0)
	{
		if ( ! $filter instanceof FrameFilterInterface && ! $filter instanceof AudioFilterInterface)
		{
			throw new InvalidFilterException('Filter type is not supported.');
		}
		
		if ($priority > 99)
		{
			throw new \RangeException('Priority should be in the range from 0 to 99.');
		}
		
		$this->filters->insert($filter, $priority);
		
		return $this;
	}
280014
public static function orderBy($col = 'id', $type='asc')
    {
        try {
            self::init();
            $query = 'SELECT * FROM ' . self::$modelTable . ' ORDER BY '.$col. ' '.$type;
            return new QueryBuilder(self::$connect, $query);

        } catch (\Exception $exception) {
            var_dump($exception->getMessage());
        }
    }
213003
private function resolveFilterType(Filter\FilterTypeInterface $type)
    {
        $typeExtensions = [];
        $parentType = $type->getParent();
        $class = get_class($type);

        foreach ($this->extensions as $extension) {
            $typeExtensions = array_merge(
                $typeExtensions,
                $extension->getFilterTypeExtensions($class)
            );
        }

        return $this->resolvedTypeFactory->createResolvedFilterType(
            $type,
            $typeExtensions,
            $parentType ? $this->getFilterType($parentType) : null
        );
    }
333220
public function findByFilter(Filter $filter, $limit = null, $offset = 0, $order = null)
    {
        return $this->findByCriteria($filter->getCriteria(), $limit, $offset, $order);
    }