@@ -27,7 +27,7 @@ |
||
27 | 27 | /** |
28 | 28 | * @param array $config |
29 | 29 | * @param string $columnName |
30 | - * @return array |
|
30 | + * @return \Doctrine\DBAL\Schema\Column |
|
31 | 31 | */ |
32 | 32 | public function setConfig(array $config, $columnName) |
33 | 33 | { |
@@ -17,11 +17,11 @@ |
||
17 | 17 | */ |
18 | 18 | public function readConfig($action) |
19 | 19 | { |
20 | - $this->fieldsPresentation = $this->getConfigValue('fields_presentation') ? : []; |
|
21 | - $this->formTypes = $this->getConfigValue($action, 'form_types') ? : []; |
|
22 | - $this->validationRules = $this->getConfigValue($action, 'validation') ? : []; |
|
23 | - $this->functions = $this->getConfigValue($action, 'functions') ? : []; |
|
24 | - $this->defaults = $this->getConfigValue($action, 'defaults') ? : []; |
|
20 | + $this->fieldsPresentation = $this->getConfigValue('fields_presentation') ?: []; |
|
21 | + $this->formTypes = $this->getConfigValue($action, 'form_types') ?: []; |
|
22 | + $this->validationRules = $this->getConfigValue($action, 'validation') ?: []; |
|
23 | + $this->functions = $this->getConfigValue($action, 'functions') ?: []; |
|
24 | + $this->defaults = $this->getConfigValue($action, 'defaults') ?: []; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -4,8 +4,6 @@ |
||
4 | 4 | namespace Anavel\Crud\Abstractor\Eloquent\Traits; |
5 | 5 | |
6 | 6 | |
7 | -use Anavel\Crud\Contracts\Abstractor\Field; |
|
8 | - |
|
9 | 7 | trait ModelFields |
10 | 8 | { |
11 | 9 | protected $fieldsPresentation = []; |
@@ -55,7 +55,6 @@ |
||
55 | 55 | public function getSecondaryRelations(); |
56 | 56 | |
57 | 57 | /** |
58 | - * @param Model $relatedModel |
|
59 | 58 | * @return Relation |
60 | 59 | */ |
61 | 60 | public function setRelatedModel(\Illuminate\Database\Eloquent\Model $model); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function persist(array $relationArray = null) |
30 | 30 | { |
31 | - if (! empty($relationArray)) { |
|
31 | + if (!empty($relationArray)) { |
|
32 | 32 | /** @var \ANavallaSuiza\Laravel\Database\Contracts\Repository\Repository $repo */ |
33 | 33 | $repo = $this->modelManager->getRepository(get_class($this->eloquentRelation->getRelated())); |
34 | 34 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $alreadyAssociated = $this->relatedModel->$relationName; |
38 | 38 | |
39 | 39 | $search = []; |
40 | - if (! empty($relationArray[$relatedKeyName])) { |
|
40 | + if (!empty($relationArray[$relatedKeyName])) { |
|
41 | 41 | $search = $relationArray[$relatedKeyName]; |
42 | 42 | } |
43 | 43 | $results = $repo->pushCriteria( |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $result->save(); |
54 | 54 | } |
55 | 55 | |
56 | - if (! $missing->isEmpty()) { |
|
56 | + if (!$missing->isEmpty()) { |
|
57 | 57 | foreach ($missing as $result) { |
58 | 58 | $result->$keyName = null; |
59 | 59 | $result->save(); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | { |
99 | 99 | $results = $this->eloquentRelation->getResults(); |
100 | 100 | |
101 | - if (! $results->isEmpty()) { |
|
101 | + if (!$results->isEmpty()) { |
|
102 | 102 | $values = []; |
103 | 103 | |
104 | 104 | foreach ($results as $result) { |
@@ -9,6 +9,9 @@ |
||
9 | 9 | |
10 | 10 | trait HandleFiles |
11 | 11 | { |
12 | + /** |
|
13 | + * @param string $groupName |
|
14 | + */ |
|
12 | 15 | protected function handleField(Request $request, $item, array $fields, $currentKey, $groupName, $fieldName) |
13 | 16 | { |
14 | 17 | $modelFolder = $this->slug . DIRECTORY_SEPARATOR; |
@@ -11,18 +11,18 @@ discard block |
||
11 | 11 | { |
12 | 12 | protected function handleField(Request $request, $item, array $fields, $groupName, $fieldName) |
13 | 13 | { |
14 | - $modelFolder = $this->slug . DIRECTORY_SEPARATOR; |
|
15 | - $basePath = base_path(DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR .config('anavel-crud.uploads_path')); |
|
16 | - $modelPath = $basePath . $modelFolder; |
|
14 | + $modelFolder = $this->slug.DIRECTORY_SEPARATOR; |
|
15 | + $basePath = base_path(DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.config('anavel-crud.uploads_path')); |
|
16 | + $modelPath = $basePath.$modelFolder; |
|
17 | 17 | $skip = null; |
18 | 18 | $requestValue = null; |
19 | - if (! empty($fields["{$fieldName}__delete"])) { |
|
19 | + if (!empty($fields["{$fieldName}__delete"])) { |
|
20 | 20 | //We never want to save this field, it doesn't exist in the DB |
21 | 21 | $skip = "{$fieldName}__delete"; |
22 | 22 | |
23 | 23 | |
24 | 24 | //If user wants to delete the existing file |
25 | - if (! empty($request->input("{$groupName}.{$fieldName}__delete"))) { |
|
25 | + if (!empty($request->input("{$groupName}.{$fieldName}__delete"))) { |
|
26 | 26 | $adapter = new Local($basePath); |
27 | 27 | $filesystem = new Filesystem($adapter); |
28 | 28 | if ($filesystem->has($item->$fieldName)) { |
@@ -39,28 +39,28 @@ discard block |
||
39 | 39 | ]; |
40 | 40 | } |
41 | 41 | } |
42 | - if ($request->hasFile($groupName .'.'.$fieldName)) { |
|
43 | - $fileName = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_FILENAME); |
|
44 | - $extension = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_EXTENSION); |
|
42 | + if ($request->hasFile($groupName.'.'.$fieldName)) { |
|
43 | + $fileName = pathinfo($request->file($groupName.'.'.$fieldName)->getClientOriginalName(), PATHINFO_FILENAME); |
|
44 | + $extension = pathinfo($request->file($groupName.'.'.$fieldName)->getClientOriginalName(), PATHINFO_EXTENSION); |
|
45 | 45 | |
46 | - $fileName = uniqid() . '_' . slugify($fileName); |
|
47 | - if (! empty($extension)) { |
|
48 | - $fileName .= '.' . $extension; |
|
46 | + $fileName = uniqid().'_'.slugify($fileName); |
|
47 | + if (!empty($extension)) { |
|
48 | + $fileName .= '.'.$extension; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
52 | - $request->file($groupName .'.'.$fieldName)->move( |
|
52 | + $request->file($groupName.'.'.$fieldName)->move( |
|
53 | 53 | $modelPath, |
54 | 54 | $fileName |
55 | 55 | ); |
56 | 56 | |
57 | - $requestValue = $modelFolder . $fileName; |
|
58 | - } elseif (! empty($request->file($groupName .'.'.$fieldName)) && ! $request->file($groupName .'.'.$fieldName)->isValid()) { |
|
59 | - throw new \Exception($request->file($groupName .'.'.$fieldName)->getErrorMessage()); |
|
57 | + $requestValue = $modelFolder.$fileName; |
|
58 | + } elseif (!empty($request->file($groupName.'.'.$fieldName)) && !$request->file($groupName.'.'.$fieldName)->isValid()) { |
|
59 | + throw new \Exception($request->file($groupName.'.'.$fieldName)->getErrorMessage()); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | //Avoid losing the existing filename if the user doesn't change it: |
63 | - if (empty($requestValue) && (! empty($item->$fieldName))) { |
|
63 | + if (empty($requestValue) && (!empty($item->$fieldName))) { |
|
64 | 64 | $requestValue = $item->$fieldName; |
65 | 65 | } |
66 | 66 |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | $config = [ |
124 | 124 | 'name' => $columnName, |
125 | - 'presentation' => $this->name . ' ' . ucfirst(transcrud($columnName)), |
|
125 | + 'presentation' => $this->name.' '.ucfirst(transcrud($columnName)), |
|
126 | 126 | 'form_type' => $formType, |
127 | 127 | 'no_validate' => true, |
128 | 128 | 'validation' => null, |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $field = $this->fieldFactory |
144 | 144 | ->setColumn($column) |
145 | 145 | ->setConfig([ |
146 | - 'name' => $columnName . '__delete', |
|
146 | + 'name' => $columnName.'__delete', |
|
147 | 147 | 'presentation' => null, |
148 | 148 | 'form_type' => 'checkbox', |
149 | 149 | 'no_validate' => true, |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | 'functions' => null |
152 | 152 | ]) |
153 | 153 | ->get(); |
154 | - $fields[$columnName . '__delete'] = $field; |
|
154 | + $fields[$columnName.'__delete'] = $field; |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | } |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | $fieldName = $field->getName(); |
196 | 196 | |
197 | 197 | if (get_class($field->getFormField()) === \FormManager\Fields\File::class) { |
198 | - $handleResult = $this->handleField($request, $relationModel, $fieldsBase, $this->name . ".$relationIndex", $fieldName); |
|
199 | - if (! empty($handleResult['skip'])) { |
|
198 | + $handleResult = $this->handleField($request, $relationModel, $fieldsBase, $this->name.".$relationIndex", $fieldName); |
|
199 | + if (!empty($handleResult['skip'])) { |
|
200 | 200 | $skip = $handleResult['skip']; |
201 | 201 | unset($relationArray[$relationIndex][$skip]); |
202 | 202 | } |
203 | - if (! empty($handleResult['requestValue'])) { |
|
203 | + if (!empty($handleResult['requestValue'])) { |
|
204 | 204 | $relationArray[$relationIndex][$fieldName] = $handleResult['requestValue']; |
205 | 205 | } |
206 | 206 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | */ |
29 | 29 | public function persist(array $relationArray = null, Request $request) |
30 | 30 | { |
31 | - if (! empty($relationArray)) { |
|
31 | + if (!empty($relationArray)) { |
|
32 | 32 | $this->eloquentRelation->sync($relationArray[$this->eloquentRelation->getRelated()->getKeyName()]); |
33 | 33 | } |
34 | 34 | } |
@@ -25,6 +25,9 @@ |
||
25 | 25 | $this->formGenerator = $formGenerator; |
26 | 26 | } |
27 | 27 | |
28 | + /** |
|
29 | + * @param string $methodName |
|
30 | + */ |
|
28 | 31 | private function authorizeMethod(Model $modelAbstractor, $methodName) |
29 | 32 | { |
30 | 33 | if (array_key_exists('authorize', $config = $modelAbstractor->getConfig()) && $config['authorize'] === true) { |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | */ |
39 | 39 | private function customController(Model $modelAbstractor) |
40 | 40 | { |
41 | - if (! $this instanceof CustomController) { //Avoid infinite recursion |
|
42 | - if (array_key_exists('controller', $config = $modelAbstractor->getConfig()) && (! empty($config['controller']))) { |
|
41 | + if (!$this instanceof CustomController) { //Avoid infinite recursion |
|
42 | + if (array_key_exists('controller', $config = $modelAbstractor->getConfig()) && (!empty($config['controller']))) { |
|
43 | 43 | /** @var CustomController $controller */ |
44 | 44 | $controller = App::make($config['controller']); |
45 | 45 | $controller->setAbstractor($modelAbstractor); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | $this->authorizeMethod($modelAbstractor, 'adminIndex'); |
64 | 64 | |
65 | - if (! empty($customController = $this->customController($modelAbstractor))) { |
|
65 | + if (!empty($customController = $this->customController($modelAbstractor))) { |
|
66 | 66 | return $customController->index($request, $model); |
67 | 67 | } |
68 | 68 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | $this->authorizeMethod($modelAbstractor, 'adminCreate'); |
104 | 104 | |
105 | - if (! empty($customController = $this->customController($modelAbstractor))) { |
|
105 | + if (!empty($customController = $this->customController($modelAbstractor))) { |
|
106 | 106 | return $customController->create($model); |
107 | 107 | } |
108 | 108 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | $this->authorizeMethod($modelAbstractor, 'adminStore'); |
130 | 130 | |
131 | - if (! empty($customController = $this->customController($modelAbstractor))) { |
|
131 | + if (!empty($customController = $this->customController($modelAbstractor))) { |
|
132 | 132 | return $customController->store($request, $model); |
133 | 133 | } |
134 | 134 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | |
163 | 163 | $this->authorizeMethod($modelAbstractor, 'adminShow'); |
164 | 164 | |
165 | - if (! empty($customController = $this->customController($modelAbstractor))) { |
|
165 | + if (!empty($customController = $this->customController($modelAbstractor))) { |
|
166 | 166 | return $customController->show($model, $id); |
167 | 167 | } |
168 | 168 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | $this->authorizeMethod($modelAbstractor, 'adminEdit'); |
191 | 191 | |
192 | - if (! empty($customController = $this->customController($modelAbstractor))) { |
|
192 | + if (!empty($customController = $this->customController($modelAbstractor))) { |
|
193 | 193 | return $customController->edit($model, $id); |
194 | 194 | } |
195 | 195 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | |
220 | 220 | $this->authorizeMethod($modelAbstractor, 'adminUpdate'); |
221 | 221 | |
222 | - if (! empty($customController = $this->customController($modelAbstractor))) { |
|
222 | + if (!empty($customController = $this->customController($modelAbstractor))) { |
|
223 | 223 | return $customController->update($request, $model, $id); |
224 | 224 | } |
225 | 225 | |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | |
255 | 255 | $this->authorizeMethod($modelAbstractor, 'adminDestroy'); |
256 | 256 | |
257 | - if (! empty($customController = $this->customController($modelAbstractor))) { |
|
257 | + if (!empty($customController = $this->customController($modelAbstractor))) { |
|
258 | 258 | return $customController->destroy($request, $model, $id); |
259 | 259 | } |
260 | 260 |
@@ -23,7 +23,7 @@ |
||
23 | 23 | $modelAbstractor = $modelFactory->getByName($modelSlug); |
24 | 24 | $config = $modelAbstractor->getConfig(); |
25 | 25 | |
26 | - if (! array_key_exists('authorize', $config) || ($config['authorize'] === true && Gate::allows('adminIndex', $modelAbstractor->getInstance()) || $config['authorize'] === false)) { |
|
26 | + if (!array_key_exists('authorize', $config) || ($config['authorize'] === true && Gate::allows('adminIndex', $modelAbstractor->getInstance()) || $config['authorize'] === false)) { |
|
27 | 27 | return new RedirectResponse(route('anavel-crud.model.index', $modelSlug)); |
28 | 28 | } |
29 | 29 | } |
@@ -60,13 +60,13 @@ |
||
60 | 60 | } catch (\Exception $e) { |
61 | 61 | continue; |
62 | 62 | } |
63 | - $menuItems[$modelName]['isActive'] = $item['isActive']; |
|
63 | + $menuItems[$modelName]['isActive'] = $item['isActive']; |
|
64 | 64 | $menuItems[$modelName]['name'] = $item['name']; |
65 | 65 | $menuItems[$modelName]['items'][] = $item; |
66 | 66 | } |
67 | 67 | |
68 | 68 | //Sort alphabetically de menu items |
69 | - usort($menuItems, function ($itemA, $itemB) { |
|
69 | + usort($menuItems, function($itemA, $itemB) { |
|
70 | 70 | return strcmp($itemA['name'], $itemB['name']); |
71 | 71 | }); |
72 | 72 | return $menuItems; |