7
7
* @package Laravel
8
8
* @category Package
9
9
* @author Arjay Angeles <aqangeles@gmail.com>
10
- * @version 3.6.4
10
+ * @version 3.6.5
11
11
*/
12
12
13
13
use Closure ;
24
24
25
25
class Datatables
26
26
{
27
-
28
27
/**
29
28
* Database connection used
30
29
*
@@ -201,38 +200,38 @@ public function processData($input = [])
201
200
$ formatted_input = [];
202
201
if (isset ($ input ['draw ' ])) {
203
202
// DT version 1.10+
204
- $ input ['version ' ] = '1.10 ' ;
205
- $ formatted_input = $ input ;
203
+ $ input ['version ' ] = '1.10 ' ;
204
+ $ formatted_input = $ input ;
206
205
$ this ->new_version = true ;
207
206
} else {
208
207
// DT version < 1.10
209
208
$ formatted_input ['version ' ] = '1.9 ' ;
210
- $ formatted_input ['draw ' ] = Arr::get ($ input , 'sEcho ' , '' );
211
- $ formatted_input ['start ' ] = Arr::get ($ input , 'iDisplayStart ' , 0 );
212
- $ formatted_input ['length ' ] = Arr::get ($ input , 'iDisplayLength ' , 10 );
213
- $ formatted_input ['search ' ] = [
209
+ $ formatted_input ['draw ' ] = Arr::get ($ input , 'sEcho ' , '' );
210
+ $ formatted_input ['start ' ] = Arr::get ($ input , 'iDisplayStart ' , 0 );
211
+ $ formatted_input ['length ' ] = Arr::get ($ input , 'iDisplayLength ' , 10 );
212
+ $ formatted_input ['search ' ] = [
214
213
'value ' => Arr::get ($ input , 'sSearch ' , '' ),
215
214
'regex ' => Arr::get ($ input , 'bRegex ' , '' ),
216
215
];
217
- $ formatted_input ['_ ' ] = Arr::get ($ input , '_ ' , '' );
218
- $ columns = explode (', ' , Arr::get ($ input , 'sColumns ' , '' ));
216
+ $ formatted_input ['_ ' ] = Arr::get ($ input , '_ ' , '' );
217
+ $ columns = explode (', ' , Arr::get ($ input , 'sColumns ' , '' ));
219
218
$ formatted_input ['columns ' ] = [];
220
219
for ($ i = 0 ; $ i < Arr::get ($ input , 'iColumns ' , 0 ); $ i ++) {
221
- $ arr = [];
222
- $ arr ['name ' ] = isset ($ columns [$ i ]) ? $ columns [$ i ] : '' ;
223
- $ arr ['data ' ] = Arr::get ($ input , 'mDataProp_ ' . $ i , '' );
224
- $ arr ['searchable ' ] = Arr::get ($ input , 'bSearchable_ ' . $ i , '' );
225
- $ arr ['search ' ] = [];
226
- $ arr ['search ' ]['value ' ] = Arr::get ($ input , 'sSearch_ ' . $ i , '' );
227
- $ arr ['search ' ]['regex ' ] = Arr::get ($ input , 'bRegex_ ' . $ i , '' );
228
- $ arr ['orderable ' ] = Arr::get ($ input , 'bSortable_ ' . $ i , '' );
220
+ $ arr = [];
221
+ $ arr ['name ' ] = isset ($ columns [$ i ]) ? $ columns [$ i ] : '' ;
222
+ $ arr ['data ' ] = Arr::get ($ input , 'mDataProp_ ' . $ i , '' );
223
+ $ arr ['searchable ' ] = Arr::get ($ input , 'bSearchable_ ' . $ i , '' );
224
+ $ arr ['search ' ] = [];
225
+ $ arr ['search ' ]['value ' ] = Arr::get ($ input , 'sSearch_ ' . $ i , '' );
226
+ $ arr ['search ' ]['regex ' ] = Arr::get ($ input , 'bRegex_ ' . $ i , '' );
227
+ $ arr ['orderable ' ] = Arr::get ($ input , 'bSortable_ ' . $ i , '' );
229
228
$ formatted_input ['columns ' ][] = $ arr ;
230
229
}
231
230
$ formatted_input ['order ' ] = [];
232
231
for ($ i = 0 ; $ i < Arr::get ($ input , 'iSortingCols ' , 0 ); $ i ++) {
233
- $ arr = [];
234
- $ arr ['column ' ] = Arr::get ($ input , 'iSortCol_ ' . $ i , '' );
235
- $ arr ['dir ' ] = Arr::get ($ input , 'sSortDir_ ' . $ i , '' );
232
+ $ arr = [];
233
+ $ arr ['column ' ] = Arr::get ($ input , 'iSortCol_ ' . $ i , '' );
234
+ $ arr ['dir ' ] = Arr::get ($ input , 'sSortDir_ ' . $ i , '' );
236
235
$ formatted_input ['order ' ][] = $ arr ;
237
236
}
238
237
}
@@ -273,13 +272,13 @@ public static function of($builder)
273
272
274
273
if ($ builder instanceof QueryBuilder) {
275
274
$ ins ->query_type = 'builder ' ;
276
- $ ins ->query = $ builder ;
277
- $ ins ->columns = $ ins ->query ->columns ;
275
+ $ ins ->query = $ builder ;
276
+ $ ins ->columns = $ ins ->query ->columns ;
278
277
$ ins ->connection = $ ins ->query ->getConnection ();
279
278
} else {
280
279
$ ins ->query_type = 'eloquent ' ;
281
- $ ins ->query = $ builder instanceof EloquentBuilder ? $ builder : $ builder ->getQuery ();
282
- $ ins ->columns = $ ins ->query ->getQuery ()->columns ;
280
+ $ ins ->query = $ builder instanceof EloquentBuilder ? $ builder : $ builder ->getQuery ();
281
+ $ ins ->columns = $ ins ->query ->getQuery ()->columns ;
283
282
$ ins ->connection = $ ins ->query ->getQuery ()->getConnection ();
284
283
}
285
284
@@ -298,7 +297,7 @@ private function getColumnName($str)
298
297
{
299
298
preg_match ('#^(\S*?)\s+as\s+(\S*?)$#si ' , $ str , $ matches );
300
299
301
- if ( ! empty ($ matches )) {
300
+ if (! empty ($ matches )) {
302
301
return $ matches [2 ];
303
302
} elseif (strpos ($ str , '. ' )) {
304
303
$ array = explode ('. ' , $ str );
@@ -330,7 +329,7 @@ private function count()
330
329
331
330
// if its a normal query ( no union ) replace the select with static text to improve performance
332
331
$ myQuery = clone $ query ;
333
- if ( ! preg_match ('/UNION/i ' , strtoupper ($ myQuery ->toSql ()))) {
332
+ if (! preg_match ('/UNION/i ' , strtoupper ($ myQuery ->toSql ()))) {
334
333
$ myQuery ->select ($ this ->connection ->raw ("'1' as row_count " ));
335
334
}
336
335
@@ -372,29 +371,29 @@ public function make($mDataSupport = false)
372
371
*/
373
372
private function doFiltering ()
374
373
{
375
- $ input = $ this ->input ;
374
+ $ input = $ this ->input ;
376
375
$ columns = $ input ['columns ' ];
377
376
378
377
// if older version, set the column name to query's fields
379
378
// or if new version but does not use mData support
380
- if ( ! $ this ->new_version or ( ! $ this ->mDataSupport and $ this ->new_version )) {
379
+ if (! $ this ->new_version or (! $ this ->mDataSupport and $ this ->new_version )) {
381
380
for ($ i = 0 ; $ i < count ($ columns ); $ i ++) {
382
- if ( ! isset ($ this ->columns [$ i ])) {
381
+ if (! isset ($ this ->columns [$ i ])) {
383
382
continue ;
384
383
}
385
384
386
385
$ columns [$ i ]['name ' ] = $ this ->columns [$ i ];
387
386
if (stripos ($ columns [$ i ]['name ' ], ' AS ' ) !== false or
388
387
$ columns [$ i ]['name ' ] instanceof Expression
389
388
) {
390
- $ columns [$ i ]['name ' ] = '' ;
389
+ $ columns [$ i ]['name ' ] = '' ;
391
390
$ columns [$ i ]['searchable ' ] = false ;
392
- $ columns [$ i ]['orderable ' ] = false ;
391
+ $ columns [$ i ]['orderable ' ] = false ;
393
392
}
394
393
}
395
394
}
396
395
397
- if ( ! empty ($ this ->input ['search ' ]['value ' ])) {
396
+ if (! empty ($ this ->input ['search ' ]['value ' ])) {
398
397
$ this ->query ->where (function ($ query ) use ($ columns , $ input ) {
399
398
for ($ i = 0 , $ c = count ($ columns ); $ i < $ c ; $ i ++) {
400
399
if ($ columns [$ i ]['searchable ' ] == "true " and ! empty ($ columns [$ i ]['name ' ])) {
@@ -448,7 +447,7 @@ public function doColumnSearch(array $columns)
448
447
{
449
448
for ($ i = 0 , $ c = count ($ columns ); $ i < $ c ; $ i ++) {
450
449
if ($ columns [$ i ]['searchable ' ] == "true " and ! empty ($ columns [$ i ]['search ' ]['value ' ]) and ! empty ($ columns [$ i ]['name ' ])) {
451
- $ column = $ columns [$ i ]['name ' ];
450
+ $ column = $ columns [$ i ]['name ' ];
452
451
$ keyword = $ this ->setupKeyword ($ columns [$ i ]['search ' ]['value ' ]);
453
452
454
453
// wrap column possibly allow reserved words to be used as column
@@ -527,7 +526,7 @@ private function cleanColumns($cols, $use_alias = true)
527
526
*/
528
527
public function useDataColumns ()
529
528
{
530
- if ( ! count ($ this ->result_array_r )) {
529
+ if (! count ($ this ->result_array_r )) {
531
530
return [];
532
531
}
533
532
@@ -550,7 +549,7 @@ public function useDataColumns()
550
549
*/
551
550
public function wildcardLikeString ($ str , $ lowercase = true )
552
551
{
553
- $ wild = '% ' ;
552
+ $ wild = '% ' ;
554
553
$ length = strlen ($ str );
555
554
if ($ length ) {
556
555
for ($ i = 0 ; $ i < $ length ; $ i ++) {
@@ -590,13 +589,13 @@ protected function prefixColumn($column)
590
589
*/
591
590
protected function tableNames ()
592
591
{
593
- $ names = [];
594
- $ query = ($ this ->query_type == 'builder ' ) ? $ this ->query : $ this ->query ->getQuery ();
595
- $ names [] = $ query ->from ;
596
- $ joins = $ query ->joins ?: [];
592
+ $ names = [];
593
+ $ query = ($ this ->query_type == 'builder ' ) ? $ this ->query : $ this ->query ->getQuery ();
594
+ $ names [] = $ query ->from ;
595
+ $ joins = $ query ->joins ?: [];
597
596
$ databasePrefix = $ this ->databasePrefix ();
598
597
foreach ($ joins as $ join ) {
599
- $ table = preg_split ("/ as /i " , $ join ->table );
598
+ $ table = preg_split ("/ as /i " , $ join ->table );
600
599
$ names [] = $ table [0 ];
601
600
if (isset ($ table [1 ]) && ! empty ($ databasePrefix ) && strpos ($ table [1 ], $ databasePrefix ) == 0 ) {
602
601
$ names [] = preg_replace ('/^ ' . $ databasePrefix . '/ ' , '' , $ table [1 ]);
@@ -639,7 +638,7 @@ private function getFilteredRecords()
639
638
*/
640
639
private function doPaging ()
641
640
{
642
- if ( ! is_null ($ this ->input ['start ' ]) && ! is_null ($ this ->input ['length ' ]) && $ this ->input ['length ' ] != -1 ) {
641
+ if (! is_null ($ this ->input ['start ' ]) && ! is_null ($ this ->input ['length ' ]) && $ this ->input ['length ' ] != -1 ) {
643
642
$ this ->query ->skip ($ this ->input ['start ' ])
644
643
->take ((int ) $ this ->input ['length ' ] > 0 ? $ this ->input ['length ' ] : 10 );
645
644
}
@@ -717,22 +716,22 @@ private function initColumns()
717
716
718
717
// Process add columns
719
718
foreach ($ this ->extra_columns as $ key => $ value ) {
720
- if (is_string ($ value ['content ' ])):
719
+ if (is_string ($ value ['content ' ])) {
721
720
$ value ['content ' ] = $ this ->blader ($ value ['content ' ], $ data );
722
- elseif (is_callable ($ value ['content ' ])):
721
+ } elseif (is_callable ($ value ['content ' ])) {
723
722
$ value ['content ' ] = $ value ['content ' ]($ this ->result_object [$ rkey ]);
724
- endif ;
723
+ }
725
724
726
725
$ rvalue = $ this ->includeInArray ($ value , $ rvalue );
727
726
}
728
727
729
728
// Process edit columns
730
729
foreach ($ this ->edit_columns as $ key => $ value ) {
731
- if (is_string ($ value ['content ' ])):
730
+ if (is_string ($ value ['content ' ])) {
732
731
$ value ['content ' ] = $ this ->blader ($ value ['content ' ], $ data );
733
- elseif (is_callable ($ value ['content ' ])):
732
+ } elseif (is_callable ($ value ['content ' ])) {
734
733
$ value ['content ' ] = $ value ['content ' ]($ this ->result_object [$ rkey ]);
735
- endif ;
734
+ }
736
735
737
736
$ rvalue [$ value ['name ' ]] = $ value ['content ' ];
738
737
}
@@ -747,8 +746,8 @@ private function initColumns()
747
746
private function blader ($ str , $ data = [])
748
747
{
749
748
$ empty_filesystem_instance = new Filesystem ;
750
- $ blade = new BladeCompiler ($ empty_filesystem_instance , 'datatables ' );
751
- $ parsed_string = $ blade ->compileString ($ str );
749
+ $ blade = new BladeCompiler ($ empty_filesystem_instance , 'datatables ' );
750
+ $ parsed_string = $ blade ->compileString ($ str );
752
751
753
752
ob_start () and extract ($ data , EXTR_SKIP );
754
753
@@ -776,7 +775,7 @@ private function includeInArray($item, $array)
776
775
return array_merge ($ array , [$ item ['name ' ] => $ item ['content ' ]]);
777
776
} else {
778
777
$ count = 0 ;
779
- $ last = $ array ;
778
+ $ last = $ array ;
780
779
$ first = [];
781
780
foreach ($ array as $ key => $ value ) {
782
781
if ($ count == $ item ['order ' ]) {
@@ -820,16 +819,16 @@ private function regulateArray()
820
819
*/
821
820
protected function setupDTRowVariables ($ key , array &$ data )
822
821
{
823
- if ( ! empty ($ this ->row_id_tmpl )) {
824
- if ( ! is_callable ($ this ->row_id_tmpl ) and Arr::get ($ data , $ this ->row_id_tmpl )) {
822
+ if (! empty ($ this ->row_id_tmpl )) {
823
+ if (! is_callable ($ this ->row_id_tmpl ) and Arr::get ($ data , $ this ->row_id_tmpl )) {
825
824
$ data ['DT_RowId ' ] = Arr::get ($ data , $ this ->row_id_tmpl );
826
825
} else {
827
826
$ data ['DT_RowId ' ] = $ this ->getContent ($ this ->row_id_tmpl , $ data , $ this ->result_object [$ key ]);
828
827
}
829
828
}
830
829
831
- if ( ! empty ($ this ->row_class_tmpl )) {
832
- if ( ! is_callable ($ this ->row_class_tmpl ) and Arr::get ($ data , $ this ->row_class_tmpl )) {
830
+ if (! empty ($ this ->row_class_tmpl )) {
831
+ if (! is_callable ($ this ->row_class_tmpl ) and Arr::get ($ data , $ this ->row_class_tmpl )) {
833
832
$ data ['DT_RowClass ' ] = Arr::get ($ data , $ this ->row_class_tmpl );
834
833
} else {
835
834
$ data ['DT_RowClass ' ] = $ this ->getContent ($ this ->row_class_tmpl , $ data , $ this ->result_object [$ key ]);
@@ -849,7 +848,6 @@ protected function setupDTRowVariables($key, array &$data)
849
848
$ data ['DT_RowAttr ' ][$ tkey ] = $ this ->getContent ($ tvalue , $ data , $ this ->result_object [$ key ]);
850
849
}
851
850
}
852
-
853
851
}
854
852
855
853
/**
@@ -883,7 +881,7 @@ private function output()
883
881
];
884
882
} else {
885
883
$ sColumns = $ this ->getOutputColumns ();
886
- $ output = [
884
+ $ output = [
887
885
"sEcho " => (int ) $ this ->input ['draw ' ],
888
886
"iTotalRecords " => $ this ->totalRecords ,
889
887
"iTotalDisplayRecords " => $ this ->filteredRecords ,
@@ -950,7 +948,7 @@ public function editColumn($name, $content)
950
948
*/
951
949
public function removeColumn ()
952
950
{
953
- $ names = func_get_args ();
951
+ $ names = func_get_args ();
954
952
$ this ->excess_columns = array_merge ($ this ->excess_columns , $ names );
955
953
956
954
return $ this ;
@@ -991,7 +989,7 @@ protected function databaseDriver()
991
989
*/
992
990
protected function wrapColumn ($ value )
993
991
{
994
- $ parts = explode ('. ' , $ value );
992
+ $ parts = explode ('. ' , $ value );
995
993
$ column = '' ;
996
994
foreach ($ parts as $ key ) {
997
995
switch ($ this ->databaseDriver ()) {
@@ -1128,5 +1126,4 @@ protected function addRowAttr($key, $value)
1128
1126
1129
1127
return $ this ;
1130
1128
}
1131
-
1132
1129
}
0 commit comments