@@ -7,23 +7,23 @@ |
||
| 7 | 7 | |
| 8 | 8 | class DefaultRenderer extends BaseRenderer |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @param GridView $view |
|
| 12 | - * @return string |
|
| 13 | - * @throws \Throwable |
|
| 14 | - */ |
|
| 15 | - public function render(GridView $view): string |
|
| 16 | - { |
|
| 17 | - $page = intval($_GET['page'] ?? 1); |
|
| 10 | + /** |
|
| 11 | + * @param GridView $view |
|
| 12 | + * @return string |
|
| 13 | + * @throws \Throwable |
|
| 14 | + */ |
|
| 15 | + public function render(GridView $view): string |
|
| 16 | + { |
|
| 17 | + $page = intval($_GET['page'] ?? 1); |
|
| 18 | 18 | |
| 19 | - return view('woo_gridview::render-default', [ |
|
| 20 | - 'columns' => $view->columns, |
|
| 21 | - 'data' => $view->dataProvider->getData($page, $view->rowsPerPage), |
|
| 22 | - 'tableHtmlOptions' => GridViewHelper::htmlOptionsToString($view->tableHtmlOptions), |
|
| 23 | - 'dataProvider' => $view->dataProvider, |
|
| 24 | - 'perPage' => $view->rowsPerPage, |
|
| 25 | - 'currentPage' => $page, |
|
| 26 | - 'containerId' => $this->id, |
|
| 27 | - ])->render(); |
|
| 28 | - } |
|
| 19 | + return view('woo_gridview::render-default', [ |
|
| 20 | + 'columns' => $view->columns, |
|
| 21 | + 'data' => $view->dataProvider->getData($page, $view->rowsPerPage), |
|
| 22 | + 'tableHtmlOptions' => GridViewHelper::htmlOptionsToString($view->tableHtmlOptions), |
|
| 23 | + 'dataProvider' => $view->dataProvider, |
|
| 24 | + 'perPage' => $view->rowsPerPage, |
|
| 25 | + 'currentPage' => $page, |
|
| 26 | + 'containerId' => $this->id, |
|
| 27 | + ])->render(); |
|
| 28 | + } |
|
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -6,60 +6,60 @@ discard block |
||
| 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 = ''; |
|
| 9 | + /** |
|
| 10 | + * By default is empty for this column |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + public $title = ''; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Value contains short codes for actions |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - public $value = '{show} {edit} {delete}'; |
|
| 15 | + /** |
|
| 16 | + * Value contains short codes for actions |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + public $value = '{show} {edit} {delete}'; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Additional actions could be added, key is short-code and value is callback |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $additionalActions = []; |
|
| 21 | + /** |
|
| 22 | + * Additional actions could be added, key is short-code and value is callback |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $additionalActions = []; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var \Closure|null |
|
| 29 | - */ |
|
| 30 | - public $actionsUrls; |
|
| 27 | + /** |
|
| 28 | + * @var \Closure|null |
|
| 29 | + */ |
|
| 30 | + public $actionsUrls; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $contentFormat = 'raw'; |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $contentFormat = 'raw'; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return array |
|
| 39 | - */ |
|
| 40 | - protected function configTests(): array |
|
| 41 | - { |
|
| 42 | - return array_merge(parent::configTests(), [ |
|
| 43 | - 'value' => 'string', |
|
| 44 | - 'additionalActions' => 'array', |
|
| 45 | - 'actionsUrls' => 'any', |
|
| 46 | - ]); |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * @return array |
|
| 39 | + */ |
|
| 40 | + protected function configTests(): array |
|
| 41 | + { |
|
| 42 | + return array_merge(parent::configTests(), [ |
|
| 43 | + 'value' => 'string', |
|
| 44 | + 'additionalActions' => 'array', |
|
| 45 | + 'actionsUrls' => 'any', |
|
| 46 | + ]); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return array |
|
| 51 | - */ |
|
| 52 | - public function basicActions() |
|
| 53 | - { |
|
| 54 | - return [ |
|
| 55 | - 'show' => function($model) { |
|
| 56 | - return '<a href="' . call_user_func($this->actionsUrls, $model)['show'] . '">View</a>'; |
|
| 57 | - }, |
|
| 58 | - 'edit' => function($model) { |
|
| 59 | - return '<a href="' . call_user_func($this->actionsUrls, $model)['edit'] . '">Edit</a>'; |
|
| 60 | - }, |
|
| 61 | - 'delete' => function($model) { |
|
| 62 | - return ' |
|
| 49 | + /** |
|
| 50 | + * @return array |
|
| 51 | + */ |
|
| 52 | + public function basicActions() |
|
| 53 | + { |
|
| 54 | + return [ |
|
| 55 | + 'show' => function($model) { |
|
| 56 | + return '<a href="' . call_user_func($this->actionsUrls, $model)['show'] . '">View</a>'; |
|
| 57 | + }, |
|
| 58 | + 'edit' => function($model) { |
|
| 59 | + return '<a href="' . call_user_func($this->actionsUrls, $model)['edit'] . '">Edit</a>'; |
|
| 60 | + }, |
|
| 61 | + 'delete' => function($model) { |
|
| 62 | + return ' |
|
| 63 | 63 | <form action="' . call_user_func($this->actionsUrls, $model)['delete'] . '" method="post" class="deleteForm"> |
| 64 | 64 | <input type="hidden" name="_token" value="' . csrf_token() . '"> |
| 65 | 65 | <input type="hidden" name="_method" value="DELETE"> |
@@ -68,27 +68,27 @@ discard block |
||
| 68 | 68 | >Delete</button> |
| 69 | 69 | </form> |
| 70 | 70 | '; |
| 71 | - }, |
|
| 72 | - ]; |
|
| 73 | - } |
|
| 71 | + }, |
|
| 72 | + ]; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @inheritdoc |
|
| 77 | - */ |
|
| 78 | - public function _renderValue($row) |
|
| 79 | - { |
|
| 80 | - $result = $this->value; |
|
| 75 | + /** |
|
| 76 | + * @inheritdoc |
|
| 77 | + */ |
|
| 78 | + public function _renderValue($row) |
|
| 79 | + { |
|
| 80 | + $result = $this->value; |
|
| 81 | 81 | |
| 82 | - $actions = array_merge($this->basicActions(), $this->additionalActions); |
|
| 82 | + $actions = array_merge($this->basicActions(), $this->additionalActions); |
|
| 83 | 83 | |
| 84 | - foreach ($actions as $key => $action) { |
|
| 85 | - if (strpos($result, '{' . $key . '}') === false) { |
|
| 86 | - continue; |
|
| 87 | - } |
|
| 84 | + foreach ($actions as $key => $action) { |
|
| 85 | + if (strpos($result, '{' . $key . '}') === false) { |
|
| 86 | + continue; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - $result = str_replace('{' . $key . '}', $action($row), $result); |
|
| 90 | - } |
|
| 89 | + $result = str_replace('{' . $key . '}', $action($row), $result); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return $result; |
|
| 93 | - } |
|
| 92 | + return $result; |
|
| 93 | + } |
|
| 94 | 94 | } |
| 95 | 95 | \ No newline at end of file |
@@ -6,46 +6,46 @@ |
||
| 6 | 6 | |
| 7 | 7 | class EloquentDataProvider implements DataProviderInterface |
| 8 | 8 | { |
| 9 | - protected $query; |
|
| 10 | - |
|
| 11 | - /** |
|
| 12 | - * EloquentDataProvider constructor. |
|
| 13 | - * @param Builder $query |
|
| 14 | - */ |
|
| 15 | - public function __construct(Builder $query) |
|
| 16 | - { |
|
| 17 | - $this->query = $query; |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @inheritdoc |
|
| 22 | - */ |
|
| 23 | - public function getCount(): int |
|
| 24 | - { |
|
| 25 | - return $this->query->count(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @inheritdoc |
|
| 30 | - */ |
|
| 31 | - public function getTotalPages(int $perPage): int |
|
| 32 | - { |
|
| 33 | - if ($perPage == 0) { |
|
| 34 | - return 1; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - return ceil($this->getCount() / $perPage); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @inheritdoc |
|
| 42 | - */ |
|
| 43 | - public function getData(int $page, int $perPage) |
|
| 44 | - { |
|
| 45 | - if ($perPage == 0) { |
|
| 46 | - return $this->query->get(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - return (clone $this->query)->paginate($perPage, ['*'], 'page', $page); |
|
| 50 | - } |
|
| 9 | + protected $query; |
|
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * EloquentDataProvider constructor. |
|
| 13 | + * @param Builder $query |
|
| 14 | + */ |
|
| 15 | + public function __construct(Builder $query) |
|
| 16 | + { |
|
| 17 | + $this->query = $query; |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @inheritdoc |
|
| 22 | + */ |
|
| 23 | + public function getCount(): int |
|
| 24 | + { |
|
| 25 | + return $this->query->count(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @inheritdoc |
|
| 30 | + */ |
|
| 31 | + public function getTotalPages(int $perPage): int |
|
| 32 | + { |
|
| 33 | + if ($perPage == 0) { |
|
| 34 | + return 1; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + return ceil($this->getCount() / $perPage); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @inheritdoc |
|
| 42 | + */ |
|
| 43 | + public function getData(int $page, int $perPage) |
|
| 44 | + { |
|
| 45 | + if ($perPage == 0) { |
|
| 46 | + return $this->query->get(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + return (clone $this->query)->paginate($perPage, ['*'], 'page', $page); |
|
| 50 | + } |
|
| 51 | 51 | } |
| 52 | 52 | \ No newline at end of file |
@@ -4,43 +4,43 @@ |
||
| 4 | 4 | |
| 5 | 5 | class ArrayDataProvider implements DataProviderInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @var array |
|
| 9 | - */ |
|
| 10 | - private $data; |
|
| 7 | + /** |
|
| 8 | + * @var array |
|
| 9 | + */ |
|
| 10 | + private $data; |
|
| 11 | 11 | |
| 12 | - public function __construct(array $data) |
|
| 13 | - { |
|
| 14 | - $this->data = $data; |
|
| 15 | - } |
|
| 12 | + public function __construct(array $data) |
|
| 13 | + { |
|
| 14 | + $this->data = $data; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Should return total amount of rows |
|
| 19 | - * @return int |
|
| 20 | - */ |
|
| 21 | - public function getCount() : int |
|
| 22 | - { |
|
| 23 | - return count($this->data); |
|
| 24 | - } |
|
| 17 | + /** |
|
| 18 | + * Should return total amount of rows |
|
| 19 | + * @return int |
|
| 20 | + */ |
|
| 21 | + public function getCount() : int |
|
| 22 | + { |
|
| 23 | + return count($this->data); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Should return amount of pages |
|
| 28 | - * @param int $perPage - amount of records per page |
|
| 29 | - * @return int |
|
| 30 | - */ |
|
| 31 | - public function getTotalPages(int $perPage) : int |
|
| 32 | - { |
|
| 33 | - return ceil($this->getCount() / $perPage); |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * Should return amount of pages |
|
| 28 | + * @param int $perPage - amount of records per page |
|
| 29 | + * @return int |
|
| 30 | + */ |
|
| 31 | + public function getTotalPages(int $perPage) : int |
|
| 32 | + { |
|
| 33 | + return ceil($this->getCount() / $perPage); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Should return a list of data for current page |
|
| 38 | - * @param int $page |
|
| 39 | - * @param int $perPage - amount of records per page |
|
| 40 | - * @return mixed |
|
| 41 | - */ |
|
| 42 | - public function getData(int $page, int $perPage) |
|
| 43 | - { |
|
| 44 | - return array_splice($this->data, ($page -1) * $perPage, $perPage); |
|
| 45 | - } |
|
| 36 | + /** |
|
| 37 | + * Should return a list of data for current page |
|
| 38 | + * @param int $page |
|
| 39 | + * @param int $perPage - amount of records per page |
|
| 40 | + * @return mixed |
|
| 41 | + */ |
|
| 42 | + public function getData(int $page, int $perPage) |
|
| 43 | + { |
|
| 44 | + return array_splice($this->data, ($page -1) * $perPage, $perPage); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | \ No newline at end of file |
@@ -41,6 +41,6 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | public function getData(int $page, int $perPage) |
| 43 | 43 | { |
| 44 | - return array_splice($this->data, ($page -1) * $perPage, $perPage); |
|
| 44 | + return array_splice($this->data, ($page - 1) * $perPage, $perPage); |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | \ No newline at end of file |