@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | $this->setEntityTable($db_name); |
| 92 | 92 | |
| 93 | - if($this->getEntityTable()=='' || $this->getPrimaryKey()==''){ |
|
| 93 | + if ($this->getEntityTable()=='' || $this->getPrimaryKey()=='') { |
|
| 94 | 94 | throw new InvalidEntityPropertyException('Свойства entityTable или key не заданы'); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | return $this->adapter; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - public function setAdapter(QueryBuilderInterface $adapter){ |
|
| 105 | + public function setAdapter(QueryBuilderInterface $adapter) { |
|
| 106 | 106 | $this->adapter = $adapter; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * Уставнока таблицы |
| 116 | 116 | */ |
| 117 | 117 | protected function setEntityTable($db_name) { |
| 118 | - $this->entityTable = !empty($db_name)? "$db_name.".$this->table : $this->table; |
|
| 118 | + $this->entityTable = !empty($db_name) ? "$db_name.".$this->table : $this->table; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function findById($id) |
| 127 | 127 | { |
| 128 | - $Criteria = (new Specification())->setWhere($this->key , $id); |
|
| 128 | + $Criteria = (new Specification())->setWhere($this->key, $id); |
|
| 129 | 129 | |
| 130 | 130 | return $this->findBySpecification($Criteria); |
| 131 | 131 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | $data = $this->unbuildEntity($Entity); |
| 140 | 140 | |
| 141 | - if(method_exists($this, 'onPrepareData' )) $this->onPrepareData( $Entity , $data ); |
|
| 141 | + if (method_exists($this, 'onPrepareData')) $this->onPrepareData($Entity, $data); |
|
| 142 | 142 | |
| 143 | 143 | $id = $data[$this->getPrimaryKey()]; |
| 144 | 144 | unset($data[$this->getPrimaryKey()]); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | unset($data[$this->setSoftDeleteKey()]); |
| 150 | 150 | |
| 151 | - $this->getAdapter()->insert($this->getEntityTable(),$data); |
|
| 151 | + $this->getAdapter()->insert($this->getEntityTable(), $data); |
|
| 152 | 152 | |
| 153 | 153 | if (!$id = $this->getAdapter()->insert_id()) { |
| 154 | 154 | return false; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | //update |
| 160 | 160 | else { |
| 161 | 161 | |
| 162 | - if(!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")){ |
|
| 162 | + if (!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")) { |
|
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -174,13 +174,13 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function save(EntityInterface $Entity) |
| 176 | 176 | { |
| 177 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity ); |
|
| 177 | + if (method_exists($this, 'onAfterSave')) $this->onAfterSave($Entity); |
|
| 178 | 178 | |
| 179 | - if(!$this->saveWithoutEvents($Entity)){ |
|
| 179 | + if (!$this->saveWithoutEvents($Entity)) { |
|
| 180 | 180 | return false; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
| 183 | + if (method_exists($this, 'onBeforeSave')) $this->onBeforeSave($Entity); |
|
| 184 | 184 | |
| 185 | 185 | return true; |
| 186 | 186 | } |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | * получение мапперов в порядке их использования с учетом вложенности |
| 191 | 191 | * @return array |
| 192 | 192 | */ |
| 193 | - protected function createListRelation(){ |
|
| 193 | + protected function createListRelation() { |
|
| 194 | 194 | $rel_list = []; |
| 195 | 195 | |
| 196 | 196 | $rel_map = $this->getRelations(); |
| 197 | 197 | |
| 198 | - $this->createListRelationReq($rel_map,$rel_list); |
|
| 198 | + $this->createListRelationReq($rel_map, $rel_list); |
|
| 199 | 199 | |
| 200 | 200 | return $rel_list; |
| 201 | 201 | } |
@@ -205,17 +205,17 @@ discard block |
||
| 205 | 205 | * @param array $rel_map |
| 206 | 206 | * @param type $rel_list |
| 207 | 207 | */ |
| 208 | - protected function createListRelationReq(array $rel_map,&$rel_list,$obj_parent_link = null) { |
|
| 208 | + protected function createListRelationReq(array $rel_map, &$rel_list, $obj_parent_link = null) { |
|
| 209 | 209 | |
| 210 | - foreach ($rel_map as $rel){ |
|
| 210 | + foreach ($rel_map as $rel) { |
|
| 211 | 211 | |
| 212 | 212 | $obj_link = '#'.$rel['alias'].'()'; |
| 213 | 213 | |
| 214 | - if(count($rel['relations'])>0){ |
|
| 215 | - $this->createListRelationReq($rel['relations'],$rel_list,$obj_parent_link.'get'.$rel['alias'].'()'); |
|
| 216 | - $rel_list [$obj_parent_link.$obj_link]= $rel['name']; |
|
| 214 | + if (count($rel['relations']) > 0) { |
|
| 215 | + $this->createListRelationReq($rel['relations'], $rel_list, $obj_parent_link.'get'.$rel['alias'].'()'); |
|
| 216 | + $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
|
| 217 | 217 | } |
| 218 | - else{ |
|
| 218 | + else { |
|
| 219 | 219 | $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
| 220 | 220 | } |
| 221 | 221 | } |
@@ -225,12 +225,12 @@ discard block |
||
| 225 | 225 | /** |
| 226 | 226 | * получить связи |
| 227 | 227 | */ |
| 228 | - protected function getRelations(){ |
|
| 228 | + protected function getRelations() { |
|
| 229 | 229 | $rel_map = []; |
| 230 | - foreach ($this->mapping_fields as $field => $cfg){ |
|
| 231 | - if(isset($cfg['relation'])){ |
|
| 230 | + foreach ($this->mapping_fields as $field => $cfg) { |
|
| 231 | + if (isset($cfg['relation'])) { |
|
| 232 | 232 | $rels = $this->DI->get($cfg['relation'])->getRelations(); |
| 233 | - $rel_map []= [ |
|
| 233 | + $rel_map [] = [ |
|
| 234 | 234 | 'name' => $cfg['relation'], |
| 235 | 235 | 'alias' => $field, |
| 236 | 236 | 'relations' => $rels |
@@ -254,23 +254,23 @@ discard block |
||
| 254 | 254 | * @return \Core\Infrastructure\EntityInterface |
| 255 | 255 | * @throws BadMethodCallException |
| 256 | 256 | */ |
| 257 | - protected function buildEntity(EntityInterface $Entity, array $row){ |
|
| 257 | + protected function buildEntity(EntityInterface $Entity, array $row) { |
|
| 258 | 258 | //ed($row); |
| 259 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
| 259 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
| 260 | 260 | |
| 261 | 261 | $value = false; |
| 262 | 262 | |
| 263 | 263 | //автоопределени формата массива |
| 264 | 264 | $field = $cfg['field']; |
| 265 | 265 | |
| 266 | - $method_set = 'set' . ucfirst($alias); |
|
| 266 | + $method_set = 'set'.ucfirst($alias); |
|
| 267 | 267 | |
| 268 | - if(!method_exists($Entity, $method_set )){ |
|
| 268 | + if (!method_exists($Entity, $method_set)) { |
|
| 269 | 269 | throw new BadMethodCallException("Метод {$method_set} не определен"); |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | //событие на формирование поля |
| 273 | - if( isset($cfg['build']) && is_object($cfg['build']) ){ |
|
| 273 | + if (isset($cfg['build']) && is_object($cfg['build'])) { |
|
| 274 | 274 | |
| 275 | 275 | // ed([ |
| 276 | 276 | // get_class($Entity), |
@@ -281,11 +281,11 @@ discard block |
||
| 281 | 281 | $value = call_user_func($cfg['build'], $row); |
| 282 | 282 | } |
| 283 | 283 | //на связь |
| 284 | - elseif(isset($cfg['relation'])){ |
|
| 284 | + elseif (isset($cfg['relation'])) { |
|
| 285 | 285 | |
| 286 | 286 | $mapper = $this->DI->get($cfg['relation']); |
| 287 | 287 | |
| 288 | - if($this->use_joins===true || empty($row[$field])){ |
|
| 288 | + if ($this->use_joins===true || empty($row[$field])) { |
|
| 289 | 289 | |
| 290 | 290 | $value = $mapper->createEntity($row); |
| 291 | 291 | |
@@ -296,17 +296,17 @@ discard block |
||
| 296 | 296 | // ]); |
| 297 | 297 | |
| 298 | 298 | } |
| 299 | - else{ |
|
| 300 | - $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
|
| 299 | + else { |
|
| 300 | + $fkey = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
| 301 | 301 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | } |
| 305 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
| 305 | + elseif (is_string($field) && isset($row[strtolower($field)])) { |
|
| 306 | 306 | $value = $row[strtolower($field)]; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if($value!==false) |
|
| 309 | + if ($value!==false) |
|
| 310 | 310 | $Entity->{$method_set}($value); |
| 311 | 311 | |
| 312 | 312 | } |
@@ -321,11 +321,11 @@ discard block |
||
| 321 | 321 | * @return \Core\Infrastructure\EntityInterface |
| 322 | 322 | * @throws BadMethodCallException |
| 323 | 323 | */ |
| 324 | - protected function unbuildEntity(EntityInterface $Entity){ |
|
| 324 | + protected function unbuildEntity(EntityInterface $Entity) { |
|
| 325 | 325 | |
| 326 | 326 | $row = []; |
| 327 | 327 | |
| 328 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
| 328 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
| 329 | 329 | |
| 330 | 330 | //автоопределени формата массива |
| 331 | 331 | // if(isset($row[$this->key])){ |
@@ -336,19 +336,19 @@ discard block |
||
| 336 | 336 | // } |
| 337 | 337 | $field = $cfg['field']; |
| 338 | 338 | |
| 339 | - $method_get = 'get' . ucfirst($alias); |
|
| 339 | + $method_get = 'get'.ucfirst($alias); |
|
| 340 | 340 | |
| 341 | - if(!method_exists($Entity, $method_get )){ |
|
| 341 | + if (!method_exists($Entity, $method_get)) { |
|
| 342 | 342 | throw new BadMethodCallException("Метод {$method_get} не определен"); |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | //-------------------------------------------------------------------- |
| 346 | - if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
|
| 347 | - $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
|
| 346 | + if (isset($cfg['unbuild']) && is_object($cfg['unbuild'])) { |
|
| 347 | + $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}()); |
|
| 348 | 348 | } |
| 349 | - elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){ |
|
| 349 | + elseif (isset($cfg['relation']) && is_object($Entity->{$method_get}())) { |
|
| 350 | 350 | |
| 351 | - if(isset($cfg['on'])) |
|
| 351 | + if (isset($cfg['on'])) |
|
| 352 | 352 | $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
| 353 | 353 | else |
| 354 | 354 | $fkey = 'id'; |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
| 357 | 357 | |
| 358 | 358 | } |
| 359 | - else{ |
|
| 359 | + else { |
|
| 360 | 360 | $value = $Entity->{$method_get}(); |
| 361 | 361 | } |
| 362 | 362 | |
@@ -370,22 +370,22 @@ discard block |
||
| 370 | 370 | /** |
| 371 | 371 | * Установка поля для маппинга |
| 372 | 372 | */ |
| 373 | - protected function addMappingField($alias,$field = null){ |
|
| 373 | + protected function addMappingField($alias, $field = null) { |
|
| 374 | 374 | |
| 375 | - if(is_string($field)){ |
|
| 375 | + if (is_string($field)) { |
|
| 376 | 376 | $field = ['field' => $field]; |
| 377 | 377 | } |
| 378 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
| 379 | - $field['field'] = $alias; |
|
| 378 | + elseif ((is_array($field) && !isset($field['field'])) || empty($field)) { |
|
| 379 | + $field['field'] = $alias; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | $this->mapping_fields[$alias] = $field; |
| 383 | 383 | |
| 384 | - if(isset($field['primary']) && $field['primary']===true){ |
|
| 384 | + if (isset($field['primary']) && $field['primary']===true) { |
|
| 385 | 385 | $this->key = $field['field']; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if(isset($field['softdelete']) && $field['softdelete']===true){ |
|
| 388 | + if (isset($field['softdelete']) && $field['softdelete']===true) { |
|
| 389 | 389 | $this->soft_delete_key = $field['field']; |
| 390 | 390 | } |
| 391 | 391 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @param type $field |
| 417 | 417 | * @return type |
| 418 | 418 | */ |
| 419 | - public function getFieldAlias($field){ |
|
| 419 | + public function getFieldAlias($field) { |
|
| 420 | 420 | return $this->mapping_fields_aliases[$field]; |
| 421 | 421 | } |
| 422 | 422 | |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | * @param ISpecificationCriteria $specification |
| 437 | 437 | * @return type |
| 438 | 438 | */ |
| 439 | - public function findBySpecification(ISpecificationCriteria $specification){ |
|
| 439 | + public function findBySpecification(ISpecificationCriteria $specification) { |
|
| 440 | 440 | |
| 441 | 441 | //псеводо удаление |
| 442 | 442 | $this->setSoftDelete($specification); |
@@ -446,13 +446,13 @@ discard block |
||
| 446 | 446 | $specification->setLimit(1); |
| 447 | 447 | |
| 448 | 448 | //получение записей |
| 449 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
| 449 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
| 450 | 450 | |
| 451 | 451 | if (!$row = $res->row_array()) { |
| 452 | 452 | return null; |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - if($this->result_array===true){ |
|
| 455 | + if ($this->result_array===true) { |
|
| 456 | 456 | return $row; |
| 457 | 457 | } |
| 458 | 458 | |
@@ -473,13 +473,13 @@ discard block |
||
| 473 | 473 | |
| 474 | 474 | if ( |
| 475 | 475 | $delete_key > '' && |
| 476 | - $Entity->getId() > 0){ |
|
| 477 | - $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
| 476 | + $Entity->getId() > 0) { |
|
| 477 | + $result = $this->getAdapter()->update($this->getEntityTable(), [$delete_key => 1], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
| 478 | 478 | } |
| 479 | - elseif($Entity->getId() > 0){ |
|
| 479 | + elseif ($Entity->getId() > 0) { |
|
| 480 | 480 | |
| 481 | - if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
|
| 482 | - if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
|
| 481 | + if ($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())) { |
|
| 482 | + if (method_exists($this, 'onBeforeDelete')) { $result = $this->onBeforeDelete($Entity); } |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | |
@@ -496,17 +496,17 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | $this->setRelations($specification); |
| 498 | 498 | |
| 499 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
| 499 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
| 500 | 500 | |
| 501 | 501 | if (!$rows = $res->result_array()) { |
| 502 | 502 | return null; |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | - if($this->result_array===true){ |
|
| 505 | + if ($this->result_array===true) { |
|
| 506 | 506 | return $rows; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - foreach($rows as $k => $row){ |
|
| 509 | + foreach ($rows as $k => $row) { |
|
| 510 | 510 | $rows[$k] = $this->createEntity($row); |
| 511 | 511 | } |
| 512 | 512 | |
@@ -522,13 +522,13 @@ discard block |
||
| 522 | 522 | * Выборка удаленных моделей |
| 523 | 523 | * @param ISpecificationCriteria $specification |
| 524 | 524 | */ |
| 525 | - private function setSoftDelete(ISpecificationCriteria $specification){ |
|
| 526 | - if( |
|
| 527 | - $this->use_delete === false && |
|
| 528 | - $this->setSoftDeleteKey()>'' |
|
| 525 | + private function setSoftDelete(ISpecificationCriteria $specification) { |
|
| 526 | + if ( |
|
| 527 | + $this->use_delete===false && |
|
| 528 | + $this->setSoftDeleteKey() > '' |
|
| 529 | 529 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
| 530 | 530 | ) |
| 531 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
| 531 | + $specification->setWhere($this->setSoftDeleteKey(), 0); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -539,12 +539,12 @@ discard block |
||
| 539 | 539 | * belongs_to - многие к многим (пользователь имет множество оплат одного заказа) |
| 540 | 540 | * has_one - один к одному |
| 541 | 541 | */ |
| 542 | - protected function setRelations(ISpecificationCriteria $Specification){ |
|
| 542 | + protected function setRelations(ISpecificationCriteria $Specification) { |
|
| 543 | 543 | |
| 544 | 544 | $joins = []; |
| 545 | 545 | |
| 546 | - foreach ($this->mapping_fields as $field => $cfg){ |
|
| 547 | - if(isset($cfg['relation'])){ |
|
| 546 | + foreach ($this->mapping_fields as $field => $cfg) { |
|
| 547 | + if (isset($cfg['relation'])) { |
|
| 548 | 548 | |
| 549 | 549 | $reltype = isset($cfg['reltype']) ? $cfg['reltype'] : 'belongs_to'; |
| 550 | 550 | |
@@ -555,18 +555,18 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | $table = $mapper->getEntityTable(); |
| 557 | 557 | |
| 558 | - $relation_key = isset($cfg['on'])? $cfg['on'] : $mapper->key; |
|
| 558 | + $relation_key = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
| 559 | 559 | |
| 560 | 560 | $joins[$table] = [ |
| 561 | 561 | 'alias' => $field, |
| 562 | - 'type' => $reltype != 'has_many' ? 'INNER' : 'LEFT OUTER', |
|
| 562 | + 'type' => $reltype!='has_many' ? 'INNER' : 'LEFT OUTER', |
|
| 563 | 563 | 'on' => "`{$this->table}`.{$cfg['field']} = `{$field}`.{$relation_key}" |
| 564 | 564 | ]; |
| 565 | 565 | |
| 566 | 566 | } |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - if($this->use_joins===true){ |
|
| 569 | + if ($this->use_joins===true) { |
|
| 570 | 570 | $Specification->setJoins($joins); |
| 571 | 571 | } |
| 572 | 572 | } |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | return $o; |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - public function withDelete(){ |
|
| 584 | + public function withDelete() { |
|
| 585 | 585 | $o = clone $this; |
| 586 | 586 | $o->use_delete = true; |
| 587 | 587 | return $o; |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | * Данные только в массиве |
| 592 | 592 | * @return \SimpleORM\AbstractDataMapper |
| 593 | 593 | */ |
| 594 | - public function resultArray(){ |
|
| 594 | + public function resultArray() { |
|
| 595 | 595 | $o = clone $this; |
| 596 | 596 | $o->result_array = true; |
| 597 | 597 | return $o; |
@@ -138,7 +138,9 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | $data = $this->unbuildEntity($Entity); |
| 140 | 140 | |
| 141 | - if(method_exists($this, 'onPrepareData' )) $this->onPrepareData( $Entity , $data ); |
|
| 141 | + if(method_exists($this, 'onPrepareData' )) { |
|
| 142 | + $this->onPrepareData( $Entity , $data ); |
|
| 143 | + } |
|
| 142 | 144 | |
| 143 | 145 | $id = $data[$this->getPrimaryKey()]; |
| 144 | 146 | unset($data[$this->getPrimaryKey()]); |
@@ -174,13 +176,17 @@ discard block |
||
| 174 | 176 | */ |
| 175 | 177 | public function save(EntityInterface $Entity) |
| 176 | 178 | { |
| 177 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity ); |
|
| 179 | + if(method_exists($this, 'onAfterSave' )) { |
|
| 180 | + $this->onAfterSave( $Entity ); |
|
| 181 | + } |
|
| 178 | 182 | |
| 179 | 183 | if(!$this->saveWithoutEvents($Entity)){ |
| 180 | 184 | return false; |
| 181 | 185 | } |
| 182 | 186 | |
| 183 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
| 187 | + if(method_exists($this, 'onBeforeSave' )) { |
|
| 188 | + $this->onBeforeSave( $Entity ); |
|
| 189 | + } |
|
| 184 | 190 | |
| 185 | 191 | return true; |
| 186 | 192 | } |
@@ -214,8 +220,7 @@ discard block |
||
| 214 | 220 | if(count($rel['relations'])>0){ |
| 215 | 221 | $this->createListRelationReq($rel['relations'],$rel_list,$obj_parent_link.'get'.$rel['alias'].'()'); |
| 216 | 222 | $rel_list [$obj_parent_link.$obj_link]= $rel['name']; |
| 217 | - } |
|
| 218 | - else{ |
|
| 223 | + } else{ |
|
| 219 | 224 | $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
| 220 | 225 | } |
| 221 | 226 | } |
@@ -295,19 +300,18 @@ discard block |
||
| 295 | 300 | // $value |
| 296 | 301 | // ]); |
| 297 | 302 | |
| 298 | - } |
|
| 299 | - else{ |
|
| 303 | + } else{ |
|
| 300 | 304 | $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
| 301 | 305 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
| 302 | 306 | } |
| 303 | 307 | |
| 304 | - } |
|
| 305 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
| 308 | + } elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
| 306 | 309 | $value = $row[strtolower($field)]; |
| 307 | 310 | } |
| 308 | 311 | |
| 309 | - if($value!==false) |
|
| 310 | - $Entity->{$method_set}($value); |
|
| 312 | + if($value!==false) { |
|
| 313 | + $Entity->{$method_set}($value); |
|
| 314 | + } |
|
| 311 | 315 | |
| 312 | 316 | } |
| 313 | 317 | |
@@ -345,18 +349,17 @@ discard block |
||
| 345 | 349 | //-------------------------------------------------------------------- |
| 346 | 350 | if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
| 347 | 351 | $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
| 348 | - } |
|
| 349 | - elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){ |
|
| 352 | + } elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){ |
|
| 350 | 353 | |
| 351 | - if(isset($cfg['on'])) |
|
| 352 | - $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
| 353 | - else |
|
| 354 | - $fkey = 'id'; |
|
| 354 | + if(isset($cfg['on'])) { |
|
| 355 | + $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
| 356 | + } else { |
|
| 357 | + $fkey = 'id'; |
|
| 358 | + } |
|
| 355 | 359 | |
| 356 | 360 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
| 357 | 361 | |
| 358 | - } |
|
| 359 | - else{ |
|
| 362 | + } else{ |
|
| 360 | 363 | $value = $Entity->{$method_get}(); |
| 361 | 364 | } |
| 362 | 365 | |
@@ -374,8 +377,7 @@ discard block |
||
| 374 | 377 | |
| 375 | 378 | if(is_string($field)){ |
| 376 | 379 | $field = ['field' => $field]; |
| 377 | - } |
|
| 378 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
| 380 | + } elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
| 379 | 381 | $field['field'] = $alias; |
| 380 | 382 | } |
| 381 | 383 | |
@@ -475,8 +477,7 @@ discard block |
||
| 475 | 477 | $delete_key > '' && |
| 476 | 478 | $Entity->getId() > 0){ |
| 477 | 479 | $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
| 478 | - } |
|
| 479 | - elseif($Entity->getId() > 0){ |
|
| 480 | + } elseif($Entity->getId() > 0){ |
|
| 480 | 481 | |
| 481 | 482 | if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
| 482 | 483 | if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
@@ -527,8 +528,9 @@ discard block |
||
| 527 | 528 | $this->use_delete === false && |
| 528 | 529 | $this->setSoftDeleteKey()>'' |
| 529 | 530 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
| 530 | - ) |
|
| 531 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
| 531 | + ) { |
|
| 532 | + $specification->setWhere($this->setSoftDeleteKey(),0); |
|
| 533 | + } |
|
| 532 | 534 | } |
| 533 | 535 | |
| 534 | 536 | /** |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | protected function onPrepareData(\SimpleORM\EntityInterface $Entity, &$data) { |
| 23 | 23 | foreach ($this->mapping_fields as $field => $cfg) { |
| 24 | - if (isset($cfg['null']) && $cfg['null'] === false && empty($data[$cfg['field']])) { |
|
| 24 | + if (isset($cfg['null']) && $cfg['null']===false && empty($data[$cfg['field']])) { |
|
| 25 | 25 | $data[$cfg['field']] = $cfg['default']; |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | foreach ($this->relations as $alias => $cfg) { |
| 36 | 36 | $mapper = $cfg['mapper']; |
| 37 | 37 | //если связь один к одному то удаляем сущность |
| 38 | - if ($cfg['reltype'] == 'has_one') { |
|
| 39 | - $Entity = $Entity->{'get' . $alias}(); |
|
| 38 | + if ($cfg['reltype']=='has_one') { |
|
| 39 | + $Entity = $Entity->{'get'.$alias}(); |
|
| 40 | 40 | if (!$mapper->delete($Entity)) { |
| 41 | 41 | throw new \Autoprice\Exceptions\EntityNotDeleteException('Unable to delete Entity!'); |
| 42 | 42 | } |
@@ -62,25 +62,25 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | $set_path = str_replace(['#', '();'], ['->set', '($o);'], $call_obj); |
| 64 | 64 | |
| 65 | - $ar_path = explode('()',$obj_path); |
|
| 65 | + $ar_path = explode('()', $obj_path); |
|
| 66 | 66 | |
| 67 | 67 | $o = $Entity; |
| 68 | 68 | |
| 69 | - foreach ($ar_path as $_m){ |
|
| 69 | + foreach ($ar_path as $_m) { |
|
| 70 | 70 | |
| 71 | - $_mc = str_replace('#','get',ucfirst($_m)); |
|
| 71 | + $_mc = str_replace('#', 'get', ucfirst($_m)); |
|
| 72 | 72 | |
| 73 | 73 | //Set logic |
| 74 | - if(empty($_m)){ |
|
| 74 | + if (empty($_m)) { |
|
| 75 | 75 | |
| 76 | - $_mc = ltrim( $ar_path[(count($ar_path)-2)] , '#'); |
|
| 76 | + $_mc = ltrim($ar_path[(count($ar_path) - 2)], '#'); |
|
| 77 | 77 | |
| 78 | - if (isset($$_mc) && is_object($$_mc) && is_a($$_mc,'SimpleORM\EntityInterface') && $this->DI->get($mapper)->saveWithoutEvents($o)) { |
|
| 78 | + if (isset($$_mc) && is_object($$_mc) && is_a($$_mc, 'SimpleORM\EntityInterface') && $this->DI->get($mapper)->saveWithoutEvents($o)) { |
|
| 79 | 79 | $o = $$_mc; |
| 80 | 80 | eval($set_path); |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | - elseif(is_object($o) ){ |
|
| 83 | + elseif (is_object($o)) { |
|
| 84 | 84 | $$_mc = $o->{$_mc}(); |
| 85 | 85 | $o = $$_mc; |
| 86 | 86 | } |