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.                 'format' => 'yyyy-MM-dd',
  67.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  68.                 'data' => new \DateTime(),
  69.                 'constraints' => [
  70.                     new Assert\NotBlank(),
  71.                     new Assert\DateTime(),
  72.                 ],
  73.                 'attr' => [
  74.                     'data-target' => '#'.$this->getBlockPrefix().'_issue_date',
  75.                     'data-toggle' => 'datetimepicker',
  76.                 ],
  77.             ])
  78.             ->add('title'TextType::class, [
  79.                 'required' => false,
  80.                 'attr' => ['maxlength' => $config['eccube_stext_len']],
  81.                 'constraints' => [
  82.                     new Assert\Length(['max' => $config['eccube_stext_len']]),
  83.                 ],
  84.             ])
  85.             ->add('download_kind'ChoiceType::class, [
  86.                 'choices' => [
  87.                     'admin.order.delivery_note_output_format__file' => 1,
  88.                     'admin.order.delivery_note_output_format__browser' => 2,
  89.                 ],
  90.                 'expanded' => false,
  91.                 'multiple' => false,
  92.                 'required' => false,
  93.                 'mapped' => false,
  94.                 'placeholder' => false,
  95.             ])
  96.             // メッセージ
  97.             ->add('message1'TextType::class, [
  98.                 'required' => false,
  99.                 'attr' => ['maxlength' => $config['eccube_order_pdf_message_len']],
  100.                 'constraints' => [
  101.                     new Assert\Length(['max' => $config['eccube_order_pdf_message_len']]),
  102.                 ],
  103.                 'trim' => false,
  104.             ])
  105.             ->add('message2'TextType::class, [
  106.                 'required' => false,
  107.                 'attr' => ['maxlength' => $config['eccube_order_pdf_message_len']],
  108.                 'constraints' => [
  109.                     new Assert\Length(['max' => $config['eccube_order_pdf_message_len']]),
  110.                 ],
  111.                 'trim' => false,
  112.             ])
  113.             ->add('message3'TextType::class, [
  114.                 'required' => false,
  115.                 'attr' => ['maxlength' => $config['eccube_order_pdf_message_len']],
  116.                 'constraints' => [
  117.                     new Assert\Length(['max' => $config['eccube_order_pdf_message_len']]),
  118.                 ],
  119.                 'trim' => false,
  120.             ])
  121.             // 備考
  122.             ->add('note1'TextType::class, [
  123.                 'required' => false,
  124.                 'attr' => ['maxlength' => $config['eccube_stext_len']],
  125.                 'constraints' => [
  126.                     new Assert\Length(['max' => $config['eccube_stext_len']]),
  127.                 ],
  128.             ])
  129.             ->add('note2'TextType::class, [
  130.                 'required' => false,
  131.                 'attr' => ['maxlength' => $config['eccube_stext_len']],
  132.                 'constraints' => [
  133.                     new Assert\Length(['max' => $config['eccube_stext_len']]),
  134.                 ],
  135.             ])
  136.             ->add('note3'TextType::class, [
  137.                 'required' => false,
  138.                 'attr' => ['maxlength' => $config['eccube_stext_len']],
  139.                 'constraints' => [
  140.                     new Assert\Length(['max' => $config['eccube_stext_len']]),
  141.                 ],
  142.             ])
  143.             ->add('default'CheckboxType::class, [
  144.                 'label' => 'admin.order.delivery_note_save_input',
  145.                 'required' => false,
  146.             ])
  147.             ->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  148.                 $form $event->getForm();
  149.                 $data $form->getData();
  150.                 if (!isset($data['ids']) || !is_string($data['ids'])) {
  151.                     return;
  152.                 }
  153.                 $ids explode(','$data['ids']);
  154.                 $qb $this->entityManager->createQueryBuilder();
  155.                 $qb->select('count(s.id)')
  156.                     ->from('Eccube\\Entity\\Shipping''s')
  157.                     ->where($qb->expr()->in('s.id'':ids'))
  158.                     ->setParameter('ids'$ids);
  159.                 $actual $qb->getQuery()->getSingleScalarResult();
  160.                 $expected count($ids);
  161.                 if ($actual != $expected) {
  162.                     $form['ids']->addError(
  163.                         new FormError(trans('admin.order.delivery_note_parameter_error'))
  164.                     );
  165.                 }
  166.             });
  167.     }
  168.     /**
  169.      * Get name method (form factory name).
  170.      *
  171.      * @return string
  172.      */
  173.     public function getName()
  174.     {
  175.         return 'admin_order_pdf';
  176.     }
  177. }