@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | return Nibii::getModelTable($this); |
| 54 | 54 | } |
| 55 | 55 | ); |
| 56 | - foreach($this->behaviours as $behaviour) { |
|
| 56 | + foreach ($this->behaviours as $behaviour) { |
|
| 57 | 57 | $behaviourInstance = $this->loadDependency($behaviour); |
| 58 | 58 | $behaviourInstance->setModel($this); |
| 59 | 59 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | protected function getDataAdapter() |
| 67 | 67 | { |
| 68 | - if(!$this->adapter) |
|
| 68 | + if (!$this->adapter) |
|
| 69 | 69 | { |
| 70 | 70 | $this->adapter = DriverAdapter::getDefaultInstance(); |
| 71 | 71 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | private function retrieveItem($key) |
| 105 | 105 | { |
| 106 | 106 | $relationships = $this->getDescription()->getRelationships(); |
| 107 | - if(isset($relationships[$key])) { |
|
| 107 | + if (isset($relationships[$key])) { |
|
| 108 | 108 | return $this->fetchRelatedFields($relationships[$key]); |
| 109 | 109 | } else { |
| 110 | 110 | return isset($this->modelData[$key]) ? $this->modelData[$key] : null; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | private function expandArrayValue($array, $relationships, $depth, $index = null) |
| 161 | 161 | { |
| 162 | - foreach($relationships as $name => $relationship) { |
|
| 162 | + foreach ($relationships as $name => $relationship) { |
|
| 163 | 163 | $array[$name] = $this->fetchRelatedFields($relationship, $index)->toArray($depth); |
| 164 | 164 | } |
| 165 | 165 | return $array; |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | $relationships = $this->getDescription()->getRelationships(); |
| 171 | 171 | $array = $this->modelData; |
| 172 | - if($depth > 0) { |
|
| 173 | - if($this->hasMultipleData()) { |
|
| 174 | - foreach($array as $i => $value) { |
|
| 172 | + if ($depth > 0) { |
|
| 173 | + if ($this->hasMultipleData()) { |
|
| 174 | + foreach ($array as $i => $value) { |
|
| 175 | 175 | $array[$i] = $this->expandArrayValue($value, $relationships, $depth - 1, $i); |
| 176 | 176 | } |
| 177 | 177 | } else { |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | private function hasMultipleData() |
| 192 | 192 | { |
| 193 | - if(count($this->modelData) > 0) { |
|
| 193 | + if (count($this->modelData) > 0) { |
|
| 194 | 194 | return is_numeric(array_keys($this->modelData)[0]); |
| 195 | 195 | } else { |
| 196 | 196 | return false; |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | { |
| 202 | 202 | $data = []; |
| 203 | 203 | |
| 204 | - if(count($this->modelData) == 0) { |
|
| 204 | + if (count($this->modelData) == 0) { |
|
| 205 | 205 | $data = $this->modelData; |
| 206 | - } else if($this->hasMultipleData()) { |
|
| 206 | + } else if ($this->hasMultipleData()) { |
|
| 207 | 207 | $data = $this->modelData; |
| 208 | - } else if(count($this->modelData) > 0) { |
|
| 208 | + } else if (count($this->modelData) > 0) { |
|
| 209 | 209 | $data[] = $this->modelData; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | |
| 221 | 221 | public function mergeData($data) |
| 222 | 222 | { |
| 223 | - foreach($data as $key => $value) { |
|
| 223 | + foreach ($data as $key => $value) { |
|
| 224 | 224 | $this->modelData[$key] = $value; |
| 225 | 225 | } |
| 226 | 226 | $this->dataSet = true; |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | private function wrap($offset) |
| 255 | 255 | { |
| 256 | - if(isset($this->modelData[$offset])) { |
|
| 256 | + if (isset($this->modelData[$offset])) { |
|
| 257 | 257 | $newInstance = $this->createNew(); |
| 258 | 258 | $newInstance->setData($this->modelData[$offset]); |
| 259 | 259 | return $newInstance; |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | |
| 305 | 305 | private function fetchRelatedFields($relationship, $index = null) |
| 306 | 306 | { |
| 307 | - if($index === null) { |
|
| 307 | + if ($index === null) { |
|
| 308 | 308 | $data = $this->modelData; |
| 309 | 309 | } else { |
| 310 | 310 | $data = $this->modelData[$index]; |
| 311 | 311 | } |
| 312 | 312 | $model = $relationship->getModelInstance(); |
| 313 | - if(empty($data)) { |
|
| 313 | + if (empty($data)) { |
|
| 314 | 314 | return $model; |
| 315 | 315 | } else { |
| 316 | 316 | return $model->fetch($relationship->getQuery($data)); |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | |
| 48 | 48 | public function getModelInstance() |
| 49 | 49 | { |
| 50 | - if(!$this->setup) { |
|
| 50 | + if (!$this->setup) { |
|
| 51 | 51 | $this->runSetup(); |
| 52 | 52 | $this->setup = true; |
| 53 | 53 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function mapDataTypes($nativeType) |
| 14 | 14 | { |
| 15 | - switch($nativeType) |
|
| 15 | + switch ($nativeType) |
|
| 16 | 16 | { |
| 17 | 17 | case 'character varying': |
| 18 | 18 | return 'string'; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public function preSaveCallback($data) |
| 18 | 18 | { |
| 19 | - if(isset($this->model->getDescription()->getFields()['created'])) |
|
| 19 | + if (isset($this->model->getDescription()->getFields()['created'])) |
|
| 20 | 20 | { |
| 21 | 21 | $data['created'] = date('Y-m-d H:i:s'); |
| 22 | 22 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function preUpdateCallback($data) |
| 27 | 27 | { |
| 28 | - if(isset($this->model->getDescription()->getFields()['updated'])) |
|
| 28 | + if (isset($this->model->getDescription()->getFields()['updated'])) |
|
| 29 | 29 | { |
| 30 | 30 | $data['updated'] = date('Y-m-d H:i:s'); |
| 31 | 31 | } |
@@ -42,10 +42,10 @@ |
||
| 42 | 42 | |
| 43 | 43 | public function runSetup() |
| 44 | 44 | { |
| 45 | - if($this->options['foreign_key'] == null) { |
|
| 45 | + if ($this->options['foreign_key'] == null) { |
|
| 46 | 46 | $this->options['foreign_key'] = Text::singularize($this->setupTable) . '_id'; |
| 47 | 47 | } |
| 48 | - if($this->options['local_key'] == null) { |
|
| 48 | + if ($this->options['local_key'] == null) { |
|
| 49 | 49 | $this->options['local_key'] = $this->setupPrimaryKey[0]; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | ->filterBy($this->options['junction_local_key'], $data[$this->options['local_key']]) |
| 47 | 47 | ->fetch(); |
| 48 | 48 | $foreignKeys = []; |
| 49 | - foreach($filter->toArray() as $foreignItem) { |
|
| 49 | + foreach ($filter->toArray() as $foreignItem) { |
|
| 50 | 50 | $foreignKeys[] = $foreignItem[$this->options['junction_foreign_key']]; |
| 51 | 51 | } |
| 52 | 52 | $query = (new \ntentan\nibii\QueryParameters($this->getModelInstance())) |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | public function runSetup() |
| 58 | 58 | { |
| 59 | - if(isset($this->options['through'])) { |
|
| 59 | + if (isset($this->options['through'])) { |
|
| 60 | 60 | $junctionModelName = $this->options['through']; |
| 61 | 61 | } else { |
| 62 | 62 | $junctionModelName = Nibii::joinModels($this->setupName, $this->options['model']); |
@@ -64,20 +64,20 @@ discard block |
||
| 64 | 64 | $this->options['junction_model'] = $junctionModelName; |
| 65 | 65 | |
| 66 | 66 | $foreignModel = Nibii::load($this->options['model']); |
| 67 | - if($this->options['foreign_key'] == null) { |
|
| 67 | + if ($this->options['foreign_key'] == null) { |
|
| 68 | 68 | $this->options['foreign_key'] = $foreignModel->getDescription()->getPrimaryKey()[0]; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if($this->options['local_key'] == null) { |
|
| 71 | + if ($this->options['local_key'] == null) { |
|
| 72 | 72 | $this->options['local_key'] = $this->setupPrimaryKey[0]; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if(!isset($this->options['junction_local_key'])) { |
|
| 75 | + if (!isset($this->options['junction_local_key'])) { |
|
| 76 | 76 | $this->options['junction_local_key'] = |
| 77 | 77 | Text::singularize($this->setupTable) . '_id'; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if(!isset($this->options['junction_foreign_key'])) { |
|
| 80 | + if (!isset($this->options['junction_foreign_key'])) { |
|
| 81 | 81 | $this->options['junction_foreign_key'] = |
| 82 | 82 | Text::singularize($foreignModel->getTable()) . '_id'; |
| 83 | 83 | } |
@@ -45,19 +45,19 @@ |
||
| 45 | 45 | public function run($field, $data) |
| 46 | 46 | { |
| 47 | 47 | $test = []; |
| 48 | - foreach($field['name'] as $name) { |
|
| 48 | + foreach ($field['name'] as $name) { |
|
| 49 | 49 | $test[$name] = isset($data[$name]) ? $data[$name] : null; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if($this->mode == \ntentan\nibii\DataOperations::MODE_UPDATE) { |
|
| 52 | + if ($this->mode == \ntentan\nibii\DataOperations::MODE_UPDATE) { |
|
| 53 | 53 | $primaryKeyFields = $this->model->getDescription()->getPrimaryKey(); |
| 54 | 54 | $keys = []; |
| 55 | - foreach($primaryKeyFields as $name) { |
|
| 55 | + foreach ($primaryKeyFields as $name) { |
|
| 56 | 56 | $keys[$name] = $data[$name]; |
| 57 | 57 | } |
| 58 | 58 | $testItem = $this->model->createNew()->fetchFirst($test); |
| 59 | 59 | $intersection = array_intersect($testItem->toArray(), $keys); |
| 60 | - if(!empty($intersection)) { |
|
| 60 | + if (!empty($intersection)) { |
|
| 61 | 61 | return true; |
| 62 | 62 | } |
| 63 | 63 | } else { |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function mapDataTypes($nativeType) |
| 14 | 14 | { |
| 15 | - switch($nativeType) |
|
| 15 | + switch ($nativeType) |
|
| 16 | 16 | { |
| 17 | 17 | case 'character varying': |
| 18 | 18 | return 'string'; |
@@ -42,10 +42,10 @@ |
||
| 42 | 42 | |
| 43 | 43 | public function runSetup() |
| 44 | 44 | { |
| 45 | - if($this->options['foreign_key'] == null) { |
|
| 45 | + if ($this->options['foreign_key'] == null) { |
|
| 46 | 46 | $this->options['foreign_key'] = Text::singularize($this->setupTable) . '_id'; |
| 47 | 47 | } |
| 48 | - if($this->options['local_key'] == null) { |
|
| 48 | + if ($this->options['local_key'] == null) { |
|
| 49 | 49 | $this->options['local_key'] = $this->setupPrimaryKey[0]; |
| 50 | 50 | } |
| 51 | 51 | } |