Created
November 20, 2012 09:07
-
-
Save gkalyan/4116866 to your computer and use it in GitHub Desktop.
List Entities Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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