|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
10
|
|
|
use Chamilo\CoreBundle\Form\ProfileType; |
|
11
|
|
|
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository; |
|
12
|
|
|
use Chamilo\CoreBundle\Repository\Node\UserRepository; |
|
13
|
|
|
use Chamilo\CoreBundle\Traits\ControllerTrait; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
16
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
17
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class AccountController. |
|
21
|
|
|
* |
|
22
|
|
|
* @Route("/account") |
|
23
|
|
|
* |
|
24
|
|
|
* @author Julio Montoya <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class AccountController extends BaseController |
|
27
|
|
|
{ |
|
28
|
|
|
use ControllerTrait; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @Route("/edit", methods={"GET", "POST"}, name="chamilo_core_account_edit") |
|
32
|
|
|
*/ |
|
33
|
|
|
public function editAction(Request $request, UserRepository $userRepository, IllustrationRepository $illustrationRepo) |
|
34
|
|
|
{ |
|
35
|
|
|
$user = $this->getUser(); |
|
36
|
|
|
|
|
37
|
|
|
if (!is_object($user) || !$user instanceof UserInterface) { |
|
38
|
|
|
throw $this->createAccessDeniedException('This user does not have access to this section'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** @var User $user */ |
|
42
|
|
|
$form = $this->createForm(ProfileType::class, $user); |
|
43
|
|
|
$form->setData($user); |
|
44
|
|
|
$form->handleRequest($request); |
|
45
|
|
|
|
|
46
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
47
|
|
|
$illustration = $form['illustration']->getData(); |
|
48
|
|
|
if ($illustration) { |
|
49
|
|
|
$illustrationRepo->addIllustration($user, $user, $illustration); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$userRepository->updateUser($user); |
|
53
|
|
|
$this->addFlash('success', $this->trans('Updated')); |
|
54
|
|
|
$url = $this->generateUrl('chamilo_core_account_home', [ |
|
55
|
|
|
'username' => $user->getUsername(), |
|
56
|
|
|
]); |
|
57
|
|
|
|
|
58
|
|
|
return new RedirectResponse($url); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $this->render('@ChamiloCore/Account/edit.html.twig', [ |
|
62
|
|
|
'form' => $form->createView(), |
|
63
|
|
|
'user' => $user, |
|
64
|
|
|
]); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|