@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function boot() |
| 15 | 15 | { |
| 16 | - $this->loadViewsFrom(__DIR__.'/../views', 'woo_gridview'); |
|
| 16 | + $this->loadViewsFrom(__DIR__ . '/../views', 'woo_gridview'); |
|
| 17 | 17 | |
| 18 | 18 | require_once __DIR__ . '/functions.php'; |
| 19 | 19 | } |
@@ -10,103 +10,103 @@ |
||
| 10 | 10 | |
| 11 | 11 | class GridView |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var DataProviderInterface |
|
| 15 | - */ |
|
| 16 | - public $dataProvider; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - public $columns = []; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - public $columnClass = AttributeColumn::class; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var string|RendererInterface |
|
| 30 | - */ |
|
| 31 | - public $renderer = DefaultRenderer::class; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var int |
|
| 35 | - */ |
|
| 36 | - public $rowsPerPage = 25; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - public $tableHtmlOptions = [ |
|
| 42 | - 'class' => 'table table-bordered gridview-table', |
|
| 43 | - ]; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * GridView constructor. |
|
| 47 | - * @param array $config |
|
| 48 | - */ |
|
| 49 | - public function __construct(array $config) |
|
| 50 | - { |
|
| 51 | - GridViewHelper::loadConfig($this, $config); |
|
| 52 | - |
|
| 53 | - GridViewHelper::testConfig($this, [ |
|
| 54 | - 'dataProvider' => DataProviderInterface::class, |
|
| 55 | - 'columns' => 'array', |
|
| 56 | - 'columnClass' => BaseColumn::class, |
|
| 57 | - 'renderer' => RendererInterface::class, |
|
| 58 | - 'rowsPerPage' => 'int', |
|
| 59 | - 'tableHtmlOptions' => 'array', |
|
| 60 | - ]); |
|
| 61 | - |
|
| 62 | - $this->buildColumns(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Build columns into objects |
|
| 67 | - */ |
|
| 68 | - protected function buildColumns() |
|
| 69 | - { |
|
| 70 | - foreach ($this->columns as &$column) { |
|
| 71 | - |
|
| 72 | - if (is_object($column)) { |
|
| 73 | - continue; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $className = $column['class'] ?? $this->columnClass; |
|
| 77 | - $column = new $className($column); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Makes an instance |
|
| 83 | - * @param $params |
|
| 84 | - * @return GridView |
|
| 85 | - */ |
|
| 86 | - public static function make($params) |
|
| 87 | - { |
|
| 88 | - return new self($params); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Draws widget and return html code |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public function render() |
|
| 96 | - { |
|
| 97 | - if (!is_object($this->renderer)) { |
|
| 98 | - $this->renderer = new $this->renderer; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $this->renderer->render($this); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Wrapper for draw method |
|
| 106 | - * @see View::draw() |
|
| 107 | - */ |
|
| 108 | - public function __toString() |
|
| 109 | - { |
|
| 110 | - return $this->render(); |
|
| 111 | - } |
|
| 13 | + /** |
|
| 14 | + * @var DataProviderInterface |
|
| 15 | + */ |
|
| 16 | + public $dataProvider; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + public $columns = []; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + public $columnClass = AttributeColumn::class; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var string|RendererInterface |
|
| 30 | + */ |
|
| 31 | + public $renderer = DefaultRenderer::class; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var int |
|
| 35 | + */ |
|
| 36 | + public $rowsPerPage = 25; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + public $tableHtmlOptions = [ |
|
| 42 | + 'class' => 'table table-bordered gridview-table', |
|
| 43 | + ]; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * GridView constructor. |
|
| 47 | + * @param array $config |
|
| 48 | + */ |
|
| 49 | + public function __construct(array $config) |
|
| 50 | + { |
|
| 51 | + GridViewHelper::loadConfig($this, $config); |
|
| 52 | + |
|
| 53 | + GridViewHelper::testConfig($this, [ |
|
| 54 | + 'dataProvider' => DataProviderInterface::class, |
|
| 55 | + 'columns' => 'array', |
|
| 56 | + 'columnClass' => BaseColumn::class, |
|
| 57 | + 'renderer' => RendererInterface::class, |
|
| 58 | + 'rowsPerPage' => 'int', |
|
| 59 | + 'tableHtmlOptions' => 'array', |
|
| 60 | + ]); |
|
| 61 | + |
|
| 62 | + $this->buildColumns(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Build columns into objects |
|
| 67 | + */ |
|
| 68 | + protected function buildColumns() |
|
| 69 | + { |
|
| 70 | + foreach ($this->columns as &$column) { |
|
| 71 | + |
|
| 72 | + if (is_object($column)) { |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $className = $column['class'] ?? $this->columnClass; |
|
| 77 | + $column = new $className($column); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Makes an instance |
|
| 83 | + * @param $params |
|
| 84 | + * @return GridView |
|
| 85 | + */ |
|
| 86 | + public static function make($params) |
|
| 87 | + { |
|
| 88 | + return new self($params); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Draws widget and return html code |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public function render() |
|
| 96 | + { |
|
| 97 | + if (!is_object($this->renderer)) { |
|
| 98 | + $this->renderer = new $this->renderer; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $this->renderer->render($this); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Wrapper for draw method |
|
| 106 | + * @see View::draw() |
|
| 107 | + */ |
|
| 108 | + public function __toString() |
|
| 109 | + { |
|
| 110 | + return $this->render(); |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | \ No newline at end of file |