2019-03-05 23:52:45 +01:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
|
*
|
2022-11-29 22:28:53 +01:00
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
2020-02-22 18:14:36 +01:00
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2019-03-05 23:52:45 +01:00
|
|
|
namespace App\DataTables;
|
|
|
|
|
|
2023-10-06 13:08:46 +02:00
|
|
|
use App\DataTables\Adapters\TwoStepORMAdapter;
|
2019-09-07 15:23:03 +02:00
|
|
|
use App\DataTables\Column\EntityColumn;
|
2024-03-02 18:48:31 +01:00
|
|
|
use App\DataTables\Column\EnumColumn;
|
2020-05-22 22:31:19 +02:00
|
|
|
use App\DataTables\Column\IconLinkColumn;
|
2019-09-07 12:48:49 +02:00
|
|
|
use App\DataTables\Column\LocaleDateTimeColumn;
|
2019-11-10 19:43:55 +01:00
|
|
|
use App\DataTables\Column\MarkdownColumn;
|
2019-11-10 19:16:39 +01:00
|
|
|
use App\DataTables\Column\PartAttachmentsColumn;
|
2022-09-09 00:10:29 +02:00
|
|
|
use App\DataTables\Column\PrettyBoolColumn;
|
2022-12-17 01:19:52 +01:00
|
|
|
use App\DataTables\Column\RowClassColumn;
|
2022-09-10 01:26:09 +02:00
|
|
|
use App\DataTables\Column\SelectColumn;
|
2022-09-10 00:37:47 +02:00
|
|
|
use App\DataTables\Column\SIUnitNumberColumn;
|
2019-11-10 19:38:36 +01:00
|
|
|
use App\DataTables\Column\TagsColumn;
|
2022-08-15 01:01:27 +02:00
|
|
|
use App\DataTables\Filters\PartFilter;
|
2022-09-09 23:33:49 +02:00
|
|
|
use App\DataTables\Filters\PartSearchFilter;
|
2024-03-02 18:48:31 +01:00
|
|
|
use App\DataTables\Helpers\ColumnSortHelper;
|
2022-12-18 21:58:21 +01:00
|
|
|
use App\DataTables\Helpers\PartDataTableHelper;
|
2024-03-02 18:48:31 +01:00
|
|
|
use App\Doctrine\Helpers\FieldHelper;
|
|
|
|
|
use App\Entity\Parts\ManufacturingStatus;
|
2019-08-12 18:04:53 +02:00
|
|
|
use App\Entity\Parts\Part;
|
2022-09-04 03:37:54 +02:00
|
|
|
use App\Entity\Parts\PartLot;
|
2024-03-02 18:48:31 +01:00
|
|
|
use App\Entity\ProjectSystem\Project;
|
2019-03-05 23:52:45 +01:00
|
|
|
use App\Services\EntityURLGenerator;
|
2024-03-02 18:48:31 +01:00
|
|
|
use App\Services\Formatters\AmountFormatter;
|
2024-08-21 22:02:56 +02:00
|
|
|
use App\Settings\BehaviorSettings\TableSettings;
|
2024-03-03 19:57:31 +01:00
|
|
|
use Doctrine\ORM\AbstractQuery;
|
2026-02-15 19:30:53 +01:00
|
|
|
use Doctrine\ORM\Query;
|
2019-03-05 23:52:45 +01:00
|
|
|
use Doctrine\ORM\QueryBuilder;
|
|
|
|
|
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider;
|
|
|
|
|
use Omines\DataTablesBundle\Column\TextColumn;
|
|
|
|
|
use Omines\DataTablesBundle\DataTable;
|
|
|
|
|
use Omines\DataTablesBundle\DataTableTypeInterface;
|
2024-03-02 18:48:31 +01:00
|
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
2020-03-08 13:05:53 +01:00
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
2019-09-06 18:25:24 +02:00
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
2019-03-05 23:52:45 +01:00
|
|
|
|
2020-01-05 22:49:00 +01:00
|
|
|
final class PartsDataTable implements DataTableTypeInterface
|
2019-03-05 23:52:45 +01:00
|
|
|
{
|
2025-02-01 23:42:19 +01:00
|
|
|
const LENGTH_MENU = [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]];
|
|
|
|
|
|
2023-10-08 21:07:22 +02:00
|
|
|
public function __construct(
|
|
|
|
|
private readonly EntityURLGenerator $urlGenerator,
|
|
|
|
|
private readonly TranslatorInterface $translator,
|
|
|
|
|
private readonly AmountFormatter $amountFormatter,
|
|
|
|
|
private readonly PartDataTableHelper $partDataTableHelper,
|
|
|
|
|
private readonly Security $security,
|
|
|
|
|
private readonly ColumnSortHelper $csh,
|
2024-08-21 22:02:56 +02:00
|
|
|
private readonly TableSettings $tableSettings,
|
2023-10-08 21:07:22 +02:00
|
|
|
) {
|
2019-03-05 23:52:45 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-15 13:56:31 +01:00
|
|
|
public function configureOptions(OptionsResolver $optionsResolver): void
|
2020-03-08 13:05:53 +01:00
|
|
|
{
|
|
|
|
|
$optionsResolver->setDefaults([
|
2022-09-09 23:33:49 +02:00
|
|
|
'filter' => null,
|
|
|
|
|
'search' => null
|
2020-03-15 13:56:31 +01:00
|
|
|
]);
|
2020-03-08 13:05:53 +01:00
|
|
|
|
2022-09-09 23:33:49 +02:00
|
|
|
$optionsResolver->setAllowedTypes('filter', [PartFilter::class, 'null']);
|
|
|
|
|
$optionsResolver->setAllowedTypes('search', [PartSearchFilter::class, 'null']);
|
2020-03-08 13:05:53 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-05 15:46:58 +01:00
|
|
|
public function configure(DataTable $dataTable, array $options): void
|
2019-03-05 23:52:45 +01:00
|
|
|
{
|
2020-03-08 13:05:53 +01:00
|
|
|
$resolver = new OptionsResolver();
|
|
|
|
|
$this->configureOptions($resolver);
|
|
|
|
|
$options = $resolver->resolve($options);
|
|
|
|
|
|
Enhance KiCad integration: API v2, batch EDA editing, field export control (#1241)
* Add stock quantity, datasheet URL, and HTTP caching to KiCad API
- Add Stock field showing total available quantity across all part lots
- Add Storage Location field when parts have stored locations
- Resolve actual datasheet PDF from attachments (by type name, attachment
name, or first PDF) instead of always linking to Part-DB page
- Keep Part-DB page URL as separate "Part-DB URL" field
- Add ETag and Cache-Control headers to all KiCad API endpoints
- Support conditional requests (If-None-Match) returning 304
- Categories/part lists cached 5 min, part details cached 1 min
* Add KiCadHelper unit tests and fix PDF detection for external URLs
- Add comprehensive KiCadHelperTest with 14 test cases covering:
- Stock quantity calculation (zero, single lot, multiple lots)
- Stock exclusion of expired and unknown-quantity lots
- Storage location display (present, absent, multiple)
- Datasheet URL resolution by type name, attachment name, PDF extension
- Datasheet fallback to Part-DB URL when no match
- "Data sheet" (with space) name variant matching
- Fix PDF extension detection for external attachments (getExtension()
returns null for external-only attachments, now also parses URL path)
* Fix 304 response body, parse_url safety, and location/stock consistency
- Use empty Response instead of JsonResponse(null) for 304 Not Modified
to avoid sending "null" as response body
- Guard parse_url() result with is_string() since it can return false
for malformed URLs
- Move storage location tracking inside the availability check so
expired and unknown-quantity lots don't contribute locations
* Fix testPartDetailsPart2 to actually test Part 2
The test was requesting /parts/1.json instead of /parts/2.json and had
Part 1's expected data. Now tests Part 2 which inherits EDA info from
its category and footprint, verifying the inheritance behavior.
* Use Symfony's built-in ETag handling for HTTP caching
Replace manual If-None-Match comparison with Response::setEtag() and
Response::isNotModified(), which properly handles ETag quoting, weak
vs strong comparison, and 304 response cleanup. Fixes PHPStan return
type error and CI test failures.
* Add configurable KiCad field export for part parameters
Add a kicad_export checkbox to parameters, allowing users to control
which specifications appear as fields in the KiCad HTTP library API.
Parameters with kicad_export enabled are included using their formatted
value, without overwriting hardcoded fields like description or Stock.
* Add partdb:kicad:populate command for bulk KiCad path assignment
Console command that populates KiCad footprint/symbol paths on Footprint
and Category entities based on name-to-library mappings. Supports dry-run,
force overwrite, and list modes. Includes 130+ footprint mappings and 30+
category symbol mappings for KiCad 9.x standard libraries.
* Add CSV import support for EDA/KiCad fields
Add user-friendly column aliases (kicad_symbol, kicad_footprint,
kicad_reference, kicad_value, eda_exclude_bom, etc.) to the CSV import
system. Users can now bulk-set KiCad symbols, footprints, and other EDA
metadata via CSV/Excel import without knowing the internal dot notation.
* Add batch EDA field editing from parts table
Users can now select multiple parts in any parts table and batch-edit
their EDA/KiCad fields (symbol, footprint, reference prefix, value,
visibility, exclude from BOM/board/sim). Each field has an "Apply"
checkbox so users control exactly which fields are changed.
* Remove unused counter variable in BatchEdaController
* Fix PHPStan errors in PopulateKicadCommand and BatchEdaController
Add @var type annotations for Doctrine repository findAll() calls so
PHPStan can resolve getEdaInfo() on Footprint/Category entities. Fix
array return type for numeric-string keys and add explicit callback to
array_filter to satisfy strict rules.
* Fix batch EDA edit: required validation and pre-populate shared values
- Add required=false to TriStateCheckboxType fields so HTML5 validation
doesn't force users to check visibility/BOM/board checkboxes
- Pre-populate form fields when all selected parts share the same EDA
value, so users can see current state before editing
* Add KiCad API v2, orderdetail export control, EDA status indicator, BOM improvements
- Add KiCad API v2 endpoints (/kicad-api/v2) with volatile field support
for stock and storage location (shown but not saved to schematic)
- Add kicad_export flag to Orderdetail entity for per-supplier SPN control
(backward compatible: if no flag set, all SPNs exported as before)
- Add EDA completeness indicator column in parts datatable (bolt icon)
- Add ?minimal=true query param for faster category parts loading
- Improve category descriptions (use comment instead of URL when available)
- Improve BOM importer multi-footprint support: merge entries by Part-DB
part ID when linked, tracking footprint variants in comments
- Fix KiCost manf/manf# fields always present (not conditional on orderdetails)
- Fix duplicate getEdaInfo() call in shouldPartBeVisible
- Consolidate supplier SPN and KiCost field generation into single loop
* Fix kicad_export column default for SQLite compatibility
Add options default to ORM column definition so schema:update
works correctly on SQLite test databases.
* Make EDA status bolt icon clickable to open EDA settings tab
* Fix EDA bolt link to correctly open EDA tab via data-turbo=false
* Add configurable datasheet URL mode for KiCad API
New setting "Datasheet field links to PDF" in KiCad EDA settings.
When enabled (default), the datasheet field resolves to the actual
PDF attachment URL. When disabled, it links to the Part-DB page
(old behavior). Configurable via settings UI or EDA_KICAD_DATASHEET_AS_PDF env var.
* Fix settings crash when upgrading: make datasheetAsPdf nullable
The settings bundle stores values in the database. When upgrading from
a version without datasheetAsPdf, the stored JSON lacks this key,
causing a TypeError when assigning null to a non-nullable bool.
Making it nullable with a fallback in KiCadHelper fixes the upgrade path.
* Add functional tests for KiCad API v2 and batch EDA controller
- KiCadApiV2ControllerTest: root, categories, parts, volatile fields,
v1 vs v2 comparison, cache headers, 304 conditional request, auth
- BatchEdaControllerTest: page load, empty redirect, form submission
* Fix test failures: correct ids format and anonymous access assertion
* Improve test coverage for BatchEdaController
Add tests for: applying all EDA fields at once, custom redirect URL,
and verifying unchecked fields are skipped.
* Address PR review: rename to eda_visibility, merge migrations, API versioning
Changes based on jbtronics' review of PR #1241:
- Rename kicad_export -> eda_visibility (entities, forms, templates,
translations, tests) with nullable bool for system default support
- Merge two database migrations into one (Version20260211000000)
- Rename createCachedJsonResponse -> createCacheableJsonResponse
- Change bool $apiV2 -> int $apiVersion with version validation
- EDA visibility field only shown for part parameters, not other entities
- PopulateKicadCommand: check alternative names of footprints/categories
- PopulateKicadCommand: support external JSON mapping file (--mapping-file)
- Ship default mappings JSON at contrib/kicad-populate/default_mappings.json
- Add system-wide defaultEdaVisibility setting in KiCadEDASettings
- Add KiCad HTTP Library v2 spec link in controller docs
* Fix duplicate loadMappingFile method causing PHP fatal error
* Add tests for mapping file and alternative name matching, update populate command docs
Add 5 new tests for PopulateKicadCommand covering:
- Custom mapping file overriding defaults
- Invalid JSON mapping file error handling
- Missing mapping file error handling
- Footprint alternative name matching
- Category alternative name matching
Update contrib README to document --mapping-file option,
alternative name matching, and custom JSON mapping format.
* Split out KiCad API v2 into separate PR as requested by maintainer
Remove v2 controller, tests, and volatile field support from this PR.
The v2 API will be submitted as a separate PR for focused discussion.
* Improve test coverage for KiCadHelper and PopulateKicadCommand
KiCadHelper: Add tests for orderdetail eda_visibility filtering,
backward compatibility when no flags set, manufacturer/KiCost fields,
and parameter with empty name skipping.
PopulateKicadCommand: Add tests for mapping file with both footprints
and categories sections, and mapping file with only categories.
* Load populate Kicad default mappings from json file
* Moved kicad:populate documentation to central docs
* Added introduced column to PartTableColumns to make it configurable in the settings
* Use TristateCheckboxes for parameter and orderdetail types
* Fixed translation keys
* Split up default eda visibility for parameters and purchase infos
---------
Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
2026-03-01 22:10:13 +01:00
|
|
|
/*************************************************************************************************************
|
|
|
|
|
* When adding columns here, add them also to PartTableColumns enum, to make them configurable in the settings!
|
|
|
|
|
*************************************************************************************************************/
|
|
|
|
|
|
2023-10-08 21:07:22 +02:00
|
|
|
$this->csh
|
2022-12-17 01:19:52 +01:00
|
|
|
//Color the table rows depending on the review and favorite status
|
2023-10-08 21:07:22 +02:00
|
|
|
->add('row_color', RowClassColumn::class, [
|
2023-06-11 14:15:46 +02:00
|
|
|
'render' => function ($value, Part $context): string {
|
2022-12-17 01:19:52 +01:00
|
|
|
if ($context->isNeedsReview()) {
|
|
|
|
|
return 'table-secondary';
|
|
|
|
|
}
|
|
|
|
|
if ($context->isFavorite()) {
|
|
|
|
|
return 'table-info';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ''; //Default coloring otherwise
|
|
|
|
|
},
|
2023-10-08 21:07:22 +02:00
|
|
|
], visibility_configurable: false)
|
|
|
|
|
->add('select', SelectColumn::class, visibility_configurable: false)
|
2019-10-03 14:53:50 +02:00
|
|
|
->add('picture', TextColumn::class, [
|
|
|
|
|
'label' => '',
|
2022-09-10 01:26:09 +02:00
|
|
|
'className' => 'no-colvis',
|
2023-06-11 14:15:46 +02:00
|
|
|
'render' => fn($value, Part $context) => $this->partDataTableHelper->renderPicture($context),
|
2023-10-08 21:07:22 +02:00
|
|
|
], visibility_configurable: false)
|
2019-09-06 18:25:24 +02:00
|
|
|
->add('name', TextColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.name'),
|
2023-06-11 14:15:46 +02:00
|
|
|
'render' => fn($value, Part $context) => $this->partDataTableHelper->renderName($context),
|
2024-06-17 21:38:16 +02:00
|
|
|
'orderField' => 'NATSORT(part.name)'
|
2019-09-06 18:25:24 +02:00
|
|
|
])
|
|
|
|
|
->add('id', TextColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.id'),
|
|
|
|
|
])
|
2022-12-04 02:28:47 +01:00
|
|
|
->add('ipn', TextColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.ipn'),
|
2024-06-17 21:38:16 +02:00
|
|
|
'orderField' => 'NATSORT(part.ipn)'
|
2022-12-04 02:28:47 +01:00
|
|
|
])
|
2019-11-10 19:43:55 +01:00
|
|
|
->add('description', MarkdownColumn::class, [
|
2019-09-06 18:25:24 +02:00
|
|
|
'label' => $this->translator->trans('part.table.description'),
|
2023-10-08 21:36:05 +02:00
|
|
|
])
|
|
|
|
|
->add('category', EntityColumn::class, [
|
2019-09-07 15:23:03 +02:00
|
|
|
'label' => $this->translator->trans('part.table.category'),
|
2019-09-08 16:56:05 +02:00
|
|
|
'property' => 'category',
|
2024-06-17 21:38:16 +02:00
|
|
|
'orderField' => 'NATSORT(_category.name)'
|
2023-10-08 21:36:05 +02:00
|
|
|
])
|
|
|
|
|
->add('footprint', EntityColumn::class, [
|
2019-09-07 15:23:03 +02:00
|
|
|
'property' => 'footprint',
|
2019-11-09 00:47:20 +01:00
|
|
|
'label' => $this->translator->trans('part.table.footprint'),
|
2024-06-17 21:38:16 +02:00
|
|
|
'orderField' => 'NATSORT(_footprint.name)'
|
2023-10-08 21:36:05 +02:00
|
|
|
])
|
|
|
|
|
->add('manufacturer', EntityColumn::class, [
|
2019-09-07 15:23:03 +02:00
|
|
|
'property' => 'manufacturer',
|
2019-11-09 00:47:20 +01:00
|
|
|
'label' => $this->translator->trans('part.table.manufacturer'),
|
2024-06-17 21:38:16 +02:00
|
|
|
'orderField' => 'NATSORT(_manufacturer.name)'
|
2023-10-08 21:36:05 +02:00
|
|
|
])
|
|
|
|
|
->add('storelocation', TextColumn::class, [
|
2019-09-08 17:52:50 +02:00
|
|
|
'label' => $this->translator->trans('part.table.storeLocations'),
|
2024-11-04 23:46:45 +01:00
|
|
|
//We need to use a aggregate function to get the first store location, as we have a one-to-many relation
|
|
|
|
|
'orderField' => 'NATSORT(MIN(_storelocations.name))',
|
2025-08-02 23:35:30 +02:00
|
|
|
'render' => fn($value, Part $context) => $this->partDataTableHelper->renderStorageLocations($context),
|
2023-10-08 21:36:05 +02:00
|
|
|
], alias: 'storage_location')
|
2024-06-17 21:38:16 +02:00
|
|
|
|
2023-10-08 21:36:05 +02:00
|
|
|
->add('amount', TextColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.amount'),
|
2025-08-02 23:35:30 +02:00
|
|
|
'render' => fn($value, Part $context) => $this->partDataTableHelper->renderAmount($context),
|
2023-10-08 21:36:05 +02:00
|
|
|
'orderField' => 'amountSum'
|
|
|
|
|
])
|
2019-09-06 18:25:24 +02:00
|
|
|
->add('minamount', TextColumn::class, [
|
2019-09-07 13:12:24 +02:00
|
|
|
'label' => $this->translator->trans('part.table.minamount'),
|
2025-08-02 23:35:30 +02:00
|
|
|
'render' => fn($value, Part $context): string => htmlspecialchars($this->amountFormatter->format(
|
|
|
|
|
$value,
|
|
|
|
|
$context->getPartUnit()
|
|
|
|
|
)),
|
2023-10-08 21:36:05 +02:00
|
|
|
])
|
|
|
|
|
->add('partUnit', TextColumn::class, [
|
2019-09-07 13:12:24 +02:00
|
|
|
'label' => $this->translator->trans('part.table.partUnit'),
|
2024-06-19 23:28:53 +02:00
|
|
|
'orderField' => 'NATSORT(_partUnit.name)',
|
2025-08-02 23:35:30 +02:00
|
|
|
'render' => function ($value, Part $context): string {
|
2024-06-19 23:28:53 +02:00
|
|
|
$partUnit = $context->getPartUnit();
|
2024-06-22 00:31:43 +02:00
|
|
|
if ($partUnit === null) {
|
2024-06-19 23:28:53 +02:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tmp = htmlspecialchars($partUnit->getName());
|
|
|
|
|
|
|
|
|
|
if ($partUnit->getUnit()) {
|
2025-08-02 23:35:30 +02:00
|
|
|
$tmp .= ' (' . htmlspecialchars($partUnit->getUnit()) . ')';
|
2024-06-19 23:28:53 +02:00
|
|
|
}
|
|
|
|
|
return $tmp;
|
|
|
|
|
}
|
2023-10-08 21:36:05 +02:00
|
|
|
])
|
2025-10-27 21:58:16 +01:00
|
|
|
->add('partCustomState', TextColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.partCustomState'),
|
|
|
|
|
'orderField' => 'NATSORT(_partCustomState.name)',
|
|
|
|
|
'render' => function($value, Part $context): string {
|
|
|
|
|
$partCustomState = $context->getPartCustomState();
|
|
|
|
|
|
|
|
|
|
if ($partCustomState === null) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return htmlspecialchars($partCustomState->getName());
|
|
|
|
|
}
|
|
|
|
|
])
|
2023-10-08 21:36:05 +02:00
|
|
|
->add('addedDate', LocaleDateTimeColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.addedDate'),
|
|
|
|
|
])
|
2019-09-07 12:48:49 +02:00
|
|
|
->add('lastModified', LocaleDateTimeColumn::class, [
|
2019-09-06 18:25:24 +02:00
|
|
|
'label' => $this->translator->trans('part.table.lastModified'),
|
|
|
|
|
])
|
2022-09-09 00:10:29 +02:00
|
|
|
->add('needs_review', PrettyBoolColumn::class, [
|
2019-09-06 18:25:24 +02:00
|
|
|
'label' => $this->translator->trans('part.table.needsReview'),
|
|
|
|
|
])
|
2022-09-09 00:10:29 +02:00
|
|
|
->add('favorite', PrettyBoolColumn::class, [
|
2019-09-06 18:25:24 +02:00
|
|
|
'label' => $this->translator->trans('part.table.favorite'),
|
|
|
|
|
])
|
2023-07-08 23:49:47 +02:00
|
|
|
->add('manufacturing_status', EnumColumn::class, [
|
2019-09-06 18:25:24 +02:00
|
|
|
'label' => $this->translator->trans('part.table.manufacturingStatus'),
|
2023-07-08 23:49:47 +02:00
|
|
|
'class' => ManufacturingStatus::class,
|
2023-10-08 21:07:22 +02:00
|
|
|
'render' => function (?ManufacturingStatus $status, Part $context): string {
|
2024-06-22 00:31:43 +02:00
|
|
|
if ($status === null) {
|
2023-07-08 23:49:47 +02:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->translator->trans($status->toTranslationKey());
|
2023-10-08 21:07:22 +02:00
|
|
|
},
|
2019-09-06 18:25:24 +02:00
|
|
|
])
|
|
|
|
|
->add('manufacturer_product_number', TextColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.mpn'),
|
2024-06-18 22:34:29 +02:00
|
|
|
'orderField' => 'NATSORT(part.manufacturer_product_number)'
|
2019-09-06 18:25:24 +02:00
|
|
|
])
|
2022-09-10 00:37:47 +02:00
|
|
|
->add('mass', SIUnitNumberColumn::class, [
|
2019-09-06 18:25:24 +02:00
|
|
|
'label' => $this->translator->trans('part.table.mass'),
|
2022-09-10 00:37:47 +02:00
|
|
|
'unit' => 'g'
|
2019-09-06 18:25:24 +02:00
|
|
|
])
|
2026-02-08 15:51:39 +01:00
|
|
|
->add('gtin', TextColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.gtin'),
|
|
|
|
|
'orderField' => 'NATSORT(part.gtin)'
|
|
|
|
|
])
|
2019-11-10 19:38:36 +01:00
|
|
|
->add('tags', TagsColumn::class, [
|
2019-09-06 18:25:24 +02:00
|
|
|
'label' => $this->translator->trans('part.table.tags'),
|
|
|
|
|
])
|
2019-11-10 19:16:39 +01:00
|
|
|
->add('attachments', PartAttachmentsColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.attachments'),
|
Enhance KiCad integration: API v2, batch EDA editing, field export control (#1241)
* Add stock quantity, datasheet URL, and HTTP caching to KiCad API
- Add Stock field showing total available quantity across all part lots
- Add Storage Location field when parts have stored locations
- Resolve actual datasheet PDF from attachments (by type name, attachment
name, or first PDF) instead of always linking to Part-DB page
- Keep Part-DB page URL as separate "Part-DB URL" field
- Add ETag and Cache-Control headers to all KiCad API endpoints
- Support conditional requests (If-None-Match) returning 304
- Categories/part lists cached 5 min, part details cached 1 min
* Add KiCadHelper unit tests and fix PDF detection for external URLs
- Add comprehensive KiCadHelperTest with 14 test cases covering:
- Stock quantity calculation (zero, single lot, multiple lots)
- Stock exclusion of expired and unknown-quantity lots
- Storage location display (present, absent, multiple)
- Datasheet URL resolution by type name, attachment name, PDF extension
- Datasheet fallback to Part-DB URL when no match
- "Data sheet" (with space) name variant matching
- Fix PDF extension detection for external attachments (getExtension()
returns null for external-only attachments, now also parses URL path)
* Fix 304 response body, parse_url safety, and location/stock consistency
- Use empty Response instead of JsonResponse(null) for 304 Not Modified
to avoid sending "null" as response body
- Guard parse_url() result with is_string() since it can return false
for malformed URLs
- Move storage location tracking inside the availability check so
expired and unknown-quantity lots don't contribute locations
* Fix testPartDetailsPart2 to actually test Part 2
The test was requesting /parts/1.json instead of /parts/2.json and had
Part 1's expected data. Now tests Part 2 which inherits EDA info from
its category and footprint, verifying the inheritance behavior.
* Use Symfony's built-in ETag handling for HTTP caching
Replace manual If-None-Match comparison with Response::setEtag() and
Response::isNotModified(), which properly handles ETag quoting, weak
vs strong comparison, and 304 response cleanup. Fixes PHPStan return
type error and CI test failures.
* Add configurable KiCad field export for part parameters
Add a kicad_export checkbox to parameters, allowing users to control
which specifications appear as fields in the KiCad HTTP library API.
Parameters with kicad_export enabled are included using their formatted
value, without overwriting hardcoded fields like description or Stock.
* Add partdb:kicad:populate command for bulk KiCad path assignment
Console command that populates KiCad footprint/symbol paths on Footprint
and Category entities based on name-to-library mappings. Supports dry-run,
force overwrite, and list modes. Includes 130+ footprint mappings and 30+
category symbol mappings for KiCad 9.x standard libraries.
* Add CSV import support for EDA/KiCad fields
Add user-friendly column aliases (kicad_symbol, kicad_footprint,
kicad_reference, kicad_value, eda_exclude_bom, etc.) to the CSV import
system. Users can now bulk-set KiCad symbols, footprints, and other EDA
metadata via CSV/Excel import without knowing the internal dot notation.
* Add batch EDA field editing from parts table
Users can now select multiple parts in any parts table and batch-edit
their EDA/KiCad fields (symbol, footprint, reference prefix, value,
visibility, exclude from BOM/board/sim). Each field has an "Apply"
checkbox so users control exactly which fields are changed.
* Remove unused counter variable in BatchEdaController
* Fix PHPStan errors in PopulateKicadCommand and BatchEdaController
Add @var type annotations for Doctrine repository findAll() calls so
PHPStan can resolve getEdaInfo() on Footprint/Category entities. Fix
array return type for numeric-string keys and add explicit callback to
array_filter to satisfy strict rules.
* Fix batch EDA edit: required validation and pre-populate shared values
- Add required=false to TriStateCheckboxType fields so HTML5 validation
doesn't force users to check visibility/BOM/board checkboxes
- Pre-populate form fields when all selected parts share the same EDA
value, so users can see current state before editing
* Add KiCad API v2, orderdetail export control, EDA status indicator, BOM improvements
- Add KiCad API v2 endpoints (/kicad-api/v2) with volatile field support
for stock and storage location (shown but not saved to schematic)
- Add kicad_export flag to Orderdetail entity for per-supplier SPN control
(backward compatible: if no flag set, all SPNs exported as before)
- Add EDA completeness indicator column in parts datatable (bolt icon)
- Add ?minimal=true query param for faster category parts loading
- Improve category descriptions (use comment instead of URL when available)
- Improve BOM importer multi-footprint support: merge entries by Part-DB
part ID when linked, tracking footprint variants in comments
- Fix KiCost manf/manf# fields always present (not conditional on orderdetails)
- Fix duplicate getEdaInfo() call in shouldPartBeVisible
- Consolidate supplier SPN and KiCost field generation into single loop
* Fix kicad_export column default for SQLite compatibility
Add options default to ORM column definition so schema:update
works correctly on SQLite test databases.
* Make EDA status bolt icon clickable to open EDA settings tab
* Fix EDA bolt link to correctly open EDA tab via data-turbo=false
* Add configurable datasheet URL mode for KiCad API
New setting "Datasheet field links to PDF" in KiCad EDA settings.
When enabled (default), the datasheet field resolves to the actual
PDF attachment URL. When disabled, it links to the Part-DB page
(old behavior). Configurable via settings UI or EDA_KICAD_DATASHEET_AS_PDF env var.
* Fix settings crash when upgrading: make datasheetAsPdf nullable
The settings bundle stores values in the database. When upgrading from
a version without datasheetAsPdf, the stored JSON lacks this key,
causing a TypeError when assigning null to a non-nullable bool.
Making it nullable with a fallback in KiCadHelper fixes the upgrade path.
* Add functional tests for KiCad API v2 and batch EDA controller
- KiCadApiV2ControllerTest: root, categories, parts, volatile fields,
v1 vs v2 comparison, cache headers, 304 conditional request, auth
- BatchEdaControllerTest: page load, empty redirect, form submission
* Fix test failures: correct ids format and anonymous access assertion
* Improve test coverage for BatchEdaController
Add tests for: applying all EDA fields at once, custom redirect URL,
and verifying unchecked fields are skipped.
* Address PR review: rename to eda_visibility, merge migrations, API versioning
Changes based on jbtronics' review of PR #1241:
- Rename kicad_export -> eda_visibility (entities, forms, templates,
translations, tests) with nullable bool for system default support
- Merge two database migrations into one (Version20260211000000)
- Rename createCachedJsonResponse -> createCacheableJsonResponse
- Change bool $apiV2 -> int $apiVersion with version validation
- EDA visibility field only shown for part parameters, not other entities
- PopulateKicadCommand: check alternative names of footprints/categories
- PopulateKicadCommand: support external JSON mapping file (--mapping-file)
- Ship default mappings JSON at contrib/kicad-populate/default_mappings.json
- Add system-wide defaultEdaVisibility setting in KiCadEDASettings
- Add KiCad HTTP Library v2 spec link in controller docs
* Fix duplicate loadMappingFile method causing PHP fatal error
* Add tests for mapping file and alternative name matching, update populate command docs
Add 5 new tests for PopulateKicadCommand covering:
- Custom mapping file overriding defaults
- Invalid JSON mapping file error handling
- Missing mapping file error handling
- Footprint alternative name matching
- Category alternative name matching
Update contrib README to document --mapping-file option,
alternative name matching, and custom JSON mapping format.
* Split out KiCad API v2 into separate PR as requested by maintainer
Remove v2 controller, tests, and volatile field support from this PR.
The v2 API will be submitted as a separate PR for focused discussion.
* Improve test coverage for KiCadHelper and PopulateKicadCommand
KiCadHelper: Add tests for orderdetail eda_visibility filtering,
backward compatibility when no flags set, manufacturer/KiCost fields,
and parameter with empty name skipping.
PopulateKicadCommand: Add tests for mapping file with both footprints
and categories sections, and mapping file with only categories.
* Load populate Kicad default mappings from json file
* Moved kicad:populate documentation to central docs
* Added introduced column to PartTableColumns to make it configurable in the settings
* Use TristateCheckboxes for parameter and orderdetail types
* Fixed translation keys
* Split up default eda visibility for parameters and purchase infos
---------
Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
2026-03-01 22:10:13 +01:00
|
|
|
])
|
|
|
|
|
->add('eda_status', TextColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.eda_status'),
|
|
|
|
|
'render' => fn($value, Part $context) => $this->partDataTableHelper->renderEdaStatus($context),
|
|
|
|
|
'className' => 'text-center',
|
2024-03-02 18:48:31 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
//Add a column to list the projects where the part is used, when the user has the permission to see the projects
|
|
|
|
|
if ($this->security->isGranted('read', Project::class)) {
|
|
|
|
|
$this->csh->add('projects', TextColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('project.labelp'),
|
|
|
|
|
'render' => function ($value, Part $context): string {
|
|
|
|
|
//Only show the first 5 projects names
|
|
|
|
|
$projects = $context->getProjects();
|
|
|
|
|
$tmp = "";
|
|
|
|
|
|
|
|
|
|
$max = 5;
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < min($max, count($projects)); $i++) {
|
|
|
|
|
$url = $this->urlGenerator->infoURL($projects[$i]);
|
|
|
|
|
$tmp .= sprintf('<a href="%s">%s</a>', $url, htmlspecialchars($projects[$i]->getName()));
|
|
|
|
|
if ($i < count($projects) - 1) {
|
|
|
|
|
$tmp .= ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count($projects) > $max) {
|
2025-08-02 23:35:30 +02:00
|
|
|
$tmp .= ", + " . (count($projects) - $max);
|
2024-03-02 18:48:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $tmp;
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->csh
|
2020-05-22 22:31:19 +02:00
|
|
|
->add('edit', IconLinkColumn::class, [
|
|
|
|
|
'label' => $this->translator->trans('part.table.edit'),
|
2023-06-11 14:15:46 +02:00
|
|
|
'href' => fn($value, Part $context) => $this->urlGenerator->editURL($context),
|
|
|
|
|
'disabled' => fn($value, Part $context) => !$this->security->isGranted('edit', $context),
|
2020-05-22 22:31:19 +02:00
|
|
|
'title' => $this->translator->trans('part.table.edit.title'),
|
2023-10-08 21:07:22 +02:00
|
|
|
]);
|
2023-10-04 21:30:04 +02:00
|
|
|
|
2023-10-08 21:07:22 +02:00
|
|
|
//Apply the user configured order and visibility and add the columns to the table
|
2024-08-21 22:02:56 +02:00
|
|
|
$this->csh->applyVisibilityAndConfigureColumns($dataTable, $this->tableSettings->partsDefaultColumns,
|
2023-10-08 21:32:57 +02:00
|
|
|
"TABLE_PARTS_DEFAULT_COLUMNS");
|
2019-09-06 18:25:24 +02:00
|
|
|
|
2023-10-04 21:30:04 +02:00
|
|
|
$dataTable->addOrderBy('name')
|
2023-10-08 21:54:51 +02:00
|
|
|
->createAdapter(TwoStepORMAdapter::class, [
|
2023-07-23 21:48:38 +02:00
|
|
|
'filter_query' => $this->getFilterQuery(...),
|
|
|
|
|
'detail_query' => $this->getDetailQuery(...),
|
2019-03-05 23:52:45 +01:00
|
|
|
'entity' => Part::class,
|
2024-03-03 19:57:31 +01:00
|
|
|
'hydrate' => AbstractQuery::HYDRATE_OBJECT,
|
2024-02-25 00:58:26 +01:00
|
|
|
//Use the simple total query, as we just want to get the total number of parts without any conditions
|
|
|
|
|
//For this the normal query would be pretty slow
|
|
|
|
|
'simple_total_query' => true,
|
2019-03-05 23:52:45 +01:00
|
|
|
'criteria' => [
|
2020-01-05 15:46:58 +01:00
|
|
|
function (QueryBuilder $builder) use ($options): void {
|
2019-09-05 22:27:18 +02:00
|
|
|
$this->buildCriteria($builder, $options);
|
|
|
|
|
},
|
2019-11-09 00:47:20 +01:00
|
|
|
new SearchCriteriaProvider(),
|
|
|
|
|
],
|
2024-02-29 23:13:17 +01:00
|
|
|
'query_modifier' => $this->addJoins(...),
|
2019-03-05 23:52:45 +01:00
|
|
|
]);
|
2023-07-22 23:51:06 +02:00
|
|
|
}
|
|
|
|
|
|
2023-07-23 21:48:38 +02:00
|
|
|
|
|
|
|
|
private function getFilterQuery(QueryBuilder $builder): void
|
2023-07-22 23:51:06 +02:00
|
|
|
{
|
2023-07-23 21:48:38 +02:00
|
|
|
/* In the filter query we only select the IDs. The fetching of the full entities is done in the detail query.
|
|
|
|
|
* We only need to join the entities here, so we can filter by them.
|
|
|
|
|
* The filter conditions are added to this QB in the buildCriteria method.
|
2024-02-29 23:35:05 +01:00
|
|
|
*
|
|
|
|
|
* The amountSum field and the joins are dynmically added by the addJoins method, if the fields are used in the query.
|
|
|
|
|
* This improves the performance, as we do not need to join all tables, if we do not need them.
|
2023-07-23 21:48:38 +02:00
|
|
|
*/
|
|
|
|
|
$builder
|
|
|
|
|
->select('part.id')
|
|
|
|
|
->addSelect('part.minamount AS HIDDEN minamount')
|
|
|
|
|
->from(Part::class, 'part')
|
|
|
|
|
|
2024-06-16 22:52:15 +02:00
|
|
|
//The other group by fields, are dynamically added by the addJoins method
|
|
|
|
|
->addGroupBy('part');
|
2019-03-05 23:52:45 +01:00
|
|
|
}
|
2020-01-05 15:46:58 +01:00
|
|
|
|
2023-07-29 16:42:27 +02:00
|
|
|
private function getDetailQuery(QueryBuilder $builder, array $filter_results): void
|
2020-01-05 15:46:58 +01:00
|
|
|
{
|
2024-03-03 19:57:31 +01:00
|
|
|
$ids = array_map(static fn($row) => $row['id'], $filter_results);
|
2023-07-29 16:42:27 +02:00
|
|
|
|
2023-07-23 21:48:38 +02:00
|
|
|
/*
|
|
|
|
|
* In this query we take the IDs which were filtered, paginated and sorted in the filter query, and fetch the
|
|
|
|
|
* full entities.
|
|
|
|
|
* We can do complex fetch joins, as we do not need to filter or sort here (which would kill the performance).
|
|
|
|
|
* The only condition should be for the IDs.
|
|
|
|
|
* It is important that elements are ordered the same way, as the IDs are passed, or ordering will be wrong.
|
2024-02-25 01:46:35 +01:00
|
|
|
*
|
|
|
|
|
* We do not require the subqueries like amountSum here, as it is not used to render the table (and only for sorting)
|
2023-07-23 21:48:38 +02:00
|
|
|
*/
|
2023-07-22 23:51:06 +02:00
|
|
|
$builder
|
|
|
|
|
->select('part')
|
2023-07-23 21:48:38 +02:00
|
|
|
->addSelect('category')
|
2020-01-26 21:54:21 +01:00
|
|
|
->addSelect('footprint')
|
|
|
|
|
->addSelect('manufacturer')
|
|
|
|
|
->addSelect('partUnit')
|
2025-10-27 21:58:16 +01:00
|
|
|
->addSelect('partCustomState')
|
2020-01-26 21:54:21 +01:00
|
|
|
->addSelect('master_picture_attachment')
|
|
|
|
|
->addSelect('footprint_attachment')
|
|
|
|
|
->addSelect('partLots')
|
|
|
|
|
->addSelect('orderdetails')
|
|
|
|
|
->addSelect('attachments')
|
2023-07-23 21:48:38 +02:00
|
|
|
->addSelect('storelocations')
|
2026-02-15 20:07:38 +01:00
|
|
|
->addSelect('projectBomEntries')
|
2020-01-05 15:46:58 +01:00
|
|
|
->from(Part::class, 'part')
|
|
|
|
|
->leftJoin('part.category', 'category')
|
|
|
|
|
->leftJoin('part.master_picture_attachment', 'master_picture_attachment')
|
|
|
|
|
->leftJoin('part.partLots', 'partLots')
|
|
|
|
|
->leftJoin('partLots.storage_location', 'storelocations')
|
|
|
|
|
->leftJoin('part.footprint', 'footprint')
|
|
|
|
|
->leftJoin('footprint.master_picture_attachment', 'footprint_attachment')
|
|
|
|
|
->leftJoin('part.manufacturer', 'manufacturer')
|
|
|
|
|
->leftJoin('part.orderdetails', 'orderdetails')
|
2020-03-08 13:05:53 +01:00
|
|
|
->leftJoin('orderdetails.supplier', 'suppliers')
|
2020-01-05 15:46:58 +01:00
|
|
|
->leftJoin('part.attachments', 'attachments')
|
2022-08-29 01:12:36 +02:00
|
|
|
->leftJoin('part.partUnit', 'partUnit')
|
2025-10-27 21:58:16 +01:00
|
|
|
->leftJoin('part.partCustomState', 'partCustomState')
|
2022-09-08 00:31:18 +02:00
|
|
|
->leftJoin('part.parameters', 'parameters')
|
2026-02-15 20:07:38 +01:00
|
|
|
->leftJoin('part.project_bom_entries', 'projectBomEntries')
|
2023-07-23 21:48:38 +02:00
|
|
|
->where('part.id IN (:ids)')
|
|
|
|
|
->setParameter('ids', $ids)
|
|
|
|
|
|
2022-11-28 23:43:30 +01:00
|
|
|
//We have to group by all elements, or only the first sub elements of an association is fetched! (caused issue #190)
|
2023-07-23 21:48:38 +02:00
|
|
|
->addGroupBy('part')
|
|
|
|
|
->addGroupBy('partLots')
|
2022-11-28 23:43:30 +01:00
|
|
|
->addGroupBy('category')
|
|
|
|
|
->addGroupBy('master_picture_attachment')
|
|
|
|
|
->addGroupBy('storelocations')
|
|
|
|
|
->addGroupBy('footprint')
|
|
|
|
|
->addGroupBy('footprint_attachment')
|
|
|
|
|
->addGroupBy('manufacturer')
|
|
|
|
|
->addGroupBy('orderdetails')
|
|
|
|
|
->addGroupBy('suppliers')
|
|
|
|
|
->addGroupBy('attachments')
|
|
|
|
|
->addGroupBy('partUnit')
|
2025-10-27 21:58:16 +01:00
|
|
|
->addGroupBy('partCustomState')
|
2026-02-15 19:30:53 +01:00
|
|
|
->addGroupBy('parameters')
|
2026-02-15 20:07:38 +01:00
|
|
|
->addGroupBy('projectBomEntries')
|
2026-02-15 19:30:53 +01:00
|
|
|
|
|
|
|
|
->setHint(Query::HINT_READ_ONLY, true)
|
2026-02-15 20:07:38 +01:00
|
|
|
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, false)
|
2026-02-15 19:30:53 +01:00
|
|
|
;
|
2023-07-29 16:42:27 +02:00
|
|
|
|
|
|
|
|
//Get the results in the same order as the IDs were passed
|
|
|
|
|
FieldHelper::addOrderByFieldParam($builder, 'part.id', 'ids');
|
2020-01-05 15:46:58 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-29 23:13:17 +01:00
|
|
|
/**
|
|
|
|
|
* This function is called right before the filter query is executed.
|
|
|
|
|
* We use it to dynamically add joins to the query, if the fields are used in the query.
|
|
|
|
|
* @param QueryBuilder $builder
|
|
|
|
|
* @return QueryBuilder
|
|
|
|
|
*/
|
|
|
|
|
private function addJoins(QueryBuilder $builder): QueryBuilder
|
2020-01-05 15:46:58 +01:00
|
|
|
{
|
2024-02-25 01:40:25 +01:00
|
|
|
//Check if the query contains certain conditions, for which we need to add additional joins
|
|
|
|
|
//The join fields get prefixed with an underscore, so we can check if they are used in the query easy without confusing them for a part subfield
|
|
|
|
|
$dql = $builder->getDQL();
|
|
|
|
|
|
2024-02-29 23:35:05 +01:00
|
|
|
//Add the amountSum field, if it is used in the query
|
|
|
|
|
if (str_contains($dql, 'amountSum')) {
|
|
|
|
|
//Calculate amount sum using a subquery, so we can filter and sort by it
|
|
|
|
|
$builder->addSelect(
|
|
|
|
|
'(
|
2024-06-13 23:01:53 +02:00
|
|
|
SELECT COALESCE(SUM(partLot.amount), 0.0)
|
2025-08-02 23:35:30 +02:00
|
|
|
FROM ' . PartLot::class . ' partLot
|
2024-02-29 23:35:05 +01:00
|
|
|
WHERE partLot.part = part.id
|
|
|
|
|
AND partLot.instock_unknown = false
|
|
|
|
|
AND (partLot.expiration_date IS NULL OR partLot.expiration_date > CURRENT_DATE())
|
|
|
|
|
) AS HIDDEN amountSum'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 01:40:25 +01:00
|
|
|
if (str_contains($dql, '_category')) {
|
|
|
|
|
$builder->leftJoin('part.category', '_category');
|
2024-06-16 22:52:15 +02:00
|
|
|
$builder->addGroupBy('_category');
|
2024-02-25 01:40:25 +01:00
|
|
|
}
|
|
|
|
|
if (str_contains($dql, '_master_picture_attachment')) {
|
|
|
|
|
$builder->leftJoin('part.master_picture_attachment', '_master_picture_attachment');
|
2024-06-16 22:52:15 +02:00
|
|
|
$builder->addGroupBy('_master_picture_attachment');
|
2024-02-25 01:40:25 +01:00
|
|
|
}
|
|
|
|
|
if (str_contains($dql, '_partLots') || str_contains($dql, '_storelocations')) {
|
|
|
|
|
$builder->leftJoin('part.partLots', '_partLots');
|
|
|
|
|
$builder->leftJoin('_partLots.storage_location', '_storelocations');
|
2024-06-16 22:52:15 +02:00
|
|
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
|
|
|
|
//$builder->addGroupBy('_partLots');
|
|
|
|
|
//$builder->addGroupBy('_storelocations');
|
2024-02-25 01:40:25 +01:00
|
|
|
}
|
|
|
|
|
if (str_contains($dql, '_footprint')) {
|
|
|
|
|
$builder->leftJoin('part.footprint', '_footprint');
|
2024-06-16 22:52:15 +02:00
|
|
|
$builder->addGroupBy('_footprint');
|
2024-02-25 01:40:25 +01:00
|
|
|
}
|
|
|
|
|
if (str_contains($dql, '_manufacturer')) {
|
|
|
|
|
$builder->leftJoin('part.manufacturer', '_manufacturer');
|
2024-06-16 22:52:15 +02:00
|
|
|
$builder->addGroupBy('_manufacturer');
|
2024-02-25 01:40:25 +01:00
|
|
|
}
|
|
|
|
|
if (str_contains($dql, '_orderdetails') || str_contains($dql, '_suppliers')) {
|
|
|
|
|
$builder->leftJoin('part.orderdetails', '_orderdetails');
|
|
|
|
|
$builder->leftJoin('_orderdetails.supplier', '_suppliers');
|
2024-06-16 22:52:15 +02:00
|
|
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
|
|
|
|
//$builder->addGroupBy('_orderdetails');
|
|
|
|
|
//$builder->addGroupBy('_suppliers');
|
2024-02-25 01:40:25 +01:00
|
|
|
}
|
|
|
|
|
if (str_contains($dql, '_attachments')) {
|
|
|
|
|
$builder->leftJoin('part.attachments', '_attachments');
|
2024-06-16 22:52:15 +02:00
|
|
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
|
|
|
|
//$builder->addGroupBy('_attachments');
|
2024-02-25 01:40:25 +01:00
|
|
|
}
|
|
|
|
|
if (str_contains($dql, '_partUnit')) {
|
|
|
|
|
$builder->leftJoin('part.partUnit', '_partUnit');
|
2024-06-16 22:52:15 +02:00
|
|
|
$builder->addGroupBy('_partUnit');
|
2024-02-25 01:40:25 +01:00
|
|
|
}
|
2025-10-27 21:58:16 +01:00
|
|
|
if (str_contains($dql, '_partCustomState')) {
|
|
|
|
|
$builder->leftJoin('part.partCustomState', '_partCustomState');
|
|
|
|
|
$builder->addGroupBy('_partCustomState');
|
|
|
|
|
}
|
2024-02-25 01:40:25 +01:00
|
|
|
if (str_contains($dql, '_parameters')) {
|
|
|
|
|
$builder->leftJoin('part.parameters', '_parameters');
|
2024-06-16 22:52:15 +02:00
|
|
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
|
|
|
|
//$builder->addGroupBy('_parameters');
|
2024-02-25 01:40:25 +01:00
|
|
|
}
|
2024-03-02 19:00:09 +01:00
|
|
|
if (str_contains($dql, '_projectBomEntries')) {
|
|
|
|
|
$builder->leftJoin('part.project_bom_entries', '_projectBomEntries');
|
2024-06-16 22:52:15 +02:00
|
|
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
|
|
|
|
//$builder->addGroupBy('_projectBomEntries');
|
2024-03-02 19:00:09 +01:00
|
|
|
}
|
2025-08-02 23:35:30 +02:00
|
|
|
if (str_contains($dql, '_jobPart')) {
|
|
|
|
|
$builder->leftJoin('part.bulkImportJobParts', '_jobPart');
|
|
|
|
|
$builder->leftJoin('_jobPart.job', '_bulkImportJob');
|
|
|
|
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
|
|
|
|
//$builder->addGroupBy('_jobPart');
|
|
|
|
|
//$builder->addGroupBy('_bulkImportJob');
|
|
|
|
|
}
|
2024-02-25 01:40:25 +01:00
|
|
|
|
2024-02-29 23:13:17 +01:00
|
|
|
return $builder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function buildCriteria(QueryBuilder $builder, array $options): void
|
|
|
|
|
{
|
|
|
|
|
//Apply the search criterias first
|
|
|
|
|
if ($options['search'] instanceof PartSearchFilter) {
|
|
|
|
|
$search = $options['search'];
|
|
|
|
|
$search->apply($builder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//We do the most stuff here in the filter class
|
|
|
|
|
if ($options['filter'] instanceof PartFilter) {
|
|
|
|
|
$filter = $options['filter'];
|
|
|
|
|
$filter->apply($builder);
|
|
|
|
|
}
|
2020-01-05 15:46:58 +01:00
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|