@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | // depending on how this grid was set up, this call may or may not have been made. |
| 73 | 73 | // The results are cached so call it here to be safe. |
| 74 | 74 | $totalCount = $this->getTotalCount(); |
| 75 | - $limit = [ |
|
| 75 | + $limit = [ |
|
| 76 | 76 | 'start' => $pagination->getOffset(), |
| 77 | 77 | 'length' => $pagination->getLimit(), |
| 78 | 78 | 'total' => ($totalCount > 0 ? $totalCount : true) |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * Store a total count to save multiple recalculations |
| 122 | 122 | * @var type |
| 123 | 123 | */ |
| 124 | - private $_totalCountCache=[]; |
|
| 124 | + private $_totalCountCache = []; |
|
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * @inheritDoc |
@@ -45,8 +45,9 @@ discard block |
||
| 45 | 45 | public function __clone() |
| 46 | 46 | { |
| 47 | 47 | parent::__clone(); |
| 48 | - if ($this->_queryBuilder) |
|
| 49 | - $this->_queryBuilder = clone $this->_queryBuilder; |
|
| 48 | + if ($this->_queryBuilder) { |
|
| 49 | + $this->_queryBuilder = clone $this->_queryBuilder; |
|
| 50 | + } |
|
| 50 | 51 | } |
| 51 | 52 | |
| 52 | 53 | /** |
@@ -67,8 +68,9 @@ discard block |
||
| 67 | 68 | { |
| 68 | 69 | // prepare pagination |
| 69 | 70 | $pagination = $this->getPagination(); |
| 70 | - if ($pagination === false) |
|
| 71 | - return []; |
|
| 71 | + if ($pagination === false) { |
|
| 72 | + return []; |
|
| 73 | + } |
|
| 72 | 74 | // depending on how this grid was set up, this call may or may not have been made. |
| 73 | 75 | // The results are cached so call it here to be safe. |
| 74 | 76 | $totalCount = $this->getTotalCount(); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * 'count_current', 'count_deleted', ['deleted']] - deleted is set if you've |
| 49 | 49 | * set $includeDeleted to true |
| 50 | 50 | */ |
| 51 | - public function listClasses($module, &$total, $includeDeleted=false, $start=0, $length=100, $orderBy='label'); |
|
| 51 | + public function listClasses($module, &$total, $includeDeleted = false, $start = 0, $length = 100, $orderBy = 'label'); |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Return the number of defined classes |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param boolean $includeDeleted default false |
| 58 | 58 | * @return integer |
| 59 | 59 | */ |
| 60 | - public function countClasses($module=null, $includeDeleted=false); |
|
| 60 | + public function countClasses($module = null, $includeDeleted = false); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * create a new class |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * class_type, label, description, module, deleted, count_total, |
| 97 | 97 | * count_deleted, members |
| 98 | 98 | */ |
| 99 | - public function getClass($classType, $includeMembers=false); |
|
| 99 | + public function getClass($classType, $includeMembers = false); |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * Edit a class |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * where deleted is given if $includeDeleted is true and keyBy is @see $keyBy |
| 157 | 157 | * Empty array is returned if there are no results |
| 158 | 158 | */ |
| 159 | - public function listMembers($classType, $includeDeleted=false, $keyBy='member_ref'); |
|
| 159 | + public function listMembers($classType, $includeDeleted = false, $keyBy = 'member_ref'); |
|
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Create a new member for a class |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @throw InvalidArgumentException if the member already exists or the class doesn't |
| 183 | 183 | * @throw RunTimeException if the member could not be added |
| 184 | 184 | */ |
| 185 | - public function addMember($classType, &$memberRef, $dataTypeRef, $label, $description, $additional=null); |
|
| 185 | + public function addMember($classType, &$memberRef, $dataTypeRef, $label, $description, $additional = null); |
|
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * Get the details of a member |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * id, class_type, member_ref, data_type_ref, label, description, |
| 195 | 195 | * choices, link_class, deleted] |
| 196 | 196 | */ |
| 197 | - public function getMember($classType, $memberRef, $fields=[]); |
|
| 197 | + public function getMember($classType, $memberRef, $fields = []); |
|
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | 200 | * Edit a member's details |
@@ -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']; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | $query->andWhere('[[o]].[[_deleted]] = 0'); |
| 278 | 278 | if ($inFull) { |
| 279 | 279 | $tableName = $this->getTableFromClassType($classType); |
| 280 | - $query->innerJoin('{{' . $tableName . '}} t', '[[o]].[[_uuid]]=[[t]].[[_uuid]]'); |
|
| 280 | + $query->innerJoin('{{'.$tableName.'}} t', '[[o]].[[_uuid]]=[[t]].[[_uuid]]'); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | if (is_array($order)) { |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | $object->_created = $now; |
| 321 | 321 | $object->_updated = $now; |
| 322 | 322 | if (!$object->save()) |
| 323 | - throw new \RuntimeException("Couldn't create object: " . print_r($object->errors, true)); |
|
| 323 | + throw new \RuntimeException("Couldn't create object: ".print_r($object->errors, true)); |
|
| 324 | 324 | |
| 325 | 325 | // increment the class's object count |
| 326 | 326 | $class->count_total += 1; |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | if (count($fields)) |
| 348 | - $query = "INSERT INTO `$table` (`_uuid`, " . implode(', ', $fields) . ") VALUES ('{$object->_uuid}', " . implode(', ', $inserts) . ")"; |
|
| 348 | + $query = "INSERT INTO `$table` (`_uuid`, ".implode(', ', $fields).") VALUES ('{$object->_uuid}', ".implode(', ', $inserts).")"; |
|
| 349 | 349 | else |
| 350 | 350 | $query = "INSERT INTO `$table` (`_uuid`) VALUES ('{$object->_uuid}')"; |
| 351 | 351 | $command = neon()->db->createCommand($query); |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | $table = $this->getTableFromClassType($object->_class_type); |
| 434 | 434 | $query = "SELECT `o`.*, `t`.* FROM `dds_object` `o` LEFT JOIN `$table` `t` ON `o`.`_uuid`=`t`.`_uuid` WHERE `o`.`_uuid`=:uuid LIMIT 1"; |
| 435 | 435 | $rows = neon()->db->createCommand($query)->bindValue(':uuid', $uuid)->queryAll(); |
| 436 | - $row = count($rows) > 0 ? $rows[0] : null; |
|
| 436 | + $row = count($rows) > 0 ? $rows[0] : null; |
|
| 437 | 437 | $this->convertFromDBToPHP($row, $this->getMemberLinks($uuid)); |
| 438 | 438 | return $row; |
| 439 | 439 | } |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | if (count($updates) == 0) |
| 492 | 492 | return false; |
| 493 | 493 | |
| 494 | - $query = "UPDATE `$table` SET " . implode(', ', $updates) . " WHERE `_uuid`='$uuid' LIMIT 1"; |
|
| 494 | + $query = "UPDATE `$table` SET ".implode(', ', $updates)." WHERE `_uuid`='$uuid' LIMIT 1"; |
|
| 495 | 495 | neon()->db->createCommand($query)->bindValues($values)->execute(); |
| 496 | 496 | |
| 497 | 497 | // add or remove any links from the linking table |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | $table = $this->getTableFromClassType($classType); |
| 531 | 531 | $memberStorage = $this->getMemberStorage($classType); |
| 532 | 532 | if (count($memberStorage) == 0) { |
| 533 | - throw new \InvalidArgumentException('Unknown or empty class type ' . $classType); |
|
| 533 | + throw new \InvalidArgumentException('Unknown or empty class type '.$classType); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | // see if we are recording changes into the change log |
@@ -573,14 +573,14 @@ discard block |
||
| 573 | 573 | $objectValues[$placeHolder] = $id; |
| 574 | 574 | $count++; |
| 575 | 575 | } |
| 576 | - $uuidClause = '(' . implode(',', $uuidClause) . ')'; |
|
| 576 | + $uuidClause = '('.implode(',', $uuidClause).')'; |
|
| 577 | 577 | |
| 578 | 578 | // update the latest changed |
| 579 | 579 | $db = neon()->db; |
| 580 | - $query = "UPDATE `dds_object` SET `_updated`=NOW() WHERE `_uuid` IN $uuidClause LIMIT " . count($uuids); |
|
| 580 | + $query = "UPDATE `dds_object` SET `_updated`=NOW() WHERE `_uuid` IN $uuidClause LIMIT ".count($uuids); |
|
| 581 | 581 | $db->createCommand($query)->bindValues($objectValues)->execute(); |
| 582 | 582 | // make the changes |
| 583 | - $query = "UPDATE `$table` SET " . implode(', ', $updates) . " WHERE `_uuid` IN $uuidClause LIMIT " . count($uuids); |
|
| 583 | + $query = "UPDATE `$table` SET ".implode(', ', $updates)." WHERE `_uuid` IN $uuidClause LIMIT ".count($uuids); |
|
| 584 | 584 | $db->createCommand($query)->bindValues($values)->execute(); |
| 585 | 585 | |
| 586 | 586 | // |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | $object->_deleted = 1; |
| 612 | 612 | $object->_updated = date('Y-m-d H:i:s'); |
| 613 | 613 | if (!$object->save()) |
| 614 | - throw new \RuntimeException("Couldn't delete the object: " . print_r($object->errors, true)); |
|
| 614 | + throw new \RuntimeException("Couldn't delete the object: ".print_r($object->errors, true)); |
|
| 615 | 615 | // and update the class object deleted count |
| 616 | 616 | $class = null; |
| 617 | 617 | $this->findClass($object['_class_type'], $class); |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | $object->_deleted = 0; |
| 700 | 700 | $object->_updated = date('Y-m-d H:i:s'); |
| 701 | 701 | if (!$object->save()) |
| 702 | - throw new \RuntimeException("Couldn't undelete the object: " . print_r($object->errors, true)); |
|
| 702 | + throw new \RuntimeException("Couldn't undelete the object: ".print_r($object->errors, true)); |
|
| 703 | 703 | |
| 704 | 704 | // and update the class object deleted count |
| 705 | 705 | $class = null; |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | { |
| 822 | 822 | $row = DdsClass::find()->where(['class_type'=>$classType])->one()->toArray(); |
| 823 | 823 | if ($row) { |
| 824 | - return ['total'=>$row['count_total'], 'active'=>($row['count_total']-$row['count_deleted']), 'deleted'=>$row['count_deleted']]; |
|
| 824 | + return ['total'=>$row['count_total'], 'active'=>($row['count_total'] - $row['count_deleted']), 'deleted'=>$row['count_deleted']]; |
|
| 825 | 825 | } |
| 826 | 826 | return null; |
| 827 | 827 | } |
@@ -940,7 +940,7 @@ discard block |
||
| 940 | 940 | static $counter = 0; |
| 941 | 941 | $counter++; |
| 942 | 942 | // a randomly generated resultKey prevents db query chaching. |
| 943 | - $resultKey = $resultKey ? $resultKey : $request['requestKey'] . '_' . $counter; |
|
| 943 | + $resultKey = $resultKey ? $resultKey : $request['requestKey'].'_'.$counter; |
|
| 944 | 944 | $request['resultKey'] = $resultKey; |
| 945 | 945 | if (!array_key_exists($request['requestKey'], self::$_requestResultsCache)) |
| 946 | 946 | $this->convertRequestToSql($request); |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | } |
| 1027 | 1027 | $request['totalSql'] .= ", '$request[requestKey]' as `{$this->requestKeyField}`, '$request[resultKey]_total' as `{$this->resultKeyField}` FROM `dds_class` WHERE `class_type` = '$classType'"; |
| 1028 | 1028 | } else { |
| 1029 | - $request['totalSql'] = "SELECT COUNT(*) as `total`, '$request[requestKey]' as `{$this->requestKeyField}`, '$request[resultKey]_total' as `{$this->resultKeyField}` FROM $table t $join $where"; |
|
| 1029 | + $request['totalSql'] = "SELECT COUNT(*) as `total`, '$request[requestKey]' as `{$this->requestKeyField}`, '$request[resultKey]_total' as `{$this->resultKeyField}` FROM $table t $join $where"; |
|
| 1030 | 1030 | } |
| 1031 | 1031 | } |
| 1032 | 1032 | } |
@@ -1148,7 +1148,7 @@ discard block |
||
| 1148 | 1148 | $clauseSql[] = $filter['filterSql']; |
| 1149 | 1149 | unset($filter['sql']); |
| 1150 | 1150 | } |
| 1151 | - $filters['sql'] = '(' . implode(') OR (', $clauseSql) . ')'; |
|
| 1151 | + $filters['sql'] = '('.implode(') OR (', $clauseSql).')'; |
|
| 1152 | 1152 | } |
| 1153 | 1153 | return; |
| 1154 | 1154 | } |
@@ -1160,7 +1160,7 @@ discard block |
||
| 1160 | 1160 | $filter = (in_array($filters[0], $links) ? "`link_{$filters[0]}`.`to_id`" : $this->quoteField($filters[0])); |
| 1161 | 1161 | $filterKeys[$filters[0]] = $filters[0]; |
| 1162 | 1162 | if ($this->operatorTakesObject($filters[1]) && isset($filters[2])) |
| 1163 | - $filters['itemSql'] = $filters['sql'] = "$filter " . $this->prepareForPDO($filters[1], $filters[2]); |
|
| 1163 | + $filters['itemSql'] = $filters['sql'] = "$filter ".$this->prepareForPDO($filters[1], $filters[2]); |
|
| 1164 | 1164 | else { |
| 1165 | 1165 | $filters['itemSql'] = $filters['sql'] = "$filter $filters[1]"; |
| 1166 | 1166 | } |
@@ -1174,7 +1174,7 @@ discard block |
||
| 1174 | 1174 | throw new \InvalidArgumentException("Daedalus: Cannot pass an *array* of values with an operator of $operator"); |
| 1175 | 1175 | foreach ($value as $v) { |
| 1176 | 1176 | if (is_array($v)) |
| 1177 | - throw new \InvalidArgumentException("Daedalus: Cannot pass an *array* of *array* of values as filters (silly billy). You passed " . print_r($value, true)); |
|
| 1177 | + throw new \InvalidArgumentException("Daedalus: Cannot pass an *array* of *array* of values as filters (silly billy). You passed ".print_r($value, true)); |
|
| 1178 | 1178 | $count = count($this->boundValues); |
| 1179 | 1179 | $variable = ":var{$count}end"; |
| 1180 | 1180 | $this->boundValues[$variable] = $v; |
@@ -1185,7 +1185,7 @@ discard block |
||
| 1185 | 1185 | $operator = 'IN'; |
| 1186 | 1186 | if ($operator == '!=') |
| 1187 | 1187 | $operator = 'NOT IN'; |
| 1188 | - return "$operator (" . implode(',', $pdoValues) . ')'; |
|
| 1188 | + return "$operator (".implode(',', $pdoValues).')'; |
|
| 1189 | 1189 | } else { |
| 1190 | 1190 | $count = count($this->boundValues); |
| 1191 | 1191 | $variable = ":var{$count}end"; |
@@ -1219,11 +1219,11 @@ discard block |
||
| 1219 | 1219 | } |
| 1220 | 1220 | // allow negative ordering in mysql for nulls last |
| 1221 | 1221 | if (strpos($o, '-') === 0) |
| 1222 | - $clause[] = '-' . substr($o, 1) . " $d"; |
|
| 1222 | + $clause[] = '-'.substr($o, 1)." $d"; |
|
| 1223 | 1223 | else |
| 1224 | 1224 | $clause[] = "$o $d"; |
| 1225 | 1225 | } |
| 1226 | - return 'ORDER BY ' . implode(', ', $clause); |
|
| 1226 | + return 'ORDER BY '.implode(', ', $clause); |
|
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | 1229 | /** |
@@ -1264,7 +1264,7 @@ discard block |
||
| 1264 | 1264 | // remove any empty toLinks that might have snuck through |
| 1265 | 1265 | $toLinks = array_filter($toLinks); |
| 1266 | 1266 | if (!$this->areUUIDs($toLinks)) |
| 1267 | - throw new \InvalidArgumentException("The toMemberLinks should be UUID64s. You passed in " . print_r($toLinks, true)); |
|
| 1267 | + throw new \InvalidArgumentException("The toMemberLinks should be UUID64s. You passed in ".print_r($toLinks, true)); |
|
| 1268 | 1268 | $toLinks = array_unique($toLinks); |
| 1269 | 1269 | |
| 1270 | 1270 | // |
@@ -1389,7 +1389,7 @@ discard block |
||
| 1389 | 1389 | $objectValues[$placeHolder] = $id; |
| 1390 | 1390 | $count++; |
| 1391 | 1391 | } |
| 1392 | - $uuidClause = '(' . implode(',', $uuidClause) . ')'; |
|
| 1392 | + $uuidClause = '('.implode(',', $uuidClause).')'; |
|
| 1393 | 1393 | $query = "SELECT [[_uuid]] FROM [[dds_object]] WHERE [[_class_type]]='$classType' AND [[_uuid]] IN $uuidClause"; |
| 1394 | 1394 | $checkedUuidResults = $db->createCommand($query)->bindValues($objectValues)->queryAll(); |
| 1395 | 1395 | return array_column($checkedUuidResults, '_uuid'); |
@@ -108,8 +108,9 @@ discard block |
||
| 108 | 108 | // set null result information about the request |
| 109 | 109 | $newData[$k] = ['start' => $r['limit']['start'], 'length' => 0, 'total' => $r['total'], 'rows' => []]; |
| 110 | 110 | $sql[] = $r['sql']; |
| 111 | - if ($r['totalSql']) |
|
| 112 | - $sql[] = $r['totalSql']; |
|
| 111 | + if ($r['totalSql']) { |
|
| 112 | + $sql[] = $r['totalSql']; |
|
| 113 | + } |
|
| 113 | 114 | $resultKey2RequestKey[$r['resultKey']] = $r['requestKey']; |
| 114 | 115 | } |
| 115 | 116 | } |
@@ -170,8 +171,9 @@ discard block |
||
| 170 | 171 | */ |
| 171 | 172 | public function runSingleObjectRequest($classType, array $filters = [], array $order = [], array $limit = [], $includeDeleted = false) |
| 172 | 173 | { |
| 173 | - if (empty($classType)) |
|
| 174 | - throw new \InvalidArgumentException('ClassType must be specified'); |
|
| 174 | + if (empty($classType)) { |
|
| 175 | + throw new \InvalidArgumentException('ClassType must be specified'); |
|
| 176 | + } |
|
| 175 | 177 | |
| 176 | 178 | // make sure that any currently queued requests from elsewhere are saved off the queue |
| 177 | 179 | $currentRequests = $this->popRequests(); |
@@ -254,16 +256,18 @@ discard block |
||
| 254 | 256 | public function listObjects($classType, &$total = null, $includeDeleted = false, $inFull = true, $start = 0, $length = 100, $order = null) |
| 255 | 257 | { |
| 256 | 258 | $classType = $this->canonicaliseRef($classType); |
| 257 | - if (empty($order)) |
|
| 258 | - $order = ['_created' => 'DESC']; |
|
| 259 | + if (empty($order)) { |
|
| 260 | + $order = ['_created' => 'DESC']; |
|
| 261 | + } |
|
| 259 | 262 | $order = $this->canonicaliseOrder($order); |
| 260 | 263 | |
| 261 | 264 | // get the total first |
| 262 | 265 | $class = null; |
| 263 | 266 | $this->findClass($classType, $class, true); |
| 264 | 267 | $total = $class->count_total; |
| 265 | - if (!$includeDeleted) |
|
| 266 | - $total -= $class->count_deleted; |
|
| 268 | + if (!$includeDeleted) { |
|
| 269 | + $total -= $class->count_deleted; |
|
| 270 | + } |
|
| 267 | 271 | |
| 268 | 272 | // now get the objects |
| 269 | 273 | $query = (new \neon\core\db\Query) |
@@ -273,8 +277,9 @@ discard block |
||
| 273 | 277 | ->offset($start) |
| 274 | 278 | ->limit($length); |
| 275 | 279 | |
| 276 | - if (!$includeDeleted) |
|
| 277 | - $query->andWhere('[[o]].[[_deleted]] = 0'); |
|
| 280 | + if (!$includeDeleted) { |
|
| 281 | + $query->andWhere('[[o]].[[_deleted]] = 0'); |
|
| 282 | + } |
|
| 278 | 283 | if ($inFull) { |
| 279 | 284 | $tableName = $this->getTableFromClassType($classType); |
| 280 | 285 | $query->innerJoin('{{' . $tableName . '}} t', '[[o]].[[_uuid]]=[[t]].[[_uuid]]'); |
@@ -289,8 +294,9 @@ discard block |
||
| 289 | 294 | $orderBits[] = "[[t]].$k $d"; |
| 290 | 295 | } |
| 291 | 296 | } |
| 292 | - if ($orderBits) |
|
| 293 | - $orderClause = implode(', ', $orderBits); |
|
| 297 | + if ($orderBits) { |
|
| 298 | + $orderClause = implode(', ', $orderBits); |
|
| 299 | + } |
|
| 294 | 300 | $query->orderBy($orderClause); |
| 295 | 301 | } |
| 296 | 302 | |
@@ -307,8 +313,9 @@ discard block |
||
| 307 | 313 | $class = null; |
| 308 | 314 | $classType = $this->canonicaliseRef($classType); |
| 309 | 315 | $this->findClass($classType, $class, true); |
| 310 | - if ($class->hasChangeLog()) |
|
| 311 | - $newValues = $data; |
|
| 316 | + if ($class->hasChangeLog()) { |
|
| 317 | + $newValues = $data; |
|
| 318 | + } |
|
| 312 | 319 | $table = $this->getTableFromClassType($classType); |
| 313 | 320 | |
| 314 | 321 | // create the new object |
@@ -319,8 +326,9 @@ discard block |
||
| 319 | 326 | $object->_class_type = $classType; |
| 320 | 327 | $object->_created = $now; |
| 321 | 328 | $object->_updated = $now; |
| 322 | - if (!$object->save()) |
|
| 323 | - throw new \RuntimeException("Couldn't create object: " . print_r($object->errors, true)); |
|
| 329 | + if (!$object->save()) { |
|
| 330 | + throw new \RuntimeException("Couldn't create object: " . print_r($object->errors, true)); |
|
| 331 | + } |
|
| 324 | 332 | |
| 325 | 333 | // increment the class's object count |
| 326 | 334 | $class->count_total += 1; |
@@ -344,10 +352,11 @@ discard block |
||
| 344 | 352 | } |
| 345 | 353 | } |
| 346 | 354 | |
| 347 | - if (count($fields)) |
|
| 348 | - $query = "INSERT INTO `$table` (`_uuid`, " . implode(', ', $fields) . ") VALUES ('{$object->_uuid}', " . implode(', ', $inserts) . ")"; |
|
| 349 | - else |
|
| 350 | - $query = "INSERT INTO `$table` (`_uuid`) VALUES ('{$object->_uuid}')"; |
|
| 355 | + if (count($fields)) { |
|
| 356 | + $query = "INSERT INTO `$table` (`_uuid`, " . implode(', ', $fields) . ") VALUES ('{$object->_uuid}', " . implode(', ', $inserts) . ")"; |
|
| 357 | + } else { |
|
| 358 | + $query = "INSERT INTO `$table` (`_uuid`) VALUES ('{$object->_uuid}')"; |
|
| 359 | + } |
|
| 351 | 360 | $command = neon()->db->createCommand($query); |
| 352 | 361 | $command->bindValues($values); |
| 353 | 362 | $command->execute(); |
@@ -355,8 +364,9 @@ discard block |
||
| 355 | 364 | // if there are any links then add these to the link table |
| 356 | 365 | $this->setMemberLinks($object->_uuid, $links); |
| 357 | 366 | |
| 358 | - if ($class->hasChangeLog()) |
|
| 359 | - $changeLogUuid = $this->createChangeLogEntry($class, 'ADD', $object->_uuid, [], $newValues); |
|
| 367 | + if ($class->hasChangeLog()) { |
|
| 368 | + $changeLogUuid = $this->createChangeLogEntry($class, 'ADD', $object->_uuid, [], $newValues); |
|
| 369 | + } |
|
| 360 | 370 | } catch (\Exception $e) { |
| 361 | 371 | // execution failed so clean up the object |
| 362 | 372 | $object->delete(); |
@@ -400,8 +410,9 @@ discard block |
||
| 400 | 410 | $objectsLinks = []; |
| 401 | 411 | $now = date('Y-m-d H:i:s'); |
| 402 | 412 | foreach ($chunkData as $row) { |
| 403 | - if ($hasChangeLog) |
|
| 404 | - $newValues = $row; |
|
| 413 | + if ($hasChangeLog) { |
|
| 414 | + $newValues = $row; |
|
| 415 | + } |
|
| 405 | 416 | // ddt table value - format row data and append the uuid |
| 406 | 417 | $this->convertFromPHPToDB($classType, $row, $links); |
| 407 | 418 | $uuid = (!empty($row['_uuid']) && $this->isUUID($row['_uuid'])) ? $row['_uuid'] : $this->generateUUID(); |
@@ -411,8 +422,9 @@ discard block |
||
| 411 | 422 | // object table row value |
| 412 | 423 | $objectDbRows[] = [$row['_uuid'], $classType, $now, $now]; |
| 413 | 424 | $objectsLinks[$row['_uuid']] = $links; |
| 414 | - if ($hasChangeLog) |
|
| 415 | - $this->createChangeLogEntry($class, 'ADD', $uuid, [], $newValues); |
|
| 425 | + if ($hasChangeLog) { |
|
| 426 | + $this->createChangeLogEntry($class, 'ADD', $uuid, [], $newValues); |
|
| 427 | + } |
|
| 416 | 428 | } |
| 417 | 429 | neon()->db->createCommand()->batchInsert(DdsObject::tableName(), ['_uuid', '_class_type', '_created', '_updated'], $objectDbRows)->execute(); |
| 418 | 430 | neon()->db->createCommand()->batchInsert($table, $columns, $rows)->execute(); |
@@ -446,20 +458,23 @@ discard block |
||
| 446 | 458 | public function editObject($uuid, array $changes, &$changeLogUuid = null) |
| 447 | 459 | { |
| 448 | 460 | // check there are some changes to make |
| 449 | - if (count($changes) == 0) |
|
| 450 | - return false; |
|
| 461 | + if (count($changes) == 0) { |
|
| 462 | + return false; |
|
| 463 | + } |
|
| 451 | 464 | |
| 452 | 465 | // check that the object exists and find its class type |
| 453 | - if (!$this->getObjectFromId($uuid, $object)) |
|
| 454 | - throw new \InvalidArgumentException("Couldn't edit object with id $uuid as not found"); |
|
| 466 | + if (!$this->getObjectFromId($uuid, $object)) { |
|
| 467 | + throw new \InvalidArgumentException("Couldn't edit object with id $uuid as not found"); |
|
| 468 | + } |
|
| 455 | 469 | |
| 456 | 470 | // see if we need to store the change log |
| 457 | 471 | $class = null; |
| 458 | 472 | $this->findClass($object['_class_type'], $class); |
| 459 | 473 | |
| 460 | 474 | $object->_updated = date('Y-m-d H:i:s'); |
| 461 | - if (!$object->save()) |
|
| 462 | - return $object->errors; |
|
| 475 | + if (!$object->save()) { |
|
| 476 | + return $object->errors; |
|
| 477 | + } |
|
| 463 | 478 | |
| 464 | 479 | // now update any member changes |
| 465 | 480 | try { |
@@ -488,8 +503,9 @@ discard block |
||
| 488 | 503 | } |
| 489 | 504 | } |
| 490 | 505 | } |
| 491 | - if (count($updates) == 0) |
|
| 492 | - return false; |
|
| 506 | + if (count($updates) == 0) { |
|
| 507 | + return false; |
|
| 508 | + } |
|
| 493 | 509 | |
| 494 | 510 | $query = "UPDATE `$table` SET " . implode(', ', $updates) . " WHERE `_uuid`='$uuid' LIMIT 1"; |
| 495 | 511 | neon()->db->createCommand($query)->bindValues($values)->execute(); |
@@ -498,8 +514,9 @@ discard block |
||
| 498 | 514 | $this->setMemberLinks($object->_uuid, $links); |
| 499 | 515 | |
| 500 | 516 | // finally note the changes in the change log |
| 501 | - if ($class && $class->hasChangeLog()) |
|
| 502 | - $changeLogUuid = $this->createChangeLogEntry($class, 'EDIT', $uuid, $originalValues, $newValues); |
|
| 517 | + if ($class && $class->hasChangeLog()) { |
|
| 518 | + $changeLogUuid = $this->createChangeLogEntry($class, 'EDIT', $uuid, $originalValues, $newValues); |
|
| 519 | + } |
|
| 503 | 520 | } catch (\yii\db\exception $e) { |
| 504 | 521 | $this->clearCaches(); |
| 505 | 522 | return ['error' => $e->getMessage()]; |
@@ -521,12 +538,14 @@ discard block |
||
| 521 | 538 | */ |
| 522 | 539 | public function editObjects($classType, array $uuids, array $changes) |
| 523 | 540 | { |
| 524 | - if (count($uuids) == 0 || count($changes) == 0) |
|
| 525 | - return false; |
|
| 541 | + if (count($uuids) == 0 || count($changes) == 0) { |
|
| 542 | + return false; |
|
| 543 | + } |
|
| 526 | 544 | try { |
| 527 | 545 | $uuids = $this->checkUuidsAgainstClassType($uuids, $classType); |
| 528 | - if (count($uuids) == 0) |
|
| 529 | - return false; |
|
| 546 | + if (count($uuids) == 0) { |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 530 | 549 | $table = $this->getTableFromClassType($classType); |
| 531 | 550 | $memberStorage = $this->getMemberStorage($classType); |
| 532 | 551 | if (count($memberStorage) == 0) { |
@@ -537,8 +556,9 @@ discard block |
||
| 537 | 556 | $class = null; |
| 538 | 557 | $this->findClass($classType, $class); |
| 539 | 558 | if ($class && $class->hasChangeLog()) { |
| 540 | - foreach ($uuids as $uuid) |
|
| 541 | - $beforeValues[$uuid] = array_intersect_key($this->getObject($uuid), $changes); |
|
| 559 | + foreach ($uuids as $uuid) { |
|
| 560 | + $beforeValues[$uuid] = array_intersect_key($this->getObject($uuid), $changes); |
|
| 561 | + } |
|
| 542 | 562 | $newValues = $changes; |
| 543 | 563 | } |
| 544 | 564 | |
@@ -560,8 +580,9 @@ discard block |
||
| 560 | 580 | } |
| 561 | 581 | } |
| 562 | 582 | } |
| 563 | - if (count($updates) == 0) |
|
| 564 | - return false; |
|
| 583 | + if (count($updates) == 0) { |
|
| 584 | + return false; |
|
| 585 | + } |
|
| 565 | 586 | |
| 566 | 587 | // sort out the uuid clause for both the update on the table and in the object table |
| 567 | 588 | $uuidClause = []; |
@@ -589,8 +610,9 @@ discard block |
||
| 589 | 610 | |
| 590 | 611 | // and save entries into a change log |
| 591 | 612 | if ($class && $class->hasChangeLog()) { |
| 592 | - foreach ($beforeValues as $uuid => $before) |
|
| 593 | - $this->createChangeLogEntry($class, 'EDIT', $uuid, $before, $newValues); |
|
| 613 | + foreach ($beforeValues as $uuid => $before) { |
|
| 614 | + $this->createChangeLogEntry($class, 'EDIT', $uuid, $before, $newValues); |
|
| 615 | + } |
|
| 594 | 616 | } |
| 595 | 617 | } catch (\yii\db\exception $e) { |
| 596 | 618 | $this->clearCaches(); |
@@ -610,8 +632,9 @@ discard block |
||
| 610 | 632 | if ($this->getObjectFromId($uuid, $object) && $object->_deleted == 0) { |
| 611 | 633 | $object->_deleted = 1; |
| 612 | 634 | $object->_updated = date('Y-m-d H:i:s'); |
| 613 | - if (!$object->save()) |
|
| 614 | - throw new \RuntimeException("Couldn't delete the object: " . print_r($object->errors, true)); |
|
| 635 | + if (!$object->save()) { |
|
| 636 | + throw new \RuntimeException("Couldn't delete the object: " . print_r($object->errors, true)); |
|
| 637 | + } |
|
| 615 | 638 | // and update the class object deleted count |
| 616 | 639 | $class = null; |
| 617 | 640 | $this->findClass($object['_class_type'], $class); |
@@ -619,8 +642,9 @@ discard block |
||
| 619 | 642 | $class->save(); |
| 620 | 643 | |
| 621 | 644 | // see if we need to store the change log |
| 622 | - if ($class && $class->hasChangeLog()) |
|
| 623 | - $changeLogUuid = $this->createChangeLogEntry($class, 'DELETE', $uuid); |
|
| 645 | + if ($class && $class->hasChangeLog()) { |
|
| 646 | + $changeLogUuid = $this->createChangeLogEntry($class, 'DELETE', $uuid); |
|
| 647 | + } |
|
| 624 | 648 | |
| 625 | 649 | /** ---- KEEP ME ---- |
| 626 | 650 | * don't delete the links so any that haven't been deleted between |
@@ -643,8 +667,9 @@ discard block |
||
| 643 | 667 | public function deleteObjects(array $uuids) |
| 644 | 668 | { |
| 645 | 669 | $objects = $this->getObjectRowsFromIds($uuids); |
| 646 | - if (count($objects) == 0) |
|
| 647 | - return; |
|
| 670 | + if (count($objects) == 0) { |
|
| 671 | + return; |
|
| 672 | + } |
|
| 648 | 673 | |
| 649 | 674 | $foundUuids = []; |
| 650 | 675 | $foundClasses = []; |
@@ -661,8 +686,9 @@ discard block |
||
| 661 | 686 | $deletedUuids[$classType][$obj['_uuid']] = $obj['_uuid']; |
| 662 | 687 | } |
| 663 | 688 | } |
| 664 | - if (count($foundUuids)) |
|
| 665 | - DdsObject::updateAll(['_deleted' => 1, '_updated' => date('Y-m-d H:i:s')], ['_uuid' => $foundUuids]); |
|
| 689 | + if (count($foundUuids)) { |
|
| 690 | + DdsObject::updateAll(['_deleted' => 1, '_updated' => date('Y-m-d H:i:s')], ['_uuid' => $foundUuids]); |
|
| 691 | + } |
|
| 666 | 692 | foreach ($foundClasses as $type => $count) { |
| 667 | 693 | $class = null; |
| 668 | 694 | if ($this->findClass($type, $class)) { |
@@ -670,8 +696,9 @@ discard block |
||
| 670 | 696 | $class->save(); |
| 671 | 697 | // TODO 20200107 Make a bulk call for change log entries |
| 672 | 698 | if ($class->hasChangeLog()) { |
| 673 | - foreach ($deletedUuids[$class->class_type] as $objUuid) |
|
| 674 | - $this->createChangeLogEntry($class, 'DELETE', $objUuid); |
|
| 699 | + foreach ($deletedUuids[$class->class_type] as $objUuid) { |
|
| 700 | + $this->createChangeLogEntry($class, 'DELETE', $objUuid); |
|
| 701 | + } |
|
| 675 | 702 | } |
| 676 | 703 | } |
| 677 | 704 | } |
@@ -698,8 +725,9 @@ discard block |
||
| 698 | 725 | if ($this->getObjectFromId($uuid, $object) && $object->_deleted == 1) { |
| 699 | 726 | $object->_deleted = 0; |
| 700 | 727 | $object->_updated = date('Y-m-d H:i:s'); |
| 701 | - if (!$object->save()) |
|
| 702 | - throw new \RuntimeException("Couldn't undelete the object: " . print_r($object->errors, true)); |
|
| 728 | + if (!$object->save()) { |
|
| 729 | + throw new \RuntimeException("Couldn't undelete the object: " . print_r($object->errors, true)); |
|
| 730 | + } |
|
| 703 | 731 | |
| 704 | 732 | // and update the class object deleted count |
| 705 | 733 | $class = null; |
@@ -708,8 +736,9 @@ discard block |
||
| 708 | 736 | $class->save(); |
| 709 | 737 | |
| 710 | 738 | // see if we need to store the change log |
| 711 | - if ($class->hasChangeLog()) |
|
| 712 | - $changeLogUuid = $this->createChangeLogEntry($class, 'UNDELETE', $uuid); |
|
| 739 | + if ($class->hasChangeLog()) { |
|
| 740 | + $changeLogUuid = $this->createChangeLogEntry($class, 'UNDELETE', $uuid); |
|
| 741 | + } |
|
| 713 | 742 | } |
| 714 | 743 | $this->clearCaches(); |
| 715 | 744 | } |
@@ -724,8 +753,9 @@ discard block |
||
| 724 | 753 | if ($this->getObjectFromId($uuid, $object)) { |
| 725 | 754 | $class = null; |
| 726 | 755 | $this->findClass($object['_class_type'], $class); |
| 727 | - if ($class && $class->hasChangeLog()) |
|
| 728 | - $originalValues = $this->getObject($uuid); |
|
| 756 | + if ($class && $class->hasChangeLog()) { |
|
| 757 | + $originalValues = $this->getObject($uuid); |
|
| 758 | + } |
|
| 729 | 759 | |
| 730 | 760 | // delete any object table data |
| 731 | 761 | $table = $this->getTableFromClassType($object['_class_type']); |
@@ -741,8 +771,9 @@ discard block |
||
| 741 | 771 | // then if ok, decrement the class's object counts |
| 742 | 772 | if ($class) { |
| 743 | 773 | $class->count_total = max(0, $class->count_total - 1); |
| 744 | - if ($object['_deleted'] == 1) |
|
| 745 | - $class->count_deleted = max(0, $class->count_deleted - 1); |
|
| 774 | + if ($object['_deleted'] == 1) { |
|
| 775 | + $class->count_deleted = max(0, $class->count_deleted - 1); |
|
| 776 | + } |
|
| 746 | 777 | $class->save(); |
| 747 | 778 | } |
| 748 | 779 | |
@@ -750,8 +781,9 @@ discard block |
||
| 750 | 781 | DdsLink::deleteAll(['or', ['from_id' => $uuid], ['to_id' => $uuid]]); |
| 751 | 782 | |
| 752 | 783 | // and note this is in the change log |
| 753 | - if ($class && $class->hasChangeLog()) |
|
| 754 | - $changeLogUuid = $this->createChangeLogEntry($class, 'DESTROY', $uuid, $originalValues); |
|
| 784 | + if ($class && $class->hasChangeLog()) { |
|
| 785 | + $changeLogUuid = $this->createChangeLogEntry($class, 'DESTROY', $uuid, $originalValues); |
|
| 786 | + } |
|
| 755 | 787 | |
| 756 | 788 | $this->clearCaches(); |
| 757 | 789 | } |
@@ -763,16 +795,18 @@ discard block |
||
| 763 | 795 | public function destroyObjects(array $uuids) |
| 764 | 796 | { |
| 765 | 797 | $objects = $this->getObjectRowsFromIds($uuids); |
| 766 | - if (count($objects) == 0) |
|
| 767 | - return; |
|
| 798 | + if (count($objects) == 0) { |
|
| 799 | + return; |
|
| 800 | + } |
|
| 768 | 801 | |
| 769 | 802 | $objectUuids = []; |
| 770 | 803 | $objectsDeleted = []; |
| 771 | 804 | $classUuids = []; |
| 772 | 805 | foreach ($objects as $obj) { |
| 773 | 806 | $objectUuids[$obj['_uuid']] = $obj['_uuid']; |
| 774 | - if ($obj['_deleted'] == 1) |
|
| 775 | - $objectsDeleted[$obj['_class_type']][$obj['_uuid']] = $obj['_uuid']; |
|
| 807 | + if ($obj['_deleted'] == 1) { |
|
| 808 | + $objectsDeleted[$obj['_class_type']][$obj['_uuid']] = $obj['_uuid']; |
|
| 809 | + } |
|
| 776 | 810 | $classUuids[$obj['_class_type']][] = $obj['_uuid']; |
| 777 | 811 | } |
| 778 | 812 | |
@@ -799,8 +833,9 @@ discard block |
||
| 799 | 833 | // decrement the class's object counts |
| 800 | 834 | if ($class) { |
| 801 | 835 | $class->count_total = max(0, $class->count_total - count($uuids)); |
| 802 | - if (isset($objectsDeleted[$classType])) |
|
| 803 | - $class->count_deleted = max(0, $class->count_deleted - count($objectsDeleted[$classType])); |
|
| 836 | + if (isset($objectsDeleted[$classType])) { |
|
| 837 | + $class->count_deleted = max(0, $class->count_deleted - count($objectsDeleted[$classType])); |
|
| 838 | + } |
|
| 804 | 839 | $class->save(); |
| 805 | 840 | } |
| 806 | 841 | } |
@@ -852,8 +887,9 @@ discard block |
||
| 852 | 887 | */ |
| 853 | 888 | private function getObjectMapManager() |
| 854 | 889 | { |
| 855 | - if (!$this->_objectMapManager) |
|
| 856 | - $this->_objectMapManager = new DdsObjectMapManager; |
|
| 890 | + if (!$this->_objectMapManager) { |
|
| 891 | + $this->_objectMapManager = new DdsObjectMapManager; |
|
| 892 | + } |
|
| 857 | 893 | return $this->_objectMapManager; |
| 858 | 894 | } |
| 859 | 895 | |
@@ -868,14 +904,16 @@ discard block |
||
| 868 | 904 | // then see if there are any multilinks to extract |
| 869 | 905 | if ($links === null) { |
| 870 | 906 | $objectIds = []; |
| 871 | - foreach ($dataSet as $row) |
|
| 872 | - $objectIds[] = $row['_uuid']; |
|
| 907 | + foreach ($dataSet as $row) { |
|
| 908 | + $objectIds[] = $row['_uuid']; |
|
| 909 | + } |
|
| 873 | 910 | $links = $this->getMembersLinks($objectIds); |
| 874 | 911 | } |
| 875 | 912 | foreach ($dataSet as &$data) { |
| 876 | 913 | // convert full rows to database. Totals are left untouched |
| 877 | - if (isset($data[$classTypeKey])) |
|
| 878 | - $this->convertFromDBToPHP($data, $links[$data['_uuid']], $classTypeKey); |
|
| 914 | + if (isset($data[$classTypeKey])) { |
|
| 915 | + $this->convertFromDBToPHP($data, $links[$data['_uuid']], $classTypeKey); |
|
| 916 | + } |
|
| 879 | 917 | } |
| 880 | 918 | } |
| 881 | 919 | |
@@ -942,8 +980,9 @@ discard block |
||
| 942 | 980 | // a randomly generated resultKey prevents db query chaching. |
| 943 | 981 | $resultKey = $resultKey ? $resultKey : $request['requestKey'] . '_' . $counter; |
| 944 | 982 | $request['resultKey'] = $resultKey; |
| 945 | - if (!array_key_exists($request['requestKey'], self::$_requestResultsCache)) |
|
| 946 | - $this->convertRequestToSql($request); |
|
| 983 | + if (!array_key_exists($request['requestKey'], self::$_requestResultsCache)) { |
|
| 984 | + $this->convertRequestToSql($request); |
|
| 985 | + } |
|
| 947 | 986 | // store the request |
| 948 | 987 | $this->objectRequests[$request['classType']][$resultKey] = $request; |
| 949 | 988 | return $resultKey; |
@@ -1052,8 +1091,9 @@ discard block |
||
| 1052 | 1091 | $join = ['INNER JOIN dds_object `o` on `t`.`_uuid` = `o`.`_uuid`']; |
| 1053 | 1092 | // now see what else needs to be added |
| 1054 | 1093 | foreach ($links as $l) { |
| 1055 | - if (in_array($l, $filterKeys)) |
|
| 1056 | - $join[] = "LEFT JOIN dds_link `link_$l` ON (`link_$l`.`from_id`=`o`.`_uuid` AND `link_$l`.`from_member`='$l')"; |
|
| 1094 | + if (in_array($l, $filterKeys)) { |
|
| 1095 | + $join[] = "LEFT JOIN dds_link `link_$l` ON (`link_$l`.`from_id`=`o`.`_uuid` AND `link_$l`.`from_member`='$l')"; |
|
| 1096 | + } |
|
| 1057 | 1097 | } |
| 1058 | 1098 | return implode(' ', $join); |
| 1059 | 1099 | } |
@@ -1070,11 +1110,13 @@ discard block |
||
| 1070 | 1110 | { |
| 1071 | 1111 | $filterKeys = []; |
| 1072 | 1112 | $notDeleted = '`o`.`_deleted`=0'; |
| 1073 | - if (count($filters) == 0) |
|
| 1074 | - return $includeDeleted ? '' : "WHERE $notDeleted"; |
|
| 1113 | + if (count($filters) == 0) { |
|
| 1114 | + return $includeDeleted ? '' : "WHERE $notDeleted"; |
|
| 1115 | + } |
|
| 1075 | 1116 | $this->createFilterClause($filters, $links, $filterKeys); |
| 1076 | - if (!$includeDeleted) |
|
| 1077 | - return "WHERE $notDeleted AND ($filters[sql])"; |
|
| 1117 | + if (!$includeDeleted) { |
|
| 1118 | + return "WHERE $notDeleted AND ($filters[sql])"; |
|
| 1119 | + } |
|
| 1078 | 1120 | return "WHERE $filters[sql]"; |
| 1079 | 1121 | } |
| 1080 | 1122 | |
@@ -1092,8 +1134,9 @@ discard block |
||
| 1092 | 1134 | // filter down until we hit the actual filters |
| 1093 | 1135 | if (is_array($filters[0])) { |
| 1094 | 1136 | foreach ($filters as $k => &$filter) { |
| 1095 | - if ($k === 'logic') |
|
| 1096 | - continue; |
|
| 1137 | + if ($k === 'logic') { |
|
| 1138 | + continue; |
|
| 1139 | + } |
|
| 1097 | 1140 | $this->createFilterClause($filter, $links, $filterKeys); |
| 1098 | 1141 | } |
| 1099 | 1142 | |
@@ -1105,25 +1148,28 @@ discard block |
||
| 1105 | 1148 | // in which case we combine those with to get the filterSql |
| 1106 | 1149 | $filterSql = []; |
| 1107 | 1150 | foreach ($filters as $k => &$filter) { |
| 1108 | - if ($k === 'logic') |
|
| 1109 | - continue; |
|
| 1151 | + if ($k === 'logic') { |
|
| 1152 | + continue; |
|
| 1153 | + } |
|
| 1110 | 1154 | // use the logic keys if any for the items - these can be in position 3 |
| 1111 | 1155 | // for most operators and position 2 for operators that don't take a key |
| 1112 | 1156 | if ($this->operatorTakesObject($filter[1])) { |
| 1113 | - if (isset($filter[3])) |
|
| 1114 | - $filterSql[$filter[3]] = $filter['itemSql']; |
|
| 1115 | - else |
|
| 1116 | - $filterSql[] = $filter['itemSql']; |
|
| 1157 | + if (isset($filter[3])) { |
|
| 1158 | + $filterSql[$filter[3]] = $filter['itemSql']; |
|
| 1159 | + } else { |
|
| 1160 | + $filterSql[] = $filter['itemSql']; |
|
| 1161 | + } |
|
| 1117 | 1162 | } else { |
| 1118 | - if (isset($filter[2])) |
|
| 1119 | - $filterSql[$filter[2]] = $filter['itemSql']; |
|
| 1120 | - else |
|
| 1121 | - $filterSql[] = $filter['itemSql']; |
|
| 1163 | + if (isset($filter[2])) { |
|
| 1164 | + $filterSql[$filter[2]] = $filter['itemSql']; |
|
| 1165 | + } else { |
|
| 1166 | + $filterSql[] = $filter['itemSql']; |
|
| 1167 | + } |
|
| 1122 | 1168 | } |
| 1123 | 1169 | } |
| 1124 | - if (empty($filters['logic'])) |
|
| 1125 | - $filters['filterSql'] = $filters['sql'] = implode(' AND ', $filterSql); |
|
| 1126 | - else { |
|
| 1170 | + if (empty($filters['logic'])) { |
|
| 1171 | + $filters['filterSql'] = $filters['sql'] = implode(' AND ', $filterSql); |
|
| 1172 | + } else { |
|
| 1127 | 1173 | // make sure we test logic filters in order from longest key to shortest key |
| 1128 | 1174 | // otherwise we can end up with subkeys screwing things up |
| 1129 | 1175 | $orderedKeys = array_map('strlen', array_keys($filterSql)); |
@@ -1135,8 +1181,9 @@ discard block |
||
| 1135 | 1181 | // double conversion, |
| 1136 | 1182 | $keys = array_keys($filterSql); |
| 1137 | 1183 | $keys2hashed = array(); |
| 1138 | - foreach ($keys as $k) |
|
| 1139 | - $keys2hashed[$k] = md5($k); |
|
| 1184 | + foreach ($keys as $k) { |
|
| 1185 | + $keys2hashed[$k] = md5($k); |
|
| 1186 | + } |
|
| 1140 | 1187 | $logicPass1 = str_replace($keys, $keys2hashed, $filters['logic']); |
| 1141 | 1188 | $filters['filterSql'] = $filters['sql'] = str_replace($keys2hashed, array_values($filterSql), $logicPass1); |
| 1142 | 1189 | } |
@@ -1159,9 +1206,9 @@ discard block |
||
| 1159 | 1206 | // |
| 1160 | 1207 | $filter = (in_array($filters[0], $links) ? "`link_{$filters[0]}`.`to_id`" : $this->quoteField($filters[0])); |
| 1161 | 1208 | $filterKeys[$filters[0]] = $filters[0]; |
| 1162 | - if ($this->operatorTakesObject($filters[1]) && isset($filters[2])) |
|
| 1163 | - $filters['itemSql'] = $filters['sql'] = "$filter " . $this->prepareForPDO($filters[1], $filters[2]); |
|
| 1164 | - else { |
|
| 1209 | + if ($this->operatorTakesObject($filters[1]) && isset($filters[2])) { |
|
| 1210 | + $filters['itemSql'] = $filters['sql'] = "$filter " . $this->prepareForPDO($filters[1], $filters[2]); |
|
| 1211 | + } else { |
|
| 1165 | 1212 | $filters['itemSql'] = $filters['sql'] = "$filter $filters[1]"; |
| 1166 | 1213 | } |
| 1167 | 1214 | } |
@@ -1170,21 +1217,25 @@ discard block |
||
| 1170 | 1217 | { |
| 1171 | 1218 | if (is_array($value)) { |
| 1172 | 1219 | $pdoValues = []; |
| 1173 | - if (!in_array($operator, ['=', '!=', 'IN', 'NOT IN'])) |
|
| 1174 | - throw new \InvalidArgumentException("Daedalus: Cannot pass an *array* of values with an operator of $operator"); |
|
| 1220 | + if (!in_array($operator, ['=', '!=', 'IN', 'NOT IN'])) { |
|
| 1221 | + throw new \InvalidArgumentException("Daedalus: Cannot pass an *array* of values with an operator of $operator"); |
|
| 1222 | + } |
|
| 1175 | 1223 | foreach ($value as $v) { |
| 1176 | - if (is_array($v)) |
|
| 1177 | - throw new \InvalidArgumentException("Daedalus: Cannot pass an *array* of *array* of values as filters (silly billy). You passed " . print_r($value, true)); |
|
| 1224 | + if (is_array($v)) { |
|
| 1225 | + throw new \InvalidArgumentException("Daedalus: Cannot pass an *array* of *array* of values as filters (silly billy). You passed " . print_r($value, true)); |
|
| 1226 | + } |
|
| 1178 | 1227 | $count = count($this->boundValues); |
| 1179 | 1228 | $variable = ":var{$count}end"; |
| 1180 | 1229 | $this->boundValues[$variable] = $v; |
| 1181 | 1230 | $pdoValues[] = $variable; |
| 1182 | 1231 | } |
| 1183 | 1232 | // converts equals to ins and outs |
| 1184 | - if ($operator == '=') |
|
| 1185 | - $operator = 'IN'; |
|
| 1186 | - if ($operator == '!=') |
|
| 1187 | - $operator = 'NOT IN'; |
|
| 1233 | + if ($operator == '=') { |
|
| 1234 | + $operator = 'IN'; |
|
| 1235 | + } |
|
| 1236 | + if ($operator == '!=') { |
|
| 1237 | + $operator = 'NOT IN'; |
|
| 1238 | + } |
|
| 1188 | 1239 | return "$operator (" . implode(',', $pdoValues) . ')'; |
| 1189 | 1240 | } else { |
| 1190 | 1241 | $count = count($this->boundValues); |
@@ -1208,8 +1259,9 @@ discard block |
||
| 1208 | 1259 | */ |
| 1209 | 1260 | private function extractOrderClause($order) |
| 1210 | 1261 | { |
| 1211 | - if (count($order) == 0) |
|
| 1212 | - return ''; |
|
| 1262 | + if (count($order) == 0) { |
|
| 1263 | + return ''; |
|
| 1264 | + } |
|
| 1213 | 1265 | $clause = []; |
| 1214 | 1266 | foreach ($order as $o => $d) { |
| 1215 | 1267 | // if any of the order clauses are RAND then replace whole clause |
@@ -1218,10 +1270,11 @@ discard block |
||
| 1218 | 1270 | break; |
| 1219 | 1271 | } |
| 1220 | 1272 | // allow negative ordering in mysql for nulls last |
| 1221 | - if (strpos($o, '-') === 0) |
|
| 1222 | - $clause[] = '-' . substr($o, 1) . " $d"; |
|
| 1223 | - else |
|
| 1224 | - $clause[] = "$o $d"; |
|
| 1273 | + if (strpos($o, '-') === 0) { |
|
| 1274 | + $clause[] = '-' . substr($o, 1) . " $d"; |
|
| 1275 | + } else { |
|
| 1276 | + $clause[] = "$o $d"; |
|
| 1277 | + } |
|
| 1225 | 1278 | } |
| 1226 | 1279 | return 'ORDER BY ' . implode(', ', $clause); |
| 1227 | 1280 | } |
@@ -1233,8 +1286,9 @@ discard block |
||
| 1233 | 1286 | */ |
| 1234 | 1287 | private function extractLimitClause($limit) |
| 1235 | 1288 | { |
| 1236 | - if (count($limit) == 0) |
|
| 1237 | - return ''; |
|
| 1289 | + if (count($limit) == 0) { |
|
| 1290 | + return ''; |
|
| 1291 | + } |
|
| 1238 | 1292 | return "LIMIT $limit[start], $limit[length]"; |
| 1239 | 1293 | } |
| 1240 | 1294 | |
@@ -1245,8 +1299,9 @@ discard block |
||
| 1245 | 1299 | */ |
| 1246 | 1300 | private function setMembersLinks($objectsLinks, $chunkSize) |
| 1247 | 1301 | { |
| 1248 | - if (count($objectsLinks) === 0) |
|
| 1249 | - return 0; |
|
| 1302 | + if (count($objectsLinks) === 0) { |
|
| 1303 | + return 0; |
|
| 1304 | + } |
|
| 1250 | 1305 | $totalCount = 0; |
| 1251 | 1306 | $db = neon()->db; |
| 1252 | 1307 | $ddsLink = DdsLink::tableName(); |
@@ -1256,15 +1311,18 @@ discard block |
||
| 1256 | 1311 | $deleteLinkClauses = []; |
| 1257 | 1312 | foreach ($chunkData as $fromUuid => $toMemberLinks) { |
| 1258 | 1313 | // check you've been supplied with rinky dinky data |
| 1259 | - if (!$this->isUUID($fromUuid)) |
|
| 1260 | - throw new \InvalidArgumentException("The fromUuid should be a UUID64. You passed in $fromUuid"); |
|
| 1314 | + if (!$this->isUUID($fromUuid)) { |
|
| 1315 | + throw new \InvalidArgumentException("The fromUuid should be a UUID64. You passed in $fromUuid"); |
|
| 1316 | + } |
|
| 1261 | 1317 | foreach ($toMemberLinks as $member => $toLinks) { |
| 1262 | - if (!is_array($toLinks)) |
|
| 1263 | - $toLinks = [$toLinks]; |
|
| 1318 | + if (!is_array($toLinks)) { |
|
| 1319 | + $toLinks = [$toLinks]; |
|
| 1320 | + } |
|
| 1264 | 1321 | // remove any empty toLinks that might have snuck through |
| 1265 | 1322 | $toLinks = array_filter($toLinks); |
| 1266 | - if (!$this->areUUIDs($toLinks)) |
|
| 1267 | - throw new \InvalidArgumentException("The toMemberLinks should be UUID64s. You passed in " . print_r($toLinks, true)); |
|
| 1323 | + if (!$this->areUUIDs($toLinks)) { |
|
| 1324 | + throw new \InvalidArgumentException("The toMemberLinks should be UUID64s. You passed in " . print_r($toLinks, true)); |
|
| 1325 | + } |
|
| 1268 | 1326 | $toLinks = array_unique($toLinks); |
| 1269 | 1327 | |
| 1270 | 1328 | // |
@@ -1279,8 +1337,9 @@ discard block |
||
| 1279 | 1337 | |
| 1280 | 1338 | // prepare the new links ready for bulk insert |
| 1281 | 1339 | $count += count($toLinks); |
| 1282 | - foreach ($toLinks as $toLink) |
|
| 1283 | - $batchInsert[] = ['from_id' => $fromUuid, 'from_member' => $member, 'to_id' => $toLink]; |
|
| 1340 | + foreach ($toLinks as $toLink) { |
|
| 1341 | + $batchInsert[] = ['from_id' => $fromUuid, 'from_member' => $member, 'to_id' => $toLink]; |
|
| 1342 | + } |
|
| 1284 | 1343 | } |
| 1285 | 1344 | } |
| 1286 | 1345 | if (count($deleteLinkClauses)) { |
@@ -1289,10 +1348,12 @@ discard block |
||
| 1289 | 1348 | } |
| 1290 | 1349 | |
| 1291 | 1350 | $insertedCount = 0; |
| 1292 | - if (count($batchInsert)) |
|
| 1293 | - $insertedCount = $db->createCommand()->batchInsert($ddsLink, ['from_id', 'from_member', 'to_id'], $batchInsert)->execute(); |
|
| 1294 | - if (YII_DEBUG && $insertedCount !== $count) |
|
| 1295 | - throw new \Exception("The link insertion failed - $count items should have been inserted vs $insertedCount actual"); |
|
| 1351 | + if (count($batchInsert)) { |
|
| 1352 | + $insertedCount = $db->createCommand()->batchInsert($ddsLink, ['from_id', 'from_member', 'to_id'], $batchInsert)->execute(); |
|
| 1353 | + } |
|
| 1354 | + if (YII_DEBUG && $insertedCount !== $count) { |
|
| 1355 | + throw new \Exception("The link insertion failed - $count items should have been inserted vs $insertedCount actual"); |
|
| 1356 | + } |
|
| 1296 | 1357 | $totalCount += $count; |
| 1297 | 1358 | } |
| 1298 | 1359 | return $totalCount; |
@@ -1333,8 +1394,9 @@ discard block |
||
| 1333 | 1394 | */ |
| 1334 | 1395 | protected function getMembersLinks(array $objectIds) |
| 1335 | 1396 | { |
| 1336 | - if (empty($objectIds)) |
|
| 1337 | - return []; |
|
| 1397 | + if (empty($objectIds)) { |
|
| 1398 | + return []; |
|
| 1399 | + } |
|
| 1338 | 1400 | $objectIds = array_unique($objectIds); |
| 1339 | 1401 | sort($objectIds, SORT_STRING); |
| 1340 | 1402 | $cacheKey = md5(serialize($objectIds)); |
@@ -1346,8 +1408,9 @@ discard block |
||
| 1346 | 1408 | ->asArray() |
| 1347 | 1409 | ->all(); |
| 1348 | 1410 | $multilinks = array_fill_keys($objectIds, []); |
| 1349 | - foreach ($rows as $row) |
|
| 1350 | - $multilinks[$row['from_id']][$row['from_member']][] = $row['to_id']; |
|
| 1411 | + foreach ($rows as $row) { |
|
| 1412 | + $multilinks[$row['from_id']][$row['from_member']][] = $row['to_id']; |
|
| 1413 | + } |
|
| 1351 | 1414 | self::$_linkResultsCache[$cacheKey] = $multilinks; |
| 1352 | 1415 | } |
| 1353 | 1416 | return self::$_linkResultsCache[$cacheKey]; |
@@ -1364,8 +1427,9 @@ discard block |
||
| 1364 | 1427 | private function createChangeLogEntry($class, $changeKey, $objectUuid, $originalValues = [], $newValues = []) |
| 1365 | 1428 | { |
| 1366 | 1429 | static $changeLog = null; |
| 1367 | - if (!$changeLog) |
|
| 1368 | - $changeLog = neon('dds')->IDdsChangeLogManagement; |
|
| 1430 | + if (!$changeLog) { |
|
| 1431 | + $changeLog = neon('dds')->IDdsChangeLogManagement; |
|
| 1432 | + } |
|
| 1369 | 1433 | return $changeLog->addLogEntry($objectUuid, $class->toArray(), $changeKey, $originalValues, $newValues); |
| 1370 | 1434 | } |
| 1371 | 1435 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | // add callback functionality to retain maximal original image size |
| 85 | 85 | $options = ['top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right']; |
| 86 | 86 | $option = in_array($params['fit'], $options) ? $params['fit'] : 'center'; |
| 87 | - $image->fit($width, $height, function ($constraint) { |
|
| 87 | + $image->fit($width, $height, function($constraint) { |
|
| 88 | 88 | $constraint->aspectRatio(); |
| 89 | 89 | $constraint->upsize(); |
| 90 | 90 | }, $option); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | } elseif ($width || $height) { |
| 94 | 94 | $width = $width * $pd; |
| 95 | 95 | $height = $height * $pd; |
| 96 | - $image->resize($width, $height, function ($constraint) { |
|
| 96 | + $image->resize($width, $height, function($constraint) { |
|
| 97 | 97 | $constraint->aspectRatio(); |
| 98 | 98 | $constraint->upsize(); |
| 99 | 99 | }); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | { |
| 154 | 154 | $filter = Arr::get($params, 'filter', false); |
| 155 | 155 | if ($filter) { |
| 156 | - $filters = explode(',',$filter); |
|
| 156 | + $filters = explode(',', $filter); |
|
| 157 | 157 | if (in_array('greyscale', $filters, true)) { |
| 158 | 158 | $image->greyscale(); |
| 159 | 159 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $x = Arr::get($crop, 'x', null); |
| 189 | 189 | $y = Arr::get($crop, 'y', null); |
| 190 | 190 | } |
| 191 | - if ($w == 0 && $h == 0 && $x == 0 && $y ==0) { |
|
| 191 | + if ($w == 0 && $h == 0 && $x == 0 && $y == 0) { |
|
| 192 | 192 | return $image; |
| 193 | 193 | } |
| 194 | 194 | $image->crop($w, $h, $x, $y); |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | foreach ($appSettings as $key => $value) { |
| 67 | 67 | // if the fields value is valid then save it |
| 68 | 68 | if ($appForm->getField($key)->validate()) { |
| 69 | - $saved = $this->getSettingsManager()->set($appKey, $key, $value); |
|
| 69 | + $saved = $this->getSettingsManager()->set($appKey, $key, $value); |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public static function render($vdom) |
| 42 | 42 | { |
| 43 | - foreach($vdom as $element) { |
|
| 43 | + foreach ($vdom as $element) { |
|
| 44 | 44 | $element[1]($element[2], $element['children']); |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -67,18 +67,18 @@ discard block |
||
| 67 | 67 | // dd($domArray); |
| 68 | 68 | // Editor::vdom($domArray); |
| 69 | 69 | |
| 70 | - $ele=dom_import_simplexml($x); |
|
| 70 | + $ele = dom_import_simplexml($x); |
|
| 71 | 71 | $dom = new DOMDocument('1.0', 'utf-8'); |
| 72 | - $element=$dom->importNode($ele,true); |
|
| 72 | + $element = $dom->importNode($ele, true); |
|
| 73 | 73 | $element->normalize(); |
| 74 | 74 | |
| 75 | 75 | $dom = simplexml_import_dom($x); |
| 76 | - foreach($dom as $d) dp($d); |
|
| 76 | + foreach ($dom as $d) dp($d); |
|
| 77 | 77 | exit; |
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | $vdom = []; |
| 81 | - foreach($x as $n) { |
|
| 81 | + foreach ($x as $n) { |
|
| 82 | 82 | Editor::node($vdom, $n); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $props = '{"components":null, "contentKey": "'.$id.'"}'; |
| 101 | 101 | if ($content !== null) { |
| 102 | 102 | // read the json data serialised inside the <!-- ni:editor {json data} --> tag |
| 103 | - $pattern = '/<!--\s+(?P<closer>\/)?ni:editor\s+(?P<attrs>{(?:(?:[^}]+|}+(?=})|(?!}\s+\/?-->).)*+)?}\s+)?(?P<void>\/)?-->/s'; |
|
| 103 | + $pattern = '/<!--\s+(?P<closer>\/)?ni:editor\s+(?P<attrs>{(?:(?:[^}]+|}+(?=})|(?!}\s+\/?-->).)*+)?}\s+)?(?P<void>\/)?-->/s'; |
|
| 104 | 104 | preg_match($pattern, $content, $matches); |
| 105 | 105 | if ($matches) { |
| 106 | 106 | $props = $matches['attrs']; |
@@ -147,18 +147,18 @@ discard block |
||
| 147 | 147 | * [children] => Array |
| 148 | 148 | * [props] => Array |
| 149 | 149 | */ |
| 150 | - public static function renderAsSmarty($node, &$depth=0) |
|
| 150 | + public static function renderAsSmarty($node, &$depth = 0) |
|
| 151 | 151 | { |
| 152 | 152 | $depth++; |
| 153 | 153 | $cmp = $node['cmp']; |
| 154 | 154 | $uuid = $node['uuid']; |
| 155 | 155 | $children = $node['children']; |
| 156 | 156 | $props = $node['props']; |
| 157 | - $out = '{'."$cmp " . static::formatProps($props) . " uuid=\"$uuid\" }\n"; |
|
| 158 | - foreach($children as $child) { |
|
| 159 | - $out .= str_repeat(' ', $depth) . static::renderAsSmarty($child, $depth); |
|
| 157 | + $out = '{'."$cmp ".static::formatProps($props)." uuid=\"$uuid\" }\n"; |
|
| 158 | + foreach ($children as $child) { |
|
| 159 | + $out .= str_repeat(' ', $depth).static::renderAsSmarty($child, $depth); |
|
| 160 | 160 | } |
| 161 | - $out .= str_repeat(' ', $depth-1) . '{/'.$cmp."}\n"; |
|
| 161 | + $out .= str_repeat(' ', $depth - 1).'{/'.$cmp."}\n"; |
|
| 162 | 162 | $depth--; |
| 163 | 163 | return $out; |
| 164 | 164 | } |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | { |
| 168 | 168 | unset($props['children']); |
| 169 | 169 | $formatParams = ''; |
| 170 | - foreach($props as $key => $value) { |
|
| 170 | + foreach ($props as $key => $value) { |
|
| 171 | 171 | if (is_array($value)) $value = var_export($value, true); |
| 172 | - $formatParams .= $key.'="'. $value .'" '; |
|
| 172 | + $formatParams .= $key.'="'.$value.'" '; |
|
| 173 | 173 | } |
| 174 | 174 | return $formatParams; |
| 175 | 175 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | public static function createFromTree($cmpIndex, $root) { |
| 185 | 185 | $out = $root; |
| 186 | - foreach($root['children'] as $key => $childId) { |
|
| 186 | + foreach ($root['children'] as $key => $childId) { |
|
| 187 | 187 | if (!empty($out['children'])) { |
| 188 | 188 | $out['children'][$key] = static::createFromTree($cmpIndex, $cmpIndex[$childId]); |
| 189 | 189 | } |
@@ -55,7 +55,9 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public static function editor($params, $content, \Smarty_Internal_Template $template, &$repeat) |
| 57 | 57 | { |
| 58 | - if ($repeat) return; |
|
| 58 | + if ($repeat) { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 59 | 61 | $id = Arr::get($params, 'id', neon()->cms->getPage()->getId()); |
| 60 | 62 | $dbContent = neon()->getCms()->getICmsStaticData()->getStaticContent($id, null); |
| 61 | 63 | if (!$dbContent) { |
@@ -73,7 +75,9 @@ discard block |
||
| 73 | 75 | $element->normalize(); |
| 74 | 76 | |
| 75 | 77 | $dom = simplexml_import_dom($x); |
| 76 | - foreach($dom as $d) dp($d); |
|
| 78 | + foreach($dom as $d) { |
|
| 79 | + dp($d); |
|
| 80 | + } |
|
| 77 | 81 | exit; |
| 78 | 82 | |
| 79 | 83 | |
@@ -168,7 +172,9 @@ discard block |
||
| 168 | 172 | unset($props['children']); |
| 169 | 173 | $formatParams = ''; |
| 170 | 174 | foreach($props as $key => $value) { |
| 171 | - if (is_array($value)) $value = var_export($value, true); |
|
| 175 | + if (is_array($value)) { |
|
| 176 | + $value = var_export($value, true); |
|
| 177 | + } |
|
| 172 | 178 | $formatParams .= $key.'="'. $value .'" '; |
| 173 | 179 | } |
| 174 | 180 | return $formatParams; |
@@ -561,8 +561,8 @@ discard block |
||
| 561 | 561 | |
| 562 | 562 | $html = []; |
| 563 | 563 | $params['loading'] = Arr::get($params, 'loading', 'lazy'); |
| 564 | - $params[Arr::get($params, 'srcset-name', 'srcset')] = Arr::get($params, 'srcset', $this->image_srcset(array_merge(['src' => $id], $params))); |
|
| 565 | - $params[Arr::get($params, 'src-name', 'src')] = $this->firefly_image(array_merge(['id' => $id, 'w' => (int)$srcWidth], $params)); |
|
| 564 | + $params[Arr::get($params, 'srcset-name', 'srcset')] = Arr::get($params, 'srcset', $this->image_srcset(array_merge(['src' => $id], $params))); |
|
| 565 | + $params[Arr::get($params, 'src-name', 'src')] = $this->firefly_image(array_merge(['id' => $id, 'w' => (int)$srcWidth], $params)); |
|
| 566 | 566 | |
| 567 | 567 | // alt |
| 568 | 568 | $params['alt'] = Arr::get($params, 'alt', $this->image_alt(['src' => $id])); |
@@ -917,7 +917,4 @@ discard block |
||
| 917 | 917 | if (!empty($params['assign'])) { |
| 918 | 918 | $smarty->assign($params['assign'], $output); |
| 919 | 919 | } else { |
| 920 | - return $output; |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | -} |
|
| 920 | + return $output |
|
| 924 | 921 | \ No newline at end of file |
@@ -333,7 +333,4 @@ |
||
| 333 | 333 | return $html; |
| 334 | 334 | } |
| 335 | 335 | profile_end('Html::Highlight'); |
| 336 | - return $html; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | -} |
|
| 336 | + return $html |
|
| 340 | 337 | \ No newline at end of file |
@@ -333,7 +333,4 @@ |
||
| 333 | 333 | return $html; |
| 334 | 334 | } |
| 335 | 335 | profile_end('Html::Highlight'); |
| 336 | - return $html; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | -} |
|
| 336 | + return $html |
|
| 340 | 337 | \ No newline at end of file |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | public static function displayAsTags($tagsArray, $class = 'label label-info') |
| 20 | 20 | { |
| 21 | 21 | $out = ''; |
| 22 | - foreach($tagsArray as $tag) { |
|
| 22 | + foreach ($tagsArray as $tag) { |
|
| 23 | 23 | $out .= "<span class=\"$class\">$tag</span>"; |
| 24 | 24 | } |
| 25 | 25 | return $out; |
@@ -333,7 +333,4 @@ discard block |
||
| 333 | 333 | return $html; |
| 334 | 334 | } |
| 335 | 335 | profile_end('Html::Highlight'); |
| 336 | - return $html; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | -} |
|
| 336 | + return $html |
|
| 340 | 337 | \ No newline at end of file |
@@ -333,7 +333,4 @@ |
||
| 333 | 333 | return $html; |
| 334 | 334 | } |
| 335 | 335 | profile_end('Html::Highlight'); |
| 336 | - return $html; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | -} |
|
| 336 | + return $html |
|
| 340 | 337 | \ No newline at end of file |
@@ -333,7 +333,4 @@ |
||
| 333 | 333 | return $html; |
| 334 | 334 | } |
| 335 | 335 | profile_end('Html::Highlight'); |
| 336 | - return $html; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | -} |
|
| 336 | + return $html |
|
| 340 | 337 | \ No newline at end of file |