src/Controller/ProfileController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Product;
  4. use App\Entity\Sizes;
  5. use App\Entity\User;
  6. use App\Form\AddProductType;
  7. use App\Form\RegistrationFormBuyerType;
  8. use App\Form\RegistrationStepTwoType;
  9. use App\Repository\IndividualProductsRepository;
  10. use App\Services\IndividualProductService;
  11. use App\Services\MasterService;
  12. use App\Repository\OrderRepository;
  13. use App\Services\OrderService;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Doctrine\ORM\Mapping\Entity;
  16. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\HttpFoundation\JsonResponse;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\Mime\Address;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. class ProfileController extends AbstractController
  24. {
  25.     #[Route('/profile/info'name'profile_info')]
  26.     public function info(Request $requestEntityManagerInterface $entityManager): Response
  27.     {
  28.         /** @var User $user */
  29.         $user $this->getUser();
  30.         if ($user->getStatus() === User::STATUS_USER_STEP_REGISTRATION_2) {
  31.             $formSellerStepTwo $this->createForm(RegistrationStepTwoType::class, $user);
  32.             $formSellerStepTwo->handleRequest($request);
  33.             if ($formSellerStepTwo->isSubmitted() && $formSellerStepTwo->isValid()) {
  34.                 // encode the plain password
  35.                 $user->setAboutMe($formSellerStepTwo->get('aboutMe')->getData());
  36.                 $user->setWebsite($formSellerStepTwo->get('website')->getData());
  37.                 $user->setStatus(User::STATUS_USER_STEP_REGISTRATION_3);
  38.                 $entityManager->persist($user);
  39.                 $entityManager->flush();
  40.                 // do anything else you need here, like send an email
  41.                 return $this->redirectToRoute('profile_info');
  42.             }
  43.             return $this->render('profile/registration_step_two.html.twig', [
  44.                 'registrationStepTwo' => $formSellerStepTwo->createView(),
  45.             ]);
  46.         } else if ($user->getStatus() === User::STATUS_USER_STEP_REGISTRATION_3) {
  47.             return $this->render('profile/info.html.twig', [
  48.                 'registrationStep' => User::STATUS_USER_STEP_REGISTRATION_3,
  49.                 'user' => $user
  50.             ]);
  51.         } else if ($user->getStatus() === User::STATUS_USER_STEP_REGISTRATION_3_MODERATOR_VIEW) {
  52.             return $this->render('profile/info.html.twig', [
  53.                 'registrationStep' => User::STATUS_USER_STEP_REGISTRATION_3_MODERATOR_VIEW,
  54.                 'user' => $user
  55.             ]);
  56.         } else if ($user->getStatus() === User::STATUS_USER_STEP_REGISTRATION_3_MODERATOR_DECLINE) {
  57.             return $this->render('profile/info.html.twig', [
  58.                 'registrationStep' => User::STATUS_USER_STEP_REGISTRATION_3_MODERATOR_DECLINE,
  59.                 'user' => $user
  60.             ]);
  61.         } else {
  62.             return $this->render('profile/info.html.twig', [
  63.                 'registrationStep' => User::STATUS_USER_READY,
  64.                 'user' => $user
  65.             ]);
  66.         }
  67.     }
  68.     #[Route('/profile/info/changeAvatar'name'profile_info_change_avatar')]
  69.     public function changeAvatar(EntityManagerInterface $entityManagerRequest $request)
  70.     {
  71.         $user $this->getUser();
  72.         $masterService = new MasterService();
  73.         $masterService->changeUserAvatar($entityManager$request$user);
  74.         return new Response(''Response::HTTP_OK);
  75.     }
  76.     #[Route('/profile/products'name'profile_products')]
  77.     public function products(EntityManagerInterface $entityManager): Response
  78.     {
  79.         $userId $this->getUser()->getId();
  80.         $products $entityManager->getRepository(Product::class)->findBy(['seller' => $userId]);
  81.         return $this->render('profile/products.html.twig', [
  82.             'controller_name' => 'ProfileController',
  83.             'products' => $products
  84.         ]);
  85.     }
  86.     #[Route('/profile/products/stop_sale'name'stop_sale'methods'GET')]
  87.     public function stopSale(Request $requestEntityManagerInterface $entityManager): Response
  88.     {
  89.         $productId $request->query->get('product');
  90.         /** @var Product $product */
  91.         $product $entityManager->getRepository(Product::class)->find($productId);
  92.         $product->getStatus() === Product::STATUS_PRODUCTS_ACTUAL $product->setStatus(Product::STATUS_PRODUCTS_NOT_ACTUAL) : $product->setStatus(Product::STATUS_PRODUCTS_ACTUAL);
  93.         $entityManager->flush();
  94.         return $this->redirectToRoute('profile_products');
  95.     }
  96.     #[Route('/profile/myOrders'name'seller_orders')]
  97.     public function orders(OrderRepository $orderRepository)
  98.     {
  99.         $userId $this->getUser()->getId();
  100.         $data $orderRepository->findSellerOrders($userId);
  101.         $orders = (new OrderService())->prepareOrderDataForSellerTemplate($data);
  102.         return $this->render('profile/orders.html.twig', [
  103.             'orders' => $orders
  104.         ]);
  105.     }
  106.     #[Route('/profile/products/addProduct'name:'seller_add_product')]
  107.     public function addProduct(EntityManagerInterface $entityManagerRequest $request)
  108.     {
  109.         $user $this->getUser();
  110.         $sizes $entityManager->getRepository(Sizes::class)->findAll();
  111.         $masterService = new MasterService();
  112.         $form $this->createForm(AddProductType::class);
  113.         $result $masterService->addNewProduct($entityManager$request$form$user);
  114.         if ($result instanceof JsonResponse)
  115.             return $result;
  116.         return $this->render('profile/addProduct.html.twig', [
  117.                 "form" => $form->createView(),
  118.                 "sizes" => $sizes,
  119.                 "newProduct" => true
  120.             ]
  121.         );
  122.     }
  123.     #[Route('/profile/products/addCustomSize'name'seller_add_customSize')]
  124.     public function addCustomSize(EntityManagerInterface $entityManager,Request $request)
  125.     {
  126.         $masterService = new MasterService();
  127.         $result $masterService->addNewSize($entityManager$request);
  128.         if ($result) {
  129.             return $this->redirectToRoute('addProduct');
  130.         }
  131.         return $this->render('profile/addCustomSize.html.twig');
  132.     }
  133.     #[Route('/profile/changeProduct/{productId}'name'seller_product_change')]
  134.     public function changeProduct(EntityManagerInterface $entityManagerstring $productIdRequest $request): JsonResponse|Response
  135.     {
  136.         $user $this->getUser();
  137.         $sizes $entityManager->getRepository(Sizes::class)->findAll();
  138.         $masterService = new MasterService();
  139.         $product $entityManager->getRepository(Product::class)->find($productId);
  140.         $form $this->createForm(AddProductType::class, $product);
  141.         if ($masterService->changeProduct($entityManager$request$form$user$productId))
  142.             return new JsonResponse(['success' => 'Товар успешно изменен']);
  143.         return $this->render('profile/addProduct.html.twig', [
  144.                 "form" => $form->createView(),
  145.                 "sizes" => $sizes,
  146.                 "newProduct" => false
  147.             ]
  148.         );
  149.     }
  150.     #[Route('/profile/individualProducts'name'seller_individual_products')]
  151.     public function showIndividualProducts(IndividualProductsRepository $individualProductsRepository): Response
  152.     {
  153.         $userId $this->getUser()->getId();
  154.         $iProducts $individualProductsRepository->getSellerIndividualProducts($userId);
  155.         return $this->render('profile/individual_products.html.twig', [
  156.             'iProducts' => $iProducts
  157.         ]);
  158.     }
  159.     #[Route('/profile/acceptIndividualProduct/{iProductId}'name'seller_individual_products_accept')]
  160.     public function acceptIndividualProduct(EntityManagerInterface $entityManagerstring $iProductId): Response
  161.     {
  162.         $user $this->getUser();
  163.         $iProductService = new IndividualProductService();
  164.         $iProductService->acceptIndividualProduct($entityManager$user$iProductId);
  165.         return $this->redirectToRoute('seller_individual_products');
  166.     }
  167.     #[Route('/profile/completeIndividualProduct/{iProductId}'name'seller_individual_products_complete')]
  168.     public function completeIndividualProduct(EntityManagerInterface $entityManagerstring $iProductId): Response
  169.     {
  170.         $user $this->getUser();
  171.         $iProductService = new IndividualProductService();
  172.         $iProductService->completeIndividualProduct($entityManager$user$iProductId);
  173.         return $this->redirectToRoute('seller_individual_products');
  174.     }
  175. }