Skip to content

Commit

Permalink
Merge pull request #1 from Pitoune/feat/symfony-3
Browse files Browse the repository at this point in the history
Make bundle works with symfony 3
  • Loading branch information
Pierre Ducoudray authored Jan 16, 2017
2 parents 7200e64 + e725de4 commit 08cd6c7
Show file tree
Hide file tree
Showing 35 changed files with 543 additions and 179 deletions.
7 changes: 4 additions & 3 deletions Controller/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ public function renderAction(Request $request)

$report = $this->findOr404($configuration);

$formType = $report->getDataFetcher();
$dataFetcher = $this->get($report->getDataFetcher());
$formType = $dataFetcher->getType();
$configurationForm = $this->container->get('form.factory')->createNamed(
'configuration',
$formType,
$report->getDataFetcherConfiguration()
);

if ($request->query->has('configuration')) {
$configurationForm->submit($request);
$configurationForm->submit($request->request->get($configurationForm->getName()));
}

return $this->container->get('templating')->renderResponse($configuration->getTemplate('show.html'), [
Expand Down Expand Up @@ -75,7 +76,7 @@ public function embedAction(Request $request, $report, array $configuration = []
}

$configuration = ($request->query->has('configuration')) ? $request->query->get('configuration', $configuration) : $report->getDataFetcherConfiguration();
$configuration['baseCurrency'] = $currencyProvider->getBaseCurrency();
$configuration['baseCurrency'] = $currencyProvider->getDefaultCurrencyCode();

$data = $this->getReportDataFetcher()->fetch($report, $configuration);

Expand Down
50 changes: 50 additions & 0 deletions DataFetcher/NumberOfOrdersDataFetcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\ReportBundle\DataFetcher;

use Sylius\Bundle\ReportBundle\Doctrine\ORM\OrderRepositoryInterface;
use Sylius\Bundle\ReportBundle\Form\Type\DataFetcher\NumberOfOrdersType;

/**
* @author Łukasz Chruściel <[email protected]>
*/
class NumberOfOrdersDataFetcher extends TimePeriod
{
/**
* @var OrderRepositoryInterface
*/
protected $orderRepository;

/**
* @param OrderRepositoryInterface $orderRepository
*/
public function __construct(OrderRepositoryInterface $orderRepository)
{
$this->orderRepository = $orderRepository;
}

/**
* {@inheritdoc}
*/
protected function getData(array $configuration = [])
{
return $this->orderRepository->ordersBetweenDatesGroupByDate($configuration);
}

/**
* {@inheritdoc}
*/
public function getType()
{
return NumberOfOrdersType::class;
}
}
50 changes: 50 additions & 0 deletions DataFetcher/SalesTotalDataFetcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\ReportBundle\DataFetcher;

use Sylius\Bundle\ReportBundle\Doctrine\ORM\OrderRepositoryInterface;
use Sylius\Bundle\ReportBundle\Form\Type\DataFetcher\SalesTotalType;

/**
* @author Łukasz Chruściel <[email protected]>
*/
class SalesTotalDataFetcher extends TimePeriod
{
/**
* @var OrderRepositoryInterface
*/
protected $orderRepository;

/**
* @param OrderRepositoryInterface $orderRepository
*/
public function __construct(OrderRepositoryInterface $orderRepository)
{
$this->orderRepository = $orderRepository;
}

/**
* {@inheritdoc}
*/
protected function getData(array $configuration = [])
{
return $this->orderRepository->revenueBetweenDatesGroupByDate($configuration);
}

/**
* {@inheritdoc}
*/
public function getType()
{
return SalesTotalType::class;
}
}
6 changes: 3 additions & 3 deletions DataFetcher/TimePeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ abstract class TimePeriod implements DataFetcherInterface
public static function getPeriodChoices()
{
return [
self::PERIOD_DAY => 'Daily',
self::PERIOD_MONTH => 'Monthly',
self::PERIOD_YEAR => 'Yearly',
'Daily' => self::PERIOD_DAY,
'Monthly' => self::PERIOD_MONTH,
'Yearly' => self::PERIOD_YEAR,
];
}

Expand Down
50 changes: 50 additions & 0 deletions DataFetcher/UserRegistrationDataFetcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\ReportBundle\DataFetcher;

use Sylius\Bundle\ReportBundle\Doctrine\ORM\UserRepositoryInterface;
use Sylius\Bundle\ReportBundle\Form\Type\DataFetcher\UserRegistrationType;

/**
* @author Łukasz Chruściel <[email protected]>
*/
class UserRegistrationDataFetcher extends TimePeriod
{
/**
* @var UserRepositoryInterface
*/
protected $userRepository;

/**
* @param UserRepositoryInterface $userRepository
*/
public function __construct(UserRepositoryInterface $userRepository)
{
$this->userRepository = $userRepository;
}

/**
* {@inheritdoc}
*/
protected function getData(array $configuration = [])
{
return $this->userRepository->getRegistrationStatistic($configuration);
}

/**
* {@inheritdoc}
*/
public function getType()
{
return UserRegistrationType::class;
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/RegisterDataFetcherPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function process(ContainerBuilder $container)
}

$name = $attributes[0]['fetcher'];
$dataFetchers[$name] = $attributes[0]['label'];
$dataFetchers[$attributes[0]['label']] = $name;

$registry->addMethodCall('register', [$name, new Reference($id)]);
}
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/RegisterRenderersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function process(ContainerBuilder $container)
}

$name = $attributes[0]['renderer'];
$renderers[$name] = $attributes[0]['label'];
$renderers[$attributes[0]['label']] = $name;
$registry->addMethodCall('register', [$name, new Reference($id)]);
}

Expand Down
7 changes: 1 addition & 6 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ private function addResourcesSection(ArrayNodeDefinition $node)
->scalarNode('controller')->defaultValue(ReportController::class)->cannotBeEmpty()->end()
->scalarNode('repository')->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue(Factory::class)->end()
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->scalarNode('default')->defaultValue(ReportType::class)->cannotBeEmpty()->end()
->end()
->end()
->scalarNode('form')->defaultValue(ReportType::class)->end()
->end()
->end()
->arrayNode('validation_groups')
Expand Down
20 changes: 20 additions & 0 deletions Doctrine/ORM/OrderRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Sylius\Bundle\ReportBundle\Doctrine\ORM;

interface OrderRepositoryInterface
{
/**
* @param array $configuration
*
* @return mixed
*/
public function revenueBetweenDatesGroupByDate(array $configuration = []);

/**
* @param array $configuration
*
* @return mixed
*/
public function ordersBetweenDatesGroupByDate(array $configuration = []);
}
13 changes: 13 additions & 0 deletions Doctrine/ORM/UserRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Sylius\Bundle\ReportBundle\Doctrine\ORM;

interface UserRepositoryInterface
{
/**
* @param array $configuration
*
* @return mixed
*/
public function getRegistrationStatistic(array $configuration = []);
}
55 changes: 55 additions & 0 deletions Form/Type/DataFetcher/DataFetcherChoiceType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\ReportBundle\Form\Type\DataFetcher;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Łukasz Chruściel <[email protected]>
*/
class DataFetcherChoiceType extends AbstractType
{
/**
* @var array
*/
protected $dataFetchers;

/**
* @param array $dataFetchers
*/
public function __construct($dataFetchers)
{
$this->dataFetchers = $dataFetchers;
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'choices' => $this->dataFetchers,
])
;
}

/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
}
49 changes: 49 additions & 0 deletions Form/Type/DataFetcher/NumberOfOrdersType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\ReportBundle\Form\Type\DataFetcher;

use Sylius\Bundle\ReportBundle\DataFetcher\NumberOfOrdersDataFetcher;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\FormBuilderInterface;

/**
* @author Łukasz Chruściel <[email protected]>
*/
class NumberOfOrdersType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('start', DateType::class, [
'label' => 'sylius.form.report.user_registration.start',
])
->add('end', DateType::class, [
'label' => 'sylius.form.report.user_registration.end',
])
->add('period', ChoiceType::class, [
'choices' => NumberOfOrdersDataFetcher::getPeriodChoices(),
'multiple' => false,
'label' => 'sylius.form.report.user_registration.period',
])
->add('empty_records', CheckboxType::class, [
'label' => 'sylius.form.report.user_registration.empty_records',
'required' => false,
])
;
}
}
Loading

0 comments on commit 08cd6c7

Please sign in to comment.