Merge remote-tracking branch 'origin/master' into rector/rules-symfony

This commit is contained in:
2023-09-27 15:25:29 +02:00
106 changed files with 1259 additions and 506 deletions

View File

@@ -26,6 +26,7 @@ use Chill\TaskBundle\Event\TaskEvent;
use Chill\TaskBundle\Event\UI\UIEvent;
use Chill\TaskBundle\Form\SingleTaskType;
use Chill\TaskBundle\Repository\SingleTaskAclAwareRepositoryInterface;
use Chill\TaskBundle\Repository\SingleTaskRepository;
use Chill\TaskBundle\Repository\SingleTaskStateRepository;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use LogicException;
@@ -57,7 +58,8 @@ final class SingleTaskController extends AbstractController
private readonly TimelineBuilder $timelineBuilder,
private readonly LoggerInterface $logger,
private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory,
private readonly SingleTaskStateRepository $singleTaskStateRepository
private readonly SingleTaskStateRepository $singleTaskStateRepository,
private readonly SingleTaskRepository $singleTaskRepository,
) {}
/**
@@ -267,7 +269,9 @@ final class SingleTaskController extends AbstractController
) {
$this->denyAccessUnlessGranted(TaskVoter::SHOW, null);
$filterOrder = $this->buildFilterOrder();
$showMissionTypeFilter = $this->singleTaskRepository->countByDistinctTypes() > 1;
$filterOrder = $this->buildFilterOrder(true, $showMissionTypeFilter);
$filteredUsers = $filterOrder->getUserPickerData('userPicker');
@@ -275,9 +279,15 @@ final class SingleTaskController extends AbstractController
$filterOrder->getCheckboxData('status'),
array_map(static fn ($i) => 'state_' . $i, $filterOrder->hasCheckboxData('states') ? $filterOrder->getCheckboxData('states') : [])
);
if ($showMissionTypeFilter) {
$types = $filterOrder->getCheckboxData('missionTypePicker');
}
$nb = $this->singleTaskAclAwareRepository->countByAllViewable(
$filterOrder->getQueryString(),
$flags,
$types ?? [],
$filteredUsers
);
$paginator = $this->paginatorFactory->create($nb);
@@ -286,6 +296,7 @@ final class SingleTaskController extends AbstractController
$tasks = $this->singleTaskAclAwareRepository->findByAllViewable(
$filterOrder->getQueryString(),
$flags,
$types ?? [],
$filteredUsers,
$paginator->getCurrentPageFirstItemNumber(),
$paginator->getItemsPerPage(),
@@ -631,7 +642,7 @@ final class SingleTaskController extends AbstractController
return $form;
}
private function buildFilterOrder($includeFilterByUser = true): FilterOrderHelper
private function buildFilterOrder($includeFilterByUser = true, $includeMissionType = false): FilterOrderHelper
{
$statuses = ['no-alert', 'warning', 'alert'];
$statusTrans = [
@@ -639,6 +650,7 @@ final class SingleTaskController extends AbstractController
'Tasks near deadline',
'Tasks over deadline',
];
$arrayOfTypes = [];
$filterBuilder = $this->filterOrderHelperFactory
->create(self::class)
@@ -658,6 +670,16 @@ final class SingleTaskController extends AbstractController
->addUserPicker('userPicker', 'Filter by user', ['multiple' => true, 'required' => false]);
}
if ($includeMissionType) {
$filterBuilder->addCheckbox(
'missionTypePicker',
array_map(
fn ($row) => $row['type'],
$this->singleTaskRepository->findAllTaskDistinctTypes()
)
);
}
return $filterBuilder->build();
}

View File

@@ -31,6 +31,15 @@ use Doctrine\ORM\Mapping as ORM;
*/
class SingleTaskPlaceEvent extends AbstractTaskPlaceEvent
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
/**
* @var SingleTask
* @ORM\ManyToOne(
@@ -51,4 +60,14 @@ class SingleTaskPlaceEvent extends AbstractTaskPlaceEvent
return $this;
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
}

View File

@@ -34,6 +34,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
public function buildBaseQuery(
?string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = []
): QueryBuilder {
$qb = $this->em->createQueryBuilder();
@@ -59,8 +60,12 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
if ($orXUser->count() > 0) {
$qb->andWhere($orXUser);
}
}
return $qb;
if (null !== $types && count($types) > 0) {
$qb->andWhere($qb->expr()->in('t.type', ':types'));
$qb->setParameter('types', $types);
}
if (null !== $flags && count($flags) > 0) {
@@ -185,9 +190,10 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
public function countByAllViewable(
?string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = []
): int {
$qb = $this->buildBaseQuery($pattern, $flags, $users);
$qb = $this->buildBaseQuery($pattern, $flags, $types, $users);
return $this
->addACLGlobal($qb)
@@ -233,12 +239,13 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
public function findByAllViewable(
?string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = [],
?int $start = 0,
?int $limit = 50,
?array $orderBy = []
): array {
$qb = $this->buildBaseQuery($pattern, $flags, $users);
$qb = $this->buildBaseQuery($pattern, $flags, $types, $users);
$qb = $this->addACLGlobal($qb);
return $this->getResult($qb, $start, $limit, $orderBy);

View File

@@ -19,6 +19,7 @@ interface SingleTaskAclAwareRepositoryInterface
public function countByAllViewable(
?string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = []
): int;
@@ -39,6 +40,7 @@ interface SingleTaskAclAwareRepositoryInterface
public function findByAllViewable(
?string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = [],
?int $start = 0,
?int $limit = 50,

View File

@@ -306,4 +306,28 @@ class SingleTaskRepository extends EntityRepository
->add($qb->expr()->isNull('st.endDate'))
->add($qb->expr()->isNull('st.warningInterval'));
}
public function countByDistinctTypes()
{
$qb = $this->createQueryBuilder('st')
->select('COUNT(DISTINCT st.type)');
$this->buildQuery($qb, []);
return (int) $qb
->getQuery()
->getSingleScalarResult();
}
public function findAllTaskDistinctTypes()
{
$qb = $this->createQueryBuilder('st')
->select('DISTINCT st.type');
$this->buildQuery($qb, []);
return $qb
->getQuery()
->getResult();
}
}