src/Eccube/Form/Type/Admin/OrderPdfType.php line 32

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 Eccube\Form\Type\Admin;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Eccube\Common\EccubeConfig;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  17. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  18. use Symfony\Component\Form\Extension\Core\Type\DateType;
  19. use Symfony\Component\Form\Extension\Core\Type\TextType;
  20. use Symfony\Component\Form\FormBuilderInterface;
  21. use Symfony\Component\Form\FormError;
  22. use Symfony\Component\Form\FormEvent;
  23. use Symfony\Component\Form\FormEvents;
  24. use Symfony\Component\Validator\Constraints as Assert;
  25. /**
  26.  * Class OrderPdfType.
  27.  */
  28. class OrderPdfType extends AbstractType
  29. {
  30.     /** @var EccubeConfig */
  31.     private $eccubeConfig;
  32.     /** @var EntityManagerInterface */
  33.     private $entityManager;
  34.     /**
  35.      * OrderPdfType constructor.
  36.      *
  37.      * @param EccubeConfig $eccubeConfig
  38.      * @param EntityManagerInterface $entityManager
  39.      */
  40.     public function __construct(EccubeConfig $eccubeConfigEntityManagerInterface $entityManager)
  41.     {
  42.         $this->eccubeConfig $eccubeConfig;
  43.         $this->entityManager $entityManager;
  44.     }
  45.     /**
  46.      * Build config type form.
  47.      *
  48.      * @param FormBuilderInterface $builder
  49.      * @param array                $options
  50.      */
  51.     public function buildForm(FormBuilderInterface $builder, array $options)
  52.     {
  53.         $config $this->eccubeConfig;
  54.         $builder
  55.             ->add('ids'TextType::class, [
  56.                 'required' => false,
  57.                 'attr' => ['readonly' => 'readonly'],
  58.                 'constraints' => [
  59.                     new Assert\NotBlank(),
  60.                 ],
  61.             ])
  62.             ->add('issue_date'DateType::class, [
  63.                 'widget' => 'single_text',
  64.                 'input' => 'datetime',
  65.                 'required' => true,
  66.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  67.                 'data' => new \DateTime(),
  68.                 'constraints' => [
  69.                     new Assert\NotBlank(),
  70.                     new Assert\Range([
  71.                         'min'=> '0003-01-01',
  72.                         'minMessage' => 'form_error.out_of_range',
  73.                     ]),
  74.                 ],
  75.                 'attr' => [
  76.                     'data-target' => '#'.$this->getBlockPrefix().'_issue_date',
  77.                     'data-toggle' => 'datetimepicker',
  78.                 ],
  79.             ])
  80.             ->add('title'TextType::class, [
  81.                 'required' => true,
  82.                 'attr' => ['maxlength' => $config['eccube_stext_len']],
  83.                 'constraints' => [
  84.                     new Assert\NotBlank(),
  85.                     new Assert\Length(['max' => $config['eccube_stext_len']]),
  86.                 ],
  87.             ])
  88.             ->add('download_kind'ChoiceType::class, [
  89.                 'choices' => [
  90.                     'admin.order.delivery_note_output_format__file' => 1,
  91.                     'admin.order.delivery_note_output_format__browser' => 2,
  92.                 ],
  93.                 'expanded' => false,
  94.                 'multiple' => false,
  95.                 'required' => false,
  96.                 'mapped' => false,
  97.                 'placeholder' => false,
  98.             ])
  99.             // メッセージ
  100.             ->add('message1'TextType::class, [
  101.                 'required' => false,
  102.                 'attr' => ['maxlength' => $config['eccube_order_pdf_message_len']],
  103.                 'constraints' => [
  104.                     new Assert\Length(['max' => $config['eccube_order_pdf_message_len']]),
  105.                 ],
  106.                 'trim' => false,
  107.             ])
  108.             ->add('message2'TextType::class, [
  109.                 'required' => false,
  110.                 'attr' => ['maxlength' => $config['eccube_order_pdf_message_len']],
  111.                 'constraints' => [
  112.                     new Assert\Length(['max' => $config['eccube_order_pdf_message_len']]),
  113.                 ],
  114.                 'trim' => false,
  115.             ])
  116.             ->add('message3'TextType::class, [
  117.                 'required' => false,
  118.                 'attr' => ['maxlength' => $config['eccube_order_pdf_message_len']],
  119.                 'constraints' => [
  120.                     new Assert\Length(['max' => $config['eccube_order_pdf_message_len']]),
  121.                 ],
  122.                 'trim' => false,
  123.             ])
  124.             // 備考
  125.             ->add('note1'TextType::class, [
  126.                 'required' => false,
  127.                 'attr' => ['maxlength' => $config['eccube_stext_len']],
  128.                 'constraints' => [
  129.                     new Assert\Length(['max' => $config['eccube_stext_len']]),
  130.                 ],
  131.             ])
  132.             ->add('note2'TextType::class, [
  133.                 'required' => false,
  134.                 'attr' => ['maxlength' => $config['eccube_stext_len']],
  135.                 'constraints' => [
  136.                     new Assert\Length(['max' => $config['eccube_stext_len']]),
  137.                 ],
  138.             ])
  139.             ->add('note3'TextType::class, [
  140.                 'required' => false,
  141.                 'attr' => ['maxlength' => $config['eccube_stext_len']],
  142.                 'constraints' => [
  143.                     new Assert\Length(['max' => $config['eccube_stext_len']]),
  144.                 ],
  145.             ])
  146.             ->add('default'CheckboxType::class, [
  147.                 'label' => 'admin.order.delivery_note_save_input',
  148.                 'required' => false,
  149.             ])
  150.             ->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  151.                 $form $event->getForm();
  152.                 $data $form->getData();
  153.                 if (!isset($data['ids']) || !is_string($data['ids'])) {
  154.                     return;
  155.                 }
  156.                 $ids explode(','$data['ids']);
  157.                 $qb $this->entityManager->createQueryBuilder();
  158.                 $qb->select('count(s.id)')
  159.                     ->from('Eccube\\Entity\\Shipping''s')
  160.                     ->where($qb->expr()->in('s.id'':ids'))
  161.                     ->setParameter('ids'$ids);
  162.                 $actual $qb->getQuery()->getSingleScalarResult();
  163.                 $expected count($ids);
  164.                 if ($actual != $expected) {
  165.                     $form['ids']->addError(
  166.                         new FormError(trans('admin.order.delivery_note_parameter_error'))
  167.                     );
  168.                 }
  169.             });
  170.     }
  171.     /**
  172.      * Get name method (form factory name).
  173.      *
  174.      * @return string
  175.      */
  176.     public function getName()
  177.     {
  178.         return 'admin_order_pdf';
  179.     }
  180. }