<?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\Form\Type\Front;
use Eccube\Common\EccubeConfig;
use Eccube\Form\Type\AddressType;
use Eccube\Form\Type\KanaType;
use Eccube\Form\Type\NameType;
use Eccube\Form\Type\PhoneNumberType;
use Eccube\Form\Type\PostalType;
use Eccube\Form\Validator\Email;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Customize\Service\FileUploader;
class ContactType extends AbstractType
{
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
/**
* @var FileUploader
*/
protected $fileUploader;
/**
* ContactType constructor.
*
* @param EccubeConfig $eccubeConfig
*/
public function __construct(
EccubeConfig $eccubeConfig,
FileUploader $fileUploader) {
$this->eccubeConfig = $eccubeConfig;
$this->fileUploader = $fileUploader;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', NameType::class, [
'required' => false,
])
->add('kana', KanaType::class, [
'required' => false,
])
->add('postal_code', PostalType::class, [
'required' => false,
])
->add('address', AddressType::class, [
'required' => false,
])
->add('phone_number', PhoneNumberType::class, [
'required' => false,
])
->add('email', EmailType::class, [
'required' => false,
'constraints' => [
// new Assert\NotBlank(),
new Email(null, null, $this->eccubeConfig['eccube_rfc_email_check'] ? 'strict' : null),
],
])
->add('contents', TextareaType::class, [
'required' => true,
'constraints' => [
// new Assert\NotBlank(),
new Assert\Length([
'max' => $this->eccubeConfig['eccube_lltext_len'],
])
],
])
;
// 追加フィールド
$builder
//お問い合わせ種別
->add('contact_type', ChoiceType::class, [
'choices' => [
'エアコン本体について' => '1',
'電気工事について' => '2',
'エアコン設置工事について' => '3',
'その他' => '4',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//企業名
->add('company_name', TextType::class, [
'required' => false,
])
//エアコン種類
->add('category', ChoiceType::class, [
'choices' => [
'ルームエアコン' => 'ルームエアコン',
'業務用エアコン' => '業務用エアコン',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//決済方法
->add('payment_method', ChoiceType::class, [
'choices' => [
'クレジットカード決済' => 'クレジットカード決済',
'ジャックスクレジット(金利手数料0円サービス適応)' => 'ジャックスクレジット(金利手数料0円サービス適応)',
'銀行振込' => '銀行振込',
'コンビニ決済' => 'コンビニ決済',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//建物の形態
->add('building_type', ChoiceType::class, [
'choices' => [
'戸建て' => '戸建て',
'マンション' => 'マンション',
'アパート' => 'アパート',
'ビル' => 'ビル',
'その他' => 'その他',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//業種
->add('kind', EntityType::class, [
'class' => 'Customize\Entity\Kind',
'choice_label' => 'name',
// 'choice_value' => 'name',
'expanded' => true,
'multiple' => false,
'required' => false,
])
//建物の材質
->add('building_material', ChoiceType::class, [
'choices' => [
'コンクリート(RC)' => 'コンクリート(RC)',
'鉄骨系' => '鉄骨系',
'木造' => '木造',
'その他' => 'その他',
'不明' => '不明',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//設置台数
->add('construction_cnt', ChoiceType::class, [
'choices' => [
'未定' => '未定',
'1台' => '1台',
'2台' => '2台',
'3台' => '3台',
'4台以上' => '4台以上',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//工事時期
->add('construction_period', ChoiceType::class, [
'choices' => [
'至急' => '至急',
'5営業日~' => '5営業日~',
'1か月以内' => '1か月以内',
'1か月以上' => '1か月以上',
'未定' => '未定',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//工事内訳
->add('construction_type', ChoiceType::class, [
'choices' => [
'新設' => '新設',
'交換(撤去含む)' => '交換(撤去含む)',
'移設' => '移設',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//重視するポイント
->add('key_points_type', ChoiceType::class, [
'choices' => [
'価格' => '価格',
'機能' => '機能',
'メーカー' => 'メーカー',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//希望メーカー
->add('maker', EntityType::class, [
'class' => 'Customize\Entity\Maker',
'choice_label' => 'name',
// 'choice_value' => 'name',
'expanded' => true,
'multiple' => false,
'required' => false,
])
//品番
->add('product_code', TextType::class, [
'required' => false,
])
//部屋の広さ
->add('room_size', ChoiceType::class, [
'choices' => [
'6畳以下' => '6畳以下',
'6畳' => '6畳',
'8畳' => '8畳',
'10畳' => '10畳',
'12畳' => '12畳',
'14畳' => '14畳',
'16畳' => '16畳',
'18畳' => '18畳',
'20畳' => '20畳',
'23畳' => '23畳',
'26畳' => '26畳',
'26畳以上' => '26畳以上',
'不明' => '不明',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//エアコン設置場所
->add('construction_floor', ChoiceType::class, [
'choices' => [
'1階' => '1階',
'2階' => '2階',
'3階' => '3階',
'4階以上' => '4階以上',
'未定' => '未定',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//エレベーターの有無
->add('elevator', ChoiceType::class, [
'choices' => [
'有り' => '有り',
'無し' => '無し',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//コンセントの形状
->add('electrical_outlet', ChoiceType::class, [
'choices' => [
'有り' => '有り',
'なし(別途工事が必要になります。)' => 'なし(別途工事が必要になります。)',
'不明' => '不明',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//コンセントの形状
->add('consent_shape', ChoiceType::class, [
'choices' => [
'並行型単層100V' => '並行型単層100V',
'アイエル形単層100V' => 'アイエル形単層100V',
'タンデム型単層200V' => 'タンデム型単層200V',
'エルバ―型単層200V' => 'エルバ―型単層200V',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//配管穴の有無
->add('piping_hole', ChoiceType::class, [
'choices' => [
'有り' => '有り',
'無し' => '無し',
'不明' => '不明',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//設置予定場所の配管の状態
->add('piping_status', ChoiceType::class, [
'choices' => [
'通常配管' => '通常配管',
'隠蔽配管' => '隠蔽配管',
'配管無し' => '配管無し',
'不明' => '不明',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//室内化粧カバー
->add('indoor_cover', ChoiceType::class, [
'choices' => [
'必要' => '必要',
'不要' => '不要',
'その他' => 'その他',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//室外化粧カバー
->add('outdoor_cover', ChoiceType::class, [
'choices' => [
'必要' => '必要',
'不要' => '不要',
'その他' => 'その他',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//室外機の設置場所(既設場所・希望設置場所)
->add('construction_outdoor', ChoiceType::class, [
'choices' => [
'1階' => '1階',
'2階' => '2階',
'3階' => '3階',
'4階以上' => '4階以上',
'不明' => '不明',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//既設室外機の設置場所
->add('construction_outdoor2', ChoiceType::class, [
'choices' => [
'1階' => '1階',
'2階' => '2階',
'3階' => '3階',
'4階以上' => '4階以上',
'不明' => '不明',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//設置方法(既設方法・希望設置方法)
->add('construction_method', ChoiceType::class, [
'choices' => [
'①床置き(基本料金に含まれます)' => '①床置き(基本料金に含まれます)',
'②二段置き' => '②二段置き',
'③壁掛け' => '③壁掛け',
'④屋根置き(屋根に対して垂直)' => '④屋根置き(屋根に対して垂直)',
'⑤屋根置き(屋根に対して水平)' => '⑤屋根置き(屋根に対して水平)',
'⑥公団吊り(天井吊り)' => '⑥公団吊り(天井吊り)',
'⑦不明' => '⑦不明',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//工事希望日1
->add('construction_date_1', DateType::class, [
'required' => false,
'input' => 'datetime',
'widget' => 'single_text',
'placeholder' => ['year' => '----', 'month' => '--', 'day' => '--'],
])
//工事希望日2
->add('construction_date_2', DateType::class, [
'required' => false,
'input' => 'datetime',
'widget' => 'single_text',
'placeholder' => ['year' => '----', 'month' => '--', 'day' => '--'],
])
//工事希望日3
->add('construction_date_3', DateType::class, [
'required' => false,
'input' => 'datetime',
'widget' => 'single_text',
'placeholder' => ['year' => '----', 'month' => '--', 'day' => '--'],
])
//現地調査
->add('investigation', ChoiceType::class, [
'choices' => [
'希望する' => '希望する',
'希望しない' => '希望しない',
],
'expanded' => true,
'multiple' => false,
'required' => false,
])
//現地調査希望日1
->add('investigation_date_1', DateType::class, [
'required' => false,
'input' => 'datetime',
'widget' => 'single_text',
'placeholder' => ['year' => '----', 'month' => '--', 'day' => '--'],
])
//現地調査希望日2
->add('investigation_date_2', DateType::class, [
'required' => false,
'input' => 'datetime',
'widget' => 'single_text',
'placeholder' => ['year' => '----', 'month' => '--', 'day' => '--'],
])
//現地調査希望日3
->add('investigation_date_3', DateType::class, [
'required' => false,
'input' => 'datetime',
'widget' => 'single_text',
'placeholder' => ['year' => '----', 'month' => '--', 'day' => '--'],
])
->add('reason', TextareaType::class, [
'required' => false,
'constraints' => [
// new Assert\NotBlank(),
new Assert\Length([
'max' => $this->eccubeConfig['eccube_lltext_len'],
])
],
])
->add('image_attach', ChoiceType::class, [
'choices' => [
'室内機、室外機の設置場所の撮影が可能' => '室内機、室外機の設置場所の撮影が可能',
'引越し・新設等の理由により不明' => '引越し・新設等の理由により不明',
],
'expanded' => true,
'multiple' => false,
'required' => false,
'data' => '室内機、室外機の設置場所の撮影が可能',
])
->add('image_1', FileType::class, [
'multiple' => false,
'required' => false,
'mapped' => false,
])
->add('image_2', FileType::class, [
'multiple' => false,
'required' => false,
'mapped' => false,
])
->add('image_3', FileType::class, [
'multiple' => false,
'required' => false,
'mapped' => false,
])
->add('image_4', FileType::class, [
'multiple' => false,
'required' => false,
'mapped' => false,
])
->add('image_5', FileType::class, [
'multiple' => false,
'required' => false,
'mapped' => false,
])
->add('image_reason', FileType::class, [
'multiple' => false,
'required' => false,
'mapped' => false,
])
->add('filename_image_1', HiddenType::class)
->add('filename_image_2', HiddenType::class)
->add('filename_image_3', HiddenType::class)
->add('filename_image_4', HiddenType::class)
->add('filename_image_5', HiddenType::class)
->add('filename_image_reason', HiddenType::class)
;
/**
* SUBMIT前にファイルをアップロードしてfilenameにセットする
*/
$builder->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) {
$data = $event->getData();
// ファイルをアップロード
if (!empty($data['image_1'])) {
$filename = $this->fileUploader->upload($data['image_1']);
$data['filename_image_1'] = $filename;
unset($data['image_1']);
}
if (!empty($data['image_2'])) {
$filename = $this->fileUploader->upload($data['image_2']);
$data['filename_image_2'] = $filename;
unset($data['image_2']);
}
if (!empty($data['image_3'])) {
$filename = $this->fileUploader->upload($data['image_3']);
$data['filename_image_3'] = $filename;
unset($data['image_3']);
}
if (!empty($data['image_4'])) {
$filename = $this->fileUploader->upload($data['image_4']);
$data['filename_image_4'] = $filename;
unset($data['image_4']);
}
if (!empty($data['image_5'])) {
$filename = $this->fileUploader->upload($data['image_5']);
$data['filename_image_5'] = $filename;
unset($data['image_5']);
}
if (!empty($data['image_reason'])) {
$filename = $this->fileUploader->upload($data['image_reason']);
$data['filename_image_reason'] = $filename;
unset($data['image_reason']);
}
// アップロードしたデータを保存
$event->setData($data);
});
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'contact';
}
}