1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* part-db version 0.1 |
4
|
|
|
* Copyright (C) 2005 Christoph Lechner |
5
|
|
|
* http://www.cl-projects.de/. |
6
|
|
|
* |
7
|
|
|
* part-db version 0.2+ |
8
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
9
|
|
|
* http://code.google.com/p/part-db/ |
10
|
|
|
* |
11
|
|
|
* Part-DB Version 0.4+ |
12
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
13
|
|
|
* https://github.com/jbtronics |
14
|
|
|
* |
15
|
|
|
* This program is free software; you can redistribute it and/or |
16
|
|
|
* modify it under the terms of the GNU General Public License |
17
|
|
|
* as published by the Free Software Foundation; either version 2 |
18
|
|
|
* of the License, or (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* This program is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* You should have received a copy of the GNU General Public License |
26
|
|
|
* along with this program; if not, write to the Free Software |
27
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
namespace App\Controller; |
31
|
|
|
|
32
|
|
|
use App\Entity\Category; |
33
|
|
|
use App\Entity\Device; |
34
|
|
|
use App\Entity\Footprint; |
35
|
|
|
use App\Entity\Manufacturer; |
36
|
|
|
use App\Entity\Storelocation; |
37
|
|
|
use App\Entity\Supplier; |
38
|
|
|
use App\Helpers\TreeViewNode; |
39
|
|
|
use App\Services\ToolsTreeBuilder; |
40
|
|
|
use App\Services\TreeBuilder; |
41
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
42
|
|
|
use Symfony\Component\Form\Extension\Core\Type\LocaleType; |
43
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* This controller has the purpose to provide the data for all treeviews. |
47
|
|
|
* |
48
|
|
|
* @package App\Controller |
49
|
|
|
*/ |
50
|
|
|
class TreeController extends AbstractController |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* @Route("/tree/tools/", name="tree_tools") |
54
|
|
|
*/ |
55
|
|
|
public function tools(ToolsTreeBuilder $builder) |
56
|
|
|
{ |
57
|
|
|
$tree = $builder->getTree(); |
58
|
|
|
|
59
|
|
|
//Ignore null values, to save data |
60
|
|
|
return $this->json($tree, 200, [], ['skip_null_values' => true]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @Route("/tree/category/{id}", name="tree_category") |
65
|
|
|
* @Route("/tree/categories") |
66
|
|
|
*/ |
67
|
|
|
public function categoryTree(TreeBuilder $builder, Category $category = null) |
68
|
|
|
{ |
69
|
|
|
if ($category != null) { |
70
|
|
|
$tree[] = $builder->elementToTreeNode($category); |
|
|
|
|
71
|
|
|
} else { |
72
|
|
|
$tree = $builder->typeToTree(Category::class); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
return $this->json($tree, 200, [], ['skip_null_values' => true]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @Route("/tree/footprint/{id}", name="tree_footprint") |
81
|
|
|
* @Route("/tree/footprints") |
82
|
|
|
*/ |
83
|
|
|
public function footprintTree(TreeBuilder $builder, Footprint $footprint = null) |
84
|
|
|
{ |
85
|
|
|
if ($footprint != null) { |
86
|
|
|
$tree[] = $builder->elementToTreeNode($footprint); |
|
|
|
|
87
|
|
|
} else { |
88
|
|
|
$tree = $builder->typeToTree(Footprint::class, null); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
return $this->json($tree, 200, [], ['skip_null_values' => true]); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @Route("/tree/location/{id}", name="tree_location") |
97
|
|
|
* @Route("/tree/locations") |
98
|
|
|
*/ |
99
|
|
|
public function locationTree(TreeBuilder $builder, Storelocation $location = null) |
100
|
|
|
{ |
101
|
|
|
if ($location != null) { |
102
|
|
|
$tree[] = $builder->elementToTreeNode($location); |
|
|
|
|
103
|
|
|
} else { |
104
|
|
|
$tree = $builder->typeToTree(Storelocation::class, null); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
return $this->json($tree, 200, [], ['skip_null_values' => true]); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @Route("/tree/manufacturer/{id}", name="tree_manufacturer") |
113
|
|
|
* @Route("/tree/manufacturers") |
114
|
|
|
*/ |
115
|
|
|
public function manufacturerTree(TreeBuilder $builder, Manufacturer $manufacturer = null) |
116
|
|
|
{ |
117
|
|
|
if ($manufacturer != null) { |
118
|
|
|
$tree[] = $builder->elementToTreeNode($manufacturer); |
|
|
|
|
119
|
|
|
} else { |
120
|
|
|
$tree = $builder->typeToTree(Manufacturer::class, null); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
return $this->json($tree, 200, [], ['skip_null_values' => true]); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @Route("/tree/supplier/{id}", name="tree_supplier") |
129
|
|
|
* @Route("/tree/suppliers") |
130
|
|
|
*/ |
131
|
|
|
public function supplierTree(TreeBuilder $builder, Supplier $supplier = null) |
132
|
|
|
{ |
133
|
|
|
if ($supplier != null) { |
134
|
|
|
$tree[] = $builder->elementToTreeNode($supplier); |
|
|
|
|
135
|
|
|
} else { |
136
|
|
|
$tree = $builder->typeToTree(Supplier::class, null); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
return $this->json($tree, 200, [], ['skip_null_values' => true]); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @Route("/tree/device/{id}", name="tree_device") |
145
|
|
|
* @Route("/tree/devices") |
146
|
|
|
*/ |
147
|
|
|
public function deviceTree(TreeBuilder $builder, Device $device = null) |
148
|
|
|
{ |
149
|
|
|
if ($device != null) { |
150
|
|
|
$tree[] = $builder->elementToTreeNode($device); |
|
|
|
|
151
|
|
|
} else { |
152
|
|
|
$tree = $builder->typeToTree(Device::class, null); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
return $this->json($tree, 200, [], ['skip_null_values' => true]); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
} |
161
|
|
|
|