@@ -9,32 +9,32 @@ |
||
| 9 | 9 | |
| 10 | 10 | abstract class BaseRenderer |
| 11 | 11 | { |
| 12 | - use Configurable; |
|
| 12 | + use Configurable; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var GridView |
|
| 16 | - */ |
|
| 17 | - public $gridView; |
|
| 14 | + /** |
|
| 15 | + * @var GridView |
|
| 16 | + */ |
|
| 17 | + public $gridView; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * BaseRenderer constructor. |
|
| 21 | - * @param $config |
|
| 22 | - * @throws GridViewConfigException |
|
| 23 | - */ |
|
| 24 | - public function __construct($config) |
|
| 25 | - { |
|
| 26 | - $this->loadConfig($config); |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * BaseRenderer constructor. |
|
| 21 | + * @param $config |
|
| 22 | + * @throws GridViewConfigException |
|
| 23 | + */ |
|
| 24 | + public function __construct($config) |
|
| 25 | + { |
|
| 26 | + $this->loadConfig($config); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - protected function configTests(): array |
|
| 33 | - { |
|
| 34 | - return [ |
|
| 35 | - 'gridView' => GridView::class, |
|
| 36 | - ]; |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + protected function configTests(): array |
|
| 33 | + { |
|
| 34 | + return [ |
|
| 35 | + 'gridView' => GridView::class, |
|
| 36 | + ]; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public abstract function render() : string; |
|
| 39 | + public abstract function render() : string; |
|
| 40 | 40 | } |
| 41 | 41 | \ No newline at end of file |
@@ -7,22 +7,22 @@ |
||
| 7 | 7 | |
| 8 | 8 | class DefaultRenderer extends BaseRenderer |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @return string |
|
| 12 | - * @throws \Throwable |
|
| 13 | - */ |
|
| 14 | - public function render(): string |
|
| 15 | - { |
|
| 16 | - $filters = []; |
|
| 17 | - foreach ($this->gridView->columns as $column) { |
|
| 18 | - if ($column->filter) { |
|
| 19 | - $filters[$column->filter->name] = $this->gridView->getRequest()->getFilterValue($column->filter->name); |
|
| 20 | - } |
|
| 21 | - } |
|
| 10 | + /** |
|
| 11 | + * @return string |
|
| 12 | + * @throws \Throwable |
|
| 13 | + */ |
|
| 14 | + public function render(): string |
|
| 15 | + { |
|
| 16 | + $filters = []; |
|
| 17 | + foreach ($this->gridView->columns as $column) { |
|
| 18 | + if ($column->filter) { |
|
| 19 | + $filters[$column->filter->name] = $this->gridView->getRequest()->getFilterValue($column->filter->name); |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - return view('woo_gridview::renderers.default', [ |
|
| 24 | - 'grid' => $this->gridView, |
|
| 25 | - 'filters' => $filters, |
|
| 26 | - ])->render(); |
|
| 27 | - } |
|
| 23 | + return view('woo_gridview::renderers.default', [ |
|
| 24 | + 'grid' => $this->gridView, |
|
| 25 | + 'filters' => $filters, |
|
| 26 | + ])->render(); |
|
| 27 | + } |
|
| 28 | 28 | } |
| 29 | 29 | \ No newline at end of file |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Action constructor. |
| 26 | - * @param string|Closure $url |
|
| 26 | + * @param string $url |
|
| 27 | 27 | * @param string $content |
| 28 | 28 | * @param string $method |
| 29 | 29 | */ |
@@ -6,63 +6,63 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Action |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var string |
|
| 11 | - */ |
|
| 12 | - protected $url; |
|
| 9 | + /** |
|
| 10 | + * @var string |
|
| 11 | + */ |
|
| 12 | + protected $url; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $content; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $content; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $method; |
|
| 19 | + /** |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $method; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Action constructor. |
|
| 26 | - * @param string|Closure $url |
|
| 27 | - * @param string $content |
|
| 28 | - * @param string $method |
|
| 29 | - */ |
|
| 30 | - public function __construct($url, string $content, string $method = 'GET') |
|
| 31 | - { |
|
| 32 | - $this->url = $url; |
|
| 24 | + /** |
|
| 25 | + * Action constructor. |
|
| 26 | + * @param string|Closure $url |
|
| 27 | + * @param string $content |
|
| 28 | + * @param string $method |
|
| 29 | + */ |
|
| 30 | + public function __construct($url, string $content, string $method = 'GET') |
|
| 31 | + { |
|
| 32 | + $this->url = $url; |
|
| 33 | 33 | |
| 34 | - $this->content = $content; |
|
| 34 | + $this->content = $content; |
|
| 35 | 35 | |
| 36 | - $this->method = $method; |
|
| 37 | - } |
|
| 36 | + $this->method = $method; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - protected function buildUrl($row) |
|
| 40 | - { |
|
| 41 | - if ($this->url instanceof Closure) { |
|
| 42 | - return call_user_func($this->url, $row); |
|
| 43 | - } |
|
| 39 | + protected function buildUrl($row) |
|
| 40 | + { |
|
| 41 | + if ($this->url instanceof Closure) { |
|
| 42 | + return call_user_func($this->url, $row); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return preg_replace_callback('/\{([\w\_]+)\}/', function($match) use ($row) { |
|
| 45 | + return preg_replace_callback('/\{([\w\_]+)\}/', function($match) use ($row) { |
|
| 46 | 46 | |
| 47 | - $match = $match[1]; |
|
| 47 | + $match = $match[1]; |
|
| 48 | 48 | |
| 49 | - if (isset($row->$match)) { |
|
| 50 | - return $row->$match; |
|
| 49 | + if (isset($row->$match)) { |
|
| 50 | + return $row->$match; |
|
| 51 | 51 | |
| 52 | - } elseif (isset($row[$match])) { |
|
| 53 | - return $row[$match]; |
|
| 54 | - } |
|
| 52 | + } elseif (isset($row[$match])) { |
|
| 53 | + return $row[$match]; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return ''; |
|
| 57 | - }, $this->url); |
|
| 58 | - } |
|
| 56 | + return ''; |
|
| 57 | + }, $this->url); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function render($row) |
|
| 61 | - { |
|
| 62 | - return view('woo_gridview::columns.action', [ |
|
| 63 | - 'url' => $this->buildUrl($row), |
|
| 64 | - 'content' => $this->content, |
|
| 65 | - 'method' => $this->method, |
|
| 66 | - ])->render(); |
|
| 67 | - } |
|
| 60 | + public function render($row) |
|
| 61 | + { |
|
| 62 | + return view('woo_gridview::columns.action', [ |
|
| 63 | + 'url' => $this->buildUrl($row), |
|
| 64 | + 'content' => $this->content, |
|
| 65 | + 'method' => $this->method, |
|
| 66 | + ])->render(); |
|
| 67 | + } |
|
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -6,87 +6,87 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ActionsColumn extends BaseColumn |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * By default is empty for this column |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - public $title = ''; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * Value contains short codes for actions |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $value = []; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var bool |
|
| 23 | - */ |
|
| 24 | - public $sortable = false; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - public $formatters = []; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - public $delimiter = ' '; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var null |
|
| 38 | - */ |
|
| 39 | - public $filter = null; |
|
| 40 | - |
|
| 41 | - public function __construct(array $config) |
|
| 42 | - { |
|
| 43 | - parent::__construct($config); |
|
| 44 | - $this->buildActions(); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - protected function buildActions() |
|
| 48 | - { |
|
| 49 | - foreach ($this->value as &$action) { |
|
| 50 | - if (is_object($action)) { |
|
| 51 | - continue; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (is_string($action)) { |
|
| 55 | - $tmp = explode(':', $action); |
|
| 56 | - |
|
| 57 | - $action = [ |
|
| 58 | - 'class' => array_shift($tmp), |
|
| 59 | - 'args' => $tmp, |
|
| 60 | - ]; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $className = GridViewHelper::resolveAlias('action', $action['class']); |
|
| 64 | - $action = new $className(...$action['args']); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @return array |
|
| 70 | - */ |
|
| 71 | - protected function configTests(): array |
|
| 72 | - { |
|
| 73 | - return array_merge(parent::configTests(), [ |
|
| 74 | - 'value' => 'array', |
|
| 75 | - 'delimiter' => 'string', |
|
| 76 | - ]); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @inheritdoc |
|
| 81 | - */ |
|
| 82 | - public function _renderValue($row) |
|
| 83 | - { |
|
| 84 | - $result = []; |
|
| 85 | - |
|
| 86 | - foreach ($this->value as $action) { |
|
| 87 | - $result[] = $action->render($row); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return implode($this->delimiter, $result); |
|
| 91 | - } |
|
| 9 | + /** |
|
| 10 | + * By default is empty for this column |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + public $title = ''; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * Value contains short codes for actions |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $value = []; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var bool |
|
| 23 | + */ |
|
| 24 | + public $sortable = false; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + public $formatters = []; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + public $delimiter = ' '; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var null |
|
| 38 | + */ |
|
| 39 | + public $filter = null; |
|
| 40 | + |
|
| 41 | + public function __construct(array $config) |
|
| 42 | + { |
|
| 43 | + parent::__construct($config); |
|
| 44 | + $this->buildActions(); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + protected function buildActions() |
|
| 48 | + { |
|
| 49 | + foreach ($this->value as &$action) { |
|
| 50 | + if (is_object($action)) { |
|
| 51 | + continue; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (is_string($action)) { |
|
| 55 | + $tmp = explode(':', $action); |
|
| 56 | + |
|
| 57 | + $action = [ |
|
| 58 | + 'class' => array_shift($tmp), |
|
| 59 | + 'args' => $tmp, |
|
| 60 | + ]; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $className = GridViewHelper::resolveAlias('action', $action['class']); |
|
| 64 | + $action = new $className(...$action['args']); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @return array |
|
| 70 | + */ |
|
| 71 | + protected function configTests(): array |
|
| 72 | + { |
|
| 73 | + return array_merge(parent::configTests(), [ |
|
| 74 | + 'value' => 'array', |
|
| 75 | + 'delimiter' => 'string', |
|
| 76 | + ]); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @inheritdoc |
|
| 81 | + */ |
|
| 82 | + public function _renderValue($row) |
|
| 83 | + { |
|
| 84 | + $result = []; |
|
| 85 | + |
|
| 86 | + foreach ($this->value as $action) { |
|
| 87 | + $result[] = $action->render($row); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return implode($this->delimiter, $result); |
|
| 91 | + } |
|
| 92 | 92 | } |
| 93 | 93 | \ No newline at end of file |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | class DeleteAction extends Action |
| 6 | 6 | { |
| 7 | - public function __construct(string $url, string $content = '<i class="fa fa-trash-alt"></i>') |
|
| 8 | - { |
|
| 9 | - parent::__construct($url, $content, 'DELETE'); |
|
| 10 | - } |
|
| 7 | + public function __construct(string $url, string $content = '<i class="fa fa-trash-alt"></i>') |
|
| 8 | + { |
|
| 9 | + parent::__construct($url, $content, 'DELETE'); |
|
| 10 | + } |
|
| 11 | 11 | } |
| 12 | 12 | \ No newline at end of file |
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ShowAction extends Action |
| 8 | 8 | { |
| 9 | - public function __construct(string $url, string $content = '<i class="fa fa-eye"></i>') |
|
| 10 | - { |
|
| 11 | - parent::__construct($url, $content, 'GET'); |
|
| 12 | - } |
|
| 9 | + public function __construct(string $url, string $content = '<i class="fa fa-eye"></i>') |
|
| 10 | + { |
|
| 11 | + parent::__construct($url, $content, 'GET'); |
|
| 12 | + } |
|
| 13 | 13 | } |
| 14 | 14 | \ No newline at end of file |
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | |
| 7 | 7 | class EditAction extends Action |
| 8 | 8 | { |
| 9 | - public function __construct(string $url, string $content = '<i class="fa fa-edit"></i>') |
|
| 10 | - { |
|
| 11 | - parent::__construct($url, $content, 'GET'); |
|
| 12 | - } |
|
| 9 | + public function __construct(string $url, string $content = '<i class="fa fa-edit"></i>') |
|
| 10 | + { |
|
| 11 | + parent::__construct($url, $content, 'GET'); |
|
| 12 | + } |
|
| 13 | 13 | } |
| 14 | 14 | \ No newline at end of file |
@@ -8,6 +8,6 @@ |
||
| 8 | 8 | { |
| 9 | 9 | public function __construct(string $url, string $content = '<i class="fa fa-edit"></i>') |
| 10 | 10 | { |
| 11 | - parent::__construct($url, $content, 'GET'); |
|
| 11 | + parent::__construct($url, $content, 'GET'); |
|
| 12 | 12 | } |
| 13 | 13 | } |
| 14 | 14 | \ No newline at end of file |
@@ -7,77 +7,77 @@ |
||
| 7 | 7 | |
| 8 | 8 | class GridViewRequest |
| 9 | 9 | { |
| 10 | - use Configurable; |
|
| 11 | - |
|
| 12 | - public $page; |
|
| 13 | - |
|
| 14 | - public $sortColumn; |
|
| 15 | - |
|
| 16 | - public $sortOrder; |
|
| 17 | - |
|
| 18 | - public $perPage; |
|
| 19 | - |
|
| 20 | - public $filters = []; |
|
| 21 | - |
|
| 22 | - private function __construct($config) |
|
| 23 | - { |
|
| 24 | - $this->loadConfig($config); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - private static function gridField(int $gridId, string $field) |
|
| 28 | - { |
|
| 29 | - return $gridId == 0 ? $field : 'grid.' . $gridId . '.' . $field; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Allows to parse request information and making request instance |
|
| 34 | - * @param int $gridId |
|
| 35 | - * @return GridViewRequest |
|
| 36 | - */ |
|
| 37 | - public static function parse(int $gridId) |
|
| 38 | - { |
|
| 39 | - $request = Request::instance(); |
|
| 40 | - |
|
| 41 | - $page = $request->input(self::gridField($gridId, 'page'), 1); |
|
| 42 | - $sortColumn = $request->input(self::gridField($gridId, 'sort'), ''); |
|
| 43 | - $sortOrder = $request->input(self::gridField($gridId, 'order'), 'DESC'); |
|
| 44 | - $filters = $request->input(self::gridField($gridId, 'filters'), []); |
|
| 45 | - |
|
| 46 | - if ($page <= 0) { |
|
| 47 | - $page = 1; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (!is_string($sortColumn)) { |
|
| 51 | - $sortColumn = ''; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (!in_array($sortOrder, ['ASC', 'DESC'])) { |
|
| 55 | - $sortOrder = 'DESC'; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!is_array($filters)) { |
|
| 59 | - $filters = []; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return new GridViewRequest([ |
|
| 63 | - 'page' => $page, |
|
| 64 | - 'sortColumn' => $sortColumn, |
|
| 65 | - 'sortOrder' => $sortOrder, |
|
| 66 | - 'filters' => $filters, |
|
| 67 | - ]); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function getFilterValue(string $name) |
|
| 71 | - { |
|
| 72 | - return $this->filters[$name] ?? ''; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Should specify tests |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - protected function configTests(): array |
|
| 80 | - { |
|
| 81 | - return []; |
|
| 82 | - } |
|
| 10 | + use Configurable; |
|
| 11 | + |
|
| 12 | + public $page; |
|
| 13 | + |
|
| 14 | + public $sortColumn; |
|
| 15 | + |
|
| 16 | + public $sortOrder; |
|
| 17 | + |
|
| 18 | + public $perPage; |
|
| 19 | + |
|
| 20 | + public $filters = []; |
|
| 21 | + |
|
| 22 | + private function __construct($config) |
|
| 23 | + { |
|
| 24 | + $this->loadConfig($config); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + private static function gridField(int $gridId, string $field) |
|
| 28 | + { |
|
| 29 | + return $gridId == 0 ? $field : 'grid.' . $gridId . '.' . $field; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Allows to parse request information and making request instance |
|
| 34 | + * @param int $gridId |
|
| 35 | + * @return GridViewRequest |
|
| 36 | + */ |
|
| 37 | + public static function parse(int $gridId) |
|
| 38 | + { |
|
| 39 | + $request = Request::instance(); |
|
| 40 | + |
|
| 41 | + $page = $request->input(self::gridField($gridId, 'page'), 1); |
|
| 42 | + $sortColumn = $request->input(self::gridField($gridId, 'sort'), ''); |
|
| 43 | + $sortOrder = $request->input(self::gridField($gridId, 'order'), 'DESC'); |
|
| 44 | + $filters = $request->input(self::gridField($gridId, 'filters'), []); |
|
| 45 | + |
|
| 46 | + if ($page <= 0) { |
|
| 47 | + $page = 1; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (!is_string($sortColumn)) { |
|
| 51 | + $sortColumn = ''; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (!in_array($sortOrder, ['ASC', 'DESC'])) { |
|
| 55 | + $sortOrder = 'DESC'; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!is_array($filters)) { |
|
| 59 | + $filters = []; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return new GridViewRequest([ |
|
| 63 | + 'page' => $page, |
|
| 64 | + 'sortColumn' => $sortColumn, |
|
| 65 | + 'sortOrder' => $sortOrder, |
|
| 66 | + 'filters' => $filters, |
|
| 67 | + ]); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function getFilterValue(string $name) |
|
| 71 | + { |
|
| 72 | + return $this->filters[$name] ?? ''; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Should specify tests |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + protected function configTests(): array |
|
| 80 | + { |
|
| 81 | + return []; |
|
| 82 | + } |
|
| 83 | 83 | } |
| 84 | 84 | \ No newline at end of file |
@@ -6,74 +6,74 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ArrayDataProvider extends BaseDataProvider |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 12 | - private $data; |
|
| 9 | + /** |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | + private $data; |
|
| 13 | 13 | |
| 14 | - public function __construct(array $data) |
|
| 15 | - { |
|
| 16 | - $this->data = $data; |
|
| 17 | - } |
|
| 14 | + public function __construct(array $data) |
|
| 15 | + { |
|
| 16 | + $this->data = $data; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param GridViewRequest $request |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - protected function processData(GridViewRequest $request) : array |
|
| 24 | - { |
|
| 25 | - if (empty($this->data)) { |
|
| 26 | - return []; |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * @param GridViewRequest $request |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + protected function processData(GridViewRequest $request) : array |
|
| 24 | + { |
|
| 25 | + if (empty($this->data)) { |
|
| 26 | + return []; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - $tmp = collect($this->data); |
|
| 29 | + $tmp = collect($this->data); |
|
| 30 | 30 | |
| 31 | - if (!empty($request->filters)) { |
|
| 32 | - $tmp = $tmp->filter(function($item) use ($request) { |
|
| 33 | - foreach ($request->filters as $filterKey => $filterValue) { |
|
| 31 | + if (!empty($request->filters)) { |
|
| 32 | + $tmp = $tmp->filter(function($item) use ($request) { |
|
| 33 | + foreach ($request->filters as $filterKey => $filterValue) { |
|
| 34 | 34 | |
| 35 | - if (!isset($item[$filterKey])) { |
|
| 36 | - return false; |
|
| 37 | - } |
|
| 35 | + if (!isset($item[$filterKey])) { |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - if (strpos($item[$filterKey], $filterValue) === false) { |
|
| 40 | - return false; |
|
| 41 | - } |
|
| 42 | - } |
|
| 39 | + if (strpos($item[$filterKey], $filterValue) === false) { |
|
| 40 | + return false; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return true; |
|
| 45 | - }); |
|
| 46 | - } |
|
| 44 | + return true; |
|
| 45 | + }); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - if (!empty($request->sortColumn)) { |
|
| 49 | - $tmp = $tmp->sortBy( |
|
| 50 | - $request->sortColumn, |
|
| 51 | - SORT_REGULAR, |
|
| 52 | - $request->sortOrder == 'DESC' |
|
| 53 | - ); |
|
| 54 | - } |
|
| 48 | + if (!empty($request->sortColumn)) { |
|
| 49 | + $tmp = $tmp->sortBy( |
|
| 50 | + $request->sortColumn, |
|
| 51 | + SORT_REGULAR, |
|
| 52 | + $request->sortOrder == 'DESC' |
|
| 53 | + ); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $tmp->values()->all(); |
|
| 57 | - } |
|
| 56 | + return $tmp->values()->all(); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @inheritdoc |
|
| 61 | - */ |
|
| 62 | - public function getCount(GridViewRequest $request) : int |
|
| 63 | - { |
|
| 64 | - return count($this->processData($request)); |
|
| 65 | - } |
|
| 59 | + /** |
|
| 60 | + * @inheritdoc |
|
| 61 | + */ |
|
| 62 | + public function getCount(GridViewRequest $request) : int |
|
| 63 | + { |
|
| 64 | + return count($this->processData($request)); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @inheritdoc |
|
| 69 | - */ |
|
| 70 | - public function getData(GridViewRequest $request) |
|
| 71 | - { |
|
| 72 | - $tmp = $this->processData($request); |
|
| 67 | + /** |
|
| 68 | + * @inheritdoc |
|
| 69 | + */ |
|
| 70 | + public function getData(GridViewRequest $request) |
|
| 71 | + { |
|
| 72 | + $tmp = $this->processData($request); |
|
| 73 | 73 | |
| 74 | - return array_splice( |
|
| 75 | - $tmp, |
|
| 76 | - ($request->page -1) * $request->perPage, $request->perPage |
|
| 77 | - ); |
|
| 78 | - } |
|
| 74 | + return array_splice( |
|
| 75 | + $tmp, |
|
| 76 | + ($request->page -1) * $request->perPage, $request->perPage |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | 79 | } |
| 80 | 80 | \ No newline at end of file |
@@ -73,7 +73,7 @@ |
||
| 73 | 73 | |
| 74 | 74 | return array_splice( |
| 75 | 75 | $tmp, |
| 76 | - ($request->page -1) * $request->perPage, $request->perPage |
|
| 76 | + ($request->page - 1) * $request->perPage, $request->perPage |
|
| 77 | 77 | ); |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | \ No newline at end of file |