From fb49b6e846cb396645690480380b92f23f138ea1 Mon Sep 17 00:00:00 2001 From: arseniew Date: Thu, 7 Nov 2013 15:05:54 +0100 Subject: [PATCH 1/3] Update Datatable.php Fixed issue that was preventing ability to join one column multiple times. --- Datatables/Datatable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Datatables/Datatable.php b/Datatables/Datatable.php index a65fdf1..bf193d8 100755 --- a/Datatables/Datatable.php +++ b/Datatables/Datatable.php @@ -313,7 +313,7 @@ protected function setRelatedEntityColumnInfo(array &$association, array $fields $metadata = $this->em->getClassMetadata( $metadata->getAssociationTargetClass($entityName) ); - $joinName .= '_' . $this->getJoinName( + $joinName .= $field.'_' . $this->getJoinName( $metadata, Container::camelize($metadata->getTableName()), $entityName From c590179ce6751dd37c41a726e00552cae79d2b44 Mon Sep 17 00:00:00 2001 From: arseniew Date: Mon, 2 Dec 2013 14:30:34 +0100 Subject: [PATCH 2/3] Conditional case-insensitive search added --- Datatables/Datatable.php | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Datatables/Datatable.php b/Datatables/Datatable.php index bf193d8..fa32694 100755 --- a/Datatables/Datatable.php +++ b/Datatables/Datatable.php @@ -78,6 +78,11 @@ class Datatable * @var boolean Whether to hide the filtered count if using pre-filter callbacks */ protected $hideFilteredCount = true; + + /** + * @var boolean Whether to use case-insensitive search + */ + protected $caseInsensitiveSearch = false; /** * @var string Whether or not to add DT_RowId to each record @@ -435,6 +440,16 @@ public function hideFilteredCount($hideFilteredCount) return $this; } + + /** + * @param boolean Wheter to use case-insensitive search (Depends on database support) + */ + public function caseInsensitiveSearch($caseInsensitiveSearch) + { + $this->caseInsensitiveSearch = bool $caseInsensitiveSearch; + + return $this; + } /** * Set the scope of the result set @@ -479,12 +494,18 @@ public function setWhere(QueryBuilder $qb) $orExpr = $qb->expr()->orX(); for ($i=0 ; $i < count($this->parameters); $i++) { if (isset($this->request['bSearchable_'.$i]) && $this->request['bSearchable_'.$i] == "true") { + $field = $this->associations[$i]['fullName']; + $value = $this->request['sSearch']; + if ($this->caseInsensitiveSearch) { + $field = "LOWER({$field})"; + $value = mb_convert_case($value, MB_CASE_LOWER); + } $qbParam = "sSearch_global_{$this->associations[$i]['entityName']}_{$this->associations[$i]['fieldName']}"; $orExpr->add($qb->expr()->like( - $this->associations[$i]['fullName'], + $field, ":$qbParam" )); - $qb->setParameter($qbParam, "%" . $this->request['sSearch'] . "%"); + $qb->setParameter($qbParam, "%" . $value . "%"); } } $qb->where($orExpr); @@ -495,11 +516,17 @@ public function setWhere(QueryBuilder $qb) for ($i=0 ; $i < count($this->parameters); $i++) { if (isset($this->request['bSearchable_'.$i]) && $this->request['bSearchable_'.$i] == "true" && $this->request['sSearch_'.$i] != '') { $qbParam = "sSearch_single_{$this->associations[$i]['entityName']}_{$this->associations[$i]['fieldName']}"; + $field = $this->associations[$i]['fullName']; + $value = $this->request['sSearch_'.$i]; + if ($this->caseInsensitiveSearch) { + $field = "LOWER({$field})"; + $value = mb_convert_case($value, MB_CASE_LOWER); + } $andExpr->add($qb->expr()->like( - $this->associations[$i]['fullName'], + $field, ":$qbParam" )); - $qb->setParameter($qbParam, "%" . $this->request['sSearch_'.$i] . "%"); + $qb->setParameter($qbParam, "%" . $value . "%"); } } if ($andExpr->count() > 0) { From 3711da2fe0580e8429b93c8ba9b5757cc7b15967 Mon Sep 17 00:00:00 2001 From: arseniew Date: Mon, 2 Dec 2013 15:11:34 +0100 Subject: [PATCH 3/3] bugfix --- Datatables/Datatable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Datatables/Datatable.php b/Datatables/Datatable.php index fa32694..fbd3f84 100755 --- a/Datatables/Datatable.php +++ b/Datatables/Datatable.php @@ -446,7 +446,7 @@ public function hideFilteredCount($hideFilteredCount) */ public function caseInsensitiveSearch($caseInsensitiveSearch) { - $this->caseInsensitiveSearch = bool $caseInsensitiveSearch; + $this->caseInsensitiveSearch = (bool) $caseInsensitiveSearch; return $this; }