public function listAction(Request $request, $sort)
{
$format = $request->getRequestFormat();
if (!array_key_exists($sort, $this->sortFields)) {
$msg = sprintf('%s is not a valid sorting field', $sort);
if ('json' === $format) {
return new JsonResponse(array('status' => 'error', 'message' => $msg), 406);
}
throw new HttpException(406, $msg);
}
$sortField = $this->sortFields[$sort];
$query = $this->getRepository('Bundle')->queryAllWithOwnersAndContributorsSortedBy($sortField);
$paginator = $this->getPaginator($query, $request->query->get('page', 1), $request->query->get('limit', 10));
if ('json' === $format) {
$result = array('results' => array(), 'total' => $paginator->getNbResults());
/* @var $bundle Bundle */
foreach ($paginator as $bundle) {
$result['results'][] = $bundle->toSmallArray() + array('url' => $this->generateUrl('bundle_show', array('ownerName' => $bundle->getOwnerName(), 'name' => $bundle->getName()), true), 'composerName' => $bundle->getComposerName());
}
if ($paginator->hasPreviousPage()) {
$result['prev'] = $this->generateUrl('bundle_list', array('sort' => $sort, 'page' => $paginator->getPreviousPage(), 'limit' => $request->query->get('limit'), '_format' => 'json'), true);
}
if ($paginator->hasNextPage()) {
$result['next'] = $this->generateUrl('bundle_list', array('sort' => $sort, 'page' => $paginator->getNextPage(), 'limit' => $request->query->get('limit'), '_format' => 'json'), true);
}
return new JsonResponse($result);
}
$this->highlightMenu('bundles');
$developers = $this->getRepository('Developer')->findAllSortedBy('createdAt', 20);
$activities = $this->getRepository('Activity')->findAllSortedBy('createdAt', 10);
$graphPeriod = $this->container->getParameter('knp_bundles.bundle.graph.main_page.period');
$response = $this->render('KnpBundlesBundle:Bundle:list.html.twig', array('series' => array(array('name' => 'New bundles', 'data' => $this->getRepository('Bundle')->getEvolutionCounts($graphPeriod))), 'bundles' => $paginator, 'developers' => $developers, 'activities' => $activities, 'sort' => $sort, 'sortLegends' => $this->sortLegends));
// caching
$response->setPublic();
$response->setSharedMaxAge(600);
return $response;
}