Skip to content

Commit

Permalink
Filtering fix
Browse files Browse the repository at this point in the history
When filtering you can not use the alias for WHERE #66
Convert columns as raw if they contain a parenthesis
  • Loading branch information
MarkVaughn committed Jan 5, 2014
1 parent aed14a6 commit f68d685
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Bllim/Datatables/Datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @package Laravel
* @category Bundle
* @version 1.3.1
* @version 1.3.3
* @author Bilal Gultekin <[email protected]>
*/

Expand Down Expand Up @@ -345,7 +345,7 @@ private function ordering()

if(!is_null(Input::get('iSortCol_0')))
{
$columns = $this->cleanColumns( $this->last_columns );
$columns = $this->clean_columns( $this->last_columns );

for ( $i=0, $c=intval(Input::get('iSortingCols')); $i<$c ; $i++ )
{
Expand All @@ -360,15 +360,16 @@ private function ordering()
}
/**
* @param array $cols
* @param bool $use_alias weather to get the column/function or the alias
* @return array
*/
private function cleanColumns( $cols )
private function clean_columns( $cols, $use_alias = true)
{
$return = array();
foreach ( $cols as $i=> $col )
{
preg_match('#^(.*?)\s+as\s+(\S*?)$#si',$col,$matches);
$return[$i] = empty($matches) ? $col : $matches[2];
$return[$i] = empty($matches) ? $col : $matches[$use_alias?2:1];
}

return $return;
Expand All @@ -382,7 +383,7 @@ private function cleanColumns( $cols )

private function filtering()
{
$columns = $this->cleanColumns( $this->columns );
$columns = $this->clean_columns( $this->columns, false );

if (Input::get('sSearch','') != '')
{
Expand Down Expand Up @@ -448,7 +449,8 @@ private function filtering()
$column = $db_prefix . $columns[$i];
$this->query->where(DB::raw('LOWER('.$column.')'),'LIKE', $keyword);
} else {
$this->query->where($columns[$i], 'LIKE', $keyword);
$col = strstr($columns[$i],'(')?DB::raw($columns[$i]):$columns[$i];
$this->query->where($col], 'LIKE', $keyword);
}
}
}
Expand Down

0 comments on commit f68d685

Please sign in to comment.