app/Plugin/EPub42/Controller/Mypage/EPubController.php line 50

Open in your IDE?
  1. <?php
  2. namespace Plugin\EPub42\Controller\Mypage;
  3. use Eccube\Controller\AbstractController;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  8. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  9. use Plugin\EPub42\Repository\EPubRepository;
  10. use Plugin\EPub42\Service\EPubService;
  11. class EPubController extends AbstractController
  12. {
  13.     /**
  14.      * @var EPubRepository
  15.      */
  16.     protected $ePubRepository;
  17.     /**
  18.      * @var EPubService
  19.      */
  20.     protected $ePubService;
  21.     /**
  22.      * CouponShoppingController constructor.
  23.      *
  24.      * @var EPubRepository $ePubRepository
  25.      * @var EPubService $ePubService
  26.      */
  27.     public function __construct(
  28.         EPubRepository $ePubRepository,
  29.         EPubService $ePubService
  30.     )
  31.     {
  32.         $this->ePubRepository $ePubRepository;
  33.         $this->ePubService $ePubService;
  34.     }
  35.     /**
  36.      * 書籍読み放題ページページ.
  37.      *
  38.      * @Route("/mypage/readebook/{id}", name="mypage_read_ebook", methods={"GET"}, requirements={"id" = "\d+"})
  39.      * @Template("Mypage/read_ebook.twig")
  40.      *
  41.      * @param Request $request
  42.      */
  43.     public function eBook(Request $request$id=null)
  44.     {
  45.         if($id == null || ($id != && $id != )){
  46.             throw new NotFoundHttpException();
  47.         }
  48.         //定期ユーザーかチェック
  49.         $Customer $this->getUser();
  50.         if ($id == 1) {
  51.             $eBooks $this->ePubRepository->getPublishedEBook($id);
  52.             return [
  53.                 'eBooks' => $eBooks,
  54.                 'Customer' => $Customer,
  55.                 'category' => $id,
  56.             ];
  57.         }
  58.         if ($id == 2) {
  59.             /**
  60.              * 登録されている健康教室の電子書籍を取得する
  61.              * 定期ユーザの場合は、購入履歴をチェックする
  62.              * 定期ユーザの場合
  63.              * 購入履歴に健康教室定期の購入があれば、その号だけ見せる
  64.              * なければ、今日から12ヶ月前の健康教室を見せる
  65.              */
  66.             if($Customer->getTeikiUserFlg()) {
  67.                 $eBooks = [];
  68.                 //本日より以前の発売済みの健康教室の電子書籍を全て取得する
  69.                 $KenkouKyoushituEBooks $this->ePubRepository->getKenkoukyoushitsuEBooks();
  70.                 if($KenkouKyoushituEBooks) {
  71.                     //健康教室定期の購入履歴があるか
  72.                     $teiki_order_flg false;
  73.                     foreach($KenkouKyoushituEBooks as $book) {
  74.                         // 定期の購入があるかどうか
  75.                         $TeikiOrder $this->ePubService->getTeikiOrder($Customer$book->getStartDate());
  76.                         if ($TeikiOrder) {
  77.                             array_push($eBooks$book);
  78.                         } else {
  79.                             // 単品での購入があるかどうか
  80.                             $SingleOrder $this->ePubService->getSingleItemOrder($Customer$book->getProductId());
  81.                             if ($SingleOrder) {
  82.                                 array_push($eBooks$book);
  83.                             }
  84.                         }
  85.                     }
  86.                     //if($teiki_order_flg == false) {
  87.                     //    // 過去12ヶ月分を無条件で見せる
  88.                     //    $today = new \DateTime();
  89.                     //    $i = 0;
  90.                     //    foreach ($KenkouKyoushituEBooks as $book) {
  91.                     //        if($i < 12) {
  92.                     //            if($book->getStartDate() <= $today){
  93.                     //                array_push($eBooks, $book);
  94.                     //            }
  95.                     //        }
  96.                     //        $i++;
  97.                     //    }
  98.                     //}
  99.                 }
  100.                 // 定期ユーザは、一旦すべてみせる
  101.                 //foreach ($KenkouKyoushituEBooks as $book) {
  102.                 //    array_push($eBooks, $book);
  103.                 //}
  104.                 //$eBooks = $this->ePubRepository->getPublishedEBook($id);
  105.                 return [
  106.                     'eBooks' => $eBooks,
  107.                     'Customer' => $Customer,
  108.                     'category' => $id,
  109.                 ];
  110.             } else {
  111.             }
  112.         }
  113.     }
  114. }