Created
July 2, 2015 02:13
-
-
Save LewisGet/2d6d6f76c1bce47c77a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
class ItemGroupController extends Controller | |
{ | |
/** | |
* Lists all ItemGroup entities. | |
* | |
* @Route("/", name="api_itemgroup") | |
* @Method("GET") | |
* @Template() | |
*/ | |
public function indexAction() | |
{ | |
/** | |
* @var \Doctrine\ORM\EntityManager | |
*/ | |
$em = $this->getDoctrine()->getManager(); | |
$sql = <<<SQL | |
select | |
itemgroup.`id` as `id`, | |
itemgroup.`name` as `name`, | |
itemgroup.`type` as `type`, | |
concat('[', group_concat(groupmapper.item_id separator ','), ']') as `items` | |
from item_group as itemgroup | |
left join item_group_mapper as groupmapper on itemgroup.id = groupmapper.group_id | |
group by itemgroup.id | |
SQL; | |
$q = $em->getConnection()->executeQuery($sql); | |
$groups = $q->fetchAll(); | |
return new JsonResponse(array( | |
'entities' => $groups, | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment