diff --git a/src/DataTables/Filters/PartFilter.php b/src/DataTables/Filters/PartFilter.php index 03c031a2..1e415c6e 100644 --- a/src/DataTables/Filters/PartFilter.php +++ b/src/DataTables/Filters/PartFilter.php @@ -115,31 +115,31 @@ class PartFilter implements FilterInterface */ //We have to use Having here, as we use an alias column which is not supported on the where clause and would result in an error $this->amountSum = (new IntConstraint('amountSum'))->useHaving(); - $this->lotCount = new IntConstraint('COUNT(partLots)'); + $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->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->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->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->parametersCount = new IntConstraint('COUNT(_parameters)'); } public function apply(QueryBuilder $queryBuilder): void diff --git a/src/DataTables/Filters/PartSearchFilter.php b/src/DataTables/Filters/PartSearchFilter.php index b94d805a..a00dd25f 100644 --- a/src/DataTables/Filters/PartSearchFilter.php +++ b/src/DataTables/Filters/PartSearchFilter.php @@ -82,7 +82,7 @@ class PartSearchFilter implements FilterInterface $fields_to_search[] = 'part.name'; } if($this->category) { - $fields_to_search[] = 'category.name'; + $fields_to_search[] = '_category.name'; } if($this->description) { $fields_to_search[] = 'part.description'; @@ -94,22 +94,22 @@ class PartSearchFilter implements FilterInterface $fields_to_search[] = 'part.tags'; } if($this->storelocation) { - $fields_to_search[] = 'storelocations.name'; + $fields_to_search[] = '_storelocations.name'; } if($this->ordernr) { - $fields_to_search[] = 'orderdetails.supplierpartnr'; + $fields_to_search[] = '_orderdetails.supplierpartnr'; } if($this->mpn) { $fields_to_search[] = 'part.manufacturer_product_number'; } if($this->supplier) { - $fields_to_search[] = 'suppliers.name'; + $fields_to_search[] = '_suppliers.name'; } if($this->manufacturer) { - $fields_to_search[] = 'manufacturer.name'; + $fields_to_search[] = '_manufacturer.name'; } if($this->footprint) { - $fields_to_search[] = 'footprint.name'; + $fields_to_search[] = '_footprint.name'; } if ($this->ipn) { $fields_to_search[] = 'part.ipn'; diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index 066ae528..f2289fe2 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -241,7 +241,7 @@ final class PartsDataTable implements DataTableTypeInterface ) AS HIDDEN amountSum' ) ->from(Part::class, 'part') - ->leftJoin('part.category', 'category') + /*->leftJoin('part.category', 'category') ->leftJoin('part.master_picture_attachment', 'master_picture_attachment') ->leftJoin('part.partLots', 'partLots') ->leftJoin('partLots.storage_location', 'storelocations') @@ -252,7 +252,7 @@ final class PartsDataTable implements DataTableTypeInterface ->leftJoin('orderdetails.supplier', 'suppliers') ->leftJoin('part.attachments', 'attachments') ->leftJoin('part.partUnit', 'partUnit') - ->leftJoin('part.parameters', 'parameters') + ->leftJoin('part.parameters', 'parameters')*/ //This must be the only group by, or the paginator will not work correctly ->addGroupBy('part.id'); @@ -339,5 +339,40 @@ final class PartsDataTable implements DataTableTypeInterface $filter = $options['filter']; $filter->apply($builder); } + + //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(); + + if (str_contains($dql, '_category')) { + $builder->leftJoin('part.category', '_category'); + } + if (str_contains($dql, '_master_picture_attachment')) { + $builder->leftJoin('part.master_picture_attachment', '_master_picture_attachment'); + } + if (str_contains($dql, '_partLots') || str_contains($dql, '_storelocations')) { + $builder->leftJoin('part.partLots', '_partLots'); + $builder->leftJoin('_partLots.storage_location', '_storelocations'); + } + if (str_contains($dql, '_footprint')) { + $builder->leftJoin('part.footprint', '_footprint'); + } + if (str_contains($dql, '_manufacturer')) { + $builder->leftJoin('part.manufacturer', '_manufacturer'); + } + if (str_contains($dql, '_orderdetails') || str_contains($dql, '_suppliers')) { + $builder->leftJoin('part.orderdetails', '_orderdetails'); + $builder->leftJoin('_orderdetails.supplier', '_suppliers'); + } + if (str_contains($dql, '_attachments')) { + $builder->leftJoin('part.attachments', '_attachments'); + } + if (str_contains($dql, '_partUnit')) { + $builder->leftJoin('part.partUnit', '_partUnit'); + } + if (str_contains($dql, '_parameters')) { + $builder->leftJoin('part.parameters', '_parameters'); + } + } }