handle DirectExport in controller and export manager

This commit is contained in:
2019-01-16 10:58:05 +01:00
parent 6741eb949c
commit 6ee7a834cb
5 changed files with 145 additions and 101 deletions

View File

@@ -348,12 +348,13 @@ class ExportManager
* center, false if the user hasn't access to element for at least one center.
*
* @param \Chill\MainBundle\Export\ExportElementInterface $element
* @param ExportInterface|DirectExportInterface $export
* @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, ExportInterface $export = NULL, array $centers = null)
public function isGrantedForElement(ExportElementInterface $element, ExportElementInterface $export = NULL, array $centers = null)
{
if ($element instanceof ExportInterface) {
if ($element instanceof ExportInterface || $element instanceof DirectExportInterface) {
$role = $element->requiredRole();
} elseif ($element instanceof ModifierInterface ) {
if (is_null($element->addRole())) {
@@ -433,8 +434,10 @@ class ExportManager
$centers = $this->getPickedCenters($pickedCentersData);
if ($export instanceof DirectExportInterface) {
return $export->generate($this->buildCenterReachableScopes($centers, $export),
$data[ExportType::EXPORT_KEY]);
return $export->generate(
$this->buildCenterReachableScopes($centers, $export),
$data[ExportType::EXPORT_KEY]
);
}
$query = $export->initiateQuery(
@@ -571,6 +574,10 @@ class ExportManager
*/
private function retrieveUsedModifiers($data)
{
if ($data === null) {
return [];
}
$usedTypes = array_merge(
$this->retrieveUsedFiltersType($data[ExportType::FILTER_KEY]),
$this->retrieveUsedAggregatorsType($data[ExportType::AGGREGATOR_KEY])
@@ -590,6 +597,10 @@ class ExportManager
*/
private function retrieveUsedFiltersType($data)
{
if ($data === null) {
return [];
}
$usedTypes = array();
foreach($data as $alias => $filterData) {
if ($filterData['enabled'] == true){
@@ -610,6 +621,10 @@ class ExportManager
*/
private function retrieveUsedAggregatorsType($data)
{
if ($data === null) {
return [];
}
$usedTypes = array();
foreach($this->retrieveUsedAggregators($data) as $alias => $aggregator) {
if (!in_array($aggregator->applyOn(), $usedTypes)) {
@@ -627,6 +642,10 @@ class ExportManager
*/
private function retrieveUsedAggregators($data)
{
if ($data === null) {
return [];
}
foreach ($data as $alias => $aggregatorData) {
if ($aggregatorData['enabled'] === true){
yield $alias => $this->getAggregator($alias);
@@ -640,6 +659,10 @@ class ExportManager
*/
private function retrieveUsedFilters($data)
{
if ($data === null) {
return [];
}
foreach ($data as $alias => $filterData) {
if ($filterData['enabled'] === true) {
yield $alias => $this->getFilter($alias);