Failed Conditions
Pull Request — 3.0.9-dev (#1466)
by k-yamamura
74:16 queued 48:01
created

AuthorityController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 45%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 10
lcom 0
cbo 4
dl 0
loc 84
ccs 9
cts 20
cp 0.45
rs 10
c 2
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
C index() 0 80 10
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\Controller\Admin\Setting\System;
26
27
use Eccube\Application;
28
use Eccube\Controller\AbstractController;
29
use Eccube\Event\EccubeEvents;
30
use Eccube\Event\EventArgs;
31
use Symfony\Component\HttpFoundation\Request;
32
33
class AuthorityController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
34
{
35
36 1
    public function index(Application $app, Request $request)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
37
    {
38
        $AuthorityRoles = $app['eccube.repository.authority_role']->findAllSort();
39
40
        $builder = $app['form.factory']->createBuilder();
41
        $builder
42
            ->add('AuthorityRoles', 'collection', array(
43 1
                'type' => 'admin_authority_role',
44 1
                'allow_add' => true,
45 1
                'allow_delete' => true,
46 1
                'prototype' => true,
47
                'data' => $AuthorityRoles,
48
            ));
49
50
        $event = new EventArgs(
51
            array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
52
                'builder' => $builder,
53
                'AuthorityRoles' => $AuthorityRoles
54 1
            ),
55
            $request
56
        );
57
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_AUTHORITY_INDEX_INITIALIZE, $event);
58
59
        $form = $builder->getForm();
60
61
        if (count($AuthorityRoles) == 0) {
62
            // 1件もない場合、空行を追加
63
            $form->get('AuthorityRoles')->add(uniqid(), 'admin_authority_role');
64
        }
65
66
67
        if ('POST' === $request->getMethod()) {
68
69
            $form->handleRequest($request);
70
71
            if ($form->isValid()) {
72
                $data = $form->getData();
73
74
                foreach ($AuthorityRoles as $AuthorityRole) {
75
                    $app['orm.em']->remove($AuthorityRole);
76
                }
77
78
                foreach ($data['AuthorityRoles'] as $AuthorityRole) {
79
                    $Authority = $AuthorityRole->getAuthority();
80
                    $denyUrl = $AuthorityRole->getDenyUrl();
81
                    if ($Authority && !empty($denyUrl)) {
82
                        $app['orm.em']->persist($AuthorityRole);
83
                    } else {
84
                        $id = $AuthorityRole->getId();
85
                        if (!empty($id)) {
86
                            $role = $app['eccube.repository.authority_role']->find($id);
87
                            if ($role) {
88
                                // 削除
89
                                $app['orm.em']->remove($AuthorityRole);
90
                            }
91
                        }
92
                    }
93
                }
94
                $app['orm.em']->flush();
95
96
                $event = new EventArgs(
97
                    array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
98
                        'form' => $form,
99
                        'AuthorityRoles' => $AuthorityRoles
100
                    ),
101
                    $request
102
                );
103
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_AUTHORITY_INDEX_COMPLETE, $event);
104
105
                $app->addSuccess('admin.system.authority.save.complete', 'admin');
106
107
                return $app->redirect($app->url('admin_setting_system_authority'));
108
109
            }
110
        }
111
112 1
        return $app->render('Setting/System/authority.twig', array(
113 1
            'form' => $form->createView(),
114
        ));
115 1
    }
116
}
117