<?php
namespace Customize\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Controller\AbstractController;
use Knp\Component\Pager\PaginatorInterface;
use Plugin\CMBlogPro42\Entity\Blog;
use Plugin\CMBlogPro42\Entity\BlogStatus;
use Plugin\CMBlogPro42\Form\Type\Admin\BlogType;
use Customize\Repository\BlogRepository;
use Plugin\CMBlogPro42\Repository\CategoryRepository;
use Plugin\CMBlogPro42\Repository\ConfigRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Eccube\Repository\PageRepository;
use Eccube\Repository\ProductRepository;
use Symfony\Component\HttpFoundation\Response;
class CustomController extends AbstractController
{
protected $entityManager;
/**
* @var BlogRepository
*/
protected $blogRepository;
/**
* @var CategoryRepository
*/
protected $categoryRepository;
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @var ConfigRepository
*/
protected $configRepository;
/**
* @var PageRepository
*/
protected $pageRepository;
/**
* BlogController constructor.
*/
public function __construct(
EntityManagerInterface $entityManager,
BlogRepository $blogRepository,
CategoryRepository $categoryRepository,
PageRepository $pageRepository,
ProductRepository $productRepository,
ConfigRepository $configRepository)
{
$this->entityManager = $entityManager;
$this->blogRepository = $blogRepository;
$this->categoryRepository = $categoryRepository;
$this->productRepository = $productRepository;
$this->configRepository = $configRepository;
$this->pageRepository = $pageRepository;
}
/**
* 工事実績一覧
* @Route("/results", name="results")
* @Template("blog/list.twig")
*/
public function results(Request $request, PaginatorInterface $paginator) {
$form = $this->createForm(BlogType::class);
$search = $request->query->all();
$search["status"] = 1;
$search['disp_number'] = 9;
$qb = $this->blogRepository->getQueryBuilderBySearchData($search);
$config = $this->configRepository->get();
$pagination = $paginator->paginate(
$qb,
!empty($search['pageno']) ? $search['pageno'] : 1,
!empty($search['disp_number']) ? $search['disp_number'] : $config->getDisplayPage()
);
return [
'form' => $form->createView(),
'categories' => $this->categoryRepository->getFrontCategoryList(),
'pagination' => $pagination,
'monthArr' => $this->setMonthArchive($search),
'search_year' => empty($search['date']) ? "" : date('Y', strtotime($search['date'])),
'page_title' => '工事実績',
'title' => '工事が得意のエアココの実績をご紹介',
'description' => 'エアココは、電気工事会社が運営しているので、工事がとても強い。これまでの工事の一例をご紹介します。',
];
}
/**
* コラム
* @Route("/columns", name="columns")
* @Template("blog/list.twig")
*/
public function columns(Request $request, PaginatorInterface $paginator) {
$form = $this->createForm(BlogType::class);
$search = $request->query->all();
$search["status"] = 1;
$search['categories'] = 1; //コラム
$qb = $this->blogRepository->getQueryBuilderBySearchData($search);
$config = $this->configRepository->get();
$pagination = $paginator->paginate(
$qb,
!empty($search['pageno']) ? $search['pageno'] : 1,
!empty($search['disp_number']) ? $search['disp_number'] : $config->getDisplayPage()
);
return [
'form' => $form->createView(),
'categories' => $this->categoryRepository->getFrontCategoryList(),
'pagination' => $pagination,
'monthArr' => $this->setMonthArchive($search),
'search_year' => empty($search['date']) ? "" : date('Y', strtotime($search['date'])),
'title' => 'お役立ち情報・お得情報を随時配信中',
'description' => 'エアココは日常生活でお役に立つ情報やお得情報を調査して随時、発信しています。',
];
}
/**
* 月別アーカイブ表示のため取得
*
* @param
*
* @return array 月別配列
*/
private function setMonthArchive($search = []) {
// $releaseDate = $this->blogRepository->getReleaseDate($search);
$releaseDate = $this->blogRepository->getReleaseDate(["status" => 1]);
$monthArr = [];
foreach($releaseDate as $val) {
// if(is_null($val['release_date'])) {
// continue;
// }
// $key = $val['release_date']->format('Y-m');
// if(isset($monthArr[$key])) {
// continue;
// }
// $monthArr[$key] = $val['release_date']->format('Y年m月');
if(is_null($val['release_date'])) {
continue;
}
$key_y = $val['release_date']->format('Y');
$key_m = $val['release_date']->format('Y-m');
$monthArr[$key_y][$key_m] = array(
'ym' => $val['release_date']->format('Y年m月'),
'count' => (empty($monthArr[$key_y][$key_m]['count']) ? 0 : (int)$monthArr[$key_y][$key_m]['count']) + 1,
);
}
return $monthArr;
}
}