app/Plugin/EPub42/Controller/EPubController.php line 39

Open in your IDE?
  1. <?php
  2. namespace Plugin\EPub42\Controller;
  3. use Eccube\Controller\AbstractController;
  4. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  5. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  10. use Symfony\Component\Filesystem\Filesystem;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
  13. use Plugin\EPub42\Entity\EPub;
  14. use Plugin\EPub42\Repository\EPubRepository;
  15. use Plugin\EPub42\Form\Type\Admin\EPubType;
  16. class EPubController extends AbstractController
  17. {
  18.     /**
  19.      * @var EPubRepository
  20.      */
  21.     protected $ePubRepository;
  22.     /**
  23.      * PageController constructor.
  24.      *
  25.      * @param EPubRepository $ePubRepository
  26.      */
  27.     public function __construct(
  28.         EPubRepository $ePubRepository
  29.     ) {
  30.         $this->ePubRepository $ePubRepository;
  31.     }
  32.     /**
  33.      * @Route("/block/free_e_kenkouokyoushitsu", name="block_free_e_kenkouokyoushitsu", methods={"GET"})
  34.      * @Template("Block/free_e_kenkouokyoushitsu.twig")
  35.      */
  36.     public function block(Request $request)
  37.     {
  38.         // 試し読み
  39.         $id 49;
  40.         $eBooks $this->ePubRepository->getPublishedEBookFromId($id);
  41.         if(is_array($eBooks) && empty($eBooks)){
  42.             $eBooks = [];
  43.         }
  44.         return [
  45.             'eBooks' => $eBooks,
  46.         ];
  47.     }
  48.     /**
  49.      * @Route("/epub", name="epub")
  50.      * @Template("@EPub42/default/epub_list.twig")
  51.      */
  52.     public function index(Request $request)
  53.     {
  54.         log_info('ePub表示');
  55.         $book $request->query->get('book');
  56.         if(!$book){
  57.             throw new NotFoundHttpException();
  58.         }
  59.         $epub $this->ePubRepository->checkEpubBook($book.'.zip');
  60.         if(!$epub){
  61.             throw new NotFoundHttpException();
  62.         }
  63.         //試し読みかチェック
  64.         if($epub->getId() != 35){
  65.             //無料公開でない場合は定期ユーザーかチェック
  66.             if($epub->getCategoryId() != 3){
  67.                 if(!$this->getUser()){
  68.                     throw new NotFoundHttpException();
  69.                 }
  70.                 if(!$this->getUser()->getTeikiUserFlg()) {
  71.                     throw new NotFoundHttpException();
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }