|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Advert; |
|
6
|
|
|
use App\Entity\Application; |
|
7
|
|
|
use App\Entity\User; |
|
8
|
|
|
use App\Form\AccountType; |
|
9
|
|
|
use App\Form\CurriculumType; |
|
10
|
|
|
use App\Repository\ApplicationRepository; |
|
11
|
|
|
use App\Service\FileUploader; |
|
12
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
13
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
16
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\File\Exception\FileException; |
|
18
|
|
|
|
|
19
|
|
|
class AccountController extends AbstractController |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @Route("/account/cv/{id}", name="add_cv") |
|
23
|
|
|
*/ |
|
24
|
|
|
public function curriculum(Request $request, $id, FileUploader $fileUploader) |
|
25
|
|
|
{ |
|
26
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
27
|
|
|
$user = $em->getRepository(User::class)->find($id); |
|
28
|
|
|
//dump($user);die(); |
|
29
|
|
|
|
|
30
|
|
|
$form = $this->createForm(CurriculumType::class, $user); |
|
31
|
|
|
$form->handleRequest($request); |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
35
|
|
|
// $file stores the uploaded PDF file |
|
36
|
|
|
/** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */ |
|
37
|
|
|
$file = $form->get('curriculum')->getData(); |
|
38
|
|
|
$fileName = $fileUploader->upload($file); |
|
39
|
|
|
|
|
40
|
|
|
$user->setCurriculum($fileName); |
|
41
|
|
|
|
|
42
|
|
|
$em->persist($user); |
|
43
|
|
|
$em->flush(); |
|
44
|
|
|
|
|
45
|
|
|
$this->addFlash('success', 'Votre CV a été téléchargé'); |
|
46
|
|
|
return $this->redirectToRoute('account', ['id' => $user->getId()]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $this->render('account/cv.html.twig', [ |
|
50
|
|
|
'cvForm' => $form->createView(), |
|
51
|
|
|
]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @Route("/account/cv/edit/{id}", name="edit_cv") |
|
56
|
|
|
*/ |
|
57
|
|
|
public function editCurriculum(Request $request, $id, FileUploader $fileUploader) |
|
58
|
|
|
{ |
|
59
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
60
|
|
|
$user = $em->getRepository(User::class)->find($id); |
|
61
|
|
|
//dump($user);die(); |
|
62
|
|
|
|
|
63
|
|
|
$form = $this->createForm(CurriculumType::class, $user); |
|
64
|
|
|
$form->handleRequest($request); |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
68
|
|
|
// $file stores the uploaded PDF file |
|
69
|
|
|
/** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */ |
|
70
|
|
|
$file = $form->get('curriculum')->getData(); |
|
71
|
|
|
; |
|
72
|
|
|
$fileName = $fileUploader->upload($file); |
|
73
|
|
|
|
|
74
|
|
|
$user->setCurriculum($fileName); |
|
75
|
|
|
|
|
76
|
|
|
$em->persist($user); |
|
77
|
|
|
$em->flush(); |
|
78
|
|
|
|
|
79
|
|
|
$this->addFlash('success', 'Votre CV a été téléchargé'); |
|
80
|
|
|
return $this->redirectToRoute('account', ['id' => $user->getId()]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $this->render('account/cv_edit.html.twig', [ |
|
84
|
|
|
'cvForm' => $form->createView(), |
|
85
|
|
|
]); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
private function generateUniqueFileName() |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
// md5() reduces the similarity of the file names generated by |
|
94
|
|
|
// uniqid(), which is based on timestamps |
|
95
|
|
|
return md5(uniqid()); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @Route("/account/{id}", name="account") |
|
100
|
|
|
*/ |
|
101
|
|
|
public function view($id, Request $request, ObjectManager $manager) |
|
102
|
|
|
{ |
|
103
|
|
|
$user = $this->getDoctrine()->getRepository(User::class)->find($id); |
|
104
|
|
|
if (null === $user) { |
|
105
|
|
|
throw new NotFoundHttpException("L'utilisateur ".$id." n'existe pas"); |
|
106
|
|
|
} |
|
107
|
|
|
//dump($this->getUser()->getEmail());die(); |
|
108
|
|
|
if ($user->getEmail() === $this->getUser()->getEmail()) { |
|
109
|
|
|
$form = $this->createForm(AccountType::class, $user); |
|
110
|
|
|
$form->handleRequest($request); |
|
111
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
112
|
|
|
$user->setEmail($this->getUser()->getEmail()); |
|
113
|
|
|
$manager->persist($user); |
|
114
|
|
|
$manager->flush(); |
|
115
|
|
|
$this->addFlash( |
|
116
|
|
|
'notice', |
|
117
|
|
|
'Votre compte a bien été modifié!' |
|
118
|
|
|
); |
|
119
|
|
|
dump($request); |
|
|
|
|
|
|
120
|
|
|
die(); |
|
|
|
|
|
|
121
|
|
|
return $this->redirectToRoute('account', ['id' => $user->getId()]); |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
return $this->render('account/index.html.twig', [ |
|
124
|
|
|
'user' => $user, |
|
125
|
|
|
'formAccount' => $form->createView() |
|
126
|
|
|
]); |
|
127
|
|
|
} else { |
|
128
|
|
|
$this->addFlash('warning', 'Vous ne pouvez pas accéder à cette page !'); |
|
129
|
|
|
return $this->redirectToRoute('home'); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @Route("/account/myadverts/{id}", name="my_adverts") |
|
135
|
|
|
*/ |
|
136
|
|
|
public function myAdverts($id) |
|
|
|
|
|
|
137
|
|
|
{ |
|
138
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
|
|
|
|
|
139
|
|
|
$adverts = $this->getDoctrine()->getRepository(Advert::class)->findByAuthor($this->getUser()); |
|
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
return $this->render('account/myadverts.html.twig', [ |
|
142
|
|
|
'adverts' => $adverts |
|
143
|
|
|
]); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @Route("/account/myadvert/applications/{id}", name="list_applications") |
|
148
|
|
|
*/ |
|
149
|
|
|
public function ApplicationsByAdvert($id) |
|
150
|
|
|
{ |
|
151
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
152
|
|
|
$advert = $this->getDoctrine()->getRepository(Advert::class)->find($id); |
|
153
|
|
|
|
|
154
|
|
|
$listApplications = $em |
|
155
|
|
|
->getRepository(Application::class) |
|
156
|
|
|
->findBy(['advert' => $advert]) |
|
157
|
|
|
; |
|
158
|
|
|
|
|
159
|
|
|
return $this->render('account/applications.html.twig', [ |
|
160
|
|
|
'advert' => $advert, |
|
161
|
|
|
'listApplications' => $listApplications |
|
162
|
|
|
]); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.