app/Customize/Controller/TopController.php line 55

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Controller;
  13. use Customize\Repository\ProductRepositoryCustomize;
  14. use Eccube\Common\EccubeConfig;
  15. use Eccube\Controller\AbstractController;
  16. use Plugin\CourcesManagerPlugin\Repository\Admin\TjoCourseRepository;
  17. use Plugin\EventsManagerPlugin\Repository\TjoEventRepository;
  18. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Customize\Repository\DocumentsRepository;
  21. class TopController extends AbstractController
  22. {
  23.     /** @var EccubeConfig */
  24.     protected $eccubeConfig;    
  25.     /** @var TjoCourseRepository */
  26.     protected $tjoCourseRepository;
  27.     /** @var TjoEventRepository */
  28.     protected $tjoEventRepository;
  29.     /** @var ProductRepositoryCustomize */
  30.     protected $productRepository;
  31.     /** @var DocumentsRepository */
  32.     protected $documentsRepository;
  33.     public function __construct(
  34.         EccubeConfig            $eccubeConfig,
  35.         TjoCourseRepository $tjoCourseRepository,
  36.         TjoEventRepository $tjoEventRepository,
  37.         ProductRepositoryCustomize $productRepository,
  38.         DocumentsRepository $documentsRepository,
  39.     ){
  40.         $this->eccubeConfig             $eccubeConfig;
  41.         $this->tjoCourseRepository      $tjoCourseRepository;
  42.         $this->tjoEventRepository       $tjoEventRepository;
  43.         $this->productRepository        $productRepository;
  44.         $this->documentsRepository      $documentsRepository;
  45.     }
  46.     /**
  47.      * @Route("/", name="homepage", methods={"GET"})
  48.      * @Template("index.twig")
  49.      */
  50.     public function index()
  51.     {
  52.         $lat $this->eccubeConfig['weathers']['lat'];
  53.         $lon $this->eccubeConfig['weathers']['lon'];
  54.         
  55.         try{
  56.             $weathers file_get_contents('https://api.open-meteo.com/v1/forecast?latitude=' $lat '&longitude=' $lon '&current=temperature_2m,apparent_temperature,precipitation,weather_code,wind_speed_10m,wind_direction_10m&hourly=temperature_2m,apparent_temperature,precipitation_probability,precipitation,weather_code&daily=weather_code,temperature_2m_max,temperature_2m_min,sunrise,sunset,precipitation_sum,precipitation_probability_max,wind_speed_10m_max&timezone=Asia%2FTokyo');
  57.             $weathers json_decode($weathers);
  58.         }catch(Exception $e){
  59.             dd($e);
  60.         }
  61.         $products $this->productRepository->getOrderBy();
  62.         
  63.         return [
  64.             'courses'       => $this->tjoCourseRepository->getCourses(),
  65.             'events'        => $this->tjoEventRepository->getEvents(),
  66.             'products'      => $products,
  67.             'current_units' => $weathers->current_units,
  68.             'current'       => $weathers->current,
  69.             'hourly_units'  => $weathers->hourly_units,
  70.             'hourly'        => $weathers->hourly,
  71.             'daily_units'   => $weathers->daily_units,
  72.             'daily'         => $weathers->daily,
  73.             'documents'     => $this->documentsRepository->getDocuments(),
  74.         ];
  75.     }
  76. }