mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
[export] sort filters and aggregators by title
This commit is contained in:
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
@@ -54,20 +55,17 @@ class ExportManager
|
||||
*/
|
||||
private array $formatters = [];
|
||||
|
||||
private readonly string|\Stringable|\Symfony\Component\Security\Core\User\UserInterface $user;
|
||||
|
||||
public function __construct(
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly AuthorizationCheckerInterface $authorizationChecker,
|
||||
private readonly AuthorizationHelperInterface $authorizationHelper,
|
||||
TokenStorageInterface $tokenStorage,
|
||||
private readonly TokenStorageInterface $tokenStorage,
|
||||
iterable $exports,
|
||||
iterable $aggregators,
|
||||
iterable $filters
|
||||
// iterable $formatters,
|
||||
// iterable $exportElementProvider
|
||||
) {
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->exports = iterator_to_array($exports);
|
||||
$this->aggregators = iterator_to_array($aggregators);
|
||||
$this->filters = iterator_to_array($filters);
|
||||
@@ -91,20 +89,24 @@ class ExportManager
|
||||
*
|
||||
* @return FilterInterface[] a \Generator that contains filters. The key is the filter's alias
|
||||
*/
|
||||
public function &getFiltersApplyingOn(DirectExportInterface|ExportInterface $export, array $centers = null): iterable
|
||||
public function getFiltersApplyingOn(DirectExportInterface|ExportInterface $export, array $centers = null): array
|
||||
{
|
||||
if ($export instanceof DirectExportInterface) {
|
||||
return;
|
||||
return [];
|
||||
}
|
||||
|
||||
$filters = [];
|
||||
|
||||
foreach ($this->filters as $alias => $filter) {
|
||||
if (
|
||||
\in_array($filter->applyOn(), $export->supportsModifiers(), true)
|
||||
&& $this->isGrantedForElement($filter, $export, $centers)
|
||||
) {
|
||||
yield $alias => $filter;
|
||||
$filters[$alias] = $filter;
|
||||
}
|
||||
}
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,22 +114,26 @@ class ExportManager
|
||||
*
|
||||
* @internal This class check the interface implemented by export, and, if ´ListInterface´ is used, return an empty array
|
||||
*
|
||||
* @return iterable<string, AggregatorInterface>|null a \Generator that contains aggretagors. The key is the filter's alias
|
||||
* @return array<string, AggregatorInterface> an array that contains aggregators. The key is the filter's alias
|
||||
*/
|
||||
public function &getAggregatorsApplyingOn(DirectExportInterface|ExportInterface $export, array $centers = null): ?iterable
|
||||
public function getAggregatorsApplyingOn(DirectExportInterface|ExportInterface $export, array $centers = null): array
|
||||
{
|
||||
if ($export instanceof ListInterface || $export instanceof DirectExportInterface) {
|
||||
return;
|
||||
return [];
|
||||
}
|
||||
|
||||
$aggregators = [];
|
||||
|
||||
foreach ($this->aggregators as $alias => $aggregator) {
|
||||
if (
|
||||
\in_array($aggregator->applyOn(), $export->supportsModifiers(), true)
|
||||
&& $this->isGrantedForElement($aggregator, $export, $centers)
|
||||
) {
|
||||
yield $alias => $aggregator;
|
||||
$aggregators[$alias] = $aggregator;
|
||||
}
|
||||
}
|
||||
|
||||
return $aggregators;
|
||||
}
|
||||
|
||||
public function addExportElementsProvider(ExportElementsProviderInterface $provider, string $prefix): void
|
||||
@@ -347,6 +353,17 @@ class ExportManager
|
||||
return $this->filters[$alias];
|
||||
}
|
||||
|
||||
public function getAllFilters(): array
|
||||
{
|
||||
$filters = [];
|
||||
|
||||
foreach ($this->filters as $alias => $filter) {
|
||||
$filters[$alias] = $filter;
|
||||
}
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* get all filters.
|
||||
*
|
||||
@@ -452,7 +469,7 @@ class ExportManager
|
||||
if (null === $centers || [] === $centers) {
|
||||
// we want to try if at least one center is reachable
|
||||
return [] !== $this->authorizationHelper->getReachableCenters(
|
||||
$this->user,
|
||||
$this->tokenStorage->getToken()->getUser(),
|
||||
$role
|
||||
);
|
||||
}
|
||||
@@ -484,11 +501,17 @@ class ExportManager
|
||||
{
|
||||
$r = [];
|
||||
|
||||
$user = $this->tokenStorage->getToken()->getUser();
|
||||
|
||||
if (!$user instanceof User) {
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($centers as $center) {
|
||||
$r[] = [
|
||||
'center' => $center,
|
||||
'circles' => $this->authorizationHelper->getReachableScopes(
|
||||
$this->user,
|
||||
$user,
|
||||
$element->requiredRole(),
|
||||
$center
|
||||
),
|
||||
|
Reference in New Issue
Block a user