Skip to content

Commit

Permalink
Merge 4906d21 into 3bcbc5c
Browse files Browse the repository at this point in the history
  • Loading branch information
nobuhiko committed Nov 26, 2015
2 parents 3bcbc5c + 4906d21 commit 3edc4ab
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 0 deletions.
114 changes: 114 additions & 0 deletions src/Eccube/Controller/Admin/Setting/System/MasterdataController.php
@@ -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(),
));
}
}
4 changes: 4 additions & 0 deletions src/Eccube/ControllerProvider/AdminControllerProvider.php
Expand Up @@ -204,6 +204,10 @@ public function connect(Application $app)
// system/log
$c->match('/setting/system/log', '\Eccube\Controller\Admin\Setting\System\LogController::index')->bind('admin_setting_system_log');

// system/masterdata
$c->match('/setting/system/masterdata', '\Eccube\Controller\Admin\Setting\System\MasterdataController::index')->bind('admin_setting_system_masterdata');
$c->match('/setting/system/masterdata/edit', '\Eccube\Controller\Admin\Setting\System\MasterdataController::edit')->bind('admin_setting_system_masterdata_edit');

// store
$c->match('/store/template', '\Eccube\Controller\Admin\Store\TemplateController::index')->bind('admin_store_template');
$c->match('/store/template/install', '\Eccube\Controller\Admin\Store\TemplateController::add')->bind('admin_store_template_install');
Expand Down
74 changes: 74 additions & 0 deletions src/Eccube/Form/Type/Admin/MasterdataDataType.php
@@ -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';
}
}
68 changes: 68 additions & 0 deletions src/Eccube/Form/Type/Admin/MasterdataEditType.php
@@ -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';
}
}
79 changes: 79 additions & 0 deletions src/Eccube/Form/Type/Admin/MasterdataType.php
@@ -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';
}
}
3 changes: 3 additions & 0 deletions src/Eccube/Resource/config/nav.yml.dist
Expand Up @@ -110,6 +110,9 @@
- id: log
name: EC-CUBE ログ表示
url: admin_setting_system_log
- id: masterdata
name: マスターデータ管理
url: admin_setting_system_masterdata
- id: store
name: オーナーズストア
has_child: true
Expand Down

0 comments on commit 3edc4ab

Please sign in to comment.