1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Controller\Admin\Setting\System; |
15
|
|
|
|
16
|
|
|
use Eccube\Controller\AbstractController; |
17
|
|
|
use Eccube\Event\EccubeEvents; |
18
|
|
|
use Eccube\Event\EventArgs; |
19
|
|
|
use Eccube\Form\Type\Admin\AuthorityRoleType; |
20
|
|
|
use Eccube\Repository\AuthorityRoleRepository; |
21
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
22
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
23
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType; |
24
|
|
|
use Symfony\Component\HttpFoundation\Request; |
25
|
|
|
|
26
|
|
|
class AuthorityController extends AbstractController |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var AuthorityRoleRepository |
30
|
|
|
*/ |
31
|
|
|
protected $authorityRoleRepository; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* AuthorityController constructor. |
35
|
|
|
* |
36
|
|
|
* @param AuthorityRoleRepository $authorityRoleRepository |
37
|
|
|
*/ |
38
|
5 |
|
public function __construct(AuthorityRoleRepository $authorityRoleRepository) |
39
|
|
|
{ |
40
|
5 |
|
$this->authorityRoleRepository = $authorityRoleRepository; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @Route("/%eccube_admin_route%/setting/system/authority", name="admin_setting_system_authority") |
45
|
|
|
* @Template("@admin/Setting/System/authority.twig") |
46
|
|
|
*/ |
47
|
5 |
|
public function index(Request $request) |
48
|
|
|
{ |
49
|
5 |
|
$AuthorityRoles = $this->authorityRoleRepository->findAllSort(); |
50
|
|
|
|
51
|
5 |
|
$builder = $this->formFactory->createBuilder(); |
52
|
|
|
$builder |
53
|
5 |
|
->add( |
54
|
5 |
|
'AuthorityRoles', |
55
|
5 |
|
CollectionType::class, |
56
|
|
|
[ |
57
|
5 |
|
'entry_type' => AuthorityRoleType::class, |
58
|
|
|
'allow_add' => true, |
59
|
|
|
'allow_delete' => true, |
60
|
|
|
'prototype' => true, |
61
|
5 |
|
'data' => $AuthorityRoles, |
62
|
|
|
] |
63
|
|
|
); |
64
|
|
|
|
65
|
5 |
|
$event = new EventArgs( |
66
|
|
|
[ |
67
|
5 |
|
'builder' => $builder, |
68
|
5 |
|
'AuthorityRoles' => $AuthorityRoles, |
69
|
|
|
], |
70
|
5 |
|
$request |
71
|
|
|
); |
72
|
5 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_AUTHORITY_INDEX_INITIALIZE, $event); |
73
|
|
|
|
74
|
5 |
|
$form = $builder->getForm(); |
75
|
|
|
|
76
|
5 |
|
if (count($AuthorityRoles) == 0) { |
77
|
|
|
// 1件もない場合、空行を追加 |
78
|
2 |
|
$form->get('AuthorityRoles')->add(uniqid(), AuthorityRoleType::class); |
79
|
|
|
} |
80
|
|
|
|
81
|
5 |
|
if ('POST' === $request->getMethod()) { |
82
|
3 |
|
$form->handleRequest($request); |
83
|
|
|
|
84
|
3 |
|
if ($form->isValid()) { |
85
|
3 |
|
$data = $form->getData(); |
86
|
|
|
|
87
|
3 |
|
foreach ($AuthorityRoles as $AuthorityRole) { |
88
|
2 |
|
$this->entityManager->remove($AuthorityRole); |
89
|
|
|
} |
90
|
|
|
|
91
|
3 |
|
foreach ($data['AuthorityRoles'] as $AuthorityRole) { |
92
|
3 |
|
$Authority = $AuthorityRole->getAuthority(); |
93
|
3 |
|
$denyUrl = $AuthorityRole->getDenyUrl(); |
94
|
3 |
|
if ($Authority && !empty($denyUrl)) { |
95
|
2 |
|
$this->entityManager->persist($AuthorityRole); |
96
|
|
|
} else { |
97
|
1 |
|
$id = $AuthorityRole->getId(); |
98
|
1 |
|
if (!empty($id)) { |
99
|
1 |
|
$role = $this->authorityRoleRepository->find($id); |
|
|
|
|
100
|
1 |
|
if ($role) { |
101
|
|
|
// 削除 |
102
|
3 |
|
$this->entityManager->remove($AuthorityRole); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
3 |
|
$this->entityManager->flush(); |
108
|
|
|
|
109
|
3 |
|
$event = new EventArgs( |
110
|
|
|
[ |
111
|
3 |
|
'form' => $form, |
112
|
3 |
|
'AuthorityRoles' => $AuthorityRoles, |
113
|
|
|
], |
114
|
3 |
|
$request |
115
|
|
|
); |
116
|
3 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_AUTHORITY_INDEX_COMPLETE, $event); |
117
|
|
|
|
118
|
3 |
|
$this->addSuccess('admin.system.authority.save.complete', 'admin'); |
119
|
|
|
|
120
|
3 |
|
return $this->redirectToRoute('admin_setting_system_authority'); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return [ |
125
|
2 |
|
'form' => $form->createView(), |
126
|
|
|
]; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.