@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * Builder constructor. |
36 | 36 | * @param Grid $grid |
37 | 37 | */ |
38 | - public function __construct( Grid $grid ) |
|
38 | + public function __construct(Grid $grid) |
|
39 | 39 | { |
40 | 40 | $this->grid = $grid; |
41 | 41 | } |
@@ -61,12 +61,12 @@ discard block |
||
61 | 61 | */ |
62 | 62 | protected function searchField() |
63 | 63 | { |
64 | - if( !$this->grid->hasTool( 'search' ) ) |
|
64 | + if (!$this->grid->hasTool('search')) |
|
65 | 65 | { |
66 | 66 | return null; |
67 | 67 | } |
68 | 68 | |
69 | - return ( new SearchField( $this->url( 'index' ) ) )->render(); |
|
69 | + return (new SearchField($this->url('index')))->render(); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function getTableColumns() |
76 | 76 | { |
77 | - $tableColumns = $this->grid()->getColumns()->map( function( Column $column ) |
|
77 | + $tableColumns = $this->grid()->getColumns()->map(function(Column $column) |
|
78 | 78 | { |
79 | - return $this->getColumnHeader( $column ); |
|
79 | + return $this->getColumnHeader($column); |
|
80 | 80 | } ); |
81 | 81 | |
82 | - $tableColumns->push( Html::th( Html::span( ' ' ) ) ); |
|
82 | + $tableColumns->push(Html::th(Html::span(' '))); |
|
83 | 83 | |
84 | 84 | return $tableColumns; |
85 | 85 | } |
@@ -88,37 +88,37 @@ discard block |
||
88 | 88 | * @param Column $column |
89 | 89 | * @return Element |
90 | 90 | */ |
91 | - protected function getColumnHeader( Column $column ) |
|
91 | + protected function getColumnHeader(Column $column) |
|
92 | 92 | { |
93 | - if( $column->isSortable() ) |
|
93 | + if ($column->isSortable()) |
|
94 | 94 | { |
95 | - $link = Html::link( $column->getLabel() ) |
|
96 | - ->addAttributes( [ |
|
97 | - 'href' => $this->getColumnOrderUrl( $column->getName() ) |
|
98 | - ] ); |
|
95 | + $link = Html::link($column->getLabel()) |
|
96 | + ->addAttributes([ |
|
97 | + 'href' => $this->getColumnOrderUrl($column->getName()) |
|
98 | + ]); |
|
99 | 99 | |
100 | - if( request( '_order_by' ) === $column->getName() ) |
|
100 | + if (request('_order_by') === $column->getName()) |
|
101 | 101 | { |
102 | - $link->append( $this->getOrderByIcon() ); |
|
102 | + $link->append($this->getOrderByIcon()); |
|
103 | 103 | } |
104 | 104 | |
105 | - return Html::th( $link ); |
|
105 | + return Html::th($link); |
|
106 | 106 | } |
107 | 107 | |
108 | - return Html::th( Html::span( $column->getLabel() ) ); |
|
108 | + return Html::th(Html::span($column->getLabel())); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | 112 | * @param $column |
113 | 113 | * @return string |
114 | 114 | */ |
115 | - protected function getColumnOrderUrl( $column ) |
|
115 | + protected function getColumnOrderUrl($column) |
|
116 | 116 | { |
117 | - return $this->grid->getModule()->url( 'index', array_filter( [ |
|
118 | - 'search' => request( 'search' ), |
|
117 | + return $this->grid->getModule()->url('index', array_filter([ |
|
118 | + 'search' => request('search'), |
|
119 | 119 | '_order_by' => $column, |
120 | - '_order' => request( '_order' ) === 'ASC' ? 'DESC' : 'ASC', |
|
121 | - ] ) ); |
|
120 | + '_order' => request('_order') === 'ASC' ? 'DESC' : 'ASC', |
|
121 | + ])); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | protected function getOrderByIcon() |
128 | 128 | { |
129 | 129 | return Html::i() |
130 | - ->addClass( 'fa' ) |
|
130 | + ->addClass('fa') |
|
131 | 131 | ->addClass( |
132 | - ( request( '_order' ) === 'DESC' ) |
|
132 | + (request('_order') === 'DESC') |
|
133 | 133 | ? 'fa-sort-up' |
134 | 134 | : 'fa-sort-down' |
135 | 135 | ); |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function tableHeader(): Element |
142 | 142 | { |
143 | - $header = Html::header( [ |
|
144 | - Html::h1( trans( 'arbory::resources.all_resources' ) ), |
|
145 | - ] ); |
|
143 | + $header = Html::header([ |
|
144 | + Html::h1(trans('arbory::resources.all_resources')), |
|
145 | + ]); |
|
146 | 146 | |
147 | - if( $this->grid->isPaginated() ) |
|
147 | + if ($this->grid->isPaginated()) |
|
148 | 148 | { |
149 | - $header->append( Html::span( trans( 'arbory::pagination.items_found', [ 'total' => $this->items->total() ] ) ) |
|
150 | - ->addClass( 'extras totals only-text' ) ); |
|
149 | + $header->append(Html::span(trans('arbory::pagination.items_found', [ 'total' => $this->items->total() ])) |
|
150 | + ->addClass('extras totals only-text')); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | return $header; |
@@ -158,22 +158,22 @@ discard block |
||
158 | 158 | */ |
159 | 159 | protected function table() |
160 | 160 | { |
161 | - return new Content( [ |
|
161 | + return new Content([ |
|
162 | 162 | $this->tableHeader(), |
163 | 163 | Html::div( |
164 | - Html::table( [ |
|
164 | + Html::table([ |
|
165 | 165 | Html::thead( |
166 | - Html::tr( $this->getTableColumns()->toArray() ) |
|
166 | + Html::tr($this->getTableColumns()->toArray()) |
|
167 | 167 | ), |
168 | 168 | Html::tbody( |
169 | - $this->grid()->getRows()->map( function( Row $row ) |
|
169 | + $this->grid()->getRows()->map(function(Row $row) |
|
170 | 170 | { |
171 | 171 | return $row->render(); |
172 | 172 | } )->toArray() |
173 | - )->addClass( 'tbody' ), |
|
174 | - ] )->addClass( 'table' ) |
|
175 | - )->addClass( 'body' ) |
|
176 | - ] ); |
|
173 | + )->addClass('tbody'), |
|
174 | + ])->addClass('table') |
|
175 | + )->addClass('body') |
|
176 | + ]); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -181,16 +181,16 @@ discard block |
||
181 | 181 | */ |
182 | 182 | protected function createButton() |
183 | 183 | { |
184 | - if( !$this->grid->hasTool( 'create' ) ) |
|
184 | + if (!$this->grid->hasTool('create')) |
|
185 | 185 | { |
186 | 186 | return null; |
187 | 187 | } |
188 | 188 | |
189 | 189 | return |
190 | - Link::create( $this->url( 'create' ) ) |
|
191 | - ->asButton( 'primary' ) |
|
192 | - ->withIcon( 'plus' ) |
|
193 | - ->title( trans( 'arbory::resources.create_new' ) ); |
|
190 | + Link::create($this->url('create')) |
|
191 | + ->asButton('primary') |
|
192 | + ->withIcon('plus') |
|
193 | + ->title(trans('arbory::resources.create_new')); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | trans('arbory::resources.export') |
207 | 207 | )->addClass('title'), |
208 | 208 | Html::div( |
209 | - Link::create($this->url('export', $parameters + ['as' => 'xls'])) |
|
209 | + Link::create($this->url('export', $parameters + [ 'as' => 'xls' ])) |
|
210 | 210 | ->title('XLS') |
211 | 211 | )->addClass('options'), |
212 | 212 | Html::div( |
213 | - Link::create($this->url('export', $parameters + ['as' => 'json'])) |
|
213 | + Link::create($this->url('export', $parameters + [ 'as' => 'json' ])) |
|
214 | 214 | ->title('JSON') |
215 | 215 | )->addClass('options') |
216 | 216 | ])->addClass('export'); |
@@ -223,15 +223,15 @@ discard block |
||
223 | 223 | { |
224 | 224 | $tools = new Tools(); |
225 | 225 | |
226 | - $tools->getBlock( 'secondary' )->push( $this->exportOptions() ); |
|
227 | - $tools->getBlock( 'primary' )->push( $this->createButton() ); |
|
226 | + $tools->getBlock('secondary')->push($this->exportOptions()); |
|
227 | + $tools->getBlock('primary')->push($this->createButton()); |
|
228 | 228 | |
229 | - $this->addCustomToolsToFooterToolset( $tools ); |
|
229 | + $this->addCustomToolsToFooterToolset($tools); |
|
230 | 230 | |
231 | - if ( $this->grid->isPaginated() && $this->items->hasPages() ) |
|
231 | + if ($this->grid->isPaginated() && $this->items->hasPages()) |
|
232 | 232 | { |
233 | - $pagination = ( new Pagination( $this->items ) )->render(); |
|
234 | - $tools->getBlock( $pagination->attributes()->get( 'class' ) )->push( $pagination->content() ); |
|
233 | + $pagination = (new Pagination($this->items))->render(); |
|
234 | + $tools->getBlock($pagination->attributes()->get('class'))->push($pagination->content()); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | return $tools; |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | * @param Tools $toolset |
242 | 242 | * @return void |
243 | 243 | */ |
244 | - protected function addCustomToolsToFooterToolset( Tools $toolset ) |
|
244 | + protected function addCustomToolsToFooterToolset(Tools $toolset) |
|
245 | 245 | { |
246 | - foreach( $this->grid->getTools() as list( $tool, $location ) ) |
|
246 | + foreach ($this->grid->getTools() as list($tool, $location)) |
|
247 | 247 | { |
248 | - $toolset->getBlock( $location )->push( $tool->render() ); |
|
248 | + $toolset->getBlock($location)->push($tool->render()); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | */ |
255 | 255 | protected function footer() |
256 | 256 | { |
257 | - $footer = new Footer( 'main' ); |
|
257 | + $footer = new Footer('main'); |
|
258 | 258 | |
259 | - if ( $this->grid->hasTools() ) |
|
259 | + if ($this->grid->hasTools()) |
|
260 | 260 | { |
261 | - $footer->getRows()->prepend( $this->footerTools() ); |
|
261 | + $footer->getRows()->prepend($this->footerTools()); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | return $footer->render(); |
@@ -269,28 +269,28 @@ discard block |
||
269 | 269 | * @param array $parameters |
270 | 270 | * @return string |
271 | 271 | */ |
272 | - public function url( $route, $parameters = [] ) |
|
272 | + public function url($route, $parameters = [ ]) |
|
273 | 273 | { |
274 | - return $this->grid()->getModule()->url( $route, $parameters ); |
|
274 | + return $this->grid()->getModule()->url($route, $parameters); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
278 | 278 | * @param Collection|Paginator $items |
279 | 279 | * @return Content |
280 | 280 | */ |
281 | - public function render( $items ) |
|
281 | + public function render($items) |
|
282 | 282 | { |
283 | 283 | $this->items = $items; |
284 | 284 | |
285 | - return new Content( [ |
|
286 | - Html::header( [ |
|
285 | + return new Content([ |
|
286 | + Html::header([ |
|
287 | 287 | $this->breadcrumbs(), |
288 | 288 | $this->searchField(), |
289 | - ] ), |
|
290 | - Html::section( [ |
|
289 | + ]), |
|
290 | + Html::section([ |
|
291 | 291 | $this->table(), |
292 | 292 | $this->footer(), |
293 | - ] ) |
|
294 | - ] ); |
|
293 | + ]) |
|
294 | + ]); |
|
295 | 295 | } |
296 | 296 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | */ |
28 | 28 | public function render() |
29 | 29 | { |
30 | - $items = $this->grid->getRows()->map(function (Row $row) { |
|
30 | + $items = $this->grid->getRows()->map(function(Row $row) { |
|
31 | 31 | return $row->toArray(); |
32 | 32 | }); |
33 | 33 |
@@ -46,7 +46,7 @@ |
||
46 | 46 | */ |
47 | 47 | public function __toString() |
48 | 48 | { |
49 | - return (string)$this->render(); |
|
49 | + return (string) $this->render(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param Grid $grid |
32 | 32 | * @param Model $model |
33 | 33 | */ |
34 | - public function __construct( Grid $grid, Model $model ) |
|
34 | + public function __construct(Grid $grid, Model $model) |
|
35 | 35 | { |
36 | 36 | $this->grid = $grid; |
37 | 37 | $this->model = $model; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getCells(): Collection |
52 | 52 | { |
53 | - return $this->grid->getColumns()->map(function (Column $column) { |
|
53 | + return $this->grid->getColumns()->map(function(Column $column) { |
|
54 | 54 | return new Cell($column, $this, $this->model); |
55 | 55 | }); |
56 | 56 | } |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | $cells->push( |
66 | 66 | Html::td( |
67 | 67 | Toolbox::create( |
68 | - $this->grid->getModule()->url( 'dialog', [ 'dialog' => 'toolbox', 'id' => $this->model->getKey() ] ) |
|
68 | + $this->grid->getModule()->url('dialog', [ 'dialog' => 'toolbox', 'id' => $this->model->getKey() ]) |
|
69 | 69 | )->render() |
70 | - )->addClass( 'only-icon toolbox-cell' ) |
|
70 | + )->addClass('only-icon toolbox-cell') |
|
71 | 71 | ); |
72 | 72 | |
73 | - return Html::tr( $cells->toArray() ) |
|
74 | - ->addAttributes( [ |
|
73 | + return Html::tr($cells->toArray()) |
|
74 | + ->addAttributes([ |
|
75 | 75 | 'data-id' => $this->model->getKey(), |
76 | - ] ) |
|
77 | - ->addClass( 'row' ); |
|
76 | + ]) |
|
77 | + ->addClass('row'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function toArray(): array |
84 | 84 | { |
85 | - return $this->getCells()->mapWithKeys( function( Cell $cell ) { |
|
86 | - return [ $cell->getColumn()->getName() => strip_tags( $cell ) ]; |
|
85 | + return $this->getCells()->mapWithKeys(function(Cell $cell) { |
|
86 | + return [ $cell->getColumn()->getName() => strip_tags($cell) ]; |
|
87 | 87 | } )->toArray(); |
88 | 88 | } |
89 | 89 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * @var array |
50 | 50 | */ |
51 | - protected $tools = []; |
|
51 | + protected $tools = [ ]; |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @var Collection|null |
@@ -74,15 +74,15 @@ discard block |
||
74 | 74 | * @param Model $model |
75 | 75 | * @param Closure $layout |
76 | 76 | */ |
77 | - public function __construct( Model $model, Closure $layout ) |
|
77 | + public function __construct(Model $model, Closure $layout) |
|
78 | 78 | { |
79 | 79 | $this->model = $model; |
80 | 80 | $this->columns = new Collection(); |
81 | 81 | $this->rows = new Collection(); |
82 | - $this->renderer = new Builder( $this ); |
|
82 | + $this->renderer = new Builder($this); |
|
83 | 83 | |
84 | 84 | $this->setupFilter(); |
85 | - $this->setupLayout( $layout ); |
|
85 | + $this->setupLayout($layout); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * @param Closure $layout |
98 | 98 | */ |
99 | - protected function setupLayout( Closure $layout ): void |
|
99 | + protected function setupLayout(Closure $layout): void |
|
100 | 100 | { |
101 | 101 | $layout($this); |
102 | 102 | } |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function setupFilter() |
108 | 108 | { |
109 | - $this->setFilter( new Filter( $this->model ) ); |
|
109 | + $this->setFilter(new Filter($this->model)); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | 113 | * @param FilterInterface $filter |
114 | 114 | * @return Grid |
115 | 115 | */ |
116 | - public function setFilter( FilterInterface $filter ) |
|
116 | + public function setFilter(FilterInterface $filter) |
|
117 | 117 | { |
118 | 118 | $this->filter = $filter; |
119 | 119 | |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | * @param string|null $side |
134 | 134 | * @return void |
135 | 135 | */ |
136 | - public function addTool( Renderable $tool, string $side = null ) |
|
136 | + public function addTool(Renderable $tool, string $side = null) |
|
137 | 137 | { |
138 | - $this->tools[] = [ $tool, $side ?: self::FOOTER_SIDE_SECONDARY ]; |
|
138 | + $this->tools[ ] = [ $tool, $side ?: self::FOOTER_SIDE_SECONDARY ]; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @param string[] $tools |
151 | 151 | * @return Grid |
152 | 152 | */ |
153 | - public function tools( array $tools ) |
|
153 | + public function tools(array $tools) |
|
154 | 154 | { |
155 | 155 | $this->enabledDefaultTools = $tools; |
156 | 156 | |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | * @param array|Collection $items |
162 | 162 | * @return Grid |
163 | 163 | */ |
164 | - public function items( $items ) |
|
164 | + public function items($items) |
|
165 | 165 | { |
166 | - if( is_array( $items ) ) |
|
166 | + if (is_array($items)) |
|
167 | 167 | { |
168 | - $items = new Collection( $items ); |
|
168 | + $items = new Collection($items); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | $this->items = $items; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @param bool $paginate |
178 | 178 | * @return Grid |
179 | 179 | */ |
180 | - public function paginate( bool $paginate = true ) |
|
180 | + public function paginate(bool $paginate = true) |
|
181 | 181 | { |
182 | 182 | $this->paginated = $paginate; |
183 | 183 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | /** |
188 | 188 | * @param $renderer |
189 | 189 | */ |
190 | - public function setRenderer( $renderer ) |
|
190 | + public function setRenderer($renderer) |
|
191 | 191 | { |
192 | 192 | $this->renderer = $renderer; |
193 | 193 | } |
@@ -213,19 +213,19 @@ discard block |
||
213 | 213 | * @param null $label |
214 | 214 | * @return Column |
215 | 215 | */ |
216 | - public function column( $name = null, $label = null ) |
|
216 | + public function column($name = null, $label = null) |
|
217 | 217 | { |
218 | - $column = new Column( $name, $label ); |
|
219 | - $column->setGrid( $this ); |
|
218 | + $column = new Column($name, $label); |
|
219 | + $column->setGrid($this); |
|
220 | 220 | |
221 | - $this->columns->push( $column ); |
|
221 | + $this->columns->push($column); |
|
222 | 222 | |
223 | - if( strpos( $name, '.' ) !== false ) |
|
223 | + if (strpos($name, '.') !== false) |
|
224 | 224 | { |
225 | - list( $relationName, $relationColumn ) = explode( '.', $name ); |
|
225 | + list($relationName, $relationColumn) = explode('.', $name); |
|
226 | 226 | |
227 | - $this->filter->withRelation( $relationName ); |
|
228 | - $column->setRelation( $relationName, $relationColumn ); |
|
227 | + $this->filter->withRelation($relationName); |
|
228 | + $column->setRelation($relationName, $relationColumn); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | return $column; |
@@ -234,25 +234,25 @@ discard block |
||
234 | 234 | /** |
235 | 235 | * @param Collection|LengthAwarePaginator $items |
236 | 236 | */ |
237 | - protected function buildRows( $items ) |
|
237 | + protected function buildRows($items) |
|
238 | 238 | { |
239 | - if( $items instanceof LengthAwarePaginator ) |
|
239 | + if ($items instanceof LengthAwarePaginator) |
|
240 | 240 | { |
241 | - $items = new Collection( $items->items() ); |
|
241 | + $items = new Collection($items->items()); |
|
242 | 242 | } |
243 | 243 | |
244 | - $this->rows = $items->map( function( $model ) |
|
244 | + $this->rows = $items->map(function($model) |
|
245 | 245 | { |
246 | - return new Row( $this, $model ); |
|
246 | + return new Row($this, $model); |
|
247 | 247 | } ); |
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
251 | 251 | * @param Closure $callback |
252 | 252 | */ |
253 | - public function filter( Closure $callback ) |
|
253 | + public function filter(Closure $callback) |
|
254 | 254 | { |
255 | - call_user_func( $callback, $this->filter ); |
|
255 | + call_user_func($callback, $this->filter); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -260,12 +260,12 @@ discard block |
||
260 | 260 | */ |
261 | 261 | protected function fetchData() |
262 | 262 | { |
263 | - if( method_exists( $this->filter, 'setPaginated' ) ) |
|
263 | + if (method_exists($this->filter, 'setPaginated')) |
|
264 | 264 | { |
265 | - $this->filter->setPaginated( $this->paginated ); |
|
265 | + $this->filter->setPaginated($this->paginated); |
|
266 | 266 | } |
267 | 267 | |
268 | - return $this->filter->execute( $this->getColumns() ); |
|
268 | + return $this->filter->execute($this->getColumns()); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | $result = $this->fetchData(); |
277 | 277 | $items = $this->items ?? $result; |
278 | 278 | |
279 | - $this->buildRows( $items ); |
|
279 | + $this->buildRows($items); |
|
280 | 280 | |
281 | - return $this->renderer->render( $items ); |
|
281 | + return $this->renderer->render($items); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -302,16 +302,16 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public function hasTools(): bool |
304 | 304 | { |
305 | - return !empty( $this->enabledDefaultTools ); |
|
305 | + return !empty($this->enabledDefaultTools); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | 309 | * @param string $tool |
310 | 310 | * @return bool |
311 | 311 | */ |
312 | - public function hasTool( string $tool ): bool |
|
312 | + public function hasTool(string $tool): bool |
|
313 | 313 | { |
314 | - return in_array( $tool, $this->enabledDefaultTools, false ); |
|
314 | + return in_array($tool, $this->enabledDefaultTools, false); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -321,16 +321,16 @@ discard block |
||
321 | 321 | { |
322 | 322 | $items = $this->fetchData(); |
323 | 323 | |
324 | - $this->buildRows( $items ); |
|
324 | + $this->buildRows($items); |
|
325 | 325 | |
326 | - $columns = $this->columns->map( function( Column $column ) |
|
326 | + $columns = $this->columns->map(function(Column $column) |
|
327 | 327 | { |
328 | 328 | return (string) $column; |
329 | 329 | } )->toArray(); |
330 | 330 | |
331 | - return $this->rows->map( function( Row $row ) use ( $columns ) |
|
331 | + return $this->rows->map(function(Row $row) use ($columns) |
|
332 | 332 | { |
333 | - return array_combine( $columns, $row->toArray() ); |
|
333 | + return array_combine($columns, $row->toArray()); |
|
334 | 334 | } )->toArray(); |
335 | 335 | } |
336 | 336 | } |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected function module() |
40 | 40 | { |
41 | - if( $this->module === null ) |
|
41 | + if ($this->module === null) |
|
42 | 42 | { |
43 | - $this->module =\Admin::modules()->findModuleByControllerClass( get_class( $this ) ); |
|
43 | + $this->module = \Admin::modules()->findModuleByControllerClass(get_class($this)); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | return $this->module; |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * @param Model $model |
51 | 51 | * @return Form |
52 | 52 | */ |
53 | - protected function form( Model $model ) |
|
53 | + protected function form(Model $model) |
|
54 | 54 | { |
55 | - return $this->module()->form( $model, function ( Form $form ) { return $form; } ); |
|
55 | + return $this->module()->form($model, function(Form $form) { return $form; } ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function grid() |
62 | 62 | { |
63 | - return $this->module()->grid( $this->resource(), function ( Grid $grid ) { return $grid; } ); |
|
63 | + return $this->module()->grid($this->resource(), function(Grid $grid) { return $grid; } ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function index() |
70 | 70 | { |
71 | - $layout = new Layout( function ( Layout $layout ) |
|
71 | + $layout = new Layout(function(Layout $layout) |
|
72 | 72 | { |
73 | - $layout->body( $this->grid( $this->resource() ) ); |
|
73 | + $layout->body($this->grid($this->resource())); |
|
74 | 74 | } ); |
75 | 75 | |
76 | - $layout->bodyClass( 'controller-' . str_slug( $this->module()->name() ) . ' view-index' ); |
|
76 | + $layout->bodyClass('controller-' . str_slug($this->module()->name()) . ' view-index'); |
|
77 | 77 | |
78 | 78 | return $layout; |
79 | 79 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param $resourceId |
83 | 83 | * @return \Illuminate\Http\RedirectResponse |
84 | 84 | */ |
85 | - public function show( $resourceId ) |
|
85 | + public function show($resourceId) |
|
86 | 86 | { |
87 | - return redirect( $this->module()->url( 'edit', $resourceId ) ); |
|
87 | + return redirect($this->module()->url('edit', $resourceId)); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function create() |
94 | 94 | { |
95 | - $layout = new Layout( function ( Layout $layout ) |
|
95 | + $layout = new Layout(function(Layout $layout) |
|
96 | 96 | { |
97 | - $layout->body( $this->form( $this->resource() ) ); |
|
97 | + $layout->body($this->form($this->resource())); |
|
98 | 98 | } ); |
99 | 99 | |
100 | - $layout->bodyClass( 'controller-' . str_slug( $this->module()->name() ) . ' view-edit' ); |
|
100 | + $layout->bodyClass('controller-' . str_slug($this->module()->name()) . ' view-edit'); |
|
101 | 101 | |
102 | 102 | return $layout; |
103 | 103 | } |
@@ -106,38 +106,38 @@ discard block |
||
106 | 106 | * @param Request $request |
107 | 107 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
108 | 108 | */ |
109 | - public function store( Request $request ) |
|
109 | + public function store(Request $request) |
|
110 | 110 | { |
111 | - $form = $this->form( $this->resource() ); |
|
111 | + $form = $this->form($this->resource()); |
|
112 | 112 | |
113 | - $request->request->add( [ 'fields' => $form->fields() ] ); |
|
113 | + $request->request->add([ 'fields' => $form->fields() ]); |
|
114 | 114 | |
115 | 115 | $form->validate(); |
116 | 116 | |
117 | - if( $request->ajax() ) |
|
117 | + if ($request->ajax()) |
|
118 | 118 | { |
119 | - return response()->json( [ 'ok' ] ); |
|
119 | + return response()->json([ 'ok' ]); |
|
120 | 120 | } |
121 | 121 | |
122 | - $form->store( $request ); |
|
122 | + $form->store($request); |
|
123 | 123 | |
124 | - return $this->getAfterEditResponse( $request ); |
|
124 | + return $this->getAfterEditResponse($request); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * @param $resourceId |
129 | 129 | * @return Layout |
130 | 130 | */ |
131 | - public function edit( $resourceId ) |
|
131 | + public function edit($resourceId) |
|
132 | 132 | { |
133 | - $resource = $this->findOrNew( $resourceId ); |
|
133 | + $resource = $this->findOrNew($resourceId); |
|
134 | 134 | |
135 | - $layout = new Layout( function ( Layout $layout ) use ( $resource ) |
|
135 | + $layout = new Layout(function(Layout $layout) use ($resource) |
|
136 | 136 | { |
137 | - $layout->body( $this->form( $resource ) ); |
|
137 | + $layout->body($this->form($resource)); |
|
138 | 138 | } ); |
139 | 139 | |
140 | - $layout->bodyClass( 'controller-' . str_slug( $this->module()->name() ) . ' view-edit' ); |
|
140 | + $layout->bodyClass('controller-' . str_slug($this->module()->name()) . ' view-edit'); |
|
141 | 141 | |
142 | 142 | return $layout; |
143 | 143 | } |
@@ -147,36 +147,36 @@ discard block |
||
147 | 147 | * @param $resourceId |
148 | 148 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
149 | 149 | */ |
150 | - public function update( Request $request, $resourceId ) |
|
150 | + public function update(Request $request, $resourceId) |
|
151 | 151 | { |
152 | - $resource = $this->findOrNew( $resourceId ); |
|
153 | - $form = $this->form( $resource ); |
|
152 | + $resource = $this->findOrNew($resourceId); |
|
153 | + $form = $this->form($resource); |
|
154 | 154 | |
155 | - $request->request->add( [ 'fields' => $form->fields() ] ); |
|
155 | + $request->request->add([ 'fields' => $form->fields() ]); |
|
156 | 156 | |
157 | 157 | $form->validate(); |
158 | 158 | |
159 | - if( $request->ajax() ) |
|
159 | + if ($request->ajax()) |
|
160 | 160 | { |
161 | - return response()->json( [ 'ok' ] ); |
|
161 | + return response()->json([ 'ok' ]); |
|
162 | 162 | } |
163 | 163 | |
164 | - $form->update( $request ); |
|
164 | + $form->update($request); |
|
165 | 165 | |
166 | - return $this->getAfterEditResponse( $request ); |
|
166 | + return $this->getAfterEditResponse($request); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | 170 | * @param $resourceId |
171 | 171 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
172 | 172 | */ |
173 | - public function destroy( $resourceId ) |
|
173 | + public function destroy($resourceId) |
|
174 | 174 | { |
175 | - $resource = $this->resource()->findOrFail( $resourceId ); |
|
175 | + $resource = $this->resource()->findOrFail($resourceId); |
|
176 | 176 | |
177 | - $this->form( $resource )->destroy(); |
|
177 | + $this->form($resource)->destroy(); |
|
178 | 178 | |
179 | - return redirect( $this->module()->url( 'index' ) ); |
|
179 | + return redirect($this->module()->url('index')); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -184,18 +184,18 @@ discard block |
||
184 | 184 | * @param $name |
185 | 185 | * @return mixed |
186 | 186 | */ |
187 | - public function dialog( Request $request, $name ) |
|
187 | + public function dialog(Request $request, $name) |
|
188 | 188 | { |
189 | - $method = camel_case( $name ) . 'Dialog'; |
|
189 | + $method = camel_case($name) . 'Dialog'; |
|
190 | 190 | |
191 | - if( !$name || !method_exists( $this, $method ) ) |
|
191 | + if (!$name || !method_exists($this, $method)) |
|
192 | 192 | { |
193 | - app()->abort( Response::HTTP_NOT_FOUND ); |
|
193 | + app()->abort(Response::HTTP_NOT_FOUND); |
|
194 | 194 | |
195 | 195 | return null; |
196 | 196 | } |
197 | 197 | |
198 | - return $this->{$method}( $request ); |
|
198 | + return $this->{$method}($request); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | |
@@ -228,13 +228,13 @@ discard block |
||
228 | 228 | * @param Request $request |
229 | 229 | * @return string |
230 | 230 | */ |
231 | - protected function toolboxDialog( Request $request ) |
|
231 | + protected function toolboxDialog(Request $request) |
|
232 | 232 | { |
233 | - $node = $this->findOrNew( $request->get( 'id' ) ); |
|
233 | + $node = $this->findOrNew($request->get('id')); |
|
234 | 234 | |
235 | - $toolbox = new ToolboxMenu( $node ); |
|
235 | + $toolbox = new ToolboxMenu($node); |
|
236 | 236 | |
237 | - $this->toolbox( $toolbox ); |
|
237 | + $this->toolbox($toolbox); |
|
238 | 238 | |
239 | 239 | return $toolbox->render(); |
240 | 240 | } |
@@ -242,28 +242,28 @@ discard block |
||
242 | 242 | /** |
243 | 243 | * @param \Arbory\Base\Admin\Tools\ToolboxMenu $tools |
244 | 244 | */ |
245 | - protected function toolbox( ToolboxMenu $tools ) |
|
245 | + protected function toolbox(ToolboxMenu $tools) |
|
246 | 246 | { |
247 | 247 | $model = $tools->model(); |
248 | 248 | |
249 | - $tools->add( 'edit', $this->url( 'edit', $model->getKey() ) ); |
|
250 | - $tools->add( 'delete', $this->url( 'dialog', [ 'dialog' => 'confirm_delete', 'id' => $model->getKey() ] ) )->dialog()->danger(); |
|
249 | + $tools->add('edit', $this->url('edit', $model->getKey())); |
|
250 | + $tools->add('delete', $this->url('dialog', [ 'dialog' => 'confirm_delete', 'id' => $model->getKey() ]))->dialog()->danger(); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
254 | 254 | * @param Request $request |
255 | 255 | * @return \Illuminate\View\View |
256 | 256 | */ |
257 | - protected function confirmDeleteDialog( Request $request ) |
|
257 | + protected function confirmDeleteDialog(Request $request) |
|
258 | 258 | { |
259 | - $resourceId = $request->get( 'id' ); |
|
260 | - $model = $this->resource()->find( $resourceId ); |
|
259 | + $resourceId = $request->get('id'); |
|
260 | + $model = $this->resource()->find($resourceId); |
|
261 | 261 | |
262 | - return view( 'arbory::dialogs.confirm_delete', [ |
|
263 | - 'form_target' => $this->url( 'destroy', [ $resourceId ] ), |
|
264 | - 'list_url' => $this->url( 'index' ), |
|
262 | + return view('arbory::dialogs.confirm_delete', [ |
|
263 | + 'form_target' => $this->url('destroy', [ $resourceId ]), |
|
264 | + 'list_url' => $this->url('index'), |
|
265 | 265 | 'object_name' => (string) $model, |
266 | - ] ); |
|
266 | + ]); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -271,18 +271,18 @@ discard block |
||
271 | 271 | * @param $name |
272 | 272 | * @return null |
273 | 273 | */ |
274 | - public function api( Request $request, $name ) |
|
274 | + public function api(Request $request, $name) |
|
275 | 275 | { |
276 | - $method = camel_case( $name ) . 'Api'; |
|
276 | + $method = camel_case($name) . 'Api'; |
|
277 | 277 | |
278 | - if( !$name || !method_exists( $this, $method ) ) |
|
278 | + if (!$name || !method_exists($this, $method)) |
|
279 | 279 | { |
280 | - app()->abort( Response::HTTP_NOT_FOUND ); |
|
280 | + app()->abort(Response::HTTP_NOT_FOUND); |
|
281 | 281 | |
282 | 282 | return null; |
283 | 283 | } |
284 | 284 | |
285 | - return $this->{$method}( $request ); |
|
285 | + return $this->{$method}($request); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -290,29 +290,29 @@ discard block |
||
290 | 290 | * @param array $parameters |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - public function url( $route, $parameters = [] ) |
|
293 | + public function url($route, $parameters = [ ]) |
|
294 | 294 | { |
295 | - return $this->module()->url( $route, $parameters ); |
|
295 | + return $this->module()->url($route, $parameters); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
299 | 299 | * @param mixed $resourceId |
300 | 300 | * @return Model |
301 | 301 | */ |
302 | - protected function findOrNew( $resourceId ): Model |
|
302 | + protected function findOrNew($resourceId): Model |
|
303 | 303 | { |
304 | 304 | /** |
305 | 305 | * @var Model $resource |
306 | 306 | */ |
307 | 307 | $resource = $this->resource(); |
308 | 308 | |
309 | - if( method_exists( $resource, 'bootSoftDeletes' ) ) |
|
309 | + if (method_exists($resource, 'bootSoftDeletes')) |
|
310 | 310 | { |
311 | 311 | $resource = $resource->withTrashed(); |
312 | 312 | } |
313 | 313 | |
314 | - $resource = $resource->findOrNew( $resourceId ); |
|
315 | - $resource->setAttribute( $resource->getKeyName(), $resourceId ); |
|
314 | + $resource = $resource->findOrNew($resourceId); |
|
315 | + $resource->setAttribute($resource->getKeyName(), $resourceId); |
|
316 | 316 | |
317 | 317 | return $resource; |
318 | 318 | } |
@@ -321,13 +321,13 @@ discard block |
||
321 | 321 | * @param Request $request |
322 | 322 | * @return array|Request|string |
323 | 323 | */ |
324 | - public function slugGeneratorApi( Request $request ) |
|
324 | + public function slugGeneratorApi(Request $request) |
|
325 | 325 | { |
326 | 326 | /** @var \Illuminate\Database\Query\Builder $query */ |
327 | - $slug = str_slug( $request->input( 'from' ) ); |
|
328 | - $column = $request->input( 'column_name' ); |
|
327 | + $slug = str_slug($request->input('from')); |
|
328 | + $column = $request->input('column_name'); |
|
329 | 329 | |
330 | - $query = \DB::table( $request->input( 'model_table' ) )->where( $column, $slug ); |
|
330 | + $query = \DB::table($request->input('model_table'))->where($column, $slug); |
|
331 | 331 | |
332 | 332 | if ($locale = $request->input('locale')) { |
333 | 333 | $query->where('locale', $locale); |
@@ -337,9 +337,9 @@ discard block |
||
337 | 337 | $query->where('id', '<>', $objectId); |
338 | 338 | } |
339 | 339 | |
340 | - if( $column && $query->exists() ) |
|
340 | + if ($column && $query->exists()) |
|
341 | 341 | { |
342 | - $slug .= '-' . random_int( 0, 9999 ); |
|
342 | + $slug .= '-' . random_int(0, 9999); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | return $slug; |
@@ -349,8 +349,8 @@ discard block |
||
349 | 349 | * @param Request $request |
350 | 350 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
351 | 351 | */ |
352 | - protected function getAfterEditResponse( Request $request ) |
|
352 | + protected function getAfterEditResponse(Request $request) |
|
353 | 353 | { |
354 | - return redirect( $request->has( 'save_and_return' ) ? $this->module()->url( 'index' ) : $request->url() ); |
|
354 | + return redirect($request->has('save_and_return') ? $this->module()->url('index') : $request->url()); |
|
355 | 355 | } |
356 | 356 | } |