<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller;
use Customize\Repository\ProductRepositoryCustomize;
use Eccube\Common\EccubeConfig;
use Eccube\Controller\AbstractController;
use Plugin\CourcesManagerPlugin\Repository\Admin\TjoCourseRepository;
use Plugin\EventsManagerPlugin\Repository\TjoEventRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Customize\Repository\DocumentsRepository;
class TopController extends AbstractController
{
/** @var EccubeConfig */
protected $eccubeConfig;
/** @var TjoCourseRepository */
protected $tjoCourseRepository;
/** @var TjoEventRepository */
protected $tjoEventRepository;
/** @var ProductRepositoryCustomize */
protected $productRepository;
/** @var DocumentsRepository */
protected $documentsRepository;
public function __construct(
EccubeConfig $eccubeConfig,
TjoCourseRepository $tjoCourseRepository,
TjoEventRepository $tjoEventRepository,
ProductRepositoryCustomize $productRepository,
DocumentsRepository $documentsRepository,
){
$this->eccubeConfig = $eccubeConfig;
$this->tjoCourseRepository = $tjoCourseRepository;
$this->tjoEventRepository = $tjoEventRepository;
$this->productRepository = $productRepository;
$this->documentsRepository = $documentsRepository;
}
/**
* @Route("/", name="homepage", methods={"GET"})
* @Template("index.twig")
*/
public function index()
{
$lat = $this->eccubeConfig['weathers']['lat'];
$lon = $this->eccubeConfig['weathers']['lon'];
try{
$weathers = file_get_contents('https://api.open-meteo.com/v1/forecast?latitude=' . $lat . '&longitude=' . $lon . '¤t=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');
$weathers = json_decode($weathers);
}catch(Exception $e){
dd($e);
}
$products = $this->productRepository->getOrderBy();
return [
'courses' => $this->tjoCourseRepository->getCourses(),
'events' => $this->tjoEventRepository->getEvents(),
'products' => $products,
'current_units' => $weathers->current_units,
'current' => $weathers->current,
'hourly_units' => $weathers->hourly_units,
'hourly' => $weathers->hourly,
'daily_units' => $weathers->daily_units,
'daily' => $weathers->daily,
'documents' => $this->documentsRepository->getDocuments(),
];
}
}