mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
handle DirectExport in controller and export manager
This commit is contained in:
parent
6741eb949c
commit
6ee7a834cb
@ -410,7 +410,7 @@ class ExportController extends Controller
|
||||
$dataFormatter = $this->session->get('formatter_step_raw', null);
|
||||
$dataExport = $this->session->get('export_step_raw', null);
|
||||
|
||||
if ($dataFormatter === NULL) {
|
||||
if ($dataFormatter === NULL and $export instanceof \Chill\MainBundle\Export\ExportInterface) {
|
||||
return $this->redirectToRoute('chill_main_export_new', array(
|
||||
'alias' => $alias, 'step' => $this->getNextStep('generate', $export, true)
|
||||
));
|
||||
@ -423,9 +423,9 @@ class ExportController extends Controller
|
||||
$this->session->remove('formatter_step');
|
||||
|
||||
$redirectParameters = array_merge(
|
||||
$dataFormatter,
|
||||
$dataExport,
|
||||
$dataCenters,
|
||||
$dataFormatter ?? [],
|
||||
$dataExport ?? [],
|
||||
$dataCenters ?? [],
|
||||
array('alias' => $alias)
|
||||
);
|
||||
unset($redirectParameters['_token']);
|
||||
@ -447,6 +447,7 @@ class ExportController extends Controller
|
||||
{
|
||||
/* @var $exportManager \Chill\MainBundle\Export\ExportManager */
|
||||
$exportManager = $this->exportManager;
|
||||
$export = $exportManager->getExport($alias);
|
||||
|
||||
$formCenters = $this->createCreateFormExport($alias, 'generate_centers');
|
||||
$formCenters->handleRequest($request);
|
||||
@ -456,13 +457,19 @@ class ExportController extends Controller
|
||||
$formExport->handleRequest($request);
|
||||
$dataExport = $formExport->getData();
|
||||
|
||||
$formFormatter = $this->createCreateFormExport($alias, 'generate_formatter',
|
||||
$dataExport);
|
||||
$formFormatter->handleRequest($request);
|
||||
$dataFormatter = $formFormatter->getData();
|
||||
if ($export instanceof \Chill\MainBundle\Export\ExportInterface) {
|
||||
$formFormatter = $this->createCreateFormExport($alias, 'generate_formatter',
|
||||
$dataExport);
|
||||
$formFormatter->handleRequest($request);
|
||||
$dataFormatter = $formFormatter->getData();
|
||||
}
|
||||
|
||||
$r = $exportManager->generate($alias, $dataCenters['centers'],
|
||||
$dataExport['export'], $dataFormatter['formatter']);
|
||||
$r = $exportManager->generate(
|
||||
$alias,
|
||||
$dataCenters['centers'],
|
||||
$dataExport['export'],
|
||||
isset($dataFormatter) ? $dataFormatter['formatter'] : []
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
@ -480,7 +487,11 @@ class ExportController extends Controller
|
||||
$dataExport = $formExport->getData();
|
||||
|
||||
$formatterAlias = $exportManager->getFormatterAlias($dataExport['export']);
|
||||
$formater = $exportManager->getFormatter($formatterAlias);
|
||||
if ($formatterAlias !== null) {
|
||||
$formater = $exportManager->getFormatter($formatterAlias);
|
||||
} else {
|
||||
$formater = null;
|
||||
}
|
||||
|
||||
$viewVariables = [
|
||||
'alias' => $alias
|
||||
|
@ -11,5 +11,5 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
*/
|
||||
interface DirectExportInterface extends ExportElementInterface
|
||||
{
|
||||
//put your code here
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -75,51 +75,55 @@ class ExportType extends AbstractType
|
||||
|
||||
$builder->add($exportBuilder, null, $exportOptions);
|
||||
|
||||
//add filters
|
||||
$filters = $this->exportManager->getFiltersApplyingOn($export, $options['picked_centers']);
|
||||
$filterBuilder = $builder->create(self::FILTER_KEY, FormType::class, array('compound' => true));
|
||||
if ($export instanceof \Chill\MainBundle\Export\ExportInterface) {
|
||||
//add filters
|
||||
$filters = $this->exportManager->getFiltersApplyingOn($export, $options['picked_centers']);
|
||||
$filterBuilder = $builder->create(self::FILTER_KEY, FormType::class, array('compound' => true));
|
||||
|
||||
foreach($filters as $alias => $filter) {
|
||||
$filterBuilder->add($alias, FilterType::class, array(
|
||||
'filter_alias' => $alias,
|
||||
'export_manager' => $this->exportManager,
|
||||
'label' => $filter->getTitle(),
|
||||
'constraints' => array(
|
||||
new ExportElementConstraint(['element' => $filter])
|
||||
)
|
||||
));
|
||||
foreach($filters as $alias => $filter) {
|
||||
$filterBuilder->add($alias, FilterType::class, array(
|
||||
'filter_alias' => $alias,
|
||||
'export_manager' => $this->exportManager,
|
||||
'label' => $filter->getTitle(),
|
||||
'constraints' => array(
|
||||
new ExportElementConstraint(['element' => $filter])
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
$builder->add($filterBuilder);
|
||||
|
||||
//add aggregators
|
||||
$aggregators = $this->exportManager
|
||||
->getAggregatorsApplyingOn($export, $options['picked_centers']);
|
||||
$aggregatorBuilder = $builder->create(self::AGGREGATOR_KEY, FormType::class,
|
||||
array('compound' => true));
|
||||
|
||||
foreach($aggregators as $alias => $aggregator) {
|
||||
$aggregatorBuilder->add($alias, AggregatorType::class, array(
|
||||
'aggregator_alias' => $alias,
|
||||
'export_manager' => $this->exportManager,
|
||||
'label' => $aggregator->getTitle(),
|
||||
'constraints' => array(
|
||||
new ExportElementConstraint(['element' => $aggregator])
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
$builder->add($aggregatorBuilder);
|
||||
}
|
||||
|
||||
$builder->add($filterBuilder);
|
||||
|
||||
//add aggregators
|
||||
$aggregators = $this->exportManager
|
||||
->getAggregatorsApplyingOn($export, $options['picked_centers']);
|
||||
$aggregatorBuilder = $builder->create(self::AGGREGATOR_KEY, FormType::class,
|
||||
array('compound' => true));
|
||||
|
||||
foreach($aggregators as $alias => $aggregator) {
|
||||
$aggregatorBuilder->add($alias, AggregatorType::class, array(
|
||||
'aggregator_alias' => $alias,
|
||||
'export_manager' => $this->exportManager,
|
||||
'label' => $aggregator->getTitle(),
|
||||
'constraints' => array(
|
||||
new ExportElementConstraint(['element' => $aggregator])
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
$builder->add($aggregatorBuilder);
|
||||
|
||||
// add export form
|
||||
$exportBuilder = $builder->create(self::EXPORT_KEY, FormType::class, array('compound' => true));
|
||||
$this->exportManager->getExport($options['export_alias'])
|
||||
->buildForm($exportBuilder);
|
||||
$builder->add($exportBuilder);
|
||||
|
||||
$builder->add(self::PICK_FORMATTER_KEY, PickFormatterType::class, array(
|
||||
'export_alias' => $options['export_alias']
|
||||
));
|
||||
if ($export instanceof \Chill\MainBundle\Export\ExportInterface) {
|
||||
$builder->add(self::PICK_FORMATTER_KEY, PickFormatterType::class, array(
|
||||
'export_alias' => $options['export_alias']
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -34,50 +34,54 @@
|
||||
|
||||
{{ form_start(form) }}
|
||||
|
||||
{% if form.children.export.children.filters is not empty%}
|
||||
<div style="clear:both; padding-top: 1.5em;">
|
||||
<h2>{{ 'Filters'| trans }}</h2>
|
||||
{% for filter_form in form.children.export.children.filters %}
|
||||
<div>
|
||||
<p>
|
||||
{{ form_widget(filter_form.enabled, { 'attr' : { 'style' : 'vertical-align: middle;', 'data-display-target': filter_form.vars.id } }) }}
|
||||
<span class="force-inline-label">{{ form_label(filter_form) }}</span>
|
||||
</p>
|
||||
|
||||
<div data-display-show-hide="{{ filter_form.vars.id }}">
|
||||
{{ form_widget(filter_form.form) }}
|
||||
{{ form_errors(filter_form) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{{ form_errors(form.children.export.children.filters) }}
|
||||
</div>
|
||||
{% else %}
|
||||
{# render the children, to mark the widget as 'rendered' #}
|
||||
{{ form_widget(form.children.export.children.filters) }}
|
||||
{% if form.children.export.children.filters is defined %}
|
||||
{% if form.children.export.children.filters is not empty%}
|
||||
<div style="clear:both; padding-top: 1.5em;">
|
||||
<h2>{{ 'Filters'| trans }}</h2>
|
||||
{% for filter_form in form.children.export.children.filters %}
|
||||
<div>
|
||||
<p>
|
||||
{{ form_widget(filter_form.enabled, { 'attr' : { 'style' : 'vertical-align: middle;', 'data-display-target': filter_form.vars.id } }) }}
|
||||
<span class="force-inline-label">{{ form_label(filter_form) }}</span>
|
||||
</p>
|
||||
|
||||
<div data-display-show-hide="{{ filter_form.vars.id }}">
|
||||
{{ form_widget(filter_form.form) }}
|
||||
{{ form_errors(filter_form) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{{ form_errors(form.children.export.children.filters) }}
|
||||
</div>
|
||||
{% else %}
|
||||
{# render the children, to mark the widget as 'rendered' #}
|
||||
{{ form_widget(form.children.export.children.filters) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if form.children.export.children.aggregators is not empty %}
|
||||
<div style="clear:both; padding-top: 1.5em;">
|
||||
<h2>{{ 'Aggregators'| trans }}</h2>
|
||||
{% for aggregator_form in form.children.export.children.aggregators %}
|
||||
<div>
|
||||
<p>
|
||||
{{ form_widget(aggregator_form.enabled, { 'attr' : { 'style' : 'vertical-align: middle;', 'data-display-target': aggregator_form.vars.id } }) }}
|
||||
<span class="force-inline-label">{{ form_label(aggregator_form) }}</span>
|
||||
</p>
|
||||
|
||||
<div data-display-show-hide="{{ aggregator_form.vars.id }}">
|
||||
{{ form_widget(aggregator_form.form) }}
|
||||
{{ form_errors(aggregator_form) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{# render the children, to mark the widget as 'rendered' #}
|
||||
{{ form_widget(form.children.export.children.aggregators) }}
|
||||
{% endif %}
|
||||
{% if form.children.export.children.aggregators is defined %}
|
||||
{% if form.children.export.children.aggregators is not empty %}
|
||||
<div style="clear:both; padding-top: 1.5em;">
|
||||
<h2>{{ 'Aggregators'| trans }}</h2>
|
||||
{% for aggregator_form in form.children.export.children.aggregators %}
|
||||
<div>
|
||||
<p>
|
||||
{{ form_widget(aggregator_form.enabled, { 'attr' : { 'style' : 'vertical-align: middle;', 'data-display-target': aggregator_form.vars.id } }) }}
|
||||
<span class="force-inline-label">{{ form_label(aggregator_form) }}</span>
|
||||
</p>
|
||||
|
||||
<div data-display-show-hide="{{ aggregator_form.vars.id }}">
|
||||
{{ form_widget(aggregator_form.form) }}
|
||||
{{ form_errors(aggregator_form) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{# render the children, to mark the widget as 'rendered' #}
|
||||
{{ form_widget(form.children.export.children.aggregators) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if form.children.export.children.export.children|length > 0 %}
|
||||
@ -90,13 +94,15 @@
|
||||
{{ form_widget(form.children.export.children.export) }}
|
||||
{% endif %}
|
||||
|
||||
<div style="clear: both; padding-top: 1.5em;">
|
||||
<h2>{{ 'Formatter'| trans }}</h2>
|
||||
|
||||
<p> {{ 'Choose the formatter'|trans }}</p>
|
||||
|
||||
{{ form_row(form.children.export.children.pick_formatter.children.alias, { 'label' : 'Formatter' }) }}
|
||||
</div>
|
||||
{% if form.children.export.children.pick_formatter is defined %}
|
||||
<div style="clear: both; padding-top: 1.5em;">
|
||||
<h2>{{ 'Formatter'| trans }}</h2>
|
||||
|
||||
<p> {{ 'Choose the formatter'|trans }}</p>
|
||||
|
||||
{{ form_row(form.children.export.children.pick_formatter.children.alias, { 'label' : 'Formatter' }) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<p>{{ form_widget(form.submit, { 'attr' : { 'class' : 'sc-button btn-create' }, 'label' : 'Go to formatter options' } ) }}</p>
|
||||
{{ form_end(form) }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user