@@ -33,8 +33,9 @@ discard block |
||
| 33 | 33 | $class = parent::getClass($classType, $version, $classOverrideCriteria); |
| 34 | 34 | // update member definitions with the latest from the database and |
| 35 | 35 | // override again with the changes that were defined before |
| 36 | - if ($class) |
|
| 37 | - $class->definition = $this->updateDefinitionFromDds($class->definition); |
|
| 36 | + if ($class) { |
|
| 37 | + $class->definition = $this->updateDefinitionFromDds($class->definition); |
|
| 38 | + } |
|
| 38 | 39 | return $class; |
| 39 | 40 | } |
| 40 | 41 | |
@@ -55,8 +56,9 @@ discard block |
||
| 55 | 56 | { |
| 56 | 57 | $object = parent::getObject($objectId); |
| 57 | 58 | // update the data from Daedalus if required |
| 58 | - if ($object) |
|
| 59 | - $object->updateFromDds(); |
|
| 59 | + if ($object) { |
|
| 60 | + $object->updateFromDds(); |
|
| 61 | + } |
|
| 60 | 62 | return $object; |
| 61 | 63 | } |
| 62 | 64 | |
@@ -54,8 +54,9 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | protected function replaceDefinitionFromDds($definition) |
| 56 | 56 | { |
| 57 | - if (empty($definition)) |
|
| 58 | - return []; |
|
| 57 | + if (empty($definition)) { |
|
| 58 | + return []; |
|
| 59 | + } |
|
| 59 | 60 | |
| 60 | 61 | $classes = $this->getDdsClassDefinitions($definition); |
| 61 | 62 | foreach ($definition['renderables'] as &$renderable) { |
@@ -100,8 +101,9 @@ discard block |
||
| 100 | 101 | $parentClassId = null; |
| 101 | 102 | if (isset($r['parentClassId'])) { |
| 102 | 103 | $parentClassId = $r['parentClassId']; |
| 103 | - if (!in_array($r['parentClassId'], $renderableKeys)) |
|
| 104 | - $parentClassId = $this->findParentClassIdFromType($r['parentClassId'], $definition['renderables']); |
|
| 104 | + if (!in_array($r['parentClassId'], $renderableKeys)) { |
|
| 105 | + $parentClassId = $this->findParentClassIdFromType($r['parentClassId'], $definition['renderables']); |
|
| 106 | + } |
|
| 105 | 107 | } |
| 106 | 108 | $r['relations'] = [ |
| 107 | 109 | [ |
@@ -117,8 +119,9 @@ discard block |
||
| 117 | 119 | protected function findParentClassIdFromType($type, $renderables) |
| 118 | 120 | { |
| 119 | 121 | foreach ($renderables as $r) { |
| 120 | - if ($this->isClass($r) && $r['class_type'] == $type) |
|
| 121 | - return $r['id']; |
|
| 122 | + if ($this->isClass($r) && $r['class_type'] == $type) { |
|
| 123 | + return $r['id']; |
|
| 124 | + } |
|
| 122 | 125 | } |
| 123 | 126 | // can't find it so return the original so as not to break anything |
| 124 | 127 | return $type; |
@@ -169,8 +172,9 @@ discard block |
||
| 169 | 172 | } |
| 170 | 173 | } |
| 171 | 174 | $definitions = []; |
| 172 | - foreach ($requiredClassTypes as $rct) |
|
| 173 | - $definitions[$rct] = isset($requestedClasses[$rct]) ? $requestedClasses[$rct]->definition : null; |
|
| 175 | + foreach ($requiredClassTypes as $rct) { |
|
| 176 | + $definitions[$rct] = isset($requestedClasses[$rct]) ? $requestedClasses[$rct]->definition : null; |
|
| 177 | + } |
|
| 174 | 178 | return $definitions; |
| 175 | 179 | } |
| 176 | 180 | |
@@ -182,8 +186,9 @@ discard block |
||
| 182 | 186 | $memberDefinition = $classes[$renderable['class_type']]['fields'][$renderable['member_ref']]; |
| 183 | 187 | $differences = []; |
| 184 | 188 | foreach ($renderDefinition as $key=>$value) { |
| 185 | - if (!isset($memberDefinition['definition'][$key]) || ($memberDefinition['definition'][$key] != $value)) |
|
| 186 | - $differences[$key] = $value; |
|
| 189 | + if (!isset($memberDefinition['definition'][$key]) || ($memberDefinition['definition'][$key] != $value)) { |
|
| 190 | + $differences[$key] = $value; |
|
| 191 | + } |
|
| 187 | 192 | } |
| 188 | 193 | $renderable['changes']=$differences; |
| 189 | 194 | } |
@@ -233,8 +238,9 @@ discard block |
||
| 233 | 238 | |
| 234 | 239 | private function ddsPhoebe() |
| 235 | 240 | { |
| 236 | - if (!$this->_ddsPhoebe) |
|
| 237 | - $this->_ddsPhoebe = neon('phoebe')->getIPhoebeType('daedalus'); |
|
| 241 | + if (!$this->_ddsPhoebe) { |
|
| 242 | + $this->_ddsPhoebe = neon('phoebe')->getIPhoebeType('daedalus'); |
|
| 243 | + } |
|
| 238 | 244 | return $this->_ddsPhoebe; |
| 239 | 245 | } |
| 240 | 246 | private $_ddsPhoebe = null; |
@@ -42,15 +42,17 @@ discard block |
||
| 42 | 42 | // NOTE - changes are only saved into $this->data and not |
| 43 | 43 | // to the phoebe object in general. |
| 44 | 44 | |
| 45 | - if (empty($changes) || $changes == $this->data) |
|
| 46 | - return true; |
|
| 45 | + if (empty($changes) || $changes == $this->data) { |
|
| 46 | + return true; |
|
| 47 | + } |
|
| 47 | 48 | |
| 48 | 49 | // Get the associated class object |
| 49 | 50 | $classType = $this->getClassType(); |
| 50 | 51 | $class = $this->getClassModel($classType); |
| 51 | 52 | |
| 52 | - if (!$class) |
|
| 53 | - throw new \RuntimeException("Class of type '$classType' not found. Can't save objects of unknown types"); |
|
| 53 | + if (!$class) { |
|
| 54 | + throw new \RuntimeException("Class of type '$classType' not found. Can't save objects of unknown types"); |
|
| 55 | + } |
|
| 54 | 56 | |
| 55 | 57 | // save the history object |
| 56 | 58 | if ($class->object_history) { |
@@ -58,15 +60,17 @@ discard block |
||
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | // update the version if the class is not version locked |
| 61 | - if (!$class->version_locked) |
|
| 62 | - $this->version = $class->version; |
|
| 63 | + if (!$class->version_locked) { |
|
| 64 | + $this->version = $class->version; |
|
| 65 | + } |
|
| 63 | 66 | |
| 64 | 67 | // merge the changes and save the model |
| 65 | 68 | $this->data = $changes; |
| 66 | 69 | $this->updated = date('Y-m-d H:i:s'); |
| 67 | 70 | $model = $this->getModel(); |
| 68 | - if (!$model->save()) |
|
| 69 | - return $model->errors; |
|
| 71 | + if (!$model->save()) { |
|
| 72 | + return $model->errors; |
|
| 73 | + } |
|
| 70 | 74 | return true; |
| 71 | 75 | } |
| 72 | 76 | |
@@ -124,8 +128,9 @@ discard block |
||
| 124 | 128 | public function setOverride($overrideUuid, $force=false) |
| 125 | 129 | { |
| 126 | 130 | // don't override an override unless forced to do so |
| 127 | - if (!$force && $this->override_uuid) |
|
| 128 | - return false; |
|
| 131 | + if (!$force && $this->override_uuid) { |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 129 | 134 | |
| 130 | 135 | // Get the associated class object and check the override applies to this class |
| 131 | 136 | if ($this->getClassOverrideModel($overrideUuid, $this->version)) { |
@@ -158,8 +163,9 @@ discard block |
||
| 158 | 163 | $query = ObjectHistoryModel::find() |
| 159 | 164 | ->where(['object_uuid' => $this->uuid]); |
| 160 | 165 | |
| 161 | - if ($paginator['start']==0) |
|
| 162 | - $paginator['total'] = $query->count(); |
|
| 166 | + if ($paginator['start']==0) { |
|
| 167 | + $paginator['total'] = $query->count(); |
|
| 168 | + } |
|
| 163 | 169 | |
| 164 | 170 | // and get the results |
| 165 | 171 | return $query->offset($paginator['start']) |
@@ -236,8 +242,9 @@ discard block |
||
| 236 | 242 | $hmodel->version = $this->version; |
| 237 | 243 | $hmodel->override_uuid = $this->override_uuid; |
| 238 | 244 | $hmodel->serialised_data = $this->serialised_data; |
| 239 | - if (!$hmodel->save()) |
|
| 240 | - throw new \RuntimeException("Failed to save the history of the object. Model errors were ".print_r($hmodel->errors,true)); |
|
| 245 | + if (!$hmodel->save()) { |
|
| 246 | + throw new \RuntimeException("Failed to save the history of the object. Model errors were ".print_r($hmodel->errors,true)); |
|
| 247 | + } |
|
| 241 | 248 | } |
| 242 | 249 | |
| 243 | 250 | } |
| 244 | 251 | \ No newline at end of file |
@@ -70,10 +70,11 @@ discard block |
||
| 70 | 70 | public function beforeSave($insert) |
| 71 | 71 | { |
| 72 | 72 | // data can only be an array and are stored as JSON |
| 73 | - if (is_array($this->data) && count($this->data)) |
|
| 74 | - $this->serialised_data = json_encode($this->data); |
|
| 75 | - else |
|
| 76 | - $this->serialised_data = null; |
|
| 73 | + if (is_array($this->data) && count($this->data)) { |
|
| 74 | + $this->serialised_data = json_encode($this->data); |
|
| 75 | + } else { |
|
| 76 | + $this->serialised_data = null; |
|
| 77 | + } |
|
| 77 | 78 | return parent::beforeSave($insert); |
| 78 | 79 | } |
| 79 | 80 | |
@@ -83,8 +84,9 @@ discard block |
||
| 83 | 84 | public function afterFind() |
| 84 | 85 | { |
| 85 | 86 | // return data as decoded json or null |
| 86 | - if (is_string($this->serialised_data)) |
|
| 87 | - $this->data = json_decode($this->serialised_data, true); |
|
| 87 | + if (is_string($this->serialised_data)) { |
|
| 88 | + $this->data = json_decode($this->serialised_data, true); |
|
| 89 | + } |
|
| 88 | 90 | parent::afterFind(); |
| 89 | 91 | } |
| 90 | 92 | |
@@ -101,14 +103,17 @@ discard block |
||
| 101 | 103 | } |
| 102 | 104 | $query = PhoebeObject::find()->select(['phoebe_object.uuid', 'phoebe_class.label']) |
| 103 | 105 | ->leftJoin('phoebe_class', 'phoebe_class.phoebe_type=phoebe_object.phoebe_type AND phoebe_class.class_type=phoebe_object.class_type'); |
| 104 | - if (!empty($query)) |
|
| 105 | - $query->where(['like', 'phoebe_class.label', $query]); |
|
| 106 | - if (count($filters)) |
|
| 107 | - $query->andWhere($filters); |
|
| 106 | + if (!empty($query)) { |
|
| 107 | + $query->where(['like', 'phoebe_class.label', $query]); |
|
| 108 | + } |
|
| 109 | + if (count($filters)) { |
|
| 110 | + $query->andWhere($filters); |
|
| 111 | + } |
|
| 108 | 112 | $objects = $query->orderBy('phoebe_class.label')->asArray()->all(); |
| 109 | 113 | $results = []; |
| 110 | - foreach ($objects as $object) |
|
| 111 | - $results[$object['uuid']] = "$object[label]: $object[uuid]"; |
|
| 114 | + foreach ($objects as $object) { |
|
| 115 | + $results[$object['uuid']] = "$object[label]: $object[uuid]"; |
|
| 116 | + } |
|
| 112 | 117 | return $results; |
| 113 | 118 | } |
| 114 | 119 | } |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | // active_from must be set |
| 101 | 101 | // overrides can only be an array and are stored as JSON or already JSON |
| 102 | - if (is_array($this->overrides) && count($this->overrides)) |
|
| 103 | - $this->serialised_overrides = json_encode($this->overrides); |
|
| 104 | - else { |
|
| 102 | + if (is_array($this->overrides) && count($this->overrides)) { |
|
| 103 | + $this->serialised_overrides = json_encode($this->overrides); |
|
| 104 | + } else { |
|
| 105 | 105 | $this->serialised_overrides = null; |
| 106 | 106 | } |
| 107 | 107 | return parent::beforeSave($insert); |
@@ -113,8 +113,9 @@ discard block |
||
| 113 | 113 | public function afterFind() |
| 114 | 114 | { |
| 115 | 115 | // return overrides as decoded json or null |
| 116 | - if (is_string($this->serialised_overrides)) |
|
| 117 | - $this->overrides = json_decode($this->serialised_overrides, true); |
|
| 116 | + if (is_string($this->serialised_overrides)) { |
|
| 117 | + $this->overrides = json_decode($this->serialised_overrides, true); |
|
| 118 | + } |
|
| 118 | 119 | parent::afterFind(); |
| 119 | 120 | } |
| 120 | 121 | |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | public function beforeSave($insert) |
| 85 | 85 | { |
| 86 | 86 | // definition can only be an array and are stored as JSON or already JSON |
| 87 | - if (is_array($this->definition) && count($this->definition)) |
|
| 88 | - $this->serialised_definition = json_encode($this->definition); |
|
| 89 | - else { |
|
| 87 | + if (is_array($this->definition) && count($this->definition)) { |
|
| 88 | + $this->serialised_definition = json_encode($this->definition); |
|
| 89 | + } else { |
|
| 90 | 90 | $this->serialised_definition = null; |
| 91 | 91 | } |
| 92 | 92 | return parent::beforeSave($insert); |
@@ -98,8 +98,9 @@ discard block |
||
| 98 | 98 | public function afterFind() |
| 99 | 99 | { |
| 100 | 100 | // return definition as decoded json or null |
| 101 | - if (is_string($this->serialised_definition)) |
|
| 102 | - $this->definition = json_decode($this->serialised_definition, true); |
|
| 101 | + if (is_string($this->serialised_definition)) { |
|
| 102 | + $this->definition = json_decode($this->serialised_definition, true); |
|
| 103 | + } |
|
| 103 | 104 | parent::afterFind(); |
| 104 | 105 | } |
| 105 | 106 | |
@@ -120,14 +121,17 @@ discard block |
||
| 120 | 121 | public static function listClassTypes($query, $filters) |
| 121 | 122 | { |
| 122 | 123 | $query = PhoebeClass::find()->select(['class_type', 'label']); |
| 123 | - if (!empty($query)) |
|
| 124 | - $query->where(['like', 'label', $query]); |
|
| 125 | - if (count($filters)) |
|
| 126 | - $query->where($filters); |
|
| 124 | + if (!empty($query)) { |
|
| 125 | + $query->where(['like', 'label', $query]); |
|
| 126 | + } |
|
| 127 | + if (count($filters)) { |
|
| 128 | + $query->where($filters); |
|
| 129 | + } |
|
| 127 | 130 | $classes = $query->orderBy('label')->asArray()->all(); |
| 128 | 131 | $results = []; |
| 129 | - foreach ($classes as $class) |
|
| 130 | - $results[$class['class_type']] = $class['label']; |
|
| 132 | + foreach ($classes as $class) { |
|
| 133 | + $results[$class['class_type']] = $class['label']; |
|
| 134 | + } |
|
| 131 | 135 | return $results; |
| 132 | 136 | } |
| 133 | 137 | } |
@@ -103,8 +103,9 @@ discard block |
||
| 103 | 103 | $model = new ClassModel(); |
| 104 | 104 | $model->attributes = array_merge($oldAttrs, $changes); |
| 105 | 105 | $model->updated = date('Y-m-d H:i:s'); |
| 106 | - if (!$model->save()) |
|
| 107 | - throw new \RuntimeException('Save failed with the following errors '.print_r($model->errors,true)); |
|
| 106 | + if (!$model->save()) { |
|
| 107 | + throw new \RuntimeException('Save failed with the following errors '.print_r($model->errors,true)); |
|
| 108 | + } |
|
| 108 | 109 | $this->setModel($model); |
| 109 | 110 | $hasChanges = true; |
| 110 | 111 | } else { |
@@ -127,8 +128,9 @@ discard block |
||
| 127 | 128 | $model->attributes = $oldAttrs; |
| 128 | 129 | return $errors; |
| 129 | 130 | } |
| 130 | - if ($hasChanges) |
|
| 131 | - $this->createEditClassMigration($model->attributes, $oldAttrs, $newModel); |
|
| 131 | + if ($hasChanges) { |
|
| 132 | + $this->createEditClassMigration($model->attributes, $oldAttrs, $newModel); |
|
| 133 | + } |
|
| 132 | 134 | return $hasChanges; |
| 133 | 135 | } |
| 134 | 136 | |
@@ -216,10 +218,11 @@ discard block |
||
| 216 | 218 | { |
| 217 | 219 | if ($overrideUuid) { |
| 218 | 220 | $override = $this->getOverride($overrideUuid); |
| 219 | - if (isset($override['overrides'])) |
|
| 220 | - $this->applyClassOverrideByDefinition($override['overrides']); |
|
| 221 | - else |
|
| 222 | - $this->applyClassOverrideByDefinition([]); |
|
| 221 | + if (isset($override['overrides'])) { |
|
| 222 | + $this->applyClassOverrideByDefinition($override['overrides']); |
|
| 223 | + } else { |
|
| 224 | + $this->applyClassOverrideByDefinition([]); |
|
| 225 | + } |
|
| 223 | 226 | } |
| 224 | 227 | } |
| 225 | 228 | |
@@ -250,8 +253,9 @@ discard block |
||
| 250 | 253 | 'deleted' => 0 |
| 251 | 254 | ])->asArray()->all(); |
| 252 | 255 | $list = []; |
| 253 | - foreach ($overrides as $o) |
|
| 254 | - $list[$o['uuid']] = $o['label']; |
|
| 256 | + foreach ($overrides as $o) { |
|
| 257 | + $list[$o['uuid']] = $o['label']; |
|
| 258 | + } |
|
| 255 | 259 | return $list; |
| 256 | 260 | } |
| 257 | 261 | |
@@ -303,8 +307,9 @@ discard block |
||
| 303 | 307 | $override->created = date('Y-m-d H:i:s'); |
| 304 | 308 | $override->deleted = 0; |
| 305 | 309 | $override->overrides = []; |
| 306 | - if ($override->save()) |
|
| 307 | - return $uuid; |
|
| 310 | + if ($override->save()) { |
|
| 311 | + return $uuid; |
|
| 312 | + } |
|
| 308 | 313 | return $override->errors; |
| 309 | 314 | } |
| 310 | 315 | |
@@ -320,18 +325,21 @@ discard block |
||
| 320 | 325 | ); |
| 321 | 326 | |
| 322 | 327 | // nothing to see here move along |
| 323 | - if (count($changes)===0) |
|
| 324 | - return true; |
|
| 328 | + if (count($changes)===0) { |
|
| 329 | + return true; |
|
| 330 | + } |
|
| 325 | 331 | // ok now do the edit |
| 326 | 332 | $override = $this->getClassOverrideModel($uuid); |
| 327 | 333 | if ($override) { |
| 328 | 334 | foreach ($changes as $key=>$value) { |
| 329 | - if ($key == 'active_from') |
|
| 330 | - $value = $this->setDateToNowOnEmpty($value); |
|
| 335 | + if ($key == 'active_from') { |
|
| 336 | + $value = $this->setDateToNowOnEmpty($value); |
|
| 337 | + } |
|
| 331 | 338 | $override->$key = $value; |
| 332 | 339 | } |
| 333 | - if ($override->save()) |
|
| 334 | - return true; |
|
| 340 | + if ($override->save()) { |
|
| 341 | + return true; |
|
| 342 | + } |
|
| 335 | 343 | return $override->errors; |
| 336 | 344 | } |
| 337 | 345 | return false; |
@@ -367,8 +375,9 @@ discard block |
||
| 367 | 375 | public function destroyOverride($uuid) |
| 368 | 376 | { |
| 369 | 377 | $override = $this->getClassOverrideModel($uuid); |
| 370 | - if ($override) |
|
| 371 | - $override->delete(); |
|
| 378 | + if ($override) { |
|
| 379 | + $override->delete(); |
|
| 380 | + } |
|
| 372 | 381 | } |
| 373 | 382 | |
| 374 | 383 | |
@@ -383,8 +392,9 @@ discard block |
||
| 383 | 392 | public function getDefinition() |
| 384 | 393 | { |
| 385 | 394 | $definition = $this->getModel()->definition; |
| 386 | - if ($this->_overrides) |
|
| 387 | - $definition = array_replace_recursive($definition, $this->_overrides); |
|
| 395 | + if ($this->_overrides) { |
|
| 396 | + $definition = array_replace_recursive($definition, $this->_overrides); |
|
| 397 | + } |
|
| 388 | 398 | return $definition; |
| 389 | 399 | } |
| 390 | 400 | |
@@ -399,8 +409,9 @@ discard block |
||
| 399 | 409 | $classType = $this->getClassType(); |
| 400 | 410 | |
| 401 | 411 | // don't do this unless we know definitely what we are |
| 402 | - if (!$phoebeType || !$classType) |
|
| 403 | - return; |
|
| 412 | + if (!$phoebeType || !$classType) { |
|
| 413 | + return; |
|
| 414 | + } |
|
| 404 | 415 | |
| 405 | 416 | // clear out any override objects |
| 406 | 417 | OverridesModel::deleteAll([ |
@@ -430,8 +441,9 @@ discard block |
||
| 430 | 441 | protected function createEditClassMigration($newAttrs, $oldAttrs, $newModel) |
| 431 | 442 | { |
| 432 | 443 | // check to make sure the changes are real and need to be saved as a migration |
| 433 | - if (!($newModel || $this->hasChanges($newAttrs, $oldAttrs))) |
|
| 434 | - return; |
|
| 444 | + if (!($newModel || $this->hasChanges($newAttrs, $oldAttrs))) { |
|
| 445 | + return; |
|
| 446 | + } |
|
| 435 | 447 | |
| 436 | 448 | $up = $this->getTableRowReplaceSql('phoebe_class', $newAttrs); |
| 437 | 449 | $down = ''; |
@@ -36,8 +36,9 @@ discard block |
||
| 36 | 36 | $paginator = $this->createPaginator($paginator); |
| 37 | 37 | $orderBy = count($orderBy)>0 ? $orderBy : 'label ASC'; |
| 38 | 38 | $filters = array_intersect_key($filters, array_flip(['class_type','label','description','module'])); |
| 39 | - if (isset($filters['class_type'])) |
|
| 40 | - $filters['class_type'] = $this->canonicaliseRef($filters['class_type']); |
|
| 39 | + if (isset($filters['class_type'])) { |
|
| 40 | + $filters['class_type'] = $this->canonicaliseRef($filters['class_type']); |
|
| 41 | + } |
|
| 41 | 42 | |
| 42 | 43 | /* |
| 43 | 44 | * This slightly unusual query according to MySQL is an efficient way to find the highest version of |
@@ -61,10 +62,12 @@ discard block |
||
| 61 | 62 | $query->andWhere(['p1.deleted'=>0]); |
| 62 | 63 | } |
| 63 | 64 | $query->select($select); |
| 64 | - foreach ($filters as $key=>$value) |
|
| 65 | - $query->andWhere(['like', "p1.$key", $value]); |
|
| 66 | - if ($paginator['start']==0) |
|
| 67 | - $paginator['total'] = $query->count(); |
|
| 65 | + foreach ($filters as $key=>$value) { |
|
| 66 | + $query->andWhere(['like', "p1.$key", $value]); |
|
| 67 | + } |
|
| 68 | + if ($paginator['start']==0) { |
|
| 69 | + $paginator['total'] = $query->count(); |
|
| 70 | + } |
|
| 68 | 71 | |
| 69 | 72 | // and get the results |
| 70 | 73 | $results = $query->offset($paginator['start']) |
@@ -74,8 +77,9 @@ discard block |
||
| 74 | 77 | |
| 75 | 78 | // finally index them by the class_type as this is useful for changes in other classes |
| 76 | 79 | $return = []; |
| 77 | - foreach ($results as $r) |
|
| 78 | - $return[$r['class_type']] = $r; |
|
| 80 | + foreach ($results as $r) { |
|
| 81 | + $return[$r['class_type']] = $r; |
|
| 82 | + } |
|
| 79 | 83 | return $return; |
| 80 | 84 | } |
| 81 | 85 | |
@@ -85,8 +89,9 @@ discard block |
||
| 85 | 89 | public function addClass(&$classType, $module='') |
| 86 | 90 | { |
| 87 | 91 | $classType = $this->canonicaliseRef($classType); |
| 88 | - if (empty($classType)) |
|
| 89 | - throw new \RuntimeException("Invalid classType $classType"); |
|
| 92 | + if (empty($classType)) { |
|
| 93 | + throw new \RuntimeException("Invalid classType $classType"); |
|
| 94 | + } |
|
| 90 | 95 | |
| 91 | 96 | // create a model for the class |
| 92 | 97 | $model = $this->createPhoebeClassModel($classType, $module); |
@@ -94,8 +99,9 @@ discard block |
||
| 94 | 99 | try { |
| 95 | 100 | if ($model->save()) { |
| 96 | 101 | $class = $this->createIPhoebeClass($model); |
| 97 | - } else |
|
| 98 | - throw new \Exception('Errors on save'); |
|
| 102 | + } else { |
|
| 103 | + throw new \Exception('Errors on save'); |
|
| 104 | + } |
|
| 99 | 105 | } catch (\Exception $e) { |
| 100 | 106 | throw new \RuntimeException('Failed to create model. Exception was "'.$e->getMessage().'". Model errors were '.print_r($model->errors, true)); |
| 101 | 107 | } |
@@ -109,16 +115,18 @@ discard block |
||
| 109 | 115 | public function getClass($classType, $version=null, $classOverrideCriteria=[]) |
| 110 | 116 | { |
| 111 | 117 | $classType = $this->canonicaliseRef($classType); |
| 112 | - if (empty($classType)) |
|
| 113 | - return null; |
|
| 118 | + if (empty($classType)) { |
|
| 119 | + return null; |
|
| 120 | + } |
|
| 114 | 121 | |
| 115 | 122 | $model = $this->getClassModel($classType, $version); |
| 116 | 123 | if ($model) { |
| 117 | 124 | $class = $this->createIPhoebeClass($model); |
| 118 | 125 | if ($classOverrideCriteria !== false) { |
| 119 | 126 | $override = $class->findClassOverride($classOverrideCriteria); |
| 120 | - if ($override) |
|
| 121 | - $class->applyClassOverrideByDefinition($override['overrides']); |
|
| 127 | + if ($override) { |
|
| 128 | + $class->applyClassOverrideByDefinition($override['overrides']); |
|
| 129 | + } |
|
| 122 | 130 | } |
| 123 | 131 | return $class; |
| 124 | 132 | } |
@@ -132,8 +140,9 @@ discard block |
||
| 132 | 140 | { |
| 133 | 141 | $models = $this->getClassModels($classTypes); |
| 134 | 142 | $classes = array(); |
| 135 | - foreach ($models as $type => $model) |
|
| 136 | - $classes[$type] = $model ? $this->createIPhoebeClass($model) : null; |
|
| 143 | + foreach ($models as $type => $model) { |
|
| 144 | + $classes[$type] = $model ? $this->createIPhoebeClass($model) : null; |
|
| 145 | + } |
|
| 137 | 146 | return $classes; |
| 138 | 147 | } |
| 139 | 148 | |
@@ -176,8 +185,9 @@ discard block |
||
| 176 | 185 | ]); |
| 177 | 186 | $select = ['uuid','phoebe_type','class_type','version','created','updated']; |
| 178 | 187 | |
| 179 | - if (in_array('data', $additionalFields)) |
|
| 180 | - $select[] = 'serialised_data'; |
|
| 188 | + if (in_array('data', $additionalFields)) { |
|
| 189 | + $select[] = 'serialised_data'; |
|
| 190 | + } |
|
| 181 | 191 | if (in_array('deleted', $additionalFields)) { |
| 182 | 192 | $select[] = 'deleted'; |
| 183 | 193 | } else { |
@@ -185,10 +195,12 @@ discard block |
||
| 185 | 195 | } |
| 186 | 196 | $query->select($select); |
| 187 | 197 | |
| 188 | - foreach ($filters as $key=>$value) |
|
| 189 | - $query->andWhere(['=', $key, $value]); |
|
| 190 | - if ($paginator['start']==0) |
|
| 191 | - $paginator['total'] = $query->count(); |
|
| 198 | + foreach ($filters as $key=>$value) { |
|
| 199 | + $query->andWhere(['=', $key, $value]); |
|
| 200 | + } |
|
| 201 | + if ($paginator['start']==0) { |
|
| 202 | + $paginator['total'] = $query->count(); |
|
| 203 | + } |
|
| 192 | 204 | // and get the results |
| 193 | 205 | return $query->offset($paginator['start']) |
| 194 | 206 | ->limit($paginator['length']) |
@@ -215,13 +227,15 @@ discard block |
||
| 215 | 227 | // work out what class override needs to be applied |
| 216 | 228 | if ($classOverrideCriteria !== false) { |
| 217 | 229 | $override = $phoebeObject->findClassOverride($classOverrideCriteria, ['uuid']); |
| 218 | - if ($override) |
|
| 219 | - $model->override_uuid = $override['uuid']; |
|
| 230 | + if ($override) { |
|
| 231 | + $model->override_uuid = $override['uuid']; |
|
| 232 | + } |
|
| 220 | 233 | $model->save(); |
| 221 | 234 | } |
| 222 | 235 | return $phoebeObject; |
| 223 | - } else |
|
| 224 | - throw new \Exception('Errors on save'); |
|
| 236 | + } else { |
|
| 237 | + throw new \Exception('Errors on save'); |
|
| 238 | + } |
|
| 225 | 239 | } catch (\Exception $e) { |
| 226 | 240 | throw new \RuntimeException('Failed to create model. Exception was "'.$e->getMessage().'". Model errors were '.print_r($model->errors, true)); |
| 227 | 241 | } |
@@ -252,13 +266,15 @@ discard block |
||
| 252 | 266 | protected function getClassFromType($classType) |
| 253 | 267 | { |
| 254 | 268 | $classType = $this->canonicaliseRef($classType); |
| 255 | - if (empty($classType)) |
|
| 256 | - throw new \RuntimeException("Invalid classType '$classType'"); |
|
| 269 | + if (empty($classType)) { |
|
| 270 | + throw new \RuntimeException("Invalid classType '$classType'"); |
|
| 271 | + } |
|
| 257 | 272 | |
| 258 | 273 | // check a class of this classType exists |
| 259 | 274 | $class = $this->getClassModel($classType); |
| 260 | - if (!$class) |
|
| 261 | - throw new \RuntimeException("No class of type '$classType' available"); |
|
| 275 | + if (!$class) { |
|
| 276 | + throw new \RuntimeException("No class of type '$classType' available"); |
|
| 277 | + } |
|
| 262 | 278 | return $class; |
| 263 | 279 | } |
| 264 | 280 | |
@@ -83,8 +83,9 @@ discard block |
||
| 83 | 83 | public function __get($name) |
| 84 | 84 | { |
| 85 | 85 | $attrs = $this->getModelAttributes(); |
| 86 | - if (array_key_exists($name, $attrs)) |
|
| 87 | - return $attrs[$name]; |
|
| 86 | + if (array_key_exists($name, $attrs)) { |
|
| 87 | + return $attrs[$name]; |
|
| 88 | + } |
|
| 88 | 89 | return parent::__get($name); |
| 89 | 90 | } |
| 90 | 91 | |
@@ -92,10 +93,11 @@ discard block |
||
| 92 | 93 | { |
| 93 | 94 | $model = $this->getModel(); |
| 94 | 95 | $attrs = $model->attributes(); |
| 95 | - if (in_array($name, $attrs)) |
|
| 96 | - $model->$name = $value; |
|
| 97 | - else |
|
| 98 | - parent::__set($name, $value); |
|
| 96 | + if (in_array($name, $attrs)) { |
|
| 97 | + $model->$name = $value; |
|
| 98 | + } else { |
|
| 99 | + parent::__set($name, $value); |
|
| 100 | + } |
|
| 99 | 101 | } |
| 100 | 102 | |
| 101 | 103 | /** |
@@ -106,8 +108,9 @@ discard block |
||
| 106 | 108 | */ |
| 107 | 109 | protected function getPhoebeType() |
| 108 | 110 | { |
| 109 | - if (empty($this->phoebeType)) |
|
| 110 | - throw new \RuntimeException('The phoebeType needs to be set during construction'); |
|
| 111 | + if (empty($this->phoebeType)) { |
|
| 112 | + throw new \RuntimeException('The phoebeType needs to be set during construction'); |
|
| 113 | + } |
|
| 111 | 114 | return $this->phoebeType; |
| 112 | 115 | } |
| 113 | 116 | |
@@ -119,8 +122,9 @@ discard block |
||
| 119 | 122 | */ |
| 120 | 123 | protected function getClassType() |
| 121 | 124 | { |
| 122 | - if (empty($this->classType)) |
|
| 123 | - throw new \RuntimeException('The classType needs to be set during construction'); |
|
| 125 | + if (empty($this->classType)) { |
|
| 126 | + throw new \RuntimeException('The classType needs to be set during construction'); |
|
| 127 | + } |
|
| 124 | 128 | return $this->classType; |
| 125 | 129 | } |
| 126 | 130 | |
@@ -132,8 +136,9 @@ discard block |
||
| 132 | 136 | */ |
| 133 | 137 | protected function getClassVersion() |
| 134 | 138 | { |
| 135 | - if (empty($this->classVersion)) |
|
| 136 | - throw new \RuntimeException('The classVersion needs to be set during construction'); |
|
| 139 | + if (empty($this->classVersion)) { |
|
| 140 | + throw new \RuntimeException('The classVersion needs to be set during construction'); |
|
| 141 | + } |
|
| 137 | 142 | return $this->classVersion; |
| 138 | 143 | } |
| 139 | 144 | |
@@ -172,8 +177,9 @@ discard block |
||
| 172 | 177 | */ |
| 173 | 178 | protected function getModel() |
| 174 | 179 | { |
| 175 | - if (!$this->_model) |
|
| 176 | - throw new \RuntimeException('The model has not yet been set'); |
|
| 180 | + if (!$this->_model) { |
|
| 181 | + throw new \RuntimeException('The model has not yet been set'); |
|
| 182 | + } |
|
| 177 | 183 | return $this->_model; |
| 178 | 184 | } |
| 179 | 185 | |
@@ -183,8 +189,9 @@ discard block |
||
| 183 | 189 | */ |
| 184 | 190 | protected function getModelAttributes() |
| 185 | 191 | { |
| 186 | - if ($this->_model) |
|
| 187 | - return $this->_model->attributes; |
|
| 192 | + if ($this->_model) { |
|
| 193 | + return $this->_model->attributes; |
|
| 194 | + } |
|
| 188 | 195 | return []; |
| 189 | 196 | } |
| 190 | 197 | |
@@ -197,8 +204,9 @@ discard block |
||
| 197 | 204 | { |
| 198 | 205 | $model = $this->getModel(); |
| 199 | 206 | $model->deleted = 1; |
| 200 | - if ($model->save()) |
|
| 201 | - return true; |
|
| 207 | + if ($model->save()) { |
|
| 208 | + return true; |
|
| 209 | + } |
|
| 202 | 210 | return $model->errors; |
| 203 | 211 | } |
| 204 | 212 | |
@@ -211,8 +219,9 @@ discard block |
||
| 211 | 219 | { |
| 212 | 220 | $model = $this->getModel(); |
| 213 | 221 | $model->deleted = 0; |
| 214 | - if ($model->save()) |
|
| 215 | - return true; |
|
| 222 | + if ($model->save()) { |
|
| 223 | + return true; |
|
| 224 | + } |
|
| 216 | 225 | return $model->errors; |
| 217 | 226 | } |
| 218 | 227 | |
@@ -228,10 +237,11 @@ discard block |
||
| 228 | 237 | 'phoebe_type'=>$this->getPhoebeType(), |
| 229 | 238 | 'class_type'=>$classType |
| 230 | 239 | ]); |
| 231 | - if ($version) |
|
| 232 | - $query->andWhere(['version'=>$version]); |
|
| 233 | - else |
|
| 234 | - $query->limit(1)->orderBy('version DESC'); |
|
| 240 | + if ($version) { |
|
| 241 | + $query->andWhere(['version'=>$version]); |
|
| 242 | + } else { |
|
| 243 | + $query->limit(1)->orderBy('version DESC'); |
|
| 244 | + } |
|
| 235 | 245 | |
| 236 | 246 | return $query->one(); |
| 237 | 247 | } |
@@ -268,8 +278,9 @@ discard block |
||
| 268 | 278 | ->andWhere('b.version IS NULL') |
| 269 | 279 | ->all(); |
| 270 | 280 | $classes = []; |
| 271 | - foreach ($models as $model) |
|
| 272 | - $classes[$model->class_type] = $model; |
|
| 281 | + foreach ($models as $model) { |
|
| 282 | + $classes[$model->class_type] = $model; |
|
| 283 | + } |
|
| 273 | 284 | return $classes; |
| 274 | 285 | } |
| 275 | 286 | |
@@ -291,16 +302,18 @@ discard block |
||
| 291 | 302 | */ |
| 292 | 303 | protected function getTableRowReplaceSql($table, $row) |
| 293 | 304 | { |
| 294 | - if (!is_array($row)) |
|
| 295 | - $row = $row->toArray(); |
|
| 305 | + if (!is_array($row)) { |
|
| 306 | + $row = $row->toArray(); |
|
| 307 | + } |
|
| 296 | 308 | $fields = []; |
| 297 | 309 | $values = []; |
| 298 | 310 | foreach ($row as $f=>$v) { |
| 299 | 311 | $fields[]=$f; |
| 300 | 312 | $values[] = $this->pdoQuote($v); |
| 301 | 313 | } |
| 302 | - if (count($fields)) |
|
| 303 | - return "REPLACE INTO `$table` (`".(implode('`,`',$fields)).'`) VALUES ('.(implode(",",$values)).");"; |
|
| 314 | + if (count($fields)) { |
|
| 315 | + return "REPLACE INTO `$table` (`".(implode('`,`',$fields)).'`) VALUES ('.(implode(",",$values)).");"; |
|
| 316 | + } |
|
| 304 | 317 | return null; |
| 305 | 318 | } |
| 306 | 319 | |
@@ -336,8 +349,9 @@ discard block |
||
| 336 | 349 | ]; |
| 337 | 350 | // convert a request for overrides to serialised_overrides |
| 338 | 351 | if ($fields) { |
| 339 | - if (in_array('overrides', $fields)) |
|
| 340 | - $fields[] ='serialised_overrides'; |
|
| 352 | + if (in_array('overrides', $fields)) { |
|
| 353 | + $fields[] ='serialised_overrides'; |
|
| 354 | + } |
|
| 341 | 355 | $selectFields = array_intersect($selectFields, $fields); |
| 342 | 356 | } |
| 343 | 357 | $selector = !empty($filters['selector']) ? $filters['selector'] : ''; |
@@ -366,10 +380,12 @@ discard block |
||
| 366 | 380 | */ |
| 367 | 381 | private function pdoQuote($value) |
| 368 | 382 | { |
| 369 | - if (is_array($value)) |
|
| 370 | - $value = json_encode($value); |
|
| 371 | - if (is_null($value)) |
|
| 372 | - return 'null'; |
|
| 383 | + if (is_array($value)) { |
|
| 384 | + $value = json_encode($value); |
|
| 385 | + } |
|
| 386 | + if (is_null($value)) { |
|
| 387 | + return 'null'; |
|
| 388 | + } |
|
| 373 | 389 | return neon()->db->pdo->quote($value); |
| 374 | 390 | } |
| 375 | 391 | |