mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
wooops, that was missing.
This commit is contained in:
parent
933d0d1a01
commit
0e330653cc
2 changed files with 78 additions and 0 deletions
22
src/Sylius/Bundle/SalesBundle/Filtering/FilterInterface.php
Normal file
22
src/Sylius/Bundle/SalesBundle/Filtering/FilterInterface.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\SalesBundle\Filtering;
|
||||
|
||||
/**
|
||||
* Interface for filter.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
interface FilterInterface
|
||||
{
|
||||
function filter($filterable);
|
||||
}
|
||||
56
src/Sylius/Bundle/SalesBundle/Filtering/ORM/OrderFilter.php
Executable file
56
src/Sylius/Bundle/SalesBundle/Filtering/ORM/OrderFilter.php
Executable file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\SalesBundle\Filtering\ORM;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Sylius\Bundle\SalesBundle\Filtering\FilterInterface;
|
||||
|
||||
/**
|
||||
* Default ORM filter.
|
||||
* Filters order entities.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class OrderFilter extends ContainerAware implements FilterInterface
|
||||
{
|
||||
public function filter($filterable)
|
||||
{
|
||||
if (!$filterable instanceof QueryBuilder) {
|
||||
throw new InvalidArgumentException('Default filter supports only "Doctrine\\ORM\\QueryBuilder" as argument.');
|
||||
}
|
||||
|
||||
$request = $this->container->get('request');
|
||||
$filters = $filters = $request->query->get('filters');
|
||||
if (null == $filters || !is_array($filters)) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$orderClass = $this->container->getParameter('sylius_sales.model.order.class');
|
||||
$reflectionClass = new \ReflectionClass($orderClass);
|
||||
$properties = array_keys($reflectionClass->getDefaultProperties());
|
||||
|
||||
$i = 0;
|
||||
foreach ($filters as $property => $filter) {
|
||||
if (in_array($property, $properties) && in_array($filter[1], array('>', '<', '=', '>=', '<='))) {
|
||||
/** @var QueryBuilder */
|
||||
$filterable
|
||||
->andWhere('o.'.$property . ' ' . $filter[1] . ' :PARAM' . $i)
|
||||
->setParameter('PARAM' . $i, $filter[0])
|
||||
;
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue