dependencies-upgrade
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Yajra\DataTables;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class ApiResourceDataTable extends CollectionDataTable
|
||||
{
|
||||
@@ -25,7 +25,7 @@ class ApiResourceDataTable extends CollectionDataTable
|
||||
/**
|
||||
* Can the DataTable engine be created with these parameters.
|
||||
*
|
||||
* @param mixed $source
|
||||
* @param mixed $source
|
||||
* @return bool
|
||||
*/
|
||||
public static function canCreate($source)
|
||||
@@ -36,7 +36,7 @@ class ApiResourceDataTable extends CollectionDataTable
|
||||
/**
|
||||
* Factory method, create and return an instance for the DataTable engine.
|
||||
*
|
||||
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection $source
|
||||
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection $source
|
||||
* @return ApiResourceDataTable|DataTableAbstract
|
||||
*/
|
||||
public static function create($source)
|
||||
@@ -47,7 +47,7 @@ class ApiResourceDataTable extends CollectionDataTable
|
||||
/**
|
||||
* CollectionEngine constructor.
|
||||
*
|
||||
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection $collection
|
||||
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection $collection
|
||||
*/
|
||||
public function __construct(AnonymousResourceCollection $collection)
|
||||
{
|
||||
|
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Yajra\DataTables;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CollectionDataTable extends DataTableAbstract
|
||||
{
|
||||
@@ -33,7 +33,7 @@ class CollectionDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Can the DataTable engine be created with these parameters.
|
||||
*
|
||||
* @param mixed $source
|
||||
* @param mixed $source
|
||||
* @return bool
|
||||
*/
|
||||
public static function canCreate($source)
|
||||
@@ -44,7 +44,7 @@ class CollectionDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Factory method, create and return an instance for the DataTable engine.
|
||||
*
|
||||
* @param array|\Illuminate\Support\Collection $source
|
||||
* @param array|\Illuminate\Support\Collection $source
|
||||
* @return CollectionDataTable|DataTableAbstract
|
||||
*/
|
||||
public static function create($source)
|
||||
@@ -59,7 +59,7 @@ class CollectionDataTable extends DataTableAbstract
|
||||
/**
|
||||
* CollectionEngine constructor.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $collection
|
||||
* @param \Illuminate\Support\Collection $collection
|
||||
*/
|
||||
public function __construct(Collection $collection)
|
||||
{
|
||||
@@ -73,7 +73,7 @@ class CollectionDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Serialize collection.
|
||||
*
|
||||
* @param mixed $collection
|
||||
* @param mixed $collection
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function serialize($collection)
|
||||
@@ -100,7 +100,7 @@ class CollectionDataTable extends DataTableAbstract
|
||||
{
|
||||
$columns = $this->request->get('columns', []);
|
||||
for ($i = 0, $c = count($columns); $i < $c; $i++) {
|
||||
$column = $this->getColumnName($i);
|
||||
$column = $this->getColumnName($i, 'filter');
|
||||
|
||||
if (! $this->request->isColumnSearchable($i) || $this->isBlacklisted($column)) {
|
||||
continue;
|
||||
@@ -151,7 +151,7 @@ class CollectionDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Organizes works.
|
||||
*
|
||||
* @param bool $mDataSupport
|
||||
* @param bool $mDataSupport
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function make($mDataSupport = true)
|
||||
@@ -201,7 +201,7 @@ class CollectionDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Revert transformed DT_RowIndex back to it's original values.
|
||||
*
|
||||
* @param bool $mDataSupport
|
||||
* @param bool $mDataSupport
|
||||
*/
|
||||
private function revertIndexColumn($mDataSupport)
|
||||
{
|
||||
@@ -219,7 +219,7 @@ class CollectionDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Perform global search for the given keyword.
|
||||
*
|
||||
* @param string $keyword
|
||||
* @param string $keyword
|
||||
*/
|
||||
protected function globalSearch($keyword)
|
||||
{
|
||||
@@ -230,8 +230,8 @@ class CollectionDataTable extends DataTableAbstract
|
||||
|
||||
$data = $this->serialize($row);
|
||||
foreach ($this->request->searchableColumnIndex() as $index) {
|
||||
$column = $this->getColumnName($index);
|
||||
$value = Arr::get($data, $column);
|
||||
$column = $this->getColumnName($index, 'sort');
|
||||
$value = Arr::get($data, $column);
|
||||
if (! $value || is_array($value)) {
|
||||
if (! is_numeric($value)) {
|
||||
continue;
|
||||
@@ -278,14 +278,14 @@ class CollectionDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Get array sorter closure.
|
||||
*
|
||||
* @param array $criteria
|
||||
* @param array $criteria
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function getSorter(array $criteria)
|
||||
{
|
||||
$sorter = function ($a, $b) use ($criteria) {
|
||||
foreach ($criteria as $orderable) {
|
||||
$column = $this->getColumnName($orderable['column']);
|
||||
$column = $this->getColumnName($orderable['column'], 'sort');
|
||||
$direction = $orderable['direction'];
|
||||
if ($direction === 'desc') {
|
||||
$first = $b;
|
||||
@@ -294,10 +294,18 @@ class CollectionDataTable extends DataTableAbstract
|
||||
$first = $a;
|
||||
$second = $b;
|
||||
}
|
||||
if ($this->config->isCaseInsensitive()) {
|
||||
$cmp = strnatcasecmp($first[$column], $second[$column]);
|
||||
if (is_numeric($first[$column] ?? null) && is_numeric($second[$column] ?? null)) {
|
||||
if ($first[$column] < $second[$column]) {
|
||||
$cmp = -1;
|
||||
} elseif ($first[$column] > $second[$column]) {
|
||||
$cmp = 1;
|
||||
} else {
|
||||
$cmp = 0;
|
||||
}
|
||||
} elseif ($this->config->isCaseInsensitive()) {
|
||||
$cmp = strnatcasecmp($first[$column] ?? null, $second[$column] ?? null);
|
||||
} else {
|
||||
$cmp = strnatcmp($first[$column], $second[$column]);
|
||||
$cmp = strnatcmp($first[$column] ?? null, $second[$column] ?? null);
|
||||
}
|
||||
if ($cmp != 0) {
|
||||
return $cmp;
|
||||
@@ -326,7 +334,7 @@ class CollectionDataTable extends DataTableAbstract
|
||||
* the FULL dataset the collection was sliced from. It effectively allows the
|
||||
* collection to be "pre-sliced".
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int $offset
|
||||
* @return $this
|
||||
*/
|
||||
public function setOffset(int $offset)
|
||||
|
@@ -29,8 +29,8 @@ interface DataTable
|
||||
* Set auto filter off and run your own filter.
|
||||
* Overrides global search.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param bool $globalSearch
|
||||
* @param callable $callback
|
||||
* @param bool $globalSearch
|
||||
* @return $this
|
||||
*/
|
||||
public function filter(callable $callback, $globalSearch = false);
|
||||
@@ -66,7 +66,7 @@ interface DataTable
|
||||
/**
|
||||
* Organizes works.
|
||||
*
|
||||
* @param bool $mDataSupport
|
||||
* @param bool $mDataSupport
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function make($mDataSupport = true);
|
||||
|
13
vendor/yajra/laravel-datatables-oracle/src/Contracts/Formatter.php
vendored
Normal file
13
vendor/yajra/laravel-datatables-oracle/src/Contracts/Formatter.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Yajra\DataTables\Contracts;
|
||||
|
||||
interface Formatter
|
||||
{
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $row
|
||||
* @return string
|
||||
*/
|
||||
public function format($value, $row);
|
||||
}
|
@@ -2,23 +2,25 @@
|
||||
|
||||
namespace Yajra\DataTables;
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Contracts\Support\Jsonable;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Yajra\DataTables\Utilities\Helper;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Yajra\DataTables\Contracts\DataTable;
|
||||
use Illuminate\Contracts\Support\Jsonable;
|
||||
use Yajra\DataTables\Exceptions\Exception;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Yajra\DataTables\Contracts\Formatter;
|
||||
use Yajra\DataTables\Processors\DataProcessor;
|
||||
use Yajra\DataTables\Utilities\Helper;
|
||||
|
||||
/**
|
||||
* @method DataTableAbstract setTransformer($transformer)
|
||||
* @method DataTableAbstract setSerializer($transformer)
|
||||
*
|
||||
* @property mixed transformer
|
||||
* @property mixed serializer
|
||||
*
|
||||
* @see https://github.com/yajra/laravel-datatables-fractal for transformer related methods.
|
||||
*/
|
||||
abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
@@ -145,10 +147,15 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $searchPanes = [];
|
||||
|
||||
/**
|
||||
* Can the DataTable engine be created with these parameters.
|
||||
*
|
||||
* @param mixed $source
|
||||
* @param mixed $source
|
||||
* @return bool
|
||||
*/
|
||||
public static function canCreate($source)
|
||||
@@ -159,7 +166,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Factory method, create and return an instance for the DataTable engine.
|
||||
*
|
||||
* @param mixed $source
|
||||
* @param mixed $source
|
||||
* @return DataTableAbstract
|
||||
*/
|
||||
public static function create($source)
|
||||
@@ -170,9 +177,9 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Add column in collection.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|callable $content
|
||||
* @param bool|int $order
|
||||
* @param string $name
|
||||
* @param string|callable $content
|
||||
* @param bool|int $order
|
||||
* @return $this
|
||||
*/
|
||||
public function addColumn($name, $content, $order = false)
|
||||
@@ -184,6 +191,30 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $columns
|
||||
* @param mixed|\Yajra\DataTables\Contracts\Formatter $formatter
|
||||
* @return $this
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function formatColumn($columns, $formatter)
|
||||
{
|
||||
if (is_string($formatter) && class_exists($formatter)) {
|
||||
$formatter = app($formatter);
|
||||
}
|
||||
|
||||
if (! $formatter instanceof Formatter) {
|
||||
throw new \Exception('$formatter must be an instance of '. Formatter::class);
|
||||
}
|
||||
|
||||
foreach ((array) $columns as $column) {
|
||||
$this->addColumn($column . '_formatted', $formatter);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add DT row index column on response.
|
||||
*
|
||||
@@ -199,8 +230,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Edit column's content.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|callable $content
|
||||
* @param string $name
|
||||
* @param string|callable $content
|
||||
* @return $this
|
||||
*/
|
||||
public function editColumn($name, $content)
|
||||
@@ -226,7 +257,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Get only selected columns in response.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return $this
|
||||
*/
|
||||
public function only(array $columns = [])
|
||||
@@ -239,7 +270,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Declare columns to escape values.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string|array $columns
|
||||
* @return $this
|
||||
*/
|
||||
public function escapeColumns($columns = '*')
|
||||
@@ -252,7 +283,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Add a makeHidden() to the row object.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function makeHidden(array $attributes = [])
|
||||
@@ -265,7 +296,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Add a makeVisible() to the row object.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function makeVisible(array $attributes = [])
|
||||
@@ -279,8 +310,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
* Set columns that should not be escaped.
|
||||
* Optionally merge the defaults from config.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param bool $merge
|
||||
* @param array $columns
|
||||
* @param bool $merge
|
||||
* @return $this
|
||||
*/
|
||||
public function rawColumns(array $columns, $merge = false)
|
||||
@@ -300,7 +331,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
* Sets DT_RowClass template.
|
||||
* result: <tr class="output_from_your_template">.
|
||||
*
|
||||
* @param string|callable $content
|
||||
* @param string|callable $content
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowClass($content)
|
||||
@@ -314,7 +345,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
* Sets DT_RowId template.
|
||||
* result: <tr id="output_from_your_template">.
|
||||
*
|
||||
* @param string|callable $content
|
||||
* @param string|callable $content
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowId($content)
|
||||
@@ -327,7 +358,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Set DT_RowData templates.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowData(array $data)
|
||||
@@ -340,8 +371,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Add DT_RowData template.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string|callable $value
|
||||
* @param string $key
|
||||
* @param string|callable $value
|
||||
* @return $this
|
||||
*/
|
||||
public function addRowData($key, $value)
|
||||
@@ -355,7 +386,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
* Set DT_RowAttr templates.
|
||||
* result: <tr attr1="attr1" attr2="attr2">.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowAttr(array $data)
|
||||
@@ -368,8 +399,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Add DT_RowAttr template.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string|callable $value
|
||||
* @param string $key
|
||||
* @param string|callable $value
|
||||
* @return $this
|
||||
*/
|
||||
public function addRowAttr($key, $value)
|
||||
@@ -382,8 +413,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Append data on json response.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function with($key, $value = '')
|
||||
@@ -402,8 +433,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Add with query callback value on response.
|
||||
*
|
||||
* @param string $key
|
||||
* @param callable $value
|
||||
* @param string $key
|
||||
* @param callable $value
|
||||
* @return $this
|
||||
*/
|
||||
public function withQuery($key, callable $value)
|
||||
@@ -416,7 +447,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Override default ordering method with a closure callback.
|
||||
*
|
||||
* @param callable $closure
|
||||
* @param callable $closure
|
||||
* @return $this
|
||||
*/
|
||||
public function order(callable $closure)
|
||||
@@ -429,7 +460,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Update list of columns that is not allowed for search/sort.
|
||||
*
|
||||
* @param array $blacklist
|
||||
* @param array $blacklist
|
||||
* @return $this
|
||||
*/
|
||||
public function blacklist(array $blacklist)
|
||||
@@ -442,7 +473,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Update list of columns that is allowed for search/sort.
|
||||
*
|
||||
* @param string|array $whitelist
|
||||
* @param string|array $whitelist
|
||||
* @return $this
|
||||
*/
|
||||
public function whitelist($whitelist = '*')
|
||||
@@ -455,7 +486,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Set smart search config at runtime.
|
||||
*
|
||||
* @param bool $state
|
||||
* @param bool $state
|
||||
* @return $this
|
||||
*/
|
||||
public function smart($state = true)
|
||||
@@ -468,7 +499,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Set starts_with search config at runtime.
|
||||
*
|
||||
* @param bool $state
|
||||
* @param bool $state
|
||||
* @return $this
|
||||
*/
|
||||
public function startsWithSearch($state = true)
|
||||
@@ -478,10 +509,23 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set multi_term search config at runtime.
|
||||
*
|
||||
* @param bool $multiTerm
|
||||
* @return $this
|
||||
*/
|
||||
public function setMultiTerm($multiTerm = true)
|
||||
{
|
||||
$this->config->set('datatables.search.multi_term', $multiTerm);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set total records manually.
|
||||
*
|
||||
* @param int $total
|
||||
* @param int $total
|
||||
* @return $this
|
||||
*/
|
||||
public function setTotalRecords($total)
|
||||
@@ -494,7 +538,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Set filtered records manually.
|
||||
*
|
||||
* @param int $total
|
||||
* @param int $total
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilteredRecords($total)
|
||||
@@ -519,7 +563,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Push a new column name to blacklist.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return $this
|
||||
*/
|
||||
public function pushToBlacklist($column)
|
||||
@@ -534,7 +578,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Check if column is blacklisted.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return bool
|
||||
*/
|
||||
protected function isBlacklisted($column)
|
||||
@@ -593,8 +637,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
* Set auto filter off and run your own filter.
|
||||
* Overrides global search.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param bool $globalSearch
|
||||
* @param callable $callback
|
||||
* @param bool $globalSearch
|
||||
* @return $this
|
||||
*/
|
||||
public function filter(callable $callback, $globalSearch = false)
|
||||
@@ -619,7 +663,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Convert the object to its JSON representation.
|
||||
*
|
||||
* @param int $options
|
||||
* @param int $options
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function toJson($options = 0)
|
||||
@@ -657,9 +701,18 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
}
|
||||
|
||||
$this->columnSearch();
|
||||
$this->searchPanesSearch();
|
||||
$this->filteredRecords = $this->isFilterApplied ? $this->filteredCount() : $this->totalRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform search using search pane values.
|
||||
*/
|
||||
protected function searchPanesSearch()
|
||||
{
|
||||
// Add support for search pane.
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform global search.
|
||||
*
|
||||
@@ -682,7 +735,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
* Perform multi-term search by splitting keyword into
|
||||
* individual words and searches for each of them.
|
||||
*
|
||||
* @param string $keyword
|
||||
* @param string $keyword
|
||||
*/
|
||||
protected function smartGlobalSearch($keyword)
|
||||
{
|
||||
@@ -698,7 +751,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Perform global search for the given keyword.
|
||||
*
|
||||
* @param string $keyword
|
||||
* @param string $keyword
|
||||
*/
|
||||
abstract protected function globalSearch($keyword);
|
||||
|
||||
@@ -717,8 +770,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Transform output.
|
||||
*
|
||||
* @param mixed $results
|
||||
* @param mixed $processed
|
||||
* @param mixed $results
|
||||
* @param mixed $processed
|
||||
* @return array
|
||||
*/
|
||||
protected function transform($results, $processed)
|
||||
@@ -737,8 +790,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Get processed data.
|
||||
*
|
||||
* @param mixed $results
|
||||
* @param bool $object
|
||||
* @param mixed $results
|
||||
* @param bool $object
|
||||
* @return array
|
||||
*/
|
||||
protected function processResults($results, $object = false)
|
||||
@@ -756,7 +809,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Render json response.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
protected function render(array $data)
|
||||
@@ -772,6 +825,10 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
$output = $this->showDebugger($output);
|
||||
}
|
||||
|
||||
foreach ($this->searchPanes as $column => $searchPane) {
|
||||
$output['searchPanes']['options'][$column] = $searchPane['options'];
|
||||
}
|
||||
|
||||
return new JsonResponse(
|
||||
$output,
|
||||
200,
|
||||
@@ -783,7 +840,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Attach custom with meta on response.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function attachAppends(array $data)
|
||||
@@ -794,7 +851,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Append debug parameters on output.
|
||||
*
|
||||
* @param array $output
|
||||
* @param array $output
|
||||
* @return array
|
||||
*/
|
||||
protected function showDebugger(array $output)
|
||||
@@ -807,8 +864,9 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Return an error json response.
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @param \Exception $exception
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Yajra\DataTables\Exceptions\Exception
|
||||
*/
|
||||
protected function errorResponse(\Exception $exception)
|
||||
@@ -817,7 +875,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
$debug = $this->config->get('app.debug');
|
||||
|
||||
if ($error === 'throw' || (! $error && ! $debug)) {
|
||||
throw new Exception($exception->getMessage(), $code = 0, $exception);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$this->getLogger()->error($exception);
|
||||
@@ -846,7 +904,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Set monolog/logger instance.
|
||||
*
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* @return $this
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger)
|
||||
@@ -859,7 +917,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Setup search keyword.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function setupKeyword($value)
|
||||
@@ -881,13 +939,14 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Get column name to be use for filtering and sorting.
|
||||
*
|
||||
* @param int $index
|
||||
* @param bool $wantsAlias
|
||||
* @param int $index
|
||||
* @param string|null $type
|
||||
* @param bool $wantsAlias
|
||||
* @return string
|
||||
*/
|
||||
protected function getColumnName($index, $wantsAlias = false)
|
||||
protected function getColumnName($index, $type = null, $wantsAlias = false)
|
||||
{
|
||||
$column = $this->request->columnName($index);
|
||||
$column = $this->request->columnName($index, $type);
|
||||
|
||||
// DataTables is using make(false)
|
||||
if (is_numeric($column)) {
|
||||
@@ -904,7 +963,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
/**
|
||||
* Get column name by order column index.
|
||||
*
|
||||
* @param int $index
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
protected function getColumnNameByIndex($index)
|
||||
@@ -924,4 +983,26 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a search pane options on response.
|
||||
*
|
||||
* @param string $column
|
||||
* @param mixed $options
|
||||
* @param callable|null $builder
|
||||
* @return $this
|
||||
*/
|
||||
public function searchPane($column, $options, callable $builder = null)
|
||||
{
|
||||
$options = value($options);
|
||||
|
||||
if ($options instanceof Arrayable) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
|
||||
$this->searchPanes[$column]['options'] = $options;
|
||||
$this->searchPanes[$column]['builder'] = $builder;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -26,8 +26,9 @@ class DataTables
|
||||
* Make a DataTable instance from source.
|
||||
* Alias of make for backward compatibility.
|
||||
*
|
||||
* @param mixed $source
|
||||
* @param mixed $source
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function of($source)
|
||||
@@ -38,8 +39,9 @@ class DataTables
|
||||
/**
|
||||
* Make a DataTable instance from source.
|
||||
*
|
||||
* @param mixed $source
|
||||
* @param mixed $source
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function make($source)
|
||||
@@ -85,6 +87,7 @@ class DataTables
|
||||
|
||||
/**
|
||||
* @deprecated Please use query() instead, this method will be removed in a next version.
|
||||
*
|
||||
* @param $builder
|
||||
* @return QueryDataTable
|
||||
*/
|
||||
@@ -96,8 +99,8 @@ class DataTables
|
||||
/**
|
||||
* DataTables using Query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder|mixed $builder
|
||||
* @return DataTableAbstract|QueryDataTable
|
||||
* @param \Illuminate\Database\Query\Builder|mixed $builder
|
||||
* @return QueryDataTable|DataTableAbstract
|
||||
*/
|
||||
public function query($builder)
|
||||
{
|
||||
@@ -107,8 +110,8 @@ class DataTables
|
||||
/**
|
||||
* DataTables using Eloquent Builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder|mixed $builder
|
||||
* @return DataTableAbstract|EloquentDataTable
|
||||
* @param \Illuminate\Database\Eloquent\Builder|mixed $builder
|
||||
* @return EloquentDataTable|DataTableAbstract
|
||||
*/
|
||||
public function eloquent($builder)
|
||||
{
|
||||
@@ -118,8 +121,8 @@ class DataTables
|
||||
/**
|
||||
* DataTables using Collection.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection|array $collection
|
||||
* @return DataTableAbstract|CollectionDataTable
|
||||
* @param \Illuminate\Support\Collection|array $collection
|
||||
* @return CollectionDataTable|DataTableAbstract
|
||||
*/
|
||||
public function collection($collection)
|
||||
{
|
||||
@@ -129,8 +132,8 @@ class DataTables
|
||||
/**
|
||||
* DataTables using Collection.
|
||||
*
|
||||
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection|array $collection
|
||||
* @return DataTableAbstract|ApiResourceDataTable
|
||||
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection|array $collection
|
||||
* @return ApiResourceDataTable|DataTableAbstract
|
||||
*/
|
||||
public function resource($resource)
|
||||
{
|
||||
@@ -141,6 +144,7 @@ class DataTables
|
||||
* Get html builder instance.
|
||||
*
|
||||
* @return \Yajra\DataTables\Html\Builder
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getHtmlBuilder()
|
||||
|
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Yajra\DataTables\Exceptions\Exception;
|
||||
|
||||
@@ -20,7 +21,7 @@ class EloquentDataTable extends QueryDataTable
|
||||
/**
|
||||
* Can the DataTable engine be created with these parameters.
|
||||
*
|
||||
* @param mixed $source
|
||||
* @param mixed $source
|
||||
* @return bool
|
||||
*/
|
||||
public static function canCreate($source)
|
||||
@@ -31,7 +32,7 @@ class EloquentDataTable extends QueryDataTable
|
||||
/**
|
||||
* EloquentEngine constructor.
|
||||
*
|
||||
* @param mixed $model
|
||||
* @param mixed $model
|
||||
*/
|
||||
public function __construct($model)
|
||||
{
|
||||
@@ -76,10 +77,10 @@ class EloquentDataTable extends QueryDataTable
|
||||
/**
|
||||
* Compile query builder where clause depending on configurations.
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param string $columnName
|
||||
* @param string $keyword
|
||||
* @param string $boolean
|
||||
* @param mixed $query
|
||||
* @param string $columnName
|
||||
* @param string $keyword
|
||||
* @param string $boolean
|
||||
*/
|
||||
protected function compileQuerySearch($query, $columnName, $keyword, $boolean = 'or')
|
||||
{
|
||||
@@ -91,15 +92,21 @@ class EloquentDataTable extends QueryDataTable
|
||||
return parent::compileQuerySearch($query, $columnName, $keyword, $boolean);
|
||||
}
|
||||
|
||||
$query->{$boolean . 'WhereHas'}($relation, function (Builder $query) use ($column, $keyword) {
|
||||
parent::compileQuerySearch($query, $column, $keyword, '');
|
||||
});
|
||||
if ($this->isMorphRelation($relation)) {
|
||||
$query->{$boolean . 'WhereHasMorph'}($relation, '*', function (Builder $query) use ($column, $keyword) {
|
||||
parent::compileQuerySearch($query, $column, $keyword, '');
|
||||
});
|
||||
} else {
|
||||
$query->{$boolean . 'WhereHas'}($relation, function (Builder $query) use ($column, $keyword) {
|
||||
parent::compileQuerySearch($query, $column, $keyword, '');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the proper column name be used.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return string
|
||||
*/
|
||||
protected function resolveRelationColumn($column)
|
||||
@@ -115,10 +122,29 @@ class EloquentDataTable extends QueryDataTable
|
||||
return $this->joinEagerLoadedColumn($relation, $columnName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a relation is a morphed one or not.
|
||||
*
|
||||
* @param string $relation
|
||||
* @return bool
|
||||
*/
|
||||
protected function isMorphRelation($relation)
|
||||
{
|
||||
$isMorph = false;
|
||||
if ($relation !== null && $relation !== '') {
|
||||
$relationParts = explode('.', $relation);
|
||||
$firstRelation = array_shift($relationParts);
|
||||
$model = $this->query->getModel();
|
||||
$isMorph = method_exists($model, $firstRelation) && $model->$firstRelation() instanceof MorphTo;
|
||||
}
|
||||
|
||||
return $isMorph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a relation was not used on eager loading.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return bool
|
||||
*/
|
||||
protected function isNotEagerLoaded($relation)
|
||||
@@ -131,9 +157,10 @@ class EloquentDataTable extends QueryDataTable
|
||||
/**
|
||||
* Join eager loaded relation and get the related column name.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $relationColumn
|
||||
* @param string $relation
|
||||
* @param string $relationColumn
|
||||
* @return string
|
||||
*
|
||||
* @throws \Yajra\DataTables\Exceptions\Exception
|
||||
*/
|
||||
protected function joinEagerLoadedColumn($relation, $relationColumn)
|
||||
@@ -162,16 +189,18 @@ class EloquentDataTable extends QueryDataTable
|
||||
|
||||
case $model instanceof HasOneThrough:
|
||||
$pivot = explode('.', $model->getQualifiedParentKeyName())[0]; // extract pivot table from key
|
||||
$pivotPK = $pivot . '.' . $model->getLocalKeyName();
|
||||
$pivotPK = $pivot . '.' . $model->getFirstKeyName();
|
||||
$pivotFK = $model->getQualifiedLocalKeyName();
|
||||
$this->performJoin($pivot, $pivotPK, $pivotFK);
|
||||
|
||||
$related = $model->getRelated();
|
||||
$table = $related->getTable();
|
||||
$tablePK = $related->getForeignKey();
|
||||
$tablePK = $model->getSecondLocalKeyName();
|
||||
$foreign = $pivot . '.' . $tablePK;
|
||||
$other = $related->getQualifiedKeyName();
|
||||
|
||||
$lastQuery->addSelect($lastQuery->getModel()->getTable().'.*');
|
||||
|
||||
break;
|
||||
|
||||
case $model instanceof HasOneOrMany:
|
||||
@@ -199,10 +228,10 @@ class EloquentDataTable extends QueryDataTable
|
||||
/**
|
||||
* Perform join query.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $foreign
|
||||
* @param string $other
|
||||
* @param string $type
|
||||
* @param string $table
|
||||
* @param string $foreign
|
||||
* @param string $other
|
||||
* @param string $type
|
||||
*/
|
||||
protected function performJoin($table, $foreign, $other, $type = 'left')
|
||||
{
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @mixin \Yajra\DataTables\DataTables
|
||||
*
|
||||
* @method static \Yajra\DataTables\EloquentDatatable eloquent($builder)
|
||||
* @method static \Yajra\DataTables\QueryDataTable query($builder)
|
||||
* @method static \Yajra\DataTables\CollectionDataTable collection($collection)
|
||||
|
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace Yajra\DataTables\Processors;
|
||||
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Yajra\DataTables\Contracts\Formatter;
|
||||
use Yajra\DataTables\Utilities\Helper;
|
||||
|
||||
class DataProcessor
|
||||
@@ -67,10 +69,10 @@ class DataProcessor
|
||||
protected $exceptions = ['DT_RowId', 'DT_RowClass', 'DT_RowData', 'DT_RowAttr'];
|
||||
|
||||
/**
|
||||
* @param mixed $results
|
||||
* @param array $columnDef
|
||||
* @param array $templates
|
||||
* @param int $start
|
||||
* @param mixed $results
|
||||
* @param array $columnDef
|
||||
* @param array $templates
|
||||
* @param int $start
|
||||
*/
|
||||
public function __construct($results, array $columnDef, array $templates, $start)
|
||||
{
|
||||
@@ -91,7 +93,7 @@ class DataProcessor
|
||||
/**
|
||||
* Process data to output on browser.
|
||||
*
|
||||
* @param bool $object
|
||||
* @param bool $object
|
||||
* @return array
|
||||
*/
|
||||
public function process($object = false)
|
||||
@@ -120,15 +122,22 @@ class DataProcessor
|
||||
/**
|
||||
* Process add columns.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param mixed $row
|
||||
* @param mixed $data
|
||||
* @param mixed $row
|
||||
* @return array
|
||||
*/
|
||||
protected function addColumns($data, $row)
|
||||
{
|
||||
foreach ($this->appendColumns as $key => $value) {
|
||||
$value['content'] = Helper::compileContent($value['content'], $data, $row);
|
||||
$data = Helper::includeInArray($value, $data);
|
||||
foreach ($this->appendColumns as $value) {
|
||||
if ($value['content'] instanceof Formatter) {
|
||||
$column = str_replace('_formatted', '', $value['name']);
|
||||
|
||||
$value['content'] = $value['content']->format($data[$column], $row);
|
||||
} else {
|
||||
$value['content'] = Helper::compileContent($value['content'], $data, $row);
|
||||
}
|
||||
|
||||
$data = Helper::includeInArray($value, $data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -137,8 +146,8 @@ class DataProcessor
|
||||
/**
|
||||
* Process edit columns.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param mixed $row
|
||||
* @param mixed $data
|
||||
* @param mixed $row
|
||||
* @return array
|
||||
*/
|
||||
protected function editColumns($data, $row)
|
||||
@@ -154,8 +163,8 @@ class DataProcessor
|
||||
/**
|
||||
* Setup additional DT row variables.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param mixed $row
|
||||
* @param mixed $data
|
||||
* @param mixed $row
|
||||
* @return array
|
||||
*/
|
||||
protected function setupRowVariables($data, $row)
|
||||
@@ -173,32 +182,31 @@ class DataProcessor
|
||||
/**
|
||||
* Get only needed columns.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function selectOnlyNeededColumns(array $data)
|
||||
{
|
||||
if (is_null($this->onlyColumns)) {
|
||||
return $data;
|
||||
} else {
|
||||
$results = [];
|
||||
foreach ($this->onlyColumns as $onlyColumn) {
|
||||
Arr::set($results, $onlyColumn, Arr::get($data, $onlyColumn));
|
||||
}
|
||||
foreach ($this->exceptions as $exception) {
|
||||
if ($column = Arr::get($data, $exception)) {
|
||||
Arr::set($results, $exception, $column);
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
$results = [];
|
||||
foreach ($this->onlyColumns as $onlyColumn) {
|
||||
Arr::set($results, $onlyColumn, Arr::get($data, $onlyColumn));
|
||||
}
|
||||
foreach ($this->exceptions as $exception) {
|
||||
if ($column = Arr::get($data, $exception)) {
|
||||
Arr::set($results, $exception, $column);
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove declared hidden columns.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function removeExcessColumns(array $data)
|
||||
@@ -213,7 +221,7 @@ class DataProcessor
|
||||
/**
|
||||
* Flatten array with exceptions.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
public function flatten(array $array)
|
||||
@@ -233,7 +241,7 @@ class DataProcessor
|
||||
/**
|
||||
* Escape column values as declared.
|
||||
*
|
||||
* @param array $output
|
||||
* @param array $output
|
||||
* @return array
|
||||
*/
|
||||
protected function escapeColumns(array $output)
|
||||
@@ -253,9 +261,9 @@ class DataProcessor
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape all values of row.
|
||||
* Escape all string or Htmlable values of row.
|
||||
*
|
||||
* @param array $row
|
||||
* @param array $row
|
||||
* @return array
|
||||
*/
|
||||
protected function escapeRow(array $row)
|
||||
@@ -263,7 +271,7 @@ class DataProcessor
|
||||
$arrayDot = array_filter(Arr::dot($row));
|
||||
foreach ($arrayDot as $key => $value) {
|
||||
if (! in_array($key, $this->rawColumns)) {
|
||||
$arrayDot[$key] = e($value);
|
||||
$arrayDot[$key] = (is_string($value) || $value instanceof Htmlable) ? e($value) : $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,8 +18,8 @@ class RowProcessor
|
||||
private $row;
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @param mixed $row
|
||||
* @param mixed $data
|
||||
* @param mixed $row
|
||||
*/
|
||||
public function __construct($data, $row)
|
||||
{
|
||||
@@ -30,8 +30,8 @@ class RowProcessor
|
||||
/**
|
||||
* Process DT RowId and Class value.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string|callable $template
|
||||
* @param string $attribute
|
||||
* @param string|callable $template
|
||||
* @return $this
|
||||
*/
|
||||
public function rowValue($attribute, $template)
|
||||
@@ -50,8 +50,8 @@ class RowProcessor
|
||||
/**
|
||||
* Process DT Row Data and Attr.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param array $template
|
||||
* @param string $attribute
|
||||
* @param array $template
|
||||
* @return $this
|
||||
*/
|
||||
public function rowData($attribute, array $template)
|
||||
|
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace Yajra\DataTables;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Yajra\DataTables\Utilities\Helper;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Support\Str;
|
||||
use Yajra\DataTables\Utilities\Helper;
|
||||
|
||||
class QueryDataTable extends DataTableAbstract
|
||||
{
|
||||
@@ -62,7 +62,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Can the DataTable engine be created with these parameters.
|
||||
*
|
||||
* @param mixed $source
|
||||
* @param mixed $source
|
||||
* @return bool
|
||||
*/
|
||||
public static function canCreate($source)
|
||||
@@ -71,7 +71,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Query\Builder $builder
|
||||
* @param \Illuminate\Database\Query\Builder $builder
|
||||
*/
|
||||
public function __construct(Builder $builder)
|
||||
{
|
||||
@@ -88,8 +88,9 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Organizes works.
|
||||
*
|
||||
* @param bool $mDataSupport
|
||||
* @param bool $mDataSupport
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function make($mDataSupport = true)
|
||||
@@ -107,6 +108,28 @@ class QueryDataTable extends DataTableAbstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform search using search pane values.
|
||||
*/
|
||||
protected function searchPanesSearch()
|
||||
{
|
||||
$columns = $this->request->get('searchPanes', []);
|
||||
|
||||
foreach ($columns as $column => $values) {
|
||||
if ($this->isBlacklisted($column)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->searchPanes[$column] && $callback = $this->searchPanes[$column]['builder']) {
|
||||
$callback($this->query, $values);
|
||||
} else {
|
||||
$this->query->whereIn($column, $values);
|
||||
}
|
||||
|
||||
$this->isFilterApplied = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare query by executing count, filter, order and paginate.
|
||||
*/
|
||||
@@ -117,9 +140,10 @@ class QueryDataTable extends DataTableAbstract
|
||||
|
||||
if ($this->totalRecords) {
|
||||
$this->filterRecords();
|
||||
$this->ordering();
|
||||
$this->paginate();
|
||||
}
|
||||
|
||||
$this->ordering();
|
||||
$this->paginate();
|
||||
}
|
||||
|
||||
$this->prepared = true;
|
||||
@@ -188,12 +212,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
$builder = $this->prepareCountQuery();
|
||||
$table = $this->connection->raw('(' . $builder->toSql() . ') count_row_table');
|
||||
|
||||
return $this->connection->table($table)
|
||||
->setBindings($builder->getBindings())
|
||||
->count();
|
||||
return $this->prepareCountQuery()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,16 +220,21 @@ class QueryDataTable extends DataTableAbstract
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected function prepareCountQuery()
|
||||
public function prepareCountQuery()
|
||||
{
|
||||
$builder = clone $this->query;
|
||||
|
||||
if (! $this->isComplexQuery($builder)) {
|
||||
$row_count = $this->wrap('row_count');
|
||||
$builder->select($this->connection->raw("'1' as {$row_count}"));
|
||||
if (! $this->keepSelectBindings) {
|
||||
$builder->setBindings([], 'select');
|
||||
}
|
||||
if ($this->isComplexQuery($builder)) {
|
||||
$table = $this->connection->raw('('.$builder->toSql().') count_row_table');
|
||||
|
||||
return $this->connection->table($table)
|
||||
->setBindings($builder->getBindings());
|
||||
}
|
||||
|
||||
$row_count = $this->wrap('row_count');
|
||||
$builder->select($this->connection->raw("'1' as {$row_count}"));
|
||||
if (! $this->keepSelectBindings) {
|
||||
$builder->setBindings([], 'select');
|
||||
}
|
||||
|
||||
return $builder;
|
||||
@@ -219,7 +243,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Check if builder query uses complex sql.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $builder
|
||||
* @param \Illuminate\Database\Query\Builder $builder
|
||||
* @return bool
|
||||
*/
|
||||
protected function isComplexQuery($builder)
|
||||
@@ -230,7 +254,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Wrap column with DB grammar.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return string
|
||||
*/
|
||||
protected function wrap($column)
|
||||
@@ -287,7 +311,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
}
|
||||
|
||||
if ($this->hasFilterColumn($column)) {
|
||||
$keyword = $this->getColumnSearchKeyword($index, $raw = true);
|
||||
$keyword = $this->getColumnSearchKeyword($index, true);
|
||||
$this->applyFilterColumn($this->getBaseQueryBuilder(), $column, $keyword);
|
||||
} else {
|
||||
$column = $this->resolveRelationColumn($column);
|
||||
@@ -302,7 +326,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Check if column has custom filter handler.
|
||||
*
|
||||
* @param string $columnName
|
||||
* @param string $columnName
|
||||
* @return bool
|
||||
*/
|
||||
public function hasFilterColumn($columnName)
|
||||
@@ -313,8 +337,8 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Get column keyword to use for search.
|
||||
*
|
||||
* @param int $i
|
||||
* @param bool $raw
|
||||
* @param int $i
|
||||
* @param bool $raw
|
||||
* @return string
|
||||
*/
|
||||
protected function getColumnSearchKeyword($i, $raw = false)
|
||||
@@ -330,10 +354,10 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Apply filterColumn api search.
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param string $columnName
|
||||
* @param string $keyword
|
||||
* @param string $boolean
|
||||
* @param mixed $query
|
||||
* @param string $columnName
|
||||
* @param string $keyword
|
||||
* @param string $boolean
|
||||
*/
|
||||
protected function applyFilterColumn($query, $columnName, $keyword, $boolean = 'and')
|
||||
{
|
||||
@@ -354,7 +378,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Get the base query builder instance.
|
||||
*
|
||||
* @param mixed $instance
|
||||
* @param mixed $instance
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected function getBaseQueryBuilder($instance = null)
|
||||
@@ -373,7 +397,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Resolve the proper column name be used.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return string
|
||||
*/
|
||||
protected function resolveRelationColumn($column)
|
||||
@@ -384,14 +408,13 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Compile queries for column search.
|
||||
*
|
||||
* @param int $i
|
||||
* @param string $column
|
||||
* @param string $keyword
|
||||
* @param int $i
|
||||
* @param string $column
|
||||
* @param string $keyword
|
||||
*/
|
||||
protected function compileColumnSearch($i, $column, $keyword)
|
||||
{
|
||||
if ($this->request->isRegex($i)) {
|
||||
$column = strstr($column, '(') ? $this->connection->raw($column) : $column;
|
||||
$this->regexColumnSearch($column, $keyword);
|
||||
} else {
|
||||
$this->compileQuerySearch($this->query, $column, $keyword, '');
|
||||
@@ -401,11 +424,13 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Compile regex query column search.
|
||||
*
|
||||
* @param mixed $column
|
||||
* @param string $keyword
|
||||
* @param mixed $column
|
||||
* @param string $keyword
|
||||
*/
|
||||
protected function regexColumnSearch($column, $keyword)
|
||||
{
|
||||
$column = $this->wrap($column);
|
||||
|
||||
switch ($this->connection->getDriverName()) {
|
||||
case 'oracle':
|
||||
$sql = ! $this->config->isCaseInsensitive()
|
||||
@@ -431,7 +456,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Wrap a column and cast based on database driver.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return string
|
||||
*/
|
||||
protected function castColumn($column)
|
||||
@@ -449,10 +474,10 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Compile query builder where clause depending on configurations.
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param string $column
|
||||
* @param string $keyword
|
||||
* @param string $boolean
|
||||
* @param mixed $query
|
||||
* @param string $column
|
||||
* @param string $keyword
|
||||
* @param string $boolean
|
||||
*/
|
||||
protected function compileQuerySearch($query, $column, $keyword, $boolean = 'or')
|
||||
{
|
||||
@@ -471,8 +496,8 @@ class QueryDataTable extends DataTableAbstract
|
||||
* Patch for fix about ambiguous field.
|
||||
* Ambiguous field error will appear when query use join table and search with keyword.
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param string $column
|
||||
* @param mixed $query
|
||||
* @param string $column
|
||||
* @return string
|
||||
*/
|
||||
protected function addTablePrefix($query, $column)
|
||||
@@ -490,7 +515,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Prepare search keyword based on configurations.
|
||||
*
|
||||
* @param string $keyword
|
||||
* @param string $keyword
|
||||
* @return string
|
||||
*/
|
||||
protected function prepareKeyword($keyword)
|
||||
@@ -517,8 +542,8 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Add custom filter handler for the give column.
|
||||
*
|
||||
* @param string $column
|
||||
* @param callable $callback
|
||||
* @param string $column
|
||||
* @param callable $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function filterColumn($column, callable $callback)
|
||||
@@ -531,9 +556,9 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Order each given columns versus the given custom sql.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param string $sql
|
||||
* @param array $bindings
|
||||
* @param array $columns
|
||||
* @param string $sql
|
||||
* @param array $bindings
|
||||
* @return $this
|
||||
*/
|
||||
public function orderColumns(array $columns, $sql, $bindings = [])
|
||||
@@ -548,10 +573,11 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Override default column ordering.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $sql
|
||||
* @param array $bindings
|
||||
* @param string $column
|
||||
* @param string|\Closure $sql
|
||||
* @param array $bindings
|
||||
* @return $this
|
||||
*
|
||||
* @internal string $1 Special variable that returns the requested order direction of the column.
|
||||
*/
|
||||
public function orderColumn($column, $sql, $bindings = [])
|
||||
@@ -577,7 +603,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
* Paginate dataTable using limit without offset
|
||||
* with additional where clause via callback.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param callable $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function limit(callable $callback)
|
||||
@@ -606,9 +632,9 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Add column in collection.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|callable $content
|
||||
* @param bool|int $order
|
||||
* @param string $name
|
||||
* @param string|callable $content
|
||||
* @param bool|int $order
|
||||
* @return $this
|
||||
*/
|
||||
public function addColumn($name, $content, $order = false)
|
||||
@@ -635,7 +661,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
{
|
||||
collect($this->request->orderableColumns())
|
||||
->map(function ($orderable) {
|
||||
$orderable['name'] = $this->getColumnName($orderable['column'], true);
|
||||
$orderable['name'] = $this->getColumnName($orderable['column'], null, true);
|
||||
|
||||
return $orderable;
|
||||
})
|
||||
@@ -649,8 +675,8 @@ class QueryDataTable extends DataTableAbstract
|
||||
$this->applyOrderColumn($column, $orderable);
|
||||
} else {
|
||||
$nullsLastSql = $this->getNullsLastSql($column, $orderable['direction']);
|
||||
$normalSql = $this->wrap($column) . ' ' . $orderable['direction'];
|
||||
$sql = $this->nullsLast ? $nullsLastSql : $normalSql;
|
||||
$normalSql = $this->wrap($column) . ' ' . $orderable['direction'];
|
||||
$sql = $this->nullsLast ? $nullsLastSql : $normalSql;
|
||||
$this->query->orderByRaw($sql);
|
||||
}
|
||||
});
|
||||
@@ -659,7 +685,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Check if column has custom sort handler.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasOrderColumn($column)
|
||||
@@ -670,12 +696,16 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Apply orderColumn custom query.
|
||||
*
|
||||
* @param string $column
|
||||
* @param array $orderable
|
||||
* @param string $column
|
||||
* @param array $orderable
|
||||
*/
|
||||
protected function applyOrderColumn($column, $orderable)
|
||||
{
|
||||
$sql = $this->columnDef['order'][$column]['sql'];
|
||||
if ($sql === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_callable($sql)) {
|
||||
call_user_func($sql, $this->query, $orderable['direction']);
|
||||
} else {
|
||||
@@ -688,8 +718,8 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Get NULLS LAST SQL.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $direction
|
||||
* @param string $column
|
||||
* @param string $direction
|
||||
* @return string
|
||||
*/
|
||||
protected function getNullsLastSql($column, $direction)
|
||||
@@ -706,7 +736,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Perform global search for the given keyword.
|
||||
*
|
||||
* @param string $keyword
|
||||
* @param string $keyword
|
||||
*/
|
||||
protected function globalSearch($keyword)
|
||||
{
|
||||
@@ -733,14 +763,16 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Append debug parameters on output.
|
||||
*
|
||||
* @param array $output
|
||||
* @param array $output
|
||||
* @return array
|
||||
*/
|
||||
protected function showDebugger(array $output)
|
||||
{
|
||||
$query_log = $this->connection->getQueryLog();
|
||||
array_walk_recursive($query_log, function (&$item, $key) {
|
||||
$item = utf8_encode($item);
|
||||
array_walk_recursive($query_log, function (&$item) {
|
||||
if (is_string($item)) {
|
||||
$item = utf8_encode($item);
|
||||
}
|
||||
});
|
||||
|
||||
$output['queries'] = $query_log;
|
||||
@@ -752,7 +784,7 @@ class QueryDataTable extends DataTableAbstract
|
||||
/**
|
||||
* Attach custom with meta on response.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function attachAppends(array $data)
|
||||
|
@@ -14,7 +14,7 @@ class Config
|
||||
/**
|
||||
* Config constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $repository
|
||||
* @param \Illuminate\Contracts\Config\Repository $repository
|
||||
*/
|
||||
public function __construct(Repository $repository)
|
||||
{
|
||||
@@ -64,8 +64,8 @@ class Config
|
||||
/**
|
||||
* Get the specified configuration value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
@@ -76,8 +76,8 @@ class Config
|
||||
/**
|
||||
* Set a given configuration value.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param mixed $value
|
||||
* @param array|string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function set($key, $value = null)
|
||||
|
@@ -3,17 +3,17 @@
|
||||
namespace Yajra\DataTables\Utilities;
|
||||
|
||||
use DateTime;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
class Helper
|
||||
{
|
||||
/**
|
||||
* Places item of extra columns into results by care of their order.
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $array
|
||||
* @param array $item
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
public static function includeInArray($item, $array)
|
||||
@@ -40,8 +40,8 @@ class Helper
|
||||
/**
|
||||
* Check if item order is valid.
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $array
|
||||
* @param array $item
|
||||
* @param array $array
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isItemOrderInvalid($item, $array)
|
||||
@@ -52,16 +52,25 @@ class Helper
|
||||
/**
|
||||
* Determines if content is callable or blade string, processes and returns.
|
||||
*
|
||||
* @param mixed $content Pre-processed content
|
||||
* @param array $data data to use with blade template
|
||||
* @param mixed $param parameter to call with callable
|
||||
* @param mixed $content Pre-processed content
|
||||
* @param array $data data to use with blade template
|
||||
* @param mixed $param parameter to call with callable
|
||||
* @return mixed
|
||||
*/
|
||||
public static function compileContent($content, array $data, $param)
|
||||
{
|
||||
if (is_string($content)) {
|
||||
return static::compileBlade($content, static::getMixedValue($data, $param));
|
||||
} elseif (is_callable($content)) {
|
||||
}
|
||||
|
||||
if (is_callable($content)) {
|
||||
$reflection = new \ReflectionFunction($content);
|
||||
$arguments = $reflection->getParameters();
|
||||
|
||||
if (count($arguments) > 0) {
|
||||
return app()->call($content, [$arguments[0]->name => $param]);
|
||||
}
|
||||
|
||||
return $content($param);
|
||||
}
|
||||
|
||||
@@ -71,9 +80,10 @@ class Helper
|
||||
/**
|
||||
* Parses and compiles strings by using Blade Template System.
|
||||
*
|
||||
* @param string $str
|
||||
* @param array $data
|
||||
* @param string $str
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function compileBlade($str, $data = [])
|
||||
@@ -93,8 +103,8 @@ class Helper
|
||||
/**
|
||||
* Get a mixed value of custom data and the parameters.
|
||||
*
|
||||
* @param array $data
|
||||
* @param mixed $param
|
||||
* @param array $data
|
||||
* @param mixed $param
|
||||
* @return array
|
||||
*/
|
||||
public static function getMixedValue(array $data, $param)
|
||||
@@ -115,7 +125,7 @@ class Helper
|
||||
/**
|
||||
* Cast the parameter into an array.
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param
|
||||
* @return array
|
||||
*/
|
||||
public static function castToArray($param)
|
||||
@@ -136,7 +146,7 @@ class Helper
|
||||
/**
|
||||
* Get equivalent or method of query builder.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $method
|
||||
* @return string
|
||||
*/
|
||||
public static function getOrMethod($method)
|
||||
@@ -151,14 +161,14 @@ class Helper
|
||||
/**
|
||||
* Converts array object values to associative array.
|
||||
*
|
||||
* @param mixed $row
|
||||
* @param array $filters
|
||||
* @param mixed $row
|
||||
* @param array $filters
|
||||
* @return array
|
||||
*/
|
||||
public static function convertToArray($row, $filters = [])
|
||||
{
|
||||
$row = method_exists($row, 'makeHidden') ? $row->makeHidden(Arr::get($filters, 'hidden', [])) : $row;
|
||||
$row = method_exists($row, 'makeVisible') ? $row->makeVisible(Arr::get($filters, 'visible', [])) : $row;
|
||||
$row = is_object($row) && method_exists($row, 'makeHidden') ? $row->makeHidden(Arr::get($filters, 'hidden', [])) : $row;
|
||||
$row = is_object($row) && method_exists($row, 'makeVisible') ? $row->makeVisible(Arr::get($filters, 'visible', [])) : $row;
|
||||
$data = $row instanceof Arrayable ? $row->toArray() : (array) $row;
|
||||
|
||||
foreach ($data as &$value) {
|
||||
@@ -173,7 +183,7 @@ class Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public static function transform(array $data)
|
||||
@@ -186,7 +196,7 @@ class Helper
|
||||
/**
|
||||
* Transform row data into an array.
|
||||
*
|
||||
* @param mixed $row
|
||||
* @param mixed $row
|
||||
* @return array
|
||||
*/
|
||||
protected static function transformRow($row)
|
||||
@@ -209,7 +219,7 @@ class Helper
|
||||
/**
|
||||
* Build parameters depending on # of arguments passed.
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $args
|
||||
* @return array
|
||||
*/
|
||||
public static function buildParameters(array $args)
|
||||
@@ -233,9 +243,9 @@ class Helper
|
||||
/**
|
||||
* Replace all pattern occurrences with keyword.
|
||||
*
|
||||
* @param array $subject
|
||||
* @param string $keyword
|
||||
* @param string $pattern
|
||||
* @param array $subject
|
||||
* @param string $keyword
|
||||
* @param string $pattern
|
||||
* @return array
|
||||
*/
|
||||
public static function replacePatternWithKeyword(array $subject, $keyword, $pattern = '$1')
|
||||
@@ -255,8 +265,8 @@ class Helper
|
||||
/**
|
||||
* Get column name from string.
|
||||
*
|
||||
* @param string $str
|
||||
* @param bool $wantsAlias
|
||||
* @param string $str
|
||||
* @param bool $wantsAlias
|
||||
* @return string
|
||||
*/
|
||||
public static function extractColumnName($str, $wantsAlias)
|
||||
@@ -281,8 +291,8 @@ class Helper
|
||||
/**
|
||||
* Adds % wildcards to the given string.
|
||||
*
|
||||
* @param string $str
|
||||
* @param bool $lowercase
|
||||
* @param string $str
|
||||
* @param bool $lowercase
|
||||
* @return string
|
||||
*/
|
||||
public static function wildcardLikeString($str, $lowercase = true)
|
||||
@@ -293,9 +303,9 @@ class Helper
|
||||
/**
|
||||
* Adds wildcards to the given string.
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $wildcard
|
||||
* @param bool $lowercase
|
||||
* @param string $str
|
||||
* @param string $wildcard
|
||||
* @param bool $lowercase
|
||||
* @return string
|
||||
*/
|
||||
public static function wildcardString($str, $wildcard, $lowercase = true)
|
||||
|
@@ -3,14 +3,7 @@
|
||||
namespace Yajra\DataTables\Utilities;
|
||||
|
||||
/**
|
||||
* @method mixed input($key, $default = null)
|
||||
* @method mixed get($key, $default = null)
|
||||
* @method mixed query($key, $default = null)
|
||||
* @method mixed has($key)
|
||||
* @method mixed merge(array $values)
|
||||
* @method bool wantsJson()
|
||||
* @method bool ajax()
|
||||
* @method array all()
|
||||
* @mixin \Illuminate\Http\Request
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
@@ -30,8 +23,8 @@ class Request
|
||||
/**
|
||||
* Proxy non existing method calls to request class.
|
||||
*
|
||||
* @param mixed $name
|
||||
* @param mixed $arguments
|
||||
* @param mixed $name
|
||||
* @param mixed $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
@@ -44,7 +37,7 @@ class Request
|
||||
/**
|
||||
* Get attributes from request instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
@@ -75,7 +68,7 @@ class Request
|
||||
/**
|
||||
* Check if DataTables must uses regular expressions.
|
||||
*
|
||||
* @param int $index
|
||||
* @param int $index
|
||||
* @return bool
|
||||
*/
|
||||
public function isRegex($index)
|
||||
@@ -119,7 +112,7 @@ class Request
|
||||
/**
|
||||
* Check if a column is orderable.
|
||||
*
|
||||
* @param int $index
|
||||
* @param int $index
|
||||
* @return bool
|
||||
*/
|
||||
public function isColumnOrderable($index)
|
||||
@@ -147,8 +140,8 @@ class Request
|
||||
/**
|
||||
* Check if a column is searchable.
|
||||
*
|
||||
* @param int $i
|
||||
* @param bool $column_search
|
||||
* @param int $i
|
||||
* @param bool $column_search
|
||||
* @return bool
|
||||
*/
|
||||
public function isColumnSearchable($i, $column_search = true)
|
||||
@@ -172,12 +165,12 @@ class Request
|
||||
/**
|
||||
* Get column's search value.
|
||||
*
|
||||
* @param int $index
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public function columnKeyword($index)
|
||||
{
|
||||
$keyword = $this->request->input("columns.$index.search.value");
|
||||
$keyword = $this->request->input("columns.$index.search.value") ?? '';
|
||||
|
||||
return $this->prepareKeyword($keyword);
|
||||
}
|
||||
@@ -185,7 +178,7 @@ class Request
|
||||
/**
|
||||
* Prepare keyword string value.
|
||||
*
|
||||
* @param string|array $keyword
|
||||
* @param string|array $keyword
|
||||
* @return string
|
||||
*/
|
||||
protected function prepareKeyword($keyword)
|
||||
@@ -204,7 +197,7 @@ class Request
|
||||
*/
|
||||
public function keyword()
|
||||
{
|
||||
$keyword = $this->request->input('search.value');
|
||||
$keyword = $this->request->input('search.value') ?? '';
|
||||
|
||||
return $this->prepareKeyword($keyword);
|
||||
}
|
||||
@@ -212,13 +205,30 @@ class Request
|
||||
/**
|
||||
* Get column identity from input or database.
|
||||
*
|
||||
* @param int $i
|
||||
* @param int $i
|
||||
* @param string|null $type
|
||||
* @return string
|
||||
*/
|
||||
public function columnName($i)
|
||||
public function columnName($i, $type = null)
|
||||
{
|
||||
$column = $this->request->input("columns.$i");
|
||||
|
||||
if (isset($type) && isset($column['data']) && is_array($column['data'])) {
|
||||
if (isset($column['data'][$type]) && $column['data'][$type] != '') {
|
||||
return $column['data'][$type];
|
||||
}
|
||||
|
||||
if (isset($column['data']['display']) && $column['data']['display'] != '') {
|
||||
return $column['data']['display'];
|
||||
}
|
||||
|
||||
if (isset($column['data']['_']) && $column['data']['_'] != '') {
|
||||
return $column['data']['_'];
|
||||
}
|
||||
|
||||
return $column['name'];
|
||||
}
|
||||
|
||||
return isset($column['name']) && $column['name'] != '' ? $column['name'] : $column['data'];
|
||||
}
|
||||
|
||||
|
@@ -100,7 +100,7 @@ return [
|
||||
'raw' => ['action'],
|
||||
|
||||
/*
|
||||
* List of columns are are forbidden from being searched/sorted.
|
||||
* List of columns are forbidden from being searched/sorted.
|
||||
*/
|
||||
'blacklist' => ['password', 'remember_token'],
|
||||
|
||||
|
@@ -5,7 +5,7 @@ if (! function_exists('datatables')) {
|
||||
* Helper to make a new DataTable instance from source.
|
||||
* Or return the factory if source is not set.
|
||||
*
|
||||
* @param mixed $source
|
||||
* @param mixed $source
|
||||
* @return \Yajra\DataTables\DataTableAbstract|\Yajra\DataTables\DataTables
|
||||
*/
|
||||
function datatables($source = null)
|
||||
|
@@ -4,7 +4,7 @@ if (! function_exists('config_path')) {
|
||||
/**
|
||||
* Get the configuration path.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function config_path($path = '')
|
||||
@@ -17,7 +17,7 @@ if (! function_exists('public_path')) {
|
||||
/**
|
||||
* Return the path to public dir.
|
||||
*
|
||||
* @param null $path
|
||||
* @param null $path
|
||||
* @return string
|
||||
*/
|
||||
function public_path($path = null)
|
||||
|
Reference in New Issue
Block a user