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

Fixed issue that was preventing ability to join one column multiple times. #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions Datatables/Datatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -313,7 +318,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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down