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
|
<?php
namespace LIG\Bundle\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle as FrameworkBundle;
use Symfony\Component\HttpFoundation as HttpFoundation;
use LIG\Bundle\UserBundle as LIGUserBundle;
class UserController extends FrameworkBundle\Controller\Controller
{
public function listAction()
{
$em = $this->getDoctrine()->getManager();
$users = $em->getRepository('LIGUserBundle:User')->findAll();
return $this->render('LIGUserBundle:User:list.html.twig', array('users' => $users));
}
public function viewAction($id)
{
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('LIGUserBundle:User')->find($id);
if (!$user) {
throw $this->createNotFoundException('Unable to find User entity.');
}
return $this->render('LIGUserBundle:User:view.html.twig', array(
'user' => $user,
));
}
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('LIGUserBundle:User')->find($id);
if (!$user) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$editForm = $this->createEditForm($user);
return $this->render('LIGUserBundle:User:edit.html.twig', array(
'user' => $user,
'editForm' => $editForm->createView()
));
}
public function updateAction(HttpFoundation\Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('LIGUserBundle:User')->find($id);
if (!$user) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$editForm = $this->createEditForm($user);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('lig_user_user_edit', array('id' => $id)));
}
return $this->render('LIGUserBundle:User:edit.html.twig', array(
'user' => $user,
'editForm' => $editForm->createView()
));
}
public function deleteAction($id)
{
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('LIGUserBundle:User')->find($id);
if (!$user) {
throw $this->createNotFoundException('Unable to find User entity.');
}
return $this->render('LIGUserBundle:User:delete.html.twig', array(
'user' => $user,
));
}
private function createEditForm(LIGUserBundle\Entity\User $user)
{
$userDiscriminator = $this->get('pugx_user.manager.user_discriminator');
$formType = $userDiscriminator->getFormType('registration');
$formType = new \LIG\Bundle\UserBundle\Form\Entity\User\Administrator\RegistrationFormType('LIG\Bundle\UserBundle\Entity\UserAdministrator');
$editForm = $this->createForm($formType, $user, array(
'action' => $this->generateUrl('lig_user_user_update', array('id' => $user->getId())),
'method' => 'POST',
'attr' => array('novalidate' => 'novalidate'),
'validation_groups' => array('Default', 'Edit')
));
$editForm->add('submit', 'submit', array('label' => 'Update'));
return $editForm;
}
} |
Partager