[wip] add different steps to handle request

This commit is contained in:
2016-01-11 21:45:20 +01:00
parent b40b85527a
commit e1a9ad1612
13 changed files with 829 additions and 48 deletions

View File

@@ -0,0 +1,86 @@
<?php
/*
* Copyright (C) 2016 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\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Chill\MainBundle\Export\ExportManager;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* Transform a formatter alias to an FormatterInterface class
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class AliasToFormatterTransformer implements DataTransformerInterface
{
/**
*
* @var ExportManager
*/
protected $exportManager;
public function __construct(ExportManager $exportManager)
{
$this->exportManager = $exportManager;
}
public function reverseTransform($value)
{
if ($value === NULL) {
return NULL;
}
if (!value instanceof \Chill\MainBundle\Export\FormatterInterface) {
throw new TransformationFailedException("The given value is not a "
. "Chill\MainBundle\Export\FormatterInterface");
}
// we do not have the alias, which is only known by the container.
// we try to check the formatter by the php internal object id.
$formatters = $this->exportManager
->getFormattersByTypes(array($value->getType()));
foreach($formatters as $alias => $formatter) {
if (spl_object_hash($formatter) === spl_object_hash($value)) {
return $alias;
}
}
throw new TransformationFailedException("The formatter could not be found "
. "by his object_hash. Maybe you created a formatter manually ? "
. "Use the export manager to get your formatter.");
}
/**
*
* @param type $value
* @return \Chill\MainBundle\Export\FormatterInterface
* @throws TransformationFailedException
*/
public function transform($value)
{
if (empty($value)) {
throw new TransformationFailedException("The formatter with empty "
. "alias is not allowed. Given value is ".$value);
}
return $this->exportManager->getFormatter($value);
}
}

View File

@@ -23,8 +23,7 @@ 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;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
/**
*
@@ -49,15 +48,14 @@ class AggregatorType extends AbstractType
$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']
))
)
->add('enabled', ChoiceType::class, array(
'choices' => array(
'enabled' => true,
'disabled' => false
),
'multiple' => false,
'expanded' => true,
'choices_as_values' => true
));
$filterFormBuilder = $builder->create('form', 'form', array(

View File

@@ -88,6 +88,10 @@ class ExportType extends AbstractType
$builder->add($aggregatorBuilder);
$builder->add('formatter', PickFormatterType::class, array(
'export_alias' => $options['export_alias']
));
}

View File

@@ -0,0 +1,59 @@
<?php
/*
* Copyright (C) 2016 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 FormatterType extends AbstractType
{
/**
*
* @var ExportManager
*/
protected $exportManager;
public function __construct(ExportManager $manager)
{
$this->exportManager = $manager;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(array('formatter_alias', 'export_alias',
'aggregator_aliases'));
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$formatter = $this->exportManager->getFormatter($options['formatter_alias']);
$formatter->buildForm($builder, $options['export_alias'],
$options['aggregator_aliases']);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*
* Copyright (C) 2016 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\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Form\Type\DataTransformer\AliasToFormatterTransformer;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class PickFormatterType extends AbstractType
{
protected $exportManager;
public function __construct(ExportManager $exportManager)
{
$this->exportManager = $exportManager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$export = $this->exportManager->getExport($options['export_alias']);
$allowedFormatters = $this->exportManager
->getFormattersByTypes($export->getAllowedFormattersTypes());
//$transformer = new AliasToFormatterTransformer($this->exportManager);
//build choices
$choices = array();
foreach($allowedFormatters as $alias => $formatter) {
$choices[$formatter->getName()] = $alias;
}
$builder->add('alias', 'choice', array(
'choices' => $choices,
'choices_as_values' => true,
'multiple' => false
));
//$builder->get('type')->addModelTransformer($transformer);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(array('export_alias'));
}
}