Skip to content

Commit aed14a6

Browse files
committed
CleanCollumns function more flexible
get the alias of a column regardless of function name
1 parent 255f016 commit aed14a6

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

src/Bllim/Datatables/Datatables.php

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @package Laravel
99
* @category Bundle
10-
* @version 1.3
10+
* @version 1.3.1
1111
* @author Bilal Gultekin <bilal@bilal.im>
1212
*/
1313

@@ -23,21 +23,22 @@ class Datatables
2323
public $query;
2424
protected $query_type;
2525

26-
protected $extra_columns = array();
27-
protected $excess_columns = array();
28-
protected $edit_columns = array();
29-
protected $sColumns = array();
26+
protected $extra_columns = array();
27+
protected $excess_columns = array();
28+
protected $edit_columns = array();
29+
protected $sColumns = array();
3030

31-
public $columns = array();
31+
public $columns = array();
3232
public $last_columns = array();
3333

3434
protected $count_all = 0;
35+
protected $display_all = 0;
3536

3637
protected $result_object;
37-
protected $result_array = array();
38+
protected $result_array = array();
3839
protected $result_array_r = array();
3940

40-
protected $mDataSupport;
41+
protected $mDataSupport;
4142

4243

4344
/**
@@ -357,33 +358,20 @@ private function ordering()
357358

358359
}
359360
}
360-
361+
/**
362+
* @param array $cols
363+
* @return array
364+
*/
361365
private function cleanColumns( $cols )
362366
{
363-
$_search = [
364-
'GROUP_CONCAT( ',
365-
'CONCAT( ',
366-
'DISTINCT( ',
367-
',',
368-
' )',
369-
'as',
370-
];
371-
372-
foreach ( $cols as $col )
367+
$return = array();
368+
foreach ( $cols as $i=> $col )
373369
{
374-
$_column = explode( ' ' , str_replace( $_search, '', $col, $count ) );
375-
376-
if ( $count > 0 )
377-
{
378-
$columns[] = array_shift( $_column );
379-
}
380-
else
381-
{
382-
$columns[] = end( $_column );
383-
}
370+
preg_match('#^(.*?)\s+as\s+(\S*?)$#si',$col,$matches);
371+
$return[$i] = empty($matches) ? $col : $matches[2];
384372
}
385373

386-
return $columns;
374+
return $return;
387375
}
388376

389377
/**
@@ -411,9 +399,7 @@ private function filtering()
411399
{
412400
if (Input::get('bSearchable_'.$i) == "true")
413401
{
414-
415-
preg_match('#^(.*?)\s+as\s+(\S*?)$#si',$copy_this->columns[$i],$matches);
416-
$column = empty($matches) ? $copy_this->columns[$i] : $matches[1];
402+
$column = $copy_this->columns[$i];
417403

418404
if (stripos($column, ' AS ') !== false){
419405
$column = substr($column, stripos($column, ' AS ')+4);

0 commit comments

Comments
 (0)