app/Customize/Form/Type/Front/ContactType.php line 41

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\Form\Type\Front;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Form\Type\AddressType;
  15. use Eccube\Form\Type\KanaType;
  16. use Eccube\Form\Type\NameType;
  17. use Eccube\Form\Type\PhoneNumberType;
  18. use Eccube\Form\Type\PostalType;
  19. use Eccube\Form\Validator\Email;
  20. use Symfony\Component\Form\AbstractType;
  21. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  22. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  23. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  24. use Symfony\Component\Form\Extension\Core\Type\TextType;
  25. use Symfony\Component\Form\Extension\Core\Type\FileType;
  26. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  27. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  28. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  29. use Symfony\Component\Form\Extension\Core\Type\DateType;
  30. use Symfony\Component\Form\FormEvent;
  31. use Symfony\Component\Form\FormEvents;
  32. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  33. use Symfony\Component\Form\FormBuilderInterface;
  34. use Symfony\Component\Validator\Constraints as Assert;
  35. use Customize\Service\FileUploader;
  36. class ContactType extends AbstractType
  37. {
  38.     /**
  39.      * @var EccubeConfig
  40.      */
  41.     protected $eccubeConfig;
  42.     /**
  43.      * @var FileUploader
  44.      */
  45.     protected $fileUploader;
  46.     /**
  47.      * ContactType constructor.
  48.      *
  49.      * @param EccubeConfig $eccubeConfig
  50.      */
  51.     public function __construct(
  52.         EccubeConfig $eccubeConfig,
  53.         FileUploader $fileUploader) {
  54.         $this->eccubeConfig $eccubeConfig;
  55.         $this->fileUploader $fileUploader;
  56.     }
  57.     /**
  58.      * {@inheritdoc}
  59.      */
  60.     public function buildForm(FormBuilderInterface $builder, array $options)
  61.     {
  62.         $builder
  63.             ->add('name'NameType::class, [
  64.                 'required' => false,
  65.             ])
  66.             ->add('kana'KanaType::class, [
  67.                 'required' => false,
  68.             ])
  69.             ->add('postal_code'PostalType::class, [
  70.                 'required' => false,
  71.             ])
  72.             ->add('address'AddressType::class, [
  73.                 'required' => false,
  74.             ])
  75.             ->add('phone_number'PhoneNumberType::class, [
  76.                 'required' => false,
  77.             ])
  78.             ->add('email'EmailType::class, [
  79.                 'required' => false,
  80.                 'constraints' => [
  81.                     // new Assert\NotBlank(),
  82.                     new Email(nullnull$this->eccubeConfig['eccube_rfc_email_check'] ? 'strict' null),
  83.                 ],
  84.             ])
  85.             ->add('contents'TextareaType::class, [
  86.                 'required' => true,
  87.                 'constraints' => [
  88.                     // new Assert\NotBlank(),
  89.                     new Assert\Length([
  90.                         'max' => $this->eccubeConfig['eccube_lltext_len'],
  91.                     ])
  92.                 ],
  93.             ])
  94.         ;
  95.         // 追加フィールド
  96.         $builder
  97.             //お問い合わせ種別
  98.             ->add('contact_type'ChoiceType::class, [
  99.                 'choices'  => [
  100.                     'エアコン本体について' => '1',
  101.                     '電気工事について' => '2',
  102.                     'エアコン設置工事について' => '3',
  103.                     'その他' => '4',
  104.                 ],
  105.                 'expanded' => true,
  106.                 'multiple' => false,
  107.                 'required' => false,
  108.             ])      
  109.             //企業名      
  110.             ->add('company_name'TextType::class, [
  111.                 'required' => false,
  112.             ])
  113.             //エアコン種類
  114.             ->add('category'ChoiceType::class, [
  115.                 'choices'  => [
  116.                     'ルームエアコン' => 'ルームエアコン',
  117.                     '業務用エアコン' => '業務用エアコン',
  118.                 ],
  119.                 'expanded' => true,
  120.                 'multiple' => false,
  121.                 'required' => false,
  122.             ])
  123.             //決済方法
  124.             ->add('payment_method'ChoiceType::class, [
  125.                 'choices'  => [
  126.                     'クレジットカード決済' => 'クレジットカード決済',
  127.                     'ジャックスクレジット(金利手数料0円サービス適応)' => 'ジャックスクレジット(金利手数料0円サービス適応)',
  128.                     '銀行振込' => '銀行振込',
  129.                     'コンビニ決済' => 'コンビニ決済',
  130.                 ],
  131.                 'expanded' => true,
  132.                 'multiple' => false,
  133.                 'required' => false,
  134.             ])
  135.             //建物の形態
  136.             ->add('building_type'ChoiceType::class, [
  137.                 'choices'  => [
  138.                     '戸建て' => '戸建て',
  139.                     'マンション' => 'マンション',
  140.                     'アパート' => 'アパート',
  141.                     'ビル' => 'ビル',
  142.                     'その他' => 'その他',
  143.                 ],
  144.                 'expanded' => true,
  145.                 'multiple' => false,
  146.                 'required' => false,
  147.             ])
  148.             //業種
  149.             ->add('kind'EntityType::class, [
  150.                 'class' => 'Customize\Entity\Kind',
  151.                 'choice_label' => 'name',
  152.                 // 'choice_value' => 'name',
  153.                 'expanded' => true,
  154.                 'multiple' => false,
  155.                 'required' => false,
  156.             ])
  157.             //建物の材質
  158.             ->add('building_material'ChoiceType::class, [
  159.                 'choices'  => [
  160.                     'コンクリート(RC)' => 'コンクリート(RC)',
  161.                     '鉄骨系' => '鉄骨系',
  162.                     '木造' => '木造',
  163.                     'その他' => 'その他',
  164.                     '不明' => '不明',
  165.                 ],
  166.                 'expanded' => true,
  167.                 'multiple' => false,
  168.                 'required' => false,
  169.             ])
  170.             //設置台数
  171.             ->add('construction_cnt'ChoiceType::class, [
  172.                 'choices'  => [
  173.                     '未定' => '未定',
  174.                     '1台' => '1台',
  175.                     '2台' => '2台',
  176.                     '3台' => '3台',
  177.                     '4台以上' => '4台以上',
  178.                 ],
  179.                 'expanded' => true,
  180.                 'multiple' => false,
  181.                 'required' => false,
  182.             ])
  183.             //工事時期
  184.             ->add('construction_period'ChoiceType::class, [
  185.                 'choices'  => [
  186.                     '至急' => '至急',
  187.                     '5営業日~' => '5営業日~',
  188.                     '1か月以内' => '1か月以内',
  189.                     '1か月以上' => '1か月以上',
  190.                     '未定' => '未定',
  191.                 ],
  192.                 'expanded' => true,
  193.                 'multiple' => false,
  194.                 'required' => false,
  195.             ])
  196.             //工事内訳
  197.             ->add('construction_type'ChoiceType::class, [
  198.                 'choices'  => [
  199.                     '新設' => '新設',
  200.                     '交換(撤去含む)' => '交換(撤去含む)',
  201.                     '移設' => '移設',
  202.                 ],
  203.                 'expanded' => true,
  204.                 'multiple' => false,
  205.                 'required' => false,
  206.             ])
  207.             //重視するポイント
  208.             ->add('key_points_type'ChoiceType::class, [
  209.                 'choices'  => [
  210.                     '価格' => '価格',
  211.                     '機能' => '機能',
  212.                     'メーカー' => 'メーカー',
  213.                 ],
  214.                 'expanded' => true,
  215.                 'multiple' => false,
  216.                 'required' => false,
  217.             ])
  218.             //希望メーカー
  219.             ->add('maker'EntityType::class, [
  220.                 'class' => 'Customize\Entity\Maker',
  221.                 'choice_label' => 'name',
  222.                 // 'choice_value' => 'name',
  223.                 'expanded' => true,
  224.                 'multiple' => false,
  225.                 'required' => false,
  226.             ])
  227.             //品番      
  228.             ->add('product_code'TextType::class, [
  229.                 'required' => false,
  230.             ])
  231.             //部屋の広さ
  232.             ->add('room_size'ChoiceType::class, [
  233.                 'choices'  => [
  234.                     '6畳以下' => '6畳以下',
  235.                     '6畳' => '6畳',
  236.                     '8畳' => '8畳',
  237.                     '10畳' => '10畳',
  238.                     '12畳' => '12畳',
  239.                     '14畳' => '14畳',
  240.                     '16畳' => '16畳',
  241.                     '18畳' => '18畳',
  242.                     '20畳' => '20畳',
  243.                     '23畳' => '23畳',
  244.                     '26畳' => '26畳',
  245.                     '26畳以上' => '26畳以上',
  246.                     '不明' => '不明',
  247.                 ],
  248.                 'expanded' => true,
  249.                 'multiple' => false,
  250.                 'required' => false,
  251.             ])
  252.             //エアコン設置場所
  253.             ->add('construction_floor'ChoiceType::class, [
  254.                 'choices'  => [
  255.                     '1階' => '1階',
  256.                     '2階' => '2階',
  257.                     '3階' => '3階',
  258.                     '4階以上' => '4階以上',
  259.                     '未定' => '未定',
  260.                 ],
  261.                 'expanded' => true,
  262.                 'multiple' => false,
  263.                 'required' => false,
  264.             ])
  265.             //エレベーターの有無
  266.             ->add('elevator'ChoiceType::class, [
  267.                 'choices'  => [
  268.                     '有り' => '有り',
  269.                     '無し' => '無し',
  270.                 ],
  271.                 'expanded' => true,
  272.                 'multiple' => false,
  273.                 'required' => false,
  274.             ])
  275.             //コンセントの形状
  276.             ->add('electrical_outlet'ChoiceType::class, [
  277.                 'choices'  => [
  278.                     '有り' => '有り',
  279.                     'なし(別途工事が必要になります。)' => 'なし(別途工事が必要になります。)',
  280.                     '不明' => '不明',
  281.                 ],
  282.                 'expanded' => true,
  283.                 'multiple' => false,
  284.                 'required' => false,
  285.             ])
  286.             //コンセントの形状
  287.             ->add('consent_shape'ChoiceType::class, [
  288.                 'choices'  => [
  289.                     '並行型単層100V' => '並行型単層100V',
  290.                     'アイエル形単層100V' => 'アイエル形単層100V',
  291.                     'タンデム型単層200V' => 'タンデム型単層200V',
  292.                     'エルバ―型単層200V' => 'エルバ―型単層200V',
  293.                 ],
  294.                 'expanded' => true,
  295.                 'multiple' => false,
  296.                 'required' => false,
  297.             ])
  298.             //配管穴の有無
  299.             ->add('piping_hole'ChoiceType::class, [
  300.                 'choices'  => [
  301.                     '有り' => '有り',
  302.                     '無し' => '無し',
  303.                     '不明' => '不明',
  304.                 ],
  305.                 'expanded' => true,
  306.                 'multiple' => false,
  307.                 'required' => false,
  308.             ])
  309.             //設置予定場所の配管の状態
  310.             ->add('piping_status'ChoiceType::class, [
  311.                 'choices'  => [
  312.                     '通常配管' => '通常配管',
  313.                     '隠蔽配管' => '隠蔽配管',
  314.                     '配管無し' => '配管無し',
  315.                     '不明' => '不明',
  316.                 ],
  317.                 'expanded' => true,
  318.                 'multiple' => false,
  319.                 'required' => false,
  320.             ])
  321.             //室内化粧カバー
  322.             ->add('indoor_cover'ChoiceType::class, [
  323.                 'choices'  => [
  324.                     '必要' => '必要',
  325.                     '不要' => '不要',
  326.                     'その他' => 'その他',
  327.                 ],
  328.                 'expanded' => true,
  329.                 'multiple' => false,
  330.                 'required' => false,
  331.             ])
  332.             //室外化粧カバー
  333.             ->add('outdoor_cover'ChoiceType::class, [
  334.                 'choices'  => [
  335.                     '必要' => '必要',
  336.                     '不要' => '不要',
  337.                     'その他' => 'その他',
  338.                 ],
  339.                 'expanded' => true,
  340.                 'multiple' => false,
  341.                 'required' => false,
  342.             ])
  343.             //室外機の設置場所(既設場所・希望設置場所)
  344.             ->add('construction_outdoor'ChoiceType::class, [
  345.                 'choices'  => [
  346.                     '1階' => '1階',
  347.                     '2階' => '2階',
  348.                     '3階' => '3階',
  349.                     '4階以上' => '4階以上',
  350.                     '不明' => '不明',
  351.                 ],
  352.                 'expanded' => true,
  353.                 'multiple' => false,
  354.                 'required' => false,
  355.             ])
  356.             //既設室外機の設置場所
  357.             ->add('construction_outdoor2'ChoiceType::class, [
  358.                 'choices'  => [
  359.                     '1階' => '1階',
  360.                     '2階' => '2階',
  361.                     '3階' => '3階',
  362.                     '4階以上' => '4階以上',
  363.                     '不明' => '不明',
  364.                 ],
  365.                 'expanded' => true,
  366.                 'multiple' => false,
  367.                 'required' => false,
  368.             ])
  369.             //設置方法(既設方法・希望設置方法)
  370.             ->add('construction_method'ChoiceType::class, [
  371.                 'choices'  => [
  372.                     '①床置き(基本料金に含まれます)' => '①床置き(基本料金に含まれます)',
  373.                     '②二段置き' => '②二段置き',
  374.                     '③壁掛け' => '③壁掛け',
  375.                     '④屋根置き(屋根に対して垂直)' => '④屋根置き(屋根に対して垂直)',
  376.                     '⑤屋根置き(屋根に対して水平)' => '⑤屋根置き(屋根に対して水平)',
  377.                     '⑥公団吊り(天井吊り)' => '⑥公団吊り(天井吊り)',
  378.                     '⑦不明' => '⑦不明',
  379.                 ],
  380.                 'expanded' => true,
  381.                 'multiple' => false,
  382.                 'required' => false,
  383.             ])
  384.             //工事希望日1
  385.             ->add('construction_date_1'DateType::class, [
  386.                 'required' => false,
  387.                 'input' => 'datetime',
  388.                 'widget' => 'single_text',
  389.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  390.             ])
  391.             //工事希望日2
  392.             ->add('construction_date_2'DateType::class, [
  393.                 'required' => false,
  394.                 'input' => 'datetime',
  395.                 'widget' => 'single_text',
  396.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  397.             ])
  398.             //工事希望日3
  399.             ->add('construction_date_3'DateType::class, [
  400.                 'required' => false,
  401.                 'input' => 'datetime',
  402.                 'widget' => 'single_text',
  403.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  404.             ])
  405.             //現地調査
  406.             ->add('investigation'ChoiceType::class, [
  407.                 'choices'  => [
  408.                     '希望する' => '希望する',
  409.                     '希望しない' => '希望しない',
  410.                 ],
  411.                 'expanded' => true,
  412.                 'multiple' => false,
  413.                 'required' => false,
  414.             ])
  415.             //現地調査希望日1
  416.             ->add('investigation_date_1'DateType::class, [
  417.                 'required' => false,
  418.                 'input' => 'datetime',
  419.                 'widget' => 'single_text',
  420.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  421.             ])
  422.             //現地調査希望日2
  423.             ->add('investigation_date_2'DateType::class, [
  424.                 'required' => false,
  425.                 'input' => 'datetime',
  426.                 'widget' => 'single_text',
  427.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  428.             ])
  429.             //現地調査希望日3
  430.             ->add('investigation_date_3'DateType::class, [
  431.                 'required' => false,
  432.                 'input' => 'datetime',
  433.                 'widget' => 'single_text',
  434.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  435.             ])
  436.             ->add('reason'TextareaType::class, [
  437.                 'required' => false,
  438.                 'constraints' => [
  439.                     // new Assert\NotBlank(),
  440.                     new Assert\Length([
  441.                         'max' => $this->eccubeConfig['eccube_lltext_len'],
  442.                     ])
  443.                 ],
  444.             ])
  445.             ->add('image_attach'ChoiceType::class, [
  446.                 'choices'  => [
  447.                     '室内機、室外機の設置場所の撮影が可能' => '室内機、室外機の設置場所の撮影が可能',
  448.                     '引越し・新設等の理由により不明' => '引越し・新設等の理由により不明',
  449.                 ],
  450.                 'expanded' => true,
  451.                 'multiple' => false,
  452.                 'required' => false,
  453.                 'data' => '室内機、室外機の設置場所の撮影が可能',
  454.             ])
  455.             ->add('image_1'FileType::class, [
  456.                 'multiple' => false,
  457.                 'required' => false,
  458.                 'mapped' => false,
  459.             ])
  460.             ->add('image_2'FileType::class, [
  461.                 'multiple' => false,
  462.                 'required' => false,
  463.                 'mapped' => false,
  464.             ])
  465.             ->add('image_3'FileType::class, [
  466.                 'multiple' => false,
  467.                 'required' => false,
  468.                 'mapped' => false,
  469.             ])
  470.             ->add('image_4'FileType::class, [
  471.                 'multiple' => false,
  472.                 'required' => false,
  473.                 'mapped' => false,
  474.             ])
  475.             ->add('image_5'FileType::class, [
  476.                 'multiple' => false,
  477.                 'required' => false,
  478.                 'mapped' => false,
  479.             ])
  480.             ->add('image_reason'FileType::class, [
  481.                 'multiple' => false,
  482.                 'required' => false,
  483.                 'mapped' => false,
  484.             ])
  485.             ->add('filename_image_1'HiddenType::class)
  486.             ->add('filename_image_2'HiddenType::class)
  487.             ->add('filename_image_3'HiddenType::class)
  488.             ->add('filename_image_4'HiddenType::class)
  489.             ->add('filename_image_5'HiddenType::class)
  490.             ->add('filename_image_reason'HiddenType::class)
  491.         ;
  492.         /**
  493.          * SUBMIT前にファイルをアップロードしてfilenameにセットする
  494.          */
  495.         $builder->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) {
  496.             $data $event->getData();
  497.             // ファイルをアップロード
  498.             if (!empty($data['image_1'])) {
  499.                 $filename $this->fileUploader->upload($data['image_1']);
  500.                 $data['filename_image_1'] = $filename;
  501.                 unset($data['image_1']);
  502.             }
  503.             if (!empty($data['image_2'])) {
  504.                 $filename $this->fileUploader->upload($data['image_2']);
  505.                 $data['filename_image_2'] = $filename;
  506.                 unset($data['image_2']);
  507.             }
  508.             if (!empty($data['image_3'])) {
  509.                 $filename $this->fileUploader->upload($data['image_3']);
  510.                 $data['filename_image_3'] = $filename;
  511.                 unset($data['image_3']);
  512.             }
  513.             if (!empty($data['image_4'])) {
  514.                 $filename $this->fileUploader->upload($data['image_4']);
  515.                 $data['filename_image_4'] = $filename;
  516.                 unset($data['image_4']);
  517.             }
  518.             if (!empty($data['image_5'])) {
  519.                 $filename $this->fileUploader->upload($data['image_5']);
  520.                 $data['filename_image_5'] = $filename;
  521.                 unset($data['image_5']);
  522.             }
  523.             if (!empty($data['image_reason'])) {
  524.                 $filename $this->fileUploader->upload($data['image_reason']);
  525.                 $data['filename_image_reason'] = $filename;
  526.                 unset($data['image_reason']);
  527.             }
  528.             // アップロードしたデータを保存
  529.             $event->setData($data);
  530.         });
  531.     }
  532.     /**
  533.      * {@inheritdoc}
  534.      */
  535.     public function getBlockPrefix()
  536.     {
  537.         return 'contact';
  538.     }
  539. }