I'm using Symfony 2 with Sonata Admin Bundle.
As far as i can see, Sonata Admin has only AND filtering on list action.
Use this as example:
My entity : Prodotto
/**
* Prodotto
*
* @ORM\Table()
* @ORM\Entity
* @UniqueEntity("prodotto")
*/
class Prodotto extends DefaultEntity
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
//getters - setters Zone
/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @var string
*
* @ORM\Column(name="prodotto", type="string", length=255)
*/
private $prodotto;
/**
* @var \mybundle\Entity\Tipologia
* @ORM\ManyToOne(targetEntity="Tipologia")
*/
private $tipologia;
/**
* @var \mybundle\Entity\Brand
* @ORM\JoinColumn(name="brand_id", referencedColumnName="id")
* @ORM\ManyToOne(targetEntity="Brand")
*
*/
private $brand;
/**
* @var \mybundle\Entity\Layout
* @ORM\ManyToOne(targetEntity="Layout")
* @ORM\JoinColumn(name="layout_id", referencedColumnName="id")
*/
private $layout;
/**
* @var \mybundle\Entity\Carta
* @ORM\ManyToOne(targetEntity="Carta")
* @ORM\JoinColumn(name="carta_id", referencedColumnName="id")
*/
private $carta;
//[... many other fields omitted...]
//[... Getters and setters omitted (default get/set, no custom code) ...]
My admin class: ProdottoAdmin (please note that i copied only the configuration useful for this question, the class contains all the required configurations for all the actions)
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('id')
->add('prodotto')
->add('tipologia')
->add('brand')
->add('layout')
->add('misura')
;
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('dataModifica','datetime',array('pattern' => 'dd/MM/yyyy','label'=>'Data'))
->add('tipologia')
->add('brand')
->add('layout')
->add('misura')
->add('Nome Prodotto', 'string', array('template' => 'mybundle:Admin:List/link_column_list_prodotto.html.twig'))
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
'delete' => array(),
)
))
;
}My Service Configuration (in services.yml):
services:
mybundle.admin.prodotto:
class: mybundle\Admin\ProdottoAdmin
arguments: [~, mybundle\Entity\Prodotto, mybundle:ProdottoAdmin]
tags:
- {name: sonata.admin, manager_type: orm, group: Prodotti, label: Prodotti}
With this configuration, i actually got a fully functional data grid filter, as you can see from the picture(image added for better understanding of the problem):
But, the default Sonata Admin filtering expose only an AND filter, i can add ONE time all the property of the entity and make an AND filtering with them. But, now i need to extend that functionality. I need to add an OR filter, app-wide. I want that the user can filter like "give me all the product that are related with Brand1 OR Brand2 AND are of Tipologia1."
I know i can make precise custom query, like the example above, to obtain a single result, but:
So, finally, my question is:
There is a "correct" (or at least, a raccomended) way or pattern / maybe a configurable bundle to implement that OR filtering?