Reformat code to allow easier diff between ProjectBomEntriesDataTable.php and PartsDataTable.php

This commit is contained in:
Marc Kreidler 2026-04-03 22:40:22 +02:00
parent d13353c09f
commit c42c989831

View file

@ -1,8 +1,5 @@
<?php <?php
/**
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * 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) * Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
@ -20,6 +17,9 @@ declare(strict_types=1);
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
declare(strict_types=1);
namespace App\DataTables; namespace App\DataTables;
use App\DataTables\Column\EntityColumn; use App\DataTables\Column\EntityColumn;
@ -44,9 +44,12 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class ProjectBomEntriesDataTable implements DataTableTypeInterface class ProjectBomEntriesDataTable implements DataTableTypeInterface
{ {
public function __construct(protected TranslatorInterface $translator, protected PartDataTableHelper $partDataTableHelper, public function __construct(
protected EntityURLGenerator $entityURLGenerator, protected AmountFormatter $amountFormatter) protected EntityURLGenerator $entityURLGenerator,
{ protected TranslatorInterface $translator,
protected AmountFormatter $amountFormatter,
protected PartDataTableHelper $partDataTableHelper
) {
} }
@ -62,7 +65,7 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
return ''; return '';
} }
return $this->partDataTableHelper->renderPicture($context->getPart()); return $this->partDataTableHelper->renderPicture($context->getPart());
}, }
]) ])
->add('id', TextColumn::class, [ ->add('id', TextColumn::class, [
@ -133,18 +136,18 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
->add('category', EntityColumn::class, [ ->add('category', EntityColumn::class, [
'label' => $this->translator->trans('part.table.category'), 'label' => $this->translator->trans('part.table.category'),
'property' => 'part.category', 'property' => 'part.category',
'orderField' => 'NATSORT(category.name)', 'orderField' => 'NATSORT(category.name)'
]) ])
->add('footprint', EntityColumn::class, [ ->add('footprint', EntityColumn::class, [
'property' => 'part.footprint', 'property' => 'part.footprint',
'label' => $this->translator->trans('part.table.footprint'), 'label' => $this->translator->trans('part.table.footprint'),
'orderField' => 'NATSORT(footprint.name)', 'orderField' => 'NATSORT(footprint.name)'
]) ])
->add('manufacturer', EntityColumn::class, [ ->add('manufacturer', EntityColumn::class, [
'property' => 'part.manufacturer', 'property' => 'part.manufacturer',
'label' => $this->translator->trans('part.table.manufacturer'), 'label' => $this->translator->trans('part.table.manufacturer'),
'orderField' => 'NATSORT(manufacturer.name)', 'orderField' => 'NATSORT(manufacturer.name)'
]) ])
->add('manufacturing_status', EnumColumn::class, [ ->add('manufacturing_status', EnumColumn::class, [
@ -225,7 +228,8 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
private function getQuery(QueryBuilder $builder, array $options): void private function getQuery(QueryBuilder $builder, array $options): void
{ {
$builder->select('bom_entry') $builder
->select('bom_entry')
->addSelect('part') ->addSelect('part')
->from(ProjectBOMEntry::class, 'bom_entry') ->from(ProjectBOMEntry::class, 'bom_entry')
->leftJoin('bom_entry.part', 'part') ->leftJoin('bom_entry.part', 'part')
@ -238,7 +242,6 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
->where('bom_entry.project = :project') ->where('bom_entry.project = :project')
->setParameter('project', $options['project']) ->setParameter('project', $options['project'])
//We have to group by all elements, or only the first sub elements of an association is fetched! (see issue #190)
->addGroupBy('part') ->addGroupBy('part')
->addGroupBy('partLots') ->addGroupBy('partLots')
->addGroupBy('category') ->addGroupBy('category')