mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add an interface for export which are lists
Lists does not supports aggregators. The export manager will filter the aggregators applying on the export depending on the interface implemented by the export: if the export implements `Export\ListInterface`, no aggregators will be returned for this export.
This commit is contained in:
parent
dc59c99f70
commit
9d18581db1
@ -25,6 +25,10 @@ use Doctrine\ORM\QueryBuilder;
|
||||
* Interface for Export.
|
||||
*
|
||||
* An export is a class which will initiate a query for an export.
|
||||
*
|
||||
* **Note** : the report implementing this class will be modified by
|
||||
* both filters **and** aggregators. If the report does not support
|
||||
* aggregation, use `ListInterface`.
|
||||
*
|
||||
* @example Chill\PersonBundle\Export\CountPerson an example of implementation
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
|
@ -33,6 +33,7 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
|
||||
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
||||
use Chill\MainBundle\Export\ListInterface;
|
||||
|
||||
/**
|
||||
* Collects all agregators, filters and export from
|
||||
@ -235,6 +236,11 @@ class ExportManager
|
||||
return $this->filters[$alias];
|
||||
}
|
||||
|
||||
/**
|
||||
* get all filters
|
||||
*
|
||||
* @param \Generator $aliases
|
||||
*/
|
||||
public function getFilters(array $aliases)
|
||||
{
|
||||
foreach($aliases as $alias) {
|
||||
@ -273,6 +279,13 @@ class ExportManager
|
||||
return $this->formatters[$alias];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all formatters which supports one of the given types.
|
||||
*
|
||||
*
|
||||
* @param array $types
|
||||
* @return \Generator
|
||||
*/
|
||||
public function getFormattersByTypes(array $types)
|
||||
{
|
||||
foreach ($this->formatters as $alias => $formatter) {
|
||||
@ -358,12 +371,17 @@ class ExportManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a \Generator containing aggregators which support type
|
||||
* Return a \Generator containing aggregators supported by the given export
|
||||
*
|
||||
* @internal This class check the interface implemented by export, and, if ´ListInterface´ is used, return an empty array
|
||||
* @return AggregatorInterface[] a \Generator that contains aggretagors. The key is the filter's alias
|
||||
*/
|
||||
public function &getAggregatorsApplyingOn(ExportInterface $export, array $centers = null)
|
||||
{
|
||||
if ($export instanceof ListInterface) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($this->aggregators as $alias => $aggregator) {
|
||||
if (in_array($aggregator->applyOn(), $export->supportsModifiers()) &&
|
||||
$this->isGrantedForElement($aggregator, $export, $centers)) {
|
||||
|
@ -182,7 +182,8 @@ class CSVListFormatter implements FormatterInterface
|
||||
}
|
||||
|
||||
foreach ($first_row as $key => $value) {
|
||||
$header_line[] = $this->getLabel($key, '_header');
|
||||
$header_line[] = $this->translator->trans(
|
||||
$this->getLabel($key, '_header'));
|
||||
}
|
||||
|
||||
if (count($header_line) > 0) {
|
||||
|
17
Export/ListInterface.php
Normal file
17
Export/ListInterface.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
/**
|
||||
* Define methods to export list.
|
||||
*
|
||||
* This interface is a specification of export interface
|
||||
* and should be used when the export does not supports aggregators
|
||||
* (and list does not support aggregation on their data).
|
||||
*
|
||||
* When used, the `ExportManager` will not handle aggregator for this class.
|
||||
*/
|
||||
interface ListInterface extends ExportInterface
|
||||
{
|
||||
|
||||
}
|
@ -76,7 +76,7 @@ class ExportType extends AbstractType
|
||||
|
||||
$builder->add($filterBuilder);
|
||||
|
||||
//add aggregators
|
||||
//add aggregators
|
||||
$aggregators = $this->exportManager
|
||||
->getAggregatorsApplyingOn($export, $options['picked_centers']);
|
||||
$aggregatorBuilder = $builder->create(self::AGGREGATOR_KEY, 'form',
|
||||
|
@ -58,6 +58,7 @@
|
||||
{{ form_widget(child) }}
|
||||
{{ form_label(child, '', {'label_attr': { 'class' : 'inline'} }) }}
|
||||
</span>
|
||||
<br/>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<script type="text/javascript">chill.checkNullValuesInChoices("{{ form.vars.full_name }}");</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user