src/Controller/ItemsController.php line 76

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\DataArt;
  4. use App\Repository\DataArtRepository;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. class ItemsController extends BaseController{
  10.     public $dataClass      'DataArt::class';
  11.     public $dataRepository 'dataArtRepository';
  12.     public $img            'https://acnhcdn.com/latest/FtrIcon/';
  13.     public $dataArtRepository;
  14.     public $managerRegistry;
  15.     public function __construct(DataArtRepository $dataArtRepositoryManagerRegistry $managerRegistry)
  16.     {
  17.         parent::__construct();
  18.         $this->dataArtRepository=$dataArtRepository;
  19.         $this->managerRegistry $managerRegistry;
  20.     }
  21.     /**
  22.      * @Route("/items/{type}/{currentPage}", name="items_type")
  23.      * @param Request $request
  24.      * @return \Symfony\Component\HttpFoundation\Response
  25.      */
  26.     public function itemsIndex(Request $request$type$currentPage=1){
  27.         $items=array();
  28.         if($type){
  29.             $em $this->getDoctrine()->getManager();
  30.             $limit 15;
  31.             $name=$this->returType($type);
  32.             if($name[3]!=''){
  33.                 $items $em->getRepository($name[0])->getAllByField($currentPage$limit'tag',$name[3]);
  34.             }else{
  35.                 $items $em->getRepository($name[0])->getAll($currentPage$limit);
  36.             }
  37.             $itemsResultado $items['paginator'];
  38.             $itemsQueryCompleta =  $items['query'];
  39.             $maxPages ceil($items['paginator']->count() / $limit);
  40.             $typesRepository = new $name[1]($this->managerRegistry);
  41.             $typesRepository->findBy(array(), array('name' => 'ASC'));
  42.         }
  43.         return $this->render('items/index.html.twig', [
  44.             'typeName'  => $type,
  45.             'types'     => $typesRepository,
  46.             'items'     => $itemsResultado,
  47.             'maxPages'  => $maxPages,
  48.             'thisPage'  => $currentPage,
  49.             'all_items' => $itemsQueryCompleta,
  50.             'rutaimg'   => $name[2],
  51.             'type'      => $type
  52.         ]);
  53.     }
  54.     /**
  55.      * @Route("/items/{type}/{currentPage}/{category}", name="items_type_category")
  56.      * @param Request $request
  57.      * @return \Symfony\Component\HttpFoundation\Response
  58.      */
  59.     public function categoryIndex(Request $request$type$currentPage=1$category=null){
  60.         $items=array();
  61.         if($type){
  62.             $em $this->getDoctrine()->getManager();
  63.             $limit 15;
  64.             $name=$this->returType($type);
  65.             $items $em->getRepository($name[0])->getAllByCategory($category$currentPage$limit);
  66.             $maxPages ceil($items['paginator']->count() / $limit);
  67.             if($maxPages<$currentPage){
  68.                 $items $em->getRepository($name[0])->getAllByCategory($category$currentPage=1$limit);
  69.             }
  70.             $itemsResultado $items['paginator'];
  71.             $itemsQueryCompleta =  $items['query'];
  72.             $typesRepository = new $name[1]($this->managerRegistry);
  73.             $typesRepository->findBy(array(), array('name' => 'ASC'));
  74.         }
  75.         return $this->render('items/index.html.twig', [
  76.             'typeName'  => $type,
  77.             'types'     => $typesRepository,
  78.             'items'     => $itemsResultado,
  79.             'maxPages'  => $maxPages,
  80.             'thisPage'  => $currentPage,
  81.             'all_items' => $itemsQueryCompleta,
  82.             'rutaimg'   => $name[2],
  83.             'category'  => $category,
  84.             'type'      => $type
  85.         ]);
  86.     }
  87.     private function returType($type)
  88.     {
  89.         $typeucfirst($type);
  90.         $tag='';
  91.         $img            '/resources/img/icons/';
  92.         switch ($type) {
  93.             case 'Bushes':
  94.                 $type   'Other';
  95.                 $tag    'bushes';
  96.                 break;
  97.             case 'Flowers':
  98.                 $type   'Other';
  99.                 $tag    'Plants';
  100.                 break;
  101.             default:
  102.                 //$img            = 'https://acnhcdn.com/latest/FtrIcon/';
  103.                 break;
  104.         }
  105.         $dataClass      "App\Entity\Data{$type}";
  106.         $dataRepository "\App\Repository\data{$type}Repository";
  107.         /*switch ($type) {
  108.             case 'art':
  109.                 $dataClass      = 'App\Entity\DataArt';
  110.                 $dataRepository = 'dataArtRepository';
  111.                 $img            = 'https://acnhcdn.com/latest/FtrIcon/';
  112.                 break;
  113.             case 'bushes':
  114.                 $dataClass      = 'App\Entity\DataBushes';
  115.                 $dataRepository = 'App\Repository\dataBushesRepository';
  116.                 $img            = 'https://acnhcdn.com/latest/FtrIcon/';
  117.                 break;
  118.             case 'bags':
  119.                 $dataClass      = 'App\Entity\DataBags';
  120.                 $dataRepository = 'App\Repository\dataBagsRepository';
  121.                 break;
  122.         }
  123.         */
  124.         if(isset($dataClass) && class_exists($dataClass)){
  125.             return array("{$dataClass}","{$dataRepository}""{$img}""{$tag}");
  126.         }else{
  127.             return array($this->dataClass,$this->dataRepository$this->img);
  128.         }
  129.     }
  130. }