WIP: Implement uploads
This commit is contained in:
@@ -5,8 +5,10 @@ namespace App\Controller\Teamer;
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\ApiClientException;
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Form\TeamerProfileType;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -18,7 +20,8 @@ class ProfileController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly ApiClient $apiClient
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly UploadHandler $uploadHandler
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -36,10 +39,22 @@ class ProfileController extends AbstractController
|
||||
$this->entityManager->persist($teamer);
|
||||
}
|
||||
|
||||
$form = $this->createForm(TeamerProfileType::class, $teamer);
|
||||
$uploadSession = $this->uploadHandler->getUploadSession();
|
||||
|
||||
$form = $this->createForm(TeamerProfileType::class, $teamer, ['upload_session' => $uploadSession]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if ($uploadSession->getCount() > 0) {
|
||||
if (null !== $existingUpload = $teamer->getPhoto()) {
|
||||
$this->entityManager->remove($existingUpload);
|
||||
}
|
||||
$upload = Upload::fromUploadDto($uploadSession->getUploads()->first(), $user, Upload::TYPE_PHOTO);
|
||||
$teamer->setPhoto($upload);
|
||||
$this->uploadHandler->moveUploadSessionFilesFromOrphanage('photo', $uploadSession);
|
||||
$this->uploadHandler->destroyUploadSession();
|
||||
}
|
||||
|
||||
try {
|
||||
$bpnPassword = $request->getSession()->get('bpn_password');
|
||||
$this->apiClient->updateProfile($user, $bpnPassword);
|
||||
@@ -47,6 +62,8 @@ class ProfileController extends AbstractController
|
||||
} catch (ApiClientException $e) {
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Deine Daten wurden aktualisiert');
|
||||
|
||||
return $this->redirectToRoute('app_teamer_profile');
|
||||
@@ -54,6 +71,7 @@ class ProfileController extends AbstractController
|
||||
|
||||
return $this->render('teamer/profile.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'teamer' => $teamer,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user