ProfileController.php
4.42 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
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace UBV\AutenticacionBundle\Controller;
use FOS\UserBundle\Form\Factory\FactoryInterface;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
* Controller managing the user profile
*
* @author Christophe Coevoet <stof@notk.org>
*/
class ProfileController extends Controller
{
/**
* Show the user
*/
public function showAction()
{
$em = $this->getDoctrine()->getManager();
$user = $this->getUser();
$persona = $em->getRepository("UBVSurUbvBundle:Persona")->findArregloPersonaById($user->getId());
//die(dump($persona));
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
//$nacionalidad = $user->getPersonaNacionalidads();
//die(var_dump($nacionalidad));
return $this->render('FOSUserBundle:Profile:show.html.twig', array(
'user' => $persona
));
}
/**
* Edit the user
*
* @param Request $request
*
* @return Response
*/
public function editAction(Request $request)
{
$user = $this->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
/** @var $dispatcher EventDispatcherInterface */
$dispatcher = $this->get('event_dispatcher');
$event = new GetResponseUserEvent($user, $request);
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event);
if (null !== $event->getResponse()) {
return $event->getResponse();
}
/** @var $formFactory FactoryInterface */
$formFactory = $this->get('fos_user.profile.form.factory');
$form = $formFactory->createForm();
$form->setData($user);
$form->handleRequest($request);
if ($form->isValid()) {
/** @var $userManager UserManagerInterface */
$userManager = $this->get('fos_user.user_manager');
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);
$userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
$url = $this->generateUrl('fos_user_profile_show');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}
return $this->render('FOSUserBundle:Profile:edit.html.twig', array(
'form' => $form->createView()
));
}
public function mostrarUsuarioAction($id)
{
//die(dump($id));
//$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
//$aspirante = $em->getRepository('UBVSurUbvBundle:Aspirante')->findOneById($id);
//$nombreusuario = $aspirante->getPersona()->getUsername();
//die(dump($nombreusuario));
//$user = $this->get('fos_user.user_manager')->findUserById($id);
$persona = $em->getRepository("UBVSurUbvBundle:Persona")->findArregloPersonaById($id);
// if (!is_object($user) || !$user instanceof UserInterface) {
// throw new AccessDeniedException('This user does not have access to this section.');
// }
return $this->render('FOSUserBundle:Profile:show.html.twig', array(
'user' => $persona
));
}
}