- <?php
- namespace Plugin\Blogs42\Controller;
- use Eccube\Controller\AbstractController;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Routing\Annotation\Route;
- use Doctrine\Common\Collections\Criteria;
- use Eccube\Event\EccubeEvents;
- use Eccube\Event\EventArgs;
- use Plugin\Blogs42\Entity\Blogs;
- use Plugin\Blogs42\Repository\BlogsRepository;
- use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
- use Knp\Component\Pager\PaginatorInterface;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use Plugin\Blogs42\Form\Type\SearchBlogsType;
- /**
-  * Class CampaignController.
-  */
- class BlogsController extends AbstractController
- {
-    /**
-      * @var BlogsRepository
-      */
-     protected $blogsRepository;
-     /**
-      * BlogsController constructor.
-      *
-      * @param BlogsRepository $blogsRepository
-      */
-     public function __construct(BlogsRepository $blogsRepository)
-     {
-         $this->blogsRepository = $blogsRepository;
-     }
-     /**
-      * お知らせ一覧画面.
-      *
-      * @Route("/blogs/list", name="blogs42_list", methods={"GET"})
-      * @Template("Blogs42/list.twig")
-      */
-     public function index(Request $request, PaginatorInterface $paginator)
-     {
-         // handleRequestは空のqueryの場合は無視するため
-         if ($request->getMethod() === 'GET') {
-             $request->query->set('pageno', $request->query->get('pageno', ''));
-         }
-         // searchForm
-         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
-         $builder = $this->formFactory->createNamedBuilder('', SearchBlogsType::class);
-         if ($request->getMethod() === 'GET') {
-             $builder->setMethod('GET');
-         }
-         /* @var $searchForm \Symfony\Component\Form\FormInterface */
-         $searchForm = $builder->getForm();
-         $searchForm->handleRequest($request);
-         // paginator
-         $searchData = $searchForm->getData();
-         $qb = $this->blogsRepository->getQueryBuilderBySearchData($searchData);
-         $query = $qb->getQuery()
-             ->useResultCache(true, $this->eccubeConfig['eccube_result_cache_lifetime_short']);
-         /** @var SlidingPagination $pagination */
-         $pagination = $paginator->paginate(
-             $query,
-             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
-             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
-         );
-         $Category = $searchForm->get('blogs_category_id')->getData();
-         return [
-             'search_form' => $searchForm->createView(),
-             'pagination' => $pagination,
-             'Category' => $Category,
-         ];
-     }
-     /**
-      * お知らせ詳細画面.
-      *
-      * @Route("/blogs/detail/{id}", name="blogs42_detail", requirements={"id":"\d+"})
-      * @Template("Blogs42/detail.twig")
-      */
-     public function Detail(Request $request, $id=null)
-     {
-         $Blogs = $this->blogsRepository->find($id);
-         $today = new \DateTime();
-         $is_admin = $this->session->has('_security_admin');
-         if (!$is_admin) {
-             //404設定 記事の存在、公開、公開日
-             if(!$Blogs || $Blogs->isVisible() == false || $Blogs['publish_date'] > $today){
-                 throw new NotFoundHttpException();
-             }
-         }else{
-             if(!$Blogs){
-                 throw new NotFoundHttpException();
-             }
-         }
-         return [
-             'Blogs' => $Blogs,
-         ];
-     }
- }
-