Completed
Push — master ( 69e16e...69bb37 )
by Denis
01:15
created
src/GridView.php 1 patch
Indentation   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -15,232 +15,232 @@
 block discarded – undo
15 15
 
16 16
 class GridView
17 17
 {
18
-    use Configurable;
19
-
20
-    /**
21
-     * Counter for ids
22
-     * @var int
23
-     */
24
-    private static $counter = 0;
25
-
26
-    /**
27
-     * Grid id (used for request handling, for
28
-     * @var int
29
-     */
30
-    private $id;
31
-
32
-    /**
33
-     * DataProvider provides gridview with the data for representation
34
-     * @var BaseDataProvider
35
-     */
36
-    public $dataProvider;
37
-
38
-    /**
39
-     * Columns config. You may specify array or GridColumn instance
40
-     * @var BaseColumn[]
41
-     */
42
-    public $columns = [];
43
-
44
-    /**
45
-     * Common options for all columns, will be appended to all columns configs
46
-     * @var array
47
-     */
48
-    public $columnOptions = [
49
-        'class' => AttributeColumn::class,
50
-    ];
51
-
52
-    /**
53
-     * Renders the final UI
54
-     * @var string|BaseRenderer
55
-     */
56
-    public $renderer = DefaultRenderer::class;
57
-
58
-    /**
59
-     * Allows to pass some options into renderer/customize rendered behavior
60
-     * @var array
61
-     */
62
-    public $rendererOptions = [];
63
-
64
-    /**
65
-     * Controls amount of data per page
66
-     * @var int
67
-     */
68
-    public $rowsPerPage = 25;
69
-
70
-    /**
71
-     * Allows to tune the <table> tag with html options
72
-     * @var array
73
-     */
74
-    public $tableHtmlOptions = [
75
-        'class' => 'table table-bordered gridview-table',
76
-    ];
77
-
78
-    /**
79
-     * Indicate if filters will be shown or not
80
-     * @var bool
81
-     */
82
-    public $showFilters = true;
83
-
84
-    /**
85
-     * Flags allow to change standalone vue to. If false, GridView component should be included in your root Vue instance
86
-     * @var bool
87
-     */
88
-    public $standaloneVue = true;
89
-
90
-    /**
91
-     * List of additinal params which'll be added to filter requests
92
-     * @var array
93
-     */
94
-    public $additionalRequestParams = [];
95
-
96
-    /**
97
-     * @var Paginator
98
-     */
99
-    protected $pagination;
100
-
101
-    /**
102
-     * @var GridViewRequest
103
-     */
104
-    protected $request;
105
-
106
-    /**
107
-     * GridView constructor.
108
-     * @param array $config
109
-     * @throws Exceptions\GridViewConfigException
110
-     */
111
-    public function __construct(array $config)
112
-    {
113
-        $this->id = self::$counter++;
114
-
115
-        $this->loadConfig($config);
116
-
117
-        /**
118
-         * Making renderer
119
-         */
120
-        if (!is_object($this->renderer)) {
121
-            $className = GridViewHelper::resolveAlias('renderer', $this->renderer);
122
-            $this->renderer = new $className(array_merge(
123
-                $this->rendererOptions, [
124
-                    'gridView' => $this,
125
-                ]
126
-            ));
127
-        }
128
-
129
-        /**
130
-         * Build columns from config
131
-         */
132
-        $this->buildColumns();
133
-
134
-        $this->request = GridViewRequest::parse($this->id);
135
-        $this->request->perPage = $this->rowsPerPage;
136
-
137
-        $this->pagination = new LengthAwarePaginator(
138
-            $this->dataProvider->getData($this->request),
139
-            $this->dataProvider->getCount($this->request),
140
-            $this->rowsPerPage,
141
-            $this->request->page
142
-        );
143
-    }
144
-
145
-    /**
146
-     * @return array
147
-     */
148
-    protected function configTests(): array
149
-    {
150
-        return [
151
-            'dataProvider' => BaseDataProvider::class,
152
-            'columns' => 'array',
153
-            'renderer' => BaseRenderer::class,
154
-            'rowsPerPage' => 'int',
155
-            'tableHtmlOptions' => 'array',
156
-            'showFilters' => 'boolean',
157
-        ];
158
-    }
159
-
160
-    /**
161
-     * Build columns into objects
162
-     */
163
-    protected function buildColumns()
164
-    {
165
-        foreach ($this->columns as $key => &$columnOptions) {
166
-
167
-            /**
168
-             * In case of when column is already build
169
-             */
170
-            if (is_object($columnOptions)) {
171
-                continue;
172
-            }
173
-
174
-            /**
175
-             * When only attribute name/value passed
176
-             */
177
-            if (is_string($columnOptions)) {
178
-                $columnOptions = [
179
-                    'value' => $columnOptions,
180
-                ];
181
-            }
182
-
183
-            if ($columnOptions instanceof Closure) {
184
-                $columnOptions = [
185
-                    'class' => CallbackColumn::class,
186
-                    'value' => $columnOptions,
187
-                    'title' => GridViewHelper::columnTitle($key),
188
-                ];
189
-            }
190
-
191
-            /**
192
-             * Inline column declaration detector
193
-             */
194
-            if (is_string($columnOptions['value']) && strpos($columnOptions['value'], 'view:') === 0) {
195
-                $columnOptions['class'] = 'view';
196
-                $columnOptions['value'] = str_replace('view:', '', $columnOptions['value']);
197
-            }
198
-
199
-            $columnOptions = array_merge($this->columnOptions, $columnOptions);
200
-
201
-            $className = GridViewHelper::resolveAlias('column', $columnOptions['class']);
202
-            $columnOptions = new $className($columnOptions);
203
-        }
204
-    }
205
-
206
-    /**
207
-     * Draws widget and return html code
208
-     * @return string
209
-     */
210
-    public function render()
211
-    {
212
-        return $this->renderer->render($this);
213
-    }
214
-
215
-    /**
216
-     * @return LengthAwarePaginator|Paginator
217
-     */
218
-    public function getPagination()
219
-    {
220
-        return $this->pagination;
221
-    }
222
-
223
-    /**
224
-     * @return GridViewRequest
225
-     */
226
-    public function getRequest()
227
-    {
228
-        return $this->request;
229
-    }
230
-
231
-    /**
232
-     * @return int
233
-     */
234
-    public function getId() : int
235
-    {
236
-        return $this->id;
237
-    }
238
-
239
-    /**
240
-     * @return string
241
-     */
242
-    public function compileTableHtmlOptions() : string
243
-    {
244
-        return GridViewHelper::htmlOptionsToString($this->tableHtmlOptions);
245
-    }
18
+	use Configurable;
19
+
20
+	/**
21
+	 * Counter for ids
22
+	 * @var int
23
+	 */
24
+	private static $counter = 0;
25
+
26
+	/**
27
+	 * Grid id (used for request handling, for
28
+	 * @var int
29
+	 */
30
+	private $id;
31
+
32
+	/**
33
+	 * DataProvider provides gridview with the data for representation
34
+	 * @var BaseDataProvider
35
+	 */
36
+	public $dataProvider;
37
+
38
+	/**
39
+	 * Columns config. You may specify array or GridColumn instance
40
+	 * @var BaseColumn[]
41
+	 */
42
+	public $columns = [];
43
+
44
+	/**
45
+	 * Common options for all columns, will be appended to all columns configs
46
+	 * @var array
47
+	 */
48
+	public $columnOptions = [
49
+		'class' => AttributeColumn::class,
50
+	];
51
+
52
+	/**
53
+	 * Renders the final UI
54
+	 * @var string|BaseRenderer
55
+	 */
56
+	public $renderer = DefaultRenderer::class;
57
+
58
+	/**
59
+	 * Allows to pass some options into renderer/customize rendered behavior
60
+	 * @var array
61
+	 */
62
+	public $rendererOptions = [];
63
+
64
+	/**
65
+	 * Controls amount of data per page
66
+	 * @var int
67
+	 */
68
+	public $rowsPerPage = 25;
69
+
70
+	/**
71
+	 * Allows to tune the <table> tag with html options
72
+	 * @var array
73
+	 */
74
+	public $tableHtmlOptions = [
75
+		'class' => 'table table-bordered gridview-table',
76
+	];
77
+
78
+	/**
79
+	 * Indicate if filters will be shown or not
80
+	 * @var bool
81
+	 */
82
+	public $showFilters = true;
83
+
84
+	/**
85
+	 * Flags allow to change standalone vue to. If false, GridView component should be included in your root Vue instance
86
+	 * @var bool
87
+	 */
88
+	public $standaloneVue = true;
89
+
90
+	/**
91
+	 * List of additinal params which'll be added to filter requests
92
+	 * @var array
93
+	 */
94
+	public $additionalRequestParams = [];
95
+
96
+	/**
97
+	 * @var Paginator
98
+	 */
99
+	protected $pagination;
100
+
101
+	/**
102
+	 * @var GridViewRequest
103
+	 */
104
+	protected $request;
105
+
106
+	/**
107
+	 * GridView constructor.
108
+	 * @param array $config
109
+	 * @throws Exceptions\GridViewConfigException
110
+	 */
111
+	public function __construct(array $config)
112
+	{
113
+		$this->id = self::$counter++;
114
+
115
+		$this->loadConfig($config);
116
+
117
+		/**
118
+		 * Making renderer
119
+		 */
120
+		if (!is_object($this->renderer)) {
121
+			$className = GridViewHelper::resolveAlias('renderer', $this->renderer);
122
+			$this->renderer = new $className(array_merge(
123
+				$this->rendererOptions, [
124
+					'gridView' => $this,
125
+				]
126
+			));
127
+		}
128
+
129
+		/**
130
+		 * Build columns from config
131
+		 */
132
+		$this->buildColumns();
133
+
134
+		$this->request = GridViewRequest::parse($this->id);
135
+		$this->request->perPage = $this->rowsPerPage;
136
+
137
+		$this->pagination = new LengthAwarePaginator(
138
+			$this->dataProvider->getData($this->request),
139
+			$this->dataProvider->getCount($this->request),
140
+			$this->rowsPerPage,
141
+			$this->request->page
142
+		);
143
+	}
144
+
145
+	/**
146
+	 * @return array
147
+	 */
148
+	protected function configTests(): array
149
+	{
150
+		return [
151
+			'dataProvider' => BaseDataProvider::class,
152
+			'columns' => 'array',
153
+			'renderer' => BaseRenderer::class,
154
+			'rowsPerPage' => 'int',
155
+			'tableHtmlOptions' => 'array',
156
+			'showFilters' => 'boolean',
157
+		];
158
+	}
159
+
160
+	/**
161
+	 * Build columns into objects
162
+	 */
163
+	protected function buildColumns()
164
+	{
165
+		foreach ($this->columns as $key => &$columnOptions) {
166
+
167
+			/**
168
+			 * In case of when column is already build
169
+			 */
170
+			if (is_object($columnOptions)) {
171
+				continue;
172
+			}
173
+
174
+			/**
175
+			 * When only attribute name/value passed
176
+			 */
177
+			if (is_string($columnOptions)) {
178
+				$columnOptions = [
179
+					'value' => $columnOptions,
180
+				];
181
+			}
182
+
183
+			if ($columnOptions instanceof Closure) {
184
+				$columnOptions = [
185
+					'class' => CallbackColumn::class,
186
+					'value' => $columnOptions,
187
+					'title' => GridViewHelper::columnTitle($key),
188
+				];
189
+			}
190
+
191
+			/**
192
+			 * Inline column declaration detector
193
+			 */
194
+			if (is_string($columnOptions['value']) && strpos($columnOptions['value'], 'view:') === 0) {
195
+				$columnOptions['class'] = 'view';
196
+				$columnOptions['value'] = str_replace('view:', '', $columnOptions['value']);
197
+			}
198
+
199
+			$columnOptions = array_merge($this->columnOptions, $columnOptions);
200
+
201
+			$className = GridViewHelper::resolveAlias('column', $columnOptions['class']);
202
+			$columnOptions = new $className($columnOptions);
203
+		}
204
+	}
205
+
206
+	/**
207
+	 * Draws widget and return html code
208
+	 * @return string
209
+	 */
210
+	public function render()
211
+	{
212
+		return $this->renderer->render($this);
213
+	}
214
+
215
+	/**
216
+	 * @return LengthAwarePaginator|Paginator
217
+	 */
218
+	public function getPagination()
219
+	{
220
+		return $this->pagination;
221
+	}
222
+
223
+	/**
224
+	 * @return GridViewRequest
225
+	 */
226
+	public function getRequest()
227
+	{
228
+		return $this->request;
229
+	}
230
+
231
+	/**
232
+	 * @return int
233
+	 */
234
+	public function getId() : int
235
+	{
236
+		return $this->id;
237
+	}
238
+
239
+	/**
240
+	 * @return string
241
+	 */
242
+	public function compileTableHtmlOptions() : string
243
+	{
244
+		return GridViewHelper::htmlOptionsToString($this->tableHtmlOptions);
245
+	}
246 246
 }
Please login to merge, or discard this patch.