PHP code example of bartlomiejbeta / filter-sorter-bundle

1. Go to this page and download the library: Download bartlomiejbeta/filter-sorter-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bartlomiejbeta / filter-sorter-bundle example snippets


public function registerBundles()
{
    $bundles = array(
        // ...
        new BartB\FilterSorterBundle\FilterSorterBundle(),
    );
}

class CarRepository extends AbstractEntitySpecificationAwareRepository
{
}

$carCollectionFilter = (new CarCollectionFilter())->setGearboxType('automatic');

$carSorter     = new CarSort(CarSort::FUEL_TYPE);
$sortDirection = new SortDirectionType(SortDirectionType::DESC);
		
/** @var FilterQueryManager $filterQueryManager */
$filterQueryManager = $this->filterQueryManager;
$carRepository      = $this->repostioryCar;
$sort 	            = new Sort($sortDirection, $carSorter);
$limit              = new Limit(1);

$basicRepositoryDTO = new BasicRepositoryDTO($carRepository);
$queryAttributesDTO = new QueryAttributesDTO($carCollectionFilter, $sort, $limit);

$queryBuilder = $filterQueryManager->getQueryBuilder($basicRepositoryDTO, $queryAttributesDTO);
$query        = $queryBuilder->getQuery();
$result       = $query->execute();