-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQuickLinkController.php
More file actions
165 lines (143 loc) · 4.3 KB
/
Copy pathQuickLinkController.php
File metadata and controls
165 lines (143 loc) · 4.3 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
namespace Bigfoot\Bundle\CoreBundle\Controller;
use Bigfoot\Bundle\CoreBundle\Entity\QuickLink;
use Bigfoot\Bundle\CoreBundle\Form\QuickLinkType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* QuickLink Controller
* @Route("/quicklink")
*/
class QuickLinkController extends CrudController
{
protected function getName()
{
return 'admin_quicklink_form';
}
/**
* Must return the entity full name (eg. BigfootCoreBundle:Tag).
*
* @return string
*/
protected function getEntity()
{
return 'BigfootCoreBundle:QuickLink';
}
/**
* Must return an associative array field name => field label.
*
* @return array
*/
protected function getFields()
{
return array(
'id' => 'ID',
'linkLabel' => 'linkLabel'
);
}
protected function getFormType()
{
return QuickLinkType::class;
}
/**
* QuickLink Widget
*
* @Route("/widget", name="admin_quicklink_widget")
* @Template("BigfootCoreBundle:quicklink:quicklink.widget.html.twig")
*/
public function quickLinkWidgetAction()
{
$em = $this->getEntityManager();
$quickLinks = $em->getRepository('BigfootCoreBundle:QuickLink')->findBy(array(),array('id' => 'desc'));
return array(
'quicklinks' => $quickLinks
);
}
/**
* QuickLink Star
*
* @Route("/star/{currentRoute}", name="admin_quicklink_star")
* @Template("BigfootCoreBundle:quicklink:quicklink.star.html.twig")
*/
public function quickLinkStarAction($currentRoute)
{
$em = $this->getEntityManager();
$quickLink = $em->getRepository('BigfootCoreBundle:QuickLink')->findOneByLink($currentRoute);
$alreadyQuickLink = false;
if ($quickLink) {
$alreadyQuickLink = true;
}
return array(
'alreadyQuickLink' => $alreadyQuickLink
);
}
/**
* QuickLink form.
*
* @Route("/", name="admin_quicklink_form")
* @Template("BigfootCoreBundle:quicklink:quicklink.form.html.twig")
*/
public function quickLinkFormAction()
{
$form = $this->createForm(QuickLinkType::class, new QuickLink());
return array(
'formQuickLink' => $form->createView()
);
}
/**
* QuickLink form.
*
* @Route("/new", name="admin_quicklink_form_new")
* @Template("BigfootCoreBundle:quicklink:popin.quicklink.html.twig")
* @param Request $request
* @return array|RedirectResponse
*/
public function newAction(Request $request)
{
$arrayNew = $this->doNew($request);
$arrayNew['isAjax'] = true;
$arrayNew['modal_title'] = 'bigfoot_core.quick_link.modal.title';
return $arrayNew;
}
/**
* Creates a new QuickLink entity.
*
* @Route("/create", name="admin_quicklink_form_create")
* @Method("POST")
* @Template("BigfootCoreBundle:quicklink:popin.quicklink.html.twig")
*/
public function createAction(Request $request)
{
$entity = new QuickLink();
$form = $this->container->get('form.factory')->create($this->getFormType(), $entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->container->get('doctrine')->getManager();
$em->persist($entity);
$em->flush();
return new JsonResponse(array(
'success' => true
));
}
return new JsonResponse(array(
'success' => false,
'errors' => 'Form is invalid',
));
}
/**
* Deletes a QuickLink entity.
*
* @Route("/delete/{id}", name="admin_quicklink_delete")
* @Method("GET|DELETE")
*/
public function deleteAction(Request $request, $id)
{
return $this->doDelete($request, $id);
}
}