Skip to content

Commit

Permalink
Merge pull request #7 from pedro-teixeira/issue-7-pt-improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
Pedro Teixeira committed Apr 16, 2013
2 parents a4afde8 + 9873c2f commit aa22dd4
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 7 deletions.
18 changes: 17 additions & 1 deletion Grid/Filter/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ class Date extends FilterAbstract
*/
protected $operatorType = 'date';

/**
* @var string
*/
protected $dateFormat;

/**
* @param \Symfony\Component\DependencyInjection\Container $container
*/
public function __construct(\Symfony\Component\DependencyInjection\Container $container)
{
parent::__construct($container);

$this->dateFormat = $this->container->getParameter('pedro_teixeira_grid.date.date_format');
$this->setPlaceholder(strtoupper($this->dateFormat));
}

/**
* @return string
*/
public function render()
{
if ($this->getUseDatePicker()) {
$html = '<input ' . $this->getNameAndId() . ' type="text" value="' . $this->getValue() . '" placeholder="' . $this->getPlaceholder() . '" data-date-format="' . strtolower($this->container->getParameter('pedro_teixeira_grid.date.date_format')) . '">';
$html = '<input ' . $this->getNameAndId() . ' type="text" value="' . $this->getValue() . '" placeholder="' . $this->getPlaceholder() . '" data-date-format="' . strtolower($this->dateFormat) . '">';
$html .= '<script type="text/javascript">$(document).ready(function () {$("#' . $this->getId() . '").datepicker()})</script>';
} else {
$html = '<input ' . $this->getNameAndId() . ' type="date" value="' . $this->getValue() . '" placeholder="' . $this->getPlaceholder() . '">';
Expand Down
9 changes: 5 additions & 4 deletions Grid/Filter/DateRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ public function render()
{
if ($this->getUseDatePicker()) {

$html = '<input class="date-input" name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'from" type="text" value="' . $this->getValue() . '" placeholder="' . $this->getPlaceholder() . '" data-date-format="' . strtolower($this->container->getParameter('pedro_teixeira_grid.date.date_format')) . '">';
$html = '<input class="date-input" name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'from" type="text" value="' . $this->getValue() . '" placeholder="' . $this->getPlaceholder() . '" data-date-format="' . strtolower($this->dateFormat) . '">';
$html .= $this->getInputSeparator();
$html .= '<input class="date-input" name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'to" type="text" value="' . $this->getValue() . '" placeholder="' . $this->getPlaceholder() . '" data-date-format="' . strtolower($this->container->getParameter('pedro_teixeira_grid.date.date_format')) . '">';
$html .= '<input class="date-input" name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'to" type="text" value="' . $this->getValue() . '" placeholder="' . $this->getPlaceholder() . '" data-date-format="' . strtolower($this->dateFormat) . '">';
$html .= '<script type="text/javascript">$(document).ready(function () {$("#' . $this->getId() . 'from").datepicker(); $("#' . $this->getId() . 'to").datepicker()})</script>';

} else {

$html = '<input name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'from" type="date" value="' . $this->getValue() . '"> ';
$html .= '<input name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'to" type="date" value="' . $this->getValue() . '">';
$html = '<input class="date-input" name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'from" type="date" placeholder="' . $this->getPlaceholder() . '" value="' . $this->getValue() . '"> ';
$html .= $this->getInputSeparator();
$html .= '<input class="date-input" name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'to" type="date" placeholder="' . $this->getPlaceholder() . '" value="' . $this->getValue() . '">';

}

Expand Down
51 changes: 51 additions & 0 deletions Grid/Filter/NumberRange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace PedroTeixeira\Bundle\GridBundle\Grid\Filter;

/**
* Filter NumberRange
*/
class NumberRange extends FilterAbstract
{
/**
* @var string
*/
protected $operatorType = 'number_range';

/**
* @var string
*/
protected $inputSeparator = ' : ';

/**
* @return string
*/
public function render()
{
$html = '<input class="number-input" name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'from" type="text" placeholder="' . $this->getPlaceholder() . '" value="' . $this->getValue() . '"> ';
$html .= $this->getInputSeparator();
$html .= '<input class="number-input" name="' . $this->getIndex() . '[]" id="' . $this->getId() . 'to" type="text" placeholder="' . $this->getPlaceholder() . '" value="' . $this->getValue() . '">';

return $html;
}

/**
* @param string $inputSeparator
*
* @return DateRange
*/
public function setInputSeparator($inputSeparator)
{
$this->inputSeparator = $inputSeparator;

return $this;
}

/**
* @return string
*/
public function getInputSeparator()
{
return $this->inputSeparator;
}
}
48 changes: 48 additions & 0 deletions Grid/Filter/Operator/NumberRange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace PedroTeixeira\Bundle\GridBundle\Grid\Filter\Operator;

/**
* NumberRange
*/
class NumberRange extends OperatorAbstract
{
/**
* @param array $value
*
* @throws \Exception
*/
public function execute($value)
{
if (!is_array($value) || count($value) != 2) {
throw new \Exception('Value for number range comparison should have to values');
}

$queryBuilder = $this->getQueryBuilder();

if (!empty($value[0])) {
$queryBuilder->andWhere(
$queryBuilder->expr()->gte(
$this->getIndex(),
":{$this->getIndexClean()}_1"
))
->setParameter(
":{$this->getIndexClean()}_1",
(float) $value[0]
);
}

if (!empty($value[1])) {

$queryBuilder->andWhere(
$queryBuilder->expr()->lte(
$this->getIndex(),
":{$this->getIndexClean()}_2"
))
->setParameter(
":{$this->getIndexClean()}_2",
(float) $value[1]
);
}
}
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ Create your grid
->setField('name')
->setIndex('r.name');

$this->addColumn('Number')
->setField('number')
->setIndex('r.number')
->setFilterType('number_range');

$this->addColumn('Options')
->setField('option')
->setIndex('r.options')
Expand Down
10 changes: 10 additions & 0 deletions Resources/doc/column/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Operator Comparison Types:
* end_with
* not_end_with
* not_contain
* number_range

date
------------
Expand All @@ -77,6 +78,15 @@ Attributes:

* inputSeparator

number_range
------------

Two fields to define a number range.

Attributes:

* inputSeparator

select
------------

Expand Down
6 changes: 5 additions & 1 deletion Resources/public/css/grid.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
}

.pedroteixeira-grid-wrapper table thead tr th .date-input {
width: 70px;
width: 75px;
}

.pedroteixeira-grid-wrapper table thead tr th .number-input {
width: 75px;
}

.pedroteixeira-grid-wrapper table tfoot #pagination {
Expand Down
5 changes: 4 additions & 1 deletion Resources/public/less/grid.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
width: auto;
}
.date-input {
width: 70px;
width: 75px;
}
.number-input {
width: 75px;
}
}
}
Expand Down

0 comments on commit aa22dd4

Please sign in to comment.