fileUploader = $fileUploader; $this->profileRepo = $profileRepo; } #[Route('/profile/{uuid}', name: 'profile_view', methods: ['GET'])] public function viewProfile(string $uuid, ParticipantRepository $profileRepo): Response { $currentProfile = $profileRepo->findOneBy(['idParticipant' => $uuid]); return $this->render('profile/view.html.twig', [ 'profile' => $currentProfile, ]); } #[Route('/profile/edit/{uuid}', name: 'profile_edit', methods: ['GET', 'POST'])] public function editProfile(string $uuid, Request $request): Response { try { $profile = $this->profileRepo->findOneBy(['idParticipant' => $uuid]); if (!$profile === $this->getUser()) { $this->addFlash('error', "Vous ne pouvez pas modifier un profil qui n'est pas le votre"); return $this->redirectToRoute('profile_view',['uuid' => $profile->getIdParticipant()]); } $form = $this->createForm(RegistrationFormType::class, $profile); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $imageFile = $form->get('image')->getData(); if (($form->has('deleteImage') && $form['deleteImage']->getData()) || $imageFile) { $this->fileUploader->delete($profile->getFileName(), '/upload/image/profile'); if ($imageFile) { $imageFilename = $this->fileUploader->upload($imageFile); $profile->setFileName($imageFilename); } else { $profile->setFileName(''); } } $profileToUpdate = $this->profileRepo->update($profile); if (!$profileToUpdate) { throw $this->createNotFoundException('No profile found'); } $this->addFlash('success', 'Votre profile est bien à jour'); return $this->redirectToRoute('profile_view',['uuid' => $profile->getIdParticipant()]); } return $this->render('profile/edit.html.twig', [ 'formProfile' => $form, ]); } catch(\Exception $e) { $formProfile = $this->createForm(RegistrationFormType::class, $profile); $this->addFlash('error', $e->getMessage()); return $this->render('profile/edit.html.twig', ['formProfile' => $formProfile]); } } }