Skip to content

Commit c5aa9f3

Browse files
committed
Formatting
1 parent 0263b64 commit c5aa9f3

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/Controllers/ModelController.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ private function save($model, Request $request)
2424
$sync = [];
2525
$morph = [];
2626
$row = [];
27-
foreach($this->columns() as $columnId => $column) {
27+
foreach ($this->columns() as $columnId => $column) {
2828
if (isset($column['type']) && $column['type'] == 'pivot') {
2929
$sync[$column['model']] = $request[$columnId];
3030
if (!empty($column['morph'])) {
3131
$morph[$column['model']] = $column['morph'];
3232
}
3333
} elseif (isset($column['type']) && $column['type'] == 'rows') {
3434
$row[$column['model']]['self'] = $column['self'];
35-
foreach($column['columns'] as $columnId2 => $opt) {
35+
foreach ($column['columns'] as $columnId2 => $opt) {
3636
$r = $request[$columnId . '_' . $columnId2];
3737
array_shift($r);
38-
foreach($r as $key => $value) {
38+
foreach ($r as $key => $value) {
3939
$row[$column['model']][$key][$columnId2] = $value;
4040
}
4141
}
@@ -67,22 +67,22 @@ private function save($model, Request $request)
6767

6868
$model->save();
6969

70-
foreach($row as $foreign => $data) {
70+
foreach ($row as $foreign => $data) {
7171
$fm = new $foreign;
7272
$self = $data['self'];
7373
unset($data['self']);
7474
$fm::where($self, $model->id)->delete();
75-
foreach($data as $row) {
75+
foreach ($data as $row) {
7676
$fm = new $foreign;
7777
$fm->$self = $model->id;
78-
foreach($row as $column => $value) {
78+
foreach ($row as $column => $value) {
7979
$fm->$column = $value;
8080
}
8181
$fm->save();
8282
}
8383
}
8484

85-
foreach($sync as $foreign => $values) {
85+
foreach ($sync as $foreign => $values) {
8686
if (isset($morph[$foreign])) {
8787
$model->morphToMany($foreign, $morph[$foreign])->sync($values);
8888
} else {
@@ -91,7 +91,7 @@ private function save($model, Request $request)
9191
}
9292

9393
return [
94-
'active' => $this->module('active') ? $model[$this->module('active')]==true : true,
94+
'active' => $this->module('active') ? $model[$this->module('active')] == true : true,
9595
'id' => $model->id,
9696
'listview' => $this->listviewData(request()->__modelRoot),
9797
'li' => $this->listviewRow($model),
@@ -115,7 +115,7 @@ public function store($slug, Request $request)
115115
public function filter_pivot($columns)
116116
{
117117
$filtered = $columns;
118-
foreach($filtered as $columnId => $column) {
118+
foreach ($filtered as $columnId => $column) {
119119
if ($column['type'] == 'pivot') {
120120
unset($filtered[$columnId]);
121121
}
@@ -134,19 +134,19 @@ public function show($slug, $id)
134134
$this->checkSlug($slug, 'read');
135135
// Get the original values and not the altered values from model accessors
136136
$row = @$this->model()::findOrFail($id, $this->filter_pivot($this->columns()))->getOriginal();
137-
foreach($this->columns() as $columnId => $column) {
137+
foreach ($this->columns() as $columnId => $column) {
138138
// Output array columns with JSON_PRETTY_PRINT
139139
if ($column['type'] == 'array') {
140140
$row[$columnId] = json_encode(json_decode($row[$columnId]), JSON_PRETTY_PRINT);
141141
}
142142
// If column type is rows return those rows
143143
if ($column['type'] == 'rows') {
144-
unset($row['"'.$columnId.'"']);
144+
unset($row['"' . $columnId . '"']);
145145
$row[$columnId] = $this->model()::findOrFail($id)->hasMany($column['model'])->get(array_keys($column['columns']))->toArray();
146146
}
147147
// If column type is pivot return matching ids
148148
if ($column['type'] == 'pivot') {
149-
unset($row['"'.$columnId.'"']);
149+
unset($row['"' . $columnId . '"']);
150150
$ids = [];
151151
if (!empty($column['morph'])) {
152152
$pivotData = $this->model()::findOrFail($id)->morphToMany($column['model'], $column['morph'])->get();
@@ -156,7 +156,7 @@ public function show($slug, $id)
156156
foreach ($pivotData as $pivot) {
157157
$ids[] = $pivot->id;
158158
}
159-
$row['_pivot.'.$columnId] = implode(',', $ids);
159+
$row['_pivot.' . $columnId] = implode(',', $ids);
160160
}
161161
// If column is a password (and maybe even hidden) return it with a 'masked' values of ********
162162
if (isset($column['type']) && $column['type'] == 'password' && $row[$columnId]) {
@@ -210,21 +210,22 @@ public function destroy($slug, $id)
210210
}
211211

212212
// This method is called after nestedSortable is done and parent changed
213-
public function changeParent($slug, Request $request, $id) {
213+
public function changeParent($slug, Request $request, $id)
214+
{
214215
$this->checkSlug($slug, 'update');
215216
$row = $this->model()::findOrFail($id);
216217

217218
// Get the parent and oldparent from Input, make null if needed
218-
$parent=$request->input('parent');
219-
$oldparent=$request->input('oldparent');
220-
if ($oldparent<1) $oldparent=null;
221-
if ($parent<1) $parent=null;
219+
$parent = $request->input('parent');
220+
$oldparent = $request->input('oldparent');
221+
if ($oldparent < 1) $oldparent = null;
222+
if ($parent < 1) $parent = null;
222223

223224
// Check if oldparent matches the actual id for safety
224-
if ($row->parent != $oldparent) die('Invalid oldparent '.$oldparent);
225+
if ($row->parent != $oldparent) die('Invalid oldparent ' . $oldparent);
225226

226227
// Save the new parent
227-
$row->parent=$parent;
228+
$row->parent = $parent;
228229
$row->save();
229230

230231
// Now sort the items too
@@ -237,10 +238,10 @@ public function sort($slug, $parent, Request $request)
237238
$this->checkSlug($slug, 'update');
238239
$ids = $request->input('ids');
239240
// Get the row for each id and update the sort
240-
if ($parent<1) $parent = null;
241+
if ($parent < 1) $parent = null;
241242
$sort = 0;
242243
$table = $this->model()->getTable();
243-
foreach(explode(',', $ids) as $id) {
244+
foreach (explode(',', $ids) as $id) {
244245
$sort++;
245246
DB::table($table)->where('id', $id)->update(['sort' => $sort]);
246247
}

0 commit comments

Comments
 (0)