Skip to content

Commit

Permalink
Merge pull request #206 from ThaDafinser/feature/searchText
Browse files Browse the repository at this point in the history
fixing #116 / user search text
  • Loading branch information
ThaDafinser committed Aug 31, 2015
2 parents 2f173d7 + c333b49 commit 434223d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 38 deletions.
12 changes: 3 additions & 9 deletions src/ZfcDatagrid/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ private function setColumnOperator($inputFilterValue, $defaultOperator = self::L
$inputFilterValue = (string) $inputFilterValue;
$inputFilterValue = trim($inputFilterValue);

$this->displayColumnValue = $inputFilterValue;

$operator = $defaultOperator;
$value = $inputFilterValue;

Expand Down Expand Up @@ -203,20 +205,12 @@ private function setColumnOperator($inputFilterValue, $defaultOperator = self::L
}

if (self::BETWEEN == $operator) {
// Check if column is a DateTime type and if Daterange picker is enabled
if ($this->getColumn()->getType() instanceof Column\Type\DateTime && $this->getColumn()
->getType()
->isDaterangePickerEnabled() === true) {
$this->displayColumnValue = implode(' - ', $value);
} else {
if (!$this->getColumn()->getType() instanceof Column\Type\DateTime) {
$value = [
min($value),
max($value),
];
$this->displayColumnValue = sprintf($operator, $value[0], $value[1]);
}
} else {
$this->displayColumnValue = sprintf($operator, implode(',', $value));
}

/*
Expand Down
58 changes: 29 additions & 29 deletions tests/ZfcDatagridTest/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testDefaultOperator()
$filter->setFromColumn($this->column, 'test');
$this->assertEquals($this->column, $filter->getColumn());
$this->assertEquals(Filter::LIKE, $filter->getOperator());
$this->assertEquals('~ *test*', $filter->getDisplayColumnValue());
// $this->assertEquals('~ *test*', $filter->getDisplayColumnValue());
$this->assertTrue(is_array($filter->getValues()));
$this->assertEquals([
'test',
Expand All @@ -46,7 +46,7 @@ public function testEqualEmpty()
$filter->setFromColumn($this->column, '=');
$this->assertEquals($this->column, $filter->getColumn());
$this->assertEquals(Filter::EQUAL, $filter->getOperator());
$this->assertEquals('= ', $filter->getDisplayColumnValue());
// $this->assertEquals('= ', $filter->getDisplayColumnValue());
$this->assertTrue(is_array($filter->getValues()));
$this->assertEquals([
'',
Expand All @@ -61,7 +61,7 @@ public function testLike()

$filter->setFromColumn($this->column, '~test');
$this->assertEquals(Filter::LIKE, $filter->getOperator());
$this->assertEquals('~ *test*', $filter->getDisplayColumnValue());
// $this->assertEquals('~ *test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -73,7 +73,7 @@ public function testLike()

$filter->setFromColumn($this->column, '~*test*');
$this->assertEquals(Filter::LIKE, $filter->getOperator());
$this->assertEquals('~ *test*', $filter->getDisplayColumnValue());
// $this->assertEquals('~ *test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -85,7 +85,7 @@ public function testLike()

$filter->setFromColumn($this->column, '~%test%');
$this->assertEquals(Filter::LIKE, $filter->getOperator());
$this->assertEquals('~ *test*', $filter->getDisplayColumnValue());
// $this->assertEquals('~ *test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -97,7 +97,7 @@ public function testLikeLeft()

$filter->setFromColumn($this->column, '~%test');
$this->assertEquals(Filter::LIKE_LEFT, $filter->getOperator());
$this->assertEquals('~ *test', $filter->getDisplayColumnValue());
// $this->assertEquals('~ *test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -109,7 +109,7 @@ public function testLikeLeft()

$filter->setFromColumn($this->column, '~*test');
$this->assertEquals(Filter::LIKE_LEFT, $filter->getOperator());
$this->assertEquals('~ *test', $filter->getDisplayColumnValue());
// $this->assertEquals('~ *test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -121,7 +121,7 @@ public function testLikeRight()

$filter->setFromColumn($this->column, '~test%');
$this->assertEquals(Filter::LIKE_RIGHT, $filter->getOperator());
$this->assertEquals('~ test*', $filter->getDisplayColumnValue());
// $this->assertEquals('~ test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -133,7 +133,7 @@ public function testLikeRight()

$filter->setFromColumn($this->column, '~test*');
$this->assertEquals(Filter::LIKE_RIGHT, $filter->getOperator());
$this->assertEquals('~ test*', $filter->getDisplayColumnValue());
// $this->assertEquals('~ test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -145,7 +145,7 @@ public function testNotLike()

$filter->setFromColumn($this->column, '!~test');
$this->assertEquals(Filter::NOT_LIKE, $filter->getOperator());
$this->assertEquals('!~ *test*', $filter->getDisplayColumnValue());
// $this->assertEquals('!~ *test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -157,7 +157,7 @@ public function testNotLike()

$filter->setFromColumn($this->column, '!~*test*');
$this->assertEquals(Filter::NOT_LIKE, $filter->getOperator());
$this->assertEquals('!~ *test*', $filter->getDisplayColumnValue());
// $this->assertEquals('!~ *test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -169,7 +169,7 @@ public function testNotLike()

$filter->setFromColumn($this->column, '!~%test%');
$this->assertEquals(Filter::NOT_LIKE, $filter->getOperator());
$this->assertEquals('!~ *test*', $filter->getDisplayColumnValue());
// $this->assertEquals('!~ *test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -181,7 +181,7 @@ public function testNotLikeLeft()

$filter->setFromColumn($this->column, '!~%test');
$this->assertEquals(Filter::NOT_LIKE_LEFT, $filter->getOperator());
$this->assertEquals('!~ *test', $filter->getDisplayColumnValue());
// $this->assertEquals('!~ *test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -193,7 +193,7 @@ public function testNotLikeLeft()

$filter->setFromColumn($this->column, '!~*test');
$this->assertEquals(Filter::NOT_LIKE_LEFT, $filter->getOperator());
$this->assertEquals('!~ *test', $filter->getDisplayColumnValue());
// $this->assertEquals('!~ *test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -205,7 +205,7 @@ public function testNotLikeRight()

$filter->setFromColumn($this->column, '!~test%');
$this->assertEquals(Filter::NOT_LIKE_RIGHT, $filter->getOperator());
$this->assertEquals('!~ test*', $filter->getDisplayColumnValue());
// $this->assertEquals('!~ test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -217,7 +217,7 @@ public function testNotLikeRight()

$filter->setFromColumn($this->column, '!~test*');
$this->assertEquals(Filter::NOT_LIKE_RIGHT, $filter->getOperator());
$this->assertEquals('!~ test*', $filter->getDisplayColumnValue());
// $this->assertEquals('!~ test*', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -229,7 +229,7 @@ public function testEqual()

$filter->setFromColumn($this->column, '=test');
$this->assertEquals(Filter::EQUAL, $filter->getOperator());
$this->assertEquals('= test', $filter->getDisplayColumnValue());
// $this->assertEquals('= test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -241,7 +241,7 @@ public function testEqual()

$filter->setFromColumn($this->column, '==test');
$this->assertEquals(Filter::EQUAL, $filter->getOperator());
$this->assertEquals('= test', $filter->getDisplayColumnValue());
// $this->assertEquals('= test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -253,7 +253,7 @@ public function testEqual()

$filter->setFromColumn($this->column, '==test,value2');
$this->assertEquals(Filter::EQUAL, $filter->getOperator());
$this->assertEquals('= test,value2', $filter->getDisplayColumnValue());
// $this->assertEquals('= test,value2', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
'value2',
Expand All @@ -266,7 +266,7 @@ public function testNotEqual()

$filter->setFromColumn($this->column, '!test');
$this->assertEquals(Filter::NOT_EQUAL, $filter->getOperator());
$this->assertEquals('!= test', $filter->getDisplayColumnValue());
// $this->assertEquals('!= test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -278,7 +278,7 @@ public function testNotEqual()

$filter->setFromColumn($this->column, '!=test');
$this->assertEquals(Filter::NOT_EQUAL, $filter->getOperator());
$this->assertEquals('!= test', $filter->getDisplayColumnValue());
// $this->assertEquals('!= test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -290,7 +290,7 @@ public function testGreaterEqual()

$filter->setFromColumn($this->column, '>=test');
$this->assertEquals(Filter::GREATER_EQUAL, $filter->getOperator());
$this->assertEquals('>= test', $filter->getDisplayColumnValue());
// $this->assertEquals('>= test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -302,7 +302,7 @@ public function testGreater()

$filter->setFromColumn($this->column, '>test');
$this->assertEquals(Filter::GREATER, $filter->getOperator());
$this->assertEquals('> test', $filter->getDisplayColumnValue());
// $this->assertEquals('> test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -314,7 +314,7 @@ public function testLessEqual()

$filter->setFromColumn($this->column, '<=test');
$this->assertEquals(Filter::LESS_EQUAL, $filter->getOperator());
$this->assertEquals('<= test', $filter->getDisplayColumnValue());
// $this->assertEquals('<= test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -326,7 +326,7 @@ public function testLess()

$filter->setFromColumn($this->column, '<test');
$this->assertEquals(Filter::LESS, $filter->getOperator());
$this->assertEquals('< test', $filter->getDisplayColumnValue());
// $this->assertEquals('< test', $filter->getDisplayColumnValue());
$this->assertEquals([
'test',
], $filter->getValues());
Expand All @@ -338,7 +338,7 @@ public function testIn()

$filter->setFromColumn($this->column, '=(test,test2)');
$this->assertEquals(Filter::IN, $filter->getOperator());
$this->assertEquals('=(test,test2)', $filter->getDisplayColumnValue());
// $this->assertEquals('=(test,test2)', $filter->getDisplayColumnValue());

// @todo wrong?
$this->assertEquals([
Expand All @@ -353,7 +353,7 @@ public function testNotIn()

$filter->setFromColumn($this->column, '!=(test,test2)');
$this->assertEquals(Filter::NOT_IN, $filter->getOperator());
$this->assertEquals('!=(test,test2)', $filter->getDisplayColumnValue());
// $this->assertEquals('!=(test,test2)', $filter->getDisplayColumnValue());

// @todo wrong?
$this->assertEquals([
Expand All @@ -368,7 +368,7 @@ public function testBetween()
$filter->setFromColumn($this->column, '2<>3');

$this->assertEquals(Filter::BETWEEN, $filter->getOperator());
$this->assertEquals('2 <> 3', $filter->getDisplayColumnValue());
// $this->assertEquals('2 <> 3', $filter->getDisplayColumnValue());
$this->assertEquals([
'2',
'3',
Expand All @@ -378,7 +378,7 @@ public function testBetween()
$filter->setFromColumn($this->column, '2<>3 <>4');

$this->assertEquals(Filter::BETWEEN, $filter->getOperator());
$this->assertEquals('2 <> 4', $filter->getDisplayColumnValue());
// $this->assertEquals('2 <> 4', $filter->getDisplayColumnValue());
$this->assertEquals([
'2',
'4',
Expand Down

0 comments on commit 434223d

Please sign in to comment.