This repository has been archived by the owner on Sep 23, 2022. It is now read-only.
/
DeveloperController.php
92 lines (71 loc) · 3 KB
/
DeveloperController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace Knp\Bundle\KnpBundlesBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Templating\EngineInterface;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Knp\Menu\MenuItem;
class DeveloperController extends BaseController
{
protected $sortFields = array(
'name' => 'name',
'best' => 'score',
);
protected $sortLegends = array(
'name' => 'developers.sort.name',
'best' => 'developers.sort.best',
);
public function userbarAction()
{
$response = $this->render('KnpBundlesBundle:Developer:userbar.html.twig');
// this is private cache (don't cache with shared proxy)
$response->setPrivate();
return $response;
}
public function showAction(Request $request, $name)
{
if (!$developer = $this->getRepository('Developer')->findOneByNameWithRepos($name)) {
throw new NotFoundHttpException(sprintf('The developer "%s" does not exist', $name));
}
$format = $this->recognizeRequestFormat($request);
$this->highlightMenu('developers');
return $this->render('KnpBundlesBundle:Developer:show.'.$format.'.twig', array(
'developer' => $developer,
'callback' => $request->query->get('callback')
));
}
public function listAction(Request $request, $sort = 'name')
{
if (!array_key_exists($sort, $this->sortFields)) {
throw new HttpException(sprintf('%s is not a valid sorting field', $sort), 406);
}
$format = $this->recognizeRequestFormat($request);
$sortField = $this->sortFields[$sort];
$this->highlightMenu('developers');
$query = $this->getRepository('Developer')->queryAllWithBundlesSortedBy($sortField);
$developers = $this->getPaginator($query, $request->query->get('page', 1), 18);
return $this->render('KnpBundlesBundle:Developer:list.'.$format.'.twig', array(
'developers' => $developers,
'sort' => $sort,
'sortLegends' => $this->sortLegends,
'callback' => $request->query->get('callback')
));
}
public function bundlesAction(Request $request, $name)
{
$format = $this->recognizeRequestFormat($request);
if ($format == 'html') {
return $this->redirect($this->generateUrl('developer_show', array('name' => $name)));
}
if (!$developer = $this->getRepository('Developer')->findOneByName($name)) {
throw new NotFoundHttpException(sprintf('The developer "%s" does not exist', $name));
}
return $this->render('KnpBundlesBundle:Bundle:list.'.$format.'.twig', array(
'bundles' => $developer->getBundles(),
'callback' => $request->query->get('callback')
));
}
}