validation-bugsnag-email
This commit is contained in:
@@ -38,14 +38,9 @@ class DateColumn extends BaseColumn {
|
||||
public function run($model)
|
||||
{
|
||||
|
||||
if (is_string(is_array($model) ? $model[$this->name] : $model->{$this->name}))
|
||||
if(is_string(is_array($model) ? $model[$this->name]: $model->{$this->name}))
|
||||
{
|
||||
if ($this->custom)
|
||||
{
|
||||
return strftime($this->custom, strtotime($model->{$this->name}));
|
||||
}
|
||||
|
||||
return is_array($model) ? $model[$this->name] : $model->{$this->name};
|
||||
return is_array($model) ? $model[$this->name]: $model->{$this->name};
|
||||
}
|
||||
|
||||
switch($this->format)
|
||||
@@ -71,4 +66,4 @@ class DateColumn extends BaseColumn {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@
|
||||
use Chumper\Datatable\Engines\CollectionEngine;
|
||||
use Chumper\Datatable\Engines\QueryEngine;
|
||||
use Input;
|
||||
use Request;
|
||||
|
||||
/**
|
||||
* Class Datatable
|
||||
@@ -10,31 +11,35 @@ use Input;
|
||||
*/
|
||||
class Datatable {
|
||||
|
||||
private $columnNames = array();
|
||||
|
||||
/**
|
||||
* @param $query
|
||||
* @return QueryEngine
|
||||
* @return \Chumper\Datatable\Engines\QueryEngine
|
||||
*/
|
||||
public function query($query)
|
||||
{
|
||||
return new QueryEngine($query);
|
||||
$class = config('chumper.datatable.classmap.QueryEngine');
|
||||
return new $class($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $collection
|
||||
* @return CollectionEngine
|
||||
* @return \Chumper\Datatable\Engines\CollectionEngine
|
||||
*/
|
||||
public function collection($collection)
|
||||
{
|
||||
return new CollectionEngine($collection);
|
||||
$class = config('chumper.datatable.classmap.CollectionEngine');
|
||||
return new $class($collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Table
|
||||
* @return \Chumper\Datatable\Table
|
||||
*/
|
||||
public function table()
|
||||
{
|
||||
|
||||
return new Table;
|
||||
$class = config('chumper.datatable.classmap.Table');
|
||||
return new $class();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,4 +54,4 @@ class Datatable {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,29 +1,48 @@
|
||||
<?php namespace Chumper\Datatable;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use View;
|
||||
|
||||
class DatatableServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// $this->package('chumper/datatable');
|
||||
$this->publishes([
|
||||
__DIR__.'/../../config/config.php' => config_path('chumper.datatable.php'),
|
||||
__DIR__.'/../../views' => base_path('resources/views/vendor/chumper.datatable'),
|
||||
]);
|
||||
|
||||
$this->loadViewsFrom(__DIR__ . '/../../views', 'chumper.datatable');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('datatable', Datatable::class);
|
||||
|
||||
$this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'chumper.datatable');
|
||||
|
||||
$this->app->singleton('datatable', function($app)
|
||||
{
|
||||
return new Datatable;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,4 +54,5 @@ class DatatableServiceProvider extends ServiceProvider {
|
||||
{
|
||||
return array('datatable');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,14 +1,16 @@
|
||||
<?php namespace Chumper\Datatable\Engines;
|
||||
|
||||
use Exception;
|
||||
use Assetic\Extension\Twig\AsseticFilterFunction;
|
||||
use Chumper\Datatable\Columns\DateColumn;
|
||||
use Chumper\Datatable\Columns\FunctionColumn;
|
||||
use Chumper\Datatable\Columns\TextColumn;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
|
||||
/**
|
||||
* Class BaseEngine
|
||||
* @package Chumper\Datatable\Engines
|
||||
@@ -121,22 +123,12 @@ abstract class BaseEngine {
|
||||
*/
|
||||
protected $exactWordSearch = false;
|
||||
|
||||
/**
|
||||
* @var bool If you need to display all records.
|
||||
*/
|
||||
protected $enableDisplayAll = false;
|
||||
|
||||
/**
|
||||
* @var mixed Additional data which passed from server to client.
|
||||
*/
|
||||
protected $additionalData = null;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->columns = new Collection();
|
||||
$this->config = Config::get('datatable::engine');
|
||||
$this->setExactWordSearch( isset($this->config['exactWordSearch'])? $this->config['exactWordSearch'] : false );
|
||||
$this->setEnableDisplayAll( isset($this->config['enableDisplayAll'])? $this->config['enableDisplayAll'] : false );
|
||||
$this->config = Config::get('chumper.datatable.engine');
|
||||
$this->setExactWordSearch( $this->config['exactWordSearch'] );
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -234,29 +226,20 @@ abstract class BaseEngine {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to handle all the inputs directly from an engine, instead of from Datatables.
|
||||
* @see QueryEngine
|
||||
*/
|
||||
protected function prepareEngine()
|
||||
{
|
||||
$this->handleInputs();
|
||||
$this->prepareSearchColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function make()
|
||||
{
|
||||
$this->prepareEngine();
|
||||
//TODO Handle all inputs
|
||||
$this->handleInputs();
|
||||
$this->prepareSearchColumns();
|
||||
|
||||
$output = array(
|
||||
"aaData" => $this->internalMake($this->columns, $this->searchColumns)->toArray(),
|
||||
"sEcho" => intval($this->sEcho),
|
||||
"iTotalRecords" => $this->totalCount(),
|
||||
"iTotalDisplayRecords" => $this->count(),
|
||||
"aaAdditional" => $this->additionalData,
|
||||
);
|
||||
return Response::json($output);
|
||||
}
|
||||
@@ -286,6 +269,9 @@ abstract class BaseEngine {
|
||||
$cols = func_get_args();
|
||||
}
|
||||
|
||||
if (count($cols) == 1 && $cols[0] == '*')
|
||||
$cols = $this->showColumns;
|
||||
|
||||
$this->orderColumns = $cols;
|
||||
return $this;
|
||||
}
|
||||
@@ -332,26 +318,15 @@ abstract class BaseEngine {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEnableDisplayAll($value = true)
|
||||
{
|
||||
$this->enableDisplayAll = $value;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @param $columnNames Sets up a lookup table for which columns should use exact matching -sburkett
|
||||
* @return $this
|
||||
*/
|
||||
public function setExactMatchColumns($columnNames)
|
||||
{
|
||||
foreach($columnNames as $columnIndex)
|
||||
$this->columnSearchExact[ $columnIndex ] = true;
|
||||
foreach($columnNames as $columnIndex)
|
||||
$this->columnSearchExact[ $columnIndex ] = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAdditionalData($data)
|
||||
{
|
||||
$this->additionalData = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -374,11 +349,6 @@ abstract class BaseEngine {
|
||||
{
|
||||
return $this->aliasMapping;
|
||||
}
|
||||
|
||||
public function getEnableDisplayAll()
|
||||
{
|
||||
return $this->enableDisplayAll;
|
||||
}
|
||||
//-------------protected functionS-------------------
|
||||
|
||||
/**
|
||||
@@ -397,18 +367,7 @@ abstract class BaseEngine {
|
||||
{
|
||||
//limit nicht am query, sondern den ganzen
|
||||
//holen und dann dynamisch in der Collection taken und skippen
|
||||
// fix dispaly all when iDisplayLength choosed unlimit.
|
||||
if(is_numeric($value)){
|
||||
if($value > -1){
|
||||
$this->take($value);
|
||||
return;// jmp
|
||||
}else if($value == -1 && $this->enableDisplayAll){
|
||||
// Display All.
|
||||
return;// jmp
|
||||
}
|
||||
}
|
||||
// iDisplayLength invalid!
|
||||
$this->take(isset($this->config['defaultDisplayLength'])? $this->config['defaultDisplayLength'] : 10);
|
||||
$this->take($value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,17 +393,15 @@ abstract class BaseEngine {
|
||||
*/
|
||||
protected function handleiSortCol_0($value)
|
||||
{
|
||||
if(Input::get('sSortDir_0') == 'desc')
|
||||
$direction[$value] = BaseEngine::ORDER_DESC;
|
||||
if(Request::get('sSortDir_0') == 'desc')
|
||||
$direction = BaseEngine::ORDER_DESC;
|
||||
else
|
||||
$direction[$value] = BaseEngine::ORDER_ASC;
|
||||
$direction = BaseEngine::ORDER_ASC;
|
||||
|
||||
$columns = array();
|
||||
//check if order is allowed
|
||||
if(empty($this->orderColumns))
|
||||
{
|
||||
$columns[] = array(0 => $value, 1 => '`'.$this->getNameByIndex($value).'`');
|
||||
$this->order($columns, $direction);
|
||||
$this->order(array(0 => $value, 1 => $this->getNameByIndex($value)), $direction);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -462,22 +419,16 @@ abstract class BaseEngine {
|
||||
}
|
||||
}
|
||||
|
||||
$iSortingCols = Input::get('iSortingCols');
|
||||
$sortingCols[] = $value;
|
||||
for($i = 1; $i < $iSortingCols; $i++) {
|
||||
$isc = Input::get('iSortCol_'.$i);
|
||||
$sortingCols[] = $isc;
|
||||
$direction[$isc] = Input::get('sSortDir_'.$i);
|
||||
}
|
||||
|
||||
$allColumns = array_keys($this->columns->all());
|
||||
foreach ($sortingCols as $num) {
|
||||
if(isset($allColumns[$num]) && in_array($allColumns[$num], $cleanNames)) {
|
||||
$columns[] = array(0 => $num, 1 => '`'.$this->orderColumns[array_search($allColumns[$num],$cleanNames)].'`');
|
||||
$i = 0;
|
||||
foreach($this->columns as $name => $column)
|
||||
{
|
||||
if($i == $value && in_array($name, $cleanNames))
|
||||
{
|
||||
$this->order(array(0 => $value, 1 => $this->orderColumns[array_search($name,$cleanNames)]), $direction);
|
||||
return;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->order($columns, $direction);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,6 +439,7 @@ abstract class BaseEngine {
|
||||
*/
|
||||
protected function handleSingleColumnSearch($columnIndex, $searchValue)
|
||||
{
|
||||
//dd($columnIndex, $searchValue, $this->searchColumns);
|
||||
if (!isset($this->searchColumns[$columnIndex])) return;
|
||||
if (empty($searchValue) && $searchValue !== '0') return;
|
||||
|
||||
@@ -501,7 +453,7 @@ abstract class BaseEngine {
|
||||
protected function handleInputs()
|
||||
{
|
||||
//Handle all inputs magically
|
||||
foreach (Input::all() as $key => $input) {
|
||||
foreach (Request::all() as $key => $input) {
|
||||
|
||||
// handle single column search
|
||||
if ($this->isParameterForSingleColumnSearch($key))
|
||||
@@ -598,4 +550,4 @@ abstract class BaseEngine {
|
||||
abstract protected function totalCount();
|
||||
abstract protected function count();
|
||||
abstract protected function internalMake(Collection $columns, array $searchColumns = array());
|
||||
}
|
||||
}
|
@@ -12,6 +12,19 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class CollectionEngine extends BaseEngine {
|
||||
|
||||
/**
|
||||
* Constant for OR queries in internal search
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OR_CONDITION = 'OR';
|
||||
/**
|
||||
* Constant for AND queries in internal search
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const AND_CONDITION = 'AND';
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
@@ -22,23 +35,14 @@ class CollectionEngine extends BaseEngine {
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const OR_CONDITION = 'OR';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const AND_CONDITION = 'AND';
|
||||
|
||||
/**
|
||||
* @var array Different options
|
||||
*/
|
||||
private $options = array(
|
||||
'stripOrder' => false,
|
||||
'stripSearch' => false,
|
||||
'caseSensitive' => false,
|
||||
'sortFlags' => SORT_NATURAL,
|
||||
'stripOrder' => false,
|
||||
'stripSearch' => false,
|
||||
'caseSensitive' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -98,9 +102,9 @@ class CollectionEngine extends BaseEngine {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function stripOrder()
|
||||
public function stripOrder($callback = true)
|
||||
{
|
||||
$this->options['stripOrder'] = true;
|
||||
$this->options['stripOrder'] = $callback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -110,9 +114,20 @@ class CollectionEngine extends BaseEngine {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOrderStrip()
|
||||
public function setOrderStrip($callback = true)
|
||||
{
|
||||
$this->options['stripOrder'] = true;
|
||||
return $this->stripOrder($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sort behaviour of the doInternalOrder() function.
|
||||
*
|
||||
* @param int $sort_flags For details see: http://php.net/manual/en/function.sort.php
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrderFlags($sort_flags = SORT_NATURAL)
|
||||
{
|
||||
$this->options['sortFlags'] = $sort_flags;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -137,6 +152,13 @@ class CollectionEngine extends BaseEngine {
|
||||
return $this->workingCollection->slice($this->skip,$this->limit)->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a collection based on the DataTables search parameters (sSearch_0 etc)
|
||||
* See http://legacy.datatables.net/usage/server-side
|
||||
*
|
||||
* @param Collection $columns All the columns in the DataTable
|
||||
* @param array $searchColumns Columns to search on - values are case-sensitive (must match definition from $columns)
|
||||
*/
|
||||
private function doInternalSearch(Collection $columns, array $searchColumns)
|
||||
{
|
||||
if((is_null($this->search) || empty($this->search)) && empty($this->fieldSearches))
|
||||
@@ -146,9 +168,7 @@ class CollectionEngine extends BaseEngine {
|
||||
$caseSensitive = $this->options['caseSensitive'];
|
||||
|
||||
$toSearch = array();
|
||||
|
||||
$searchType = self::AND_CONDITION;
|
||||
|
||||
// Map the searchColumns to the real columns
|
||||
$ii = 0;
|
||||
foreach($columns as $i => $col)
|
||||
@@ -164,7 +184,6 @@ class CollectionEngine extends BaseEngine {
|
||||
{
|
||||
if($value)
|
||||
$searchType = self::OR_CONDITION;
|
||||
|
||||
$toSearch[$ii] = $value;
|
||||
}
|
||||
}
|
||||
@@ -174,7 +193,6 @@ class CollectionEngine extends BaseEngine {
|
||||
$self = $this;
|
||||
$this->workingCollection = $this->workingCollection->filter(function($row) use ($toSearch, $caseSensitive, $self, $searchType)
|
||||
{
|
||||
|
||||
for($i=0, $stack=array(), $nb=count($row); $i<$nb; $i++)
|
||||
{
|
||||
if(!array_key_exists($i, $toSearch))
|
||||
@@ -221,11 +239,9 @@ class CollectionEngine extends BaseEngine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($searchType == $self::AND_CONDITION)
|
||||
{
|
||||
$result = array_diff_key(array_filter($toSearch), $stack);
|
||||
|
||||
if(empty($result))
|
||||
return true;
|
||||
}
|
||||
@@ -242,33 +258,31 @@ class CollectionEngine extends BaseEngine {
|
||||
if(is_null($this->orderColumn))
|
||||
return;
|
||||
|
||||
// Bug added on pull request #309
|
||||
$column = array_values($this->orderColumn)[0];
|
||||
$direction = array_values($this->orderDirection)[0];
|
||||
$column = $this->orderColumn[0];
|
||||
$stripOrder = $this->options['stripOrder'];
|
||||
$self = $this;
|
||||
$this->workingCollection = $this->workingCollection->sortBy(function($row) use ($column,$stripOrder,$self) {
|
||||
|
||||
$sortFunction = 'sortBy';
|
||||
if ($direction == BaseEngine::ORDER_DESC)
|
||||
$sortFunction = 'sortByDesc';
|
||||
|
||||
$this->workingCollection->{$sortFunction}(function($row) use ($column,$stripOrder) {
|
||||
|
||||
if($this->getAliasMapping())
|
||||
if($self->getAliasMapping())
|
||||
{
|
||||
$column = $this->getNameByIndex($column[0]);
|
||||
return $row[$column];
|
||||
$column = $self->getNameByIndex($column);
|
||||
}
|
||||
if($stripOrder)
|
||||
{
|
||||
return strip_tags($row[$column]);
|
||||
if(is_callable($stripOrder)){
|
||||
return $stripOrder($row, $column);
|
||||
}else{
|
||||
return strip_tags($row[$column]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_array($column))
|
||||
return $row[$column[0]];
|
||||
return $row[$column];
|
||||
}
|
||||
});
|
||||
}, $this->options['sortFlags']);
|
||||
|
||||
if($this->orderDirection == BaseEngine::ORDER_DESC)
|
||||
$this->workingCollection = $this->workingCollection->reverse();
|
||||
}
|
||||
|
||||
private function compileArray($columns)
|
||||
@@ -286,6 +300,10 @@ class CollectionEngine extends BaseEngine {
|
||||
{
|
||||
$entry['DT_RowId'] = call_user_func($self->getRowId(),$row);
|
||||
}
|
||||
if(!is_null($self->getRowData()) && is_callable($self->getRowData()))
|
||||
{
|
||||
$entry['DT_RowData'] = call_user_func($self->getRowData(),$row);
|
||||
}
|
||||
$i=0;
|
||||
foreach ($columns as $col)
|
||||
{
|
||||
@@ -303,4 +321,4 @@ class CollectionEngine extends BaseEngine {
|
||||
return $entry;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,22 +1,27 @@
|
||||
<?php namespace Chumper\Datatable\Engines;
|
||||
|
||||
use \Exception;
|
||||
use Chumper\Datatable\Datatable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class QueryEngine extends BaseEngine {
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Query\Builder
|
||||
* @var Builder
|
||||
*/
|
||||
public $builder;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Query\Builder
|
||||
* @var Builder
|
||||
*/
|
||||
public $originalBuilder;
|
||||
|
||||
/**
|
||||
* @var array single column searches
|
||||
*/
|
||||
public $columnSearches = array();
|
||||
|
||||
/**
|
||||
* @var Collection the returning collection
|
||||
*/
|
||||
@@ -30,16 +35,12 @@ class QueryEngine extends BaseEngine {
|
||||
/**
|
||||
* @var array Different options
|
||||
*/
|
||||
private $options = array(
|
||||
protected $options = array(
|
||||
'searchOperator' => 'LIKE',
|
||||
'searchWithAlias' => false,
|
||||
'orderOrder' => null,
|
||||
'counter' => 0,
|
||||
'noGroupByOnCount' => false,
|
||||
'distinctCountGroup'=> false,
|
||||
'emptyAtEnd' => false,
|
||||
'returnQuery' => false,
|
||||
'queryKeepsLimits' => false,
|
||||
);
|
||||
|
||||
function __construct($builder)
|
||||
@@ -64,21 +65,20 @@ class QueryEngine extends BaseEngine {
|
||||
|
||||
public function totalCount()
|
||||
{
|
||||
if ($this->options['distinctCountGroup'] && count($this->originalBuilder->groups) == 1)
|
||||
{
|
||||
$this->originalBuilder->groups = null;
|
||||
// Store temporary copy as we may modify it, we'd be stupid to modify
|
||||
// the actual "original" copy...
|
||||
$originalBuilder = $this->originalBuilder;
|
||||
|
||||
if ($this->options['noGroupByOnCount']) {
|
||||
$originalBuilder = $this->removeGroupBy($originalBuilder);
|
||||
}
|
||||
if($this->options['searchWithAlias']) {
|
||||
$cnt = count($this->originalBuilder->get());
|
||||
} else {
|
||||
$cnt = $this->originalBuilder->count();
|
||||
}
|
||||
return $cnt;
|
||||
|
||||
return $originalBuilder->count();
|
||||
}
|
||||
|
||||
public function getArray()
|
||||
{
|
||||
return $this->getCollection($this->builder)->toArray();
|
||||
return $this->getCollection($this->builder)->toArray();
|
||||
}
|
||||
|
||||
public function reset()
|
||||
@@ -94,100 +94,18 @@ class QueryEngine extends BaseEngine {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSearchWithAlias($value = true)
|
||||
public function setSearchWithAlias()
|
||||
{
|
||||
$this->options['searchWithAlias'] = (bool)$value;
|
||||
$this->options['searchWithAlias'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEmptyAtEnd()
|
||||
public function setNoGroupByOnCount()
|
||||
{
|
||||
$this->options['emptyAtEnd'] = true;
|
||||
$this->options['noGroupByOnCount'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setNoGroupByOnCount($value = true)
|
||||
{
|
||||
$this->options['noGroupByOnCount'] = (bool)$value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the COUNT(*) when there is a group by
|
||||
*
|
||||
* setDistinctIfGroup will change the count(*) query inside the query builder if it only finds one group by.
|
||||
*
|
||||
* Instead of counting all of the rows, the distinct rows in the group by will be counted instead.
|
||||
*
|
||||
* @param bool $value should this option be enabled?
|
||||
* @return $this
|
||||
*/
|
||||
public function setDistinctCountGroup($value = true)
|
||||
{
|
||||
$this->options['distinctCountGroup'] = (bool)$value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Let internalMake return a QueryBuilder, instead of a collection.
|
||||
*
|
||||
* @param bool $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setReturnQuery($value = true)
|
||||
{
|
||||
$this->options['returnQuery'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow setting an array of options on the QueryEngine without needing to run each setter.
|
||||
*
|
||||
* @param array $options
|
||||
* @return $this
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setOptions($options = array())
|
||||
{
|
||||
foreach($options as $option_name => $option_value)
|
||||
{
|
||||
if (!isset($this->options[$option_name]))
|
||||
throw new Exception("The option $option_name is not a valid that can be selected.");
|
||||
|
||||
if (is_bool($this->options[$option_name]))
|
||||
$option_value = (bool)$option_value;
|
||||
|
||||
$this->options[$option_name] = $option_value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the behaviour of getQueryBuiler for limits
|
||||
*
|
||||
* @param bool $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setQueryKeepsLimits($value = true)
|
||||
{
|
||||
$this->options['queryKeepsLimits'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Builder object back from the engine. Don't return a collection.
|
||||
*
|
||||
* @return Query\Builder
|
||||
*/
|
||||
public function getQueryBuilder()
|
||||
{
|
||||
$this->prepareEngine();
|
||||
$this->setReturnQuery();
|
||||
|
||||
return $this->internalMake($this->columns, $this->searchColumns);
|
||||
}
|
||||
|
||||
//--------PRIVATE FUNCTIONS
|
||||
|
||||
protected function internalMake(Collection $columns, array $searchColumns = array())
|
||||
@@ -198,68 +116,64 @@ class QueryEngine extends BaseEngine {
|
||||
$builder = $this->doInternalSearch($builder, $searchColumns);
|
||||
$countBuilder = $this->doInternalSearch($countBuilder, $searchColumns);
|
||||
|
||||
if ($this->options['distinctCountGroup'] && count($countBuilder->groups) == 1)
|
||||
{
|
||||
$countBuilder->select(\DB::raw('COUNT(DISTINCT `' . $countBuilder->groups[0] . '`) as total'));
|
||||
$countBuilder->groups = null;
|
||||
|
||||
$results = $countBuilder->get('rows');
|
||||
if (isset($results[0]))
|
||||
{
|
||||
$result = array_change_key_case((array) $results[0]);
|
||||
|
||||
}
|
||||
$this->options['counter'] = $result['total'];
|
||||
}
|
||||
elseif($this->options['searchWithAlias'])
|
||||
if($this->options['searchWithAlias'])
|
||||
{
|
||||
$this->options['counter'] = count($countBuilder->get());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove the GROUP BY clause for the count
|
||||
if ($this->options['noGroupByOnCount']) {
|
||||
$countBuilder->groups = null;
|
||||
$countBuilder = $this->removeGroupBy($countBuilder);
|
||||
}
|
||||
$this->options['counter'] = $countBuilder->count();
|
||||
}
|
||||
|
||||
$builder = $this->doInternalOrder($builder, $columns);
|
||||
|
||||
if ($this->options['returnQuery'])
|
||||
if ($this->options['queryKeepsLimits'])
|
||||
return $this->getQuery($builder);
|
||||
else
|
||||
return $builder;
|
||||
|
||||
$collection = $this->compile($builder, $columns);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $builder
|
||||
* @return Collection
|
||||
* Remove the GROUP BY clause from a builder.
|
||||
*
|
||||
* @param Builder|QueryBuilder $builder
|
||||
* @return Builder|QueryBuilder $builder with the groups property set to null.
|
||||
*/
|
||||
private function getQuery($builder)
|
||||
private function removeGroupBy($builder)
|
||||
{
|
||||
if (is_null($this->collection)) {
|
||||
if ($this->skip > 0) {
|
||||
$builder = $builder->skip($this->skip);
|
||||
}
|
||||
if ($this->limit > 0) {
|
||||
$builder = $builder->take($this->limit);
|
||||
}
|
||||
// Handle \Illuminate\Database\Eloquent\Builder
|
||||
if ($builder instanceof Builder) {
|
||||
$query = $builder->getQuery();
|
||||
$query->groups = null;
|
||||
$builder->setQuery($query);
|
||||
}
|
||||
// Handle \Illuminate\Database\Query\Builder
|
||||
else {
|
||||
$builder->groups = null;
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $builder
|
||||
* @return Collection
|
||||
*/
|
||||
private function getCollection($builder)
|
||||
{
|
||||
$builder = $this->getQuery($builder);
|
||||
|
||||
if (is_null($this->collection))
|
||||
if($this->collection == null)
|
||||
{
|
||||
if($this->skip > 0)
|
||||
{
|
||||
$builder = $builder->skip($this->skip);
|
||||
}
|
||||
if($this->limit > 0)
|
||||
{
|
||||
$builder = $builder->take($this->limit);
|
||||
}
|
||||
//dd($this->builder->toSql());
|
||||
$this->collection = $builder->get();
|
||||
|
||||
if(is_array($this->collection))
|
||||
@@ -271,32 +185,38 @@ class QueryEngine extends BaseEngine {
|
||||
private function doInternalSearch($builder, $columns)
|
||||
{
|
||||
if (!empty($this->search)) {
|
||||
$builder = $this->buildSearchQuery($builder, $columns);
|
||||
$this->buildSearchQuery($builder, $columns);
|
||||
}
|
||||
|
||||
if (!empty($this->columnSearches)) {
|
||||
$builder = $this->buildSingleColumnSearches($builder);
|
||||
$this->buildSingleColumnSearches($builder);
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
private function buildSearchQuery($builder, $columns)
|
||||
protected function buildSearchQuery($builder, $columns)
|
||||
{
|
||||
$like = $this->options['searchOperator'];
|
||||
$search = $this->search;
|
||||
$exact = $this->exactWordSearch;
|
||||
$builder = $builder->where(function($query) use ($columns, $search, $like, $exact) {
|
||||
foreach ($columns as $c) {
|
||||
//column to search within relationships : relatedModel::column
|
||||
if(strrpos($c, '::')) {
|
||||
$c = explode('::', $c);
|
||||
$query->orWhereHas($c[0], function($q) use($c, $like, $exact, $search){
|
||||
$q->where($c[1], $like, $exact ? $search : '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
//column to CAST following the pattern column:newType:[maxlength]
|
||||
if(strrpos($c, ':')){
|
||||
elseif(strrpos($c, ':')){
|
||||
$c = explode(':', $c);
|
||||
if(isset($c[2]))
|
||||
$c[1] .= "($c[2])";
|
||||
$query->orWhereRaw("cast($c[0] as $c[1]) ".$like." ?", array($exact ? "$search" : "%$search%"));
|
||||
}
|
||||
else
|
||||
$query->orWhere($c,$like,$exact ? $search : '%'.$search.'%');
|
||||
$query->orWhere($c, $like, $exact ? $search : '%' . $search . '%');
|
||||
}
|
||||
});
|
||||
return $builder;
|
||||
@@ -306,17 +226,14 @@ class QueryEngine extends BaseEngine {
|
||||
* @param $builder
|
||||
* Modified by sburkett to facilitate individual exact match searching on individual columns (rather than for all columns)
|
||||
*/
|
||||
private function buildSingleColumnSearches(Builder $builder)
|
||||
|
||||
private function buildSingleColumnSearches($builder)
|
||||
{
|
||||
foreach ($this->columnSearches as $index => $searchValue) {
|
||||
$fieldSearchIndex = $this->fieldSearches[$index];
|
||||
|
||||
if (isset($this->columnSearchExact[$fieldSearchIndex])
|
||||
&& $this->columnSearchExact[$fieldSearchIndex] == 1)
|
||||
{
|
||||
$builder->where($fieldSearchIndex, '=', $searchValue);
|
||||
if(@$this->columnSearchExact[ $this->fieldSearches[$index] ] == 1) {
|
||||
$builder->where($this->fieldSearches[$index], '=', $searchValue );
|
||||
} else {
|
||||
$builder->where($fieldSearchIndex, $this->options['searchOperator'], '%' . $searchValue . '%');
|
||||
$builder->where($this->fieldSearches[$index], $this->options['searchOperator'], '%' . $searchValue . '%');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,22 +279,28 @@ class QueryEngine extends BaseEngine {
|
||||
|
||||
private function doInternalOrder($builder, $columns)
|
||||
{
|
||||
//var_dump($this->orderColumn);
|
||||
if(!is_null($this->orderColumn))
|
||||
{
|
||||
foreach ($this->orderColumn as $ordCol) {
|
||||
if(strrpos($ordCol[1], ':')){
|
||||
$c = explode(':', $ordCol[1]);
|
||||
if(isset($c[2]))
|
||||
$c[1] .= "($c[2])";
|
||||
$prefix = $this->options['emptyAtEnd'] ? "ISNULL({$c[0]}) asc," : '';
|
||||
$builder = $builder->orderByRaw($prefix." cast($c[0] as $c[1]) ".$this->orderDirection[$ordCol[0]]);
|
||||
}
|
||||
else {
|
||||
$prefix = $this->options['emptyAtEnd'] ? "ISNULL({$ordCol[1]}) asc," : '';
|
||||
$builder = $builder->orderByRaw($prefix.' '.$ordCol[1].' '.$this->orderDirection[$ordCol[0]]);
|
||||
$i = 0;
|
||||
foreach($columns as $col)
|
||||
{
|
||||
|
||||
if($i === (int) $this->orderColumn[0])
|
||||
{
|
||||
if(strrpos($this->orderColumn[1], ':')){
|
||||
$c = explode(':', $this->orderColumn[1]);
|
||||
if(isset($c[2]))
|
||||
$c[1] .= "($c[2])";
|
||||
$builder = $builder->orderByRaw("cast($c[0] as $c[1]) ".$this->orderDirection);
|
||||
}
|
||||
else
|
||||
$builder = $builder->orderBy($col->getName(), $this->orderDirection);
|
||||
return $builder;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $builder;
|
||||
}
|
||||
}
|
||||
}
|
39
vendor/chumper/datatable/src/config/config.php
vendored
39
vendor/chumper/datatable/src/config/config.php
vendored
@@ -93,7 +93,7 @@ return array(
|
||||
|
|
||||
*/
|
||||
|
||||
'table_view' => 'datatable::template',
|
||||
'table_view' => 'chumper.datatable::template',
|
||||
|
||||
|
||||
/*
|
||||
@@ -106,9 +106,7 @@ return array(
|
||||
|
|
||||
*/
|
||||
|
||||
'script_view' => 'datatable::javascript',
|
||||
|
||||
|
||||
'script_view' => 'chumper.datatable::javascript',
|
||||
),
|
||||
|
||||
|
||||
@@ -132,24 +130,17 @@ return array(
|
||||
*/
|
||||
|
||||
'exactWordSearch' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable to display all records.
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Be careful! It may be overloaded with large record.
|
||||
| Supported: boolean
|
||||
|
|
||||
*/
|
||||
'enableDisplayAll' => false,
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Limit display when iDisplayLength invaild
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'defaultDisplayLength' => 10,
|
||||
|
||||
),
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allow overrides Datatable core classes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
*/
|
||||
'classmap' => array(
|
||||
'CollectionEngine' => 'Chumper\Datatable\Engines\CollectionEngine',
|
||||
'QueryEngine' => 'Chumper\Datatable\Engines\QueryEngine',
|
||||
'Table' => 'Chumper\Datatable\Table',
|
||||
)
|
||||
|
||||
|
||||
);
|
||||
);
|
@@ -1,32 +1,8 @@
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function(){
|
||||
// dynamic table
|
||||
oTable = jQuery('#{{ $id }}').dataTable({
|
||||
|
||||
@foreach ($options as $k => $o)
|
||||
{{ json_encode($k) }}: @if(!is_array($o)) @if(preg_match("/function/", $o)) {{ $o }}, @else {{ json_encode($o) }}, @endif
|
||||
@elseif(key($o) === 0) {{-- if we have an array, no need to print keys --}}
|
||||
[
|
||||
@foreach ($o as $r)
|
||||
@if(is_array($r)) {{ json_encode($r) }}, @elseif(preg_match("/function/", $r)) {{ $r }}, @else {{ json_encode($r) }}, @endif
|
||||
|
||||
@endforeach
|
||||
],
|
||||
@else
|
||||
{
|
||||
@foreach ($o as $x => $r)
|
||||
{{ json_encode($x) }}: @if(is_array($r)) {{ json_encode($r) }}, @elseif(preg_match("/function/", $r)) {{ $r }}, @else {{ json_encode($r) }}, @endif
|
||||
@endforeach
|
||||
},
|
||||
@endif
|
||||
|
||||
@endforeach
|
||||
|
||||
@foreach ($callbacks as $k => $o)
|
||||
{{ json_encode($k) }}: {{ $o }},
|
||||
@endforeach
|
||||
|
||||
});
|
||||
// custom values are available via $values array
|
||||
oTable = jQuery('#{!! $id !!}').dataTable(
|
||||
{!! $options !!}
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</script>
|
@@ -1,36 +1,27 @@
|
||||
<table id="{{ $id }}" class="{{ $class }}">
|
||||
<table id="{!! $id !!}" class="{!! $class !!}">
|
||||
<colgroup>
|
||||
@for ($i = 0; $i < count($columns); $i++)
|
||||
<col class="con{{ $i }}" />
|
||||
<col class="con{!! $i !!}" />
|
||||
@endfor
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
@foreach($columns as $i => $c)
|
||||
<th align="center" valign="middle" class="head{{ $i }}">{{ $c }}</th>
|
||||
<th align="center" valign="middle" class="head{!! $i !!}">{!! $c !!}</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
@if ($footerMode !== 'hidden')
|
||||
<tfoot>
|
||||
<tr>
|
||||
@foreach($columns as $i => $c)
|
||||
<th align="center" valign="middle" class="footer{{ $i }}">@if($footerMode === 'columns') {{ $c }} @endif</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</tfoot>
|
||||
@endif
|
||||
<tbody>
|
||||
@foreach($data as $d)
|
||||
<tr>
|
||||
@foreach($d as $dd)
|
||||
<td>{{ $dd }}</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
<tr>
|
||||
@foreach($d as $dd)
|
||||
<td>{!! $dd !!}</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@if (!$noScript)
|
||||
@include(Config::get('datatable::table.script_view'), array('id' => $id, 'options' => $options, 'callbacks' => $callbacks))
|
||||
@include(Config::get('chumper.datatable.table.script_view'), array('id' => $id, 'options' => $options))
|
||||
@endif
|
Reference in New Issue
Block a user