app/Customize/Controller/CustomController.php line 74

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Eccube\Controller\AbstractController;
  5. use Knp\Component\Pager\PaginatorInterface;
  6. use Plugin\CMBlogPro42\Entity\Blog;
  7. use Plugin\CMBlogPro42\Entity\BlogStatus;
  8. use Plugin\CMBlogPro42\Form\Type\Admin\BlogType;
  9. use Customize\Repository\BlogRepository;
  10. use Plugin\CMBlogPro42\Repository\CategoryRepository;
  11. use Plugin\CMBlogPro42\Repository\ConfigRepository;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Eccube\Repository\PageRepository;
  16. use Eccube\Repository\ProductRepository;
  17. use Symfony\Component\HttpFoundation\Response;
  18. class CustomController extends AbstractController
  19. {
  20.     protected $entityManager;
  21.     /**
  22.      * @var BlogRepository
  23.      */
  24.     protected $blogRepository;
  25.     /**
  26.      * @var CategoryRepository
  27.      */
  28.     protected $categoryRepository;
  29.     /**
  30.      * @var ProductRepository
  31.      */
  32.     protected $productRepository;
  33.     /**
  34.      * @var ConfigRepository
  35.      */
  36.     protected $configRepository;
  37.     /**
  38.      * @var PageRepository
  39.      */
  40.     protected $pageRepository;
  41.     /**
  42.      * BlogController constructor.
  43.      */
  44.     public function __construct(
  45.         EntityManagerInterface $entityManager,
  46.         BlogRepository $blogRepository,
  47.         CategoryRepository $categoryRepository,
  48.         PageRepository $pageRepository,
  49.         ProductRepository $productRepository,
  50.         ConfigRepository $configRepository)
  51.     {
  52.         $this->entityManager $entityManager;
  53.         $this->blogRepository $blogRepository;
  54.         $this->categoryRepository $categoryRepository;
  55.         $this->productRepository $productRepository;
  56.         $this->configRepository $configRepository;
  57.         $this->pageRepository $pageRepository;
  58.     }
  59.     /**
  60.      * 工事実績一覧
  61.      * @Route("/results", name="results")
  62.      * @Template("blog/list.twig")
  63.      */
  64.     public function results(Request $requestPaginatorInterface $paginator) {
  65.         $form $this->createForm(BlogType::class);
  66.         $search $request->query->all();
  67.         $search["status"] = 1;
  68.         $search['disp_number'] = 9;
  69.         $qb $this->blogRepository->getQueryBuilderBySearchData($search);
  70.         $config $this->configRepository->get();
  71.         $pagination $paginator->paginate(
  72.             $qb,
  73.             !empty($search['pageno']) ? $search['pageno'] : 1,
  74.             !empty($search['disp_number']) ? $search['disp_number'] : $config->getDisplayPage()
  75.         );
  76.         return [
  77.             'form' => $form->createView(),
  78.             'categories' => $this->categoryRepository->getFrontCategoryList(),
  79.             'pagination' => $pagination,
  80.             'monthArr' => $this->setMonthArchive($search),
  81.             'search_year' => empty($search['date']) ? "" date('Y'strtotime($search['date'])),
  82.             'page_title' => '工事実績',
  83.             'title' => '工事が得意のエアココの実績をご紹介',
  84.             'description' => 'エアココは、電気工事会社が運営しているので、工事がとても強い。これまでの工事の一例をご紹介します。',
  85.         ];
  86.     }
  87.     /**
  88.      * コラム
  89.      * @Route("/columns", name="columns")
  90.      * @Template("blog/list.twig")
  91.      */
  92.     public function columns(Request $requestPaginatorInterface $paginator) {
  93.         $form $this->createForm(BlogType::class);
  94.         $search $request->query->all();
  95.         $search["status"] = 1;
  96.         $search['categories'] = 1//コラム
  97.         $qb $this->blogRepository->getQueryBuilderBySearchData($search);
  98.         $config $this->configRepository->get();
  99.         $pagination $paginator->paginate(
  100.             $qb,
  101.             !empty($search['pageno']) ? $search['pageno'] : 1,
  102.             !empty($search['disp_number']) ? $search['disp_number'] : $config->getDisplayPage()
  103.         );
  104.         return [
  105.             'form' => $form->createView(),
  106.             'categories' => $this->categoryRepository->getFrontCategoryList(),
  107.             'pagination' => $pagination,
  108.             'monthArr' => $this->setMonthArchive($search),
  109.             'search_year' => empty($search['date']) ? "" date('Y'strtotime($search['date'])),
  110.             'title' => 'お役立ち情報・お得情報を随時配信中',
  111.             'description' => 'エアココは日常生活でお役に立つ情報やお得情報を調査して随時、発信しています。',
  112.         ];
  113.     }
  114.     /**
  115.      * 月別アーカイブ表示のため取得
  116.      *
  117.      * @param 
  118.      *
  119.      * @return array 月別配列
  120.      */
  121.     private function setMonthArchive($search = []) {
  122.         
  123.         // $releaseDate = $this->blogRepository->getReleaseDate($search);
  124.         $releaseDate $this->blogRepository->getReleaseDate(["status" => 1]);
  125.         $monthArr = [];
  126.         foreach($releaseDate as $val) {
  127.             // if(is_null($val['release_date'])) {
  128.             //     continue;
  129.             // }
  130.             // $key = $val['release_date']->format('Y-m');
  131.             // if(isset($monthArr[$key])) {
  132.             //     continue;
  133.             // }
  134.             // $monthArr[$key] = $val['release_date']->format('Y年m月');
  135.             
  136.             if(is_null($val['release_date'])) {
  137.                 continue;
  138.             }
  139.             $key_y $val['release_date']->format('Y');
  140.             $key_m $val['release_date']->format('Y-m');
  141.             
  142.             $monthArr[$key_y][$key_m] = array(
  143.                 'ym' => $val['release_date']->format('Y年m月'),
  144.                 'count' => (empty($monthArr[$key_y][$key_m]['count']) ? : (int)$monthArr[$key_y][$key_m]['count']) + 1,
  145.             );   
  146.         }
  147.         return $monthArr;
  148.     }
  149. }