Controlador:
Código PHP:
public function filtrosAction(Request $request)
{
$request = $this->container->get('request');
$data = $request->request->all();
$color = $data['form']['color'];
$tipo = $data['form']['tipo'];
$expansion = $data['form']['expansion'];
$form = $this->formBusqueda($color, $tipo, $expansion);
$em = $this->getDoctrine()->getManager();
if($color == "10" && $tipo == "12")
$cartas = $em->getRepository('CartasBundle:Cartas')
->findExpansionCarta($expansion);
elseif($color == "10")
$cartas = $em->getRepository('CartasBundle:Cartas')
->findTipoCarta($tipo, $expansion);
elseif($tipo == "12")
$cartas = $em->getRepository('CartasBundle:Cartas')
->findColorCarta($color, $expansion);
else
$cartas = $em->getRepository('CartasBundle:Cartas')
->findCarta($color, $tipo, $expansion);
$expansion = $em->getRepository('CartasBundle:Expansion')
->findExpansion($expansion);
return $this->render('CartasBundle:Default:portada.html.twig', array(
'cartas' => $cartas,
'expansion' => $expansion,
'form' => $form->createView()
));
Consulta:
Código PHP:
public function findCarta($color, $tipo, $expansion)
{
$em = $this->getEntityManager();
$dql = 'SELECT c, t, r, e
FROM CartasBundle:Cartas c
JOIN c.tipo t JOIN c.color r JOIN c.expansion e
WHERE t.id = :tipo
AND r.id = :color
AND e.id = :expansion
ORDER BY c.nombre ASC';
$consulta = $em->createQuery($dql);
$consulta->setParameter('color', $color);
$consulta->setParameter('tipo', $tipo);
$consulta->setParameter('expansion', $expansion);
return $consulta->getResult();
}