<?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 custumPageController 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("/products", name="product", methods={"GET"})
* @Template("Product/index.twig")
*/
public function product()
{
try {
//DBコネクション
$conn = $this->entityManager->getConnection();
//お気に入り情報
$query =<<<__LONG_STRRING__
SELECT dtb_product.id,dtb_product.name, t2.file_name,dtb_product.item14,dtb_product.item19,dtb_product.item22, dtb_product.search_word,dtb_product.item16 FROM dtb_product
left join (select product_id, file_name from dtb_product_image where (product_id, sort_no ) in (select product_id ,min(sort_no) as price from dtb_product_image group by product_id)) t2 on dtb_product.id =t2.product_id
__LONG_STRRING__;
//SQL実行
// $stmt = $conn->prepare($query);
$stmt = $conn->query($query);
$rows = $stmt->fetchAll();
$products=[];
foreach($rows as $val) {
$products[$val['id']]=$val;
}
//返却値
return [
'products' => $products,
];
} catch (\Exception $e) {
// log_error('getFavorites Exception: ', $e->getMessage());
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/photo", name="photo", methods={"GET"})
* @Template("Photo/index.twig")
*/
public function photo()
{
try {
//DBコネクション
$conn = $this->entityManager->getConnection();
//お気に入り情報
$query =<<<__LONG_STRRING__
SELECT dtb_product.id,dtb_product.name, t2.file_name, dtb_product.item13, dtb_product.item14 FROM dtb_product
left join (select product_id, file_name ,min(sort_no) from dtb_product_image group by product_id) t2 on dtb_product.id =t2.product_id
__LONG_STRRING__;
//SQL実行
$stmt = $conn->query($query);
$rows = $stmt->fetchAll();
$products=[];
foreach($rows as $val) {
$products[$val['id']]=$val;
}
//返却値
$timemin=2;
return [
'products' => $products,
'calendar_start_date' => date('Y-m-d', strtotime('+'.$timemin.'day')),
'calendar_end_date' => date('Y-m-d', strtotime('+3 month')),
];
} catch (\Exception $e) {
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/photo/reserved", name="photo_reserved", methods={"POST"})
* @Template("Photo/reserved.twig")
*/
public function photoReserved()
{
try {
// カレンダーID
$calendarId = $_POST['calendarId'];
$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_EVENTS);
// ユーザーアカウントのjsonを指定
$client->setAuthConfig($aimJsonPath);
// サービスオブジェクトの用意
$service = new Google_Service_Calendar($client);
$start_datetime = new Carbon($_POST['date'].' '.$_POST['starttime']);
$end_datetime = new Carbon($_POST['date'].' '.$_POST['starttime']);
$end_datetime->addHour(2);
$shootinglocation=$_POST['shootinglocation'];
if(!$shootinglocation) {
$shootinglocation=$_POST['shootinglocationname'];
}
$description = "日時:".$_POST['date'].' '.$_POST['starttime'];
$description .= "<br>name:".$_POST['name'];
$description .= "<br>Country:".$_POST['country'];
$description .= "<br>mail:".$_POST['email'];
$description .= "<br>tel:".$_POST['tel'];
$description .= "<br>参加人数:".$_POST['participants'];
$description .= "<br>集合場所:".$_POST['pickup'];
$description .= "<br>撮影場所:".$shootinglocation;
$description .= "<br>体験運転:".$_POST['experience'];
$description .= "<br>コメント:".$_POST['message'];
$event = new Google_Service_Calendar_Event(array(
'summary' => "name:".$_POST['name'],
'start' => array(
'dateTime' => $start_datetime,
'timeZone' => 'Asia/Tokyo',
),
'end' => array(
'dateTime' => $end_datetime,
'timeZone' => 'Asia/Tokyo',
),
'description' => $description,
));
$event = $service->events->insert($calendarId, $event);
$this->mailService->sendReserveRequest($_POST,10);
return [
];
} catch (\Exception $e) {
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* 商品詳細画面.
*
* @Route("/photo/detail/{id}", name="photo_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Photo/detail.twig")
* @ParamConverter("Photo", options={"repository_method" = "findWithSortedClassCategories"})
*
* @param Request $request
* @param Product $Product
*
* @return array
*/
public function detail(Request $request, Product $Product)
{
if (!$this->checkVisibility($Product)) {
throw new NotFoundHttpException();
}
//----------------------------------
//ここから下はカレンダー
//----------------------------------
// サービスオブジェクトを作成
$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
// 商品マスタから取得
$calendarId = '4f27c24687328a69f1c56a92418269c0eec7b0cbf324dfebdd66b1468b16e540@group.calendar.google.com';
if($Product->getItem13()) {
$calendarId = $Product->getItem13();
}
// 取得時の詳細設定
// 日付を最短
$timemin=1;
if($Product->getItem15()) {
$timemin=$Product->getItem15()-1;
}
$optParams = array(
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMax' => date('c',strtotime("+3 month")), //3か月分
'timeMin' => date('c', strtotime('+'.$timemin.' day')), //1週間後から
);
$results = $service->events->listEvents($calendarId, $optParams);
//書式設定
$res=[];
foreach( $results->getItems() as $event) {
// $tDate=date('Y-m-d',strtotime($start = $event->start->dateTime));
// $tDate=date('Y-m-d',strtotime($start = $event->end->dateTime));
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;
}
}
// $res[$tDate][]=date('H',strtotime($start = $event->start->dateTime));
// $res[$tDate][]=date('H',strtotime($start = $event->end->dateTime));
}
//フロントカレンダー用に+1日する。
$timemin+=1;
return [
'title' => $Product->getName(),
'subtitle' => $Product->getName(),
'Product' => $Product,
'events' => json_encode($res),
'calendar_start_date' => date('Y-m-d', strtotime('+'.$timemin.'day')),
];
}
/**
* @Route("/drive", name="drive", methods={"GET"})
* @Template("Drive/index.twig")
*/
public function drive()
{
try {
//DBコネクション
$conn = $this->entityManager->getConnection();
//お気に入り情報
$query =<<<__LONG_STRRING__
SELECT dtb_product.id,dtb_product.name, t2.file_name, dtb_product.item13, dtb_product.item14, dtb_product.search_word FROM dtb_product
left join (select product_id, file_name from dtb_product_image where (product_id, sort_no ) in (select product_id ,min(sort_no) as price from dtb_product_image group by product_id)) t2 on dtb_product.id =t2.product_id
__LONG_STRRING__;
//SQL実行
$stmt = $conn->query($query);
$rows = $stmt->fetchAll();
$products=[];
foreach($rows as $val) {
$products[$val['id']]=$val;
}
//返却値
$timemin=2;
return [
'products' => $products,
'calendar_start_date' => date('Y-m-d', strtotime('+'.$timemin.'day')),
'calendar_end_date' => date('Y-m-d', strtotime('+3 month')),
];
} catch (\Exception $e) {
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/drive/reserved", name="drive_reserved", methods={"POST"})
* @Template("Drive/reserved.twig")
*/
public function driveReserved()
{
try {
// カレンダーID
$calendarId = $_POST['calendarId'];
$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);
$start_datetime = new Carbon($_POST['date'].' '.$_POST['starttime']);
$end_datetime = new Carbon($_POST['date'].' '.$_POST['starttime']);
$end_datetime->addHour($_POST['time']);
$shootinglocation=$_POST['shootinglocation'];
if(!$shootinglocation) {
$shootinglocation=$_POST['shootinglocationname'];
}
log_info('driveReserved 開始1-1');
$description = "日時:".$_POST['date'].' '.$_POST['starttime'];
$description = "Car Experience time:".$_POST['time'];
$description .= "<br>name:".$_POST['name'];
$description .= "<br>Country:".$_POST['country'];
log_info('driveReserved 開始1-2');
$description .= "<br>mail:".$_POST['email'];
$description .= "<br>tel:".$_POST['tel'];
$description .= "<br>参加人数:".$_POST['participants'];
$description .= "<br>集合場所:".$_POST['pickup'];
log_info('driveReserved 開始1-3');
$description .= "<br>Desired Prefix Menu:".$shootinglocation;
$description .= "<br>Photo Shoot Option by photographer:".$_POST['option'];
$description .= "<br>コメント:".$_POST['message'];
log_info('driveReserved 開始1-4');
$event = new Google_Service_Calendar_Event(array(
'summary' => "name:".$_POST['name'],
'start' => array(
'dateTime' => $start_datetime,
'timeZone' => 'Asia/Tokyo',
),
'end' => array(
'dateTime' => $end_datetime,
'timeZone' => 'Asia/Tokyo',
),
'description' => $description,
));
log_info('driveReserved 開始1-5');
$event = $service->events->insert($calendarId, $event);
}
//メール送信、12は「dtb_mail_template」のID
log_info('driveReserved 開始2-1');
$this->mailService->sendReserveRequest($_POST,12);
return [
];
} catch (\Exception $e) {
log_info('driveReserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* 商品詳細画面.
*
* @Route("/drive/detail/{id}", name="drive_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Drive/detail.twig")
* @ParamConverter("Drive", options={"repository_method" = "findWithSortedClassCategories"})
*
* @param Request $request
* @param Product $Product
*
* @return array
*/
public function driveDetail(Request $request, Product $Product)
{
if (!$this->checkVisibility($Product)) {
throw new NotFoundHttpException();
}
//----------------------------------
//ここから下はカレンダー
//----------------------------------
// サービスオブジェクトを作成
$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
// 商品マスタから取得
$calendarId = '4f27c24687328a69f1c56a92418269c0eec7b0cbf324dfebdd66b1468b16e540@group.calendar.google.com';
if($Product->getItem13()) {
$calendarId = $Product->getItem13();
}
// 取得時の詳細設定
// 日付を最短
$timemin=1;
if($Product->getItem15()) {
$timemin=$Product->getItem15()-1;
}
$optParams = array(
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMax' => date('c',strtotime("+3 month")),
);
$results = $service->events->listEvents($calendarId, $optParams);
//書式設定
$res=[];
foreach( $results->getItems() as $event) {
// $tDate=date('Y-m-d',strtotime($start = $event->start->dateTime));
// $tDate=date('Y-m-d',strtotime($start = $event->end->dateTime));
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;
}
}
// $res[$tDate][]=date('H',strtotime($start = $event->start->dateTime));
// $res[$tDate][]=date('H',strtotime($start = $event->end->dateTime));
}
//フロントカレンダー用に+1日する。
$timemin+=1;
return [
'title' => $Product->getName(),
'subtitle' => $Product->getName(),
'Product' => $Product,
'events' => json_encode($res),
'calendar_start_date' => date('Y-m-d', strtotime('+'.$timemin.'day')),
];
}
/**
* @Route("/rental", name="rental", methods={"GET"})
* @Template("Rental/index.twig")
*/
public function rental()
{
try {
//DBコネクション
$conn = $this->entityManager->getConnection();
//お気に入り情報
$query =<<<__LONG_STRRING__
SELECT dtb_product.id,dtb_product.name, t2.file_name, dtb_product.item11, dtb_product.item13, dtb_product.item14, dtb_product.item18, dtb_product.item17, dtb_product.item16, dtb_product.item19,dtb_product.item22,t3.category_id,dtb_product.search_word FROM dtb_product
left join (select product_id, file_name from dtb_product_image where (product_id, sort_no ) in (select product_id ,min(sort_no) as price from dtb_product_image group by product_id)) t2 on dtb_product.id =t2.product_id
left join (select product_id, category_id from dtb_product_category where category_id=8 or category_id=9 or category_id=10 or category_id=16 ) t3 on dtb_product.id =t3.product_id
__LONG_STRRING__;
//SQL実行
$stmt = $conn->query($query);
$rows = $stmt->fetchAll();
$products=[];
foreach($rows as $val) {
$products[$val['id']]=$val;
}
//返却値
$timemin=2;
return [
'products' => $products,
'calendar_start_date' => date('Y-m-d', strtotime('+'.$timemin.'day')),
'calendar_end_date' => date('Y-m-d', strtotime('+3 month')),
];
} catch (\Exception $e) {
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/rental/reserved", name="rental_reserved", methods={"POST"})
* @Template("Rental/reserved.twig")
*/
public function rentalReserved()
{
try {
log_info('rentalReserved 開始');
if(!$this->session->get('rental.car')) {
return $this->redirectToRoute('homepage');
}
// カレンダーID
$calendarId = $_POST['calendarId'];
$aimJsonPath = './ornate-axiom-406706-fd999b268a9d.json';
if($calendarId) {
// サービスオブジェクトを作成
$client = new Google_Client();
// このアプリケーション名
$client->setApplicationName('カレンダー操作テスト イベントの取得');
log_info('rentalReserved 開始1');
// ※ 注意ポイント: 権限の指定
// 予定を取得する時は Google_Service_Calendar::CALENDAR_READONLY
// 予定を追加する時は Google_Service_Calendar::CALENDAR_EVENTS
$client->setScopes(Google_Service_Calendar::CALENDAR_EVENTS);
log_info('rentalReserved 開始2');
// ユーザーアカウントのjsonを指定
$client->setAuthConfig($aimJsonPath);
log_info('rentalReserved 開始3');
// サービスオブジェクトの用意
$service = new Google_Service_Calendar($client);
$start_datetime = new Carbon($_POST['startdate'].' '.$_POST['starttime']);
$end_datetime = new Carbon($_POST['enddate'].' '.$_POST['endtime']);
log_info('rentalReserved 開始4');
log_info('rentalReserved 開始5');
$description = "Type:".$_POST['type'];
$description .= "<br>Rental Dates:".$_POST['startdate'].$_POST['starttime']."-".$_POST['enddate'].$_POST['endtime'];
if(!$_POST['supercarflg']) {
$description .= "<br>Destination:".$_POST['destination_name']." ".$_POST['otherkm']."km";
}
$description .= "<br>estimates:".$_POST['estimate'];
$description .= "<br>";
$description .= "<br>name:".$_POST['name'];
$description .= "<br>Country:".$_POST['country'];
$description .= "<br>age:".$_POST['age'];
$description .= "<br>International driving permit(IDP):".$_POST['idp'];
$description .= "<br>mail:".$_POST['email'];
$description .= "<br>tel:".$_POST['telcode'].' '.$_POST['tel'];
$description .= "<br>集合場所:".$_POST['pickup'];
$description .= "<br>降車場所:".$_POST['dropoff'];
$description .= "<br>Lead Car Option:".$_POST['option'];
$description .= "<br>参加人数:".$_POST['participants'];
$description .= "<br>コメント:".$_POST['message'];
log_info('rentalReserved 開始6');
$event = new Google_Service_Calendar_Event(array(
'summary' => $_POST['carname'].':'.$_POST['name'],
'start' => array(
'dateTime' => $start_datetime,
'timeZone' => 'Asia/Tokyo',
),
'end' => array(
'dateTime' => $end_datetime,
'timeZone' => 'Asia/Tokyo',
),
'description' => $description,
));
log_info('rentalReserved 開始7');
$event = $service->events->insert($calendarId, $event);
log_info('rentalReserved 開始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');
//メール送信、11は「dtb_mail_template」のID
$this->mailService->sendReserveRequest($_POST,11);
$this->session->remove('rental.car');
log_info('rentalReserved 終了');
return [
];
} catch (\Exception $e) {
log_info('rentalReserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/rental/comfirm", name="rental_comfirm", methods={"POST"})
* @Template("Rental/comfirm.twig")
*/
public function rentalConfirm()
{
$this->session->set('rental.car', $_POST);
try {
// カレンダーID
return [
'post'=>$_POST,
];
} catch (\Exception $e) {
log_info('rentalReserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* 商品詳細画面.
*
* @Route("/rental/detail/{id}", name="rental_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Rental/detail.twig")
* @ParamConverter("Rental", options={"repository_method" = "findWithSortedClassCategories"})
*
* @param Request $request
* @param Product $Product
*
* @return array
*/
public function rentalDetail(Request $request, Product $Product)
{
if (!$this->checkVisibility($Product)) {
throw new NotFoundHttpException();
}
//----------------------------------
//ここから下はカレンダー
//----------------------------------
// サービスオブジェクトを作成
$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
// 商品マスタから取得
$calendarId = '';
if($Product->getItem13()) {
$calendarId = $Product->getItem13();
}
// 取得時の詳細設定
// 日付を最短
$res['calendar']=false;
$timemin=1;
if($calendarId) {
$res['calendar']=true;
if($Product->getItem15()) {
$timemin=$Product->getItem15()-1;
}
$optParams = array(
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMax' => date('c',strtotime("+3 month")), //3か月分
);
$results = $service->events->listEvents($calendarId, $optParams);
//書式設定
foreach( $results->getItems() as $event) {
// $tDate=date('Y-m-d',strtotime($start = $event->start->dateTime));
// $tDate=date('Y-m-d',strtotime($start = $event->end->dateTime));
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;
}
}
// $res[$tDate][]=date('H',strtotime($start = $event->start->dateTime));
// $res[$tDate][]=date('H',strtotime($start = $event->end->dateTime));
}
}
//フロントカレンダー用に+1日する。
$timemin+=1;
return [
'title' => $Product->getName(),
'subtitle' => $Product->getName(),
'Product' => $Product,
'events' => json_encode($res),
'calendar_start_date' => date('Y-m-d', strtotime('+'.$timemin.'day')),
];
}
/**
* @Route("/help/company", name="help_company", methods={"GET"})
* @Template("Help/company.twig")
*/
public function company()
{
return [];
}
/**
* @Route("/help/club", name="help_club", methods={"GET"})
* @Template("Help/club.twig")
*/
public function club()
{
return [];
}
/**
* @Route("/plan/case01", name="plan_case01", methods={"GET"})
* @Template("Plan/case01.twig")
*/
public function case01()
{
return [];
}
/**
* @Route("/plan/case02", name="plan_case02", methods={"GET"})
* @Template("Plan/case02.twig")
*/
public function case02()
{
return [];
}
/**
* @Route("/plan/case03", name="plan_case03", methods={"GET"})
* @Template("Plan/case03.twig")
*/
public function case03(){ return []; }
/**
* @Route("/plan/case04", name="plan_case04", methods={"GET"})
* @Template("Plan/case04.twig")
*/
public function case04(){ return []; }
/**
* @Method("GET")
* @Route("/plan/{id}", name="plan_detail", methods={"GET"}))
* @Template("Plan/detail.twig")
*/
public function planMethod($id)
{
require_once('../../wpsite/wp-load.php');
$post = get_post($id);
$array = array(
"id" => $post->ID,
"title" => get_field('title_en',$post->ID),
"main_img" => get_field('main_img',$post->ID)['url'],
"sp_main_img" => get_field('sp_main_img',$post->ID)['url'],
"detail_title" => get_field('detail_title_en',$post->ID),
"list_text" => get_field('list_text_en',$post->ID),
"main_text" => get_field('main_text_en',$post->ID),
"css" => get_field('css',$post->ID),
);
for($i=1; $i <= 11; $i++) {
$array['img_'.$i] = get_field('img_'.$i, $post->ID);
$array['title_'.$i] = get_field('title_'.$i.'_en', $post->ID);
$array['text_'.$i] = get_field('text_'.$i.'_en', $post->ID);
}
return [
'WpPosts' => $array,
];
}
/**
* @Method("GET")
* @Route("/news/{id}", name="news_detail", methods={"GET"}))
* @Template("News/detail.twig")
*/
public function newsMethod($id)
{
require_once('../../wpsite/wp-load.php');
$post = get_post($id);
//明細行取得
$array = array(
"id" => $post->ID,
"title" => get_field('title_en',$post->ID),
"detail_title" => get_field('detail_title_en',$post->ID),
"main_img" => get_field('main_img',$post->ID)['url'],
"main_text" => get_field('main_text_en',$post->ID),
);
//明細行取得
for($i=1; $i <= 10; $i++) {
$array['img_'.$i] = get_field('img_'.$i, $post->ID);
$array['img_desc_'.$i] = get_field('img_desc_'.$i.'_en', $post->ID);
$array['title_'.$i] = get_field('title_'.$i.'_en', $post->ID);
$array['text_'.$i] = get_field('text_'.$i.'_en', $post->ID);
}
return [
'WpPosts' => $array,
];
}
/**
* @Route("/payment", name="payment", methods={"GET"})
* @Template("Payment/index.twig")
*/
public function payment()
{
return [];
}
/**
* @Route("/experience", name="experience", methods={"GET"})
* @Template("Experience/index.twig")
*/
public function experience()
{
return [];
}
/**
* @Route("/service", name="service", methods={"GET"})
* @Template("Service/index.twig")
*/
public function service()
{
return [];
}
/**
* 閲覧可能な商品かどうかを判定
*
* @param Product $Product
*
* @return boolean 閲覧可能な場合はtrue
*/
protected function checkVisibility(Product $Product)
{
$is_admin = $this->session->has('_security_admin');
// 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能.
if (!$is_admin) {
// 在庫なし商品の非表示オプションが有効な場合.
// if ($this->BaseInfo->isOptionNostockHidden()) {
// if (!$Product->getStockFind()) {
// return false;
// }
// }
// 公開ステータスでない商品は表示しない.
if ($Product->getStatus()->getId() !== constant('Eccube\\Entity\\Master\\ProductStatus::DISPLAY_SHOW')) {
return false;
}
}
return true;
}
/**
* @Route("/ebike/spots", name="ebike_spots", methods={"GET"})
* @Template("Ebike/spots.twig")
*/
public function ebikespots()
{
return [];
}
/**
* 商品詳細画面.
*
* @Route("/ebike/{id}", name="ebike_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Ebike/detail.twig")
* @ParamConverter("Ebike", options={"repository_method" = "findWithSortedClassCategories"})
*
* @param Request $request
* @param Product $Product
*
* @return array
*/
public function ebike(Request $request, Product $Product)
{
$this->session->set('rental.ebike', "set");
if (!$this->checkVisibility($Product)) {
throw new NotFoundHttpException();
}
//----------------------------------
//ここから下はカレンダー
//----------------------------------
// サービスオブジェクトを作成
$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
// 商品マスタから取得
$calendarId = '';
if($Product->getItem13()) {
$calendarId = $Product->getItem13();
}
// 取得時の詳細設定
// 日付を最短
$res['calendar']=false;
$tmp4=[];
$timemin=1;
if($calendarId) {
$res['calendar']=true;
if($Product->getItem15()) {
$timemin=$Product->getItem15()-1;
}
$optParams = array(
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMax' => date('c',strtotime("+3 month")), //3か月分
);
$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++){
$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));
$cnt=0;
if(array_key_exists($tmp,$res)) {
//日付の配列にデータがある場合、件数を取得
$cnt=$res[$tmp];
}
$res[$tmp] = $cnt+(int)$event->location;
}
}
}
}
//フロントカレンダー用に+1日する。
$timemin+=1;
return [
'title' => $Product->getName(),
'subtitle' => $Product->getName(),
'Product' => $Product,
'events' => json_encode($res),
'calendar_start_date' => date('Y-m-d', strtotime('+'.$timemin.'day')),
];
}
/**
* @Route("/ebike/reserved", name="ebike_reserved", methods={"POST"})
* @Template("Ebike/reserved.twig")
*/
public function ebikeReserved()
{
try {
if(!$this->session->get('rental.ebike')) {
return $this->redirectToRoute('homepage');
}
log_info('ebikeReserved 開始');
// カレンダーID
$calendarId = $_POST['calendarId'];
$aimJsonPath = './ornate-axiom-406706-fd999b268a9d.json';
if($calendarId) {
// サービスオブジェクトを作成
$client = new Google_Client();
// このアプリケーション名
$client->setApplicationName('カレンダー操作テスト イベントの取得');
log_info('ebikeReserved 開始1');
// ※ 注意ポイント: 権限の指定
// 予定を取得する時は Google_Service_Calendar::CALENDAR_READONLY
// 予定を追加する時は Google_Service_Calendar::CALENDAR_EVENTS
$client->setScopes(Google_Service_Calendar::CALENDAR_EVENTS);
log_info('ebikeReserved 開始2');
// ユーザーアカウントのjsonを指定
$client->setAuthConfig($aimJsonPath);
log_info('ebikeReserved 開始3');
// サービスオブジェクトの用意
$service = new Google_Service_Calendar($client);
$start_datetime = new Carbon($_POST['date'].' '.$_POST['starttime']);
$end_datetime = new Carbon($_POST['date'].' '.$_POST['starttime']);
$time=$_POST['time'];
if($_POST['time']) {
$end_datetime->addHour($time);
$time.=' hours';
}
log_info('ebikeReserved 開始4');
$description = "日時:".$_POST['date'].' '.$_POST['starttime'];
$description .= "<br>レンタル時間:".$_POST['time'];
$description .= "<br>units:".$_POST['units'];
$description .= "<br>name:".$_POST['name'];
$description .= "<br>Country:".$_POST['country'];
$description .= "<br>mail:".$_POST['email'];
$description .= "<br>tel:".$_POST['tel'];
$description .= "<br>コメント:".$_POST['message'];
log_info('ebikeReserved 開始5');
//カレンダー設定
$event = new Google_Service_Calendar_Event(array(
'summary' => "name:".$_POST['name'],
'start' => array(
'dateTime' => $start_datetime,
'timeZone' => 'Asia/Tokyo',
),
'end' => array(
'dateTime' => $end_datetime,
'timeZone' => 'Asia/Tokyo',
),
'description' => $description,
'location' => $_POST['units'],
));
log_info('ebikeReserved 開始6');
$event = $service->events->insert($calendarId, $event);
log_info('ebikeReserved 開始7');
}
//
// 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');
//メール送信、15は「dtb_mail_template」のID
$this->mailService->sendReserveRequest($_POST,15);
$this->session->remove('rental.ebike');
log_info('rentalReserved 終了');
return [
];
} catch (\Exception $e) {
log_info('rentalReserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/helicopter", name="helicopter", methods={"GET"})
* @Template("Helicopter/index.twig")
*/
public function helicopter()
{
return [];
}
/**
* 商品詳細画面.
*
* @Route("/helicopter/detail/{id}", name="helicopter_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Helicopter/detail.twig")
* @ParamConverter("Helicopter", options={"repository_method" = "findWithSortedClassCategories"})
*
* @param Request $request
* @param Product $Product
*
* @return array
*/
public function helicopterDetail(Request $request, Product $Product)
{
$this->session->set('rental.helicopter', "set");
if (!$this->checkVisibility($Product)) {
throw new NotFoundHttpException();
}
$res=[];
return [
'title' => $Product->getName(),
'subtitle' => $Product->getName(),
'events' => json_encode($res),
'Product' => $Product,
'calendar_start_date' => date('Y-m-d', strtotime('+1day')),
];
}
/**
* @Route("/helicopter/reserved", name="helicopter_reserved", methods={"POST"})
* @Template("Helicopter/reserved.twig")
*/
public function helicopterReserved()
{
try {
if(!$this->session->get('rental.helicopter')) {
return $this->redirectToRoute('homepage');
}
//メール送信、19は「dtb_mail_template」のID
log_info('helicopterReserved 開始2-1');
$this->mailService->sendReserveRequest($_POST,19);
$this->session->remove('rental.helicopter');
log_info('helicopterReserved 終了');
return [
];
} catch (\Exception $e) {
log_info('helicopter Reserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/fuji", name="fuji", methods={"GET"})
* @Template("Fuji/index.twig")
*/
public function fuji()
{
return [];
}
/**
* @Route("/fuji/service01", name="fuji_service01", methods={"GET"})
* @Template("Fuji/service01.twig")
*/
public function fuji_service01()
{
return [];
}
/**
* @Route("/fuji/service02", name="fuji_service02", methods={"GET"})
* @Template("Fuji/service02.twig")
*/
public function fuji_service02()
{
return [];
}
/**
* @Route("/fuji/service03", name="fuji_service03", methods={"GET"})
* @Template("Fuji/service03.twig")
*/
public function fuji_service03()
{
return [];
}
/**
* @Route("/fuji/service04", name="fuji_service04", methods={"GET"})
* @Template("Fuji/service04.twig")
*/
public function fuji_service04()
{
return [];
}
/**
* @Route("/fuji/service05", name="fuji_service05", methods={"GET"})
* @Template("Fuji/service05.twig")
*/
public function fuji_service05()
{
return [];
}
/**
* @Route("/fuji/reserved/{id}", name="fuji_reserved", methods={"GET"})
* @Template("Fuji/reserved.twig")
*/
public function fujiReserved($id)
{
try {
$this->session->set('rental.fuji', "set");
return [
'id' => $id,
];
} catch (\Exception $e) {
log_info('helicopter Reserved Exception');
return $this->redirectToRoute('homepage');
}
}
/**
* @Route("/fuji/complete", name="fuji_complete", methods={"POST"})
* @Template("Fuji/complete.twig")
*/
public function fujiComplete()
{
try {
if(!$this->session->get('rental.fuji')) {
return $this->redirectToRoute('homepage');
}
//メール送信、29は「dtb_mail_template」のID
log_info('Fuji Reserved 開始2-1');
$this->mailService->sendReserveRequest($_POST,29);
$this->session->remove('rental.fuji');
log_info('Fuji Reserved 終了');
return [
'posts' => $_POST,
];
} catch (\Exception $e) {
log_info('Fuji Reserved Exception');
// var_dump($e->getMessage());
return [
'posts' => $_POST,
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/summer", name="summer", methods={"GET"})
* @Template("Summer/index.twig")
*/
public function summer()
{
return [];
}
/**
* @Route("/autumn", name="autumn", methods={"GET"})
* @Template("Autumn/index.twig")
*/
public function autumn()
{
return [];
}
/**
* @Route("/autumn/reserved/{id}", name="autumn_reserved", methods={"GET"})
* @Template("Autumn/reserved.twig")
*/
public function autumnReserved($id)
{
try {
$this->session->set('rental.autumn', "set");
return [
'id' => $id,
];
} catch (\Exception $e) {
log_info('helicopter Reserved Exception');
return $this->redirectToRoute('homepage');
}
}
/**
* @Route("/autumn/complete", name="autumn_complete", methods={"POST"})
* @Template("Autumn/complete.twig")
*/
public function autumnComplete()
{
try {
if(!$this->session->get('rental.autumn')) {
return $this->redirectToRoute('homepage');
}
//メール送信、27は「dtb_mail_template」のID
log_info('Cruise Reserved 開始2-1');
$this->mailService->sendReserveRequest($_POST,27);
$this->session->remove('rental.autumn');
log_info('Cruise Reserved 終了');
return [
];
} catch (\Exception $e) {
log_info('Autumn Reserved Exception');
// var_dump($e->getMessage());
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* 商品詳細画面.
*
* @Route("/summer/detail/{id}", name="summer_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Summer/detail.twig")
* @ParamConverter("Summer", options={"repository_method" = "findWithSortedClassCategories"})
*
* @param Request $request
* @param Product $Product
*
* @return array
*/
public function summerDetail(Request $request, Product $Product)
{
$this->session->set('rental.helicopter', "set");
if (!$this->checkVisibility($Product)) {
throw new NotFoundHttpException();
}
$res=[];
return [
'title' => $Product->getName(),
'subtitle' => $Product->getName(),
'events' => json_encode($res),
'Product' => $Product,
'calendar_start_date' => date('Y-m-d', strtotime('+1day')),
];
}
/**
* @Route("/summer/reserved", name="summer_reserved", methods={"POST"})
* @Template("Summer/reserved.twig")
*/
public function summerReserved()
{
try {
if(!$this->session->get('rental.summer')) {
return $this->redirectToRoute('homepage');
}
//メール送信、19は「dtb_mail_template」のID
log_info('SummerReserved 開始2-1');
$this->mailService->sendReserveRequest($_POST,19);
$this->session->remove('rental.summer');
log_info('SummerReserved 終了');
return [
];
} catch (\Exception $e) {
log_info('Summer Reserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/cruise", name="cruise", methods={"GET"})
* @Template("Cruise/index.twig")
*/
public function cruise()
{
return [];
}
/**
* 商品詳細画面.
*
* @Method("GET")
* @Route("/cruise/{id}", name="cruise_detail", methods={"GET"})
* @Template("Cruise/detail.twig")
*/
public function cruiseDetail($id)
{
$this->session->set('rental.cruise', "set");
// if($id == 'tokyo')
$res=[];
return [
'id' => $id,
];
}
/**
* @Route("/cruise/reserved/{id}", name="cruise_reserved", methods={"GET"})
* @Template("Cruise/reserved.twig")
*/
public function cruiseReserved($id)
{
try {
$title="";
if($id==1) {
$title="RIVER CRUISE";
} else if($id==2) {
$title="TOKYO BAY CRUISE";
} else if($id==3) {
$title="YOKOHAMA BAY SUNSET CRUISE";
} else if($id==4) {
$title="CHIBA / MIURA RESORT CRUISE";
} else if($id==5) {
$title="CHIBA RESORT CRUISE";
} else {
return $this->redirectToRoute('homepage');
}
return [
'id' => $id,
'title' => $title,
];
} catch (\Exception $e) {
log_info('helicopter Reserved Exception');
return [
'testtest' => $e->getMessage(),
];
}
}
/**
* @Route("/cruise/complete", name="cruise_complete", methods={"POST"})
* @Template("Cruise/complete.twig")
*/
public function cruiseComplete()
{
try {
if(!$this->session->get('rental.cruise')) {
return $this->redirectToRoute('homepage');
}
//メール送信、26は「dtb_mail_template」のID
log_info('Cruise Reserved 開始2-1');
$this->mailService->sendReserveRequest($_POST,26);
$this->session->remove('rental.cruise');
log_info('Cruise Reserved 終了');
return [
];
} catch (\Exception $e) {
log_info('Cruise Reserved Exception');
// var_dump($e->getMessage());
return [
'testtest' => $e->getMessage(),
];
}
}
}