@@ -7,16 +7,16 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ViewColumn extends BaseColumn |
| 9 | 9 | { |
| 10 | - public $formatters = []; |
|
| 10 | + public $formatters = []; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * Render column value for row |
|
| 14 | - * @param array|object $row |
|
| 15 | - * @return string|mixed |
|
| 16 | - * @throws Throwable |
|
| 17 | - */ |
|
| 18 | - protected function _renderValue($row) |
|
| 19 | - { |
|
| 20 | - return view($this->value, $row)->render(); |
|
| 21 | - } |
|
| 12 | + /** |
|
| 13 | + * Render column value for row |
|
| 14 | + * @param array|object $row |
|
| 15 | + * @return string|mixed |
|
| 16 | + * @throws Throwable |
|
| 17 | + */ |
|
| 18 | + protected function _renderValue($row) |
|
| 19 | + { |
|
| 20 | + return view($this->value, $row)->render(); |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | \ No newline at end of file |
@@ -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 |
@@ -9,146 +9,146 @@ |
||
| 9 | 9 | |
| 10 | 10 | abstract class BaseColumn |
| 11 | 11 | { |
| 12 | - use Configurable; |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * Column title |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - public $title = ''; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Column value. Could be an attribute, |
|
| 22 | - * @var string|mixed |
|
| 23 | - */ |
|
| 24 | - public $value = ''; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var BaseFilter |
|
| 28 | - */ |
|
| 29 | - public $filter; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var boolean |
|
| 33 | - */ |
|
| 34 | - public $sortable = true; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - public $headerHtmlOptions = []; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - public $contentHtmlOptions = []; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var array - allowed: raw, url, email, text, image |
|
| 48 | - */ |
|
| 49 | - public $formatters = ['text']; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Value when column is empty |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - public $emptyValue = '-'; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * BaseColumn constructor. |
|
| 59 | - * @param array $config |
|
| 60 | - * @throws \Woo\GridView\Exceptions\GridViewConfigException |
|
| 61 | - */ |
|
| 62 | - public function __construct(array $config) |
|
| 63 | - { |
|
| 64 | - $this->loadConfig($config); |
|
| 65 | - |
|
| 66 | - $this->buildFilter(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - protected function buildFilter() |
|
| 70 | - { |
|
| 71 | - if (is_null($this->filter) || is_object($this->filter)) { |
|
| 72 | - return; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - if (is_string($this->filter)) { |
|
| 76 | - $this->filter = [ |
|
| 77 | - 'class' => $this->filter, |
|
| 78 | - 'name' => $this->value, |
|
| 79 | - ]; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if (empty($this->filter['class'])) { |
|
| 83 | - $this->filter['class'] = TextFilter::class; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if (empty($this->filter['name'])) { |
|
| 87 | - $this->filter['name'] = $this->value; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $className = GridViewHelper::resolveAlias('filter', $this->filter['class']); |
|
| 91 | - $this->filter = new $className($this->filter); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - protected function configTests(): array |
|
| 98 | - { |
|
| 99 | - return [ |
|
| 100 | - 'title' => 'string', |
|
| 101 | - 'value' => 'any', |
|
| 102 | - 'headerHtmlOptions' => 'array', |
|
| 103 | - 'contentHtmlOptions' => 'array', |
|
| 104 | - 'formatters' => 'array', |
|
| 105 | - 'emptyValue' => 'string', |
|
| 106 | - 'sortable' => 'bool', |
|
| 107 | - 'filter' => BaseFilter::class . '|null', |
|
| 108 | - ]; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Formatted header html options |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function compileHeaderHtmlOptions() : string |
|
| 116 | - { |
|
| 117 | - return GridViewHelper::htmlOptionsToString($this->headerHtmlOptions); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Formatted content html options |
|
| 122 | - * @param array $context |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - public function compileContentHtmlOptions(array $context) : string |
|
| 126 | - { |
|
| 127 | - return GridViewHelper::htmlOptionsToString($this->contentHtmlOptions, $context); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Render column value for row |
|
| 132 | - * @param array|object $row |
|
| 133 | - * @return string|mixed |
|
| 134 | - */ |
|
| 135 | - protected abstract function _renderValue($row); |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Renders column content |
|
| 139 | - * @param $row |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function renderValue($row) |
|
| 143 | - { |
|
| 144 | - $value = $this->_renderValue($row); |
|
| 145 | - |
|
| 146 | - foreach ($this->formatters as $formatter) { |
|
| 147 | - $className = GridViewHelper::resolveAlias('formatter', $formatter); |
|
| 148 | - $value = (new $className)->format($value); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $value; |
|
| 152 | - } |
|
| 12 | + use Configurable; |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * Column title |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + public $title = ''; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Column value. Could be an attribute, |
|
| 22 | + * @var string|mixed |
|
| 23 | + */ |
|
| 24 | + public $value = ''; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var BaseFilter |
|
| 28 | + */ |
|
| 29 | + public $filter; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var boolean |
|
| 33 | + */ |
|
| 34 | + public $sortable = true; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + public $headerHtmlOptions = []; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + public $contentHtmlOptions = []; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var array - allowed: raw, url, email, text, image |
|
| 48 | + */ |
|
| 49 | + public $formatters = ['text']; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Value when column is empty |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + public $emptyValue = '-'; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * BaseColumn constructor. |
|
| 59 | + * @param array $config |
|
| 60 | + * @throws \Woo\GridView\Exceptions\GridViewConfigException |
|
| 61 | + */ |
|
| 62 | + public function __construct(array $config) |
|
| 63 | + { |
|
| 64 | + $this->loadConfig($config); |
|
| 65 | + |
|
| 66 | + $this->buildFilter(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + protected function buildFilter() |
|
| 70 | + { |
|
| 71 | + if (is_null($this->filter) || is_object($this->filter)) { |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + if (is_string($this->filter)) { |
|
| 76 | + $this->filter = [ |
|
| 77 | + 'class' => $this->filter, |
|
| 78 | + 'name' => $this->value, |
|
| 79 | + ]; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if (empty($this->filter['class'])) { |
|
| 83 | + $this->filter['class'] = TextFilter::class; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if (empty($this->filter['name'])) { |
|
| 87 | + $this->filter['name'] = $this->value; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $className = GridViewHelper::resolveAlias('filter', $this->filter['class']); |
|
| 91 | + $this->filter = new $className($this->filter); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + protected function configTests(): array |
|
| 98 | + { |
|
| 99 | + return [ |
|
| 100 | + 'title' => 'string', |
|
| 101 | + 'value' => 'any', |
|
| 102 | + 'headerHtmlOptions' => 'array', |
|
| 103 | + 'contentHtmlOptions' => 'array', |
|
| 104 | + 'formatters' => 'array', |
|
| 105 | + 'emptyValue' => 'string', |
|
| 106 | + 'sortable' => 'bool', |
|
| 107 | + 'filter' => BaseFilter::class . '|null', |
|
| 108 | + ]; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Formatted header html options |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function compileHeaderHtmlOptions() : string |
|
| 116 | + { |
|
| 117 | + return GridViewHelper::htmlOptionsToString($this->headerHtmlOptions); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Formatted content html options |
|
| 122 | + * @param array $context |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + public function compileContentHtmlOptions(array $context) : string |
|
| 126 | + { |
|
| 127 | + return GridViewHelper::htmlOptionsToString($this->contentHtmlOptions, $context); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Render column value for row |
|
| 132 | + * @param array|object $row |
|
| 133 | + * @return string|mixed |
|
| 134 | + */ |
|
| 135 | + protected abstract function _renderValue($row); |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Renders column content |
|
| 139 | + * @param $row |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function renderValue($row) |
|
| 143 | + { |
|
| 144 | + $value = $this->_renderValue($row); |
|
| 145 | + |
|
| 146 | + foreach ($this->formatters as $formatter) { |
|
| 147 | + $className = GridViewHelper::resolveAlias('formatter', $formatter); |
|
| 148 | + $value = (new $className)->format($value); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $value; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | 154 | } |
| 155 | 155 | \ 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 |