diff --git a/src/Repository/ActivityRepository.php b/src/Repository/ActivityRepository.php index 19680317..4b6ea8a7 100644 --- a/src/Repository/ActivityRepository.php +++ b/src/Repository/ActivityRepository.php @@ -275,29 +275,25 @@ class ActivityRepository extends EntityRepository $where = $qb->expr()->andX(); - if (\in_array($query->getVisibility(), [ActivityQuery::SHOW_VISIBLE, ActivityQuery::SHOW_HIDDEN])) { + if (!$query->isShowBoth()) { if (!$query->isGlobalsOnly()) { $where->add( $qb->expr()->orX( - $qb->expr()->eq('c.visible', ':customer_visible'), - $qb->expr()->isNull('c.visible') + $qb->expr()->isNull('a.project'), + $qb->expr()->andX( + $qb->expr()->eq('c.visible', ':is_visible'), + $qb->expr()->eq('p.visible', ':is_visible') + ) ) ); - $where->add( - $qb->expr()->orX( - $qb->expr()->eq('p.visible', ':project_visible'), - $qb->expr()->isNull('p.visible') - ) - ); - $qb->setParameter('project_visible', true, \PDO::PARAM_BOOL); - $qb->setParameter('customer_visible', true, \PDO::PARAM_BOOL); + $qb->setParameter('is_visible', true, \PDO::PARAM_BOOL); } - $where->add('a.visible = :visible'); + $where->add($qb->expr()->eq('a.visible', ':visible')); - if (ActivityQuery::SHOW_VISIBLE === $query->getVisibility()) { + if ($query->isShowVisible()) { $qb->setParameter('visible', true, \PDO::PARAM_BOOL); - } elseif (ActivityQuery::SHOW_HIDDEN === $query->getVisibility()) { + } elseif ($query->isShowHidden()) { $qb->setParameter('visible', false, \PDO::PARAM_BOOL); } } @@ -359,8 +355,10 @@ class ActivityRepository extends EntityRepository // this will make sure, that we do not accidentally create results with multiple rows // => which would result in a wrong LIMIT / pagination results + // $qb->addGroupBy('a.id'); + // the second group by is needed due to SQL standard (even though logically not really required for this query) - $qb->addGroupBy('a.id')->addGroupBy($orderBy); + // $qb->addGroupBy($orderBy); return $qb; } diff --git a/src/Repository/CustomerRepository.php b/src/Repository/CustomerRepository.php index b21254bf..207ca102 100644 --- a/src/Repository/CustomerRepository.php +++ b/src/Repository/CustomerRepository.php @@ -189,6 +189,7 @@ class CustomerRepository extends EntityRepository ->from(Customer::class, 'c') ->orderBy('c.name', 'ASC'); + // TODO this where and the next if($query->hasCustomers()) should go into their own $qb->expr()->orX() $qb->andWhere($qb->expr()->eq('c.visible', ':visible')); $qb->setParameter('visible', true, \PDO::PARAM_BOOL); @@ -219,10 +220,10 @@ class CustomerRepository extends EntityRepository $orderBy = 'c.' . $query->getOrderBy(); $qb->orderBy($orderBy, $query->getOrder()); - if (CustomerQuery::SHOW_VISIBLE == $query->getVisibility()) { + if ($query->isShowVisible()) { $qb->andWhere($qb->expr()->eq('c.visible', ':visible')); $qb->setParameter('visible', true, \PDO::PARAM_BOOL); - } elseif (CustomerQuery::SHOW_HIDDEN == $query->getVisibility()) { + } elseif ($query->isShowHidden()) { $qb->andWhere($qb->expr()->eq('c.visible', ':visible')); $qb->setParameter('visible', false, \PDO::PARAM_BOOL); } @@ -269,8 +270,10 @@ class CustomerRepository extends EntityRepository // this will make sure, that we do not accidentally create results with multiple rows // => which would result in a wrong LIMIT / pagination results + // $qb->addGroupBy('c.id'); + // the second group by is needed due to SQL standard (even though logically not really required for this query) - $qb->addGroupBy('c.id')->addGroupBy($orderBy); + // $qb->addGroupBy($orderBy); return $qb; } diff --git a/src/Repository/InvoiceRepository.php b/src/Repository/InvoiceRepository.php index 53c5966a..44769b47 100644 --- a/src/Repository/InvoiceRepository.php +++ b/src/Repository/InvoiceRepository.php @@ -141,8 +141,10 @@ class InvoiceRepository extends EntityRepository // this will make sure, that we do not accidentally create results with multiple rows // => which would result in a wrong LIMIT / pagination results + // $qb->addGroupBy('i.id'); + // the second group by is needed due to SQL standard (even though logically not really required for this query) - $qb->addGroupBy('i.id')->addGroupBy($orderBy); + // $qb->addGroupBy($orderBy); return $qb; } diff --git a/src/Repository/ProjectRepository.php b/src/Repository/ProjectRepository.php index 90d97c47..62c5dd98 100644 --- a/src/Repository/ProjectRepository.php +++ b/src/Repository/ProjectRepository.php @@ -271,15 +271,15 @@ class ProjectRepository extends EntityRepository $qb->addOrderBy($orderBy, $query->getOrder()); - if (\in_array($query->getVisibility(), [ProjectQuery::SHOW_VISIBLE, ProjectQuery::SHOW_HIDDEN])) { + if (!$query->isShowBoth()) { $qb ->andWhere($qb->expr()->eq('p.visible', ':visible')) ->andWhere($qb->expr()->eq('c.visible', ':customer_visible')) ; - if (ProjectQuery::SHOW_VISIBLE === $query->getVisibility()) { + if ($query->isShowVisible()) { $qb->setParameter('visible', true, \PDO::PARAM_BOOL); - } elseif (ProjectQuery::SHOW_HIDDEN === $query->getVisibility()) { + } elseif ($query->isShowHidden()) { $qb->setParameter('visible', false, \PDO::PARAM_BOOL); } @@ -368,8 +368,10 @@ class ProjectRepository extends EntityRepository // this will make sure, that we do not accidentally create results with multiple rows // => which would result in a wrong LIMIT / pagination results + // $qb->addGroupBy('p.id'); + // the second group by is needed due to SQL standard (even though logically not really required for this query) - $qb->addGroupBy('p.id')->addGroupBy($orderBy); + // $qb->addGroupBy($orderBy); return $qb; }