gtsrc/Catalog/Controller/CustomsKeywordsController.php line 101

Open in your IDE?
  1. <?php
  2. /**
  3.  * CustomsKeywordsController.php
  4.  * Created by Giedrius Tumelis.
  5.  * Date: 2021-04-07
  6.  * Time: 12:03
  7.  */
  8. namespace Gt\Catalog\Controller;
  9. use Gt\Catalog\Exception\CatalogErrorException;
  10. use Gt\Catalog\Exception\CatalogValidateException;
  11. use Gt\Catalog\Form\CustomsKeywordsFormType;
  12. use Gt\Catalog\Services\AutoAssignCustomsNumbersByKeywordsService;
  13. use Gt\Catalog\Services\CustomsKeywordsService;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\File\UploadedFile;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. class CustomsKeywordsController  extends AbstractController
  19. {
  20.     /**
  21.      * @param Request $request
  22.      * @param CustomsKeywordsService $customsKeywordsService
  23.      * @return \Symfony\Component\HttpFoundation\Response
  24.      */
  25.     public function listAction(Request $requestCustomsKeywordsService $customsKeywordsService) {
  26.         $filterType = new CustomsKeywordsFormType();
  27.         $form $this->createForm(CustomsKeywordsFormType::class, $filterType);
  28.         $form->handleRequest($request);
  29.         $customsKeywords $customsKeywordsService->getKeywords($filterType);
  30.         return $this->render('@Catalog/customs/keywords_list.html.twig', [
  31.             'form' => $form->createView(),
  32.             'customs_keywords' => $customsKeywords,
  33.         ]);
  34.     }
  35.     /**
  36.      * @return \Symfony\Component\HttpFoundation\Response
  37.      */
  38.     public function importFormAction() {
  39.         return $this->render('@Catalog/customs/keywords_import_form.html.twig', [
  40.         ]);
  41.     }
  42.     /**
  43.      * @param Request $request
  44.      * @param CustomsKeywordsService $customsKeywordsService
  45.      * @return \Symfony\Component\HttpFoundation\Response
  46.      */
  47.     public function importAction(Request $requestCustomsKeywordsService $customsKeywordsService) {
  48.         /** @var UploadedFile $file */
  49.         $file $request->files->get('csvfile');
  50.         try {
  51.             if (empty($file)) {
  52.                 throw new CatalogErrorException('Csv file is not given!');
  53.             }
  54.             $count $customsKeywordsService->importKeywordsFromCsvFile($file->getRealPath(), $file->getClientOriginalName());
  55.             return $this->render('@Catalog/customs/keywords_import_result.html.twig', [
  56.                 'count' =>$count,
  57.             ]);
  58.         } catch (CatalogErrorException $e ) {
  59.             return $this->render('@Catalog/error/error.html.twig', [
  60.                 'error'=> $e->getMessage(),
  61.             ]);
  62.         }
  63.         catch ( CatalogValidateException $e ) {
  64.             return $this->render('@Catalog/error/error.html.twig', [
  65.                 'error'=> 'Validavimo klaida:' $e->getMessage(),
  66.             ]);
  67.         }
  68.     }
  69.     /**
  70.      * @param $id
  71.      * @param CustomsKeywordsService $customsKeywordsService
  72.      * @return Response
  73.      */
  74.     public function deleteAction($idCustomsKeywordsService $customsKeywordsService) {
  75.         try {
  76.             $customsKeywordsService->deleteKeyword($id);
  77.             return $this->redirectToRoute('gt.catalog.customs.keywords_list');
  78.         }
  79.         catch ( CatalogValidateException $e ) {
  80.             return $this->render('@Catalog/error/error.html.twig', [
  81.                 'error'=> 'Validavimo klaida:' $e->getMessage(),
  82.             ]);
  83.         }
  84.     }
  85.     /**
  86.      * @param AutoAssignCustomsNumbersByKeywordsService $autoAssignCustomsNumbersByKeywordsService
  87.      * @return Response
  88.      * @throws \Doctrine\DBAL\Exception
  89.      */
  90.     public function showAssignmentPrognoze(AutoAssignCustomsNumbersByKeywordsService $autoAssignCustomsNumbersByKeywordsService) {
  91.         $limit 100;
  92.         $data $autoAssignCustomsNumbersByKeywordsService->showUpdates($limit);
  93.         return $this->render(
  94.             '@Catalog/customs/show_keywords_assignements.html.twig',
  95.             [
  96.                 'data' => $data,
  97.                 'limit' => $limit
  98.             ]
  99.         );
  100.     }
  101. }