Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Enable multi-column search (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlakis authored Sep 25, 2020
1 parent bb3565c commit 9a27532
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .php_cs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"php":"7.4.8","version":"2.16.4:v2.16.4#1023c3458137ab052f6ff1e09621a721bfdeca13","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"ordered_imports":{"sort_algorithm":"length"}},"hashes":{"src\/Repository\/AbstractPaginatorRepository.php":1476324894,"src\/Repository\/PaginatorConfigInterface.php":1383826169,"src\/Repository\/PaginationQueryManagerInterface.php":2483929998,"src\/Helper\/NativeSqlHelper.php":1346947594,"src\/Particle\/ParticleFilterFactory.php":3398098011,"tests\/phpunit\/Rule\/UpperCaseCharacterRuleTest.php":3187295278,"tests\/phpunit\/Rule\/MinimumLengthRuleTest.php":1503783452,"tests\/phpunit\/Rule\/AllRulesTest.php":1356751865,"tests\/phpunit\/Rule\/SpecialCharacterRuleTest.php":1220784808,"tests\/phpunit\/Rule\/DigitRuleTest.php":2593523549,"tests\/phpunit\/Format\/HumanReadablePolicyTest.php":2918699308,"tests\/phpunit\/Policy\/JsonPolicyTest.php":1409930937,"src\/GridPaginator.php":2986785666,"src\/Repository\/Filter.php":2062942533,"src\/Paginator.php":1549210670}}
{"php":"7.4.8","version":"2.16.4:v2.16.4#1023c3458137ab052f6ff1e09621a721bfdeca13","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"ordered_imports":{"sort_algorithm":"length"}},"hashes":{"src\/Repository\/AbstractPaginatorRepository.php":1476324894,"src\/Repository\/PaginationQueryManagerInterface.php":2483929998,"src\/Helper\/NativeSqlHelper.php":1346947594,"src\/Particle\/ParticleFilterFactory.php":3398098011,"tests\/phpunit\/Rule\/UpperCaseCharacterRuleTest.php":3187295278,"tests\/phpunit\/Rule\/MinimumLengthRuleTest.php":1503783452,"tests\/phpunit\/Rule\/AllRulesTest.php":1356751865,"tests\/phpunit\/Rule\/SpecialCharacterRuleTest.php":1220784808,"tests\/phpunit\/Rule\/DigitRuleTest.php":2593523549,"tests\/phpunit\/Format\/HumanReadablePolicyTest.php":2918699308,"tests\/phpunit\/Policy\/JsonPolicyTest.php":1409930937,"src\/Repository\/Filter.php":2062942533,"src\/Paginator.php":1549210670,"src\/GridPaginator.php":535333795,"src\/Repository\/PaginatorConfigInterface.php":2959026211,"tests\/phpunit\/Repository\/FilterTest.php":3979093524}}
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":853:{a:2:{s:7:"defects";a:2:{s:7:"Warning";i:6;s:82:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_multiple_mind_maps";i:4;}s:5:"times";a:7:{s:7:"Warning";d:0.004;s:85:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::invalid_type_throws_exception";d:0.002;s:82:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_multiple_mind_maps";d:0.001;s:105:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_bind_map_with_valid_type with data set #0";d:0.004;s:105:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_bind_map_with_valid_type with data set #1";d:0;s:105:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_bind_map_with_valid_type with data set #2";d:0;s:105:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_bind_map_with_valid_type with data set #3";d:0;}}}
C:37:"PHPUnit\Runner\DefaultTestResultCache":947:{a:2:{s:7:"defects";a:2:{s:7:"Warning";i:6;s:82:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_multiple_mind_maps";i:4;}s:5:"times";a:8:{s:7:"Warning";d:0.004;s:85:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::invalid_type_throws_exception";d:0.001;s:82:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_multiple_mind_maps";d:0;s:105:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_bind_map_with_valid_type with data set #0";d:0.005;s:105:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_bind_map_with_valid_type with data set #1";d:0;s:105:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_bind_map_with_valid_type with data set #2";d:0;s:105:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_bind_map_with_valid_type with data set #3";d:0;s:82:"StaySafe\Paginator\DataGrid\Test\Repository\FilterTest::can_add_multiple_bind_maps";d:0.001;}}}
21 changes: 21 additions & 0 deletions src/GridPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ public function sanitizeGridMetaData($gridMetaData): array
$this->filter->value('search')->defaults([]);
$this->filter->value('sort')->defaults([]);

$this->decodeSearchQuery($gridMetaData);

return $this->filter->filter($gridMetaData);
}

private function decodeSearchQuery(array &$gridMetaData): void
{
if (isset($gridMetaData['search']['all']) && \is_string($gridMetaData['search']['all'])) {
$search = \trim($gridMetaData['search']['all']);
if ('' === $search) {
return;
}
if ('%' === $search[0]) {
$search = substr($search, 1);
}

if ('%' === \substr($search, -1)) {
$search = substr($search, 0, -1);
}

$gridMetaData['search']['all'] = '%'.\urldecode($search).'%';
}
}
}
10 changes: 10 additions & 0 deletions src/Repository/PaginatorConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@

namespace StaySafe\Paginator\DataGrid\Repository;

/**
* Specify the list of columns across all tables used.
* For multi-column search, add an entry with 'concat_ws'
* e.g. "concat_ws(' ', u.first_name, u.last_name)"
*/
interface PaginatorConfigInterface
{
/**
* Returns an array with all the filtered fields which will
* be added in the WHERE clause with the search data.
* e.g. ['u.first_name'] will result to "u.first_name LIKE :allSearch"
* where ':allSearch' will be replaced with the submitted data within '%'
*
* @return array<int, string>
*/
public function getFilterableFields(): array;
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Repository/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function invalid_type_throws_exception(): void
/**
* @test
*/
public function can_add_multiple_mind_maps(): void
public function can_add_multiple_bind_maps(): void
{
$filter = new Filter('', []);
$bindings = [
Expand Down

0 comments on commit 9a27532

Please sign in to comment.