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\AdminPages; |
44
|
|
|
|
45
|
|
|
use App\Entity\Attachments\AttachmentType; |
46
|
|
|
use App\Entity\Attachments\AttachmentTypeAttachment; |
47
|
|
|
use App\Entity\Base\AbstractNamedDBElement; |
48
|
|
|
use App\Entity\Parameters\AttachmentTypeParameter; |
49
|
|
|
use App\Form\AdminPages\AttachmentTypeAdminForm; |
50
|
|
|
use App\Services\EntityExporter; |
51
|
|
|
use App\Services\EntityImporter; |
52
|
|
|
use App\Services\StructuralElementRecursionHelper; |
53
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
54
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
55
|
|
|
use Symfony\Component\HttpFoundation\Request; |
56
|
|
|
use Symfony\Component\HttpFoundation\Response; |
57
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @Route("/attachment_type") |
61
|
|
|
*/ |
62
|
|
|
class AttachmentTypeController extends BaseAdminController |
63
|
|
|
{ |
64
|
|
|
protected $entity_class = AttachmentType::class; |
65
|
|
|
protected $twig_template = 'AdminPages/AttachmentTypeAdmin.html.twig'; |
66
|
|
|
protected $form_class = AttachmentTypeAdminForm::class; |
67
|
|
|
protected $route_base = 'attachment_type'; |
68
|
|
|
protected $attachment_class = AttachmentTypeAttachment::class; |
69
|
|
|
protected $parameter_class = AttachmentTypeParameter::class; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @Route("/{id}", name="attachment_type_delete", methods={"DELETE"}) |
73
|
|
|
* |
74
|
|
|
* @return RedirectResponse |
75
|
|
|
*/ |
76
|
|
|
public function delete(Request $request, AttachmentType $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse |
77
|
|
|
{ |
78
|
|
|
return $this->_delete($request, $entity, $recursionHelper); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Route("/{id}/edit/{timestamp}", requirements={"id"="\d+"}, name="attachment_type_edit") |
83
|
|
|
* @Route("/{id}", requirements={"id"="\d+"}) |
84
|
|
|
* |
85
|
|
|
* @return Response |
86
|
|
|
*/ |
87
|
|
|
public function edit(AttachmentType $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response |
88
|
|
|
{ |
89
|
|
|
return $this->_edit($entity, $request, $em, $timestamp); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @Route("/new", name="attachment_type_new") |
94
|
|
|
* @Route("/{id}/clone", name="attachment_type_clone") |
95
|
|
|
* @Route("/") |
96
|
|
|
* |
97
|
|
|
* @return Response |
98
|
|
|
*/ |
99
|
|
|
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer, ?AttachmentType $entity = null): Response |
100
|
|
|
{ |
101
|
|
|
return $this->_new($request, $em, $importer, $entity); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @Route("/export", name="attachment_type_export_all") |
106
|
|
|
* |
107
|
|
|
* @return Response |
108
|
|
|
*/ |
109
|
|
|
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request): Response |
110
|
|
|
{ |
111
|
|
|
return $this->_exportAll($em, $exporter, $request); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @Route("/{id}/export", name="attachment_type_export") |
116
|
|
|
* |
117
|
|
|
* @return Response |
118
|
|
|
*/ |
119
|
|
|
public function exportEntity(AttachmentType $entity, EntityExporter $exporter, Request $request): Response |
120
|
|
|
{ |
121
|
|
|
return $this->_exportEntity($entity, $exporter, $request); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
protected function deleteCheck(AbstractNamedDBElement $entity): bool |
125
|
|
|
{ |
126
|
|
|
if ($entity instanceof AttachmentType) { |
127
|
|
|
if ($entity->getAttachmentsForType()->count() > 0) { |
128
|
|
|
$this->addFlash('error', 'entity.delete.must_not_contain_attachments'); |
129
|
|
|
return false; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
return true; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|