Added constraints to filter for the number of orderdetails and attachments

This commit is contained in:
Jan Böhmer 2022-08-29 01:12:36 +02:00
parent 768618cede
commit 5402d3b031
6 changed files with 91 additions and 6 deletions

View file

@ -47,10 +47,16 @@ trait FilterTrait
*/
protected function addSimpleAndConstraint(QueryBuilder $queryBuilder, string $property, string $parameterIdentifier, string $comparison_operator, $value): void
{
if($this->useHaving || $this->isAggregateFunctionString($property)) { //If the property is an aggregate function, we have to use the "having" instead of the "where"
$queryBuilder->andHaving(sprintf("%s %s (:%s)", $property, $comparison_operator, $parameterIdentifier));
if ($comparison_operator === 'IN') {
$expression = sprintf("%s %s (:%s)", $property, $comparison_operator, $parameterIdentifier);
} else {
$queryBuilder->andWhere(sprintf("%s %s (:%s)", $property, $comparison_operator, $parameterIdentifier));
$expression = sprintf("%s %s :%s", $property, $comparison_operator, $parameterIdentifier);
}
if($this->useHaving || $this->isAggregateFunctionString($property)) { //If the property is an aggregate function, we have to use the "having" instead of the "where"
$queryBuilder->andHaving($expression);
} else {
$queryBuilder->andWhere($expression);
}
$queryBuilder->setParameter($parameterIdentifier, $value);

View file

@ -68,10 +68,13 @@ class PartFilter implements FilterInterface
/** @var EntityConstraint */
protected $supplier;
/** @var IntConstraint */
protected $orderdetailsCount;
/** @var EntityConstraint */
protected $storelocation;
/** @var NumberConstraint */
/** @var IntConstraint */
protected $lotCount;
/** @var EntityConstraint */
@ -83,6 +86,9 @@ class PartFilter implements FilterInterface
/** @var TextConstraint */
protected $manufacturer_product_number;
/** @var IntConstraint */
protected $attachmentsCount;
public function __construct(NodesListBuilder $nodesListBuilder)
{
$this->name = new TextConstraint('part.name');
@ -108,7 +114,10 @@ class PartFilter implements FilterInterface
$this->manufacturer_product_url = new TextConstraint('part.manufacturer_product_url');
$this->storelocation = new EntityConstraint($nodesListBuilder, Storelocation::class, 'partLots.storage_location');
$this->lotCount = new IntConstraint('COUNT(partLots)');
$this->attachmentsCount = new IntConstraint('COUNT(attachments)');
$this->orderdetailsCount = new IntConstraint('COUNT(orderdetails)');
}
public function apply(QueryBuilder $queryBuilder): void
@ -261,4 +270,22 @@ class PartFilter implements FilterInterface
{
return $this->tags;
}
/**
* @return IntConstraint
*/
public function getOrderdetailsCount(): IntConstraint
{
return $this->orderdetailsCount;
}
/**
* @return IntConstraint
*/
public function getAttachmentsCount(): IntConstraint
{
return $this->attachmentsCount;
}
}

View file

@ -348,7 +348,10 @@ final class PartsDataTable implements DataTableTypeInterface
->leftJoin('part.orderdetails', 'orderdetails')
->leftJoin('orderdetails.supplier', 'suppliers')
->leftJoin('part.attachments', 'attachments')
->leftJoin('part.partUnit', 'partUnit');
->leftJoin('part.partUnit', 'partUnit')
->groupBy('part')
;
}
private function buildCriteria(QueryBuilder $builder, array $options): void