mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Extract Grid component & bundle
This commit is contained in:
parent
b007366bb0
commit
68a3e2e9b8
139 changed files with 2 additions and 10453 deletions
|
|
@ -54,6 +54,8 @@
|
|||
"swiftmailer/swiftmailer": "^6.0",
|
||||
"sylius-labs/association-hydrator": "^1.0",
|
||||
"sylius/fixtures-bundle": "~1.1.15",
|
||||
"sylius/grid": "~1.1.15",
|
||||
"sylius/grid-bundle": "~1.1.15",
|
||||
"sylius/mailer": "~1.1.15",
|
||||
"sylius/mailer-bundle": "~1.1.15",
|
||||
"sylius/registry": "~1.1.15",
|
||||
|
|
@ -118,8 +120,6 @@
|
|||
"sylius/currency-bundle": "self.version",
|
||||
"sylius/customer": "self.version",
|
||||
"sylius/customer-bundle": "self.version",
|
||||
"sylius/grid": "self.version",
|
||||
"sylius/grid-bundle": "self.version",
|
||||
"sylius/inventory": "self.version",
|
||||
"sylius/inventory-bundle": "self.version",
|
||||
"sylius/locale": "self.version",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ suites:
|
|||
Core: { namespace: Sylius\Component\Core, psr4_prefix: Sylius\Component\Core, spec_path: src/Sylius/Component/Core, src_path: src/Sylius/Component/Core }
|
||||
Currency: { namespace: Sylius\Component\Currency, psr4_prefix: Sylius\Component\Currency, spec_path: src/Sylius/Component/Currency, src_path: src/Sylius/Component/Currency }
|
||||
Customer: { namespace: Sylius\Component\Customer, psr4_prefix: Sylius\Component\Customer, spec_path: src/Sylius/Component/Customer, src_path: src/Sylius/Component/Customer }
|
||||
Grid: { namespace: Sylius\Component\Grid, psr4_prefix: Sylius\Component\Grid, spec_path: src/Sylius/Component/Grid, src_path: src/Sylius/Component/Grid }
|
||||
Inventory: { namespace: Sylius\Component\Inventory, psr4_prefix: Sylius\Component\Inventory, spec_path: src/Sylius/Component/Inventory, src_path: src/Sylius/Component/Inventory }
|
||||
Locale: { namespace: Sylius\Component\Locale, psr4_prefix: Sylius\Component\Locale, spec_path: src/Sylius/Component/Locale, src_path: src/Sylius/Component/Locale }
|
||||
Order: { namespace: Sylius\Component\Order, psr4_prefix: Sylius\Component\Order, spec_path: src/Sylius/Component/Order, src_path: src/Sylius/Component/Order }
|
||||
|
|
@ -27,7 +26,6 @@ suites:
|
|||
CoreBundle: { namespace: Sylius\Bundle\CoreBundle, psr4_prefix: Sylius\Bundle\CoreBundle, spec_path: src/Sylius/Bundle/CoreBundle, src_path: src/Sylius/Bundle/CoreBundle }
|
||||
CurrencyBundle: { namespace: Sylius\Bundle\CurrencyBundle, psr4_prefix: Sylius\Bundle\CurrencyBundle, spec_path: src/Sylius/Bundle/CurrencyBundle, src_path: src/Sylius/Bundle/CurrencyBundle }
|
||||
CustomerBundle: { namespace: Sylius\Bundle\CustomerBundle, psr4_prefix: Sylius\Bundle\CustomerBundle, spec_path: src/Sylius/Bundle/CustomerBundle, src_path: src/Sylius/Bundle/CustomerBundle }
|
||||
GridBundle: { namespace: Sylius\Bundle\GridBundle, psr4_prefix: Sylius\Bundle\GridBundle, spec_path: src/Sylius/Bundle/GridBundle, src_path: src/Sylius/Bundle/GridBundle }
|
||||
InventoryBundle: { namespace: Sylius\Bundle\InventoryBundle, psr4_prefix: Sylius\Bundle\InventoryBundle, spec_path: src/Sylius/Bundle/InventoryBundle, src_path: src/Sylius/Bundle/InventoryBundle }
|
||||
LocaleBundle: { namespace: Sylius\Bundle\LocaleBundle, psr4_prefix: Sylius\Bundle\LocaleBundle, spec_path: src/Sylius/Bundle/LocaleBundle, src_path: src/Sylius/Bundle/LocaleBundle }
|
||||
MoneyBundle: { namespace: Sylius\Bundle\MoneyBundle, psr4_prefix: Sylius\Bundle\MoneyBundle, spec_path: src/Sylius/Bundle/MoneyBundle, src_path: src/Sylius/Bundle/MoneyBundle }
|
||||
|
|
|
|||
8
src/Sylius/Bundle/GridBundle/.gitignore
vendored
8
src/Sylius/Bundle/GridBundle/.gitignore
vendored
|
|
@ -1,8 +0,0 @@
|
|||
vendor/
|
||||
bin/
|
||||
|
||||
composer.phar
|
||||
composer.lock
|
||||
|
||||
test/app/cache
|
||||
test/app/logs
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
final class RegisterDriversPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container): void
|
||||
{
|
||||
if (!$container->hasDefinition('sylius.registry.grid_driver')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$registry = $container->findDefinition('sylius.registry.grid_driver');
|
||||
|
||||
foreach ($container->findTaggedServiceIds('sylius.grid_driver') as $id => $attributes) {
|
||||
if (!isset($attributes[0]['alias'])) {
|
||||
throw new \InvalidArgumentException('Tagged grid drivers needs to have `alias` attribute.');
|
||||
}
|
||||
|
||||
$registry->addMethodCall('register', [$attributes[0]['alias'], new Reference($id)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
final class RegisterFieldTypesPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container): void
|
||||
{
|
||||
if (!$container->hasDefinition('sylius.registry.grid_field')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$registry = $container->getDefinition('sylius.registry.grid_field');
|
||||
|
||||
foreach ($container->findTaggedServiceIds('sylius.grid_field') as $id => $attributes) {
|
||||
if (!isset($attributes[0]['type'])) {
|
||||
throw new \InvalidArgumentException('Tagged grid fields needs to have `type` attribute.');
|
||||
}
|
||||
|
||||
$registry->addMethodCall('register', [$attributes[0]['type'], new Reference($id)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
final class RegisterFiltersPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container): void
|
||||
{
|
||||
if (!$container->hasDefinition('sylius.registry.grid_filter') || !$container->hasDefinition('sylius.form_registry.grid_filter')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$registry = $container->getDefinition('sylius.registry.grid_filter');
|
||||
$formTypeRegistry = $container->getDefinition('sylius.form_registry.grid_filter');
|
||||
|
||||
foreach ($container->findTaggedServiceIds('sylius.grid_filter') as $id => $attributes) {
|
||||
if (!isset($attributes[0]['type'], $attributes[0]['form_type'])) {
|
||||
throw new \InvalidArgumentException('Tagged grid filters needs to have `type` and `form_type` attributes.');
|
||||
}
|
||||
|
||||
$registry->addMethodCall('register', [$attributes[0]['type'], new Reference($id)]);
|
||||
$formTypeRegistry->addMethodCall('add', [$attributes[0]['type'], 'default', $attributes[0]['form_type']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\GridBundle\Doctrine\ORM\Driver as DoctrineORMDriver;
|
||||
use Sylius\Bundle\GridBundle\SyliusGridBundle;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
final class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder(): TreeBuilder
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('sylius_grid');
|
||||
|
||||
$this->addDriversSection($rootNode);
|
||||
$this->addTemplatesSection($rootNode);
|
||||
$this->addGridsSection($rootNode);
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayNodeDefinition $node
|
||||
*/
|
||||
private function addDriversSection(ArrayNodeDefinition $node): void
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->arrayNode('drivers')
|
||||
->defaultValue([SyliusGridBundle::DRIVER_DOCTRINE_ORM])
|
||||
->enumPrototype()->values(SyliusGridBundle::getAvailableDrivers())->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayNodeDefinition $node
|
||||
*/
|
||||
private function addTemplatesSection(ArrayNodeDefinition $node): void
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->arrayNode('templates')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->arrayNode('filter')
|
||||
->useAttributeAsKey('name')
|
||||
->scalarPrototype()->end()
|
||||
->end()
|
||||
->arrayNode('action')
|
||||
->useAttributeAsKey('name')
|
||||
->scalarPrototype()->end()
|
||||
->end()
|
||||
->arrayNode('bulk_action')
|
||||
->useAttributeAsKey('name')
|
||||
->scalarPrototype()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayNodeDefinition $node
|
||||
*/
|
||||
private function addGridsSection(ArrayNodeDefinition $node): void
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->arrayNode('grids')
|
||||
->useAttributeAsKey('code')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('extends')->cannotBeEmpty()->end()
|
||||
->arrayNode('driver')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('name')->cannotBeEmpty()->defaultValue(DoctrineORMDriver::NAME)->end()
|
||||
->arrayNode('options')
|
||||
->performNoDeepMerging()
|
||||
->variablePrototype()->end()
|
||||
->defaultValue([])
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('sorting')
|
||||
->performNoDeepMerging()
|
||||
->useAttributeAsKey('name')
|
||||
->enumPrototype()->values(['asc', 'desc'])->cannotBeEmpty()->end()
|
||||
->end()
|
||||
->arrayNode('limits')
|
||||
->performNoDeepMerging()
|
||||
->integerPrototype()->end()
|
||||
->defaultValue([10, 25, 50])
|
||||
->end()
|
||||
->arrayNode('fields')
|
||||
->useAttributeAsKey('name')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
|
||||
->scalarNode('label')->cannotBeEmpty()->end()
|
||||
->scalarNode('path')->cannotBeEmpty()->end()
|
||||
->scalarNode('sortable')->end()
|
||||
->scalarNode('enabled')->defaultTrue()->end()
|
||||
->scalarNode('position')->defaultValue(100)->end()
|
||||
->arrayNode('options')
|
||||
->performNoDeepMerging()
|
||||
->variablePrototype()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('filters')
|
||||
->useAttributeAsKey('name')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
|
||||
->scalarNode('label')->cannotBeEmpty()->end()
|
||||
->scalarNode('enabled')->defaultTrue()->end()
|
||||
->scalarNode('template')->end()
|
||||
->scalarNode('position')->defaultValue(100)->end()
|
||||
->arrayNode('options')
|
||||
->performNoDeepMerging()
|
||||
->variablePrototype()->end()
|
||||
->end()
|
||||
->arrayNode('form_options')
|
||||
->performNoDeepMerging()
|
||||
->variablePrototype()->end()
|
||||
->end()
|
||||
->variableNode('default_value')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('actions')
|
||||
->useAttributeAsKey('name')
|
||||
->arrayPrototype()
|
||||
->useAttributeAsKey('name')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('type')->isRequired()->end()
|
||||
->scalarNode('label')->end()
|
||||
->scalarNode('enabled')->defaultTrue()->end()
|
||||
->scalarNode('icon')->end()
|
||||
->scalarNode('position')->defaultValue(100)->end()
|
||||
->arrayNode('options')
|
||||
->performNoDeepMerging()
|
||||
->variablePrototype()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
final class SyliusGridExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container): void
|
||||
{
|
||||
$config = $this->processConfiguration($this->getConfiguration([], $container), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
|
||||
|
||||
$loader->load('services.xml');
|
||||
|
||||
$container->setParameter('sylius.grid.templates.action', $config['templates']['action']);
|
||||
$container->setParameter('sylius.grid.templates.bulk_action', $config['templates']['bulk_action']);
|
||||
$container->setParameter('sylius.grid.templates.filter', $config['templates']['filter']);
|
||||
$container->setParameter('sylius.grids_definitions', $config['grids']);
|
||||
|
||||
$container->setAlias('sylius.grid.renderer', 'sylius.grid.renderer.twig');
|
||||
$container->setAlias('sylius.grid.bulk_action_renderer', 'sylius.grid.bulk_action_renderer.twig');
|
||||
$container->setAlias('sylius.grid.data_extractor', 'sylius.grid.data_extractor.property_access');
|
||||
|
||||
foreach ($config['drivers'] as $enabledDriver) {
|
||||
$loader->load(sprintf('services/integrations/%s.xml', $enabledDriver));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\DBAL;
|
||||
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Pagerfanta\Adapter\DoctrineDbalAdapter;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Data\ExpressionBuilderInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
final class DataSource implements DataSourceInterface
|
||||
{
|
||||
/**
|
||||
* @var QueryBuilder
|
||||
*/
|
||||
private $queryBuilder;
|
||||
|
||||
/**
|
||||
* @var ExpressionBuilderInterface
|
||||
*/
|
||||
private $expressionBuilder;
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder
|
||||
*/
|
||||
public function __construct(QueryBuilder $queryBuilder)
|
||||
{
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
$this->expressionBuilder = new ExpressionBuilder($queryBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function restrict($expression, string $condition = DataSourceInterface::CONDITION_AND): void
|
||||
{
|
||||
switch ($condition) {
|
||||
case DataSourceInterface::CONDITION_AND:
|
||||
$this->queryBuilder->andWhere($expression);
|
||||
|
||||
break;
|
||||
case DataSourceInterface::CONDITION_OR:
|
||||
$this->queryBuilder->orWhere($expression);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getExpressionBuilder(): ExpressionBuilderInterface
|
||||
{
|
||||
return $this->expressionBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData(Parameters $parameters)
|
||||
{
|
||||
$countQueryBuilderModifier = function ($queryBuilder) {
|
||||
$queryBuilder
|
||||
->select('COUNT(DISTINCT o.id) AS total_results')
|
||||
->setMaxResults(1)
|
||||
;
|
||||
};
|
||||
|
||||
$paginator = new Pagerfanta(new DoctrineDbalAdapter($this->queryBuilder, $countQueryBuilderModifier));
|
||||
$paginator->setNormalizeOutOfRangePages(true);
|
||||
$paginator->setCurrentPage($parameters->get('page', 1));
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\DBAL;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Data\DriverInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
final class Driver implements DriverInterface
|
||||
{
|
||||
public const NAME = 'doctrine/dbal';
|
||||
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @param Connection $connection
|
||||
*/
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDataSource(array $configuration, Parameters $parameters): DataSourceInterface
|
||||
{
|
||||
if (!array_key_exists('table', $configuration)) {
|
||||
throw new \InvalidArgumentException('"table" must be configured.');
|
||||
}
|
||||
|
||||
$queryBuilder = $this->connection->createQueryBuilder();
|
||||
$queryBuilder
|
||||
->select('o.*')
|
||||
->from($configuration['table'], 'o')
|
||||
;
|
||||
|
||||
foreach ($configuration['aliases'] as $column => $alias) {
|
||||
$queryBuilder->addSelect(sprintf('o.%s as %s', $column, $alias));
|
||||
}
|
||||
|
||||
return new DataSource($queryBuilder);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,173 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\DBAL;
|
||||
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Sylius\Component\Grid\Data\ExpressionBuilderInterface;
|
||||
|
||||
final class ExpressionBuilder implements ExpressionBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var QueryBuilder
|
||||
*/
|
||||
private $queryBuilder;
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder
|
||||
*/
|
||||
public function __construct(QueryBuilder $queryBuilder)
|
||||
{
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function andX(...$expressions)
|
||||
{
|
||||
return $this->queryBuilder->expr()->andX(...$expressions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function orX(...$expressions)
|
||||
{
|
||||
return $this->queryBuilder->expr()->orX(...$expressions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function comparison(string $field, string $operator, $value)
|
||||
{
|
||||
return $this->queryBuilder->expr()->comparison($field, $operator, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function equals(string $field, $value)
|
||||
{
|
||||
$this->queryBuilder->setParameter($field, $value);
|
||||
|
||||
return $this->queryBuilder->expr()->eq($field, ':' . $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notEquals(string $field, $value)
|
||||
{
|
||||
$this->queryBuilder->setParameter($field, $value);
|
||||
|
||||
return $this->queryBuilder->expr()->neq($field, ':' . $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lessThan(string $field, $value)
|
||||
{
|
||||
$this->queryBuilder->andWhere($field . ' < :' . $field)->setParameter($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lessThanOrEqual(string $field, $value)
|
||||
{
|
||||
$this->queryBuilder->andWhere($field . ' =< :' . $field)->setParameter($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function greaterThan(string $field, $value)
|
||||
{
|
||||
$this->queryBuilder->andWhere($field . ' > :' . $field)->setParameter($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function greaterThanOrEqual(string $field, $value)
|
||||
{
|
||||
$this->queryBuilder->andWhere($field . ' => :%s' . $field)->setParameter($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function in(string $field, array $values)
|
||||
{
|
||||
return $this->queryBuilder->expr()->in($field, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notIn(string $field, array $values)
|
||||
{
|
||||
return $this->queryBuilder->expr()->notIn($field, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNull(string $field)
|
||||
{
|
||||
return $this->queryBuilder->expr()->isNull($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNotNull(string $field)
|
||||
{
|
||||
return $this->queryBuilder->expr()->isNotNull($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function like(string $field, string $pattern)
|
||||
{
|
||||
return $this->queryBuilder->expr()->like($field, $this->queryBuilder->expr()->literal($pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notLike(string $field, string $pattern)
|
||||
{
|
||||
return $this->queryBuilder->expr()->notLike($field, $this->queryBuilder->expr()->literal($pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function orderBy(string $field, string $direction)
|
||||
{
|
||||
return $this->queryBuilder->orderBy($field, $direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addOrderBy(string $field, string $direction)
|
||||
{
|
||||
return $this->queryBuilder->addOrderBy($field, $direction);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\ORM;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Data\ExpressionBuilderInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
final class DataSource implements DataSourceInterface
|
||||
{
|
||||
/**
|
||||
* @var QueryBuilder
|
||||
*/
|
||||
private $queryBuilder;
|
||||
|
||||
/**
|
||||
* @var ExpressionBuilderInterface
|
||||
*/
|
||||
private $expressionBuilder;
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder
|
||||
*/
|
||||
public function __construct(QueryBuilder $queryBuilder)
|
||||
{
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
$this->expressionBuilder = new ExpressionBuilder($queryBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function restrict($expression, string $condition = DataSourceInterface::CONDITION_AND): void
|
||||
{
|
||||
switch ($condition) {
|
||||
case DataSourceInterface::CONDITION_AND:
|
||||
$this->queryBuilder->andWhere($expression);
|
||||
|
||||
break;
|
||||
case DataSourceInterface::CONDITION_OR:
|
||||
$this->queryBuilder->orWhere($expression);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getExpressionBuilder(): ExpressionBuilderInterface
|
||||
{
|
||||
return $this->expressionBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData(Parameters $parameters)
|
||||
{
|
||||
// Use output walkers option in DoctrineORMAdapter should be false as it affects performance greatly. (see #3775)
|
||||
$paginator = new Pagerfanta(new DoctrineORMAdapter($this->queryBuilder, false, false));
|
||||
$paginator->setNormalizeOutOfRangePages(true);
|
||||
$paginator->setCurrentPage($parameters->get('page', 1));
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\ORM;
|
||||
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Data\DriverInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
final class Driver implements DriverInterface
|
||||
{
|
||||
public const NAME = 'doctrine/orm';
|
||||
|
||||
/**
|
||||
* @var ManagerRegistry
|
||||
*/
|
||||
private $managerRegistry;
|
||||
|
||||
/**
|
||||
* @param ManagerRegistry $managerRegistry
|
||||
*/
|
||||
public function __construct(ManagerRegistry $managerRegistry)
|
||||
{
|
||||
$this->managerRegistry = $managerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDataSource(array $configuration, Parameters $parameters): DataSourceInterface
|
||||
{
|
||||
if (!array_key_exists('class', $configuration)) {
|
||||
throw new \InvalidArgumentException('"class" must be configured.');
|
||||
}
|
||||
|
||||
$repository = $this->managerRegistry
|
||||
->getManagerForClass($configuration['class'])
|
||||
->getRepository($configuration['class']);
|
||||
|
||||
if (isset($configuration['repository']['method'])) {
|
||||
$method = $configuration['repository']['method'];
|
||||
$arguments = isset($configuration['repository']['arguments']) ? array_values($configuration['repository']['arguments']) : [];
|
||||
|
||||
$queryBuilder = $repository->$method(...$arguments);
|
||||
} else {
|
||||
$queryBuilder = $repository->createQueryBuilder('o');
|
||||
}
|
||||
|
||||
return new DataSource($queryBuilder);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,229 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\ORM;
|
||||
|
||||
use Doctrine\ORM\Query\Expr\Comparison;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Sylius\Component\Grid\Data\ExpressionBuilderInterface;
|
||||
|
||||
final class ExpressionBuilder implements ExpressionBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var QueryBuilder
|
||||
*/
|
||||
private $queryBuilder;
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder
|
||||
*/
|
||||
public function __construct(QueryBuilder $queryBuilder)
|
||||
{
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function andX(...$expressions)
|
||||
{
|
||||
return $this->queryBuilder->expr()->andX(...$expressions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function orX(...$expressions)
|
||||
{
|
||||
return $this->queryBuilder->expr()->orX(...$expressions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function comparison(string $field, string $operator, $value)
|
||||
{
|
||||
return new Comparison($field, $operator, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function equals(string $field, $value)
|
||||
{
|
||||
$parameterName = $this->getParameterName($field);
|
||||
$this->queryBuilder->setParameter($parameterName, $value);
|
||||
|
||||
return $this->queryBuilder->expr()->eq($this->getFieldName($field), ':' . $parameterName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notEquals(string $field, $value)
|
||||
{
|
||||
$parameterName = $this->getParameterName($field);
|
||||
$this->queryBuilder->setParameter($parameterName, $value);
|
||||
|
||||
return $this->queryBuilder->expr()->neq($this->getFieldName($field), ':' . $parameterName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lessThan(string $field, $value)
|
||||
{
|
||||
$parameterName = $this->getParameterName($field);
|
||||
$this->queryBuilder->setParameter($parameterName, $value);
|
||||
|
||||
return $this->queryBuilder->expr()->lt($this->getFieldName($field), ':' . $parameterName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lessThanOrEqual(string $field, $value)
|
||||
{
|
||||
$parameterName = $this->getParameterName($field);
|
||||
$this->queryBuilder->setParameter($parameterName, $value);
|
||||
|
||||
return $this->queryBuilder->expr()->lte($this->getFieldName($field), ':' . $parameterName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function greaterThan(string $field, $value)
|
||||
{
|
||||
$parameterName = $this->getParameterName($field);
|
||||
$this->queryBuilder->setParameter($parameterName, $value);
|
||||
|
||||
return $this->queryBuilder->expr()->gt($this->getFieldName($field), ':' . $parameterName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function greaterThanOrEqual(string $field, $value)
|
||||
{
|
||||
$parameterName = $this->getParameterName($field);
|
||||
$this->queryBuilder->setParameter($parameterName, $value);
|
||||
|
||||
return $this->queryBuilder->expr()->gte($this->getFieldName($field), ':' . $parameterName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function in(string $field, array $values)
|
||||
{
|
||||
return $this->queryBuilder->expr()->in($this->getFieldName($field), $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notIn(string $field, array $values)
|
||||
{
|
||||
return $this->queryBuilder->expr()->notIn($this->getFieldName($field), $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNull(string $field)
|
||||
{
|
||||
return $this->queryBuilder->expr()->isNull($this->getFieldName($field));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNotNull(string $field)
|
||||
{
|
||||
return $this->queryBuilder->expr()->isNotNull($this->getFieldName($field));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function like(string $field, string $pattern)
|
||||
{
|
||||
return $this->queryBuilder->expr()->like($this->getFieldName($field), $this->queryBuilder->expr()->literal($pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notLike(string $field, string $pattern)
|
||||
{
|
||||
return $this->queryBuilder->expr()->notLike($this->getFieldName($field), $this->queryBuilder->expr()->literal($pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function orderBy(string $field, string $direction)
|
||||
{
|
||||
return $this->queryBuilder->orderBy($this->getFieldName($field), $direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addOrderBy(string $field, string $direction)
|
||||
{
|
||||
return $this->queryBuilder->addOrderBy($this->getFieldName($field), $direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFieldName(string $field): string
|
||||
{
|
||||
if (false === strpos($field, '.')) {
|
||||
return $this->queryBuilder->getRootAlias() . '.' . $field;
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getParameterName(string $field): string
|
||||
{
|
||||
$parameterName = str_replace('.', '_', $field);
|
||||
|
||||
$i = 1;
|
||||
while ($this->hasParameterName($parameterName)) {
|
||||
$parameterName .= $i;
|
||||
}
|
||||
|
||||
return $parameterName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $parameterName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasParameterName(string $parameterName): bool
|
||||
{
|
||||
return null !== $this->queryBuilder->getParameter($parameterName);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
|
||||
|
||||
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
|
||||
use Pagerfanta\Adapter\DoctrineODMPhpcrAdapter;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Data\ExpressionBuilderInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
final class DataSource implements DataSourceInterface
|
||||
{
|
||||
/**
|
||||
* @var QueryBuilder
|
||||
*/
|
||||
private $queryBuilder;
|
||||
|
||||
/**
|
||||
* @var ExpressionBuilderInterface
|
||||
*/
|
||||
private $expressionBuilder;
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder
|
||||
* @param ExpressionBuilderInterface|null $expressionBuilder
|
||||
*/
|
||||
public function __construct(QueryBuilder $queryBuilder, ?ExpressionBuilderInterface $expressionBuilder = null)
|
||||
{
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
$this->expressionBuilder = $expressionBuilder ?: new ExpressionBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function restrict($expression, string $condition = DataSourceInterface::CONDITION_AND): void
|
||||
{
|
||||
switch ($condition) {
|
||||
case DataSourceInterface::CONDITION_AND:
|
||||
$parentNode = $this->queryBuilder->andWhere();
|
||||
|
||||
break;
|
||||
case DataSourceInterface::CONDITION_OR:
|
||||
$parentNode = $this->queryBuilder->orWhere();
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Unknown restrict condition "%s"',
|
||||
$condition
|
||||
));
|
||||
}
|
||||
|
||||
$visitor = new ExpressionVisitor($this->queryBuilder);
|
||||
$visitor->dispatch($expression, $parentNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getExpressionBuilder(): ExpressionBuilderInterface
|
||||
{
|
||||
return $this->expressionBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData(Parameters $parameters)
|
||||
{
|
||||
$orderBy = $this->queryBuilder->orderBy();
|
||||
foreach ($this->expressionBuilder->getOrderBys() as $field => $direction) {
|
||||
if (is_int($field)) {
|
||||
$field = $direction;
|
||||
$direction = 'asc';
|
||||
}
|
||||
|
||||
// todo: validate direction?
|
||||
$direction = strtolower($direction);
|
||||
$orderBy->{$direction}()->field(sprintf('%s.%s', Driver::QB_SOURCE_ALIAS, $field));
|
||||
}
|
||||
|
||||
$paginator = new Pagerfanta(new DoctrineODMPhpcrAdapter($this->queryBuilder));
|
||||
$paginator->setCurrentPage($parameters->get('page', 1));
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
|
||||
|
||||
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Data\DriverInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
final class Driver implements DriverInterface
|
||||
{
|
||||
/**
|
||||
* Driver name
|
||||
*/
|
||||
public const NAME = 'doctrine/phpcr-odm';
|
||||
|
||||
/**
|
||||
* Alias to use to reference fields from the data source class.
|
||||
*/
|
||||
public const QB_SOURCE_ALIAS = 'o';
|
||||
|
||||
/**
|
||||
* @var DocumentManagerInterface
|
||||
*/
|
||||
private $documentManager;
|
||||
|
||||
/**
|
||||
* @param DocumentManagerInterface $documentManager
|
||||
*/
|
||||
public function __construct(DocumentManagerInterface $documentManager)
|
||||
{
|
||||
$this->documentManager = $documentManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDataSource(array $configuration, Parameters $parameters): DataSourceInterface
|
||||
{
|
||||
if (!array_key_exists('class', $configuration)) {
|
||||
throw new \InvalidArgumentException('"class" must be configured.');
|
||||
}
|
||||
|
||||
$repository = $this->documentManager->getRepository($configuration['class']);
|
||||
$queryBuilder = $repository->createQueryBuilder(self::QB_SOURCE_ALIAS);
|
||||
|
||||
return new DataSource($queryBuilder);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,186 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
|
||||
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use Doctrine\Common\Collections\ExpressionBuilder as CollectionsExpressionBuilder;
|
||||
|
||||
/**
|
||||
* Creates an object graph (using Doctrine\Commons\Collections\Expr\*) which we
|
||||
* can then walk in order to build up the PHPCR-ODM query builder.
|
||||
*/
|
||||
final class ExpressionBuilder implements ExpressionBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var CollectionsExpressionBuilder
|
||||
*/
|
||||
private $expressionBuilder;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $orderBys = [];
|
||||
|
||||
/**
|
||||
* @param CollectionsExpressionBuilder|null $expressionBuilder
|
||||
*/
|
||||
public function __construct(CollectionsExpressionBuilder $expressionBuilder = null)
|
||||
{
|
||||
$this->expressionBuilder = $expressionBuilder ?: new CollectionsExpressionBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function andX(...$expressions)
|
||||
{
|
||||
return $this->expressionBuilder->andX(...$expressions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function orX(...$expressions)
|
||||
{
|
||||
return $this->expressionBuilder->orX(...$expressions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function comparison(string $field, string $operator, $value)
|
||||
{
|
||||
return new Comparison($field, $operator, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function equals(string $field, $value)
|
||||
{
|
||||
return $this->expressionBuilder->eq($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notEquals(string $field, $value)
|
||||
{
|
||||
return $this->expressionBuilder->neq($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lessThan(string $field, $value)
|
||||
{
|
||||
return $this->expressionBuilder->lt($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lessThanOrEqual(string $field, $value)
|
||||
{
|
||||
return $this->expressionBuilder->lte($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function greaterThan(string $field, $value)
|
||||
{
|
||||
return $this->expressionBuilder->gt($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function greaterThanOrEqual(string $field, $value)
|
||||
{
|
||||
return $this->expressionBuilder->gte($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function in(string $field, array $values)
|
||||
{
|
||||
return $this->expressionBuilder->in($field, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notIn(string $field, array $values)
|
||||
{
|
||||
return $this->expressionBuilder->notIn($field, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNull(string $field)
|
||||
{
|
||||
return new Comparison($field, ExtraComparison::IS_NULL, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNotNull(string $field)
|
||||
{
|
||||
return new Comparison($field, ExtraComparison::IS_NOT_NULL, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function like(string $field, string $pattern)
|
||||
{
|
||||
return $this->expressionBuilder->contains($field, $pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notLike(string $field, string $pattern)
|
||||
{
|
||||
return new Comparison($field, ExtraComparison::NOT_CONTAINS, $pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function orderBy(string $field, string $direction)
|
||||
{
|
||||
$this->orderBys = [$field => $direction];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addOrderBy(string $field, string $direction)
|
||||
{
|
||||
$this->orderBys[$field] = $direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderBys(): array
|
||||
{
|
||||
return $this->orderBys;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
|
||||
|
||||
use Sylius\Component\Grid\Data\ExpressionBuilderInterface as BaseExpressionBuilderInterface;
|
||||
|
||||
interface ExpressionBuilderInterface extends BaseExpressionBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderBys(): array;
|
||||
}
|
||||
|
|
@ -1,188 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
|
||||
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use Doctrine\Common\Collections\Expr\CompositeExpression;
|
||||
use Doctrine\Common\Collections\Expr\Expression;
|
||||
use Doctrine\ODM\PHPCR\Query\Builder\AbstractNode;
|
||||
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
|
||||
|
||||
/**
|
||||
* Walks a Doctrine\Commons\Expr object graph and builds up a PHPCR-ODM
|
||||
* query using the (fluent) PHPCR-ODM query builder.
|
||||
*/
|
||||
final class ExpressionVisitor
|
||||
{
|
||||
private $queryBuilder;
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $queryBuilder
|
||||
*/
|
||||
public function __construct(QueryBuilder $queryBuilder)
|
||||
{
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Comparison $comparison
|
||||
* @param AbstractNode $parentNode
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function walkComparison(Comparison $comparison, AbstractNode $parentNode)
|
||||
{
|
||||
$field = $comparison->getField();
|
||||
$value = $comparison->getValue()->getValue(); // shortcut for walkValue()
|
||||
|
||||
switch ($comparison->getOperator()) {
|
||||
case Comparison::EQ:
|
||||
return $parentNode->eq()->field($this->getField($field))->literal($value)->end();
|
||||
case Comparison::NEQ:
|
||||
return $parentNode->neq()->field($this->getField($field))->literal($value)->end();
|
||||
case Comparison::LT:
|
||||
return $parentNode->lt()->field($this->getField($field))->literal($value)->end();
|
||||
case Comparison::LTE:
|
||||
return $parentNode->lte()->field($this->getField($field))->literal($value)->end();
|
||||
case Comparison::GT:
|
||||
return $parentNode->gt()->field($this->getField($field))->literal($value)->end();
|
||||
case Comparison::GTE:
|
||||
return $parentNode->gte()->field($this->getField($field))->literal($value)->end();
|
||||
case Comparison::IN:
|
||||
return $this->getInConstraint($parentNode, $field, $value);
|
||||
case Comparison::NIN:
|
||||
$node = $parentNode->not();
|
||||
$this->getInConstraint($node, $field, $value);
|
||||
|
||||
return $node->end();
|
||||
case Comparison::CONTAINS:
|
||||
return $parentNode->like()->field($this->getField($field))->literal($value)->end();
|
||||
case ExtraComparison::NOT_CONTAINS:
|
||||
return $parentNode->not()->like()->field($this->getField($field))->literal($value)->end()->end();
|
||||
case ExtraComparison::IS_NULL:
|
||||
return $parentNode->not()->fieldIsset($this->getField($field))->end();
|
||||
case ExtraComparison::IS_NOT_NULL:
|
||||
return $parentNode->fieldIsset($this->getField($field));
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Unknown comparison operator: ' . $comparison->getOperator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompositeExpression $expr
|
||||
* @param AbstractNode $parentNode
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function walkCompositeExpression(CompositeExpression $expr, AbstractNode $parentNode)
|
||||
{
|
||||
switch ($expr->getType()) {
|
||||
case CompositeExpression::TYPE_AND:
|
||||
$node = $parentNode->andX();
|
||||
|
||||
break;
|
||||
case CompositeExpression::TYPE_OR:
|
||||
$node = $parentNode->orX();
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException('Unknown composite: ' . $expr->getType());
|
||||
}
|
||||
|
||||
$expressions = $expr->getExpressionList();
|
||||
|
||||
$leftExpression = array_shift($expressions);
|
||||
$this->dispatch($leftExpression, $node);
|
||||
|
||||
$parentNode = $node;
|
||||
foreach ($expressions as $index => $expression) {
|
||||
if (count($expressions) === $index + 1) {
|
||||
$this->dispatch($expression, $parentNode);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($expr->getType()) {
|
||||
case CompositeExpression::TYPE_AND:
|
||||
$parentNode = $parentNode->andX();
|
||||
|
||||
break;
|
||||
case CompositeExpression::TYPE_OR:
|
||||
$parentNode = $parentNode->orX();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$this->dispatch($expression, $parentNode);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk the given expression to build up the PHPCR-ODM query builder.
|
||||
*
|
||||
* @param Expression $expr
|
||||
* @param AbstractNode|null $parentNode
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function dispatch(Expression $expr, ?AbstractNode $parentNode = null)
|
||||
{
|
||||
if ($parentNode === null) {
|
||||
$parentNode = $this->queryBuilder->where();
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case $expr instanceof Comparison:
|
||||
return $this->walkComparison($expr, $parentNode);
|
||||
case $expr instanceof CompositeExpression:
|
||||
return $this->walkCompositeExpression($expr, $parentNode);
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Unknown Expression: ' . get_class($expr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getField(string $field): string
|
||||
{
|
||||
return Driver::QB_SOURCE_ALIAS . '.' . $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractNode $parentNode
|
||||
* @param string $field
|
||||
* @param array $values
|
||||
*/
|
||||
private function getInConstraint(AbstractNode $parentNode, string $field, array $values): void
|
||||
{
|
||||
$orNode = $parentNode->orx();
|
||||
|
||||
foreach ($values as $value) {
|
||||
$orNode->eq()->field($this->getField($field))->literal($value);
|
||||
}
|
||||
|
||||
$orNode->end();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
|
||||
|
||||
/**
|
||||
* Contains constants values for comparisons which are not supported
|
||||
* by the Doctrine\Common\Collection\Expr\Comparison class.
|
||||
*/
|
||||
final class ExtraComparison
|
||||
{
|
||||
public const NOT_CONTAINS = 'NOT_CONTAINS';
|
||||
public const IS_NULL = 'IS_NULL';
|
||||
public const IS_NOT_NULL = 'IS_NOT_NULL';
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\FieldTypes;
|
||||
|
||||
use Sylius\Component\Grid\DataExtractor\DataExtractorInterface;
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Sylius\Component\Grid\FieldTypes\FieldTypeInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class TwigFieldType implements FieldTypeInterface
|
||||
{
|
||||
/**
|
||||
* @var DataExtractorInterface
|
||||
*/
|
||||
private $dataExtractor;
|
||||
|
||||
/**
|
||||
* @var \Twig_Environment
|
||||
*/
|
||||
private $twig;
|
||||
|
||||
/**
|
||||
* @param DataExtractorInterface $dataExtractor
|
||||
* @param \Twig_Environment $twig
|
||||
*/
|
||||
public function __construct(DataExtractorInterface $dataExtractor, \Twig_Environment $twig)
|
||||
{
|
||||
$this->dataExtractor = $dataExtractor;
|
||||
$this->twig = $twig;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render(Field $field, $data, array $options)
|
||||
{
|
||||
if ('.' !== $field->getPath()) {
|
||||
$data = $this->dataExtractor->get($field, $data);
|
||||
}
|
||||
|
||||
return $this->twig->render($options['template'], ['data' => $data, 'options' => $options]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setRequired('template');
|
||||
$resolver->setAllowedTypes('template', 'string');
|
||||
|
||||
$resolver->setDefined('vars');
|
||||
$resolver->setAllowedTypes('vars', 'array');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Form\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class DateTimeFilterTransformer implements DataTransformerInterface
|
||||
{
|
||||
private static $defaultTime = [
|
||||
'from' => ['hour' => '00', 'minute' => '00'],
|
||||
'to' => ['hour' => '23', 'minute' => '59'],
|
||||
];
|
||||
|
||||
/** @var string */
|
||||
private $type;
|
||||
|
||||
public function __construct(string $type)
|
||||
{
|
||||
Assert::oneOf($type, array_keys(static::$defaultTime));
|
||||
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value): array
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reverseTransform($value): array
|
||||
{
|
||||
if (!$value['date']['year']) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$value['time']['hour'] = $value['time']['hour'] === '' ? static::$defaultTime[$this->type]['hour'] : $value['time']['hour'];
|
||||
$value['time']['minute'] = $value['time']['minute'] === '' ? static::$defaultTime[$this->type]['minute'] : $value['time']['minute'];
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Form\Registry;
|
||||
|
||||
final class FormTypeRegistry implements FormTypeRegistryInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $formTypes = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add(string $identifier, string $typeIdentifier, string $formType): void
|
||||
{
|
||||
$this->formTypes[$identifier][$typeIdentifier] = $formType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get(string $identifier, string $typeIdentifier): ?string
|
||||
{
|
||||
if (!$this->has($identifier, $typeIdentifier)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->formTypes[$identifier][$typeIdentifier];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has(string $identifier, string $typeIdentifier): bool
|
||||
{
|
||||
return isset($this->formTypes[$identifier][$typeIdentifier]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Form\Registry;
|
||||
|
||||
interface FormTypeRegistryInterface
|
||||
{
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @param string $typeIdentifier
|
||||
* @param string $formType
|
||||
*/
|
||||
public function add(string $identifier, string $typeIdentifier, string $formType): void;
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @param string $typeIdentifier
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get(string $identifier, string $typeIdentifier): ?string;
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @param string $typeIdentifier
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $identifier, string $typeIdentifier): bool;
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Form\Type\Filter;
|
||||
|
||||
use Sylius\Component\Grid\Filter\BooleanFilter;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class BooleanFilterType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'choices' => [
|
||||
'sylius.ui.yes_label' => BooleanFilter::TRUE,
|
||||
'sylius.ui.no_label' => BooleanFilter::FALSE,
|
||||
],
|
||||
'data_class' => null,
|
||||
'required' => false,
|
||||
'placeholder' => 'sylius.ui.all',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(): string
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'sylius_grid_filter_boolean';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Form\Type\Filter;
|
||||
|
||||
use Sylius\Bundle\GridBundle\Form\DataTransformer\DateTimeFilterTransformer;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class DateFilterType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('from', DateTimeType::class, [
|
||||
'label' => 'sylius.ui.from',
|
||||
'date_widget' => 'single_text',
|
||||
'time_widget' => 'single_text',
|
||||
'required' => false,
|
||||
])
|
||||
->add('to', DateTimeType::class, [
|
||||
'label' => 'sylius.ui.to',
|
||||
'date_widget' => 'single_text',
|
||||
'time_widget' => 'single_text',
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
|
||||
$builder->get('from')->addViewTransformer(new DateTimeFilterTransformer('from'));
|
||||
$builder->get('to')->addViewTransformer(new DateTimeFilterTransformer('to'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => null,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'sylius_grid_filter_date';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Form\Type\Filter;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class EntityFilterType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'class' => null,
|
||||
'label' => false,
|
||||
'placeholder' => 'sylius.ui.all',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(): string
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'sylius_grid_filter_entity';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Form\Type\Filter;
|
||||
|
||||
use Sylius\Component\Grid\Filter\ExistsFilter;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class ExistsFilterType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'choices' => [
|
||||
'sylius.ui.no_label' => ExistsFilter::FALSE,
|
||||
'sylius.ui.yes_label' => ExistsFilter::TRUE,
|
||||
],
|
||||
'choice_values' => [
|
||||
ExistsFilter::FALSE,
|
||||
ExistsFilter::TRUE,
|
||||
],
|
||||
'data_class' => null,
|
||||
'required' => false,
|
||||
'placeholder' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(): string
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'sylius_grid_filter_exists';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Form\Type\Filter;
|
||||
|
||||
use Sylius\Bundle\CurrencyBundle\Form\Type\CurrencyChoiceType;
|
||||
use Sylius\Component\Grid\Filter\MoneyFilter;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class MoneyFilterType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('greaterThan', NumberType::class, [
|
||||
'label' => 'sylius.ui.greater_than',
|
||||
'required' => false,
|
||||
'scale' => $options['scale'],
|
||||
])
|
||||
->add('lessThan', NumberType::class, [
|
||||
'label' => 'sylius.ui.less_than',
|
||||
'required' => false,
|
||||
'scale' => $options['scale'],
|
||||
])
|
||||
->add('currency', CurrencyChoiceType::class, [
|
||||
'label' => 'sylius.ui.currency',
|
||||
'placeholder' => '---',
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => null,
|
||||
'scale' => MoneyFilter::DEFAULT_SCALE,
|
||||
])
|
||||
->setAllowedTypes('scale', ['string', 'int'])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'sylius_grid_filter_money';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Form\Type\Filter;
|
||||
|
||||
use Sylius\Component\Grid\Filter\StringFilter;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class StringFilterType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
if (!isset($options['type'])) {
|
||||
$builder
|
||||
->add('type', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'sylius.ui.contains' => StringFilter::TYPE_CONTAINS,
|
||||
'sylius.ui.not_contains' => StringFilter::TYPE_NOT_CONTAINS,
|
||||
'sylius.ui.equal' => StringFilter::TYPE_EQUAL,
|
||||
'sylius.ui.not_equal' => StringFilter::TYPE_NOT_EQUAL,
|
||||
'sylius.ui.empty' => StringFilter::TYPE_EMPTY,
|
||||
'sylius.ui.not_empty' => StringFilter::TYPE_NOT_EMPTY,
|
||||
'sylius.ui.starts_with' => StringFilter::TYPE_STARTS_WITH,
|
||||
'sylius.ui.ends_with' => StringFilter::TYPE_ENDS_WITH,
|
||||
'sylius.ui.in' => StringFilter::TYPE_IN,
|
||||
'sylius.ui.not_in' => StringFilter::TYPE_NOT_IN,
|
||||
],
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('value', TextType::class, [
|
||||
'required' => false,
|
||||
'label' => 'sylius.ui.value',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => null,
|
||||
])
|
||||
->setDefined('type')
|
||||
->setAllowedValues('type', [
|
||||
StringFilter::TYPE_CONTAINS,
|
||||
StringFilter::TYPE_NOT_CONTAINS,
|
||||
StringFilter::TYPE_EQUAL,
|
||||
StringFilter::TYPE_NOT_EQUAL,
|
||||
StringFilter::TYPE_EMPTY,
|
||||
StringFilter::TYPE_NOT_EMPTY,
|
||||
StringFilter::TYPE_STARTS_WITH,
|
||||
StringFilter::TYPE_ENDS_WITH,
|
||||
StringFilter::TYPE_IN,
|
||||
StringFilter::TYPE_NOT_IN,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix(): string
|
||||
{
|
||||
return 'sylius_grid_filter_string';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2011-2018 Paweł Jędrzejewski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
SyliusGridBundle [](http://travis-ci.org/Sylius/SyliusGridBundle)
|
||||
================
|
||||
|
||||
Advanced grids for your Symfony2 project.
|
||||
|
||||
Sylius
|
||||
------
|
||||
|
||||

|
||||
|
||||
Sylius is an Open Source eCommerce solution built from decoupled components with powerful API and the highest quality code. [Read more on sylius.com](http://sylius.com).
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Documentation is available on [**docs.sylius.com**](http://docs.sylius.com/en/latest/components_and_bundles/bundles/SyliusGridBundle/index.html).
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
[This page](http://docs.sylius.com/en/latest/contributing/index.html) contains all the information about contributing to Sylius.
|
||||
|
||||
Follow Sylius' Development
|
||||
--------------------------
|
||||
|
||||
If you want to keep up with the updates and latest features, follow us on the following channels:
|
||||
|
||||
* [Official Blog](https://sylius.com/blog)
|
||||
* [Sylius on Twitter](https://twitter.com/Sylius)
|
||||
* [Sylius on Facebook](https://facebook.com/SyliusEcommerce)
|
||||
|
||||
Bug tracking
|
||||
------------
|
||||
|
||||
Sylius uses [GitHub issues](https://github.com/Sylius/Sylius/issues).
|
||||
If you have found bug, please create an issue.
|
||||
|
||||
MIT License
|
||||
-----------
|
||||
|
||||
License can be found [here](https://github.com/Sylius/Sylius/blob/master/LICENSE).
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
The bundle was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com).
|
||||
See the list of [contributors](https://github.com/Sylius/Sylius/contributors).
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Renderer;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Action;
|
||||
use Sylius\Component\Grid\Renderer\BulkActionGridRendererInterface;
|
||||
use Sylius\Component\Grid\View\GridViewInterface;
|
||||
|
||||
final class TwigBulkActionGridRenderer implements BulkActionGridRendererInterface
|
||||
{
|
||||
/**
|
||||
* @var \Twig_Environment
|
||||
*/
|
||||
private $twig;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $bulkActionTemplates;
|
||||
|
||||
public function __construct(\Twig_Environment $twig, array $bulkActionTemplates)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->bulkActionTemplates = $bulkActionTemplates;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function renderBulkAction(GridViewInterface $gridView, Action $bulkAction, $data = null): string
|
||||
{
|
||||
$type = $bulkAction->getType();
|
||||
if (!isset($this->bulkActionTemplates[$type])) {
|
||||
throw new \InvalidArgumentException(sprintf('Missing template for bulk action type "%s".', $type));
|
||||
}
|
||||
|
||||
return $this->twig->render($this->bulkActionTemplates[$type], [
|
||||
'grid' => $gridView,
|
||||
'action' => $bulkAction,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,180 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Renderer;
|
||||
|
||||
use Sylius\Bundle\GridBundle\Form\Registry\FormTypeRegistryInterface;
|
||||
use Sylius\Component\Grid\Definition\Action;
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Sylius\Component\Grid\Definition\Filter;
|
||||
use Sylius\Component\Grid\FieldTypes\FieldTypeInterface;
|
||||
use Sylius\Component\Grid\Renderer\GridRendererInterface;
|
||||
use Sylius\Component\Grid\View\GridViewInterface;
|
||||
use Sylius\Component\Registry\ServiceRegistryInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class TwigGridRenderer implements GridRendererInterface
|
||||
{
|
||||
/**
|
||||
* @var \Twig_Environment
|
||||
*/
|
||||
private $twig;
|
||||
|
||||
/**
|
||||
* @var ServiceRegistryInterface
|
||||
*/
|
||||
private $fieldsRegistry;
|
||||
|
||||
/**
|
||||
* @var FormFactoryInterface
|
||||
*/
|
||||
private $formFactory;
|
||||
|
||||
/**
|
||||
* @var FormTypeRegistryInterface
|
||||
*/
|
||||
private $formTypeRegistry;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultTemplate;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $actionTemplates;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $filterTemplates;
|
||||
|
||||
/**
|
||||
* @param \Twig_Environment $twig
|
||||
* @param ServiceRegistryInterface $fieldsRegistry
|
||||
* @param FormFactoryInterface $formFactory
|
||||
* @param FormTypeRegistryInterface $formTypeRegistry
|
||||
* @param string $defaultTemplate
|
||||
* @param array $actionTemplates
|
||||
* @param array $filterTemplates
|
||||
*/
|
||||
public function __construct(
|
||||
\Twig_Environment $twig,
|
||||
ServiceRegistryInterface $fieldsRegistry,
|
||||
FormFactoryInterface $formFactory,
|
||||
FormTypeRegistryInterface $formTypeRegistry,
|
||||
string $defaultTemplate,
|
||||
array $actionTemplates = [],
|
||||
array $filterTemplates = []
|
||||
) {
|
||||
$this->twig = $twig;
|
||||
$this->fieldsRegistry = $fieldsRegistry;
|
||||
$this->formFactory = $formFactory;
|
||||
$this->formTypeRegistry = $formTypeRegistry;
|
||||
$this->defaultTemplate = $defaultTemplate;
|
||||
$this->actionTemplates = $actionTemplates;
|
||||
$this->filterTemplates = $filterTemplates;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render(GridViewInterface $gridView, ?string $template = null)
|
||||
{
|
||||
return $this->twig->render($template ?: $this->defaultTemplate, ['grid' => $gridView]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function renderField(GridViewInterface $gridView, Field $field, $data)
|
||||
{
|
||||
/** @var FieldTypeInterface $fieldType */
|
||||
$fieldType = $this->fieldsRegistry->get($field->getType());
|
||||
$resolver = new OptionsResolver();
|
||||
$fieldType->configureOptions($resolver);
|
||||
$options = $resolver->resolve($field->getOptions());
|
||||
|
||||
return $fieldType->render($field, $data, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function renderAction(GridViewInterface $gridView, Action $action, $data = null)
|
||||
{
|
||||
$type = $action->getType();
|
||||
if (!isset($this->actionTemplates[$type])) {
|
||||
throw new \InvalidArgumentException(sprintf('Missing template for action type "%s".', $type));
|
||||
}
|
||||
|
||||
return $this->twig->render($this->actionTemplates[$type], [
|
||||
'grid' => $gridView,
|
||||
'action' => $action,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function renderFilter(GridViewInterface $gridView, Filter $filter)
|
||||
{
|
||||
$template = $this->getFilterTemplate($filter);
|
||||
|
||||
$form = $this->formFactory->createNamed('criteria', FormType::class, [], [
|
||||
'allow_extra_fields' => true,
|
||||
'csrf_protection' => false,
|
||||
'required' => false,
|
||||
]);
|
||||
$form->add(
|
||||
$filter->getName(),
|
||||
$this->formTypeRegistry->get($filter->getType(), 'default'),
|
||||
$filter->getFormOptions()
|
||||
);
|
||||
|
||||
$criteria = $gridView->getParameters()->get('criteria', []);
|
||||
$form->submit($criteria);
|
||||
|
||||
return $this->twig->render($template, [
|
||||
'grid' => $gridView,
|
||||
'filter' => $filter,
|
||||
'form' => $form->get($filter->getName())->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Filter $filter
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private function getFilterTemplate(Filter $filter): string
|
||||
{
|
||||
$template = $filter->getTemplate();
|
||||
if (null !== $template) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
$type = $filter->getType();
|
||||
if (!isset($this->filterTemplates[$type])) {
|
||||
throw new \InvalidArgumentException(sprintf('Missing template for filter type "%s".', $type));
|
||||
}
|
||||
|
||||
return $this->filterTemplates[$type];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<imports>
|
||||
<import resource="services/field_types.xml" />
|
||||
<import resource="services/filters.xml" />
|
||||
<import resource="services/templating.xml" />
|
||||
<import resource="services/twig.xml" />
|
||||
</imports>
|
||||
|
||||
<services>
|
||||
<service id="sylius.grid.data_extractor.property_access" class="Sylius\Component\Grid\DataExtractor\PropertyAccessDataExtractor">
|
||||
<argument type="service" id="property_accessor" />
|
||||
</service>
|
||||
<service id="sylius.grid.array_to_definition_converter" class="Sylius\Component\Grid\Definition\ArrayToDefinitionConverter">
|
||||
<argument type="service" id="event_dispatcher" />
|
||||
</service>
|
||||
<service id="sylius.grid.provider" class="Sylius\Component\Grid\Provider\ArrayGridProvider">
|
||||
<argument type="service" id="sylius.grid.array_to_definition_converter" />
|
||||
<argument>%sylius.grids_definitions%</argument>
|
||||
</service>
|
||||
|
||||
<service id="sylius.grid.view_factory" class="Sylius\Component\Grid\View\GridViewFactory">
|
||||
<argument type="service" id="sylius.grid.data_provider" />
|
||||
</service>
|
||||
<service id="sylius.grid.data_provider" class="Sylius\Component\Grid\Data\DataProvider">
|
||||
<argument type="service" id="sylius.grid.data_source_provider" />
|
||||
<argument type="service" id="sylius.grid.filters_applicator" />
|
||||
<argument type="service" id="sylius.grid.sorter" />
|
||||
</service>
|
||||
<service id="sylius.grid.filters_criteria_resolver" class="Sylius\Component\Grid\Filtering\FiltersCriteriaResolver" />
|
||||
<service id="sylius.grid.filters_applicator" class="Sylius\Component\Grid\Filtering\FiltersApplicator">
|
||||
<argument type="service" id="sylius.registry.grid_filter" />
|
||||
<argument type="service" id="sylius.grid.filters_criteria_resolver" />
|
||||
</service>
|
||||
<service id="sylius.grid.sorter" class="Sylius\Component\Grid\Sorting\Sorter" />
|
||||
<service id="sylius.grid.data_source_provider" class="Sylius\Component\Grid\Data\DataSourceProvider">
|
||||
<argument type="service" id="sylius.registry.grid_driver" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.registry.grid_driver" class="Sylius\Component\Registry\ServiceRegistry">
|
||||
<argument>Sylius\Component\Grid\Data\DriverInterface</argument>
|
||||
<argument>grid driver</argument>
|
||||
</service>
|
||||
<service id="sylius.registry.grid_filter" class="Sylius\Component\Registry\ServiceRegistry">
|
||||
<argument>Sylius\Component\Grid\Filtering\FilterInterface</argument>
|
||||
<argument>grid filter</argument>
|
||||
</service>
|
||||
<service id="sylius.registry.grid_field" class="Sylius\Component\Registry\ServiceRegistry">
|
||||
<argument>Sylius\Component\Grid\FieldTypes\FieldTypeInterface</argument>
|
||||
<argument>grid field</argument>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="sylius.grid_field.datetime" class="Sylius\Component\Grid\FieldTypes\DatetimeFieldType">
|
||||
<argument type="service" id="sylius.grid.data_extractor" />
|
||||
<tag name="sylius.grid_field" type="datetime" />
|
||||
</service>
|
||||
<service id="sylius.grid_field.string" class="Sylius\Component\Grid\FieldTypes\StringFieldType">
|
||||
<argument type="service" id="sylius.grid.data_extractor" />
|
||||
<tag name="sylius.grid_field" type="string" />
|
||||
</service>
|
||||
<service id="sylius.grid_field.twig" class="Sylius\Bundle\GridBundle\FieldTypes\TwigFieldType">
|
||||
<argument type="service" id="sylius.grid.data_extractor" />
|
||||
<argument type="service" id="twig" />
|
||||
<tag name="sylius.grid_field" type="twig" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="sylius.form_registry.grid_filter" class="Sylius\Bundle\GridBundle\Form\Registry\FormTypeRegistry" public="false" />
|
||||
|
||||
<service id="sylius.grid_filter.string" class="Sylius\Component\Grid\Filter\StringFilter">
|
||||
<tag name="sylius.grid_filter" type="string" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\StringFilterType" />
|
||||
</service>
|
||||
<service id="sylius.form.type.grid_filter.string" class="Sylius\Bundle\GridBundle\Form\Type\Filter\StringFilterType">
|
||||
<tag name="form.type" />
|
||||
</service>
|
||||
<service id="sylius.grid_filter.boolean" class="Sylius\Component\Grid\Filter\BooleanFilter">
|
||||
<tag name="sylius.grid_filter" type="boolean" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\BooleanFilterType" />
|
||||
</service>
|
||||
<service id="sylius.form.type.grid_filter.boolean" class="Sylius\Bundle\GridBundle\Form\Type\Filter\BooleanFilterType">
|
||||
<tag name="form.type" />
|
||||
</service>
|
||||
<service id="sylius.grid_filter.date" class="Sylius\Component\Grid\Filter\DateFilter">
|
||||
<tag name="sylius.grid_filter" type="date" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\DateFilterType" />
|
||||
</service>
|
||||
<service id="sylius.form.type.grid_filter.date" class="Sylius\Bundle\GridBundle\Form\Type\Filter\DateFilterType">
|
||||
<tag name="form.type" />
|
||||
</service>
|
||||
<service id="sylius.grid_filter.entity" class="Sylius\Component\Grid\Filter\EntityFilter">
|
||||
<tag name="sylius.grid_filter" type="entity" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\EntityFilterType" />
|
||||
</service>
|
||||
<service id="sylius.form.type.grid_filter.entity" class="Sylius\Bundle\GridBundle\Form\Type\Filter\EntityFilterType">
|
||||
<tag name="form.type" />
|
||||
</service>
|
||||
<service id="sylius.grid_filter.money" class="Sylius\Component\Grid\Filter\MoneyFilter">
|
||||
<tag name="sylius.grid_filter" type="money" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\MoneyFilterType" />
|
||||
</service>
|
||||
<service id="sylius.form.type.grid_filter.money" class="Sylius\Bundle\GridBundle\Form\Type\Filter\MoneyFilterType">
|
||||
<tag name="form.type" />
|
||||
</service>
|
||||
<service id="sylius.grid_filter.exists" class="Sylius\Component\Grid\Filter\ExistsFilter">
|
||||
<tag name="sylius.grid_filter" type="exists" form-type="Sylius\Bundle\GridBundle\Form\Type\Filter\ExistsFilterType" />
|
||||
</service>
|
||||
<service id="sylius.form.type.grid_filter.exists" class="Sylius\Bundle\GridBundle\Form\Type\Filter\ExistsFilterType">
|
||||
<tag name="form.type" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="sylius.grid_driver.doctrine.orm" class="Sylius\Bundle\GridBundle\Doctrine\ORM\Driver">
|
||||
<argument type="service" id="doctrine" />
|
||||
<tag name="sylius.grid_driver" alias="doctrine/orm" />
|
||||
</service>
|
||||
<service id="sylius.grid_driver.doctrine.dbal" class="Sylius\Bundle\GridBundle\Doctrine\DBAL\Driver">
|
||||
<argument type="service" id="doctrine.dbal.default_connection" />
|
||||
<tag name="sylius.grid_driver" alias="doctrine/dbal" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="sylius.grid_driver.doctrine.phpcrodm" class="Sylius\Bundle\GridBundle\Doctrine\PHPCRODM\Driver">
|
||||
<argument type="service" id="doctrine_phpcr.odm.document_manager" />
|
||||
<tag name="sylius.grid_driver" alias="doctrine/phpcr-odm" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="sylius.templating.helper.grid" class="Sylius\Bundle\GridBundle\Templating\Helper\GridHelper" lazy="true">
|
||||
<argument type="service" id="sylius.grid.renderer" />
|
||||
<tag name="templating.helper" alias="sylius_grid" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.templating.helper.bulk_action_grid"
|
||||
class="Sylius\Bundle\GridBundle\Templating\Helper\BulkActionGridHelper"
|
||||
lazy="true"
|
||||
>
|
||||
<argument type="service" id="sylius.grid.bulk_action_renderer" />
|
||||
<tag name="templating.helper" alias="sylius_bulk_action_grid" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="sylius.grid.renderer.twig" class="Sylius\Bundle\GridBundle\Renderer\TwigGridRenderer">
|
||||
<argument type="service" id="twig" />
|
||||
<argument type="service" id="sylius.registry.grid_field" />
|
||||
<argument type="service" id="form.factory" />
|
||||
<argument type="service" id="sylius.form_registry.grid_filter" />
|
||||
<argument>SyliusGridBundle::_grid.html.twig</argument>
|
||||
<argument>%sylius.grid.templates.action%</argument>
|
||||
<argument>%sylius.grid.templates.filter%</argument>
|
||||
</service>
|
||||
|
||||
<service id="sylius.grid.bulk_action_renderer.twig" class="Sylius\Bundle\GridBundle\Renderer\TwigBulkActionGridRenderer">
|
||||
<argument type="service" id="twig" />
|
||||
<argument>%sylius.grid.templates.bulk_action%</argument>
|
||||
</service>
|
||||
|
||||
<service id="sylius.twig.extension.grid" class="Sylius\Bundle\GridBundle\Twig\GridExtension" public="false">
|
||||
<argument type="service" id="sylius.templating.helper.grid" />
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.twig.extension.bulk_action_grid"
|
||||
class="Sylius\Bundle\GridBundle\Twig\BulkActionGridExtension"
|
||||
public="false"
|
||||
>
|
||||
<argument type="service" id="sylius.templating.helper.bulk_action_grid" />
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle;
|
||||
|
||||
use Sylius\Bundle\GridBundle\DependencyInjection\Compiler\RegisterDriversPass;
|
||||
use Sylius\Bundle\GridBundle\DependencyInjection\Compiler\RegisterFieldTypesPass;
|
||||
use Sylius\Bundle\GridBundle\DependencyInjection\Compiler\RegisterFiltersPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
final class SyliusGridBundle extends Bundle
|
||||
{
|
||||
public const DRIVER_DOCTRINE_ORM = 'doctrine/orm';
|
||||
public const DRIVER_DOCTRINE_PHPCR_ODM = 'doctrine/phpcr-odm';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(ContainerBuilder $container)
|
||||
{
|
||||
parent::build($container);
|
||||
|
||||
$container->addCompilerPass(new RegisterDriversPass());
|
||||
$container->addCompilerPass(new RegisterFiltersPass());
|
||||
$container->addCompilerPass(new RegisterFieldTypesPass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getAvailableDrivers()
|
||||
{
|
||||
return [
|
||||
self::DRIVER_DOCTRINE_ORM,
|
||||
self::DRIVER_DOCTRINE_PHPCR_ODM,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Templating\Helper;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Action;
|
||||
use Sylius\Component\Grid\Renderer\BulkActionGridRendererInterface;
|
||||
use Sylius\Component\Grid\View\GridView;
|
||||
use Symfony\Component\Templating\Helper\Helper;
|
||||
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
class BulkActionGridHelper extends Helper
|
||||
{
|
||||
/**
|
||||
* @var BulkActionGridRendererInterface
|
||||
*/
|
||||
private $bulkActionGridRenderer;
|
||||
|
||||
/**
|
||||
* @param BulkActionGridRendererInterface $bulkActionGridRenderer
|
||||
*/
|
||||
public function __construct(BulkActionGridRendererInterface $bulkActionGridRenderer)
|
||||
{
|
||||
$this->bulkActionGridRenderer = $bulkActionGridRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridView $gridView
|
||||
* @param Action $bulkAction
|
||||
* @param mixed|null $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderBulkAction(GridView $gridView, Action $bulkAction, $data = null): string
|
||||
{
|
||||
return $this->bulkActionGridRenderer->renderBulkAction($gridView, $bulkAction, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'sylius_bulk_action_grid';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Templating\Helper;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Action;
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Sylius\Component\Grid\Definition\Filter;
|
||||
use Sylius\Component\Grid\Renderer\GridRendererInterface;
|
||||
use Sylius\Component\Grid\View\GridView;
|
||||
use Symfony\Component\Templating\Helper\Helper;
|
||||
|
||||
class GridHelper extends Helper
|
||||
{
|
||||
/**
|
||||
* @var GridRendererInterface
|
||||
*/
|
||||
private $gridRenderer;
|
||||
|
||||
/**
|
||||
* @param GridRendererInterface $gridRenderer
|
||||
*/
|
||||
public function __construct(GridRendererInterface $gridRenderer)
|
||||
{
|
||||
$this->gridRenderer = $gridRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridView $gridView
|
||||
* @param string|null $template
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function renderGrid(GridView $gridView, ?string $template = null)
|
||||
{
|
||||
return $this->gridRenderer->render($gridView, $template);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridView $gridView
|
||||
* @param Field $field
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function renderField(GridView $gridView, Field $field, $data)
|
||||
{
|
||||
return $this->gridRenderer->renderField($gridView, $field, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridView $gridView
|
||||
* @param Action $action
|
||||
* @param mixed|null $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function renderAction(GridView $gridView, Action $action, $data = null)
|
||||
{
|
||||
return $this->gridRenderer->renderAction($gridView, $action, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridView $gridView
|
||||
* @param Filter $filter
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function renderFilter(GridView $gridView, Filter $filter)
|
||||
{
|
||||
return $this->gridRenderer->renderFilter($gridView, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'sylius_grid';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,308 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Tests\DependencyInjection;
|
||||
|
||||
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Sylius\Bundle\GridBundle\DependencyInjection\Configuration;
|
||||
use Sylius\Bundle\GridBundle\Doctrine\ORM\Driver;
|
||||
|
||||
final class ConfigurationTest extends TestCase
|
||||
{
|
||||
use ConfigurationTestCaseTrait;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_requires_only_grid_name(): void
|
||||
{
|
||||
$this->assertProcessedConfigurationEquals(
|
||||
[[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => null,
|
||||
],
|
||||
]],
|
||||
[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'driver' => [
|
||||
'name' => Driver::NAME,
|
||||
'options' => [],
|
||||
],
|
||||
'sorting' => [],
|
||||
'limits' => [10, 25, 50],
|
||||
'fields' => [],
|
||||
'filters' => [],
|
||||
'actions' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
'grids'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_uses_doctrine_orm_as_default_driver(): void
|
||||
{
|
||||
$this->assertProcessedConfigurationEquals(
|
||||
[[]],
|
||||
['drivers' => ['doctrine/orm']],
|
||||
'drivers'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_has_empty_action_and_filter_templates_by_default(): void
|
||||
{
|
||||
$this->assertProcessedConfigurationEquals(
|
||||
[[]],
|
||||
[
|
||||
'templates' => [
|
||||
'action' => [],
|
||||
'filter' => [],
|
||||
'bulk_action' => [],
|
||||
],
|
||||
],
|
||||
'templates'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function its_driver_cannot_be_empty(): void
|
||||
{
|
||||
$this->assertConfigurationIsInvalid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'driver' => [
|
||||
'name' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_requires_field_type_to_be_defined(): void
|
||||
{
|
||||
$this->assertConfigurationIsInvalid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'fields' => [
|
||||
'code' => [
|
||||
'label' => 'Internal code',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function its_base_sorting_can_be_overwritten(): void
|
||||
{
|
||||
$this->assertProcessedConfigurationEquals(
|
||||
[
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => ['code' => 'asc'],
|
||||
],
|
||||
]],
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => ['name' => 'desc'],
|
||||
],
|
||||
]],
|
||||
],
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => ['name' => 'desc'],
|
||||
],
|
||||
]],
|
||||
'grids.*.sorting'
|
||||
);
|
||||
|
||||
$this->assertProcessedConfigurationEquals(
|
||||
[
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => ['code' => 'asc'],
|
||||
],
|
||||
]],
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => null,
|
||||
],
|
||||
]],
|
||||
],
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => [],
|
||||
],
|
||||
]],
|
||||
'grids.*.sorting'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function its_sorting_order_can_be_only_ascending_or_descending(): void
|
||||
{
|
||||
$this->assertConfigurationIsValid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => ['code' => 'asc'],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
|
||||
$this->assertConfigurationIsValid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => ['code' => 'desc'],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
|
||||
$this->assertConfigurationIsInvalid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => ['code' => 'left'],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
|
||||
$this->assertConfigurationIsInvalid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'sorting' => ['code' => null],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function its_limits_can_only_be_a_collection_of_integers(): void
|
||||
{
|
||||
$this->assertConfigurationIsValid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => [10],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
|
||||
$this->assertConfigurationIsValid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => [10, 25],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
|
||||
$this->assertConfigurationIsInvalid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => [10.0, 25.0],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
|
||||
$this->assertConfigurationIsInvalid([[
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => [10, 25, 'surprise!'],
|
||||
],
|
||||
],
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function its_base_limits_can_be_overwritten(): void
|
||||
{
|
||||
$this->assertProcessedConfigurationEquals(
|
||||
[
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => [10, 25],
|
||||
],
|
||||
]],
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => [6, 12, 24],
|
||||
],
|
||||
]],
|
||||
],
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => [6, 12, 24],
|
||||
],
|
||||
]],
|
||||
'grids.*.limits'
|
||||
);
|
||||
|
||||
$this->assertProcessedConfigurationEquals(
|
||||
[
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => [10, 25, 50],
|
||||
],
|
||||
]],
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => null,
|
||||
],
|
||||
]],
|
||||
],
|
||||
['grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'limits' => [],
|
||||
],
|
||||
]],
|
||||
'grids.*.limits'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_should_throw_an_exception_if_an_invalid_driver_is_enabled(): void
|
||||
{
|
||||
$this->assertConfigurationIsInvalid([[
|
||||
'drivers' => ['doctrine/orm', 'foo/invalid'],
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getConfiguration(): Configuration
|
||||
{
|
||||
return new Configuration();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Tests\DependencyInjection;
|
||||
|
||||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
|
||||
use Sylius\Bundle\GridBundle\DependencyInjection\SyliusGridExtension;
|
||||
|
||||
final class SyliusGridExtensionTest extends AbstractExtensionTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_sets_configured_grids_as_parameter(): void
|
||||
{
|
||||
$this->load([
|
||||
'grids' => [
|
||||
'sylius_admin_tax_category' => [
|
||||
'driver' => [
|
||||
'name' => 'doctrine/orm',
|
||||
'options' => [
|
||||
'class' => 'Sylius\Component\Taxation\Model\TaxCategory',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertContainerBuilderHasParameter('sylius.grids_definitions', [
|
||||
'sylius_admin_tax_category' => [
|
||||
'driver' => [
|
||||
'name' => 'doctrine/orm',
|
||||
'options' => [
|
||||
'class' => 'Sylius\Component\Taxation\Model\TaxCategory',
|
||||
],
|
||||
],
|
||||
'sorting' => [],
|
||||
'limits' => [10, 25, 50],
|
||||
'fields' => [],
|
||||
'filters' => [],
|
||||
'actions' => [],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_aliases_default_services(): void
|
||||
{
|
||||
$this->load([]);
|
||||
|
||||
$this->assertContainerBuilderHasAlias('sylius.grid.renderer', 'sylius.grid.renderer.twig');
|
||||
$this->assertContainerBuilderHasAlias('sylius.grid.data_extractor', 'sylius.grid.data_extractor.property_access');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_always_defines_template_parameters(): void
|
||||
{
|
||||
$this->load([]);
|
||||
|
||||
$this->assertContainerBuilderHasParameter('sylius.grid.templates.filter', []);
|
||||
$this->assertContainerBuilderHasParameter('sylius.grid.templates.action', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_sets_filter_templates_as_parameters(): void
|
||||
{
|
||||
$this->load([
|
||||
'templates' => [
|
||||
'filter' => [
|
||||
'string' => 'AppBundle:Grid/Filter:string.html.twig',
|
||||
'date' => 'AppBundle:Grid/Filter:date.html.twig',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertContainerBuilderHasParameter('sylius.grid.templates.filter', [
|
||||
'string' => 'AppBundle:Grid/Filter:string.html.twig',
|
||||
'date' => 'AppBundle:Grid/Filter:date.html.twig',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_sets_action_templates_as_parameters(): void
|
||||
{
|
||||
$this->load([
|
||||
'templates' => [
|
||||
'action' => [
|
||||
'create' => 'AppBundle:Grid/Filter:create.html.twig',
|
||||
'update' => 'AppBundle:Grid/Filter:update.html.twig',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertContainerBuilderHasParameter('sylius.grid.templates.action', [
|
||||
'create' => 'AppBundle:Grid/Filter:create.html.twig',
|
||||
'update' => 'AppBundle:Grid/Filter:update.html.twig',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getContainerExtensions(): array
|
||||
{
|
||||
return [
|
||||
new SyliusGridExtension(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Twig;
|
||||
|
||||
use Sylius\Bundle\GridBundle\Templating\Helper\BulkActionGridHelper;
|
||||
|
||||
final class BulkActionGridExtension extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* @var BulkActionGridHelper
|
||||
*/
|
||||
private $bulkActionGridHelper;
|
||||
|
||||
/**
|
||||
* @param BulkActionGridHelper $bulkActionGridHelper
|
||||
*/
|
||||
public function __construct(BulkActionGridHelper $bulkActionGridHelper)
|
||||
{
|
||||
$this->bulkActionGridHelper = $bulkActionGridHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new \Twig_Function(
|
||||
'sylius_grid_render_bulk_action',
|
||||
[$this->bulkActionGridHelper, 'renderBulkAction'],
|
||||
['is_safe' => ['html']]
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Twig;
|
||||
|
||||
use Sylius\Bundle\GridBundle\Templating\Helper\GridHelper;
|
||||
|
||||
final class GridExtension extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* @var GridHelper
|
||||
*/
|
||||
private $gridHelper;
|
||||
|
||||
/**
|
||||
* @param GridHelper $gridHelper
|
||||
*/
|
||||
public function __construct(GridHelper $gridHelper)
|
||||
{
|
||||
$this->gridHelper = $gridHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new \Twig_Function('sylius_grid_render', [$this->gridHelper, 'renderGrid'], ['is_safe' => ['html']]),
|
||||
new \Twig_Function('sylius_grid_render_field', [$this->gridHelper, 'renderField'], ['is_safe' => ['html']]),
|
||||
new \Twig_Function('sylius_grid_render_action', [$this->gridHelper, 'renderAction'], ['is_safe' => ['html']]),
|
||||
new \Twig_Function('sylius_grid_render_filter', [$this->gridHelper, 'renderFilter'], ['is_safe' => ['html']]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
{
|
||||
"name": "sylius/grid-bundle",
|
||||
"type": "symfony-bundle",
|
||||
"description": "Amazing grids with support of filters and custom fields integrated into Symfony.",
|
||||
"keywords": ["shop", "ecommerce", "store", "webshop", "sylius", "grid", "admin", "crud"],
|
||||
"homepage": "http://sylius.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paweł Jędrzejewski",
|
||||
"homepage": "http://pjedrzejewski.com"
|
||||
},
|
||||
{
|
||||
"name": "Sylius project",
|
||||
"homepage": "http://sylius.com"
|
||||
},
|
||||
{
|
||||
"name": "Community contributions",
|
||||
"homepage": "http://github.com/Sylius/Sylius/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1",
|
||||
|
||||
"sylius/grid": "^1.1",
|
||||
"symfony/form": "^3.4",
|
||||
"symfony/framework-bundle": "^3.4",
|
||||
"symfony/templating": "^3.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"akeneo/phpspec-skip-example-extension": "^3.0",
|
||||
"doctrine/doctrine-bundle": "^1.3",
|
||||
"doctrine/orm": "^2.5",
|
||||
"doctrine/phpcr-odm": "^1.3",
|
||||
"jackalope/jackalope-doctrine-dbal": "^1.2",
|
||||
"matthiasnoback/symfony-config-test": "^3.0",
|
||||
"matthiasnoback/symfony-dependency-injection-test": "^2.0",
|
||||
"ocramius/proxy-manager": "^2.1",
|
||||
"pagerfanta/pagerfanta": "^1.0|^2.0",
|
||||
"phpspec/phpspec": "^4.0",
|
||||
"phpunit/phpunit": "^6.5",
|
||||
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
|
||||
"symfony/browser-kit": "^3.4",
|
||||
"symfony/dependency-injection": "^3.4",
|
||||
"symfony/proxy-manager-bridge": "^3.4",
|
||||
"symfony/security-csrf": "^3.4",
|
||||
"symfony/twig-bundle": "^3.4",
|
||||
"symfony/validator": "^3.4",
|
||||
"twig/twig": "^2.0"
|
||||
},
|
||||
"conflict": {
|
||||
"twig/twig": "^1.0"
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Sylius\\Bundle\\GridBundle\\": "" }
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Sylius\\Bundle\\GridBundle\\spec\\": "spec/",
|
||||
"AppBundle\\": "test/src/AppBundle/"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../../*/*"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
suites:
|
||||
main:
|
||||
namespace: Sylius\Bundle\GridBundle
|
||||
psr4_prefix: Sylius\Bundle\GridBundle
|
||||
src_path: .
|
||||
|
||||
extensions:
|
||||
Akeneo\SkipExampleExtension: ~
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
>
|
||||
<php>
|
||||
<server name="KERNEL_DIR" value="test/app/" />
|
||||
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
|
||||
</php>
|
||||
<testsuites>
|
||||
<testsuite name="SyliusAddressingBundle Test Suite">
|
||||
<directory>./test/</directory>
|
||||
</testsuite>
|
||||
|
||||
<testsuite name="Sylius Test Suite">
|
||||
<directory>./Tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./Tests</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\GridBundle\Doctrine\ORM;
|
||||
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Bundle\GridBundle\Doctrine\ORM\DataSource;
|
||||
use Sylius\Component\Grid\Data\DriverInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
final class DriverSpec extends ObjectBehavior
|
||||
{
|
||||
function let(ManagerRegistry $managerRegistry): void
|
||||
{
|
||||
$this->beConstructedWith($managerRegistry);
|
||||
}
|
||||
|
||||
function it_implements_grid_driver(): void
|
||||
{
|
||||
$this->shouldImplement(DriverInterface::class);
|
||||
}
|
||||
|
||||
function it_throws_exception_if_class_is_undefined(): void
|
||||
{
|
||||
$this
|
||||
->shouldThrow(\InvalidArgumentException::class)
|
||||
->during('getDataSource', [[], new Parameters()]);
|
||||
}
|
||||
|
||||
function it_creates_data_source_via_doctrine_orm_query_builder(
|
||||
ManagerRegistry $managerRegistry,
|
||||
EntityManagerInterface $entityManager,
|
||||
EntityRepository $entityRepository,
|
||||
QueryBuilder $queryBuilder
|
||||
): void {
|
||||
$managerRegistry->getManagerForClass('App:Book')->willReturn($entityManager);
|
||||
$entityManager->getRepository('App:Book')->willReturn($entityRepository);
|
||||
$entityRepository->createQueryBuilder('o')->willReturn($queryBuilder);
|
||||
|
||||
$this->getDataSource(['class' => 'App:Book'], new Parameters())->shouldHaveType(DataSource::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,146 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
|
||||
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use Doctrine\Common\Collections\Expr\Value;
|
||||
use Doctrine\ODM\PHPCR\Query\Builder\ConstraintComparison;
|
||||
use Doctrine\ODM\PHPCR\Query\Builder\ConstraintOrx;
|
||||
use Doctrine\ODM\PHPCR\Query\Builder\OrderBy;
|
||||
use Doctrine\ODM\PHPCR\Query\Builder\Ordering;
|
||||
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
|
||||
use Doctrine\ODM\PHPCR\Query\Query;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Bundle\GridBundle\Doctrine\PHPCRODM\ExpressionBuilderInterface;
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
/**
|
||||
* @require Doctrine\ODM\PHPCR\DocumentManagerInterface
|
||||
*/
|
||||
final class DataSourceSpec extends ObjectBehavior
|
||||
{
|
||||
function let(QueryBuilder $queryBuilder, ExpressionBuilderInterface $expressionBuilder): void
|
||||
{
|
||||
$this->beConstructedWith($queryBuilder, $expressionBuilder);
|
||||
}
|
||||
|
||||
function it_implements_data_source(): void
|
||||
{
|
||||
$this->shouldImplement(DataSourceInterface::class);
|
||||
}
|
||||
|
||||
function it_should_restrict_with_or_condition(
|
||||
Comparison $comparison,
|
||||
Value $value,
|
||||
QueryBuilder $queryBuilder,
|
||||
ConstraintOrx $constraint,
|
||||
ConstraintComparison $comparisonConstraint
|
||||
): void {
|
||||
$queryBuilder->orWhere()->willReturn($constraint);
|
||||
$value->getValue()->willReturn('value');
|
||||
$comparison->getValue()->willReturn($value);
|
||||
$comparison->getField()->willReturn('foo');
|
||||
$comparison->getOperator()->willReturn('=');
|
||||
|
||||
$constraint->eq()->willReturn($comparisonConstraint);
|
||||
$comparisonConstraint->field('o.foo')->willReturn($comparisonConstraint);
|
||||
$comparisonConstraint->literal('value')->shouldBeCalled()->willReturn($comparisonConstraint);
|
||||
$comparisonConstraint->end()->shouldBeCalled();
|
||||
|
||||
$this->restrict($comparison, DataSourceInterface::CONDITION_OR);
|
||||
}
|
||||
|
||||
function it_should_throw_an_exception_if_an_unknown_condition_is_passed(
|
||||
Comparison $comparison
|
||||
): void {
|
||||
$this->shouldThrow(
|
||||
new \RuntimeException('Unknown restrict condition "foo"')
|
||||
)->during('restrict', [$comparison, 'foo']);
|
||||
}
|
||||
|
||||
function it_should_return_the_expression_builder(
|
||||
ExpressionBuilderInterface $expressionBuilder
|
||||
): void {
|
||||
$this->getExpressionBuilder()->shouldReturn($expressionBuilder);
|
||||
}
|
||||
|
||||
function it_should_get_the_data(
|
||||
QueryBuilder $queryBuilder,
|
||||
ExpressionBuilderInterface $expressionBuilder,
|
||||
Query $query
|
||||
): void {
|
||||
$expressionBuilder->getOrderBys()->willReturn([]);
|
||||
|
||||
$queryBuilder->orderBy()->willReturn(null);
|
||||
$queryBuilder->getQuery()->willReturn($query);
|
||||
$query->setMaxResults(Argument::any())->willReturn($query);
|
||||
$query->setFirstResult(Argument::any())->willReturn($query);
|
||||
$query->execute()->willReturn([]);
|
||||
|
||||
$this->getData(new Parameters(['page' => 1]))->shouldHaveType(Pagerfanta::class);
|
||||
}
|
||||
|
||||
function it_should_set_the_order_on_the_query_builder(
|
||||
QueryBuilder $queryBuilder,
|
||||
ExpressionBuilderInterface $expressionBuilder,
|
||||
Query $query,
|
||||
OrderBy $orderBy,
|
||||
Ordering $ordering
|
||||
): void {
|
||||
$expressionBuilder->getOrderBys()->willReturn([
|
||||
'foo' => 'asc',
|
||||
'bar' => 'desc',
|
||||
]);
|
||||
$queryBuilder->orderBy()->willReturn($orderBy);
|
||||
$orderBy->asc()->willReturn($ordering);
|
||||
$orderBy->desc()->willReturn($ordering);
|
||||
$ordering->field('o.foo')->shouldBeCalled();
|
||||
$ordering->field('o.bar')->shouldBeCalled();
|
||||
|
||||
$queryBuilder->getQuery()->willReturn($query);
|
||||
$query->setMaxResults(Argument::any())->willReturn($query);
|
||||
$query->setFirstResult(Argument::any())->willReturn($query);
|
||||
$query->execute()->willReturn([]);
|
||||
|
||||
$this->getData(new Parameters(['page' => 1]))->shouldHaveType(Pagerfanta::class);
|
||||
}
|
||||
|
||||
function it_should_set_the_order_on_the_query_builder_as_fields_only(
|
||||
QueryBuilder $queryBuilder,
|
||||
ExpressionBuilderInterface $expressionBuilder,
|
||||
Query $query,
|
||||
OrderBy $orderBy,
|
||||
Ordering $ordering
|
||||
): void {
|
||||
$expressionBuilder->getOrderBys()->willReturn([
|
||||
'foo',
|
||||
'bar',
|
||||
]);
|
||||
$queryBuilder->orderBy()->willReturn($orderBy);
|
||||
$orderBy->asc()->willReturn($ordering);
|
||||
$orderBy->asc()->willReturn($ordering);
|
||||
$ordering->field('o.foo')->shouldBeCalled();
|
||||
$ordering->field('o.bar')->shouldBeCalled();
|
||||
|
||||
$queryBuilder->getQuery()->willReturn($query);
|
||||
$query->setMaxResults(Argument::any())->willReturn($query);
|
||||
$query->setFirstResult(Argument::any())->willReturn($query);
|
||||
$query->execute()->willReturn([]);
|
||||
|
||||
$this->getData(new Parameters(['page' => 1]))->shouldHaveType(Pagerfanta::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
|
||||
|
||||
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
|
||||
use Doctrine\ODM\PHPCR\DocumentRepository;
|
||||
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Bundle\GridBundle\Doctrine\PHPCRODM\DataSource;
|
||||
use Sylius\Component\Grid\Data\DriverInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
/**
|
||||
* @require Doctrine\ODM\PHPCR\DocumentManagerInterface
|
||||
*/
|
||||
final class DriverSpec extends ObjectBehavior
|
||||
{
|
||||
function let(DocumentManagerInterface $documentManager): void
|
||||
{
|
||||
$this->beConstructedWith($documentManager);
|
||||
}
|
||||
|
||||
function it_implements_grid_driver(): void
|
||||
{
|
||||
$this->shouldImplement(DriverInterface::class);
|
||||
}
|
||||
|
||||
function it_throws_exception_if_class_is_undefined(): void
|
||||
{
|
||||
$this
|
||||
->shouldThrow(\InvalidArgumentException::class)
|
||||
->during('getDataSource', [[], new Parameters()]);
|
||||
}
|
||||
|
||||
function it_creates_data_source_via_doctrine_phpcrodm_query_builder(
|
||||
DocumentManagerInterface $documentManager,
|
||||
DocumentRepository $documentRepository,
|
||||
QueryBuilder $queryBuilder
|
||||
): void {
|
||||
$documentManager->getRepository('App:Book')->willReturn($documentRepository);
|
||||
$documentRepository->createQueryBuilder('o')->willReturn($queryBuilder);
|
||||
|
||||
$this->getDataSource(['class' => 'App:Book'], new Parameters())->shouldHaveType(DataSource::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
|
||||
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use Doctrine\Common\Collections\ExpressionBuilder as CollectionsExpressionBuilder;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Bundle\GridBundle\Doctrine\PHPCRODM\ExtraComparison;
|
||||
|
||||
/**
|
||||
* @require Doctrine\ODM\PHPCR\DocumentManagerInterface
|
||||
*/
|
||||
final class ExpressionBuilderSpec extends ObjectBehavior
|
||||
{
|
||||
function let(CollectionsExpressionBuilder $expressionBuilder): void
|
||||
{
|
||||
$this->beConstructedWith($expressionBuilder);
|
||||
}
|
||||
|
||||
function it_builds_andx(
|
||||
Comparison $comparison,
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->andX([$comparison]);
|
||||
$expressionBuilder->andX([$comparison])->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_orx(
|
||||
Comparison $comparison,
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->orX([$comparison]);
|
||||
$expressionBuilder->orX([$comparison])->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_equals(
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->equals('o.foo', 'value');
|
||||
$expressionBuilder->eq('o.foo', 'value')->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_not_equals(
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->notEquals('o.foo', 'value');
|
||||
$expressionBuilder->neq('o.foo', 'value')->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_less_than_or_equal(
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->lessThanOrEqual('o.foo', 'value');
|
||||
$expressionBuilder->lte('o.foo', 'value')->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_greater_than(
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->greaterThan('o.foo', 'value');
|
||||
$expressionBuilder->gt('o.foo', 'value')->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_greater_than_or_equal(
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->greaterThanOrequal('o.foo', 'value');
|
||||
$expressionBuilder->gte('o.foo', 'value')->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_in(
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->in('o.foo', ['value']);
|
||||
$expressionBuilder->in('o.foo', ['value'])->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_not_in(
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->notIn('o.foo', ['value']);
|
||||
$expressionBuilder->notIn('o.foo', ['value'])->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_is_null(): void
|
||||
{
|
||||
$expr = $this->isNull('o.foo');
|
||||
$expr->getOperator()->shouldReturn(ExtraComparison::IS_NULL);
|
||||
$expr->getField()->shouldReturn('o.foo');
|
||||
}
|
||||
|
||||
function it_builds_is_not_null(): void
|
||||
{
|
||||
$expr = $this->isNotNull('o.foo');
|
||||
$expr->getOperator()->shouldReturn(ExtraComparison::IS_NOT_NULL);
|
||||
$expr->getField()->shouldReturn('o.foo');
|
||||
}
|
||||
|
||||
function it_builds_like(
|
||||
CollectionsExpressionBuilder $expressionBuilder
|
||||
): void {
|
||||
$this->like('o.foo', 'value');
|
||||
$expressionBuilder->contains('o.foo', 'value')->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_builds_not_like(): void
|
||||
{
|
||||
$expr = $this->notLike('o.foo', 'value');
|
||||
$expr->getOperator()->shouldReturn(ExtraComparison::NOT_CONTAINS);
|
||||
$expr->getField()->shouldReturn('o.foo');
|
||||
}
|
||||
|
||||
function it_orders_by(): void
|
||||
{
|
||||
$this->orderBy('o.foo', 'asc');
|
||||
$this->getOrderBys()->shouldReturn([
|
||||
'o.foo' => 'asc',
|
||||
]);
|
||||
}
|
||||
|
||||
function it_adds_order_by(): void
|
||||
{
|
||||
$this->orderBy('o.foo', 'asc');
|
||||
$this->addOrderBy('o.bar', 'desc');
|
||||
$this->getOrderBys()->shouldReturn([
|
||||
'o.foo' => 'asc',
|
||||
'o.bar' => 'desc',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\GridBundle\FieldTypes;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Grid\DataExtractor\DataExtractorInterface;
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Sylius\Component\Grid\FieldTypes\FieldTypeInterface;
|
||||
|
||||
final class TwigFieldTypeSpec extends ObjectBehavior
|
||||
{
|
||||
function let(DataExtractorInterface $dataExtractor, \Twig_Environment $twig): void
|
||||
{
|
||||
$this->beConstructedWith($dataExtractor, $twig);
|
||||
}
|
||||
|
||||
function it_is_a_grid_field_type(): void
|
||||
{
|
||||
$this->shouldImplement(FieldTypeInterface::class);
|
||||
}
|
||||
|
||||
function it_uses_data_extractor_to_obtain_data_and_renders_it_via_twig(
|
||||
DataExtractorInterface $dataExtractor,
|
||||
\Twig_Environment $twig,
|
||||
Field $field
|
||||
): void {
|
||||
$field->getPath()->willReturn('foo');
|
||||
|
||||
$dataExtractor->get($field, ['foo' => 'bar'])->willReturn('Value');
|
||||
$twig->render('foo.html.twig', ['data' => 'Value', 'options' => ['template' => 'foo.html.twig']])->willReturn('<html>Value</html>');
|
||||
|
||||
$this->render($field, ['foo' => 'bar'], [
|
||||
'template' => 'foo.html.twig',
|
||||
])->shouldReturn('<html>Value</html>');
|
||||
}
|
||||
|
||||
function it_uses_data_directly_if_dot_is_configured_as_path(
|
||||
\Twig_Environment $twig,
|
||||
Field $field
|
||||
): void {
|
||||
$field->getPath()->willReturn('.');
|
||||
$twig->render('foo.html.twig', ['data' => 'bar', 'options' => ['template' => 'foo.html.twig']])->willReturn('<html>Bar</html>');
|
||||
|
||||
$this->render($field, 'bar', ['template' => 'foo.html.twig'])->shouldReturn('<html>Bar</html>');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\GridBundle\Renderer;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Grid\Definition\Action;
|
||||
use Sylius\Component\Grid\Renderer\BulkActionGridRendererInterface;
|
||||
use Sylius\Component\Grid\View\GridViewInterface;
|
||||
|
||||
final class TwigBulkActionGridRendererSpec extends ObjectBehavior
|
||||
{
|
||||
function let(\Twig_Environment $twig): void
|
||||
{
|
||||
$this->beConstructedWith($twig, ['delete' => 'SyliusGridBundle:BulkAction:_delete.html.twig']);
|
||||
}
|
||||
|
||||
function it_is_a_bulk_action_grid_renderer(): void
|
||||
{
|
||||
$this->shouldImplement(BulkActionGridRendererInterface::class);
|
||||
}
|
||||
|
||||
function it_uses_twig_to_render_the_bulk_action(
|
||||
\Twig_Environment $twig,
|
||||
GridViewInterface $gridView,
|
||||
Action $bulkAction
|
||||
): void {
|
||||
$bulkAction->getType()->willReturn('delete');
|
||||
$bulkAction->getOptions()->willReturn([]);
|
||||
|
||||
$twig
|
||||
->render('SyliusGridBundle:BulkAction:_delete.html.twig', [
|
||||
'grid' => $gridView,
|
||||
'action' => $bulkAction,
|
||||
'data' => null,
|
||||
])
|
||||
->willReturn('<a href="#">Delete</a>')
|
||||
;
|
||||
|
||||
$this->renderBulkAction($gridView, $bulkAction)->shouldReturn('<a href="#">Delete</a>');
|
||||
}
|
||||
|
||||
function it_throws_an_exception_if_template_is_not_configured_for_given_bulk_action_type(
|
||||
GridViewInterface $gridView,
|
||||
Action $bulkAction
|
||||
): void {
|
||||
$bulkAction->getType()->willReturn('foo');
|
||||
|
||||
$this
|
||||
->shouldThrow(new \InvalidArgumentException('Missing template for bulk action type "foo".'))
|
||||
->during('renderBulkAction', [$gridView, $bulkAction])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\GridBundle\Renderer;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Bundle\GridBundle\Form\Registry\FormTypeRegistryInterface;
|
||||
use Sylius\Component\Grid\Definition\Action;
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Sylius\Component\Grid\FieldTypes\FieldTypeInterface;
|
||||
use Sylius\Component\Grid\Filter\StringFilter;
|
||||
use Sylius\Component\Grid\Renderer\GridRendererInterface;
|
||||
use Sylius\Component\Grid\View\GridView;
|
||||
use Sylius\Component\Grid\View\GridViewInterface;
|
||||
use Sylius\Component\Registry\ServiceRegistryInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class TwigGridRendererSpec extends ObjectBehavior
|
||||
{
|
||||
function let(
|
||||
\Twig_Environment $twig,
|
||||
ServiceRegistryInterface $fieldsRegistry,
|
||||
FormFactoryInterface $formFactory,
|
||||
FormTypeRegistryInterface $formTypeRegistry
|
||||
): void {
|
||||
$actionTemplates = [
|
||||
'link' => 'SyliusGridBundle:Action:_link.html.twig',
|
||||
'form' => 'SyliusGridBundle:Action:_form.html.twig',
|
||||
];
|
||||
$filterTemplates = [
|
||||
StringFilter::NAME => 'SyliusGridBundle:Filter:_string.html.twig',
|
||||
];
|
||||
|
||||
$this->beConstructedWith(
|
||||
$twig,
|
||||
$fieldsRegistry,
|
||||
$formFactory,
|
||||
$formTypeRegistry,
|
||||
'SyliusGridBundle:default.html.twig',
|
||||
$actionTemplates,
|
||||
$filterTemplates
|
||||
);
|
||||
}
|
||||
|
||||
function it_is_a_grid_renderer(): void
|
||||
{
|
||||
$this->shouldImplement(GridRendererInterface::class);
|
||||
}
|
||||
|
||||
function it_uses_twig_to_render_the_grid_view(\Twig_Environment $twig, GridViewInterface $gridView): void
|
||||
{
|
||||
$twig->render('SyliusGridBundle:default.html.twig', ['grid' => $gridView])->willReturn('<html>Grid!</html>');
|
||||
$this->render($gridView)->shouldReturn('<html>Grid!</html>');
|
||||
}
|
||||
|
||||
function it_uses_custom_template_if_specified(\Twig_Environment $twig, GridView $gridView): void
|
||||
{
|
||||
$twig->render('SyliusGridBundle:custom.html.twig', ['grid' => $gridView])->willReturn('<html>Grid!</html>');
|
||||
$this->render($gridView, 'SyliusGridBundle:custom.html.twig')->shouldReturn('<html>Grid!</html>');
|
||||
}
|
||||
|
||||
function it_uses_twig_to_render_the_action(\Twig_Environment $twig, GridViewInterface $gridView, Action $action): void
|
||||
{
|
||||
$action->getType()->willReturn('link');
|
||||
$action->getOptions()->willReturn([]);
|
||||
|
||||
$twig
|
||||
->render('SyliusGridBundle:Action:_link.html.twig', [
|
||||
'grid' => $gridView,
|
||||
'action' => $action,
|
||||
'data' => null,
|
||||
])
|
||||
->willReturn('<a href="#">Action!</a>')
|
||||
;
|
||||
|
||||
$this->renderAction($gridView, $action)->shouldReturn('<a href="#">Action!</a>');
|
||||
}
|
||||
|
||||
function it_renders_a_field_with_data_via_appropriate_field_type(
|
||||
GridViewInterface $gridView,
|
||||
Field $field,
|
||||
ServiceRegistryInterface $fieldsRegistry,
|
||||
FieldTypeInterface $fieldType
|
||||
): void {
|
||||
$field->getType()->willReturn('string');
|
||||
$fieldsRegistry->get('string')->willReturn($fieldType);
|
||||
$fieldType->configureOptions(Argument::type(OptionsResolver::class))
|
||||
->will(function ($args) {
|
||||
$args[0]->setRequired('foo');
|
||||
})
|
||||
;
|
||||
|
||||
$field->getOptions()->willReturn([
|
||||
'foo' => 'bar',
|
||||
]);
|
||||
$fieldType->render($field, 'Value', ['foo' => 'bar'])->willReturn('<strong>Value</strong>');
|
||||
|
||||
$this->renderField($gridView, $field, 'Value')->shouldReturn('<strong>Value</strong>');
|
||||
}
|
||||
|
||||
function it_throws_an_exception_if_template_is_not_configured_for_given_action_type(
|
||||
GridViewInterface $gridView,
|
||||
Action $action
|
||||
): void {
|
||||
$action->getType()->willReturn('foo');
|
||||
|
||||
$this
|
||||
->shouldThrow(new \InvalidArgumentException('Missing template for action type "foo".'))
|
||||
->during('renderAction', [$gridView, $action])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\GridBundle\Templating\Helper;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Grid\Definition\Action;
|
||||
use Sylius\Component\Grid\Renderer\BulkActionGridRendererInterface;
|
||||
use Sylius\Component\Grid\View\GridView;
|
||||
use Symfony\Component\Templating\Helper\Helper;
|
||||
use Symfony\Component\Templating\Helper\HelperInterface;
|
||||
|
||||
final class BulkActionGridHelperSpec extends ObjectBehavior
|
||||
{
|
||||
function let(BulkActionGridRendererInterface $bulkActionGridRenderer): void
|
||||
{
|
||||
$this->beConstructedWith($bulkActionGridRenderer);
|
||||
}
|
||||
|
||||
function it_is_a_templating_helper(): void
|
||||
{
|
||||
$this->shouldImplement(HelperInterface::class);
|
||||
}
|
||||
|
||||
function it_extends_base_templating_helper(): void
|
||||
{
|
||||
$this->shouldHaveType(Helper::class);
|
||||
}
|
||||
|
||||
function it_uses_a_grid_renderer_to_render_a_bulk_action(
|
||||
BulkActionGridRendererInterface $bulkActionGridRenderer,
|
||||
GridView $gridView,
|
||||
Action $bulkAction
|
||||
): void {
|
||||
$bulkActionGridRenderer->renderBulkAction($gridView, $bulkAction, null)->willReturn('<a href="#">Delete</a>');
|
||||
$this->renderBulkAction($gridView, $bulkAction)->shouldReturn('<a href="#">Delete</a>');
|
||||
}
|
||||
|
||||
function it_has_name(): void
|
||||
{
|
||||
$this->getName()->shouldReturn('sylius_bulk_action_grid');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\GridBundle\Templating\Helper;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Grid\Definition\Action;
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Sylius\Component\Grid\Renderer\GridRendererInterface;
|
||||
use Sylius\Component\Grid\View\GridView;
|
||||
use Symfony\Component\Templating\Helper\Helper;
|
||||
use Symfony\Component\Templating\Helper\HelperInterface;
|
||||
|
||||
final class GridHelperSpec extends ObjectBehavior
|
||||
{
|
||||
function let(GridRendererInterface $gridRenderer): void
|
||||
{
|
||||
$this->beConstructedWith($gridRenderer);
|
||||
}
|
||||
|
||||
function it_is_a_templating_helper(): void
|
||||
{
|
||||
$this->shouldImplement(HelperInterface::class);
|
||||
}
|
||||
|
||||
function it_extends_base_templating_helper(): void
|
||||
{
|
||||
$this->shouldHaveType(Helper::class);
|
||||
}
|
||||
|
||||
function it_uses_grid_renderer_to_render_grid(GridRendererInterface $gridRenderer, GridView $gridView): void
|
||||
{
|
||||
$gridRenderer->render($gridView, null)->willReturn('<html>Grid!</html>');
|
||||
$this->renderGrid($gridView, null)->shouldReturn('<html>Grid!</html>');
|
||||
}
|
||||
|
||||
function it_uses_grid_renderer_to_render_field(GridRendererInterface $gridRenderer, GridView $gridView, Field $field): void
|
||||
{
|
||||
$gridRenderer->renderField($gridView, $field, 'foo')->willReturn('Value');
|
||||
$this->renderField($gridView, $field, 'foo')->shouldReturn('Value');
|
||||
}
|
||||
|
||||
function it_uses_grid_renderer_to_render_action(GridRendererInterface $gridRenderer, GridView $gridView, Action $action): void
|
||||
{
|
||||
$gridRenderer->renderAction($gridView, $action, null)->willReturn('<a href="#">Go go Gadget arms!</a>');
|
||||
$this->renderAction($gridView, $action)->shouldReturn('<a href="#">Go go Gadget arms!</a>');
|
||||
}
|
||||
|
||||
function it_has_name(): void
|
||||
{
|
||||
$this->getName()->shouldReturn('sylius_grid');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class AppKernel extends Kernel
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function registerBundles(): array
|
||||
{
|
||||
return [
|
||||
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
|
||||
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
|
||||
new Sylius\Bundle\GridBundle\SyliusGridBundle(),
|
||||
new Symfony\Bundle\TwigBundle\TwigBundle(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function registerContainerConfiguration(LoaderInterface $loader): void
|
||||
{
|
||||
$loader->load(__DIR__ . '/config/config.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getContainerBaseClass(): string
|
||||
{
|
||||
if ('test' === $this->environment) {
|
||||
return MockerContainer::class;
|
||||
}
|
||||
|
||||
return parent::getContainerBaseClass();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
|
||||
$loader = require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
require __DIR__ . '/AppKernel.php';
|
||||
|
||||
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
|
||||
|
||||
return $loader;
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
imports:
|
||||
- { resource: "@SyliusGridBundle/test/app/config/parameters.yml" }
|
||||
|
||||
framework:
|
||||
assets: false
|
||||
translator: { fallbacks: ["%locale%"] }
|
||||
secret: "%secret%"
|
||||
router:
|
||||
resource: "%kernel.root_dir%/config/routing.yml"
|
||||
form: ~
|
||||
csrf_protection: true
|
||||
templating:
|
||||
engines: ['twig']
|
||||
default_locale: "%locale%"
|
||||
session:
|
||||
handler_id: ~
|
||||
storage_id: session.storage.mock_file
|
||||
http_method_override: true
|
||||
test: ~
|
||||
|
||||
twig:
|
||||
debug: "%kernel.debug%"
|
||||
strict_variables: "%kernel.debug%"
|
||||
|
||||
doctrine:
|
||||
dbal:
|
||||
driver: "%database_driver%"
|
||||
path: "%database_path%"
|
||||
charset: UTF8
|
||||
orm:
|
||||
entity_managers:
|
||||
default:
|
||||
auto_mapping: true
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
parameters:
|
||||
database_driver: pdo_sqlite
|
||||
database_path: "%kernel.root_dir%/db.sql"
|
||||
|
||||
locale: en_US
|
||||
secret: "Three can keep a secret, if two of them are dead."
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?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.
|
||||
*/
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
require_once __DIR__ . "/../../vendor/autoload.php";
|
||||
require_once __DIR__.'/AppKernel.php';
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
|
||||
$input = new ArgvInput();
|
||||
|
||||
$application = new Application(new AppKernel('test', true));
|
||||
$application->run($input);
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\GridBundle\Tests;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
final class SyliusGridBundleTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function its_services_are_initializable(): void
|
||||
{
|
||||
/** @var ContainerInterface $container */
|
||||
$container = self::createClient()->getContainer();
|
||||
|
||||
$services = $container->getServiceIds();
|
||||
|
||||
$services = array_filter($services, function ($serviceId) {
|
||||
return 0 === strpos($serviceId, 'sylius.');
|
||||
});
|
||||
|
||||
foreach ($services as $id) {
|
||||
$container->get($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
5
src/Sylius/Component/Grid/.gitignore
vendored
5
src/Sylius/Component/Grid/.gitignore
vendored
|
|
@ -1,5 +0,0 @@
|
|||
vendor/
|
||||
bin/
|
||||
|
||||
composer.phar
|
||||
composer.lock
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Data;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Grid;
|
||||
use Sylius\Component\Grid\Filtering\FiltersApplicatorInterface;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
use Sylius\Component\Grid\Sorting\SorterInterface;
|
||||
|
||||
final class DataProvider implements DataProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var DataSourceProviderInterface
|
||||
*/
|
||||
private $dataSourceProvider;
|
||||
|
||||
/**
|
||||
* @var FiltersApplicatorInterface
|
||||
*/
|
||||
private $filtersApplicator;
|
||||
|
||||
/**
|
||||
* @var SorterInterface
|
||||
*/
|
||||
private $sorter;
|
||||
|
||||
/**
|
||||
* @param DataSourceProviderInterface $dataSourceProvider
|
||||
* @param FiltersApplicatorInterface $filtersApplicator
|
||||
* @param SorterInterface $sorter
|
||||
*/
|
||||
public function __construct(
|
||||
DataSourceProviderInterface $dataSourceProvider,
|
||||
FiltersApplicatorInterface $filtersApplicator,
|
||||
SorterInterface $sorter
|
||||
) {
|
||||
$this->dataSourceProvider = $dataSourceProvider;
|
||||
$this->filtersApplicator = $filtersApplicator;
|
||||
$this->sorter = $sorter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData(Grid $grid, Parameters $parameters)
|
||||
{
|
||||
$dataSource = $this->dataSourceProvider->getDataSource($grid, $parameters);
|
||||
|
||||
$this->filtersApplicator->apply($dataSource, $grid, $parameters);
|
||||
$this->sorter->sort($dataSource, $grid, $parameters);
|
||||
|
||||
return $dataSource->getData($parameters);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Data;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Grid;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
interface DataProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param Grid $grid
|
||||
* @param Parameters $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData(Grid $grid, Parameters $parameters);
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Data;
|
||||
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
interface DataSourceInterface
|
||||
{
|
||||
public const CONDITION_AND = 'and';
|
||||
public const CONDITION_OR = 'or';
|
||||
|
||||
/**
|
||||
* @param mixed $expression
|
||||
* @param string $condition
|
||||
*/
|
||||
public function restrict($expression, string $condition = self::CONDITION_AND): void;
|
||||
|
||||
/**
|
||||
* @return ExpressionBuilderInterface
|
||||
*/
|
||||
public function getExpressionBuilder(): ExpressionBuilderInterface;
|
||||
|
||||
/**
|
||||
* @param Parameters $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData(Parameters $parameters);
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Data;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Grid;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
use Sylius\Component\Registry\ServiceRegistryInterface;
|
||||
|
||||
final class DataSourceProvider implements DataSourceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var ServiceRegistryInterface
|
||||
*/
|
||||
private $driversRegistry;
|
||||
|
||||
/**
|
||||
* @param ServiceRegistryInterface $driversRegistry
|
||||
*/
|
||||
public function __construct(ServiceRegistryInterface $driversRegistry)
|
||||
{
|
||||
$this->driversRegistry = $driversRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDataSource(Grid $grid, Parameters $parameters): DataSourceInterface
|
||||
{
|
||||
$driverName = $grid->getDriver();
|
||||
|
||||
if (!$this->driversRegistry->has($driverName)) {
|
||||
throw new UnsupportedDriverException($driverName);
|
||||
}
|
||||
|
||||
/** @var DriverInterface $driver */
|
||||
$driver = $this->driversRegistry->get($driverName);
|
||||
|
||||
return $driver->getDataSource($grid->getDriverConfiguration(), $parameters);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Data;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Grid;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
interface DataSourceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param Grid $grid
|
||||
* @param Parameters $parameters
|
||||
*
|
||||
* @return DataSourceInterface
|
||||
*/
|
||||
public function getDataSource(Grid $grid, Parameters $parameters): DataSourceInterface;
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Data;
|
||||
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
interface DriverInterface
|
||||
{
|
||||
/**
|
||||
* @param array $configuration
|
||||
* @param Parameters $parameters
|
||||
*
|
||||
* @return DataSourceInterface
|
||||
*/
|
||||
public function getDataSource(array $configuration, Parameters $parameters): DataSourceInterface;
|
||||
}
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Data;
|
||||
|
||||
interface ExpressionBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed ...$expressions
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function andX(...$expressions);
|
||||
|
||||
/**
|
||||
* @param mixed ...$expressions
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function orX(...$expressions);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param string $operator
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function comparison(string $field, string $operator, $value);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function equals(string $field, $value);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function notEquals(string $field, $value);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function lessThan(string $field, $value);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function lessThanOrEqual(string $field, $value);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function greaterThan(string $field, $value);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function greaterThanOrEqual(string $field, $value);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param array $values
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function in(string $field, array $values);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param array $values
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function notIn(string $field, array $values);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function isNull(string $field);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function isNotNull(string $field);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param string $pattern
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function like(string $field, string $pattern);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param string $pattern
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function notLike(string $field, string $pattern);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param string $direction
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function orderBy(string $field, string $direction);
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param string $direction
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function addOrderBy(string $field, string $direction);
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Data;
|
||||
|
||||
class UnsupportedDriverException extends \InvalidArgumentException
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(string $name)
|
||||
{
|
||||
parent::__construct(sprintf('Grid data driver "%s" is not supported.', $name));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\DataExtractor;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
|
||||
interface DataExtractorInterface
|
||||
{
|
||||
/**
|
||||
* @param Field $field
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(Field $field, $data);
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\DataExtractor;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||
|
||||
final class PropertyAccessDataExtractor implements DataExtractorInterface
|
||||
{
|
||||
/**
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
private $propertyAccessor;
|
||||
|
||||
/**
|
||||
* @param PropertyAccessorInterface $propertyAccessor
|
||||
*/
|
||||
public function __construct(PropertyAccessorInterface $propertyAccessor)
|
||||
{
|
||||
$this->propertyAccessor = $propertyAccessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get(Field $field, $data)
|
||||
{
|
||||
return $this->propertyAccessor->getValue($data, $field->getPath());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Definition;
|
||||
|
||||
class Action
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $label;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $enabled = true;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $icon;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* Position equals to 100 to ensure that wile sorting actions by position ASC
|
||||
* the action buttons positioned by default will be last
|
||||
*/
|
||||
private $position = 100;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
*/
|
||||
private function __construct(string $name, string $type)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromNameAndType(string $name, string $type): self
|
||||
{
|
||||
return new self($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*/
|
||||
public function setLabel(string $label): void
|
||||
{
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function setEnabled(bool $enabled): void
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getIcon(): ?string
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $icon
|
||||
*/
|
||||
public function setIcon(string $icon): void
|
||||
{
|
||||
$this->icon = $icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(): array
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*/
|
||||
public function setOptions(array $options): void
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition(): int
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $position
|
||||
*/
|
||||
public function setPosition(int $position): void
|
||||
{
|
||||
$this->position = $position;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Definition;
|
||||
|
||||
class ActionGroup
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var Action[]
|
||||
*/
|
||||
private $actions = [];
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
private function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function named(string $name): self
|
||||
{
|
||||
return new self($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getActions(): array
|
||||
{
|
||||
return $this->actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Action $action
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addAction(Action $action): void
|
||||
{
|
||||
if ($this->hasAction($name = $action->getName())) {
|
||||
throw new \InvalidArgumentException(sprintf('Action "%s" already exists.', $name));
|
||||
}
|
||||
|
||||
$this->actions[$name] = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return Action
|
||||
*/
|
||||
public function getAction(string $name): Action
|
||||
{
|
||||
if (!$this->hasAction($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('Action "%s" does not exist.', $name));
|
||||
}
|
||||
|
||||
return $this->actions[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAction(string $name): bool
|
||||
{
|
||||
return isset($this->actions[$name]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,204 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Definition;
|
||||
|
||||
use Sylius\Component\Grid\Event\GridDefinitionConverterEvent;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
final class ArrayToDefinitionConverter implements ArrayToDefinitionConverterInterface
|
||||
{
|
||||
public const EVENT_NAME = 'sylius.grid.%s';
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
*/
|
||||
public function __construct(EventDispatcherInterface $eventDispatcher)
|
||||
{
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function convert(string $code, array $configuration): Grid
|
||||
{
|
||||
$grid = Grid::fromCodeAndDriverConfiguration(
|
||||
$code,
|
||||
$configuration['driver']['name'],
|
||||
$configuration['driver']['options']
|
||||
);
|
||||
|
||||
if (array_key_exists('sorting', $configuration)) {
|
||||
$grid->setSorting($configuration['sorting']);
|
||||
}
|
||||
|
||||
if (array_key_exists('limits', $configuration)) {
|
||||
$grid->setLimits($configuration['limits']);
|
||||
}
|
||||
|
||||
foreach ($configuration['fields'] as $name => $fieldConfiguration) {
|
||||
$grid->addField($this->convertField($name, $fieldConfiguration));
|
||||
}
|
||||
|
||||
foreach ($configuration['filters'] as $name => $filterConfiguration) {
|
||||
$grid->addFilter($this->convertFilter($name, $filterConfiguration));
|
||||
}
|
||||
|
||||
foreach ($configuration['actions'] as $name => $actionGroupConfiguration) {
|
||||
$grid->addActionGroup($this->convertActionGroup($name, $actionGroupConfiguration));
|
||||
}
|
||||
|
||||
$this->eventDispatcher->dispatch($this->getEventName($code), new GridDefinitionConverterEvent($grid));
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $configuration
|
||||
*
|
||||
* @return Field
|
||||
*/
|
||||
private function convertField(string $name, array $configuration): Field
|
||||
{
|
||||
$field = Field::fromNameAndType($name, $configuration['type']);
|
||||
|
||||
if (array_key_exists('path', $configuration)) {
|
||||
$field->setPath($configuration['path']);
|
||||
}
|
||||
if (array_key_exists('label', $configuration)) {
|
||||
$field->setLabel($configuration['label']);
|
||||
}
|
||||
if (array_key_exists('enabled', $configuration)) {
|
||||
$field->setEnabled($configuration['enabled']);
|
||||
}
|
||||
if (array_key_exists('sortable', $configuration)) {
|
||||
$sortable = $configuration['sortable'];
|
||||
|
||||
if ($sortable === true || $sortable === null) {
|
||||
$sortable = $name;
|
||||
}
|
||||
|
||||
if ($sortable === false) {
|
||||
$sortable = null;
|
||||
}
|
||||
|
||||
$field->setSortable($sortable);
|
||||
}
|
||||
if (array_key_exists('position', $configuration)) {
|
||||
$field->setPosition($configuration['position']);
|
||||
}
|
||||
if (array_key_exists('options', $configuration)) {
|
||||
$field->setOptions($configuration['options']);
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $configuration
|
||||
*
|
||||
* @return Filter
|
||||
*/
|
||||
private function convertFilter(string $name, array $configuration): Filter
|
||||
{
|
||||
$filter = Filter::fromNameAndType($name, $configuration['type']);
|
||||
|
||||
if (array_key_exists('label', $configuration)) {
|
||||
$filter->setLabel($configuration['label']);
|
||||
}
|
||||
if (array_key_exists('template', $configuration)) {
|
||||
$filter->setTemplate($configuration['template']);
|
||||
}
|
||||
if (array_key_exists('enabled', $configuration)) {
|
||||
$filter->setEnabled($configuration['enabled']);
|
||||
}
|
||||
if (array_key_exists('position', $configuration)) {
|
||||
$filter->setPosition($configuration['position']);
|
||||
}
|
||||
if (array_key_exists('options', $configuration)) {
|
||||
$filter->setOptions($configuration['options']);
|
||||
}
|
||||
if (array_key_exists('form_options', $configuration)) {
|
||||
$filter->setFormOptions($configuration['form_options']);
|
||||
}
|
||||
if (array_key_exists('default_value', $configuration)) {
|
||||
$filter->setCriteria($configuration['default_value']);
|
||||
}
|
||||
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $configuration
|
||||
*
|
||||
* @return ActionGroup
|
||||
*/
|
||||
private function convertActionGroup(string $name, array $configuration): ActionGroup
|
||||
{
|
||||
$actionGroup = ActionGroup::named($name);
|
||||
|
||||
foreach ($configuration as $actionName => $actionConfiguration) {
|
||||
$actionGroup->addAction($this->convertAction($actionName, $actionConfiguration));
|
||||
}
|
||||
|
||||
return $actionGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $configuration
|
||||
*
|
||||
* @return Action
|
||||
*/
|
||||
private function convertAction(string $name, array $configuration): Action
|
||||
{
|
||||
$action = Action::fromNameAndType($name, $configuration['type']);
|
||||
|
||||
if (array_key_exists('label', $configuration)) {
|
||||
$action->setLabel($configuration['label']);
|
||||
}
|
||||
if (array_key_exists('icon', $configuration)) {
|
||||
$action->setIcon($configuration['icon']);
|
||||
}
|
||||
if (array_key_exists('enabled', $configuration)) {
|
||||
$action->setEnabled($configuration['enabled']);
|
||||
}
|
||||
if (array_key_exists('position', $configuration)) {
|
||||
$action->setPosition($configuration['position']);
|
||||
}
|
||||
if (array_key_exists('options', $configuration)) {
|
||||
$action->setOptions($configuration['options']);
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getEventName(string $code): string
|
||||
{
|
||||
return sprintf(self::EVENT_NAME, str_replace('sylius_', '', $code));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Definition;
|
||||
|
||||
interface ArrayToDefinitionConverterInterface
|
||||
{
|
||||
/**
|
||||
* @param string $code
|
||||
* @param array $configuration
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
public function convert(string $code, array $configuration): Grid;
|
||||
}
|
||||
|
|
@ -1,204 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Definition;
|
||||
|
||||
class Field
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $label;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $enabled = true;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $sortable;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* Position equals to 100 to ensure that wile sorting fields by position ASC
|
||||
* the fields positioned by default will be last
|
||||
*/
|
||||
private $position = 100;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
*/
|
||||
private function __construct(string $name, string $type)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
|
||||
$this->path = $name;
|
||||
$this->label = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromNameAndType(string $name, string $type): self
|
||||
{
|
||||
return new self($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
public function setPath(string $path): void
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*/
|
||||
public function setLabel(string $label): void
|
||||
{
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function setEnabled(bool $enabled): void
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $sortable
|
||||
*/
|
||||
public function setSortable(?string $sortable): void
|
||||
{
|
||||
$this->sortable = $sortable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSortable(): ?string
|
||||
{
|
||||
return $this->sortable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSortable(): bool
|
||||
{
|
||||
return null !== $this->sortable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(): array
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*/
|
||||
public function setOptions(array $options): void
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition(): int
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $position
|
||||
*/
|
||||
public function setPosition(int $position): void
|
||||
{
|
||||
$this->position = $position;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,216 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Definition;
|
||||
|
||||
class Filter
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $label;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $enabled = true;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $template;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $formOptions = [];
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $criteria;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* Position equals to 100 to ensure that wile sorting filters by position ASC
|
||||
* the filters positioned by default will be last
|
||||
*/
|
||||
private $position = 100;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
*/
|
||||
private function __construct(string $name, string $type)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
|
||||
$this->label = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromNameAndType(string $name, string $type): self
|
||||
{
|
||||
return new self($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $label
|
||||
*/
|
||||
public function setLabel($label): void
|
||||
{
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function setEnabled(bool $enabled): void
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTemplate(): ?string
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
*/
|
||||
public function setTemplate(string $template): void
|
||||
{
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(): array
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*/
|
||||
public function setOptions(array $options): void
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFormOptions(): array
|
||||
{
|
||||
return $this->formOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $formOptions
|
||||
*/
|
||||
public function setFormOptions(array $formOptions): void
|
||||
{
|
||||
$this->formOptions = $formOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition(): int
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $position
|
||||
*/
|
||||
public function setPosition(int $position): void
|
||||
{
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCriteria()
|
||||
{
|
||||
return $this->criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $criteria
|
||||
*/
|
||||
public function setCriteria($criteria)
|
||||
{
|
||||
$this->criteria = $criteria;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,392 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Definition;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
class Grid
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $code;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $driver;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $driverConfiguration;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $sorting = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $limits = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $fields = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $filters = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $actionGroups = [];
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $driver
|
||||
* @param array $driverConfiguration
|
||||
*/
|
||||
private function __construct(string $code, string $driver, array $driverConfiguration)
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->driver = $driver;
|
||||
$this->driverConfiguration = $driverConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $driver
|
||||
* @param array $driverConfiguration
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromCodeAndDriverConfiguration(string $code, string $driver, array $driverConfiguration): self
|
||||
{
|
||||
return new self($code, $driver, $driverConfiguration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDriver(): string
|
||||
{
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDriverConfiguration(): array
|
||||
{
|
||||
return $this->driverConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $driverConfiguration
|
||||
*/
|
||||
public function setDriverConfiguration(array $driverConfiguration): void
|
||||
{
|
||||
$this->driverConfiguration = $driverConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSorting(): array
|
||||
{
|
||||
return $this->sorting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sorting
|
||||
*/
|
||||
public function setSorting(array $sorting): void
|
||||
{
|
||||
$this->sorting = $sorting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLimits(): array
|
||||
{
|
||||
return $this->limits;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $limits
|
||||
*/
|
||||
public function setLimits(array $limits): void
|
||||
{
|
||||
$this->limits = $limits;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|Field[]
|
||||
*/
|
||||
public function getFields(): array
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|Field[]
|
||||
*/
|
||||
public function getEnabledFields(): array
|
||||
{
|
||||
return array_filter($this->getFields(), function (Field $field): bool {
|
||||
return $field->isEnabled();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Field $field
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addField(Field $field): void
|
||||
{
|
||||
$name = $field->getName();
|
||||
|
||||
Assert::false($this->hasField($name), sprintf('Field "%s" already exists.', $name));
|
||||
|
||||
$this->fields[$name] = $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function removeField(string $name): void
|
||||
{
|
||||
if ($this->hasField($name)) {
|
||||
unset($this->fields[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return Field
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getField(string $name): Field
|
||||
{
|
||||
Assert::true($this->hasField($name), sprintf('Field "%s" does not exist.', $name));
|
||||
|
||||
return $this->fields[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Field $field
|
||||
*/
|
||||
public function setField(Field $field): void
|
||||
{
|
||||
$name = $field->getName();
|
||||
|
||||
$this->fields[$name] = $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasField(string $name): bool
|
||||
{
|
||||
return array_key_exists($name, $this->fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|ActionGroup[]
|
||||
*/
|
||||
public function getActionGroups(): array
|
||||
{
|
||||
return $this->actionGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|ActionGroup[]
|
||||
*/
|
||||
public function getEnabledActionGroups(): array
|
||||
{
|
||||
return array_filter($this->getActionGroups(), function (ActionGroup $actionGroup): bool {
|
||||
// TODO: There's no `isEnabled` method on ActionGroup, so we assume all of them are enabled
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ActionGroup $actionGroup
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addActionGroup(ActionGroup $actionGroup): void
|
||||
{
|
||||
$name = $actionGroup->getName();
|
||||
|
||||
Assert::false($this->hasActionGroup($name), sprintf('ActionGroup "%s" already exists.', $name));
|
||||
|
||||
$this->actionGroups[$name] = $actionGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function removeActionGroup(string $name): void
|
||||
{
|
||||
if ($this->hasActionGroup($name)) {
|
||||
unset($this->actionGroups[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return ActionGroup
|
||||
*/
|
||||
public function getActionGroup(string $name): ActionGroup
|
||||
{
|
||||
Assert::true($this->hasActionGroup($name), sprintf('ActionGroup "%s" does not exist.', $name));
|
||||
|
||||
return $this->actionGroups[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ActionGroup $actionGroup
|
||||
*/
|
||||
public function setActionGroup(ActionGroup $actionGroup): void
|
||||
{
|
||||
$name = $actionGroup->getName();
|
||||
|
||||
$this->actionGroups[$name] = $actionGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $groupName
|
||||
*
|
||||
* @return array|Action[]
|
||||
*/
|
||||
public function getActions(string $groupName): array
|
||||
{
|
||||
return $this->getActionGroup($groupName)->getActions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|Action[]
|
||||
*/
|
||||
public function getEnabledActions($groupName): array
|
||||
{
|
||||
return array_filter($this->getActions($groupName), function (Action $action): bool {
|
||||
return $action->isEnabled();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasActionGroup(string $name): bool
|
||||
{
|
||||
return array_key_exists($name, $this->actionGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|Filter[]
|
||||
*/
|
||||
public function getFilters(): array
|
||||
{
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|Filter[]
|
||||
*/
|
||||
public function getEnabledFilters(): array
|
||||
{
|
||||
return array_filter($this->getFilters(), function (Filter $filter): bool {
|
||||
return $filter->isEnabled();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Filter $filter
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addFilter(Filter $filter): void
|
||||
{
|
||||
$name = $filter->getName();
|
||||
|
||||
Assert::false($this->hasFilter($name), sprintf('Filter "%s" already exists.', $name));
|
||||
|
||||
$this->filters[$name] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function removeFilter(string $name): void
|
||||
{
|
||||
if ($this->hasFilter($name)) {
|
||||
unset($this->filters[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return Filter
|
||||
*/
|
||||
public function getFilter(string $name): Filter
|
||||
{
|
||||
Assert::true($this->hasFilter($name), sprintf('Filter "%s" does not exist.', $name));
|
||||
|
||||
return $this->filters[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Filter $filter
|
||||
*/
|
||||
public function setFilter(Filter $filter): void
|
||||
{
|
||||
$name = $filter->getName();
|
||||
|
||||
$this->filters[$name] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasFilter(string $name): bool
|
||||
{
|
||||
return array_key_exists($name, $this->filters);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Event;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Grid;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
final class GridDefinitionConverterEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var Grid
|
||||
*/
|
||||
private $grid;
|
||||
|
||||
/**
|
||||
* @param Grid $grid
|
||||
*/
|
||||
public function __construct(Grid $grid)
|
||||
{
|
||||
$this->grid = $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Grid
|
||||
*/
|
||||
public function getGrid(): Grid
|
||||
{
|
||||
return $this->grid;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Exception;
|
||||
|
||||
class UndefinedGridException extends \InvalidArgumentException
|
||||
{
|
||||
/**
|
||||
* @param string $code
|
||||
*/
|
||||
public function __construct($code)
|
||||
{
|
||||
parent::__construct(sprintf('Grid "%s" does not exist.', $code));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\FieldTypes;
|
||||
|
||||
use Sylius\Component\Grid\DataExtractor\DataExtractorInterface;
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class DatetimeFieldType implements FieldTypeInterface
|
||||
{
|
||||
/**
|
||||
* @var DataExtractorInterface
|
||||
*/
|
||||
private $dataExtractor;
|
||||
|
||||
/**
|
||||
* @param DataExtractorInterface $dataExtractor
|
||||
*/
|
||||
public function __construct(DataExtractorInterface $dataExtractor)
|
||||
{
|
||||
$this->dataExtractor = $dataExtractor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function render(Field $field, $data, array $options)
|
||||
{
|
||||
$value = $this->dataExtractor->get($field, $data);
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Assert::isInstanceOf($value, \DateTimeInterface::class);
|
||||
|
||||
return $value->format($options['format']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefault('format', 'Y:m:d H:i:s');
|
||||
$resolver->setAllowedTypes('format', 'string');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\FieldTypes;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
interface FieldTypeInterface
|
||||
{
|
||||
/**
|
||||
* Return a HTML representation of the $field using the given $data and
|
||||
* $options.
|
||||
*
|
||||
* @param Field $field
|
||||
* @param mixed $data
|
||||
* @param array $options
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function render(Field $field, $data, array $options);
|
||||
|
||||
/**
|
||||
* Configure options for this field type.
|
||||
*
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void;
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\FieldTypes;
|
||||
|
||||
use Sylius\Component\Grid\DataExtractor\DataExtractorInterface;
|
||||
use Sylius\Component\Grid\Definition\Field;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class StringFieldType implements FieldTypeInterface
|
||||
{
|
||||
/**
|
||||
* @var DataExtractorInterface
|
||||
*/
|
||||
private $dataExtractor;
|
||||
|
||||
/**
|
||||
* @param DataExtractorInterface $dataExtractor
|
||||
*/
|
||||
public function __construct(DataExtractorInterface $dataExtractor)
|
||||
{
|
||||
$this->dataExtractor = $dataExtractor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render(Field $field, $data, array $options)
|
||||
{
|
||||
$value = $this->dataExtractor->get($field, $data);
|
||||
|
||||
return is_string($value) ? htmlspecialchars($value) : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filter;
|
||||
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Filtering\FilterInterface;
|
||||
|
||||
final class BooleanFilter implements FilterInterface
|
||||
{
|
||||
public const TRUE = 'true';
|
||||
public const FALSE = 'false';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void
|
||||
{
|
||||
if (empty($data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$field = $options['field'] ?? $name;
|
||||
|
||||
$data = self::TRUE === $data;
|
||||
|
||||
$dataSource->restrict($dataSource->getExpressionBuilder()->equals($field, $data));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filter;
|
||||
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Filtering\FilterInterface;
|
||||
|
||||
final class DateFilter implements FilterInterface
|
||||
{
|
||||
public const NAME = 'date';
|
||||
public const DEFAULT_INCLUSIVE_FROM = true;
|
||||
public const DEFAULT_INCLUSIVE_TO = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void
|
||||
{
|
||||
$expressionBuilder = $dataSource->getExpressionBuilder();
|
||||
|
||||
$field = (string) $this->getOption($options, 'field', $name);
|
||||
|
||||
$from = isset($data['from']) ? $this->getDateTime($data['from'], '00:00') : null;
|
||||
if (null !== $from) {
|
||||
$inclusive = (bool) $this->getOption($options, 'inclusive_from', self::DEFAULT_INCLUSIVE_FROM);
|
||||
if (true === $inclusive) {
|
||||
$dataSource->restrict($expressionBuilder->greaterThanOrEqual($field, $from));
|
||||
} else {
|
||||
$dataSource->restrict($expressionBuilder->greaterThan($field, $from));
|
||||
}
|
||||
}
|
||||
|
||||
$to = isset($data['to']) ? $this->getDateTime($data['to'], '23:59') : null;
|
||||
if (null !== $to) {
|
||||
$inclusive = (bool) $this->getOption($options, 'inclusive_to', self::DEFAULT_INCLUSIVE_TO);
|
||||
if (true === $inclusive) {
|
||||
$dataSource->restrict($expressionBuilder->lessThanOrEqual($field, $to));
|
||||
} else {
|
||||
$dataSource->restrict($expressionBuilder->lessThan($field, $to));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getOption(array $options, string $name, $default)
|
||||
{
|
||||
return $options[$name] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $data
|
||||
* @param string $defaultTime
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function getDateTime(array $data, string $defaultTime): ?string
|
||||
{
|
||||
if (empty($data['date'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($data['time'])) {
|
||||
$data['time'] = $defaultTime;
|
||||
}
|
||||
|
||||
return $data['date'] . ' ' . $data['time'];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filter;
|
||||
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Filtering\FilterInterface;
|
||||
|
||||
final class EntityFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void
|
||||
{
|
||||
if (empty($data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = $options['fields'] ?? [$name];
|
||||
|
||||
$expressionBuilder = $dataSource->getExpressionBuilder();
|
||||
|
||||
$expressions = [];
|
||||
foreach ($fields as $field) {
|
||||
$expressions[] = $expressionBuilder->equals($field, $data);
|
||||
}
|
||||
|
||||
$dataSource->restrict($expressionBuilder->orX(...$expressions));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filter;
|
||||
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Filtering\FilterInterface;
|
||||
|
||||
final class ExistsFilter implements FilterInterface
|
||||
{
|
||||
public const TRUE = true;
|
||||
public const FALSE = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void
|
||||
{
|
||||
if (null === $data) {
|
||||
return;
|
||||
}
|
||||
|
||||
$field = $options['field'] ?? $name;
|
||||
|
||||
if (self::TRUE === (bool) $data) {
|
||||
$dataSource->restrict($dataSource->getExpressionBuilder()->isNotNull($field));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$dataSource->restrict($dataSource->getExpressionBuilder()->isNull($field));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filter;
|
||||
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Filtering\FilterInterface;
|
||||
|
||||
final class MoneyFilter implements FilterInterface
|
||||
{
|
||||
public const DEFAULT_SCALE = 2;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void
|
||||
{
|
||||
if (empty($data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$field = $options['field'] ?? $name;
|
||||
$scale = (int) ($options['scale'] ?? self::DEFAULT_SCALE);
|
||||
|
||||
$greaterThan = $this->getDataValue($data, 'greaterThan');
|
||||
$lessThan = $this->getDataValue($data, 'lessThan');
|
||||
|
||||
$expressionBuilder = $dataSource->getExpressionBuilder();
|
||||
|
||||
if (!empty($data['currency'])) {
|
||||
$dataSource->restrict($expressionBuilder->equals($options['currency_field'], $data['currency']));
|
||||
}
|
||||
if ('' !== $greaterThan) {
|
||||
$dataSource->restrict($expressionBuilder->greaterThan($field, $this->normalizeAmount((float) $greaterThan, $scale)));
|
||||
}
|
||||
if ('' !== $lessThan) {
|
||||
$dataSource->restrict($expressionBuilder->lessThan($field, $this->normalizeAmount((float) $lessThan, $scale)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
* @param int $scale
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function normalizeAmount(float $amount, int $scale): int
|
||||
{
|
||||
return (int) round($amount * (10 ** $scale));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $data
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getDataValue(array $data, string $key): string
|
||||
{
|
||||
return $data[$key] ?? '';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filter;
|
||||
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Data\ExpressionBuilderInterface;
|
||||
use Sylius\Component\Grid\Filtering\FilterInterface;
|
||||
|
||||
final class StringFilter implements FilterInterface
|
||||
{
|
||||
public const NAME = 'string';
|
||||
|
||||
public const TYPE_EQUAL = 'equal';
|
||||
public const TYPE_NOT_EQUAL = 'not_equal';
|
||||
public const TYPE_EMPTY = 'empty';
|
||||
public const TYPE_NOT_EMPTY = 'not_empty';
|
||||
public const TYPE_CONTAINS = 'contains';
|
||||
public const TYPE_NOT_CONTAINS = 'not_contains';
|
||||
public const TYPE_STARTS_WITH = 'starts_with';
|
||||
public const TYPE_ENDS_WITH = 'ends_with';
|
||||
public const TYPE_IN = 'in';
|
||||
public const TYPE_NOT_IN = 'not_in';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void
|
||||
{
|
||||
$expressionBuilder = $dataSource->getExpressionBuilder();
|
||||
|
||||
if (is_array($data) && !isset($data['type'])) {
|
||||
$data['type'] = $options['type'] ?? self::TYPE_CONTAINS;
|
||||
}
|
||||
|
||||
if (!is_array($data)) {
|
||||
$data = ['type' => self::TYPE_CONTAINS, 'value' => $data];
|
||||
}
|
||||
|
||||
$fields = array_key_exists('fields', $options) ? $options['fields'] : [$name];
|
||||
|
||||
$type = $data['type'];
|
||||
$value = array_key_exists('value', $data) ? $data['value'] : null;
|
||||
|
||||
if (!in_array($type, [self::TYPE_NOT_EMPTY, self::TYPE_EMPTY], true) && '' === trim($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (1 === count($fields)) {
|
||||
$dataSource->restrict($this->getExpression($expressionBuilder, $type, current($fields), $value));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$expressions = [];
|
||||
foreach ($fields as $field) {
|
||||
$expressions[] = $this->getExpression($expressionBuilder, $type, $field, $value);
|
||||
}
|
||||
|
||||
if (self::TYPE_NOT_EQUAL === $type) {
|
||||
$dataSource->restrict($expressionBuilder->andX(...$expressions));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$dataSource->restrict($expressionBuilder->orX(...$expressions));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ExpressionBuilderInterface $expressionBuilder
|
||||
* @param string $type
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private function getExpression(
|
||||
ExpressionBuilderInterface $expressionBuilder,
|
||||
string $type,
|
||||
string $field,
|
||||
$value
|
||||
) {
|
||||
switch ($type) {
|
||||
case self::TYPE_EQUAL:
|
||||
return $expressionBuilder->equals($field, $value);
|
||||
case self::TYPE_NOT_EQUAL:
|
||||
return $expressionBuilder->notEquals($field, $value);
|
||||
case self::TYPE_EMPTY:
|
||||
return $expressionBuilder->isNull($field);
|
||||
case self::TYPE_NOT_EMPTY:
|
||||
return $expressionBuilder->isNotNull($field);
|
||||
case self::TYPE_CONTAINS:
|
||||
return $expressionBuilder->like($field, '%' . $value . '%');
|
||||
case self::TYPE_NOT_CONTAINS:
|
||||
return $expressionBuilder->notLike($field, '%' . $value . '%');
|
||||
case self::TYPE_STARTS_WITH:
|
||||
return $expressionBuilder->like($field, $value . '%');
|
||||
case self::TYPE_ENDS_WITH:
|
||||
return $expressionBuilder->like($field, '%' . $value);
|
||||
case self::TYPE_IN:
|
||||
return $expressionBuilder->in($field, array_map('trim', explode(',', $value)));
|
||||
case self::TYPE_NOT_IN:
|
||||
return $expressionBuilder->notIn($field, array_map('trim', explode(',', $value)));
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Could not get an expression for type "%s"!', $type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filtering;
|
||||
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
|
||||
interface FilterInterface
|
||||
{
|
||||
/**
|
||||
* @param DataSourceInterface $dataSource
|
||||
* @param string $name
|
||||
* @param mixed $data
|
||||
* @param array $options
|
||||
*/
|
||||
public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void;
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filtering;
|
||||
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Definition\Grid;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
use Sylius\Component\Registry\ServiceRegistryInterface;
|
||||
|
||||
final class FiltersApplicator implements FiltersApplicatorInterface
|
||||
{
|
||||
/**
|
||||
* @var ServiceRegistryInterface
|
||||
*/
|
||||
private $filtersRegistry;
|
||||
|
||||
/**
|
||||
* @var FiltersCriteriaResolverInterface
|
||||
*/
|
||||
private $criteriaResolver;
|
||||
|
||||
/**
|
||||
* @param ServiceRegistryInterface $filtersRegistry
|
||||
* @param FiltersCriteriaResolverInterface $criteriaResolver
|
||||
*/
|
||||
public function __construct(
|
||||
ServiceRegistryInterface $filtersRegistry,
|
||||
FiltersCriteriaResolverInterface $criteriaResolver
|
||||
) {
|
||||
$this->filtersRegistry = $filtersRegistry;
|
||||
$this->criteriaResolver = $criteriaResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters): void
|
||||
{
|
||||
if (!$this->criteriaResolver->hasCriteria($grid, $parameters)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$criteria = $this->criteriaResolver->getCriteria($grid, $parameters);
|
||||
foreach ($criteria as $name => $data) {
|
||||
if (!$grid->hasFilter($name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$gridFilter = $grid->getFilter($name);
|
||||
|
||||
/** @var FilterInterface $filter */
|
||||
$filter = $this->filtersRegistry->get($gridFilter->getType());
|
||||
$filter->apply($dataSource, $name, $data, $gridFilter->getOptions());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filtering;
|
||||
|
||||
use Sylius\Component\Grid\Data\DataSourceInterface;
|
||||
use Sylius\Component\Grid\Definition\Grid;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
interface FiltersApplicatorInterface
|
||||
{
|
||||
/**
|
||||
* @param DataSourceInterface $dataSource
|
||||
* @param Grid $grid
|
||||
* @param Parameters $parameters
|
||||
*/
|
||||
public function apply(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters): void;
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filtering;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Filter;
|
||||
use Sylius\Component\Grid\Definition\Grid;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
final class FiltersCriteriaResolver implements FiltersCriteriaResolverInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasCriteria(Grid $grid, Parameters $parameters): bool
|
||||
{
|
||||
return $parameters->has('criteria') || !empty($this->getFiltersDefaultCriteria($grid->getFilters()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCriteria(Grid $grid, Parameters $parameters): array
|
||||
{
|
||||
$defaultCriteria = array_map(function (Filter $filter) {
|
||||
return $filter->getCriteria();
|
||||
}, $this->getFiltersDefaultCriteria($grid->getFilters()));
|
||||
|
||||
return $parameters->get('criteria', $defaultCriteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Filter[] $filters
|
||||
*
|
||||
* @return Filter[]
|
||||
*/
|
||||
private function getFiltersDefaultCriteria(array $filters): array
|
||||
{
|
||||
return array_filter($filters, function (Filter $filter) {
|
||||
return null !== $filter->getCriteria();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Grid\Filtering;
|
||||
|
||||
use Sylius\Component\Grid\Definition\Grid;
|
||||
use Sylius\Component\Grid\Parameters;
|
||||
|
||||
interface FiltersCriteriaResolverInterface
|
||||
{
|
||||
/**
|
||||
* @param Grid $grid
|
||||
* @param Parameters $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCriteria(Grid $grid, Parameters $parameters): bool;
|
||||
|
||||
/**
|
||||
* @param Grid $grid
|
||||
* @param Parameters $parameters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCriteria(Grid $grid, Parameters $parameters): array;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue