Skip to content

Instantly share code, notes, and snippets.

@LewisGet
Created July 2, 2015 02:13
Show Gist options
  • Save LewisGet/2d6d6f76c1bce47c77a4 to your computer and use it in GitHub Desktop.
Save LewisGet/2d6d6f76c1bce47c77a4 to your computer and use it in GitHub Desktop.
<?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