<?php
namespace Plugin\EPub42\Controller;
use Eccube\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
use Plugin\EPub42\Entity\EPub;
use Plugin\EPub42\Repository\EPubRepository;
use Plugin\EPub42\Form\Type\Admin\EPubType;
class EPubController extends AbstractController
{
/**
* @var EPubRepository
*/
protected $ePubRepository;
/**
* PageController constructor.
*
* @param EPubRepository $ePubRepository
*/
public function __construct(
EPubRepository $ePubRepository
) {
$this->ePubRepository = $ePubRepository;
}
/**
* @Route("/block/free_e_kenkouokyoushitsu", name="block_free_e_kenkouokyoushitsu", methods={"GET"})
* @Template("Block/free_e_kenkouokyoushitsu.twig")
*/
public function block(Request $request)
{
// 試し読み
$id = 49;
$eBooks = $this->ePubRepository->getPublishedEBookFromId($id);
if(is_array($eBooks) && empty($eBooks)){
$eBooks = [];
}
return [
'eBooks' => $eBooks,
];
}
/**
* @Route("/epub", name="epub")
* @Template("@EPub42/default/epub_list.twig")
*/
public function index(Request $request)
{
log_info('ePub表示');
$book = $request->query->get('book');
if(!$book){
throw new NotFoundHttpException();
}
$epub = $this->ePubRepository->checkEpubBook($book.'.zip');
if(!$epub){
throw new NotFoundHttpException();
}
//試し読みかチェック
if($epub->getId() != 35){
//無料公開でない場合は定期ユーザーかチェック
if($epub->getCategoryId() != 3){
if(!$this->getUser()){
throw new NotFoundHttpException();
}
if(!$this->getUser()->getTeikiUserFlg()) {
throw new NotFoundHttpException();
}
}
}
}
}