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
|
|
|
namespace Eccube\Form\Type\Admin; |
25
|
|
|
|
26
|
|
|
use Symfony\Component\Form\AbstractType; |
27
|
|
|
use Symfony\Component\Form\Extension\Core\Type; |
28
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
29
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
30
|
|
|
|
31
|
|
|
class MasterdataType extends AbstractType |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
protected $app; |
34
|
|
|
|
35
|
663 |
|
public function __construct($app) |
|
|
|
|
36
|
|
|
{ |
37
|
663 |
|
$this->app = $app; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
4 |
|
public function buildForm(FormBuilderInterface $builder, array $options) |
44
|
|
|
{ |
45
|
|
|
/** @var $app \Eccube\Application */ |
46
|
4 |
|
$app = $this->app; |
47
|
|
|
|
48
|
4 |
|
$masterdata = array(); |
49
|
|
|
|
50
|
4 |
|
$driverChain = $app['orm.em']->getConfiguration()->getMetadataDriverImpl(); |
51
|
4 |
|
$drivers = $driverChain->getDrivers(); |
52
|
|
|
|
53
|
4 |
|
foreach ($drivers as $namespace => $driver) { |
54
|
4 |
|
if ($namespace == 'Eccube\Entity') { |
55
|
4 |
|
$classNames = $driver->getAllClassNames(); |
56
|
4 |
|
foreach ($classNames as $className) { |
57
|
4 |
|
$meta = $app['orm.em']->getMetadataFactory()->getMetadataFor($className); |
58
|
4 |
|
if (strpos($meta->rootEntityName, 'Master') !== false |
59
|
4 |
|
&& $meta->hasField('id') |
60
|
4 |
|
&& $meta->hasField('name') |
61
|
4 |
|
&& $meta->hasField('rank') |
62
|
|
|
) { |
63
|
4 |
|
$metadataName = str_replace('\\', '-', $meta->getName()); |
64
|
4 |
|
$masterdata[$metadataName] = $meta->getTableName(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$builder |
71
|
4 |
|
->add('masterdata', 'choice', array( |
72
|
4 |
|
'choices' => $masterdata, |
73
|
|
|
'expanded' => false, |
74
|
|
|
'multiple' => false, |
75
|
|
|
'constraints' => array( |
76
|
4 |
|
new Assert\NotBlank(), |
77
|
|
|
), |
78
|
|
|
)) |
79
|
|
|
; |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
663 |
|
public function getName() |
87
|
|
|
{ |
88
|
663 |
|
return 'admin_system_masterdata'; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|