mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +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);
|
$dataFormatter = $this->session->get('formatter_step_raw', null);
|
||||||
$dataExport = $this->session->get('export_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(
|
return $this->redirectToRoute('chill_main_export_new', array(
|
||||||
'alias' => $alias, 'step' => $this->getNextStep('generate', $export, true)
|
'alias' => $alias, 'step' => $this->getNextStep('generate', $export, true)
|
||||||
));
|
));
|
||||||
@ -423,9 +423,9 @@ class ExportController extends Controller
|
|||||||
$this->session->remove('formatter_step');
|
$this->session->remove('formatter_step');
|
||||||
|
|
||||||
$redirectParameters = array_merge(
|
$redirectParameters = array_merge(
|
||||||
$dataFormatter,
|
$dataFormatter ?? [],
|
||||||
$dataExport,
|
$dataExport ?? [],
|
||||||
$dataCenters,
|
$dataCenters ?? [],
|
||||||
array('alias' => $alias)
|
array('alias' => $alias)
|
||||||
);
|
);
|
||||||
unset($redirectParameters['_token']);
|
unset($redirectParameters['_token']);
|
||||||
@ -447,6 +447,7 @@ class ExportController extends Controller
|
|||||||
{
|
{
|
||||||
/* @var $exportManager \Chill\MainBundle\Export\ExportManager */
|
/* @var $exportManager \Chill\MainBundle\Export\ExportManager */
|
||||||
$exportManager = $this->exportManager;
|
$exportManager = $this->exportManager;
|
||||||
|
$export = $exportManager->getExport($alias);
|
||||||
|
|
||||||
$formCenters = $this->createCreateFormExport($alias, 'generate_centers');
|
$formCenters = $this->createCreateFormExport($alias, 'generate_centers');
|
||||||
$formCenters->handleRequest($request);
|
$formCenters->handleRequest($request);
|
||||||
@ -456,13 +457,19 @@ class ExportController extends Controller
|
|||||||
$formExport->handleRequest($request);
|
$formExport->handleRequest($request);
|
||||||
$dataExport = $formExport->getData();
|
$dataExport = $formExport->getData();
|
||||||
|
|
||||||
|
if ($export instanceof \Chill\MainBundle\Export\ExportInterface) {
|
||||||
$formFormatter = $this->createCreateFormExport($alias, 'generate_formatter',
|
$formFormatter = $this->createCreateFormExport($alias, 'generate_formatter',
|
||||||
$dataExport);
|
$dataExport);
|
||||||
$formFormatter->handleRequest($request);
|
$formFormatter->handleRequest($request);
|
||||||
$dataFormatter = $formFormatter->getData();
|
$dataFormatter = $formFormatter->getData();
|
||||||
|
}
|
||||||
|
|
||||||
$r = $exportManager->generate($alias, $dataCenters['centers'],
|
$r = $exportManager->generate(
|
||||||
$dataExport['export'], $dataFormatter['formatter']);
|
$alias,
|
||||||
|
$dataCenters['centers'],
|
||||||
|
$dataExport['export'],
|
||||||
|
isset($dataFormatter) ? $dataFormatter['formatter'] : []
|
||||||
|
);
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
@ -480,7 +487,11 @@ class ExportController extends Controller
|
|||||||
$dataExport = $formExport->getData();
|
$dataExport = $formExport->getData();
|
||||||
|
|
||||||
$formatterAlias = $exportManager->getFormatterAlias($dataExport['export']);
|
$formatterAlias = $exportManager->getFormatterAlias($dataExport['export']);
|
||||||
|
if ($formatterAlias !== null) {
|
||||||
$formater = $exportManager->getFormatter($formatterAlias);
|
$formater = $exportManager->getFormatter($formatterAlias);
|
||||||
|
} else {
|
||||||
|
$formater = null;
|
||||||
|
}
|
||||||
|
|
||||||
$viewVariables = [
|
$viewVariables = [
|
||||||
'alias' => $alias
|
'alias' => $alias
|
||||||
|
@ -11,5 +11,5 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
*/
|
*/
|
||||||
interface DirectExportInterface extends ExportElementInterface
|
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.
|
* center, false if the user hasn't access to element for at least one center.
|
||||||
*
|
*
|
||||||
* @param \Chill\MainBundle\Export\ExportElementInterface $element
|
* @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
|
* @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
|
* @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();
|
$role = $element->requiredRole();
|
||||||
} elseif ($element instanceof ModifierInterface ) {
|
} elseif ($element instanceof ModifierInterface ) {
|
||||||
if (is_null($element->addRole())) {
|
if (is_null($element->addRole())) {
|
||||||
@ -433,8 +434,10 @@ class ExportManager
|
|||||||
$centers = $this->getPickedCenters($pickedCentersData);
|
$centers = $this->getPickedCenters($pickedCentersData);
|
||||||
|
|
||||||
if ($export instanceof DirectExportInterface) {
|
if ($export instanceof DirectExportInterface) {
|
||||||
return $export->generate($this->buildCenterReachableScopes($centers, $export),
|
return $export->generate(
|
||||||
$data[ExportType::EXPORT_KEY]);
|
$this->buildCenterReachableScopes($centers, $export),
|
||||||
|
$data[ExportType::EXPORT_KEY]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $export->initiateQuery(
|
$query = $export->initiateQuery(
|
||||||
@ -571,6 +574,10 @@ class ExportManager
|
|||||||
*/
|
*/
|
||||||
private function retrieveUsedModifiers($data)
|
private function retrieveUsedModifiers($data)
|
||||||
{
|
{
|
||||||
|
if ($data === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$usedTypes = array_merge(
|
$usedTypes = array_merge(
|
||||||
$this->retrieveUsedFiltersType($data[ExportType::FILTER_KEY]),
|
$this->retrieveUsedFiltersType($data[ExportType::FILTER_KEY]),
|
||||||
$this->retrieveUsedAggregatorsType($data[ExportType::AGGREGATOR_KEY])
|
$this->retrieveUsedAggregatorsType($data[ExportType::AGGREGATOR_KEY])
|
||||||
@ -590,6 +597,10 @@ class ExportManager
|
|||||||
*/
|
*/
|
||||||
private function retrieveUsedFiltersType($data)
|
private function retrieveUsedFiltersType($data)
|
||||||
{
|
{
|
||||||
|
if ($data === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$usedTypes = array();
|
$usedTypes = array();
|
||||||
foreach($data as $alias => $filterData) {
|
foreach($data as $alias => $filterData) {
|
||||||
if ($filterData['enabled'] == true){
|
if ($filterData['enabled'] == true){
|
||||||
@ -610,6 +621,10 @@ class ExportManager
|
|||||||
*/
|
*/
|
||||||
private function retrieveUsedAggregatorsType($data)
|
private function retrieveUsedAggregatorsType($data)
|
||||||
{
|
{
|
||||||
|
if ($data === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$usedTypes = array();
|
$usedTypes = array();
|
||||||
foreach($this->retrieveUsedAggregators($data) as $alias => $aggregator) {
|
foreach($this->retrieveUsedAggregators($data) as $alias => $aggregator) {
|
||||||
if (!in_array($aggregator->applyOn(), $usedTypes)) {
|
if (!in_array($aggregator->applyOn(), $usedTypes)) {
|
||||||
@ -627,6 +642,10 @@ class ExportManager
|
|||||||
*/
|
*/
|
||||||
private function retrieveUsedAggregators($data)
|
private function retrieveUsedAggregators($data)
|
||||||
{
|
{
|
||||||
|
if ($data === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($data as $alias => $aggregatorData) {
|
foreach ($data as $alias => $aggregatorData) {
|
||||||
if ($aggregatorData['enabled'] === true){
|
if ($aggregatorData['enabled'] === true){
|
||||||
yield $alias => $this->getAggregator($alias);
|
yield $alias => $this->getAggregator($alias);
|
||||||
@ -640,6 +659,10 @@ class ExportManager
|
|||||||
*/
|
*/
|
||||||
private function retrieveUsedFilters($data)
|
private function retrieveUsedFilters($data)
|
||||||
{
|
{
|
||||||
|
if ($data === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($data as $alias => $filterData) {
|
foreach ($data as $alias => $filterData) {
|
||||||
if ($filterData['enabled'] === true) {
|
if ($filterData['enabled'] === true) {
|
||||||
yield $alias => $this->getFilter($alias);
|
yield $alias => $this->getFilter($alias);
|
||||||
|
@ -75,6 +75,7 @@ class ExportType extends AbstractType
|
|||||||
|
|
||||||
$builder->add($exportBuilder, null, $exportOptions);
|
$builder->add($exportBuilder, null, $exportOptions);
|
||||||
|
|
||||||
|
if ($export instanceof \Chill\MainBundle\Export\ExportInterface) {
|
||||||
//add filters
|
//add filters
|
||||||
$filters = $this->exportManager->getFiltersApplyingOn($export, $options['picked_centers']);
|
$filters = $this->exportManager->getFiltersApplyingOn($export, $options['picked_centers']);
|
||||||
$filterBuilder = $builder->create(self::FILTER_KEY, FormType::class, array('compound' => true));
|
$filterBuilder = $builder->create(self::FILTER_KEY, FormType::class, array('compound' => true));
|
||||||
@ -110,6 +111,7 @@ class ExportType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
$builder->add($aggregatorBuilder);
|
$builder->add($aggregatorBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
// add export form
|
// add export form
|
||||||
$exportBuilder = $builder->create(self::EXPORT_KEY, FormType::class, array('compound' => true));
|
$exportBuilder = $builder->create(self::EXPORT_KEY, FormType::class, array('compound' => true));
|
||||||
@ -117,9 +119,11 @@ class ExportType extends AbstractType
|
|||||||
->buildForm($exportBuilder);
|
->buildForm($exportBuilder);
|
||||||
$builder->add($exportBuilder);
|
$builder->add($exportBuilder);
|
||||||
|
|
||||||
|
if ($export instanceof \Chill\MainBundle\Export\ExportInterface) {
|
||||||
$builder->add(self::PICK_FORMATTER_KEY, PickFormatterType::class, array(
|
$builder->add(self::PICK_FORMATTER_KEY, PickFormatterType::class, array(
|
||||||
'export_alias' => $options['export_alias']
|
'export_alias' => $options['export_alias']
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
|
|
||||||
|
{% if form.children.export.children.filters is defined %}
|
||||||
{% if form.children.export.children.filters is not empty%}
|
{% if form.children.export.children.filters is not empty%}
|
||||||
<div style="clear:both; padding-top: 1.5em;">
|
<div style="clear:both; padding-top: 1.5em;">
|
||||||
<h2>{{ 'Filters'| trans }}</h2>
|
<h2>{{ 'Filters'| trans }}</h2>
|
||||||
@ -56,7 +57,9 @@
|
|||||||
{# render the children, to mark the widget as 'rendered' #}
|
{# render the children, to mark the widget as 'rendered' #}
|
||||||
{{ form_widget(form.children.export.children.filters) }}
|
{{ form_widget(form.children.export.children.filters) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if form.children.export.children.aggregators is defined %}
|
||||||
{% if form.children.export.children.aggregators is not empty %}
|
{% if form.children.export.children.aggregators is not empty %}
|
||||||
<div style="clear:both; padding-top: 1.5em;">
|
<div style="clear:both; padding-top: 1.5em;">
|
||||||
<h2>{{ 'Aggregators'| trans }}</h2>
|
<h2>{{ 'Aggregators'| trans }}</h2>
|
||||||
@ -78,6 +81,7 @@
|
|||||||
{# render the children, to mark the widget as 'rendered' #}
|
{# render the children, to mark the widget as 'rendered' #}
|
||||||
{{ form_widget(form.children.export.children.aggregators) }}
|
{{ form_widget(form.children.export.children.aggregators) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% if form.children.export.children.export.children|length > 0 %}
|
{% if form.children.export.children.export.children|length > 0 %}
|
||||||
@ -90,6 +94,7 @@
|
|||||||
{{ form_widget(form.children.export.children.export) }}
|
{{ form_widget(form.children.export.children.export) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if form.children.export.children.pick_formatter is defined %}
|
||||||
<div style="clear: both; padding-top: 1.5em;">
|
<div style="clear: both; padding-top: 1.5em;">
|
||||||
<h2>{{ 'Formatter'| trans }}</h2>
|
<h2>{{ 'Formatter'| trans }}</h2>
|
||||||
|
|
||||||
@ -97,6 +102,7 @@
|
|||||||
|
|
||||||
{{ form_row(form.children.export.children.pick_formatter.children.alias, { 'label' : 'Formatter' }) }}
|
{{ form_row(form.children.export.children.pick_formatter.children.alias, { 'label' : 'Formatter' }) }}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<p>{{ form_widget(form.submit, { 'attr' : { 'class' : 'sc-button btn-create' }, 'label' : 'Go to formatter options' } ) }}</p>
|
<p>{{ form_widget(form.submit, { 'attr' : { 'class' : 'sc-button btn-create' }, 'label' : 'Go to formatter options' } ) }}</p>
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user