3
namespace TSEP\Bundle\AdminBundle\Controller;
5
use Xaav\QueueBundle\JobQueue\Provider\FlatFileProvider;
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Symfony\Component\HttpFoundation\Response;
9
use TSEP\Bundle\AdminBundle\Job\ProcessIndexingRequestJob;
10
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
12
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
13
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
14
use TSEP\Bundle\SearchBundle\Entity\Profile;
15
use TSEP\Bundle\AdminBundle\Form\ProfileType;
20
* @Route("/admin/profile")
22
class ProfileController extends Controller
25
* Lists all Profile entities.
27
* @Route("/", name="admin_profile")
30
public function indexAction()
32
$em = $this->getDoctrine()->getEntityManager();
34
$entities = $em->getRepository('TSEPSearchBundle:Profile')->findAll();
36
return array('entities' => $entities);
40
* Finds and displays a Profile entity.
42
* @Route("/{id}/show", name="admin_profile_show")
45
public function showAction($id)
47
$em = $this->getDoctrine()->getEntityManager();
49
$entity = $em->getRepository('TSEPSearchBundle:Profile')->find($id);
52
throw $this->createNotFoundException('Unable to find Profile entity.');
55
$deleteForm = $this->createDeleteForm($id);
59
'delete_form' => $deleteForm->createView(),
64
* Displays a form to create a new Profile entity.
66
* @Route("/new", name="admin_profile_new")
69
public function newAction()
71
$entity = new Profile();
72
$form = $this->createForm(new ProfileType(), $entity);
76
'form' => $form->createView()
81
* Creates a new Profile entity.
83
* @Route("/create", name="admin_profile_create")
85
* @Template("TSEPAdminBundle:Profile:new.html.twig")
87
public function createAction()
89
$entity = new Profile();
90
$request = $this->getRequest();
91
$form = $this->createForm(new ProfileType(), $entity);
93
if ('POST' === $request->getMethod()) {
94
$form->bindRequest($request);
96
if ($form->isValid()) {
97
$em = $this->getDoctrine()->getEntityManager();
98
$em->persist($entity);
101
return $this->redirect($this->generateUrl('admin_profile_show', array('id' => $entity->getId())));
108
'form' => $form->createView()
113
* Displays a form to edit an existing Profile entity.
115
* @Route("/{id}/edit", name="admin_profile_edit")
118
public function editAction($id)
120
$em = $this->getDoctrine()->getEntityManager();
122
$entity = $em->getRepository('TSEPSearchBundle:Profile')->find($id);
125
throw $this->createNotFoundException('Unable to find Profile entity.');
128
$editForm = $this->createForm(new ProfileType(), $entity);
129
$deleteForm = $this->createDeleteForm($id);
133
'edit_form' => $editForm->createView(),
134
'delete_form' => $deleteForm->createView(),
139
* Edits an existing Profile entity.
141
* @Route("/{id}/update", name="admin_profile_update")
143
* @Template("TSEPAdminBundle:Profile:edit.html.twig")
145
public function updateAction($id)
147
$em = $this->getDoctrine()->getEntityManager();
149
$entity = $em->getRepository('TSEPSearchBundle:Profile')->find($id);
152
throw $this->createNotFoundException('Unable to find Profile entity.');
155
$editForm = $this->createForm(new ProfileType(), $entity);
156
$deleteForm = $this->createDeleteForm($id);
158
$request = $this->getRequest();
160
if ('POST' === $request->getMethod()) {
161
$editForm->bindRequest($request);
163
if ($editForm->isValid()) {
164
$em = $this->getDoctrine()->getEntityManager();
165
$em->persist($entity);
168
return $this->redirect($this->generateUrl('admin_profile_edit', array('id' => $id)));
174
'edit_form' => $editForm->createView(),
175
'delete_form' => $deleteForm->createView(),
180
* Deletes a Profile entity.
182
* @Route("/{id}/delete", name="admin_profile_delete")
185
public function deleteAction($id)
187
$form = $this->createDeleteForm($id);
188
$request = $this->getRequest();
190
if ('POST' === $request->getMethod()) {
191
$form->bindRequest($request);
193
if ($form->isValid()) {
194
$em = $this->getDoctrine()->getEntityManager();
195
$entity = $em->getRepository('TSEPSearchBundle:Profile')->find($id);
198
throw $this->createNotFoundException('Unable to find Profile entity.');
201
$em->remove($entity);
206
return $this->redirect($this->generateUrl('admin_profile'));
209
private function createDeleteForm($id)
211
return $this->createFormBuilder(array('id' => $id))
212
->add('id', 'hidden')
218
* @Route("/{id}/index", name="admin_profile_startIndexer")
220
public function startIndexerAction($id)
222
$em = $this->getDoctrine()->getEntityManager();
223
$profile = $em->getRepository('TSEPSearchBundle:Profile')->findOneById($id);
224
$provider = new FlatFileProvider($this->get('kernel')->getCacheDir());
225
$queue = $provider->getJobQueueByName('indexingRequests');
226
$this->get('logger')->debug($profile);
227
$queue->addJobToQueue(new ProcessIndexingRequestJob($profile));
229
return new RedirectResponse($this->generateUrl('admin_processQueue', array('queue' => 'indexingRequests')));