1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
declare(strict_types=1); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
25
|
|
|
* |
26
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) |
27
|
|
|
* |
28
|
|
|
* This program is free software; you can redistribute it and/or |
29
|
|
|
* modify it under the terms of the GNU General Public License |
30
|
|
|
* as published by the Free Software Foundation; either version 2 |
31
|
|
|
* of the License, or (at your option) any later version. |
32
|
|
|
* |
33
|
|
|
* This program is distributed in the hope that it will be useful, |
34
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
35
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
36
|
|
|
* GNU General Public License for more details. |
37
|
|
|
* |
38
|
|
|
* You should have received a copy of the GNU General Public License |
39
|
|
|
* along with this program; if not, write to the Free Software |
40
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
41
|
|
|
*/ |
42
|
|
|
|
43
|
|
|
namespace App\Controller; |
44
|
|
|
|
45
|
|
|
use App\Controller\AdminPages\BaseAdminController; |
46
|
|
|
use App\Entity\Attachments\GroupAttachment; |
47
|
|
|
use App\Entity\Base\AbstractNamedDBElement; |
48
|
|
|
use App\Entity\Parameters\GroupParameter; |
49
|
|
|
use App\Entity\UserSystem\Group; |
50
|
|
|
use App\Form\AdminPages\GroupAdminForm; |
51
|
|
|
use App\Services\EntityExporter; |
52
|
|
|
use App\Services\EntityImporter; |
53
|
|
|
use App\Services\StructuralElementRecursionHelper; |
54
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
55
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
56
|
|
|
use Symfony\Component\HttpFoundation\Request; |
57
|
|
|
use Symfony\Component\HttpFoundation\Response; |
58
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Route("/group") |
62
|
|
|
*/ |
63
|
|
|
class GroupController extends BaseAdminController |
64
|
|
|
{ |
65
|
|
|
protected $entity_class = Group::class; |
66
|
|
|
protected $twig_template = 'AdminPages/GroupAdmin.html.twig'; |
67
|
|
|
protected $form_class = GroupAdminForm::class; |
68
|
|
|
protected $route_base = 'group'; |
69
|
|
|
protected $attachment_class = GroupAttachment::class; |
70
|
|
|
protected $parameter_class = GroupParameter::class; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Route("/{id}/edit/{timestamp}", requirements={"id"="\d+"}, name="group_edit") |
74
|
|
|
* @Route("/{id}/", requirements={"id"="\d+"}) |
75
|
|
|
* |
76
|
|
|
* @return Response |
77
|
|
|
*/ |
78
|
|
|
public function edit(Group $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response |
79
|
|
|
{ |
80
|
|
|
return $this->_edit($entity, $request, $em, $timestamp); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @Route("/new", name="group_new") |
85
|
|
|
* @Route("/{id}/clone", name="group_clone") |
86
|
|
|
* @Route("/") |
87
|
|
|
* |
88
|
|
|
* @return Response |
89
|
|
|
*/ |
90
|
|
|
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer, ?Group $entity = null): Response |
91
|
|
|
{ |
92
|
|
|
return $this->_new($request, $em, $importer, $entity); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @Route("/{id}", name="group_delete", methods={"DELETE"}) |
97
|
|
|
* |
98
|
|
|
* @return RedirectResponse |
99
|
|
|
*/ |
100
|
|
|
public function delete(Request $request, Group $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse |
101
|
|
|
{ |
102
|
|
|
return $this->_delete($request, $entity, $recursionHelper); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @Route("/export", name="group_export_all") |
107
|
|
|
* |
108
|
|
|
* @return Response |
109
|
|
|
*/ |
110
|
|
|
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request): Response |
111
|
|
|
{ |
112
|
|
|
return $this->_exportAll($em, $exporter, $request); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @Route("/{id}/export", name="group_export") |
117
|
|
|
* |
118
|
|
|
* @return Response |
119
|
|
|
*/ |
120
|
|
|
public function exportEntity(Group $entity, EntityExporter $exporter, Request $request): Response |
121
|
|
|
{ |
122
|
|
|
return $this->_exportEntity($entity, $exporter, $request); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function deleteCheck(AbstractNamedDBElement $entity): bool |
126
|
|
|
{ |
127
|
|
|
if ($entity instanceof Group) { |
128
|
|
|
if ($entity->getUsers()->count() > 0) { |
129
|
|
|
$this->addFlash('error', 'entity.delete.must_not_contain_users'); |
130
|
|
|
return false; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return true; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|