diff --git a/Export/AggregatorInterface.php b/Export/AggregatorInterface.php index c2c876f06..d2f3fa34a 100644 --- a/Export/AggregatorInterface.php +++ b/Export/AggregatorInterface.php @@ -26,13 +26,11 @@ use Doctrine\ORM\QueryBuilder; * * @author Julien Fastré */ -interface AggregatorInterface +interface AggregatorInterface extends ExportElementInterface { public function applyOn(); public function buildForm(FormBuilderInterface $builder); public function alterQuery(QueryBuilder $qb, $data); - - public function getTitle(); } diff --git a/Export/ExportManager.php b/Export/ExportManager.php index bf80e52ed..fc7409977 100644 --- a/Export/ExportManager.php +++ b/Export/ExportManager.php @@ -247,6 +247,10 @@ class ExportManager * Return a \Generator containing filter which support type. If `$centers` is * not null, restrict the given filters to the center the user have access to. * + * if $centers is null, the function will returns all filters where the user + * has access in every centers he can reach (if the user can use the filter F in + * center A, but not in center B, the filter F will not be returned) + * * @param string[] $types * @param \Chill\MainBundle\Entity\Center[] $centers the centers where the user have access to * @return FilterInterface[] a \Generator that contains filters. The key is the filter's alias @@ -266,7 +270,7 @@ class ExportManager * center, false if the user hasn't access to element for at least one center. * * @param \Chill\MainBundle\Export\ExportElementInterface $element - * @param array|null $centers, if null, the function take into account all the reachables centers for the current user + * @param array|null $centers, if null, the function take into account all the reachables centers for the current user and the role given by element::requiredRole * @return boolean */ public function isGrantedForElement(ExportElementInterface $element, array $centers = null) @@ -317,10 +321,11 @@ class ExportManager * @param string[] $types * @return AggregatorInterface[] a \Generator that contains aggretagors. The key is the filter's alias */ - public function &getAggregatorsApplyingOn(array $types) + public function &getAggregatorsApplyingOn(array $types, array $centers = null) { foreach ($this->aggregators as $alias => $aggregator) { - if (in_array($aggregator->applyOn(), $types)) { + if (in_array($aggregator->applyOn(), $types) && + $this->isGrantedForElement($aggregator, $centers)) { yield $alias => $aggregator; } } diff --git a/Form/Type/Export/ExportType.php b/Form/Type/Export/ExportType.php index b0d38e989..5e3848767 100644 --- a/Form/Type/Export/ExportType.php +++ b/Form/Type/Export/ExportType.php @@ -74,7 +74,8 @@ class ExportType extends AbstractType //add aggregators $aggregators = $this->exportManager - ->getAggregatorsApplyingOn($export->supportsModifiers()); + ->getAggregatorsApplyingOn($export->supportsModifiers(), + $options['picked_centers']); $aggregatorBuilder = $builder->create('aggregators', 'form', array('compound' => true));