app/Plugin/DeliveryDate4/Controller/Block/CalendarController.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : DeliveryDate4
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\DeliveryDate4\Controller\Block;
  12. use Eccube\Controller\AbstractController;
  13. use Plugin\DeliveryDate4\Repository\ConfigRepository;
  14. use Plugin\DeliveryDate4\Repository\HolidayRepository;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\HttpFoundation\Request;
  18. class CalendarController extends AbstractController
  19. {
  20.     private $configRepository;
  21.     private $holidayRepository;
  22.     public function __construct(
  23.             ConfigRepository $configRepository,
  24.             HolidayRepository $holidayRepository
  25.             )
  26.     {
  27.         $this->configRepository $configRepository;
  28.         $this->holidayRepository $holidayRepository;
  29.     }
  30.     /**
  31.      * @Route("/block/businessday_calendar", name="block_businessday_calendar")
  32.      * @Template("Block/businessday_calendar.twig")
  33.      */
  34.     public function index(Request $request)
  35.     {
  36.         $Config $this->configRepository->findOneBy(['name' => 'calendar_month']);
  37.         if($Config){
  38.             $months $Config->getValue();
  39.         }else{
  40.             $months 2;
  41.         }
  42.         $Date = [];
  43.         for($i=$i<$months $i++){
  44.             $month = new \DateTime();
  45.             $Month $month->modify('first day of this month')->modify('+' $i 'month')->format('Y-m');
  46.             $start = new \DateTime();
  47.             $start->modify('first day of '$Month);
  48.             $end = new \DateTime();
  49.             $end->modify('last day of '$Month);
  50.             $end->modify('+1 day');
  51.             $period = new \DatePeriod (
  52.                 $start,
  53.                 new \DateInterval('P1D'),
  54.                 $end
  55.             );
  56.             foreach ($period as $day) {
  57.                 $Date[$day->format('n')][$day->format('d')]['day'] = $day;
  58.                 $Holiday $this->holidayRepository->getHoliday($day);
  59.                 if($Holiday){
  60.                     $Date[$day->format('n')][$day->format('d')]['is_holiday'] = true;
  61.                 }else{
  62.                     $Date[$day->format('n')][$day->format('d')]['is_holiday'] = false;
  63.                 }
  64.             }
  65.         }
  66.         return [
  67.             'Date' => $Date,
  68.         ];
  69.     }
  70. }