Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
458 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
src/Eccube/Controller/Admin/Setting/System/MasterdataController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.lockon.co.jp/ | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
|
||
namespace Eccube\Controller\Admin\Setting\System; | ||
|
||
use Eccube\Application; | ||
use Eccube\Controller\AbstractController; | ||
use Eccube\Form\Type\Admin\MasterdataDataType; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
class MasterdataController extends AbstractController | ||
{ | ||
public function index(Application $app, Request $request) | ||
{ | ||
$data = array(); | ||
|
||
$builder = $app['form.factory']->createBuilder('admin_system_masterdata'); | ||
$form = $builder->getForm(); | ||
|
||
if ('POST' === $request->getMethod()) { | ||
$form->handleRequest($request); | ||
if ($form->isValid()) { | ||
$data = $form->getData(); | ||
|
||
if ($data['masterdata']) { | ||
$masterdata = $app['orm.em']->getRepository($data['masterdata'])->findBy(array(), array('rank' => 'ASC')); | ||
|
||
foreach ($masterdata as $key => $value) { | ||
$data['data'][$value['rank']]['id'] = $value['id']; | ||
$data['data'][$value['rank']]['name'] = $value['name']; | ||
} | ||
|
||
$data['data'][$value['rank']+1]['id'] = ''; | ||
$data['data'][$value['rank']+1]['name'] = ''; | ||
|
||
$data['masterdata_name'] = $data['masterdata']; | ||
} | ||
} | ||
} | ||
|
||
$builder2 = $app['form.factory']->createBuilder('admin_system_masterdata_edit', $data); | ||
$form2 = $builder2->getForm(); | ||
|
||
return $app->render('Setting/System/masterdata.twig', array( | ||
'form' => $form->createView(), | ||
'form2' => $form2->createView(), | ||
)); | ||
} | ||
|
||
public function edit(Application $app, Request $request) | ||
{ | ||
$builder2 = $app['form.factory']->createBuilder('admin_system_masterdata_edit'); | ||
$form2 = $builder2->getForm(); | ||
|
||
if ('POST' === $request->getMethod()) { | ||
$form2->handleRequest($request); | ||
|
||
if ($form2->isValid()) { | ||
$data = $form2->getData(); | ||
|
||
$entity = new $data['masterdata_name'](); | ||
foreach ($data['data'] as $key => $value) { | ||
if ($value['id'] !== null && $value['name'] !== null) { | ||
$entity->setId($value['id']); | ||
$entity->setName($value['name']); | ||
$entity->setRank($key); | ||
$app['orm.em']->merge($entity); | ||
} else { | ||
// remove | ||
$rank = $app['orm.em']->getRepository($data['masterdata_name'])->findOneBy(array('rank' => $key)); | ||
if ($rank) { | ||
$app['orm.em']->remove($rank); | ||
} | ||
} | ||
} | ||
$app['orm.em']->flush(); | ||
$app->addSuccess('admin.register.complete', 'admin'); | ||
|
||
return $app->redirect($app->url('admin_setting_system_masterdata')); | ||
} | ||
} | ||
|
||
$builder = $app['form.factory']->createBuilder('admin_system_masterdata'); | ||
$form = $builder->getForm(); | ||
|
||
return $app->render('Setting/System/masterdata.twig', array( | ||
'form' => $form->createView(), | ||
'form2' => $form2->createView(), | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.lockon.co.jp/ | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
namespace Eccube\Form\Type\Admin; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class MasterdataDataType extends AbstractType | ||
{ | ||
protected $app; | ||
|
||
public function __construct($app) | ||
{ | ||
$this->app = $app; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$app = $this->app; | ||
|
||
$builder | ||
->add('id', 'text', array( | ||
'required' => false, | ||
'constraints' => array( | ||
new Assert\Length(array( | ||
'max' => $app['config']['int_len'], | ||
)), | ||
new Assert\Regex(array( | ||
'pattern' => "/^\d+$/u", | ||
'message' => 'form.type.numeric.invalid', | ||
)), | ||
), | ||
)) | ||
->add('name', 'text', array( | ||
'required' => false, | ||
)) | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'admin_system_masterdata_data'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.lockon.co.jp/ | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
namespace Eccube\Form\Type\Admin; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
class MasterdataEditType extends AbstractType | ||
{ | ||
protected $app; | ||
|
||
public function __construct($app) | ||
{ | ||
$this->app = $app; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$app = $this->app; | ||
|
||
$builder | ||
->add('data', 'collection', array( | ||
'type' => new MasterdataDataType($app), | ||
'allow_add' => true, | ||
'allow_delete' => true, | ||
'prototype' => true, | ||
)) | ||
->add('masterdata_name', 'hidden'); | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'admin_system_masterdata_edit'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.lockon.co.jp/ | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
namespace Eccube\Form\Type\Admin; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
class MasterdataType extends AbstractType | ||
{ | ||
protected $app; | ||
|
||
public function __construct($app) | ||
{ | ||
$this->app = $app; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$app = $this->app; | ||
|
||
$masterdata = array(); | ||
|
||
foreach ($app['orm.em']->getMetadataFactory()->getAllMetadata() as $meta) { | ||
if (strpos($meta->rootEntityName, 'Master') !== false) { | ||
$masterdata[$meta->getName()] = $meta->getTableName(); | ||
} | ||
} | ||
|
||
$builder | ||
->add('masterdata', 'choice', array( | ||
'choices' => $masterdata, | ||
'expanded' => false, | ||
'multiple' => false, | ||
'constraints' => array( | ||
new Assert\NotBlank(), | ||
), | ||
)) | ||
; | ||
|
||
$builder->addEventSubscriber(new \Eccube\Event\FormEventSubscriber()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'admin_system_masterdata'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.