mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 03:23:48 +00:00
add more filtering possibilities with order helper
This commit is contained in:
@@ -532,14 +532,18 @@ final class SingleTaskController extends AbstractController
|
||||
$this->denyAccessUnlessGranted('ROLE_USER');
|
||||
|
||||
$filterOrder = $this->buildFilterOrder();
|
||||
$flags = \array_merge(
|
||||
$filterOrder->getCheckboxData('status'),
|
||||
\array_map(fn ($i) => 'state_'.$i, $filterOrder->getCheckboxData('states'))
|
||||
);
|
||||
$nb = $this->singleTaskAclAwareRepository->countByCurrentUsersTasks(
|
||||
$filterOrder->getQueryString(),
|
||||
$filterOrder->getCheckbox('status')
|
||||
$flags
|
||||
);
|
||||
$paginator = $this->paginatorFactory->create($nb);
|
||||
$tasks = $this->singleTaskAclAwareRepository->findByCurrentUsersTasks(
|
||||
$filterOrder->getQueryString(),
|
||||
$filterOrder->getCheckbox('status'),
|
||||
$flags,
|
||||
$paginator->getCurrentPageFirstItemNumber(),
|
||||
$paginator->getItemsPerPage()
|
||||
);
|
||||
@@ -555,14 +559,19 @@ final class SingleTaskController extends AbstractController
|
||||
{
|
||||
$statuses = ['no-alert', 'warning', 'alert'];
|
||||
$statusTrans = [
|
||||
'Tasks without alert',
|
||||
'Tasks near deadline',
|
||||
'Tasks over deadline',
|
||||
'Tasks without alert',
|
||||
];
|
||||
$states = [
|
||||
// todo: get a list of possible states dynamically
|
||||
'new', 'in_progress', 'closed', 'canceled'
|
||||
];
|
||||
return $this->filterOrderHelperFactory
|
||||
->create(self::class)
|
||||
->addSearchBox()
|
||||
->addCheckbox('status', $statuses, $statuses, $statusTrans)
|
||||
->addCheckbox('states', $states, ['new', 'in_progress'])
|
||||
->build()
|
||||
;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -99,7 +99,7 @@ Are you sure you want to start this task ?: Êtes-vous sûrs de vouloir démarre
|
||||
|
||||
Tasks near deadline: Tâches à échéance proche
|
||||
Tasks over deadline: Tâches à échéance dépassée
|
||||
Tasks without alert: Tâches sans alerte
|
||||
Tasks without alert: Tâches à échéance future ou sans échéance
|
||||
|
||||
#title
|
||||
My tasks near deadline: Mes tâches à échéance proche
|
||||
|
Reference in New Issue
Block a user