Skip to content

Instantly share code, notes, and snippets.

@gkalyan
Created November 20, 2012 09:07
Show Gist options
  • Save gkalyan/4116866 to your computer and use it in GitHub Desktop.
Save gkalyan/4116866 to your computer and use it in GitHub Desktop.
List Entities Action
public function listEntitiesAction(Request $request)
{
$entity = $request->query->get('entity');
$table = $request->query->get('table');
$repository = $this->getDoctrine()->getRepository('AALCOCompanyBundle:' . $entity);
$metadata = $this->getDoctrine()->getEntityManager()->getClassMetadata('AALCOCompanyBundle:' . $entity);
$qb = $repository->createQueryBuilder($table);
$dataTable = new Datatable(
$request->query->all(),
$repository,
$metadata,
$this->getDoctrine()->getEntityManager(),
$qb
);
if ($entity == 'Branch') { $dataTable->setJoinType('parent.branch_name', Datatable::JOIN_LEFT); }
if ($entity == 'User') { $dataTable->setJoinType('parent.full_name', Datatable::JOIN_LEFT); }
$dataTable->makeSearch();
$view = $this->view($dataTable->getSearchResults(), 200)
->setFormat('json')
;
return $this->get('fos_rest.view_handler')->handle($view);
}
public function __construct(array $request, EntityRepository $repository,
ClassMetadata $metadata, EntityManager $em, QueryBuilder $qb)
{
$this->em = $em;
$this->request = $request;
$this->repository = $repository;
$this->metadata = $metadata;
$this->tableName = Container::camelize($metadata->getTableName());
$this->defaultJoinType = self::JOIN_INNER;
$this->setParameters();
$this->qb = $qb;
$this->echo = $this->request['sEcho'];
$this->search = $this->request['sSearch'];
$this->offset = $this->request['iDisplayStart'];
$this->amount = $this->request['iDisplayLength'];
}
request: Doctrine\ORM\Query\QueryException: [Semantical Error] line 0, col 356 near 'Branches INNER': Error: 'Branches' is already defined. (uncaught exception) at /media/sf_sandbox/aalcodev/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment