@@ -137,6 +137,9 @@ discard block |
||
| 137 | 137 | return $this; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | + /** |
|
| 141 | + * @param string $value |
|
| 142 | + */ |
|
| 140 | 143 | public function getOption($value) |
| 141 | 144 | { |
| 142 | 145 | return $this->options[$value]; |
@@ -285,6 +288,9 @@ discard block |
||
| 285 | 288 | $this->workingCollection = $this->workingCollection->reverse(); |
| 286 | 289 | } |
| 287 | 290 | |
| 291 | + /** |
|
| 292 | + * @param Collection $columns |
|
| 293 | + */ |
|
| 288 | 294 | private function compileArray($columns) |
| 289 | 295 | { |
| 290 | 296 | $self = $this; |
@@ -161,8 +161,9 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | private function doInternalSearch(Collection $columns, array $searchColumns) |
| 163 | 163 | { |
| 164 | - if((is_null($this->search) || empty($this->search)) && empty($this->fieldSearches)) |
|
| 165 | - return; |
|
| 164 | + if((is_null($this->search) || empty($this->search)) && empty($this->fieldSearches)) { |
|
| 165 | + return; |
|
| 166 | + } |
|
| 166 | 167 | |
| 167 | 168 | $value = $this->search; |
| 168 | 169 | $caseSensitive = $this->options['caseSensitive']; |
@@ -179,11 +180,11 @@ discard block |
||
| 179 | 180 | if(($field = array_search($columns->get($i)->getName(), $this->fieldSearches)) !== FALSE) |
| 180 | 181 | { |
| 181 | 182 | $toSearch[$ii] = $this->columnSearches[$field]; |
| 182 | - } |
|
| 183 | - else |
|
| 183 | + } else |
|
| 184 | 184 | { |
| 185 | - if($value) |
|
| 186 | - $searchType = self::OR_CONDITION; |
|
| 185 | + if($value) { |
|
| 186 | + $searchType = self::OR_CONDITION; |
|
| 187 | + } |
|
| 187 | 188 | $toSearch[$ii] = $value; |
| 188 | 189 | } |
| 189 | 190 | } |
@@ -195,8 +196,9 @@ discard block |
||
| 195 | 196 | { |
| 196 | 197 | for($i=0, $stack=array(), $nb=count($row); $i<$nb; $i++) |
| 197 | 198 | { |
| 198 | - if(!array_key_exists($i, $toSearch)) |
|
| 199 | - continue; |
|
| 199 | + if(!array_key_exists($i, $toSearch)) { |
|
| 200 | + continue; |
|
| 201 | + } |
|
| 200 | 202 | |
| 201 | 203 | $column = $i; |
| 202 | 204 | if($self->getAliasMapping()) |
@@ -207,8 +209,7 @@ discard block |
||
| 207 | 209 | if($self->getOption('stripSearch')) |
| 208 | 210 | { |
| 209 | 211 | $search = strip_tags($row[$column]); |
| 210 | - } |
|
| 211 | - else |
|
| 212 | + } else |
|
| 212 | 213 | { |
| 213 | 214 | $search = $row[$column]; |
| 214 | 215 | } |
@@ -216,47 +217,50 @@ discard block |
||
| 216 | 217 | { |
| 217 | 218 | if($self->exactWordSearch) |
| 218 | 219 | { |
| 219 | - if($toSearch[$i] === $search) |
|
| 220 | - $stack[$i] = true; |
|
| 221 | - } |
|
| 222 | - else |
|
| 220 | + if($toSearch[$i] === $search) { |
|
| 221 | + $stack[$i] = true; |
|
| 222 | + } |
|
| 223 | + } else |
|
| 223 | 224 | { |
| 224 | - if(str_contains($search,$toSearch[$i])) |
|
| 225 | - $stack[$i] = true; |
|
| 225 | + if(str_contains($search,$toSearch[$i])) { |
|
| 226 | + $stack[$i] = true; |
|
| 227 | + } |
|
| 226 | 228 | } |
| 227 | - } |
|
| 228 | - else |
|
| 229 | + } else |
|
| 229 | 230 | { |
| 230 | 231 | if($self->getExactWordSearch()) |
| 231 | 232 | { |
| 232 | - if(mb_strtolower($toSearch[$i]) === mb_strtolower($search)) |
|
| 233 | - $stack[$i] = true; |
|
| 234 | - } |
|
| 235 | - else |
|
| 233 | + if(mb_strtolower($toSearch[$i]) === mb_strtolower($search)) { |
|
| 234 | + $stack[$i] = true; |
|
| 235 | + } |
|
| 236 | + } else |
|
| 236 | 237 | { |
| 237 | - if(str_contains(mb_strtolower($search),mb_strtolower($toSearch[$i]))) |
|
| 238 | - $stack[$i] = true; |
|
| 238 | + if(str_contains(mb_strtolower($search),mb_strtolower($toSearch[$i]))) { |
|
| 239 | + $stack[$i] = true; |
|
| 240 | + } |
|
| 239 | 241 | } |
| 240 | 242 | } |
| 241 | 243 | } |
| 242 | 244 | if($searchType == $self::AND_CONDITION) |
| 243 | 245 | { |
| 244 | 246 | $result = array_diff_key(array_filter($toSearch), $stack); |
| 245 | - if(empty($result)) |
|
| 246 | - return true; |
|
| 247 | - } |
|
| 248 | - else |
|
| 247 | + if(empty($result)) { |
|
| 248 | + return true; |
|
| 249 | + } |
|
| 250 | + } else |
|
| 249 | 251 | { |
| 250 | - if(!empty($stack)) |
|
| 251 | - return true; |
|
| 252 | + if(!empty($stack)) { |
|
| 253 | + return true; |
|
| 254 | + } |
|
| 252 | 255 | } |
| 253 | 256 | }); |
| 254 | 257 | } |
| 255 | 258 | |
| 256 | 259 | private function doInternalOrder() |
| 257 | 260 | { |
| 258 | - if(is_null($this->orderColumn)) |
|
| 259 | - return; |
|
| 261 | + if(is_null($this->orderColumn)) { |
|
| 262 | + return; |
|
| 263 | + } |
|
| 260 | 264 | |
| 261 | 265 | $column = $this->orderColumn[0]; |
| 262 | 266 | $stripOrder = $this->options['stripOrder']; |
@@ -271,18 +275,18 @@ discard block |
||
| 271 | 275 | { |
| 272 | 276 | if(is_callable($stripOrder)){ |
| 273 | 277 | return $stripOrder($row, $column); |
| 274 | - }else{ |
|
| 278 | + } else{ |
|
| 275 | 279 | return strip_tags($row[$column]); |
| 276 | 280 | } |
| 277 | - } |
|
| 278 | - else |
|
| 281 | + } else |
|
| 279 | 282 | { |
| 280 | 283 | return $row[$column]; |
| 281 | 284 | } |
| 282 | 285 | }, $this->options['sortFlags']); |
| 283 | 286 | |
| 284 | - if($this->orderDirection == BaseEngine::ORDER_DESC) |
|
| 285 | - $this->workingCollection = $this->workingCollection->reverse(); |
|
| 287 | + if($this->orderDirection == BaseEngine::ORDER_DESC) { |
|
| 288 | + $this->workingCollection = $this->workingCollection->reverse(); |
|
| 289 | + } |
|
| 286 | 290 | } |
| 287 | 291 | |
| 288 | 292 | private function compileArray($columns) |
@@ -310,8 +314,7 @@ discard block |
||
| 310 | 314 | if($self->getAliasMapping()) |
| 311 | 315 | { |
| 312 | 316 | $entry[$col->getName()] = $col->run($row); |
| 313 | - } |
|
| 314 | - else |
|
| 317 | + } else |
|
| 315 | 318 | { |
| 316 | 319 | $entry[$i] = $col->run($row); |
| 317 | 320 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $this->doInternalOrder(); |
| 83 | 83 | |
| 84 | 84 | return array_values($this->workingCollection |
| 85 | - ->slice($this->skip,$this->limit) |
|
| 85 | + ->slice($this->skip, $this->limit) |
|
| 86 | 86 | ->toArray() |
| 87 | 87 | ); |
| 88 | 88 | } |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $this->doInternalSearch($columns, $searchColumns); |
| 150 | 150 | $this->doInternalOrder(); |
| 151 | 151 | |
| 152 | - return $this->workingCollection->slice($this->skip,$this->limit)->values(); |
|
| 152 | + return $this->workingCollection->slice($this->skip, $this->limit)->values(); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | private function doInternalSearch(Collection $columns, array $searchColumns) |
| 163 | 163 | { |
| 164 | - if((is_null($this->search) || empty($this->search)) && empty($this->fieldSearches)) |
|
| 164 | + if ((is_null($this->search) || empty($this->search)) && empty($this->fieldSearches)) |
|
| 165 | 165 | return; |
| 166 | 166 | |
| 167 | 167 | $value = $this->search; |
@@ -171,18 +171,18 @@ discard block |
||
| 171 | 171 | $searchType = self::AND_CONDITION; |
| 172 | 172 | // Map the searchColumns to the real columns |
| 173 | 173 | $ii = 0; |
| 174 | - foreach($columns as $i => $col) |
|
| 174 | + foreach ($columns as $i => $col) |
|
| 175 | 175 | { |
| 176 | - if(in_array($columns->get($i)->getName(), $searchColumns) || in_array($columns->get($i)->getName(), $this->fieldSearches)) |
|
| 176 | + if (in_array($columns->get($i)->getName(), $searchColumns) || in_array($columns->get($i)->getName(), $this->fieldSearches)) |
|
| 177 | 177 | { |
| 178 | 178 | // map values to columns, where there is no value use the global value |
| 179 | - if(($field = array_search($columns->get($i)->getName(), $this->fieldSearches)) !== FALSE) |
|
| 179 | + if (($field = array_search($columns->get($i)->getName(), $this->fieldSearches)) !== FALSE) |
|
| 180 | 180 | { |
| 181 | 181 | $toSearch[$ii] = $this->columnSearches[$field]; |
| 182 | 182 | } |
| 183 | 183 | else |
| 184 | 184 | { |
| 185 | - if($value) |
|
| 185 | + if ($value) |
|
| 186 | 186 | $searchType = self::OR_CONDITION; |
| 187 | 187 | $toSearch[$ii] = $value; |
| 188 | 188 | } |
@@ -193,18 +193,18 @@ discard block |
||
| 193 | 193 | $self = $this; |
| 194 | 194 | $this->workingCollection = $this->workingCollection->filter(function($row) use ($toSearch, $caseSensitive, $self, $searchType) |
| 195 | 195 | { |
| 196 | - for($i=0, $stack=array(), $nb=count($row); $i<$nb; $i++) |
|
| 196 | + for ($i = 0, $stack = array(), $nb = count($row); $i < $nb; $i++) |
|
| 197 | 197 | { |
| 198 | - if(!array_key_exists($i, $toSearch)) |
|
| 198 | + if (!array_key_exists($i, $toSearch)) |
|
| 199 | 199 | continue; |
| 200 | 200 | |
| 201 | 201 | $column = $i; |
| 202 | - if($self->getAliasMapping()) |
|
| 202 | + if ($self->getAliasMapping()) |
|
| 203 | 203 | { |
| 204 | 204 | $column = $self->getNameByIndex($i); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if($self->getOption('stripSearch')) |
|
| 207 | + if ($self->getOption('stripSearch')) |
|
| 208 | 208 | { |
| 209 | 209 | $search = strip_tags($row[$column]); |
| 210 | 210 | } |
@@ -212,42 +212,42 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | $search = $row[$column]; |
| 214 | 214 | } |
| 215 | - if($caseSensitive) |
|
| 215 | + if ($caseSensitive) |
|
| 216 | 216 | { |
| 217 | - if($self->exactWordSearch) |
|
| 217 | + if ($self->exactWordSearch) |
|
| 218 | 218 | { |
| 219 | - if($toSearch[$i] === $search) |
|
| 219 | + if ($toSearch[$i] === $search) |
|
| 220 | 220 | $stack[$i] = true; |
| 221 | 221 | } |
| 222 | 222 | else |
| 223 | 223 | { |
| 224 | - if(str_contains($search,$toSearch[$i])) |
|
| 224 | + if (str_contains($search, $toSearch[$i])) |
|
| 225 | 225 | $stack[$i] = true; |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | else |
| 229 | 229 | { |
| 230 | - if($self->getExactWordSearch()) |
|
| 230 | + if ($self->getExactWordSearch()) |
|
| 231 | 231 | { |
| 232 | - if(mb_strtolower($toSearch[$i]) === mb_strtolower($search)) |
|
| 232 | + if (mb_strtolower($toSearch[$i]) === mb_strtolower($search)) |
|
| 233 | 233 | $stack[$i] = true; |
| 234 | 234 | } |
| 235 | 235 | else |
| 236 | 236 | { |
| 237 | - if(str_contains(mb_strtolower($search),mb_strtolower($toSearch[$i]))) |
|
| 237 | + if (str_contains(mb_strtolower($search), mb_strtolower($toSearch[$i]))) |
|
| 238 | 238 | $stack[$i] = true; |
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | - if($searchType == $self::AND_CONDITION) |
|
| 242 | + if ($searchType == $self::AND_CONDITION) |
|
| 243 | 243 | { |
| 244 | 244 | $result = array_diff_key(array_filter($toSearch), $stack); |
| 245 | - if(empty($result)) |
|
| 245 | + if (empty($result)) |
|
| 246 | 246 | return true; |
| 247 | 247 | } |
| 248 | 248 | else |
| 249 | 249 | { |
| 250 | - if(!empty($stack)) |
|
| 250 | + if (!empty($stack)) |
|
| 251 | 251 | return true; |
| 252 | 252 | } |
| 253 | 253 | }); |
@@ -255,23 +255,23 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | private function doInternalOrder() |
| 257 | 257 | { |
| 258 | - if(is_null($this->orderColumn)) |
|
| 258 | + if (is_null($this->orderColumn)) |
|
| 259 | 259 | return; |
| 260 | 260 | |
| 261 | 261 | $column = $this->orderColumn[0]; |
| 262 | 262 | $stripOrder = $this->options['stripOrder']; |
| 263 | 263 | $self = $this; |
| 264 | - $this->workingCollection = $this->workingCollection->sortBy(function($row) use ($column,$stripOrder,$self) { |
|
| 264 | + $this->workingCollection = $this->workingCollection->sortBy(function($row) use ($column, $stripOrder, $self) { |
|
| 265 | 265 | |
| 266 | - if($self->getAliasMapping()) |
|
| 266 | + if ($self->getAliasMapping()) |
|
| 267 | 267 | { |
| 268 | 268 | $column = $self->getNameByIndex($column); |
| 269 | 269 | } |
| 270 | - if($stripOrder) |
|
| 270 | + if ($stripOrder) |
|
| 271 | 271 | { |
| 272 | - if(is_callable($stripOrder)){ |
|
| 272 | + if (is_callable($stripOrder)) { |
|
| 273 | 273 | return $stripOrder($row, $column); |
| 274 | - }else{ |
|
| 274 | + } else { |
|
| 275 | 275 | return strip_tags($row[$column]); |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | } |
| 282 | 282 | }, $this->options['sortFlags']); |
| 283 | 283 | |
| 284 | - if($this->orderDirection == BaseEngine::ORDER_DESC) |
|
| 284 | + if ($this->orderDirection == BaseEngine::ORDER_DESC) |
|
| 285 | 285 | $this->workingCollection = $this->workingCollection->reverse(); |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,28 +292,28 @@ discard block |
||
| 292 | 292 | $entry = array(); |
| 293 | 293 | |
| 294 | 294 | // add class and id if needed |
| 295 | - if(!is_null($self->getRowClass()) && is_callable($self->getRowClass())) |
|
| 295 | + if (!is_null($self->getRowClass()) && is_callable($self->getRowClass())) |
|
| 296 | 296 | { |
| 297 | - $entry['DT_RowClass'] = call_user_func($self->getRowClass(),$row); |
|
| 297 | + $entry['DT_RowClass'] = call_user_func($self->getRowClass(), $row); |
|
| 298 | 298 | } |
| 299 | - if(!is_null($self->getRowId()) && is_callable($self->getRowId())) |
|
| 299 | + if (!is_null($self->getRowId()) && is_callable($self->getRowId())) |
|
| 300 | 300 | { |
| 301 | - $entry['DT_RowId'] = call_user_func($self->getRowId(),$row); |
|
| 301 | + $entry['DT_RowId'] = call_user_func($self->getRowId(), $row); |
|
| 302 | 302 | } |
| 303 | - if(!is_null($self->getRowData()) && is_callable($self->getRowData())) |
|
| 303 | + if (!is_null($self->getRowData()) && is_callable($self->getRowData())) |
|
| 304 | 304 | { |
| 305 | - $entry['DT_RowData'] = call_user_func($self->getRowData(),$row); |
|
| 305 | + $entry['DT_RowData'] = call_user_func($self->getRowData(), $row); |
|
| 306 | 306 | } |
| 307 | - $i=0; |
|
| 307 | + $i = 0; |
|
| 308 | 308 | foreach ($columns as $col) |
| 309 | 309 | { |
| 310 | - if($self->getAliasMapping()) |
|
| 310 | + if ($self->getAliasMapping()) |
|
| 311 | 311 | { |
| 312 | - $entry[$col->getName()] = $col->run($row); |
|
| 312 | + $entry[$col->getName()] = $col->run($row); |
|
| 313 | 313 | } |
| 314 | 314 | else |
| 315 | 315 | { |
| 316 | - $entry[$i] = $col->run($row); |
|
| 316 | + $entry[$i] = $col->run($row); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | $i++; |
@@ -182,6 +182,9 @@ discard block |
||
| 182 | 182 | return $this->collection; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | + /** |
|
| 186 | + * @param Builder $builder |
|
| 187 | + */ |
|
| 185 | 188 | private function doInternalSearch($builder, $columns) |
| 186 | 189 | { |
| 187 | 190 | if (!empty($this->search)) { |
@@ -239,6 +242,9 @@ discard block |
||
| 239 | 242 | |
| 240 | 243 | } |
| 241 | 244 | |
| 245 | + /** |
|
| 246 | + * @param Collection $columns |
|
| 247 | + */ |
|
| 242 | 248 | private function compile($builder, $columns) |
| 243 | 249 | { |
| 244 | 250 | $this->resultCollection = $this->getCollection($builder); |
@@ -277,6 +283,9 @@ discard block |
||
| 277 | 283 | return $this->resultCollection; |
| 278 | 284 | } |
| 279 | 285 | |
| 286 | + /** |
|
| 287 | + * @param Collection $columns |
|
| 288 | + */ |
|
| 280 | 289 | private function doInternalOrder($builder, $columns) |
| 281 | 290 | { |
| 282 | 291 | //var_dump($this->orderColumn); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | public function getArray() |
| 80 | 80 | { |
| 81 | - return $this->getCollection($this->builder)->toArray(); |
|
| 81 | + return $this->getCollection($this->builder)->toArray(); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | public function reset() |
@@ -229,13 +229,13 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | private function buildSingleColumnSearches($builder) |
| 231 | 231 | { |
| 232 | - foreach ($this->columnSearches as $index => $searchValue) { |
|
| 232 | + foreach ($this->columnSearches as $index => $searchValue) { |
|
| 233 | 233 | if(@$this->columnSearchExact[ $this->fieldSearches[$index] ] == 1) { |
| 234 | - $builder->where($this->fieldSearches[$index], '=', $searchValue ); |
|
| 234 | + $builder->where($this->fieldSearches[$index], '=', $searchValue ); |
|
| 235 | 235 | } else { |
| 236 | - $builder->where($this->fieldSearches[$index], $this->options['searchOperator'], '%' . $searchValue . '%'); |
|
| 236 | + $builder->where($this->fieldSearches[$index], $this->options['searchOperator'], '%' . $searchValue . '%'); |
|
| 237 | + } |
|
| 237 | 238 | } |
| 238 | - } |
|
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
@@ -50,8 +50,7 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | $this->builder = $builder->getBaseQuery(); |
| 52 | 52 | $this->originalBuilder = clone $builder->getBaseQuery(); |
| 53 | - } |
|
| 54 | - else |
|
| 53 | + } else |
|
| 55 | 54 | { |
| 56 | 55 | $this->builder = $builder; |
| 57 | 56 | $this->originalBuilder = clone $builder; |
@@ -119,8 +118,7 @@ discard block |
||
| 119 | 118 | if($this->options['searchWithAlias']) |
| 120 | 119 | { |
| 121 | 120 | $this->options['counter'] = count($countBuilder->get()); |
| 122 | - } |
|
| 123 | - else |
|
| 121 | + } else |
|
| 124 | 122 | { |
| 125 | 123 | // Remove the GROUP BY clause for the count |
| 126 | 124 | if ($this->options['noGroupByOnCount']) { |
@@ -176,8 +174,9 @@ discard block |
||
| 176 | 174 | //dd($this->builder->toSql()); |
| 177 | 175 | $this->collection = $builder->get(); |
| 178 | 176 | |
| 179 | - if(is_array($this->collection)) |
|
| 180 | - $this->collection = new Collection($this->collection); |
|
| 177 | + if(is_array($this->collection)) { |
|
| 178 | + $this->collection = new Collection($this->collection); |
|
| 179 | + } |
|
| 181 | 180 | } |
| 182 | 181 | return $this->collection; |
| 183 | 182 | } |
@@ -211,12 +210,13 @@ discard block |
||
| 211 | 210 | //column to CAST following the pattern column:newType:[maxlength] |
| 212 | 211 | elseif(strrpos($c, ':')){ |
| 213 | 212 | $c = explode(':', $c); |
| 214 | - if(isset($c[2])) |
|
| 215 | - $c[1] .= "($c[2])"; |
|
| 213 | + if(isset($c[2])) { |
|
| 214 | + $c[1] .= "($c[2])"; |
|
| 215 | + } |
|
| 216 | 216 | $query->orWhereRaw("cast($c[0] as $c[1]) ".$like." ?", array($exact ? "$search" : "%$search%")); |
| 217 | + } else { |
|
| 218 | + $query->orWhere($c, $like, $exact ? $search : '%' . $search . '%'); |
|
| 217 | 219 | } |
| 218 | - else |
|
| 219 | - $query->orWhere($c, $like, $exact ? $search : '%' . $search . '%'); |
|
| 220 | 220 | } |
| 221 | 221 | }); |
| 222 | 222 | return $builder; |
@@ -265,8 +265,7 @@ discard block |
||
| 265 | 265 | if($self->getAliasMapping()) |
| 266 | 266 | { |
| 267 | 267 | $entry[$col->getName()] = $col->run($row); |
| 268 | - } |
|
| 269 | - else |
|
| 268 | + } else |
|
| 270 | 269 | { |
| 271 | 270 | $entry[$i] = $col->run($row); |
| 272 | 271 | } |
@@ -290,12 +289,13 @@ discard block |
||
| 290 | 289 | { |
| 291 | 290 | if(strrpos($this->orderColumn[1], ':')){ |
| 292 | 291 | $c = explode(':', $this->orderColumn[1]); |
| 293 | - if(isset($c[2])) |
|
| 294 | - $c[1] .= "($c[2])"; |
|
| 292 | + if(isset($c[2])) { |
|
| 293 | + $c[1] .= "($c[2])"; |
|
| 294 | + } |
|
| 295 | 295 | $builder = $builder->orderByRaw("cast($c[0] as $c[1]) ".$this->orderDirection); |
| 296 | + } else { |
|
| 297 | + $builder = $builder->orderBy($col->getName(), $this->orderDirection); |
|
| 296 | 298 | } |
| 297 | - else |
|
| 298 | - $builder = $builder->orderBy($col->getName(), $this->orderDirection); |
|
| 299 | 299 | return $builder; |
| 300 | 300 | } |
| 301 | 301 | $i++; |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | function __construct($builder) |
| 47 | 47 | { |
| 48 | 48 | parent::__construct(); |
| 49 | - if($builder instanceof Relation) |
|
| 49 | + if ($builder instanceof Relation) |
|
| 50 | 50 | { |
| 51 | 51 | $this->builder = $builder->getBaseQuery(); |
| 52 | 52 | $this->originalBuilder = clone $builder->getBaseQuery(); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $builder = $this->doInternalSearch($builder, $searchColumns); |
| 117 | 117 | $countBuilder = $this->doInternalSearch($countBuilder, $searchColumns); |
| 118 | 118 | |
| 119 | - if($this->options['searchWithAlias']) |
|
| 119 | + if ($this->options['searchWithAlias']) |
|
| 120 | 120 | { |
| 121 | 121 | $this->options['counter'] = count($countBuilder->get()); |
| 122 | 122 | } |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | private function getCollection($builder) |
| 165 | 165 | { |
| 166 | - if($this->collection == null) |
|
| 166 | + if ($this->collection == null) |
|
| 167 | 167 | { |
| 168 | - if($this->skip > 0) |
|
| 168 | + if ($this->skip > 0) |
|
| 169 | 169 | { |
| 170 | 170 | $builder = $builder->skip($this->skip); |
| 171 | 171 | } |
| 172 | - if($this->limit > 0) |
|
| 172 | + if ($this->limit > 0) |
|
| 173 | 173 | { |
| 174 | 174 | $builder = $builder->take($this->limit); |
| 175 | 175 | } |
| 176 | 176 | //dd($this->builder->toSql()); |
| 177 | 177 | $this->collection = $builder->get(); |
| 178 | 178 | |
| 179 | - if(is_array($this->collection)) |
|
| 179 | + if (is_array($this->collection)) |
|
| 180 | 180 | $this->collection = new Collection($this->collection); |
| 181 | 181 | } |
| 182 | 182 | return $this->collection; |
@@ -202,21 +202,21 @@ discard block |
||
| 202 | 202 | $builder = $builder->where(function($query) use ($columns, $search, $like, $exact) { |
| 203 | 203 | foreach ($columns as $c) { |
| 204 | 204 | //column to search within relationships : relatedModel::column |
| 205 | - if(strrpos($c, '::')) { |
|
| 205 | + if (strrpos($c, '::')) { |
|
| 206 | 206 | $c = explode('::', $c); |
| 207 | 207 | $query->orWhereHas($c[0], function($q) use($c, $like, $exact, $search){ |
| 208 | - $q->where($c[1], $like, $exact ? $search : '%' . $search . '%'); |
|
| 208 | + $q->where($c[1], $like, $exact ? $search : '%'.$search.'%'); |
|
| 209 | 209 | }); |
| 210 | 210 | } |
| 211 | 211 | //column to CAST following the pattern column:newType:[maxlength] |
| 212 | - elseif(strrpos($c, ':')){ |
|
| 212 | + elseif (strrpos($c, ':')) { |
|
| 213 | 213 | $c = explode(':', $c); |
| 214 | - if(isset($c[2])) |
|
| 214 | + if (isset($c[2])) |
|
| 215 | 215 | $c[1] .= "($c[2])"; |
| 216 | 216 | $query->orWhereRaw("cast($c[0] as $c[1]) ".$like." ?", array($exact ? "$search" : "%$search%")); |
| 217 | 217 | } |
| 218 | 218 | else |
| 219 | - $query->orWhere($c, $like, $exact ? $search : '%' . $search . '%'); |
|
| 219 | + $query->orWhere($c, $like, $exact ? $search : '%'.$search.'%'); |
|
| 220 | 220 | } |
| 221 | 221 | }); |
| 222 | 222 | return $builder; |
@@ -230,10 +230,10 @@ discard block |
||
| 230 | 230 | private function buildSingleColumnSearches($builder) |
| 231 | 231 | { |
| 232 | 232 | foreach ($this->columnSearches as $index => $searchValue) { |
| 233 | - if(@$this->columnSearchExact[ $this->fieldSearches[$index] ] == 1) { |
|
| 234 | - $builder->where($this->fieldSearches[$index], '=', $searchValue ); |
|
| 233 | + if (@$this->columnSearchExact[$this->fieldSearches[$index]] == 1) { |
|
| 234 | + $builder->where($this->fieldSearches[$index], '=', $searchValue); |
|
| 235 | 235 | } else { |
| 236 | - $builder->where($this->fieldSearches[$index], $this->options['searchOperator'], '%' . $searchValue . '%'); |
|
| 236 | + $builder->where($this->fieldSearches[$index], $this->options['searchOperator'], '%'.$searchValue.'%'); |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
@@ -244,31 +244,31 @@ discard block |
||
| 244 | 244 | $this->resultCollection = $this->getCollection($builder); |
| 245 | 245 | |
| 246 | 246 | $self = $this; |
| 247 | - $this->resultCollection = $this->resultCollection->map(function($row) use ($columns,$self) { |
|
| 247 | + $this->resultCollection = $this->resultCollection->map(function($row) use ($columns, $self) { |
|
| 248 | 248 | $entry = array(); |
| 249 | 249 | // add class and id if needed |
| 250 | - if(!is_null($self->getRowClass()) && is_callable($self->getRowClass())) |
|
| 250 | + if (!is_null($self->getRowClass()) && is_callable($self->getRowClass())) |
|
| 251 | 251 | { |
| 252 | - $entry['DT_RowClass'] = call_user_func($self->getRowClass(),$row); |
|
| 252 | + $entry['DT_RowClass'] = call_user_func($self->getRowClass(), $row); |
|
| 253 | 253 | } |
| 254 | - if(!is_null($self->getRowId()) && is_callable($self->getRowId())) |
|
| 254 | + if (!is_null($self->getRowId()) && is_callable($self->getRowId())) |
|
| 255 | 255 | { |
| 256 | - $entry['DT_RowId'] = call_user_func($self->getRowId(),$row); |
|
| 256 | + $entry['DT_RowId'] = call_user_func($self->getRowId(), $row); |
|
| 257 | 257 | } |
| 258 | - if(!is_null($self->getRowData()) && is_callable($self->getRowData())) |
|
| 258 | + if (!is_null($self->getRowData()) && is_callable($self->getRowData())) |
|
| 259 | 259 | { |
| 260 | - $entry['DT_RowData'] = call_user_func($self->getRowData(),$row); |
|
| 260 | + $entry['DT_RowData'] = call_user_func($self->getRowData(), $row); |
|
| 261 | 261 | } |
| 262 | 262 | $i = 0; |
| 263 | 263 | foreach ($columns as $col) |
| 264 | 264 | { |
| 265 | - if($self->getAliasMapping()) |
|
| 265 | + if ($self->getAliasMapping()) |
|
| 266 | 266 | { |
| 267 | - $entry[$col->getName()] = $col->run($row); |
|
| 267 | + $entry[$col->getName()] = $col->run($row); |
|
| 268 | 268 | } |
| 269 | 269 | else |
| 270 | 270 | { |
| 271 | - $entry[$i] = $col->run($row); |
|
| 271 | + $entry[$i] = $col->run($row); |
|
| 272 | 272 | } |
| 273 | 273 | $i++; |
| 274 | 274 | } |
@@ -280,17 +280,17 @@ discard block |
||
| 280 | 280 | private function doInternalOrder($builder, $columns) |
| 281 | 281 | { |
| 282 | 282 | //var_dump($this->orderColumn); |
| 283 | - if(!is_null($this->orderColumn)) |
|
| 283 | + if (!is_null($this->orderColumn)) |
|
| 284 | 284 | { |
| 285 | 285 | $i = 0; |
| 286 | - foreach($columns as $col) |
|
| 286 | + foreach ($columns as $col) |
|
| 287 | 287 | { |
| 288 | 288 | |
| 289 | - if($i === (int) $this->orderColumn[0]) |
|
| 289 | + if ($i === (int) $this->orderColumn[0]) |
|
| 290 | 290 | { |
| 291 | - if(strrpos($this->orderColumn[1], ':')){ |
|
| 291 | + if (strrpos($this->orderColumn[1], ':')) { |
|
| 292 | 292 | $c = explode(':', $this->orderColumn[1]); |
| 293 | - if(isset($c[2])) |
|
| 293 | + if (isset($c[2])) |
|
| 294 | 294 | $c[1] .= "($c[2])"; |
| 295 | 295 | $builder = $builder->orderByRaw("cast($c[0] as $c[1]) ".$this->orderDirection); |
| 296 | 296 | } |
@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | use Chumper\Datatable\Engines\CollectionEngine; |
| 4 | 4 | use Illuminate\Support\Collection; |
| 5 | -use Illuminate\Support\Facades\Input; |
|
| 6 | 5 | use Orchestra\Testbench\TestCase; |
| 7 | 6 | use Illuminate\Support\Facades\Config; |
| 8 | 7 | |
@@ -110,4 +110,4 @@ |
||
| 110 | 110 | $this->assertEquals(array('id','name','email', 'foo', 'bar'), $this->engine->getOrder()); |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | - |
|
| 114 | 113 | \ No newline at end of file |
| 114 | + |
|
| 115 | 115 | \ No newline at end of file |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $this->engine->getColumn('foo') |
| 42 | 42 | ); |
| 43 | 43 | |
| 44 | - $this->engine->addColumn('foo2', function($model){return $model->fooBar;}); |
|
| 44 | + $this->engine->addColumn('foo2', function($model) {return $model->fooBar; }); |
|
| 45 | 45 | |
| 46 | 46 | $this->assertInstanceOf( |
| 47 | 47 | 'Chumper\Datatable\Columns\FunctionColumn', |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function testClearColumns() |
| 57 | 57 | { |
| 58 | - $this->engine->addColumn('foo','Bar'); |
|
| 58 | + $this->engine->addColumn('foo', 'Bar'); |
|
| 59 | 59 | $this->assertInstanceOf( |
| 60 | 60 | 'Chumper\Datatable\Columns\TextColumn', |
| 61 | 61 | $this->engine->getColumn('foo') |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $this->engine->searchColumns('name', 'email'); |
| 75 | 75 | |
| 76 | - $this->assertEquals(array('name','email'), $this->engine->getSearchingColumns()); |
|
| 76 | + $this->assertEquals(array('name', 'email'), $this->engine->getSearchingColumns()); |
|
| 77 | 77 | |
| 78 | 78 | $this->engine->searchColumns(array('foo', 'bar')); |
| 79 | 79 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | $this->engine->orderColumns('name', 'email'); |
| 90 | 90 | |
| 91 | - $this->assertEquals(array('name','email'), $this->engine->getOrderingColumns()); |
|
| 91 | + $this->assertEquals(array('name', 'email'), $this->engine->getOrderingColumns()); |
|
| 92 | 92 | |
| 93 | 93 | $this->engine->orderColumns(array('foo', 'bar')); |
| 94 | 94 | |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | $this->engine->showColumns('name', 'email'); |
| 105 | 105 | |
| 106 | - $this->assertEquals(array('id','name','email'), $this->engine->getOrder()); |
|
| 106 | + $this->assertEquals(array('id', 'name', 'email'), $this->engine->getOrder()); |
|
| 107 | 107 | |
| 108 | 108 | $this->engine->showColumns(array('foo', 'bar')); |
| 109 | 109 | |
| 110 | - $this->assertEquals(array('id','name','email', 'foo', 'bar'), $this->engine->getOrder()); |
|
| 110 | + $this->assertEquals(array('id', 'name', 'email', 'foo', 'bar'), $this->engine->getOrder()); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | \ No newline at end of file |
@@ -303,6 +303,9 @@ discard block |
||
| 303 | 303 | ); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | + /** |
|
| 307 | + * @param CollectionEngine $engine |
|
| 308 | + */ |
|
| 306 | 309 | private function addRealColumns($engine) |
| 307 | 310 | { |
| 308 | 311 | $engine->addColumn(new FunctionColumn('foo', function($m){return $m['name'];})); |
@@ -314,6 +317,10 @@ discard block |
||
| 314 | 317 | return new FunctionColumn('id', function($row){return $row['id'];}); |
| 315 | 318 | } |
| 316 | 319 | |
| 320 | + /** |
|
| 321 | + * @param string $key |
|
| 322 | + * @param string $value |
|
| 323 | + */ |
|
| 317 | 324 | private function arrayHasKeyValue($key,$value,$array) |
| 318 | 325 | { |
| 319 | 326 | $array = array_pluck($array,$key); |
@@ -5,7 +5,6 @@ |
||
| 5 | 5 | use Illuminate\Support\Collection; |
| 6 | 6 | use Illuminate\Support\Facades\Input; |
| 7 | 7 | use Orchestra\Testbench\TestCase; |
| 8 | -use Illuminate\Support\Facades\Config; |
|
| 9 | 8 | |
| 10 | 9 | class CollectionEngineTest extends TestCase { |
| 11 | 10 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | 61 | $engine = new CollectionEngine(new Collection($this->getTestArray())); |
| 62 | - $engine->addColumn(new FunctionColumn('id', function($model){return $model['id'];})); |
|
| 62 | + $engine->addColumn(new FunctionColumn('id', function($model) {return $model['id']; })); |
|
| 63 | 63 | $engine->setAliasMapping(); |
| 64 | 64 | $this->assertEquals($should, $engine->getArray()); |
| 65 | 65 | |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | $should = '{"aaData":[{"id":"eoo"}],"sEcho":0,"iTotalRecords":2,"iTotalDisplayRecords":1}'; |
| 101 | 101 | $actual = $engine->make()->getContent(); |
| 102 | 102 | |
| 103 | - $this->assertEquals($should,$actual); |
|
| 103 | + $this->assertEquals($should, $actual); |
|
| 104 | 104 | //------------------TEST 2----------------- |
| 105 | 105 | // search in outputed data |
| 106 | - $engine = new CollectionEngine(new Collection(array(array('foo', 'foo2', 'foo3'),array('bar', 'bar2', 'bar3')))); |
|
| 107 | - $engine->addColumn(new FunctionColumn('bla', function($row){return $row[0]." - ".$row[1];})); |
|
| 108 | - $engine->addColumn(new FunctionColumn('1', function($row){return $row[2];})); |
|
| 109 | - $engine->addColumn(new FunctionColumn('bla3', function($row){return $row[0]." - ".$row[2];})); |
|
| 110 | - $engine->searchColumns("bla",1); |
|
| 106 | + $engine = new CollectionEngine(new Collection(array(array('foo', 'foo2', 'foo3'), array('bar', 'bar2', 'bar3')))); |
|
| 107 | + $engine->addColumn(new FunctionColumn('bla', function($row) {return $row[0]." - ".$row[1]; })); |
|
| 108 | + $engine->addColumn(new FunctionColumn('1', function($row) {return $row[2]; })); |
|
| 109 | + $engine->addColumn(new FunctionColumn('bla3', function($row) {return $row[0]." - ".$row[2]; })); |
|
| 110 | + $engine->searchColumns("bla", 1); |
|
| 111 | 111 | $engine->setAliasMapping(); |
| 112 | 112 | |
| 113 | 113 | Input::replace( |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | ); |
| 126 | 126 | |
| 127 | 127 | $response = json_decode($engine->make()->getContent()); |
| 128 | - $this->assertEquals(json_encode($should), json_encode((array)($response->aaData))); |
|
| 128 | + $this->assertEquals(json_encode($should), json_encode((array) ($response->aaData))); |
|
| 129 | 129 | |
| 130 | 130 | //------------------TEST 3----------------- |
| 131 | 131 | // search in initial data |
| 132 | 132 | // TODO: Search in initial data columns? |
| 133 | 133 | |
| 134 | - $engine = new CollectionEngine(new Collection(array(array('foo', 'foo2', 'foo3'),array('bar', 'bar2', 'bar3')))); |
|
| 135 | - $engine->addColumn(new FunctionColumn('bla3', function($row){return $row[0]." - ".$row[2];})); |
|
| 136 | - $engine->addColumn(new FunctionColumn('1', function($row){return $row[1];})); |
|
| 137 | - $engine->searchColumns("bla3",1); |
|
| 134 | + $engine = new CollectionEngine(new Collection(array(array('foo', 'foo2', 'foo3'), array('bar', 'bar2', 'bar3')))); |
|
| 135 | + $engine->addColumn(new FunctionColumn('bla3', function($row) {return $row[0]." - ".$row[2]; })); |
|
| 136 | + $engine->addColumn(new FunctionColumn('1', function($row) {return $row[1]; })); |
|
| 137 | + $engine->searchColumns("bla3", 1); |
|
| 138 | 138 | $engine->setAliasMapping(); |
| 139 | 139 | |
| 140 | 140 | Input::replace( |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | $engine = new CollectionEngine(new Collection($this->getRealArray())); |
| 202 | 202 | $this->addRealColumns($engine); |
| 203 | - $engine->searchColumns('foo','bar'); |
|
| 203 | + $engine->searchColumns('foo', 'bar'); |
|
| 204 | 204 | $engine->setAliasMapping(); |
| 205 | 205 | |
| 206 | 206 | Input::replace( |
@@ -212,13 +212,13 @@ discard block |
||
| 212 | 212 | $test = json_decode($engine->make()->getContent()); |
| 213 | 213 | $test = $test->aaData; |
| 214 | 214 | |
| 215 | - $this->assertTrue($this->arrayHasKeyValue('foo','Nils',(array) $test)); |
|
| 216 | - $this->assertTrue($this->arrayHasKeyValue('foo','Taylor',(array) $test)); |
|
| 215 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Nils', (array) $test)); |
|
| 216 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Taylor', (array) $test)); |
|
| 217 | 217 | |
| 218 | 218 | //Test2 |
| 219 | 219 | $engine = new CollectionEngine(new Collection($this->getRealArray())); |
| 220 | 220 | $this->addRealColumns($engine); |
| 221 | - $engine->searchColumns('foo','bar'); |
|
| 221 | + $engine->searchColumns('foo', 'bar'); |
|
| 222 | 222 | $engine->setAliasMapping(); |
| 223 | 223 | |
| 224 | 224 | Input::replace( |
@@ -230,13 +230,13 @@ discard block |
||
| 230 | 230 | $test = json_decode($engine->make()->getContent()); |
| 231 | 231 | $test = $test->aaData; |
| 232 | 232 | |
| 233 | - $this->assertTrue($this->arrayHasKeyValue('foo','Nils',(array) $test)); |
|
| 234 | - $this->assertFalse($this->arrayHasKeyValue('foo','Taylor',(array) $test)); |
|
| 233 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Nils', (array) $test)); |
|
| 234 | + $this->assertFalse($this->arrayHasKeyValue('foo', 'Taylor', (array) $test)); |
|
| 235 | 235 | |
| 236 | 236 | //test3 |
| 237 | 237 | $engine = new CollectionEngine(new Collection($this->getRealArray())); |
| 238 | 238 | $this->addRealColumns($engine); |
| 239 | - $engine->searchColumns('foo','bar'); |
|
| 239 | + $engine->searchColumns('foo', 'bar'); |
|
| 240 | 240 | $engine->setAliasMapping(); |
| 241 | 241 | |
| 242 | 242 | Input::replace( |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | |
| 251 | 251 | |
| 252 | 252 | |
| 253 | - $this->assertFalse($this->arrayHasKeyValue('foo','Nils',(array) $test)); |
|
| 254 | - $this->assertTrue($this->arrayHasKeyValue('foo','Taylor',(array) $test)); |
|
| 253 | + $this->assertFalse($this->arrayHasKeyValue('foo', 'Nils', (array) $test)); |
|
| 254 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Taylor', (array) $test)); |
|
| 255 | 255 | |
| 256 | 256 | //test4 |
| 257 | 257 | $engine = new CollectionEngine(new Collection($this->getRealArray())); |
| 258 | 258 | $this->addRealColumns($engine); |
| 259 | - $engine->searchColumns('foo','bar'); |
|
| 259 | + $engine->searchColumns('foo', 'bar'); |
|
| 260 | 260 | $engine->setAliasMapping(); |
| 261 | 261 | |
| 262 | 262 | Input::replace( |
@@ -268,8 +268,8 @@ discard block |
||
| 268 | 268 | $test = json_decode($engine->make()->getContent()); |
| 269 | 269 | $test = $test->aaData; |
| 270 | 270 | |
| 271 | - $this->assertFalse($this->arrayHasKeyValue('foo','Nils',(array) $test)); |
|
| 272 | - $this->assertTrue($this->arrayHasKeyValue('foo','Taylor',(array) $test)); |
|
| 271 | + $this->assertFalse($this->arrayHasKeyValue('foo', 'Nils', (array) $test)); |
|
| 272 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Taylor', (array) $test)); |
|
| 273 | 273 | |
| 274 | 274 | } |
| 275 | 275 | |
@@ -305,21 +305,21 @@ discard block |
||
| 305 | 305 | |
| 306 | 306 | private function addRealColumns($engine) |
| 307 | 307 | { |
| 308 | - $engine->addColumn(new FunctionColumn('foo', function($m){return $m['name'];})); |
|
| 309 | - $engine->addColumn(new FunctionColumn('bar', function($m){return $m['email'];})); |
|
| 308 | + $engine->addColumn(new FunctionColumn('foo', function($m) {return $m['name']; })); |
|
| 309 | + $engine->addColumn(new FunctionColumn('bar', function($m) {return $m['email']; })); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | private function getTestColumns() |
| 313 | 313 | { |
| 314 | - return new FunctionColumn('id', function($row){return $row['id'];}); |
|
| 314 | + return new FunctionColumn('id', function($row) {return $row['id']; }); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - private function arrayHasKeyValue($key,$value,$array) |
|
| 317 | + private function arrayHasKeyValue($key, $value, $array) |
|
| 318 | 318 | { |
| 319 | - $array = array_pluck($array,$key); |
|
| 319 | + $array = array_pluck($array, $key); |
|
| 320 | 320 | foreach ($array as $val) |
| 321 | 321 | { |
| 322 | - if(str_contains($val, $value)) |
|
| 322 | + if (str_contains($val, $value)) |
|
| 323 | 323 | return true; |
| 324 | 324 | } |
| 325 | 325 | return false; |
@@ -241,8 +241,9 @@ |
||
| 241 | 241 | $array = array_pluck($array,$key); |
| 242 | 242 | foreach ($array as $val) |
| 243 | 243 | { |
| 244 | - if(str_contains($val, $value)) |
|
| 245 | - return true; |
|
| 244 | + if(str_contains($val, $value)) { |
|
| 245 | + return true; |
|
| 246 | + } |
|
| 246 | 247 | } |
| 247 | 248 | return false; |
| 248 | 249 | |
@@ -230,12 +230,19 @@ |
||
| 230 | 230 | ); |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | + /** |
|
| 234 | + * @param QueryEngine $engine |
|
| 235 | + */ |
|
| 233 | 236 | private function addRealColumns($engine) |
| 234 | 237 | { |
| 235 | 238 | $engine->addColumn(new FunctionColumn('foo', function($m){return $m['name'];})); |
| 236 | 239 | $engine->addColumn(new FunctionColumn('bar', function($m){return $m['email'];})); |
| 237 | 240 | } |
| 238 | 241 | |
| 242 | + /** |
|
| 243 | + * @param string $key |
|
| 244 | + * @param string $value |
|
| 245 | + */ |
|
| 239 | 246 | private function arrayHasKeyValue($key,$value,$array) |
| 240 | 247 | { |
| 241 | 248 | $array = array_pluck($array,$key); |
@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | use Chumper\Datatable\Columns\FunctionColumn; |
| 4 | 4 | use Chumper\Datatable\Engines\BaseEngine; |
| 5 | -use Chumper\Datatable\Engines\EngineInterface; |
|
| 6 | 5 | use Chumper\Datatable\Engines\QueryEngine; |
| 7 | 6 | use Illuminate\Support\Collection; |
| 8 | 7 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $engine = new QueryEngine($this->builder); |
| 139 | 139 | |
| 140 | 140 | $this->addRealColumns($engine); |
| 141 | - $engine->searchColumns('foo','bar'); |
|
| 141 | + $engine->searchColumns('foo', 'bar'); |
|
| 142 | 142 | $engine->setAliasMapping(); |
| 143 | 143 | |
| 144 | 144 | Input::replace( |
@@ -150,14 +150,14 @@ discard block |
||
| 150 | 150 | $test = json_decode($engine->make()->getContent()); |
| 151 | 151 | $test = $test->aaData; |
| 152 | 152 | |
| 153 | - $this->assertTrue($this->arrayHasKeyValue('foo','Nils',$test)); |
|
| 154 | - $this->assertTrue($this->arrayHasKeyValue('foo','Taylor',$test)); |
|
| 153 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Nils', $test)); |
|
| 154 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Taylor', $test)); |
|
| 155 | 155 | |
| 156 | 156 | //Test2 |
| 157 | 157 | $engine = new QueryEngine($this->builder); |
| 158 | 158 | |
| 159 | 159 | $this->addRealColumns($engine); |
| 160 | - $engine->searchColumns('foo','bar'); |
|
| 160 | + $engine->searchColumns('foo', 'bar'); |
|
| 161 | 161 | $engine->setAliasMapping(); |
| 162 | 162 | |
| 163 | 163 | Input::replace( |
@@ -169,14 +169,14 @@ discard block |
||
| 169 | 169 | $test = json_decode($engine->make()->getContent()); |
| 170 | 170 | $test = $test->aaData; |
| 171 | 171 | |
| 172 | - $this->assertTrue($this->arrayHasKeyValue('foo','Nils',$test)); |
|
| 173 | - $this->assertTrue($this->arrayHasKeyValue('foo','Taylor',$test)); |
|
| 172 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Nils', $test)); |
|
| 173 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Taylor', $test)); |
|
| 174 | 174 | |
| 175 | 175 | //test3 |
| 176 | 176 | $engine = new QueryEngine($this->builder); |
| 177 | 177 | |
| 178 | 178 | $this->addRealColumns($engine); |
| 179 | - $engine->searchColumns('foo','bar'); |
|
| 179 | + $engine->searchColumns('foo', 'bar'); |
|
| 180 | 180 | $engine->setAliasMapping(); |
| 181 | 181 | |
| 182 | 182 | Input::replace( |
@@ -188,14 +188,14 @@ discard block |
||
| 188 | 188 | $test = json_decode($engine->make()->getContent()); |
| 189 | 189 | $test = $test->aaData; |
| 190 | 190 | |
| 191 | - $this->assertTrue($this->arrayHasKeyValue('foo','Nils',$test)); |
|
| 192 | - $this->assertTrue($this->arrayHasKeyValue('foo','Taylor',$test)); |
|
| 191 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Nils', $test)); |
|
| 192 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Taylor', $test)); |
|
| 193 | 193 | |
| 194 | 194 | //test4 |
| 195 | 195 | $engine = new QueryEngine($this->builder); |
| 196 | 196 | |
| 197 | 197 | $this->addRealColumns($engine); |
| 198 | - $engine->searchColumns('foo','bar'); |
|
| 198 | + $engine->searchColumns('foo', 'bar'); |
|
| 199 | 199 | $engine->setAliasMapping(); |
| 200 | 200 | |
| 201 | 201 | Input::replace( |
@@ -207,8 +207,8 @@ discard block |
||
| 207 | 207 | $test = json_decode($engine->make()->getContent()); |
| 208 | 208 | $test = $test->aaData; |
| 209 | 209 | |
| 210 | - $this->assertTrue($this->arrayHasKeyValue('foo','Nils',$test)); |
|
| 211 | - $this->assertTrue($this->arrayHasKeyValue('foo','Taylor',$test)); |
|
| 210 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Nils', $test)); |
|
| 211 | + $this->assertTrue($this->arrayHasKeyValue('foo', 'Taylor', $test)); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | protected function tearDown() |
@@ -232,16 +232,16 @@ discard block |
||
| 232 | 232 | |
| 233 | 233 | private function addRealColumns($engine) |
| 234 | 234 | { |
| 235 | - $engine->addColumn(new FunctionColumn('foo', function($m){return $m['name'];})); |
|
| 236 | - $engine->addColumn(new FunctionColumn('bar', function($m){return $m['email'];})); |
|
| 235 | + $engine->addColumn(new FunctionColumn('foo', function($m) {return $m['name']; })); |
|
| 236 | + $engine->addColumn(new FunctionColumn('bar', function($m) {return $m['email']; })); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - private function arrayHasKeyValue($key,$value,$array) |
|
| 239 | + private function arrayHasKeyValue($key, $value, $array) |
|
| 240 | 240 | { |
| 241 | - $array = array_pluck($array,$key); |
|
| 241 | + $array = array_pluck($array, $key); |
|
| 242 | 242 | foreach ($array as $val) |
| 243 | 243 | { |
| 244 | - if(str_contains($val, $value)) |
|
| 244 | + if (str_contains($val, $value)) |
|
| 245 | 245 | return true; |
| 246 | 246 | } |
| 247 | 247 | return false; |
@@ -241,8 +241,9 @@ |
||
| 241 | 241 | $array = array_pluck($array,$key); |
| 242 | 242 | foreach ($array as $val) |
| 243 | 243 | { |
| 244 | - if(str_contains($val, $value)) |
|
| 245 | - return true; |
|
| 244 | + if(str_contains($val, $value)) { |
|
| 245 | + return true; |
|
| 246 | + } |
|
| 246 | 247 | } |
| 247 | 248 | return false; |
| 248 | 249 | |
@@ -1,8 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | use Chumper\Datatable\Table; |
| 4 | -use Illuminate\Support\Facades\Config; |
|
| 5 | -use Illuminate\Support\Facades\Request; |
|
| 6 | 4 | use Illuminate\Support\Facades\View; |
| 7 | 5 | use Orchestra\Testbench\TestCase; |
| 8 | 6 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function testSetOptions() |
| 43 | 43 | { |
| 44 | - $this->table->setOptions('foo','bar'); |
|
| 44 | + $this->table->setOptions('foo', 'bar'); |
|
| 45 | 45 | |
| 46 | 46 | $this->table->setOptions(array( |
| 47 | 47 | 'foo2' => 'bar2', |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $this->assertArrayHasKey('foo3', $this->table->getCallbacks()); |
| 68 | 68 | |
| 69 | 69 | $this->table->setCallbacks('foo', 'bar', 'baz'); |
| 70 | - $this->assertTrue(False); // should throw exception before here |
|
| 70 | + $this->assertTrue(False); // should throw exception before here |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function testSetNamedFunctionAsCallback() |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | $parameters = $this->table->getViewParameters(); |
| 80 | 80 | |
| 81 | 81 | //an anonymous function should be included as it is. |
| 82 | - $this->assertThat($parameters['options'],$this->stringContains('"foo":function(){ return foo; }') ); |
|
| 82 | + $this->assertThat($parameters['options'], $this->stringContains('"foo":function(){ return foo; }')); |
|
| 83 | 83 | //the callback it's a function name, it shouldn't be quoted |
| 84 | - $this->assertThat($parameters['options'],$this->stringContains('"bar":myBar') ); |
|
| 84 | + $this->assertThat($parameters['options'], $this->stringContains('"bar":myBar')); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $this->assertArrayHasKey('foo3', $this->table->getCustomValues()); |
| 101 | 101 | |
| 102 | 102 | $this->table->setCustomValues('foo', 'bar', 'baz'); |
| 103 | - $this->assertTrue(False); // should throw exception before here |
|
| 103 | + $this->assertTrue(False); // should throw exception before here |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | public function testAddColumn() |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | $this->assertEquals(1, $this->table->countColumns()); |
| 111 | 111 | |
| 112 | - $this->table->addColumn('foo1','foo2'); |
|
| 112 | + $this->table->addColumn('foo1', 'foo2'); |
|
| 113 | 113 | |
| 114 | 114 | $this->assertEquals(3, $this->table->countColumns()); |
| 115 | 115 | |
| 116 | - $this->table->addColumn(array('foo3','foo4')); |
|
| 116 | + $this->table->addColumn(array('foo3', 'foo4')); |
|
| 117 | 117 | |
| 118 | 118 | $this->assertEquals(5, $this->table->countColumns()); |
| 119 | 119 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | 158 | $this->table->setData($data); |
| 159 | - $this->assertEquals($data,$this->table->getData()); |
|
| 159 | + $this->assertEquals($data, $this->table->getData()); |
|
| 160 | 160 | |
| 161 | 161 | } |
| 162 | 162 | |
@@ -164,12 +164,12 @@ discard block |
||
| 164 | 164 | { |
| 165 | 165 | $this->table->setUrl('foo/url'); |
| 166 | 166 | |
| 167 | - $this->assertArrayHasKey('bServerSide',$this->table->getOptions()); |
|
| 168 | - $this->assertArrayHasKey('sAjaxSource',$this->table->getOptions()); |
|
| 167 | + $this->assertArrayHasKey('bServerSide', $this->table->getOptions()); |
|
| 168 | + $this->assertArrayHasKey('sAjaxSource', $this->table->getOptions()); |
|
| 169 | 169 | |
| 170 | 170 | $return = $this->table->getOptions(); |
| 171 | 171 | |
| 172 | - $this->assertEquals('foo/url',$return['sAjaxSource']); |
|
| 172 | + $this->assertEquals('foo/url', $return['sAjaxSource']); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | public function tearDown() |
@@ -75,7 +75,7 @@ |
||
| 75 | 75 | * Any currently set value at this position will be pushed back in the list |
| 76 | 76 | * after the new value. |
| 77 | 77 | * |
| 78 | - * @param mixed $value |
|
| 78 | + * @param string $value |
|
| 79 | 79 | * |
| 80 | 80 | * @return void |
| 81 | 81 | */ |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * |
| 37 | 37 | * @param bool $skip |
| 38 | 38 | * |
| 39 | - * @return void |
|
| 39 | + * @return \PhpParser\NodeVisitor |
|
| 40 | 40 | */ |
| 41 | 41 | public function __construct($skip = false) |
| 42 | 42 | { |
@@ -341,6 +341,10 @@ |
||
| 341 | 341 | return $file; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | + /** |
|
| 345 | + * @param string $class |
|
| 346 | + * @param string $ext |
|
| 347 | + */ |
|
| 344 | 348 | private function findFileWithExtension($class, $ext) |
| 345 | 349 | { |
| 346 | 350 | // PSR-4 lookup |
@@ -344,14 +344,14 @@ discard block |
||
| 344 | 344 | private function findFileWithExtension($class, $ext) |
| 345 | 345 | { |
| 346 | 346 | // PSR-4 lookup |
| 347 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 347 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 348 | 348 | |
| 349 | 349 | $first = $class[0]; |
| 350 | 350 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 351 | 351 | foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { |
| 352 | 352 | if (0 === strpos($class, $prefix)) { |
| 353 | 353 | foreach ($this->prefixDirsPsr4[$prefix] as $dir) { |
| 354 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { |
|
| 354 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $length))) { |
|
| 355 | 355 | return $file; |
| 356 | 356 | } |
| 357 | 357 | } |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | // PSR-4 fallback dirs |
| 363 | 363 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 364 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 364 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 365 | 365 | return $file; |
| 366 | 366 | } |
| 367 | 367 | } |
@@ -373,14 +373,14 @@ discard block |
||
| 373 | 373 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 374 | 374 | } else { |
| 375 | 375 | // PEAR-like class name |
| 376 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 376 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | if (isset($this->prefixesPsr0[$first])) { |
| 380 | 380 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 381 | 381 | if (0 === strpos($class, $prefix)) { |
| 382 | 382 | foreach ($dirs as $dir) { |
| 383 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 383 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 384 | 384 | return $file; |
| 385 | 385 | } |
| 386 | 386 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | |
| 391 | 391 | // PSR-0 fallback dirs |
| 392 | 392 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 393 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 393 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 394 | 394 | return $file; |
| 395 | 395 | } |
| 396 | 396 | } |