create a first set of export framework

- create interfaces
- create an export manager
- add a compiler pass to gather services tagged for export
This commit is contained in:
2016-01-02 16:44:30 +01:00
parent 876a656bd2
commit b40b85527a
16 changed files with 1070 additions and 16 deletions

View File

@@ -0,0 +1,82 @@
<?php
/*
* Copyright (C) 2015 Champs-Libres <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\MainBundle\Form\Type\Export;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormBuilderInterface;
use Chill\MainBundle\Export\ExportManager;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class AggregatorType extends AbstractType
{
/**
*
* @var \ExportManager
*/
private $exportManager;
public function __construct(ExportManager $exportManager)
{
$this->exportManager = $exportManager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$aggregator = $this->exportManager->getAggregator($options['aggregator_alias']);
$builder
->add('order', IntegerType::class, array(
'constraints' => array(
new Assert\GreaterThanOrEqual(array(
'value' => -1
)),
new Assert\LessThanOrEqual(array(
'value' => $options['aggregators_length']
))
)
));
$filterFormBuilder = $builder->create('form', 'form', array(
'compound' => true, 'required' => false));
$aggregator->buildForm($filterFormBuilder);
$builder->add($filterFormBuilder);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired('aggregator_alias')
->setRequired('aggregators_length')
->setAllowedTypes(array(
'aggregators_length' => 'int'
))
->setDefault('compound', true)
;
}
}

View File

@@ -0,0 +1,102 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\MainBundle\Form\Type\Export;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormBuilderInterface;
use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Form\Type\Export\FilterType;
use Chill\MainBundle\Form\Type\Export\AggregatorType;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ExportType extends AbstractType
{
/**
*
* @var ExportManager
*/
protected $exportManager;
public function __construct(ExportManager $exportManager)
{
$this->exportManager = $exportManager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$export = $this->exportManager->getExport($options['export_alias']);
/* this part has not been experimented
if ($export->hasForm()) {
$exportBuilder = $builder->create('export', null, array('compound' => true));
$export->buildForm($exportBuilder);
$builder->add($exportBuilder);
} */
//add filters
$filters = $this->exportManager->getFiltersApplyingOn($export->supportsModifiers());
$filterBuilder = $builder->create('filters', 'form', array('compound' => true));
foreach($filters as $alias => $filter) {
$filterBuilder->add($alias, new FilterType($this->exportManager), array(
'filter_alias' => $alias,
'label' => $filter->getTitle()
));
}
$builder->add($filterBuilder);
//add aggregators
$aggregators = iterator_to_array($this->exportManager
->getAggregatorsApplyingOn($export->supportsModifiers()));
$aggregatorBuilder = $builder->create('aggregators', 'form',
array('compound' => true));
$nb = count($aggregators);
foreach($aggregators as $alias => $aggregator) {
$aggregatorBuilder->add($alias, new AggregatorType($this->exportManager), array(
'aggregator_alias' => $alias,
'aggregators_length' => $nb,
'label' => $aggregator->getTitle()
));
}
$builder->add($aggregatorBuilder);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(array('export_alias'))
->setAllowedTypes('export_alias', array('string'))
->setDefault('compound', true)
;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/*
* Copyright (C) 2015 Champs-Libres <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\MainBundle\Form\Type\Export;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormBuilderInterface;
use Chill\MainBundle\Export\ExportManager;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class FilterType extends AbstractType
{
/**
*
* @var \ExportManager
*/
private $exportManager;
public function __construct(ExportManager $exportManager)
{
$this->exportManager = $exportManager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$filter = $this->exportManager->getFilter($options['filter_alias']);
$builder
->add('enabled', 'choice', array(
'choices' => array(
'enabled' => true,
'disabled' => false
),
'multiple' => false,
'expanded' => true,
'choices_as_values' => true
));
$filterFormBuilder = $builder->create('form', null, array(
'compound' => true, 'required' => false));
$filter->buildForm($filterFormBuilder);
$builder->add($filterFormBuilder);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired('filter_alias')
->setDefault('compound', true)
;
}
}