Commit 26353ba1 authored by Mat's avatar Mat

wip.. AssoBundle + APIBundle, controller paginate sur l'entité Membre

parent 9f71a0b5
<?php
namespace APIBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use AssoBundle\Entity\Membre;
class MembreAPIController extends MasterAPIController
{
/**
* @param Request
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function readPaginateAction(Request $request)
{
// defaults
$paginate = ($request->query->get('step') !== null) ? $request->query->get('step') : 10;
$start = ($request->query->get('start') !== null) ? $request->query->get('start') : 1;
$column = ($request->query->get('column') !== null) ? $request->query->get('column') : 'id';
$order = ($request->query->get('order') !== null) ? $request->query->get('order') : 'ASC';
$em = $this->getDoctrine()->getManager();
$membres = $em->getRepository('AssoBundle:Membre')
->findAllForAPIReadPaginate($paginate, $start, $column, $order);
return $this->api($membres);
}
}
......@@ -77,6 +77,16 @@ api_image_delete_one:
requirements:
id: \d+
methods: [ DELETE ]
## MembreAPI
api_membre_read_paginate:
path: /membres/page
defaults:
_controller: APIBundle:MembreAPI:readPaginate
methods: [ GET ]
##
## Note:
##
......
......@@ -2,6 +2,7 @@
namespace AssoBundle\Repository;
/**
* MembreRepository
*
......@@ -75,4 +76,40 @@ class MembreRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getSingleResult();
}
/**
* @param $paginate
* @param $start
* @param $column
* @param $order
* @return Membre[]
*/
public function findAllForAPIReadPaginate($paginate, $start, $column = null, $order = null)
{
// $dql = "SELECT m FROM AssoBundle\Entity\Membre m
// ORDER BY m.:column :order LIMIT :start, :paginate ";
// $query = $this->getEntityManager()
// ->createQuery($dql)
// ->setParameters(array(
// ':column' => $column,
// ':order' => $order,
// ':start' => (($start - 1) * $paginate),
// ':paginate' => $paginate
// ));
// return $query->getResult();
//->add('orderBy', new Expr\OrderBy('m.:column', ':order'))
$qb = $this->createQueryBuilder('m');
$qb ->add('orderBy', 'm.:column :order')
->setParameters(array(
':column' => $column,
':order' => $order
));
$qb ->setMaxResults($paginate)
->setFirstResult(($start - 1) * $paginate);
return $qb->getQuery()->getResult();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment