@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | $query->addSelect($this->data['table'].'.'.cb()->pk($this->data['table']).' as primary_key'); |
| 27 | 27 | |
| 28 | - $softDelete = isset($this->data['disable_soft_delete'])?$this->data['disable_soft_delete']:true; |
|
| 29 | - if($softDelete === true && SchemaHelper::hasColumn($this->data['table'],'deleted_at')) { |
|
| 28 | + $softDelete = isset($this->data['disable_soft_delete']) ? $this->data['disable_soft_delete'] : true; |
|
| 29 | + if ($softDelete === true && SchemaHelper::hasColumn($this->data['table'], 'deleted_at')) { |
|
| 30 | 30 | $query->whereNull($this->data['table'].'.deleted_at'); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if(isset($joins)) { |
|
| 34 | - foreach($joins as $join) |
|
| 33 | + if (isset($joins)) { |
|
| 34 | + foreach ($joins as $join) |
|
| 35 | 35 | { |
| 36 | 36 | $query->join($join['target_table'], |
| 37 | 37 | $join['target_table_primary'], |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - foreach($columns as $column) { |
|
| 44 | + foreach ($columns as $column) { |
|
| 45 | 45 | /** @var ColumnModel $column */ |
| 46 | - if($column->getType() != "custom") { |
|
| 47 | - if(strpos($column->getField(),".") === false) { |
|
| 48 | - if(SchemaHelper::hasColumn($this->data['table'], $column->getField())) { |
|
| 46 | + if ($column->getType() != "custom") { |
|
| 47 | + if (strpos($column->getField(), ".") === false) { |
|
| 48 | + if (SchemaHelper::hasColumn($this->data['table'], $column->getField())) { |
|
| 49 | 49 | $query->addSelect($this->data['table'].'.'.$column->getField()); |
| 50 | 50 | } |
| 51 | - }else{ |
|
| 51 | + } else { |
|
| 52 | 52 | $query->addSelect($column->getField()); |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -57,27 +57,27 @@ discard block |
||
| 57 | 57 | $query = getTypeHook($column->getType())->query($query, $column); |
| 58 | 58 | |
| 59 | 59 | // Filter Query From Type |
| 60 | - $filterValue = request("filter_".slug($column->getFilterColumn(),"_")); |
|
| 61 | - if(is_array($filterValue) || sanitizeXSS($filterValue)) { |
|
| 60 | + $filterValue = request("filter_".slug($column->getFilterColumn(), "_")); |
|
| 61 | + if (is_array($filterValue) || sanitizeXSS($filterValue)) { |
|
| 62 | 62 | $query = getTypeHook($column->getType())->filterQuery($query, $column, $filterValue); |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if(request()->has('q')) |
|
| 66 | + if (request()->has('q')) |
|
| 67 | 67 | { |
| 68 | 68 | $keyword = sanitizeXSS(request("q")); |
| 69 | - if(isset($this->data['hook_search_query'])) { |
|
| 69 | + if (isset($this->data['hook_search_query'])) { |
|
| 70 | 70 | $query = call_user_func($this->data['hook_search_query'], $query, $keyword); |
| 71 | - }else{ |
|
| 72 | - $query->where(function ($where) use ($columns, $keyword) { |
|
| 71 | + } else { |
|
| 72 | + $query->where(function($where) use ($columns, $keyword) { |
|
| 73 | 73 | /** |
| 74 | 74 | * @var $where Builder |
| 75 | 75 | */ |
| 76 | - foreach($columns as $column) |
|
| 76 | + foreach ($columns as $column) |
|
| 77 | 77 | { |
| 78 | - if(strpos($column->getField(),".") === false) { |
|
| 78 | + if (strpos($column->getField(), ".") === false) { |
|
| 79 | 79 | $field = $this->data['table'].'.'.$column->getField(); |
| 80 | - }else{ |
|
| 80 | + } else { |
|
| 81 | 81 | $field = $column->getField(); |
| 82 | 82 | } |
| 83 | 83 | $where->orWhere($field, 'like', '%'.$keyword.'%'); |
@@ -90,36 +90,36 @@ discard block |
||
| 90 | 90 | /* |
| 91 | 91 | * This script to hanlde the callback inputed on this query method |
| 92 | 92 | */ |
| 93 | - if(isset($callback) && is_callable($callback)) { |
|
| 93 | + if (isset($callback) && is_callable($callback)) { |
|
| 94 | 94 | $query = call_user_func($callback, $query); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if(isset($this->data['hook_index_query']) && is_callable($this->data['hook_index_query'])) { |
|
| 97 | + if (isset($this->data['hook_index_query']) && is_callable($this->data['hook_index_query'])) { |
|
| 98 | 98 | $query = call_user_func($this->data['hook_index_query'], $query); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | |
| 102 | - if(request()->has(['order_by','order_sort'])) |
|
| 102 | + if (request()->has(['order_by', 'order_sort'])) |
|
| 103 | 103 | { |
| 104 | - $sort = (request("order_sort")=="asc")?"asc":"desc"; |
|
| 104 | + $sort = (request("order_sort") == "asc") ? "asc" : "desc"; |
|
| 105 | 105 | /* |
| 106 | 106 | * Check if order by contain "." it means {table}.{column} we have to parsing that |
| 107 | 107 | */ |
| 108 | - if(strpos(request("order_by"), ".")!==false) { |
|
| 109 | - $orderByTable = explode(".",request("order_by"))[0]; |
|
| 110 | - $orderByColumn = explode(".",request("order_by"))[1]; |
|
| 111 | - if(SchemaHelper::hasColumn($orderByTable, $orderByColumn)) { |
|
| 108 | + if (strpos(request("order_by"), ".") !== false) { |
|
| 109 | + $orderByTable = explode(".", request("order_by"))[0]; |
|
| 110 | + $orderByColumn = explode(".", request("order_by"))[1]; |
|
| 111 | + if (SchemaHelper::hasColumn($orderByTable, $orderByColumn)) { |
|
| 112 | 112 | $query->orderBy($orderByTable.".".$orderByColumn, $sort); |
| 113 | 113 | } |
| 114 | 114 | } else { |
| 115 | 115 | /* |
| 116 | 116 | * Check if order_by column in registered columns |
| 117 | 117 | */ |
| 118 | - if(in_array(request('order_by'),columnSingleton()->getColumnNameOnly())) { |
|
| 118 | + if (in_array(request('order_by'), columnSingleton()->getColumnNameOnly())) { |
|
| 119 | 119 | $query->orderBy(request('order_by'), request('order_sort')); |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | - }else{ |
|
| 122 | + } else { |
|
| 123 | 123 | /* |
| 124 | 124 | * For default, query will be order by primary key as descending |
| 125 | 125 | */ |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | if(SchemaHelper::hasColumn($this->data['table'], $column->getField())) { |
| 49 | 49 | $query->addSelect($this->data['table'].'.'.$column->getField()); |
| 50 | 50 | } |
| 51 | - }else{ |
|
| 51 | + } else{ |
|
| 52 | 52 | $query->addSelect($column->getField()); |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $keyword = sanitizeXSS(request("q")); |
| 69 | 69 | if(isset($this->data['hook_search_query'])) { |
| 70 | 70 | $query = call_user_func($this->data['hook_search_query'], $query, $keyword); |
| 71 | - }else{ |
|
| 71 | + } else{ |
|
| 72 | 72 | $query->where(function ($where) use ($columns, $keyword) { |
| 73 | 73 | /** |
| 74 | 74 | * @var $where Builder |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | if(strpos($column->getField(),".") === false) { |
| 79 | 79 | $field = $this->data['table'].'.'.$column->getField(); |
| 80 | - }else{ |
|
| 80 | + } else{ |
|
| 81 | 81 | $field = $column->getField(); |
| 82 | 82 | } |
| 83 | 83 | $where->orWhere($field, 'like', '%'.$keyword.'%'); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $query->orderBy(request('order_by'), request('order_sort')); |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | - }else{ |
|
| 122 | + } else{ |
|
| 123 | 123 | /* |
| 124 | 124 | * For default, query will be order by primary key as descending |
| 125 | 125 | */ |