mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add more filtering possibilities with order helper
This commit is contained in:
@@ -63,64 +63,74 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository
|
||||
|
||||
if (!empty($pattern)) {
|
||||
$qb->andWhere($qb->expr()->like('LOWER(UNACCENT(t.title))', 'LOWER(UNACCENT(:pattern))'))
|
||||
->setParameter('pattern', $pattern)
|
||||
->setParameter('pattern', '%'.$pattern.'%')
|
||||
;
|
||||
}
|
||||
|
||||
if (count($flags) > 0) {
|
||||
$orX = $qb->expr()->orX();
|
||||
$orXDate = $qb->expr()->orX();
|
||||
$orXState = $qb->expr()->orX();
|
||||
$now = new \DateTime();
|
||||
|
||||
if (\in_array('no-alert', $flags)) {
|
||||
$orX
|
||||
->add(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('t.endDate'),
|
||||
$qb->expr()->gte('t.endDate - COALESCE(t.warningInterval, :intervalBlank)', ':now')
|
||||
)
|
||||
);
|
||||
$qb
|
||||
->setParameter('intervalBlank', new \DateInterval('P0D'))
|
||||
->setParameter('now', $now)
|
||||
;
|
||||
foreach ($flags as $key => $flag) {
|
||||
switch ($flag) {
|
||||
case 'no-alert':
|
||||
$orXDate
|
||||
->add(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('t.endDate'),
|
||||
$qb->expr()->gte('t.endDate - COALESCE(t.warningInterval, :intervalBlank)', ':now')
|
||||
)
|
||||
);
|
||||
$qb
|
||||
->setParameter('intervalBlank', new \DateInterval('P0D'))
|
||||
->setParameter('now', $now);
|
||||
break;
|
||||
case 'warning':
|
||||
$orXDate
|
||||
->add(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->not($qb->expr()->isNull('t.endDate')),
|
||||
$qb->expr()->not($qb->expr()->isNull('t.warningInterval')),
|
||||
$qb->expr()->gte('t.endDate - t.warningInterval', ':now'),
|
||||
$qb->expr()->lt('t.endDate', ':now')
|
||||
)
|
||||
);
|
||||
$qb
|
||||
->setParameter('now', $now);
|
||||
break;
|
||||
case 'alert':
|
||||
$orXDate
|
||||
->add(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->not($qb->expr()->isNull('t.endDate')),
|
||||
$qb->expr()->lte('t.endDate', ':now')
|
||||
)
|
||||
);
|
||||
$qb
|
||||
->setParameter('now', $now);
|
||||
break;
|
||||
case \substr($flag, 0, 6) === 'state_':
|
||||
$state = \substr($flag, 6);
|
||||
$orXState
|
||||
->add(
|
||||
"JSONB_EXISTS_IN_ARRAY(t.currentStates, :state_$key) = 'TRUE'"
|
||||
);
|
||||
$qb->setParameter("state_$key", $state);
|
||||
break;
|
||||
default:
|
||||
throw new \LogicException("this flag is not supported: $flag");
|
||||
}
|
||||
}
|
||||
|
||||
if (\in_array('warning', $flags)) {
|
||||
$orX
|
||||
->add(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->eq('t.closed', "'FALSE'"),
|
||||
$qb->expr()->not($qb->expr()->isNull('t.endDate')),
|
||||
$qb->expr()->not($qb->expr()->isNull('t.warningInterval')),
|
||||
$qb->expr()->lte('t.endDate - t.warningInterval', ':now')
|
||||
)
|
||||
)
|
||||
;
|
||||
$qb
|
||||
->setParameter('now', $now)
|
||||
;
|
||||
if ($orXDate->count() > 0) {
|
||||
$qb->andWhere($orXDate);
|
||||
}
|
||||
|
||||
if (\in_array('alert', $flags)) {
|
||||
$orX
|
||||
->add(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->eq('t.closed', "'FALSE'"),
|
||||
$qb->expr()->not($qb->expr()->isNull('t.endDate')),
|
||||
$qb->expr()->lte('t.endDate', ':now')
|
||||
)
|
||||
)
|
||||
;
|
||||
$qb
|
||||
->setParameter('now', $now)
|
||||
;
|
||||
if ($orXState->count() > 0) {
|
||||
$qb->andWhere($orXState);
|
||||
}
|
||||
|
||||
$qb->andWhere($orX);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user