Allow to group exports

This commit is contained in:
2019-06-18 21:01:32 +02:00
parent b7e71088ac
commit 9c6a3de0ff
5 changed files with 76 additions and 14 deletions

View File

@@ -231,6 +231,26 @@ class ExportManager
}
}
/**
* Get all exports grouped in an array.
*
* @param bool $whereUserIsGranted
* @return array where keys are the groups's name and value is an array of exports
*/
public function getExportsGrouped($whereUserIsGranted = true): array
{
$groups = [ '_' => [] ];
foreach ($this->getExports($whereUserIsGranted) as $alias => $export) {
if ($export instanceof GroupedExportInterface) {
$groups[$export->getGroup()][$alias] = $export;
} else {
$groups['_'][$alias] = $export;
}
}
return $groups;
}
/**
* Return an export by his alias
*

View File

@@ -0,0 +1,16 @@
<?php
/*
*
*/
namespace Chill\MainBundle\Export;
/**
* Add a grouping option to exports.
*
* **usage**: the exports will be grouped under the key given by the `getGroup`
* method.
*/
interface GroupedExportInterface
{
public function getGroup(): string;
}