|
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\DataTables; |
|
31
|
|
|
|
|
32
|
|
|
use App\DataTables\Column\LocaleDateTimeColumn; |
|
33
|
|
|
use App\Entity\Parts\Category; |
|
34
|
|
|
use App\Entity\Parts\Part; |
|
35
|
|
|
use App\Services\EntityURLGenerator; |
|
36
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
37
|
|
|
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider; |
|
38
|
|
|
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter; |
|
39
|
|
|
use Omines\DataTablesBundle\Column\BoolColumn; |
|
40
|
|
|
use Omines\DataTablesBundle\Column\DateTimeColumn; |
|
41
|
|
|
use Omines\DataTablesBundle\Column\MapColumn; |
|
42
|
|
|
use Omines\DataTablesBundle\Column\TextColumn; |
|
43
|
|
|
use Omines\DataTablesBundle\DataTable; |
|
44
|
|
|
use Omines\DataTablesBundle\DataTableTypeInterface; |
|
45
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
46
|
|
|
|
|
47
|
|
|
class PartsDataTable implements DataTableTypeInterface |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* @var EntityURLGenerator |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $urlGenerator; |
|
53
|
|
|
protected $translator; |
|
54
|
|
|
|
|
55
|
|
|
public function __construct(EntityURLGenerator $urlGenerator, TranslatorInterface $translator) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->urlGenerator = $urlGenerator; |
|
58
|
|
|
$this->translator = $translator; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function getQuery(QueryBuilder $builder) |
|
62
|
|
|
{ |
|
63
|
|
|
$builder->select('p') |
|
64
|
|
|
->addSelect('category') |
|
65
|
|
|
->addSelect('footprint') |
|
66
|
|
|
->addSelect('manufacturer') |
|
67
|
|
|
->addSelect('partUnit') |
|
68
|
|
|
->from(Part::class, 'p') |
|
69
|
|
|
->leftJoin('p.category', 'category') |
|
70
|
|
|
->leftJoin('p.footprint', 'footprint') |
|
71
|
|
|
->leftJoin('p.manufacturer', 'manufacturer') |
|
72
|
|
|
->leftJoin('p.partUnit', 'partUnit'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
protected function buildCriteria(QueryBuilder $builder, array $options) |
|
76
|
|
|
{ |
|
77
|
|
|
if (isset($options['category'])) { |
|
78
|
|
|
$em = $builder->getEntityManager(); |
|
79
|
|
|
$category = $options['category']; |
|
80
|
|
|
$repo = $em->getRepository(Category::class); |
|
81
|
|
|
$list = $repo->toNodesList($category); |
|
82
|
|
|
$list[] = $category; |
|
83
|
|
|
|
|
84
|
|
|
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if (isset($options['tag'])) { |
|
88
|
|
|
$builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%' . $options['tag'] . '%'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (isset($options['search'])) { |
|
92
|
|
|
$builder->AndWhere('part.name LIKE :search')->orWhere('part.description LIKE :search')->orWhere('part.comment LIKE :search') |
|
93
|
|
|
->setParameter('search', '%' . $options['search'] . '%'); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param DataTable $dataTable |
|
99
|
|
|
* @param array $options |
|
100
|
|
|
*/ |
|
101
|
|
|
public function configure(DataTable $dataTable, array $options) |
|
102
|
|
|
{ |
|
103
|
|
|
$dataTable |
|
104
|
|
|
->add('name', TextColumn::class, [ |
|
105
|
|
|
'label' => $this->translator->trans('part.table.name'), |
|
106
|
|
|
'render' => function ($value, Part $context) { |
|
107
|
|
|
return $this->urlGenerator->infoHTML($context); |
|
108
|
|
|
}, |
|
109
|
|
|
]) |
|
110
|
|
|
->add('id', TextColumn::class, [ |
|
111
|
|
|
'label' => $this->translator->trans('part.table.id'), |
|
112
|
|
|
'visible' => false |
|
113
|
|
|
]) |
|
114
|
|
|
->add('description', TextColumn::class, [ |
|
115
|
|
|
'label' => $this->translator->trans('part.table.description'), |
|
116
|
|
|
]) |
|
117
|
|
|
->add('category', TextColumn::class, [ |
|
118
|
|
|
'field' => 'category.name', |
|
119
|
|
|
'label' => $this->translator->trans('part.table.category') |
|
120
|
|
|
]) |
|
121
|
|
|
->add('footprint', TextColumn::class, [ |
|
122
|
|
|
'field' => 'footprint.name', |
|
123
|
|
|
'label' => $this->translator->trans('part.table.footprint') |
|
124
|
|
|
]) |
|
125
|
|
|
->add('manufacturer', TextColumn::class, [ |
|
126
|
|
|
'field' => 'manufacturer.name', |
|
127
|
|
|
'label' => $this->translator->trans('part.table.manufacturer') |
|
128
|
|
|
]) |
|
129
|
|
|
//->add('footprint', TextColumn::class, ['field' => 'footprint.name']) |
|
130
|
|
|
//->add('manufacturer', TextColumn::class, ['field' => 'manufacturer.name' ]) |
|
131
|
|
|
//->add('amountSum', TextColumn::class, ['label' => 'instock.label_short']) |
|
132
|
|
|
->add('amount', TextColumn::class, [ |
|
133
|
|
|
'label' => $this->translator->trans('part.table.amount'), |
|
134
|
|
|
'propertyPath' => 'amountSum' |
|
135
|
|
|
]) |
|
136
|
|
|
->add('minamount', TextColumn::class, [ |
|
137
|
|
|
'label' => $this->translator->trans('part.table.minamount'), |
|
138
|
|
|
'visible' => false |
|
139
|
|
|
]) |
|
140
|
|
|
->add('partUnit', TextColumn::class, [ |
|
141
|
|
|
'field' => 'partUnit.name', |
|
142
|
|
|
'label' => $this->translator->trans('part.table.partUnit'), |
|
143
|
|
|
'visible' => false |
|
144
|
|
|
]) |
|
145
|
|
|
->add('addedDate', LocaleDateTimeColumn::class, [ |
|
146
|
|
|
'label' => $this->translator->trans('part.table.addedDate'), |
|
147
|
|
|
'visible' => false |
|
148
|
|
|
]) |
|
149
|
|
|
->add('lastModified', LocaleDateTimeColumn::class, [ |
|
150
|
|
|
'label' => $this->translator->trans('part.table.lastModified'), |
|
151
|
|
|
'visible' => false |
|
152
|
|
|
]) |
|
153
|
|
|
->add('needs_review', BoolColumn::class, [ |
|
154
|
|
|
'label' => $this->translator->trans('part.table.needsReview'), |
|
155
|
|
|
'trueValue' => $this->translator->trans('true'), |
|
156
|
|
|
'falseValue' => $this->translator->trans('false'), |
|
157
|
|
|
'nullValue' => '', |
|
158
|
|
|
'visible' => false |
|
159
|
|
|
]) |
|
160
|
|
|
->add('favorite', BoolColumn::class, [ |
|
161
|
|
|
'label' => $this->translator->trans('part.table.favorite'), |
|
162
|
|
|
'trueValue' => $this->translator->trans('true'), |
|
163
|
|
|
'falseValue' => $this->translator->trans('false'), |
|
164
|
|
|
'nullValue' => '', |
|
165
|
|
|
'visible' => false |
|
166
|
|
|
]) |
|
167
|
|
|
->add('manufacturing_status', MapColumn::class, [ |
|
168
|
|
|
'label' => $this->translator->trans('part.table.manufacturingStatus'), |
|
169
|
|
|
'visible' => false, |
|
170
|
|
|
'default' => $this->translator->trans('m_status.unknown'), |
|
171
|
|
|
'map' => [ |
|
172
|
|
|
'' => $this->translator->trans('m_status.unknown'), |
|
173
|
|
|
'announced' => $this->translator->trans('m_status.announced'), |
|
174
|
|
|
'active' => $this->translator->trans('m_status.active'), |
|
175
|
|
|
'nrfnd' => $this->translator->trans('m_status.nrfnd'), |
|
176
|
|
|
'eol' => $this->translator->trans('m_status.eol'), |
|
177
|
|
|
'discontinued' => $this->translator->trans('m_status.discontinued') |
|
178
|
|
|
] |
|
179
|
|
|
]) |
|
180
|
|
|
->add('manufacturer_product_number', TextColumn::class, [ |
|
181
|
|
|
'label' => $this->translator->trans('part.table.mpn'), |
|
182
|
|
|
'visible' => false |
|
183
|
|
|
]) |
|
184
|
|
|
->add('mass', TextColumn::class, [ |
|
185
|
|
|
'label' => $this->translator->trans('part.table.mass'), |
|
186
|
|
|
'visible' => false |
|
187
|
|
|
]) |
|
188
|
|
|
->add('tags', TextColumn::class, [ |
|
189
|
|
|
'label' => $this->translator->trans('part.table.tags'), |
|
190
|
|
|
'visible' => false |
|
191
|
|
|
]) |
|
192
|
|
|
|
|
193
|
|
|
->addOrderBy('name') |
|
194
|
|
|
->createAdapter(ORMAdapter::class, [ |
|
195
|
|
|
'query' => function(QueryBuilder $builder) { |
|
196
|
|
|
$this->getQuery($builder); |
|
197
|
|
|
}, |
|
198
|
|
|
'entity' => Part::class, |
|
199
|
|
|
'criteria' => [ |
|
200
|
|
|
function (QueryBuilder $builder) use ($options) { |
|
201
|
|
|
$this->buildCriteria($builder, $options); |
|
202
|
|
|
}, |
|
203
|
|
|
new SearchCriteriaProvider() |
|
204
|
|
|
] |
|
205
|
|
|
]); |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
|