@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | public static function addMigration($direction, $migration) |
27 | 27 | { |
28 | - switch($direction) { |
|
28 | + switch ($direction) { |
|
29 | 29 | case 'up': |
30 | 30 | self::$upMigrations[] = $migration; |
31 | 31 | break; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * requests to the database within one call |
23 | 23 | * @var array |
24 | 24 | */ |
25 | - private static $_mapResultsCache=[]; |
|
25 | + private static $_mapResultsCache = []; |
|
26 | 26 | /** |
27 | 27 | * The set of map requests |
28 | 28 | * An array with the requests and the maximum number in the chain |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * @inheritdoc |
47 | 47 | */ |
48 | - public function getObjectMap($classType, $filters=[], $fields=[], $start=0, $length=1000, $includeDeleted=false) |
|
48 | + public function getObjectMap($classType, $filters = [], $fields = [], $start = 0, $length = 1000, $includeDeleted = false) |
|
49 | 49 | { |
50 | 50 | if (!$classType) |
51 | 51 | throw new \InvalidArgumentException("Invalid classType '$classType' in getObjectMap. Correct calling code"); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $cacheKey = md5(serialize(func_get_args())); |
54 | 54 | if (empty(self::$_mapResultsCache[$cacheKey])) { |
55 | 55 | try { |
56 | - $limit = ['start' => max(0, (integer)$start), 'length' => min(1000, (integer)$length)]; |
|
56 | + $limit = ['start' => max(0, (integer) $start), 'length' => min(1000, (integer) $length)]; |
|
57 | 57 | $classType = $this->canonicaliseRef($classType); |
58 | 58 | $fieldsClause = ''; |
59 | 59 | $linkJoins = []; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $filterClause = ''; |
110 | 110 | $filterValues = []; |
111 | 111 | if ($filters) { |
112 | - $ddsObjectFields = ['_uuid','_created','_deleted','_updated']; |
|
112 | + $ddsObjectFields = ['_uuid', '_created', '_deleted', '_updated']; |
|
113 | 113 | // whitelist filter keys to prevent sql injection |
114 | 114 | $members = $this->getClassMembers($classType); |
115 | 115 | $filterSubClause = []; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $filterValues[":$field$vcount"] = $v; |
132 | 132 | $vcount++; |
133 | 133 | } |
134 | - $inClause = implode(',',$inClause); |
|
134 | + $inClause = implode(',', $inClause); |
|
135 | 135 | if (!empty($members[$field]) && $members[$field]['data_type_ref'] == 'link_multi') { |
136 | 136 | $linkName = "link$field"; |
137 | 137 | if (!isset($linkJoins[$linkName])) |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | $filterSubClause[] = "AND $keyClause IN ($inClause)"; |
142 | 142 | } |
143 | 143 | } |
144 | - $filterClause = implode (' ', $filterSubClause); |
|
144 | + $filterClause = implode(' ', $filterSubClause); |
|
145 | 145 | } |
146 | 146 | $linkJoinsClause = implode(' ', $linkJoins); |
147 | 147 | |
148 | - $query = "SELECT DISTINCT `o`.`_uuid`, $fieldsClause FROM `dds_object` `o` LEFT JOIN `$table` `t` ON `o`.`_uuid`=`t`.`_uuid` " . |
|
149 | - "$linkJoinsClause WHERE `o`.`_class_type` = '$classType' $filterClause $notDeleted ORDER BY $fieldsClause " . |
|
148 | + $query = "SELECT DISTINCT `o`.`_uuid`, $fieldsClause FROM `dds_object` `o` LEFT JOIN `$table` `t` ON `o`.`_uuid`=`t`.`_uuid` ". |
|
149 | + "$linkJoinsClause WHERE `o`.`_class_type` = '$classType' $filterClause $notDeleted ORDER BY $fieldsClause ". |
|
150 | 150 | "LIMIT $limit[start], $limit[length]"; |
151 | 151 | $command = neon()->db->createCommand($query); |
152 | 152 | if ($filters) |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | unset($r['_uuid']); |
159 | 159 | |
160 | 160 | // set the map |
161 | - $map[$uuid] = (count($fields)==1) ? current($r) : $r; |
|
161 | + $map[$uuid] = (count($fields) == 1) ? current($r) : $r; |
|
162 | 162 | } |
163 | 163 | self::$_mapResultsCache[$cacheKey] = $map; |
164 | 164 | } catch (\Exception $e) { |
165 | 165 | $errorMessage = "Exception during getting a map. This may be caused by empty filters - you cannot filter on null. ". |
166 | - "Your filters were: ".print_r($filters,true).". The error message is ".$e->getMessage(); |
|
166 | + "Your filters were: ".print_r($filters, true).". The error message is ".$e->getMessage(); |
|
167 | 167 | \Neon::error($errorMessage, 'DDS'); |
168 | 168 | debug_message($errorMessage); |
169 | 169 | return []; |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | /** |
176 | 176 | * @inheritdoc |
177 | 177 | */ |
178 | - public function makeMapLookupRequest($objectUuids, $chainMapFields=[], $classType=null) |
|
178 | + public function makeMapLookupRequest($objectUuids, $chainMapFields = [], $classType = null) |
|
179 | 179 | { |
180 | 180 | if (empty($objectUuids)) |
181 | 181 | return null; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | foreach ($linkedMembers as $lm) { |
199 | 199 | $requestKeys[] = $this->makeMapChainLookupRequest($objectUuids, [$lm]); |
200 | 200 | } |
201 | - return implode('|',$requestKeys); |
|
201 | + return implode('|', $requestKeys); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | foreach ($partials[0] as $u=>$p) { |
218 | 218 | foreach ($p as $i=>$v) { |
219 | 219 | if ($this->isUuid($v)) { |
220 | - for ($i=1; $i<count($requestKeys); $i++) { |
|
220 | + for ($i = 1; $i < count($requestKeys); $i++) { |
|
221 | 221 | if (array_key_exists($v, $partials[$i][1])) { |
222 | 222 | $partials[0][$u][$i] = $partials[$i][1][$v]; |
223 | 223 | continue; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | /** |
234 | 234 | * @inheritdoc |
235 | 235 | */ |
236 | - public function makeMapChainLookupRequest($objectUuids, $chainMembers=[], $chainMapFields=[], $inReverse=false) |
|
236 | + public function makeMapChainLookupRequest($objectUuids, $chainMembers = [], $chainMapFields = [], $inReverse = false) |
|
237 | 237 | { |
238 | 238 | if (empty($objectUuids)) |
239 | 239 | return null; |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $this->getMapLookupByLevel($chain); |
274 | 274 | foreach ($chain as $k=>$r) { |
275 | 275 | if ($r['next_uuid']) |
276 | - $requests['chains'][($i+1)][$k]['uuid'] = $r['next_uuid']; |
|
276 | + $requests['chains'][($i + 1)][$k]['uuid'] = $r['next_uuid']; |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | $this->convertMapRequestResults(); |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $requestsByUuid[$r['uuid']][] = $r; |
333 | 333 | } |
334 | 334 | $objectRows = DdsObject::find() |
335 | - ->select(['_uuid','_class_type']) |
|
335 | + ->select(['_uuid', '_class_type']) |
|
336 | 336 | ->where(['_uuid'=>$endpoints]) |
337 | 337 | ->andWhere(['_deleted'=>0]) |
338 | 338 | ->asArray() |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | |
353 | 353 | // now find all the maps members for the required classes |
354 | 354 | $mapFields = DdsMember::find() |
355 | - ->select(['class_type','member_ref']) |
|
355 | + ->select(['class_type', 'member_ref']) |
|
356 | 356 | ->where(['class_type'=>$classTypes, 'deleted'=>0, 'map_field'=>1]) |
357 | 357 | ->asArray() |
358 | 358 | ->all(); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | foreach ($objectsByClassMapsAndChain as $class => $chainMapObjects) { |
369 | 369 | foreach ($chainMapObjects as $chain => $mapObjects) { |
370 | 370 | foreach ($mapObjects as $mapField => $objectUuids) { |
371 | - $objs = "'".implode("','",$objectUuids)."'"; |
|
371 | + $objs = "'".implode("','", $objectUuids)."'"; |
|
372 | 372 | // make sure a map field can be created |
373 | 373 | $mapFieldsClause = ''; |
374 | 374 | if ($mapField === self::$_defaultMapChain) { |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | $mapFieldsClause = "CAST(`$mapsByClass[$class]` AS CHAR)"; |
378 | 378 | } else { |
379 | 379 | $mapFieldsClause = "CONCAT_WS('$hackySeparator'"; |
380 | - foreach (explode(',',$mapField) as $m) { |
|
380 | + foreach (explode(',', $mapField) as $m) { |
|
381 | 381 | $mapFieldsClause .= ",CAST(`$m` AS CHAR)"; |
382 | 382 | } |
383 | 383 | $mapFieldsClause .= ')'; |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | $mapsByChainAndUuid = []; |
403 | 403 | foreach ($maps as $m) { |
404 | 404 | if (strpos($m['map'], $hackySeparator) !== false) { |
405 | - $m['map'] = explode($hackySeparator,$m['map']); |
|
405 | + $m['map'] = explode($hackySeparator, $m['map']); |
|
406 | 406 | } |
407 | 407 | $mapsByChainAndUuid[$m['chain']][$m['mapFields']][$m['uuid']] = $m; |
408 | 408 | } |
@@ -473,14 +473,14 @@ discard block |
||
473 | 473 | $chainCount = count($chainMembers); |
474 | 474 | // split the chain up into requests per chain level if there are any |
475 | 475 | foreach ($chainMembers as $i=>$mc) { |
476 | - $mapFieldKey = ($i == 0 ? 0 : $chainMembers[$i-1]); |
|
477 | - $mapFields = !empty($chainMapFields[$mapFieldKey]) ? implode(',',$chainMapFields[$mapFieldKey]) : self::$_defaultMapChain; |
|
478 | - $requests['chains'][$i][$requestKey] = ['uuid'=>($i===0?$objectUuid:null), 'map'=>null, 'mapFields'=>$mapFields, 'chain'=>$mc, 'key'=>$requestKey]; |
|
476 | + $mapFieldKey = ($i == 0 ? 0 : $chainMembers[$i - 1]); |
|
477 | + $mapFields = !empty($chainMapFields[$mapFieldKey]) ? implode(',', $chainMapFields[$mapFieldKey]) : self::$_defaultMapChain; |
|
478 | + $requests['chains'][$i][$requestKey] = ['uuid'=>($i === 0 ? $objectUuid : null), 'map'=>null, 'mapFields'=>$mapFields, 'chain'=>$mc, 'key'=>$requestKey]; |
|
479 | 479 | } |
480 | 480 | // add a final chain for the last item |
481 | - $mapFieldKey = ($chainCount == 0 ? 0 : $chainMembers[$chainCount-1]); |
|
482 | - $mapFields = !empty($chainMapFields[$mapFieldKey]) ? implode(',',$chainMapFields[$mapFieldKey]) : self::$_defaultMapChain; |
|
483 | - $requests['chains'][$chainCount][$requestKey] = ['uuid'=>($chainCount===0?$objectUuid:null), 'map'=>null, 'mapFields'=>$mapFields, 'chain'=>'__FINAL__', 'key'=>$requestKey]; |
|
481 | + $mapFieldKey = ($chainCount == 0 ? 0 : $chainMembers[$chainCount - 1]); |
|
482 | + $mapFields = !empty($chainMapFields[$mapFieldKey]) ? implode(',', $chainMapFields[$mapFieldKey]) : self::$_defaultMapChain; |
|
483 | + $requests['chains'][$chainCount][$requestKey] = ['uuid'=>($chainCount === 0 ? $objectUuid : null), 'map'=>null, 'mapFields'=>$mapFields, 'chain'=>'__FINAL__', 'key'=>$requestKey]; |
|
484 | 484 | |
485 | 485 | // and add the requestKey so we don't calculate this again |
486 | 486 | $requests['keys'][$requestKey] = [ |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | $results = &static::$_mapResults; |
510 | 510 | |
511 | 511 | $tempResults = []; |
512 | - if (count($chains)===0) |
|
512 | + if (count($chains) === 0) |
|
513 | 513 | return; |
514 | 514 | foreach ($chains as $level => $maps) { |
515 | 515 | foreach ($maps as $key=>$map) { |
@@ -47,8 +47,9 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function getObjectMap($classType, $filters=[], $fields=[], $start=0, $length=1000, $includeDeleted=false) |
49 | 49 | { |
50 | - if (!$classType) |
|
51 | - throw new \InvalidArgumentException("Invalid classType '$classType' in getObjectMap. Correct calling code"); |
|
50 | + if (!$classType) { |
|
51 | + throw new \InvalidArgumentException("Invalid classType '$classType' in getObjectMap. Correct calling code"); |
|
52 | + } |
|
52 | 53 | |
53 | 54 | $cacheKey = md5(serialize(func_get_args())); |
54 | 55 | if (empty(self::$_mapResultsCache[$cacheKey])) { |
@@ -73,8 +74,9 @@ discard block |
||
73 | 74 | $class2Member = Arr::index($linkedMemberClasses, 'class_type'); |
74 | 75 | foreach ($linkedMembers as $lm) { |
75 | 76 | // only try to link through to tables that are within daedalus |
76 | - if (isset($class2Member[$lm['link_class']])) |
|
77 | - $field2link[$lm['member_ref']] = $class2Member[$lm['link_class']]; |
|
77 | + if (isset($class2Member[$lm['link_class']])) { |
|
78 | + $field2link[$lm['member_ref']] = $class2Member[$lm['link_class']]; |
|
79 | + } |
|
78 | 80 | } |
79 | 81 | } |
80 | 82 | foreach ($fields as $field) { |
@@ -82,9 +84,9 @@ discard block |
||
82 | 84 | $fl = $field2link[$field]; |
83 | 85 | $table = $this->getTableFromClassType($fl['class_type']); |
84 | 86 | $getFields[] = "`$table`.`$fl[member_ref]`"; |
85 | - if ($linkedMembers[$field]['data_type_ref'] == 'link_uni') |
|
86 | - $linkJoins[$table] = "LEFT JOIN `$table` ON `t`.`$field`=`$table`.`_uuid`"; |
|
87 | - else { |
|
87 | + if ($linkedMembers[$field]['data_type_ref'] == 'link_uni') { |
|
88 | + $linkJoins[$table] = "LEFT JOIN `$table` ON `t`.`$field`=`$table`.`_uuid`"; |
|
89 | + } else { |
|
88 | 90 | $linkName = 'link'.$field; |
89 | 91 | $linkJoins[$linkName] = "LEFT JOIN `dds_link` `$linkName` ON (`o`.`_uuid`=`$linkName`.`from_id` AND `$linkName`.`from_member`='$field')"; |
90 | 92 | $linkJoins[$table] = "LEFT JOIN `$table` ON `$linkName`.`to_id` =`$table`.`_uuid`"; |
@@ -96,8 +98,9 @@ discard block |
||
96 | 98 | $fieldsClause = implode(', ', $getFields); |
97 | 99 | } else { |
98 | 100 | $member = $this->getMapMemberForClass($classType); |
99 | - if (!$member) |
|
100 | - throw new \RuntimeException("There is no mappable member field set on class $classType"); |
|
101 | + if (!$member) { |
|
102 | + throw new \RuntimeException("There is no mappable member field set on class $classType"); |
|
103 | + } |
|
101 | 104 | // set this as an array for later |
102 | 105 | $fields = [$member['member_ref']]; |
103 | 106 | $fieldsClause = "`t`.`$member[member_ref]`"; |
@@ -116,12 +119,14 @@ discard block |
||
116 | 119 | foreach ($filters as $field=>$value) { |
117 | 120 | if ($field == '_map_field_') { |
118 | 121 | $mapMember = $this->getMapMemberForClass($classType); |
119 | - if ($mapMember && $value) |
|
120 | - $filterSubClause[] = "AND `t`.`$mapMember[member_ref]` LIKE '%$value%'"; |
|
122 | + if ($mapMember && $value) { |
|
123 | + $filterSubClause[] = "AND `t`.`$mapMember[member_ref]` LIKE '%$value%'"; |
|
124 | + } |
|
121 | 125 | continue; |
122 | 126 | } |
123 | - if (!(isset($members[$field]) || in_array($field, $ddsObjectFields))) |
|
124 | - continue; |
|
127 | + if (!(isset($members[$field]) || in_array($field, $ddsObjectFields))) { |
|
128 | + continue; |
|
129 | + } |
|
125 | 130 | $keyClause = (in_array($field, $ddsObjectFields)) ? "`o`.`$field`" : "`t`.`$field`"; |
126 | 131 | $value = is_array($value) ? $value : [$value]; |
127 | 132 | $vcount = 1; |
@@ -134,8 +139,9 @@ discard block |
||
134 | 139 | $inClause = implode(',',$inClause); |
135 | 140 | if (!empty($members[$field]) && $members[$field]['data_type_ref'] == 'link_multi') { |
136 | 141 | $linkName = "link$field"; |
137 | - if (!isset($linkJoins[$linkName])) |
|
138 | - $linkJoins[$linkName] = "LEFT JOIN `dds_link` `$linkName` ON (`o`.`_uuid`=`$linkName`.`from_id` AND `$linkName`.`from_member`='$field')"; |
|
142 | + if (!isset($linkJoins[$linkName])) { |
|
143 | + $linkJoins[$linkName] = "LEFT JOIN `dds_link` `$linkName` ON (`o`.`_uuid`=`$linkName`.`from_id` AND `$linkName`.`from_member`='$field')"; |
|
144 | + } |
|
139 | 145 | $filterSubClause[] = "AND `$linkName`.`to_id` IN ($inClause)"; |
140 | 146 | } else { |
141 | 147 | $filterSubClause[] = "AND $keyClause IN ($inClause)"; |
@@ -149,8 +155,9 @@ discard block |
||
149 | 155 | "$linkJoinsClause WHERE `o`.`_class_type` = '$classType' $filterClause $notDeleted ORDER BY $fieldsClause " . |
150 | 156 | "LIMIT $limit[start], $limit[length]"; |
151 | 157 | $command = neon()->db->createCommand($query); |
152 | - if ($filters) |
|
153 | - $command->bindValues($filterValues); |
|
158 | + if ($filters) { |
|
159 | + $command->bindValues($filterValues); |
|
160 | + } |
|
154 | 161 | $rows = $command->queryAll(); |
155 | 162 | foreach ($rows as $r) { |
156 | 163 | // extract out the uuid result |
@@ -177,8 +184,9 @@ discard block |
||
177 | 184 | */ |
178 | 185 | public function makeMapLookupRequest($objectUuids, $chainMapFields=[], $classType=null) |
179 | 186 | { |
180 | - if (empty($objectUuids)) |
|
181 | - return null; |
|
187 | + if (empty($objectUuids)) { |
|
188 | + return null; |
|
189 | + } |
|
182 | 190 | /* See if there are any linked fields that we need to get |
183 | 191 | The implementation here is somewhat crude. Generally speaking we are probably looking |
184 | 192 | at needing to implement graphql or something similar to easily manage all the possible |
@@ -235,8 +243,9 @@ discard block |
||
235 | 243 | */ |
236 | 244 | public function makeMapChainLookupRequest($objectUuids, $chainMembers=[], $chainMapFields=[], $inReverse=false) |
237 | 245 | { |
238 | - if (empty($objectUuids)) |
|
239 | - return null; |
|
246 | + if (empty($objectUuids)) { |
|
247 | + return null; |
|
248 | + } |
|
240 | 249 | |
241 | 250 | // create a request key based on the input parameters |
242 | 251 | $requestKey = md5(serialize(func_get_args())); |
@@ -265,15 +274,17 @@ discard block |
||
265 | 274 | { |
266 | 275 | $requests = &static::$_mapRequests; |
267 | 276 | // check we have any requests to make |
268 | - if (count($requests['chains']) === 0) |
|
269 | - return; |
|
277 | + if (count($requests['chains']) === 0) { |
|
278 | + return; |
|
279 | + } |
|
270 | 280 | // run through the chain and get the reverse maps for each level of requests |
271 | 281 | foreach ($requests['chains'] as $i=>&$chain) { |
272 | 282 | // the requests will be filled in during this call |
273 | 283 | $this->getMapLookupByLevel($chain); |
274 | 284 | foreach ($chain as $k=>$r) { |
275 | - if ($r['next_uuid']) |
|
276 | - $requests['chains'][($i+1)][$k]['uuid'] = $r['next_uuid']; |
|
285 | + if ($r['next_uuid']) { |
|
286 | + $requests['chains'][($i+1)][$k]['uuid'] = $r['next_uuid']; |
|
287 | + } |
|
277 | 288 | } |
278 | 289 | } |
279 | 290 | $this->convertMapRequestResults(); |
@@ -322,8 +333,9 @@ discard block |
||
322 | 333 | */ |
323 | 334 | private function getMapLookupByLevel(&$requests) |
324 | 335 | { |
325 | - if (empty($requests)) |
|
326 | - return; |
|
336 | + if (empty($requests)) { |
|
337 | + return; |
|
338 | + } |
|
327 | 339 | |
328 | 340 | $endpoints = []; |
329 | 341 | $requestsByUuid = []; |
@@ -372,8 +384,9 @@ discard block |
||
372 | 384 | // make sure a map field can be created |
373 | 385 | $mapFieldsClause = ''; |
374 | 386 | if ($mapField === self::$_defaultMapChain) { |
375 | - if (!isset($mapsByClass[$class])) |
|
376 | - continue; |
|
387 | + if (!isset($mapsByClass[$class])) { |
|
388 | + continue; |
|
389 | + } |
|
377 | 390 | $mapFieldsClause = "CAST(`$mapsByClass[$class]` AS CHAR)"; |
378 | 391 | } else { |
379 | 392 | $mapFieldsClause = "CONCAT_WS('$hackySeparator'"; |
@@ -436,8 +449,9 @@ discard block |
||
436 | 449 | */ |
437 | 450 | private function addRequest($requestKey, $objectUuid, $chainMembers, $chainMapFields, $inReverse) |
438 | 451 | { |
439 | - if (empty($objectUuid)) |
|
440 | - return; |
|
452 | + if (empty($objectUuid)) { |
|
453 | + return; |
|
454 | + } |
|
441 | 455 | |
442 | 456 | // Treat a request for objectUuids as multiple single object map requests |
443 | 457 | // TODO NJ 20190415 - make this work properly with multiple uuids without needing multiple requests |
@@ -466,8 +480,9 @@ discard block |
||
466 | 480 | $requests = &static::$_mapRequests; // to make the code slightly shorter |
467 | 481 | |
468 | 482 | // check to see if the request has already added |
469 | - if (isset($requests['keys'][$requestKey])) |
|
470 | - return; |
|
483 | + if (isset($requests['keys'][$requestKey])) { |
|
484 | + return; |
|
485 | + } |
|
471 | 486 | |
472 | 487 | // calculate how many chains we are going down |
473 | 488 | $chainCount = count($chainMembers); |
@@ -509,8 +524,9 @@ discard block |
||
509 | 524 | $results = &static::$_mapResults; |
510 | 525 | |
511 | 526 | $tempResults = []; |
512 | - if (count($chains)===0) |
|
513 | - return; |
|
527 | + if (count($chains)===0) { |
|
528 | + return; |
|
529 | + } |
|
514 | 530 | foreach ($chains as $level => $maps) { |
515 | 531 | foreach ($maps as $key=>$map) { |
516 | 532 | $tempResults[$key][$level][$map['uuid']] = $map['map']; |
@@ -31,8 +31,9 @@ |
||
31 | 31 | */ |
32 | 32 | public function hasChangeLog() |
33 | 33 | { |
34 | - if (isset($this->attributes['change_log'])) |
|
35 | - return $this->attributes['change_log']; |
|
34 | + if (isset($this->attributes['change_log'])) { |
|
35 | + return $this->attributes['change_log']; |
|
36 | + } |
|
36 | 37 | return false; |
37 | 38 | } |
38 | 39 |
@@ -86,7 +86,7 @@ |
||
86 | 86 | { |
87 | 87 | // return choices as decoded json or null |
88 | 88 | if (!empty($this->choices)) |
89 | - $this->choices = json_decode($this->choices,true); |
|
89 | + $this->choices = json_decode($this->choices, true); |
|
90 | 90 | parent::afterFind(); |
91 | 91 | } |
92 | 92 |
@@ -72,10 +72,11 @@ discard block |
||
72 | 72 | public function beforeSave($insert) |
73 | 73 | { |
74 | 74 | // choices can only be an array and are stored as JSON |
75 | - if (is_array($this->choices)) |
|
76 | - $this->choices = json_encode($this->choices); |
|
77 | - else |
|
78 | - $this->choices = null; |
|
75 | + if (is_array($this->choices)) { |
|
76 | + $this->choices = json_encode($this->choices); |
|
77 | + } else { |
|
78 | + $this->choices = null; |
|
79 | + } |
|
79 | 80 | return parent::beforeSave($insert); |
80 | 81 | } |
81 | 82 | |
@@ -85,8 +86,9 @@ discard block |
||
85 | 86 | public function afterFind() |
86 | 87 | { |
87 | 88 | // return choices as decoded json or null |
88 | - if (!empty($this->choices)) |
|
89 | - $this->choices = json_decode($this->choices,true); |
|
89 | + if (!empty($this->choices)) { |
|
90 | + $this->choices = json_decode($this->choices,true); |
|
91 | + } |
|
90 | 92 | parent::afterFind(); |
91 | 93 | } |
92 | 94 |
@@ -39,8 +39,9 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function isMemberRefUnique($classType, $candidate) |
41 | 41 | { |
42 | - if ($this->isClassTypeUnique($classType)) |
|
43 | - throw new \InvalidArgumentException("Class type ".$this->canonicaliseRef($classType)." unknown"); |
|
42 | + if ($this->isClassTypeUnique($classType)) { |
|
43 | + throw new \InvalidArgumentException("Class type ".$this->canonicaliseRef($classType)." unknown"); |
|
44 | + } |
|
44 | 45 | $mr = $this->canonicaliseRef($candidate); |
45 | 46 | $member = DdsMember::find()->where(['class_type'=>$classType, 'member_ref'=>$mr])->one(); |
46 | 47 | return ($member == null); |
@@ -65,15 +66,17 @@ discard block |
||
65 | 66 | public function listClasses($module, &$total, $includeDeleted=false, $start=0, $length=100, $orderBy='label') |
66 | 67 | { |
67 | 68 | $query = $this->_getClassesQuery($module, $includeDeleted); |
68 | - if ($start == 0) |
|
69 | - $total = (int) $query->count(); |
|
69 | + if ($start == 0) { |
|
70 | + $total = (int) $query->count(); |
|
71 | + } |
|
70 | 72 | $results = $query->asArray() |
71 | 73 | ->offset($start) |
72 | 74 | ->limit($length) |
73 | 75 | ->orderBy($orderBy) |
74 | 76 | ->all(); |
75 | - foreach ($results as &$r) |
|
76 | - $r['count_current'] = $r['count_total'] - $r['count_deleted']; |
|
77 | + foreach ($results as &$r) { |
|
78 | + $r['count_current'] = $r['count_total'] - $r['count_deleted']; |
|
79 | + } |
|
77 | 80 | return $results; |
78 | 81 | } |
79 | 82 | |
@@ -95,8 +98,9 @@ discard block |
||
95 | 98 | ->asArray() |
96 | 99 | ->all(); |
97 | 100 | $map = []; |
98 | - foreach ($mappable as $m) |
|
99 | - $map[$m['class_type']] = $m['label']; |
|
101 | + foreach ($mappable as $m) { |
|
102 | + $map[$m['class_type']] = $m['label']; |
|
103 | + } |
|
100 | 104 | return $map; |
101 | 105 | } |
102 | 106 | |
@@ -116,13 +120,15 @@ discard block |
||
116 | 120 | public function addClass(&$classType, $module) |
117 | 121 | { |
118 | 122 | $classType = $this->canonicaliseRef($classType); |
119 | - if (DdsClass::findOne(['class_type'=>$classType]) !== null) |
|
120 | - throw new \InvalidArgumentException("The class $classType already exists"); |
|
123 | + if (DdsClass::findOne(['class_type'=>$classType]) !== null) { |
|
124 | + throw new \InvalidArgumentException("The class $classType already exists"); |
|
125 | + } |
|
121 | 126 | $c = new DdsClass(); |
122 | 127 | $c->class_type = $classType; |
123 | 128 | $c->module = (empty($module) ? null : $module); |
124 | - if (!$c->save()) |
|
125 | - throw new \RuntimeException("Couldn't save the class: ".print_r($c->errors,true)); |
|
129 | + if (!$c->save()) { |
|
130 | + throw new \RuntimeException("Couldn't save the class: ".print_r($c->errors,true)); |
|
131 | + } |
|
126 | 132 | $upSql = $this->getClassTypeMigrationSql($classType); |
127 | 133 | $downSql = "DELETE FROM `dds_class` WHERE `class_type`='$classType';"; |
128 | 134 | $this->storeMigration($upSql, $downSql); |
@@ -137,8 +143,9 @@ discard block |
||
137 | 143 | { |
138 | 144 | if ($this->findClass($classType, $class)) { |
139 | 145 | $data = $class->toArray(); |
140 | - if ($includeMembers) |
|
141 | - $data['members'] = $this->listMembers($class['class_type']); |
|
146 | + if ($includeMembers) { |
|
147 | + $data['members'] = $this->listMembers($class['class_type']); |
|
148 | + } |
|
142 | 149 | return $data; |
143 | 150 | } |
144 | 151 | return null; |
@@ -150,8 +157,9 @@ discard block |
||
150 | 157 | public function editClass($classType, $changes) |
151 | 158 | { |
152 | 159 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'module', 'change_log'])); |
153 | - if (count($allowed)==0) |
|
154 | - return; |
|
160 | + if (count($allowed)==0) { |
|
161 | + return; |
|
162 | + } |
|
155 | 163 | $this->clearClassCache($classType); |
156 | 164 | $downSql = $this->getClassTypeMigrationSql($classType); |
157 | 165 | if ($this->findClass($classType, $class)) { |
@@ -159,8 +167,9 @@ discard block |
||
159 | 167 | $updates = array_diff_assoc($allowed, $class->attributes); |
160 | 168 | if (count($updates)) { |
161 | 169 | $class->attributes = $updates; |
162 | - if (!$class->save()) |
|
163 | - throw new \RuntimeException("Dds: Couldn't update the class '$classType': ".print_r($class->errors)); |
|
170 | + if (!$class->save()) { |
|
171 | + throw new \RuntimeException("Dds: Couldn't update the class '$classType': ".print_r($class->errors)); |
|
172 | + } |
|
164 | 173 | $upSql = $this->getClassTypeMigrationSql($classType); |
165 | 174 | $this->storeMigration($upSql, $downSql); |
166 | 175 | } |
@@ -203,8 +212,9 @@ discard block |
||
203 | 212 | public function destroyClass($classType) |
204 | 213 | { |
205 | 214 | if ($this->findClass($classType, $class)) { |
206 | - if ($this->hasObjects($classType)) |
|
207 | - throw new \RunTimeException("You need to delete all objects before you can destroy a class"); |
|
215 | + if ($this->hasObjects($classType)) { |
|
216 | + throw new \RunTimeException("You need to delete all objects before you can destroy a class"); |
|
217 | + } |
|
208 | 218 | |
209 | 219 | // now delete the rows |
210 | 220 | $members = DdsMember::find()->where(['class_type'=>$class->class_type])->asArray()->all(); |
@@ -216,12 +226,14 @@ discard block |
||
216 | 226 | $errors[] = $e->getMessage(); |
217 | 227 | } |
218 | 228 | } |
219 | - if (count($errors)) |
|
220 | - throw new \RuntimeException("Couldn't destroy all of the members: ".print_r($errors, true)); |
|
229 | + if (count($errors)) { |
|
230 | + throw new \RuntimeException("Couldn't destroy all of the members: ".print_r($errors, true)); |
|
231 | + } |
|
221 | 232 | // now delete the class |
222 | 233 | // can also return 0 - which is valid - false means there has been an error |
223 | - if ($class->delete() === false) |
|
224 | - throw new \RuntimeException("Couldn't destroy the class: ".print_r($class->errors, true)); |
|
234 | + if ($class->delete() === false) { |
|
235 | + throw new \RuntimeException("Couldn't destroy the class: ".print_r($class->errors, true)); |
|
236 | + } |
|
225 | 237 | // and clear away the table |
226 | 238 | $this->dropClassTable($class->class_type); |
227 | 239 | $this->clearClassCache($classType); |
@@ -251,8 +263,9 @@ discard block |
||
251 | 263 | // extract out any additional information |
252 | 264 | $choices = ((!empty($additional['choices']) && is_array($additional['choices'])) ? $additional['choices'] : []); |
253 | 265 | $linkClass = (!empty($additional['link_class']) ? $additional['link_class'] : null); |
254 | - if (DdsMember::findOne(['class_type' => $classType, 'member_ref' => $memberRef])!==null) |
|
255 | - throw new \InvalidArgumentException("The member $memberRef already exists"); |
|
266 | + if (DdsMember::findOne(['class_type' => $classType, 'member_ref' => $memberRef])!==null) { |
|
267 | + throw new \InvalidArgumentException("The member $memberRef already exists"); |
|
268 | + } |
|
256 | 269 | if (in_array($dataTypeRef, ['link_uni', 'link_multi']) && !$linkClass) { |
257 | 270 | throw new \InvalidArgumentException("Link_uni, link_multi data types require a link_class to be passed for member '$classType::$memberRef'. You passed in ".print_r($additional, true)); |
258 | 271 | } |
@@ -265,8 +278,9 @@ discard block |
||
265 | 278 | $member->choices = ($this->memberAllowedChoices($dataTypeRef) ? $choices : null); |
266 | 279 | $member->link_class = ($this->memberAllowedLinks($dataTypeRef) ? $linkClass : null); |
267 | 280 | $member->created = $this->now(); |
268 | - if (!$member->save()) |
|
269 | - throw new \RuntimeException("Couldn't save the member: ".print_r($member->errors, true)); |
|
281 | + if (!$member->save()) { |
|
282 | + throw new \RuntimeException("Couldn't save the member: ".print_r($member->errors, true)); |
|
283 | + } |
|
270 | 284 | |
271 | 285 | // create the migrations |
272 | 286 | $savedMember = $this->getMember($classType, $memberRef); |
@@ -310,12 +324,14 @@ discard block |
||
310 | 324 | { |
311 | 325 | // check that only allowed updates are made |
312 | 326 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'definition', 'choices', 'link_class'])); |
313 | - if (count($allowed)==0) |
|
314 | - return; |
|
327 | + if (count($allowed)==0) { |
|
328 | + return; |
|
329 | + } |
|
315 | 330 | |
316 | 331 | // find the member and remove any illegitamate updates |
317 | - if (!$this->findMember($classType, $memberRef, $member)) |
|
318 | - throw new \InvalidArgumentException("No member found"); |
|
332 | + if (!$this->findMember($classType, $memberRef, $member)) { |
|
333 | + throw new \InvalidArgumentException("No member found"); |
|
334 | + } |
|
319 | 335 | if (isset($allowed['choices'])) { |
320 | 336 | $allowed['choices'] = empty($allowed['choices']) ? [] : $allowed['choices']; |
321 | 337 | if (!(is_array($allowed['choices']) && $this->memberAllowedChoices($member->data_type_ref))) { |
@@ -323,16 +339,18 @@ discard block |
||
323 | 339 | } |
324 | 340 | } |
325 | 341 | |
326 | - if (isset($allowed['link_class']) && !$this->memberAllowedLinks($member->data_type_ref)) |
|
327 | - unset($allowed['link_class']); |
|
342 | + if (isset($allowed['link_class']) && !$this->memberAllowedLinks($member->data_type_ref)) { |
|
343 | + unset($allowed['link_class']); |
|
344 | + } |
|
328 | 345 | |
329 | 346 | // finally check to see if there are any actual updates and if so save the provided updates |
330 | 347 | $updates = $this->getMemberUpdateDifferences($allowed, $member->attributes); |
331 | 348 | if (count($updates)) { |
332 | 349 | $downSql = $this->getTableRowReplaceSql('dds_member', $member); |
333 | 350 | $member->attributes = $updates; |
334 | - if (!$member->save()) |
|
335 | - throw new \RuntimeException("Couldn't update the member: ".print_r ($member->errors, true)); |
|
351 | + if (!$member->save()) { |
|
352 | + throw new \RuntimeException("Couldn't update the member: ".print_r ($member->errors, true)); |
|
353 | + } |
|
336 | 354 | $upSql = $this->getTableRowReplaceSql('dds_member', $member); |
337 | 355 | $this->storeMigration($upSql, $downSql); |
338 | 356 | $this->clearClassMemberCache($classType); |
@@ -344,13 +362,15 @@ discard block |
||
344 | 362 | */ |
345 | 363 | public function setMemberAsMapField($classType, $memberRef) |
346 | 364 | { |
347 | - if (!$this->findMember($classType, $memberRef, $member)) |
|
348 | - throw new \InvalidArgumentException("No member found"); |
|
365 | + if (!$this->findMember($classType, $memberRef, $member)) { |
|
366 | + throw new \InvalidArgumentException("No member found"); |
|
367 | + } |
|
349 | 368 | |
350 | 369 | // find out which member had the map field set for migrations |
351 | 370 | $oldMember = DdsMember::findOne(['class_type'=>$classType, 'map_field'=>1]); |
352 | - if ($oldMember && $oldMember->member_ref == $memberRef) |
|
353 | - return; |
|
371 | + if ($oldMember && $oldMember->member_ref == $memberRef) { |
|
372 | + return; |
|
373 | + } |
|
354 | 374 | $upSql = "UPDATE `dds_member` SET `map_field`=(IF (`member_ref`='$memberRef', 1, 0)) WHERE `class_type`='$classType';"; |
355 | 375 | $downSql = ($oldMember ? "UPDATE `dds_member` SET `map_field`=(IF (`member_ref`='{$oldMember->member_ref}', 1, 0)) WHERE `class_type`='$classType';" : null); |
356 | 376 | neon()->db->createCommand($upSql)->execute(); |
@@ -445,16 +465,18 @@ discard block |
||
445 | 465 | public function addDataType(&$dataTypeRef, $label, $description, $definition, $storageRef) |
446 | 466 | { |
447 | 467 | $dataTypeRef = $this->canonicaliseRef($dataTypeRef); |
448 | - if ($this->findDataType($dataTypeRef)) |
|
449 | - throw new \InvalidArgumentException("The dataType $dataTypeRef already exists"); |
|
468 | + if ($this->findDataType($dataTypeRef)) { |
|
469 | + throw new \InvalidArgumentException("The dataType $dataTypeRef already exists"); |
|
470 | + } |
|
450 | 471 | $dt = new DdsDataType(); |
451 | 472 | $dt->data_type_ref = $dataTypeRef; |
452 | 473 | $dt->label = $label; |
453 | 474 | $dt->description = $description; |
454 | 475 | $dt->definition = $definition; |
455 | 476 | $dt->storage_ref = $storageRef; |
456 | - if (!$dt->save()) |
|
457 | - throw new \RuntimeException("Couldn't create the datatype $dataTypeRef: ".print_r($dt->errors, true)); |
|
477 | + if (!$dt->save()) { |
|
478 | + throw new \RuntimeException("Couldn't create the datatype $dataTypeRef: ".print_r($dt->errors, true)); |
|
479 | + } |
|
458 | 480 | |
459 | 481 | // store the migration |
460 | 482 | $this->findDataType($dataTypeRef, $dt); |
@@ -479,16 +501,18 @@ discard block |
||
479 | 501 | public function editDataType($dataTypeRef, $changes) |
480 | 502 | { |
481 | 503 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'definition'])); |
482 | - if (count($allowed) == 0) |
|
483 | - return; |
|
504 | + if (count($allowed) == 0) { |
|
505 | + return; |
|
506 | + } |
|
484 | 507 | if ($this->findDataType($dataTypeRef, $dataType)) { |
485 | 508 | // make the updates if there is anything to change |
486 | 509 | $updates = array_diff($allowed, $dataType->attributes); |
487 | 510 | if (count($updates)) { |
488 | 511 | $downSql = $this->getTableRowReplaceSql('dds_data_type', $dataType); |
489 | 512 | $dataType->attributes = $updates; |
490 | - if (!$dataType->save()) |
|
491 | - throw new \RuntimeException("Couldn't save the datatype: ".print_r($dataType->errors(),true)); |
|
513 | + if (!$dataType->save()) { |
|
514 | + throw new \RuntimeException("Couldn't save the datatype: ".print_r($dataType->errors(),true)); |
|
515 | + } |
|
492 | 516 | $upSql = $this->getTableRowReplaceSql('dds_data_type', $dataType); |
493 | 517 | $this->storeMigration($upSql, $downSql); |
494 | 518 | } |
@@ -552,8 +576,9 @@ discard block |
||
552 | 576 | private function getClassTypeMigrationSql($classType) |
553 | 577 | { |
554 | 578 | $ddsClass = DdsClass::findOne(['class_type'=>$classType]); |
555 | - if ($ddsClass == null) |
|
556 | - return null; |
|
579 | + if ($ddsClass == null) { |
|
580 | + return null; |
|
581 | + } |
|
557 | 582 | return $this->getTableRowReplaceSql('dds_class', $ddsClass); |
558 | 583 | } |
559 | 584 | |
@@ -603,11 +628,13 @@ discard block |
||
603 | 628 | if (is_array($v)) { |
604 | 629 | $diff = $this->getMemberUpdateDifferences($v, $b[$k]); |
605 | 630 | // we want all of the array if there were any differences |
606 | - if (count($diff)) |
|
607 | - $diffs[$k] = $v; |
|
631 | + if (count($diff)) { |
|
632 | + $diffs[$k] = $v; |
|
633 | + } |
|
608 | 634 | } else { |
609 | - if ((string)$v !== (string)$b[$k]) |
|
610 | - $diffs[$k] = $v; |
|
635 | + if ((string)$v !== (string)$b[$k]) { |
|
636 | + $diffs[$k] = $v; |
|
637 | + } |
|
611 | 638 | } |
612 | 639 | } else { |
613 | 640 | $diffs[$k] = $v; |
@@ -633,8 +660,9 @@ discard block |
||
633 | 660 | $query->andWhere(['deleted' => 0]); |
634 | 661 | } |
635 | 662 | $query->select($select); |
636 | - if ($module != null) |
|
637 | - $query->andWhere(['or', ['module' => $module], ['module' => NULL]]); |
|
663 | + if ($module != null) { |
|
664 | + $query->andWhere(['or', ['module' => $module], ['module' => NULL]]); |
|
665 | + } |
|
638 | 666 | return $query; |
639 | 667 | } |
640 | 668 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * @inheritdoc |
53 | 53 | */ |
54 | - public function countClasses($module=null, $includeDeleted=false) |
|
54 | + public function countClasses($module = null, $includeDeleted = false) |
|
55 | 55 | { |
56 | 56 | $query = $this->_getClassesQuery($module, $includeDeleted); |
57 | 57 | return $query->count(); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * @inheritdoc |
62 | 62 | */ |
63 | - public function listClasses($module, &$total, $includeDeleted=false, $start=0, $length=100, $orderBy='label') |
|
63 | + public function listClasses($module, &$total, $includeDeleted = false, $start = 0, $length = 100, $orderBy = 'label') |
|
64 | 64 | { |
65 | 65 | $query = $this->_getClassesQuery($module, $includeDeleted); |
66 | 66 | if ($start == 0) |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $c->class_type = $classType; |
121 | 121 | $c->module = (empty($module) ? null : $module); |
122 | 122 | if (!$c->save()) |
123 | - throw new \RuntimeException("Couldn't save the class: ".print_r($c->errors,true)); |
|
123 | + throw new \RuntimeException("Couldn't save the class: ".print_r($c->errors, true)); |
|
124 | 124 | $upSql = $this->getClassTypeMigrationSql($classType); |
125 | 125 | $downSql = "DELETE FROM `dds_class` WHERE `class_type`='$classType';"; |
126 | 126 | $this->storeMigration($upSql, $downSql); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | /** |
132 | 132 | * @inheritdoc |
133 | 133 | */ |
134 | - public function getClass($classType, $includeMembers=false) |
|
134 | + public function getClass($classType, $includeMembers = false) |
|
135 | 135 | { |
136 | 136 | if ($this->findClass($classType, $class)) { |
137 | 137 | $data = $class->toArray(); |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | public function editClass($classType, $changes) |
149 | 149 | { |
150 | 150 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'module', 'change_log'])); |
151 | - if (count($allowed)==0) |
|
151 | + if (count($allowed) == 0) |
|
152 | 152 | return; |
153 | 153 | $this->clearClassCache($classType); |
154 | 154 | $downSql = $this->getClassTypeMigrationSql($classType); |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | /** |
233 | 233 | * @inheritdoc |
234 | 234 | */ |
235 | - public function listMembers($classType, $includeDeleted=false, $keyBy='member_ref') |
|
235 | + public function listMembers($classType, $includeDeleted = false, $keyBy = 'member_ref') |
|
236 | 236 | { |
237 | 237 | return $this->listMembersForClass($classType, $includeDeleted, $keyBy); |
238 | 238 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | /** |
241 | 241 | * @inheritdoc |
242 | 242 | */ |
243 | - public function addMember($classType, &$memberRef, $dataTypeRef, $label, $description, $additional=null) |
|
243 | + public function addMember($classType, &$memberRef, $dataTypeRef, $label, $description, $additional = null) |
|
244 | 244 | { |
245 | 245 | $classType = $this->canonicaliseRef($classType); |
246 | 246 | $memberRef = $this->canonicaliseRef($memberRef); |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | // extract out any additional information |
250 | 250 | $choices = ((!empty($additional['choices']) && is_array($additional['choices'])) ? $additional['choices'] : []); |
251 | 251 | $linkClass = (!empty($additional['link_class']) ? $additional['link_class'] : null); |
252 | - if (DdsMember::findOne(['class_type' => $classType, 'member_ref' => $memberRef])!==null) |
|
252 | + if (DdsMember::findOne(['class_type' => $classType, 'member_ref' => $memberRef]) !== null) |
|
253 | 253 | throw new \InvalidArgumentException("The member $memberRef already exists"); |
254 | 254 | if (in_array($dataTypeRef, ['link_uni', 'link_multi']) && !$linkClass) { |
255 | 255 | throw new \InvalidArgumentException("Link_uni, link_multi data types require a link_class to be passed for member '$classType::$memberRef'. You passed in ".print_r($additional, true)); |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $mId = $this->storeMigration($upMember, $downMember); |
274 | 274 | |
275 | 275 | // and create the member column |
276 | - if (($error=$this->addClassMemberColumn($classType, $member->member_ref)) !== true) { |
|
276 | + if (($error = $this->addClassMemberColumn($classType, $member->member_ref)) !== true) { |
|
277 | 277 | $member->delete(); |
278 | 278 | $this->removeMigration($mId); |
279 | 279 | throw new \RuntimeException("Couldn't create the member column. Error=".$error); |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | /** |
287 | 287 | * @inheritdoc |
288 | 288 | */ |
289 | - public function getMember($classType, $memberRef, $fields=[]) |
|
289 | + public function getMember($classType, $memberRef, $fields = []) |
|
290 | 290 | { |
291 | 291 | // !! keep member as an object so it runs all conversion code |
292 | 292 | $query = DdsMember::find(); |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | { |
309 | 309 | // check that only allowed updates are made |
310 | 310 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'definition', 'choices', 'link_class'])); |
311 | - if (count($allowed)==0) |
|
311 | + if (count($allowed) == 0) |
|
312 | 312 | return; |
313 | 313 | |
314 | 314 | // find the member and remove any illegitamate updates |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $downSql = $this->getTableRowReplaceSql('dds_member', $member); |
331 | 331 | $member->attributes = $updates; |
332 | 332 | if (!$member->save()) |
333 | - throw new \RuntimeException("Couldn't update the member: ".print_r ($member->errors, true)); |
|
333 | + throw new \RuntimeException("Couldn't update the member: ".print_r($member->errors, true)); |
|
334 | 334 | $upSql = $this->getTableRowReplaceSql('dds_member', $member); |
335 | 335 | $this->storeMigration($upSql, $downSql); |
336 | 336 | $this->clearClassMemberCache($classType); |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | public function deleteMember($classType, $memberRef) |
364 | 364 | { |
365 | 365 | // delete a member if it isn't already deleted |
366 | - if ($this->findMember($classType, $memberRef, $member) && $member->deleted==0) { |
|
366 | + if ($this->findMember($classType, $memberRef, $member) && $member->deleted == 0) { |
|
367 | 367 | $upSql = "UPDATE `dds_member` SET `deleted`=1 WHERE `class_type`='$classType' AND `member_ref`='$memberRef';"; |
368 | 368 | $downSql = "UPDATE `dds_member` SET `deleted`=0 WHERE `class_type`='$classType' AND `member_ref`='$memberRef';"; |
369 | 369 | neon()->db->createCommand($upSql)->execute(); |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | public function undeleteMember($classType, $memberRef) |
379 | 379 | { |
380 | 380 | // undelete a member if it is already deleted |
381 | - if ($this->findMember($classType, $memberRef, $member) && $member->deleted==1) { |
|
381 | + if ($this->findMember($classType, $memberRef, $member) && $member->deleted == 1) { |
|
382 | 382 | // create migrations |
383 | 383 | $upSql = "UPDATE `dds_member` SET `deleted`=0 WHERE `class_type`='$classType' AND `member_ref`='$memberRef';"; |
384 | 384 | $downSql = "UPDATE `dds_member` SET `deleted`=1 WHERE `class_type`='$classType' AND `member_ref`='$memberRef';"; |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | /** |
426 | 426 | * @inheritdoc |
427 | 427 | */ |
428 | - public function listDataTypes($includeDeleted=false) |
|
428 | + public function listDataTypes($includeDeleted = false) |
|
429 | 429 | { |
430 | 430 | $query = DdsDataType::find(); |
431 | 431 | $select = ['data_type_ref', 'label', 'description', 'definition', 'storage_ref']; |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | $downSql = $this->getTableRowReplaceSql('dds_data_type', $dataType); |
487 | 487 | $dataType->attributes = $updates; |
488 | 488 | if (!$dataType->save()) |
489 | - throw new \RuntimeException("Couldn't save the datatype: ".print_r($dataType->errors(),true)); |
|
489 | + throw new \RuntimeException("Couldn't save the datatype: ".print_r($dataType->errors(), true)); |
|
490 | 490 | $upSql = $this->getTableRowReplaceSql('dds_data_type', $dataType); |
491 | 491 | $this->storeMigration($upSql, $downSql); |
492 | 492 | } |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | if (count($diff)) |
605 | 605 | $diffs[$k] = $v; |
606 | 606 | } else { |
607 | - if ((string)$v !== (string)$b[$k]) |
|
607 | + if ((string) $v !== (string) $b[$k]) |
|
608 | 608 | $diffs[$k] = $v; |
609 | 609 | } |
610 | 610 | } else { |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | */ |
622 | 622 | private static $_classCache = []; |
623 | 623 | |
624 | - private function _getClassesQuery($module=null, $includeDeleted=false) |
|
624 | + private function _getClassesQuery($module = null, $includeDeleted = false) |
|
625 | 625 | { |
626 | 626 | $query = DdsClass::find(); |
627 | 627 | $select = ['class_type', 'label', 'description', 'module', 'count_total', 'count_deleted', 'change_log']; |
@@ -18,7 +18,7 @@ |
||
18 | 18 | /** |
19 | 19 | * @inheritdoc |
20 | 20 | */ |
21 | - public function addObjectDeletionChecksOnJoin(\yii\db\Query $query, $tables, $join='innerJoin') |
|
21 | + public function addObjectDeletionChecksOnJoin(\yii\db\Query $query, $tables, $join = 'innerJoin') |
|
22 | 22 | { |
23 | 23 | foreach ($tables as $table) { |
24 | 24 | if ($join == 'innerJoin') { |
@@ -13,8 +13,9 @@ |
||
13 | 13 | */ |
14 | 14 | function smarty_function_getDdsObject($params, $template) |
15 | 15 | { |
16 | - if (!isset($params['uuid'])) |
|
17 | - throw new InvalidArgumentException("DdsObjectToJson - you need to pass in the 'uuid'"); |
|
16 | + if (!isset($params['uuid'])) { |
|
17 | + throw new InvalidArgumentException("DdsObjectToJson - you need to pass in the 'uuid'"); |
|
18 | + } |
|
18 | 19 | $assign = !empty($params['assign']) ? $params['assign'] : 'ddsObject'; |
19 | 20 | $asJson = isset($params['asJson']) ? $params['asJson'] : false; |
20 | 21 | $dds = neon('dds')->IDdsObjectManagement; |
@@ -244,7 +244,7 @@ |
||
244 | 244 | if ($count) |
245 | 245 | $classes = array_merge($classes, $nextSet); |
246 | 246 | $start += $count; |
247 | - } while ($count>0); |
|
247 | + } while ($count > 0); |
|
248 | 248 | $classesByType = array_column($classes, null, 'class_type'); |
249 | 249 | |
250 | 250 | // get the full definition of these |
@@ -103,8 +103,9 @@ discard block |
||
103 | 103 | $form = $this->getPhoebeForm($type); |
104 | 104 | $object = $this->ddo()->getObject($id); |
105 | 105 | $form->loadFromDb($object); |
106 | - if (neon()->request->getIsAjax()) |
|
107 | - return $form->ajaxValidation(); |
|
106 | + if (neon()->request->getIsAjax()) { |
|
107 | + return $form->ajaxValidation(); |
|
108 | + } |
|
108 | 109 | |
109 | 110 | if ($form->processRequest()) { |
110 | 111 | $this->ddo()->editObject($id, $form->getData()); |
@@ -128,8 +129,9 @@ discard block |
||
128 | 129 | public function actionDeleteObject($type, $id, $redirect = true) |
129 | 130 | { |
130 | 131 | $this->ddo()->deleteObject($id); |
131 | - if ($redirect) |
|
132 | - $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
132 | + if ($redirect) { |
|
133 | + $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
134 | + } |
|
133 | 135 | } |
134 | 136 | |
135 | 137 | /** |
@@ -141,8 +143,9 @@ discard block |
||
141 | 143 | public function actionUndeleteObject($type, $id, $redirect = true) |
142 | 144 | { |
143 | 145 | $this->ddo()->undeleteObject($id); |
144 | - if ($redirect) |
|
145 | - $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
146 | + if ($redirect) { |
|
147 | + $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
148 | + } |
|
146 | 149 | } |
147 | 150 | |
148 | 151 | /** |
@@ -154,8 +157,9 @@ discard block |
||
154 | 157 | public function actionDestroyObject($type, $id, $redirect = true) |
155 | 158 | { |
156 | 159 | $this->ddo()->destroyObject($id); |
157 | - if ($redirect) |
|
158 | - $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
160 | + if ($redirect) { |
|
161 | + $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
162 | + } |
|
159 | 163 | } |
160 | 164 | |
161 | 165 | |
@@ -170,8 +174,9 @@ discard block |
||
170 | 174 | while ($rows > 0) { |
171 | 175 | $count = min($rows, 100); |
172 | 176 | $data = []; |
173 | - for ($i = 0; $i < $count; $i++) |
|
174 | - $data[] = $form->fake(); |
|
177 | + for ($i = 0; $i < $count; $i++) { |
|
178 | + $data[] = $form->fake(); |
|
179 | + } |
|
175 | 180 | $this->ddo()->addObjects($type, $data); |
176 | 181 | $rows -= $count; |
177 | 182 | } |
@@ -281,8 +286,9 @@ discard block |
||
281 | 286 | do { |
282 | 287 | $nextSet = $ddc->listClasses(null, $total, false, $start, $length); |
283 | 288 | $count = count($nextSet); |
284 | - if ($count) |
|
285 | - $classes = array_merge($classes, $nextSet); |
|
289 | + if ($count) { |
|
290 | + $classes = array_merge($classes, $nextSet); |
|
291 | + } |
|
286 | 292 | $start += $count; |
287 | 293 | } while ($count>0); |
288 | 294 | $classesByType = array_column($classes, null, 'class_type'); |
@@ -295,8 +301,9 @@ discard block |
||
295 | 301 | foreach ($class['members'] as &$member) { |
296 | 302 | $member['data_type'] = $dataTypeByRef[$member['data_type_ref']]; |
297 | 303 | $member['links_to_table'] = null; |
298 | - if ($member['link_class'] && isset($classesByType[$member['link_class']])) |
|
299 | - $member['links_to_table'] = $classesByType[$member['link_class']]['label']; |
|
304 | + if ($member['link_class'] && isset($classesByType[$member['link_class']])) { |
|
305 | + $member['links_to_table'] = $classesByType[$member['link_class']]['label']; |
|
306 | + } |
|
300 | 307 | } |
301 | 308 | $definitions[$c['class_type']] = $class; |
302 | 309 | } |
@@ -82,8 +82,9 @@ discard block |
||
82 | 82 | */ |
83 | 83 | protected function ddo() |
84 | 84 | { |
85 | - if ($this->_ddo == null) |
|
86 | - $this->_ddo = neon('dds')->IDdsObjectManagement; |
|
85 | + if ($this->_ddo == null) { |
|
86 | + $this->_ddo = neon('dds')->IDdsObjectManagement; |
|
87 | + } |
|
87 | 88 | return $this->_ddo; |
88 | 89 | } |
89 | 90 | |
@@ -92,8 +93,9 @@ discard block |
||
92 | 93 | */ |
93 | 94 | protected function ddc() |
94 | 95 | { |
95 | - if ($this->_ddc == null) |
|
96 | - $this->_ddc = neon('dds')->IDdsClassManagement; |
|
96 | + if ($this->_ddc == null) { |
|
97 | + $this->_ddc = neon('dds')->IDdsClassManagement; |
|
98 | + } |
|
97 | 99 | return $this->_ddc; |
98 | 100 | } |
99 | 101 | |
@@ -102,8 +104,9 @@ discard block |
||
102 | 104 | */ |
103 | 105 | protected function ddt() |
104 | 106 | { |
105 | - if ($this->_ddt == null) |
|
106 | - $this->_ddt = neon('dds')->IDdsDataTypeManagement; |
|
107 | + if ($this->_ddt == null) { |
|
108 | + $this->_ddt = neon('dds')->IDdsDataTypeManagement; |
|
109 | + } |
|
107 | 110 | return $this->_ddt; |
108 | 111 | } |
109 | 112 |
@@ -39,7 +39,7 @@ |
||
39 | 39 | * @param array $options additional options for the form |
40 | 40 | * @return \neon\core\form\Form |
41 | 41 | */ |
42 | - protected function getPhoebeForm($type, $options=[]) |
|
42 | + protected function getPhoebeForm($type, $options = []) |
|
43 | 43 | { |
44 | 44 | return neon()->phoebe->getForm('daedalus', $type, $options); |
45 | 45 | } |