WIP: Implement profile editing
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Common;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DownloadController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly UploadHandler $uploadHandler)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/download/{uuid}', name: 'app_common_download')]
|
||||
#[IsGranted('DOWNLOAD', subject: 'upload')]
|
||||
public function index(Upload $upload): Response
|
||||
{
|
||||
$path = $this->uploadHandler->getUploadFilepath($upload);
|
||||
$originalFilename = $upload->getOriginalFilename();
|
||||
|
||||
return $this->file($path, $originalFilename);
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class IndexController extends AbstractController
|
||||
$upload = Upload::fromUploadDto($uploadSession->getUploads()->first(), $user, Upload::TYPE_PHOTO);
|
||||
$teamer->setPhoto($upload);
|
||||
$this->entityManager->flush();
|
||||
$this->uploadHandler->moveUploadSessionFilesFromOrphanage('photo', $uploadSession);
|
||||
$this->uploadHandler->moveUploadSessionFilesFromOrphanage(Upload::TYPE_PHOTO, $uploadSession);
|
||||
$this->uploadHandler->destroyUploadSession();
|
||||
|
||||
$this->addFlash('success', 'Dein Profilbild wurde aktualisiert');
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Teamer\Profile\License;
|
||||
|
||||
use App\Entity\License;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Form\LicenseType;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use App\Model\UploadSessionDto;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class AddController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UploadHandler $uploadHandler
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/teamer/profile/license/add', name: 'app_teamer_profile_license_add')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$action = $this->generateUrl('app_teamer_profile_license_add');
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$license = new License();
|
||||
|
||||
// Handle upload independently from form submission to avoid issues with failing validation
|
||||
$uploadSession = $this->uploadHandler->getUploadSession();
|
||||
if (true === $request->isMethod('POST') && 0 < $uploadSession->getCount()) {
|
||||
$this->updateCertificate($user, $license, $uploadSession);
|
||||
}
|
||||
|
||||
$form = $this->createForm(LicenseType::class, $license, ['action' => $action, 'ajax_submit' => true, 'upload_session' => $uploadSession]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
$teamer->addLicense($license);
|
||||
|
||||
$this->entityManager->persist($license);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$redirectUrl = $this->generateUrl('app_teamer_profile_skills');
|
||||
$response->setCloseAndRedirect($redirectUrl);
|
||||
} else {
|
||||
$content = $this->renderView('teamer/profile/license/add.html.twig', [
|
||||
'form' => $form,
|
||||
]);
|
||||
$response->setContent($content);
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
|
||||
private function updateCertificate(User $user, License $license, UploadSessionDto $uploadSession): void
|
||||
{
|
||||
$upload = Upload::fromUploadDto($uploadSession->getUploads()->first(), $user, Upload::TYPE_CERTIFICATE);
|
||||
$license->setCertificate($upload);
|
||||
$this->entityManager->flush();
|
||||
$this->uploadHandler->moveUploadSessionFilesFromOrphanage(Upload::TYPE_CERTIFICATE, $uploadSession);
|
||||
$this->uploadHandler->destroyUploadSession();
|
||||
|
||||
$this->addFlash('success', 'Der Nachweis wurde hochgeladen');
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Controller\Teamer\Profile;
|
||||
|
||||
use App\Entity\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
@@ -11,8 +13,14 @@ class SkillsController extends AbstractController
|
||||
{
|
||||
#[Route('/teamer/profile/skills', name: 'app_teamer_profile_skills')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
return $this->render('teamer/profile/skills.html.twig');
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
return $this->render('teamer/profile/skills.html.twig', [
|
||||
'teamer' => $teamer,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user