<?php
namespace Customize\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\Query\ResultSetMapping;
/* add */
use Eccube\Controller\AbstractController;
use Eccube\Entity\Product;
use Eccube\Repository\CustomerRepository;
use Eccube\Common\EccubeConfig;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Eccube\Service\MailService;
use Eccube\Service\TeikiService;
/* add2 reminde */
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Eccube\Form\Type\Front\ForgotType;
use Eccube\Form\Type\Front\PasswordResetType;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Eccube\Form\Type\SearchProductType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Eccube\Form\Type\AddCartType;
use Eccube\Event\EventArgs;
use Eccube\Event\EccubeEvents;
use Eccube\Repository\BaseInfoRepository;
use Google_Client;
use Google_Service_Calendar;
use Google_Service_Calendar_Event;
use Eccube\Form\Type\Front\PhotoType;
use Carbon\Carbon;
class custumEventController extends AbstractController
{
protected $BaseInfo;
protected $customerRepository;
protected $mailService;
/**
* SamplePageController constructor.
* @param \Eccube\Repository\BaseInfoRepository $baseInfoRepository
* @param \Eccube\Repository\CustomerRepository $customerRepository
* @param \Eccube\Service\MailService $mailService
*/
public function __construct(
\Eccube\Repository\BaseInfoRepository $baseInfoRepository,
\Eccube\Repository\CustomerRepository $customerRepository,
\Eccube\Service\MailService $mailService,
)
{
$this->BaseInfo = $baseInfoRepository->get();
$this->customerRepository = $customerRepository;
$this->mailService = $mailService;
}
/**
* @Route("/plan/2024sakura", name="sakura2024", methods={"GET"})
* @Template("Plan/2024sakura.twig")
*/
public function sakura2024()
{
try {
$this->session->set('sakura2004', "set");
//----------------------------------
//ここから下はカレンダー
//----------------------------------
// サービスオブジェクトを作成
$client = new Google_Client();
// サービスアカウント作成時にダウンロードしたjsonファイル
$aimJsonPath = './ornate-axiom-406706-fd999b268a9d.json';
// サービスオブジェクトを作成
$client = new Google_Client();
// このアプリケーション名
$client->setApplicationName('カレンダー操作テスト イベントの取得');
// ※ 注意ポイント: 権限の指定
// 予定を取得する時は Google_Service_Calendar::CALENDAR_READONLY
// 予定を追加する時は Google_Service_Calendar::CALENDAR_EVENTS
$client->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
// ユーザーアカウントのjsonを指定
$client->setAuthConfig($aimJsonPath);
// サービスオブジェクトの用意
$service = new Google_Service_Calendar($client);
// カレンダーID 2024桜イベントのカレンダー設定
$calendarId = 'f815c4cba3a22813d3bda95af18688b85cdbca97bd25e4c4e5bfb3fbd289d8e3@group.calendar.google.com';
// 取得時の詳細設定
// 日付を最短
$optParams = array(
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMax' => date('2024-04-08\T00:00:00\Z'),
);
$results = $service->events->listEvents($calendarId, $optParams);
//書式設定
foreach( $results->getItems() as $event) {
for($i=date('Ymd', strtotime( $event->start->dateTime)); $i<=date('Ymd', strtotime($event->end->dateTime)); $i++){
$tmp=date('Y/m/d', strtotime($i));
$res[$tmp][date('H',strtotime($event->start->dateTime))] = date('H',strtotime($event->start->dateTime));
}
}
//カレンダー開始日を設定
//+3 hourは、3時間前に時間判定するため
$today = date('Y/m/d',strtotime('+3 hour'));
$startDate = '2024/03/20';
if( $today > $startDate ) {
$startDate=$today;
}
//返却値
return [
'reserveInfo' => $res,
'startdate' => $startDate,
'nowdate' => date('Y/m/d',strtotime('+3 hour')),
'nowtime' => date('Hi',strtotime('+3 hour')),
'nextdate' => date('Y/m/d',strtotime('+1 day +3 hour')),
'next2date' => date('Y/m/d',strtotime('+2 day +3 hour')),
];
} catch (\Exception $e) {
// log_error('getFavorites Exception: ', $e->getMessage());
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/plan/2024sakura/reserved", name="2024sakura_reserved", methods={"POST"})
* @Template("Plan/2024sakura_reserved.twig")
*/
public function sakura2024_reserved()
{
try {
log_info('2024sakura_reserved 開始');
// if(!$this->session->get('sakura2004')) {
// return $this->redirectToRoute('homepage');
// }
// カレンダーID
$calendarId = 'f815c4cba3a22813d3bda95af18688b85cdbca97bd25e4c4e5bfb3fbd289d8e3@group.calendar.google.com';
$aimJsonPath = './ornate-axiom-406706-fd999b268a9d.json';
if($calendarId) {
// サービスオブジェクトを作成
$client = new Google_Client();
// このアプリケーション名
$client->setApplicationName('カレンダー操作テスト イベントの取得');
log_info('2024sakura_reserved 開始1');
// ※ 注意ポイント: 権限の指定
// 予定を取得する時は Google_Service_Calendar::CALENDAR_READONLY
// 予定を追加する時は Google_Service_Calendar::CALENDAR_EVENTS
$client->setScopes(Google_Service_Calendar::CALENDAR_EVENTS);
log_info('2024sakura_reserved 開始2');
// ユーザーアカウントのjsonを指定
$client->setAuthConfig($aimJsonPath);
log_info('2024sakura_reserved 開始3');
// サービスオブジェクトの用意
$service = new Google_Service_Calendar($client);
//日付と時間に分割
$year = substr($_POST['request'], 0, 4);
$month = substr($_POST['request'], 4, 2);
$day = substr($_POST['request'], 6, 2);
$hour = substr($_POST['request'], 8, 2);
$minute = substr($_POST['request'], 10, 2);
$start_datetime = new Carbon(sprintf("%s-%s-%s %s:%s:00", $year, $month, $day, $hour, $minute));
$end_datetime = new Carbon(sprintf("%s-%s-%s %s:%s:00", $year, $month, $day, $hour, $minute));
$end_datetime->addHour(2); //2時間後を設定
log_info('2024sakura_reserved 開始4');
$description = "name:".$_POST['name'];
log_info('2024sakura_reserved 開始5-1');
$description .= "<br>Country:".$_POST['country'];
log_info('2024sakura_reserved 開始5-2');
$description .= "<br>mail:".$_POST['email'];
log_info('2024sakura_reserved 開始5-3');
$description .= "<br>tel:".$_POST['telcode'].' '.$_POST['tel'];
log_info('2024sakura_reserved 開始5-4');
$description .= "<br>参加人数:".$_POST['participants'];
log_info('2024sakura_reserved 開始5-5');
log_info('2024sakura_reserved 開始5-6');
$description .= "<br>Transfer Option:".$_POST['transfer'];
log_info('2024sakura_reserved 開始5-7');
if (isset($_POST['pickup'])) {
$description .= "<br>pickup:".$_POST['pickup'];
} else {
$_POST['pickup']='';
}
log_info('2024sakura_reserved 開始5-8');
$description .= "<br>コメント:".$_POST['message'];
log_info('2024sakura_reserved 開始6');
$event = new Google_Service_Calendar_Event(array(
'summary' => "2024 SAKURA name:".$_POST['name'],
'start' => array(
'dateTime' => $start_datetime,
'timeZone' => 'Asia/Tokyo',
),
'end' => array(
'dateTime' => $end_datetime,
'timeZone' => 'Asia/Tokyo',
),
'description' => $description,
));
log_info('2024sakura_reserved 開始7');
$event = $service->events->insert($calendarId, $event);
log_info('2024sakura_reserved 開始8');
}
//
// INSERT INTO dtb_order(name01, email, phone_number, subtotal, tax, total, payment_total, payment_method, create_date, update_date, order_date, currency_code, add_point, use_point, order_status_id, discriminator_type) VALUES ('TEST', 'yell.616@gmail.com', '0000000000', '160000', '0', '160000', '160000', '代金引換', now(), now(), now(), 'JPY', '0', '0', '1', 'order');
//メール送信、17は「dtb_mail_template」のID
$this->mailService->sendReserveRequest($_POST,17);
$this->session->remove('sakura2004');
log_info('2024sakura_reserved 終了');
return [
];
} catch (\Exception $e) {
log_info('2024sakura_reserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/plan/limited", name="limited", methods={"GET"})
* @Template("Plan/limited.twig")
*/
public function limited()
{
try {
$this->session->set('limited', "set");
//----------------------------------
//ここから下はカレンダー
//----------------------------------
// サービスオブジェクトを作成
$client = new Google_Client();
// サービスアカウント作成時にダウンロードしたjsonファイル
$aimJsonPath = './ornate-axiom-406706-fd999b268a9d.json';
// サービスオブジェクトを作成
$client = new Google_Client();
// このアプリケーション名
$client->setApplicationName('カレンダー操作テスト イベントの取得');
// ※ 注意ポイント: 権限の指定
// 予定を取得する時は Google_Service_Calendar::CALENDAR_READONLY
// 予定を追加する時は Google_Service_Calendar::CALENDAR_EVENTS
$client->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
// ユーザーアカウントのjsonを指定
$client->setAuthConfig($aimJsonPath);
// サービスオブジェクトの用意
$service = new Google_Service_Calendar($client);
// カレンダーID 2024桜イベントのカレンダー設定
$calendarId = 'cd71e0a784b8b714563997b9e6ddafab3fd57ee1f4f9e543a15861610afb9a22@group.calendar.google.com';
// 取得時の詳細設定
// 日付を最短
$optParams = array(
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMax' => date('c',strtotime("+3 month")), //3か月分
);
$results = $service->events->listEvents($calendarId, $optParams);
//書式設定
$res['calendar']=true;
foreach( $results->getItems() as $event) {
for($i=date('Ymd', strtotime( $event->start->dateTime)); $i<=date('Ymd', strtotime($event->end->dateTime)); $i++){
$year = substr($i, 0,4);
$month = substr($i, 4,2);
$day = substr($i, 6,2);
if(checkdate ( $month , $day , $year )) {
$tmp=date('Y-m-d', strtotime($i));
$res[$tmp] = $tmp;
}
}
}
//返却値
return [
'events' => json_encode($res),
'calendar_start_date' => date('Y-m-d', strtotime('+2 day')),
];
} catch (\Exception $e) {
// log_error('getFavorites Exception: ', $e->getMessage());
return [
'testtest' => $e->getMessage(),
'events' => json_encode($res),
];
}
}
/**
* @Route("/plan/limited/reserved", name="limited_reserved", methods={"POST"})
* @Template("Plan/limited_reserved.twig")
*/
public function limited_reserved()
{
try {
log_info('limited_reserved 開始');
// if(!$this->session->get('limited')) {
// return $this->redirectToRoute('homepage');
// }
// カレンダーID
$calendarId = "cd71e0a784b8b714563997b9e6ddafab3fd57ee1f4f9e543a15861610afb9a22@group.calendar.google.com";
$aimJsonPath = './ornate-axiom-406706-fd999b268a9d.json';
if($calendarId) {
// サービスオブジェクトを作成
$client = new Google_Client();
// このアプリケーション名
$client->setApplicationName('カレンダー操作テスト イベントの取得');
// ※ 注意ポイント: 権限の指定
// 予定を取得する時は Google_Service_Calendar::CALENDAR_READONLY
// 予定を追加する時は Google_Service_Calendar::CALENDAR_EVENTS
$client->setScopes(Google_Service_Calendar::CALENDAR_EVENTS);
// ユーザーアカウントのjsonを指定
$client->setAuthConfig($aimJsonPath);
// サービスオブジェクトの用意
$service = new Google_Service_Calendar($client);
log_info('limited_reserved 開始4');
$description = "date:".$_POST['startdate'];
$description .= "<br>name:".$_POST['name'];
$description .= "<br>Country:".$_POST['country'];
$description .= "<br>mail:".$_POST['email'];
$description .= "<br>tel:".$_POST['telcode'].' '.$_POST['tel'];
$description .= "<br>参加人数:".$_POST['participants'];
$description .= "<br>pickup:".$_POST['pickup'];
$description .= "<br>コメント:".$_POST['message'];
$start_datetime = new Carbon($_POST['startdate']." 13:00:00");
$end_datetime = new Carbon($_POST['startdate']." 20:00:00");
$event = new Google_Service_Calendar_Event(array(
'summary' => "Limited - name:".$_POST['name'],
'start' => array(
'dateTime' => $start_datetime,
'timeZone' => 'Asia/Tokyo',
),
'end' => array(
'dateTime' => $end_datetime,
'timeZone' => 'Asia/Tokyo',
),
'description' => $description,
));
log_info('limited_reserved $start_datetime:'.$start_datetime);
log_info('limited_reserved $end_datetime:'.$end_datetime);
log_info('limited_reserved $description:'.$description);
log_info('limited_reserved 開始7');
$event = $service->events->insert($calendarId, $event);
log_info('limited_reserved 開始8');
}
//
//メール送信、24は「dtb_mail_template」のID
$this->mailService->sendReserveRequest($_POST,24);
$this->session->remove('limited');
log_info('limited_reserved 終了');
return [
'testtest' => '',
];
} catch (\Exception $e) {
log_info('limited_reserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/plan/fireworks", name="fireworks", methods={"GET"})
* @Template("Plan/fireworks.twig")
*/
public function fireworks()
{
try {
$this->session->set('limited', "set");
//返却値
return [
];
} catch (\Exception $e) {
// log_error('getFavorites Exception: ', $e->getMessage());
return [
'testtest' => $e->getMessage(),
'events' => json_encode($res),
];
}
}
/**
* @Route("/plan/fireworks/reserved", name="fireworks_reserved", methods={"POST"})
* @Template("Plan/fireworks_reserved.twig")
*/
public function fireworks_reserved()
{
try {
log_info('fireworks_reserved 開始');
if(!$this->session->get('limited')) {
return $this->redirectToRoute('homepage');
}
//メール送信、24は「dtb_mail_template」のID
$this->mailService->sendReserveRequest($_POST,25);
$this->session->remove('limited');
log_info('limited_reserved 終了');
return [
'testtest' => '',
];
} catch (\Exception $e) {
log_info('limited_reserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/plan/cruisefireworks", name="cruisefireworks", methods={"GET"})
* @Template("Plan/cruisefireworks.twig")
*/
public function cruisefireworks()
{
try {
$this->session->set('limited', "set");
//返却値
return [
];
} catch (\Exception $e) {
// log_error('getFavorites Exception: ', $e->getMessage());
return [
'testtest' => $e->getMessage(),
'events' => json_encode($res),
];
}
}
/**
* @Route("/plan/cruisefireworks/reserved", name="cruisefireworks_reserved", methods={"POST"})
* @Template("Plan/cruisefireworks_reserved.twig")
*/
public function cruisefireworks_reserved()
{
try {
log_info('cruisefireworks_reserved 開始');
if(!$this->session->get('limited')) {
return $this->redirectToRoute('homepage');
}
//メール送信、24は「dtb_mail_template」のID
$this->mailService->sendReserveRequest($_POST,25);
$this->session->remove('limited');
log_info('limited_reserved 終了');
return [
'testtest' => '',
];
} catch (\Exception $e) {
log_info('limited_reserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/plan/carlimited", name="carlimited", methods={"GET"})
* @Template("Plan/carlimited.twig")
*/
public function carlimited()
{
try {
$this->session->set('limited', "set");
//返却値
return [
];
} catch (\Exception $e) {
// log_error('getFavorites Exception: ', $e->getMessage());
return [
'testtest' => $e->getMessage(),
'events' => json_encode($res),
];
}
}
/**
* @Route("/plan/carlimited/reserved", name="carlimited_reserved", methods={"POST"})
* @Template("Plan/carlimited_reserved.twig")
*/
public function carlimited_reserved()
{
try {
log_info('carlimited_reserved 開始');
if(!$this->session->get('limited')) {
return $this->redirectToRoute('homepage');
}
//メール送信、28は「dtb_mail_template」のID
$this->mailService->sendReserveRequest($_POST,28);
$this->session->remove('limited');
log_info('carlimited_reserved 終了');
return [
'testtest' => '',
];
} catch (\Exception $e) {
log_info($e);
log_info('carlimited_reserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
}