src/CustomBundle/Controller/GroupHomeController.php line 52

Open in your IDE?
  1. <?php
  2. namespace CustomBundle\Controller;
  3. use AppBundle\Component\Util\Hash;
  4. use CustomBundle\Form\TopPageRestaurantSearchType;
  5. use Doctrine\ORM\NonUniqueResultException;
  6. use Doctrine\ORM\QueryBuilder;
  7. use Mod\RestaurantBundle\Entity\Genre;
  8. use Mod\RestaurantBundle\Service\BundleUtility as TopicsBundleUtility;
  9. use Mod\RestaurantBundle\Service\BundleUtility as RestaurantBundleUtility;
  10. use Mod\TopBundle\Entity\Banner;
  11. use Mod\TopBundle\Entity\GourmetPickup;
  12. use Mod\TopBundle\Entity\RestaurantPickup;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class GroupHomeController extends CustomBaseController
  16. {
  17.     /**
  18.      * @Route("/", name="group_home")
  19.      */
  20.     public function indexAction(Request $request)
  21.     {
  22.         $form $this->createForm(TopPageRestaurantSearchType::class, null, [
  23.             'method' => 'GET',
  24.             'csrf_protection' => false,
  25.         ]);
  26.         /** @var RestaurantBundleUtility $restaurant_util */
  27.         $restaurant_util $this->get('mod_restaurant.bundle_utility');
  28.         // ジャンル
  29.         $genres $restaurant_util->getGenres();
  30.         // グルメ特集
  31.         $gourmet_pickup_items $this->getGourmetPickupItems();
  32.         // 店舗特集
  33.         $restaurant_pickup_items $this->getRestaurantPickupItems();
  34.         /** @var TopicsBundleUtility $util */
  35.         $util $this->get('mod_topics.bundle_utility');
  36.         //重要なお知らせ
  37.         $recommended_news $util->searchItems(["important"=>true], ["public_date"=>"DESC"], 1);
  38.         //最新記事
  39.         $list_news $util->searchItems([], ["public_date"=>"DESC"], 5);
  40.         return $this->renderFront('index.php', [
  41.             'cms__form' => $form->createView(),
  42.             'cms__genres' => $genres,
  43.             'cms__gourmet_pickup_items' => $gourmet_pickup_items,
  44.             'cms__restaurant_pickup_items' => $restaurant_pickup_items,
  45.             'cms__recommended_news' => $recommended_news,
  46.             'cms__list_news' => $list_news,
  47.             'cms__banner' => $this->getBanner(),
  48.         ]);
  49.     }
  50.     // バナー取得
  51.     public function getBanner()
  52.     {
  53.         $repo $this->getDoctrine()->getRepository(Banner::class);
  54.         /** @var QueryBuilder $qb */
  55.         $qb $repo->createQueryBuilder('b');
  56.         $qb->addOrderBy('b.sort_num''ASC')
  57.             ->setMaxResults(1)
  58.         ;
  59.         try {
  60.             $result $qb->getQuery()->getOneOrNullResult();
  61.         } catch(NonUniqueResultException $e) {
  62.             $result null;
  63.         }
  64.         return $result;
  65.     }
  66.     // FormTypeにデータを渡す
  67.     protected function createForm($type$data null, array $options = [])
  68.     {
  69.         /** @var RestaurantBundleUtility $util */
  70.         $util $this->get('mod_restaurant.bundle_utility');
  71.         $genres $util->transformData($util->getGenres());
  72.         $time_by_cars $util->transformData($util->getTimeByCars(), true'お車''分圏内');
  73.         $scenes $util->transformData($util->getScenes());
  74.         $features $util->transformData($util->getFeatures());
  75.         $options['genres'] = $genres;
  76.         $options['time_by_cars'] = $time_by_cars;
  77.         $options['scenes'] = $scenes;
  78.         $options['features'] = $features;
  79.         return parent::createForm($type$data$options);
  80.     }
  81.     // グルメ特集
  82.     public function getGourmetPickupItems()
  83.     {
  84.         $repo $this->getDoctrine()->getRepository(GourmetPickup::class);
  85.         /** @var QueryBuilder $qb */
  86.         $qb $repo->createQueryBuilder('g');
  87.         $qb->addOrderBy('g.sort_num''ASC');
  88.         $results $qb->getQuery()->getResult();
  89.         return $results;
  90.     }
  91.     // 店舗特集
  92.     public function getRestaurantPickupItems()
  93.     {
  94.         $repo $this->getDoctrine()->getRepository(RestaurantPickup::class);
  95.         /** @var QueryBuilder $qb */
  96.         $qb $repo->createQueryBuilder('p');
  97.         $qb->innerJoin('p.restaurant''r')
  98.             ->addOrderBy('p.sort_num''ASC')
  99.         ;
  100.         
  101.         $results $qb->getQuery()->getResult();
  102.         return $results;
  103.     }
  104. }