1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace Eccube\Form\Type\Admin; |
26
|
|
|
|
27
|
|
|
use Symfony\Component\Form\AbstractType; |
28
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
29
|
|
|
use Symfony\Component\Form\FormError; |
30
|
|
|
use Symfony\Component\Form\FormEvents; |
31
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
32
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
33
|
|
|
|
34
|
|
|
class BlockType extends AbstractType |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
public $app; |
37
|
|
|
|
38
|
663 |
|
public function __construct(\Silex\Application $app) |
|
|
|
|
39
|
|
|
{ |
40
|
663 |
|
$this->app = $app; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
4 |
|
public function buildForm(FormBuilderInterface $builder, array $options) |
47
|
|
|
{ |
48
|
4 |
|
$app = $this->app; |
49
|
|
|
|
50
|
|
|
$builder |
51
|
4 |
|
->add('name', 'text', array( |
|
|
|
|
52
|
4 |
|
'label' => 'ブロック名', |
53
|
|
|
'required' => true, |
54
|
|
|
'constraints' => array( |
|
|
|
|
55
|
4 |
|
new Assert\NotBlank(), |
56
|
4 |
|
new Assert\Length(array( |
57
|
4 |
|
'max' => $app['config']['stext_len'], |
58
|
|
|
)) |
59
|
|
|
) |
60
|
|
|
)) |
61
|
4 |
|
->add('file_name', 'text', array( |
|
|
|
|
62
|
4 |
|
'label' => 'ファイル名', |
63
|
|
|
'required' => true, |
64
|
|
|
'constraints' => array( |
65
|
4 |
|
new Assert\NotBlank(), |
66
|
4 |
|
new Assert\Length(array( |
67
|
4 |
|
'max' => $app['config']['stext_len'], |
68
|
|
|
)), |
69
|
4 |
|
new Assert\Regex(array( |
70
|
4 |
|
'pattern' => '/^[0-9a-zA-Z\/_]+$/', |
71
|
|
|
)), |
72
|
|
|
) |
73
|
|
|
)) |
74
|
4 |
|
->add('block_html', 'textarea', array( |
|
|
|
|
75
|
4 |
|
'label' => 'ブロックデータ', |
76
|
|
|
'mapped' => false, |
77
|
|
|
'required' => false, |
78
|
|
|
'constraints' => array() |
79
|
|
|
)) |
80
|
4 |
|
->add('DeviceType', 'entity', array( |
81
|
4 |
|
'class' => 'Eccube\Entity\Master\DeviceType', |
82
|
|
|
'property' => 'id', |
83
|
|
|
)) |
84
|
4 |
|
->add('id', 'hidden') |
85
|
4 |
View Code Duplication |
->addEventListener(FormEvents::POST_SUBMIT, function($event) use ($app) { |
|
|
|
|
86
|
2 |
|
$form = $event->getForm(); |
87
|
2 |
|
$file_name = $form['file_name']->getData(); |
88
|
2 |
|
$DeviceType = $form['DeviceType']->getData(); |
89
|
2 |
|
$block_id = $form['id']->getData(); |
90
|
|
|
|
91
|
2 |
|
$qb = $app['orm.em']->createQueryBuilder(); |
92
|
2 |
|
$qb->select('b') |
93
|
2 |
|
->from('Eccube\\Entity\\Block', 'b') |
94
|
2 |
|
->where('b.file_name = :file_name') |
95
|
2 |
|
->setParameter('file_name', $file_name) |
96
|
2 |
|
->andWhere('b.DeviceType = :DeviceType') |
97
|
2 |
|
->setParameter('DeviceType', $DeviceType); |
98
|
2 |
|
if (isset($block_id)) { |
99
|
|
|
$qb |
100
|
2 |
|
->andWhere('b.id <> :block_id') |
101
|
2 |
|
->setParameter('block_id', $block_id); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$Block = $qb |
105
|
2 |
|
->getQuery() |
106
|
2 |
|
->getResult(); |
107
|
2 |
|
if (count($Block) > 0) { |
108
|
|
|
$form['file_name']->addError(new FormError('※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。')); |
109
|
|
|
} |
110
|
4 |
|
}); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
4 |
|
public function setDefaultOptions(OptionsResolverInterface $resolver) |
117
|
|
|
{ |
118
|
4 |
|
$resolver->setDefaults(array( |
119
|
4 |
|
'data_class' => 'Eccube\Entity\Block', |
120
|
|
|
)); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* {@inheritdoc} |
125
|
|
|
*/ |
126
|
663 |
|
public function getName() |
127
|
|
|
{ |
128
|
663 |
|
return 'block'; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|