-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathPartFilter.php
More file actions
195 lines (169 loc) · 9.53 KB
/
PartFilter.php
File metadata and controls
195 lines (169 loc) · 9.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\DataTables\Filters;
use App\DataTables\Filters\Constraints\AbstractConstraint;
use App\DataTables\Filters\Constraints\BooleanConstraint;
use App\DataTables\Filters\Constraints\ChoiceConstraint;
use App\DataTables\Filters\Constraints\DateTimeConstraint;
use App\DataTables\Filters\Constraints\EntityConstraint;
use App\DataTables\Filters\Constraints\IntConstraint;
use App\DataTables\Filters\Constraints\NumberConstraint;
use App\DataTables\Filters\Constraints\Part\BulkImportJobExistsConstraint;
use App\DataTables\Filters\Constraints\Part\BulkImportJobStatusConstraint;
use App\DataTables\Filters\Constraints\Part\BulkImportPartStatusConstraint;
use App\DataTables\Filters\Constraints\Part\LessThanDesiredConstraint;
use App\DataTables\Filters\Constraints\Part\ParameterConstraint;
use App\DataTables\Filters\Constraints\Part\TagsConstraint;
use App\DataTables\Filters\Constraints\TextConstraint;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\StorageLocation;
use App\Entity\Parts\Supplier;
use App\Entity\ProjectSystem\Project;
use App\Entity\UserSystem\User;
use App\Services\Trees\NodesListBuilder;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\QueryBuilder;
class PartFilter implements FilterInterface
{
use CompoundFilterTrait;
public readonly IntConstraint $dbId;
public readonly TextConstraint $ipn;
public readonly TextConstraint $name;
public readonly TextConstraint $description;
public readonly TextConstraint $comment;
public readonly TagsConstraint $tags;
public readonly NumberConstraint $minAmount;
public readonly NumberConstraint $orderAmount;
public readonly DateTimeConstraint $orderDelivery;
public readonly BooleanConstraint $favorite;
public readonly BooleanConstraint $needsReview;
public readonly NumberConstraint $mass;
public readonly DateTimeConstraint $lastModified;
public readonly DateTimeConstraint $addedDate;
public readonly EntityConstraint $category;
public readonly EntityConstraint $footprint;
public readonly EntityConstraint $manufacturer;
public readonly ChoiceConstraint $manufacturing_status;
public readonly EntityConstraint $supplier;
public readonly IntConstraint $orderdetailsCount;
public readonly BooleanConstraint $obsolete;
public readonly EntityConstraint $storelocation;
public readonly IntConstraint $lotCount;
public readonly IntConstraint $amountSum;
public readonly LessThanDesiredConstraint $lessThanDesired;
public readonly BooleanConstraint $lotNeedsRefill;
public readonly TextConstraint $lotDescription;
public readonly BooleanConstraint $lotUnknownAmount;
public readonly DateTimeConstraint $lotExpirationDate;
public readonly EntityConstraint $lotOwner;
public readonly EntityConstraint $measurementUnit;
public readonly TextConstraint $manufacturer_product_url;
public readonly TextConstraint $manufacturer_product_number;
public readonly IntConstraint $attachmentsCount;
public readonly EntityConstraint $attachmentType;
public readonly TextConstraint $attachmentName;
/** @var ArrayCollection<int, ParameterConstraint> */
public readonly ArrayCollection $parameters;
public readonly IntConstraint $parametersCount;
/*************************************************
* Project tab
*************************************************/
public readonly EntityConstraint $project;
public readonly NumberConstraint $bomQuantity;
public readonly TextConstraint $bomName;
public readonly TextConstraint $bomComment;
/*************************************************
* Bulk Import Job tab
*************************************************/
public readonly BulkImportJobExistsConstraint $inBulkImportJob;
public readonly BulkImportJobStatusConstraint $bulkImportJobStatus;
public readonly BulkImportPartStatusConstraint $bulkImportPartStatus;
public function __construct(NodesListBuilder $nodesListBuilder)
{
//Must be done for every new set of attachment filters, to ensure deterministic parameter names.
AbstractConstraint::resetParameterCounter();
$this->name = new TextConstraint('part.name');
$this->description = new TextConstraint('part.description');
$this->comment = new TextConstraint('part.comment');
$this->category = new EntityConstraint($nodesListBuilder, Category::class, 'part.category');
$this->footprint = new EntityConstraint($nodesListBuilder, Footprint::class, 'part.footprint');
$this->tags = new TagsConstraint('part.tags');
$this->favorite = new BooleanConstraint('part.favorite');
$this->needsReview = new BooleanConstraint('part.needs_review');
$this->measurementUnit = new EntityConstraint($nodesListBuilder, MeasurementUnit::class, 'part.partUnit');
$this->mass = new NumberConstraint('part.mass');
$this->dbId = new IntConstraint('part.id');
$this->ipn = new TextConstraint('part.ipn');
$this->addedDate = new DateTimeConstraint('part.addedDate');
$this->lastModified = new DateTimeConstraint('part.lastModified');
$this->minAmount = new NumberConstraint('part.minamount');
$this->orderAmount = new NumberConstraint('part.orderamount');
$this->orderDelivery = new DateTimeConstraint('part.orderDelivery');
/* We have to use an IntConstraint here because otherwise we get just an empty result list when applying the filter
This seems to be related to the fact, that PDO does not have an float parameter type and using string type does not work in this situation (at least in SQLite)
TODO: Find a better solution here
*/
$this->amountSum = (new IntConstraint('(
SELECT COALESCE(SUM(__partLot.amount), 0.0)
FROM ' . PartLot::class . ' __partLot
WHERE __partLot.part = part.id
AND __partLot.instock_unknown = false
AND (__partLot.expiration_date IS NULL OR __partLot.expiration_date > CURRENT_DATE())
)', identifier: "amountSumWhere"));
$this->lotCount = new IntConstraint('COUNT(_partLots)');
$this->lessThanDesired = new LessThanDesiredConstraint();
$this->storelocation = new EntityConstraint($nodesListBuilder, StorageLocation::class, '_partLots.storage_location');
$this->lotNeedsRefill = new BooleanConstraint('_partLots.needs_refill');
$this->lotUnknownAmount = new BooleanConstraint('_partLots.instock_unknown');
$this->lotExpirationDate = new DateTimeConstraint('_partLots.expiration_date');
$this->lotDescription = new TextConstraint('_partLots.description');
$this->lotOwner = new EntityConstraint($nodesListBuilder, User::class, '_partLots.owner');
$this->manufacturer = new EntityConstraint($nodesListBuilder, Manufacturer::class, 'part.manufacturer');
$this->manufacturer_product_number = new TextConstraint('part.manufacturer_product_number');
$this->manufacturer_product_url = new TextConstraint('part.manufacturer_product_url');
$this->manufacturing_status = new ChoiceConstraint('part.manufacturing_status');
$this->attachmentsCount = new IntConstraint('COUNT(_attachments)');
$this->attachmentType = new EntityConstraint($nodesListBuilder, AttachmentType::class, '_attachments.attachment_type');
$this->attachmentName = new TextConstraint('_attachments.name');
$this->supplier = new EntityConstraint($nodesListBuilder, Supplier::class, '_orderdetails.supplier');
$this->orderdetailsCount = new IntConstraint('COUNT(_orderdetails)');
$this->obsolete = new BooleanConstraint('_orderdetails.obsolete');
$this->parameters = new ArrayCollection();
$this->parametersCount = new IntConstraint('COUNT(_parameters)');
$this->project = new EntityConstraint($nodesListBuilder, Project::class, '_projectBomEntries.project');
$this->bomQuantity = new NumberConstraint('_projectBomEntries.quantity');
$this->bomName = new TextConstraint('_projectBomEntries.name');
$this->bomComment = new TextConstraint('_projectBomEntries.comment');
// Bulk Import Job filters
$this->inBulkImportJob = new BulkImportJobExistsConstraint();
$this->bulkImportJobStatus = new BulkImportJobStatusConstraint();
$this->bulkImportPartStatus = new BulkImportPartStatusConstraint();
}
public function apply(QueryBuilder $queryBuilder): void
{
$this->applyAllChildFilters($queryBuilder);
}
}