src/Controller/Block/BlockController.php line 66

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Block;
  3. use App\DTO\AppDTO;
  4. use App\Entity\Cat;
  5. use App\Entity\Char;
  6. use App\Entity\Page;
  7. use App\Entity\Timer;
  8. use App\Entity\Catpage;
  9. use App\Entity\Charval;
  10. use App\Service\Filter\Filter;
  11. use App\Model\Cart as ModelCart;
  12. use App\Model\Prod as ModelProd;
  13. use App\Repository\CatRepository;
  14. use App\Repository\CharRepository;
  15. use App\Repository\PageRepository;
  16. use App\Repository\TimerRepository;
  17. use App\Repository\CatpageRepository;
  18. use App\Repository\CharvalRepository;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use Symfony\Contracts\Cache\TagAwareCacheInterface;
  24. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  25. class BlockController extends AbstractController
  26. {
  27.     protected EntityManagerInterface $em;
  28.     protected AppDTO $app;
  29.     protected ModelProd $ModelProd;
  30.     protected ModelCart $ModelCart;
  31.     //Repositories
  32.     protected PageRepository $Pages;
  33.     protected CatRepository $Cats;
  34.     protected CatpageRepository $Catpages;
  35.     protected TimerRepository $Timers;
  36.     protected CharRepository $Chars;
  37.     protected CharvalRepository $Charvals;
  38.     public function __construct(
  39.         EntityManagerInterface $em
  40.         private TagAwareCacheInterface $appCache
  41.         AppDTO $app
  42.         ModelProd $ModelProd
  43.         ModelCart $ModelCart
  44.     )
  45.     {
  46.         $this->em $em;
  47.         $this->app $app;
  48.         $this->ModelProd $ModelProd;
  49.         $this->ModelCart $ModelCart;
  50.         $this->Pages $em->getRepository(Page::class);
  51.         $this->Cats $em->getRepository(Cat::class);
  52.         $this->Catpages $em->getRepository(Catpage::class);
  53.         $this->Timers $em->getRepository(Timer::class);
  54.         $this->Chars $em->getRepository(Char::class);
  55.         $this->Charvals $em->getRepository(Charval::class);
  56.     }
  57.     
  58.     #[Route('/{_locale}/block/charsselected/{cat_id}/{cat_intname}/filter-{filters}'name'block_chars_selected'requirements: ['_locale' => '%app.langs%'])]
  59.     #[Route('/{_locale}/block/charsselected/{spec}/{cat_id}/{cat_intname}/filter-{filters}'name'block_chars_selected_spec'requirements: ['_locale' => '%app.langs%'])]
  60.     public function charsSelectedBlock(Request $requestFilter $Filterint $cat_idstring $cat_intname ''string $filters ''string $spec ''): Response
  61.     {
  62.         $chars_selected = [];
  63.         $chars_url = [];
  64.         
  65.         if ($filters) {
  66.             preg_match_all("/char(\d+)\-([\d_]+)/"$filters$m);
  67.             if (preg_match("/sale-(\w+)/"$filters$m2)) {
  68.                 $chars_selected['sale'] = $m2[1];
  69.             }
  70.             if (isset($m[1]) && count($m[1])) {
  71.                 foreach ($m[1] as $k => $v) {
  72.                     if (preg_match("/_/"$m[2][$k])) {
  73.                         preg_match_all("/(\d+)/"$m[2][$k], $mm);
  74.                         $chars_selected[$v] = $mm[0];
  75.                     } else {
  76.                         $chars_selected[$v][] = $m[2][$k];
  77.                     }
  78.                 }
  79.             }            
  80.         }
  81.         foreach ($chars_selected as $k => $v) {
  82.             if (is_int($k)) {
  83.                 $char_id = (int) $m[1];                
  84.                 $chars_selected[$char_id] = $v;
  85.                 foreach ($v as $val) {
  86.                     $charval $this->Charvals->find($val);
  87.                     $filters $Filter->generate_filters_exclude($chars_selected$char_id$val);
  88.                     $url $this->generateUrl('prod_list_cat_filter', ['cat_id' => $cat_id'cat_intname' => $cat_intname'filters' => $filters]);
  89.                     $chars_url[$url] =  $charval->getValue();
  90.                 }                
  91.             } else {
  92.                 $char_id $k;                
  93.                 $chars_selected[$char_id] = $v;
  94.                 $val $v;
  95.                 $filters $Filter->generate_filters_exclude($chars_selected$char_id$val);                
  96.                 $url $this->generateUrl('prod_list_cat_filter', ['cat_id' => $cat_id'cat_intname' => $cat_intname'filters' => $filters]);
  97.                 $chars_url[$url] = $v;
  98.             }
  99.         }
  100.         
  101.         $response $this->render('block/chars_selected.html.twig', [
  102.             'spec' => $spec,
  103.             'cat_id' => $cat_id,
  104.             'cat_intname' => $cat_intname,
  105.             'chars_selected' => $chars_selected,
  106.             'chars_url' => $chars_url,
  107.         ]);
  108.         return $response;
  109.     }
  110. }