Skip to content

Commit

Permalink
Merge pull request #188 from einorler/attribute_filter
Browse files Browse the repository at this point in the history
Dynamic aggregate filter
  • Loading branch information
saimaz committed Sep 16, 2016
2 parents 5e5f708 + ec2d6f3 commit 48902ff
Show file tree
Hide file tree
Showing 13 changed files with 1,166 additions and 0 deletions.
22 changes: 22 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function ($v) {
->end()
->children()
->append($this->buildFilterTree('choice'))
->append($this->buildFilterTree('dynamic_aggregate'))
->append($this->buildFilterTree('multi_choice'))
->append($this->buildFilterTree('match'))
->append($this->buildFilterTree('fuzzy'))
Expand Down Expand Up @@ -193,6 +194,27 @@ private function buildFilterTree($filterName)
->end()
->end();
break;
case 'dynamic_aggregate':
$node
->children()
->scalarNode('name_field')
->info('Name of the field to provide the aggregated values from.')
->end()
->arrayNode('sort')
->children()
->enumNode('type')
->values(['_term', '_count'])
->defaultValue('_term')
->end()
->enumNode('order')
->values(['asc', 'desc'])
->defaultValue('asc')
->end()
->arrayNode('priorities')->prototype('scalar')->end()
->end()
->end()
->end();
break;
case 'match':
$node
->children()
Expand Down
51 changes: 51 additions & 0 deletions DependencyInjection/Filter/DynamicAggregateFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\FilterManagerBundle\DependencyInjection\Filter;

use Symfony\Component\DependencyInjection\Definition;

/**
* Factory for choice filter.
*/
class DynamicAggregateFactory extends AbstractFilterFactory
{
/**
* {@inheritdoc}
*/
protected function configure(Definition $definition, array $configuration)
{
parent::configure($definition, $configuration);

$definition->addMethodCall('setField', [$configuration['field']]);
$definition->addMethodCall('setNameField', [$configuration['name_field']]);

if (isset($configuration['sort']) && count($configuration['sort']) > 0) {
$definition->addMethodCall('setSortType', [$configuration['sort']]);
}
}

/**
* {@inheritdoc}
*/
protected function getNamespace()
{
return 'ONGR\FilterManagerBundle\Filter\Widget\Dynamic\DynamicAggregate';
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'dynamic_aggregate';
}
}
49 changes: 49 additions & 0 deletions Filter/ViewData/AggregateViewData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\FilterManagerBundle\Filter\ViewData;

use ONGR\FilterManagerBundle\Filter\ViewData;

/**
* This class represents view data with aggregated choices.
*/
class AggregateViewData extends ViewData
{
/**
* @var ChoicesAwareViewData[]
*/
private $items;

/**
* @return ChoicesAwareViewData[]
*/
public function getItems()
{
return $this->items;
}

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

/**
* @param ChoicesAwareViewData $item
*/
public function addItem(ChoicesAwareViewData $item)
{
$this->items[] = $item;
}
}

0 comments on commit 48902ff

Please sign in to comment.