<?php
namespace CustomBundle\Controller;
use AppBundle\Component\Util\Hash;
use CustomBundle\Form\TopPageRestaurantSearchType;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\QueryBuilder;
use Mod\RestaurantBundle\Entity\Genre;
use Mod\RestaurantBundle\Service\BundleUtility as TopicsBundleUtility;
use Mod\RestaurantBundle\Service\BundleUtility as RestaurantBundleUtility;
use Mod\TopBundle\Entity\Banner;
use Mod\TopBundle\Entity\GourmetPickup;
use Mod\TopBundle\Entity\RestaurantPickup;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class GroupHomeController extends CustomBaseController
{
/**
* @Route("/", name="group_home")
*/
public function indexAction(Request $request)
{
$form = $this->createForm(TopPageRestaurantSearchType::class, null, [
'method' => 'GET',
'csrf_protection' => false,
]);
/** @var RestaurantBundleUtility $restaurant_util */
$restaurant_util = $this->get('mod_restaurant.bundle_utility');
// ジャンル
$genres = $restaurant_util->getGenres();
// グルメ特集
$gourmet_pickup_items = $this->getGourmetPickupItems();
// 店舗特集
$restaurant_pickup_items = $this->getRestaurantPickupItems();
/** @var TopicsBundleUtility $util */
$util = $this->get('mod_topics.bundle_utility');
//重要なお知らせ
$recommended_news = $util->searchItems(["important"=>true], ["public_date"=>"DESC"], 1);
//最新記事
$list_news = $util->searchItems([], ["public_date"=>"DESC"], 5);
return $this->renderFront('index.php', [
'cms__form' => $form->createView(),
'cms__genres' => $genres,
'cms__gourmet_pickup_items' => $gourmet_pickup_items,
'cms__restaurant_pickup_items' => $restaurant_pickup_items,
'cms__recommended_news' => $recommended_news,
'cms__list_news' => $list_news,
'cms__banner' => $this->getBanner(),
]);
}
// バナー取得
public function getBanner()
{
$repo = $this->getDoctrine()->getRepository(Banner::class);
/** @var QueryBuilder $qb */
$qb = $repo->createQueryBuilder('b');
$qb->addOrderBy('b.sort_num', 'ASC')
->setMaxResults(1)
;
try {
$result = $qb->getQuery()->getOneOrNullResult();
} catch(NonUniqueResultException $e) {
$result = null;
}
return $result;
}
// FormTypeにデータを渡す
protected function createForm($type, $data = null, array $options = [])
{
/** @var RestaurantBundleUtility $util */
$util = $this->get('mod_restaurant.bundle_utility');
$genres = $util->transformData($util->getGenres());
$time_by_cars = $util->transformData($util->getTimeByCars(), true, 'お車', '分圏内');
$scenes = $util->transformData($util->getScenes());
$features = $util->transformData($util->getFeatures());
$options['genres'] = $genres;
$options['time_by_cars'] = $time_by_cars;
$options['scenes'] = $scenes;
$options['features'] = $features;
return parent::createForm($type, $data, $options);
}
// グルメ特集
public function getGourmetPickupItems()
{
$repo = $this->getDoctrine()->getRepository(GourmetPickup::class);
/** @var QueryBuilder $qb */
$qb = $repo->createQueryBuilder('g');
$qb->addOrderBy('g.sort_num', 'ASC');
$results = $qb->getQuery()->getResult();
return $results;
}
// 店舗特集
public function getRestaurantPickupItems()
{
$repo = $this->getDoctrine()->getRepository(RestaurantPickup::class);
/** @var QueryBuilder $qb */
$qb = $repo->createQueryBuilder('p');
$qb->innerJoin('p.restaurant', 'r')
->addOrderBy('p.sort_num', 'ASC')
;
$results = $qb->getQuery()->getResult();
return $results;
}
}