@@ -16,7 +16,7 @@ |
||
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Перед сохранением извелкаем объект и дополняем массив для записи, недостающими полями |
19 | - * @param \Autoprice\Domain\Price\EntityInterface $Entity |
|
19 | + * @param EntityInterface $Entity |
|
20 | 20 | * @param type $data |
21 | 21 | */ |
22 | 22 | protected function onPrepareData(\SimpleORM\EntityInterface $Entity, &$data) { |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | protected function onPrepareData(\SimpleORM\EntityInterface $Entity, &$data) { |
23 | 23 | foreach ($this->mapping_fields as $field => $cfg) { |
24 | 24 | |
25 | - if ($cfg['null'] === false && empty($data[$cfg['field']])) { |
|
25 | + if ($cfg['null']===false && empty($data[$cfg['field']])) { |
|
26 | 26 | $data[$cfg['field']] = $cfg['default']; |
27 | 27 | } |
28 | 28 | } |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | foreach ($this->relations as $alias => $cfg) { |
37 | 37 | $mapper = $cfg['mapper']; |
38 | 38 | //если связь один к одному то удаляем сущность |
39 | - if ($cgg['reltype'] == 'has_one') { |
|
40 | - $Entity = $Entity->{'get' . $alias}(); |
|
39 | + if ($cgg['reltype']=='has_one') { |
|
40 | + $Entity = $Entity->{'get'.$alias}(); |
|
41 | 41 | if (!$mapper->delete($Entity)) { |
42 | 42 | throw new \Autoprice\Exceptions\EntityNotDeleteException('Unable to delete Entity!'); |
43 | 43 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | |
60 | 60 | foreach ($rel_list as $obj_path => $mapper) { |
61 | 61 | |
62 | - $get_path = str_replace('#', '->get', '$o = $Entity' . $obj_path . ';'); |
|
63 | - $set_path = str_replace(['#', '();'], ['->set', '($o);'], '$Entity' . $obj_path . ';'); |
|
62 | + $get_path = str_replace('#', '->get', '$o = $Entity'.$obj_path.';'); |
|
63 | + $set_path = str_replace(['#', '();'], ['->set', '($o);'], '$Entity'.$obj_path.';'); |
|
64 | 64 | |
65 | 65 | eval($get_path); //получаем объект таким образом дабы не гулять по корневому объекту |
66 | 66 | |
67 | - if (is_object($o) && is_a($o,'SimpleORM\EntityInterface') && $this->DI->get($mapper)->saveWithoutEvents($o)) { |
|
67 | + if (is_object($o) && is_a($o, 'SimpleORM\EntityInterface') && $this->DI->get($mapper)->saveWithoutEvents($o)) { |
|
68 | 68 | eval($set_path); |
69 | 69 | } |
70 | 70 | unset($o); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | $this->setEntityTable($db_name); |
86 | 86 | |
87 | - if($this->getEntityTable()=='' || $this->getPrimaryKey()==''){ |
|
87 | + if ($this->getEntityTable()=='' || $this->getPrimaryKey()=='') { |
|
88 | 88 | throw new InvalidEntityPropertyException('Свойства entityTable или key не заданы'); |
89 | 89 | } |
90 | 90 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | return $this->adapter; |
97 | 97 | } |
98 | 98 | |
99 | - public function setAdapter(QueryBuilderInterface $adapter){ |
|
99 | + public function setAdapter(QueryBuilderInterface $adapter) { |
|
100 | 100 | $this->adapter = $adapter; |
101 | 101 | } |
102 | 102 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * Уставнока таблицы |
110 | 110 | */ |
111 | 111 | protected function setEntityTable($db_name) { |
112 | - $this->entityTable = !empty($db_name)? "$db_name.".$this->table : $this->table; |
|
112 | + $this->entityTable = !empty($db_name) ? "$db_name.".$this->table : $this->table; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function findById($id) |
121 | 121 | { |
122 | - $Criteria = (new Specification())->setWhere($this->key , $id); |
|
122 | + $Criteria = (new Specification())->setWhere($this->key, $id); |
|
123 | 123 | |
124 | 124 | return $this->findBySpecification($Criteria); |
125 | 125 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $data = $this->unbuildEntity($Entity); |
134 | 134 | |
135 | - if(method_exists($this, 'onPrepareData' )) $this->onPrepareData( $Entity , $data ); |
|
135 | + if (method_exists($this, 'onPrepareData')) $this->onPrepareData($Entity, $data); |
|
136 | 136 | |
137 | 137 | $id = $data[$this->getPrimaryKey()]; |
138 | 138 | unset($data[$this->getPrimaryKey()]); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | |
143 | 143 | unset($data[$this->setSoftDeleteKey()]); |
144 | 144 | |
145 | - $this->getAdapter()->insert($this->getEntityTable(),$data); |
|
145 | + $this->getAdapter()->insert($this->getEntityTable(), $data); |
|
146 | 146 | |
147 | 147 | if (!$id = $this->getAdapter()->insert_id()) { |
148 | 148 | return false; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | //update |
154 | 154 | else { |
155 | 155 | |
156 | - if(!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")){ |
|
156 | + if (!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")) { |
|
157 | 157 | return false; |
158 | 158 | } |
159 | 159 | |
@@ -168,13 +168,13 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function save(EntityInterface $Entity) |
170 | 170 | { |
171 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity ); |
|
171 | + if (method_exists($this, 'onAfterSave')) $this->onAfterSave($Entity); |
|
172 | 172 | |
173 | - if(!$this->saveWithoutEvents($Entity)){ |
|
173 | + if (!$this->saveWithoutEvents($Entity)) { |
|
174 | 174 | return false; |
175 | 175 | } |
176 | 176 | |
177 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
177 | + if (method_exists($this, 'onBeforeSave')) $this->onBeforeSave($Entity); |
|
178 | 178 | |
179 | 179 | return true; |
180 | 180 | } |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | * получение мапперов в порядке их использования с учетом вложенности |
185 | 185 | * @return array |
186 | 186 | */ |
187 | - protected function createListRelation(){ |
|
187 | + protected function createListRelation() { |
|
188 | 188 | $rel_list = []; |
189 | 189 | |
190 | 190 | $rel_map = $this->getRelations(); |
191 | 191 | |
192 | - $this->createListRelationReq($rel_map,$rel_list); |
|
192 | + $this->createListRelationReq($rel_map, $rel_list); |
|
193 | 193 | |
194 | 194 | return $rel_list; |
195 | 195 | } |
@@ -199,17 +199,17 @@ discard block |
||
199 | 199 | * @param array $rel_map |
200 | 200 | * @param type $rel_list |
201 | 201 | */ |
202 | - protected function createListRelationReq(array $rel_map,&$rel_list,$obj_parent_link = null) { |
|
202 | + protected function createListRelationReq(array $rel_map, &$rel_list, $obj_parent_link = null) { |
|
203 | 203 | |
204 | - foreach ($rel_map as $rel){ |
|
204 | + foreach ($rel_map as $rel) { |
|
205 | 205 | |
206 | 206 | $obj_link = '#'.$rel['alias'].'()'; |
207 | 207 | |
208 | - if(count($rel['relations'])>0){ |
|
209 | - $this->createListRelationReq($rel['relations'],$rel_list,$obj_parent_link.'->get'.$rel['alias'].'()'); |
|
210 | - $rel_list [$obj_parent_link.$obj_link]= $rel['name']; |
|
208 | + if (count($rel['relations']) > 0) { |
|
209 | + $this->createListRelationReq($rel['relations'], $rel_list, $obj_parent_link.'->get'.$rel['alias'].'()'); |
|
210 | + $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
|
211 | 211 | } |
212 | - else{ |
|
212 | + else { |
|
213 | 213 | $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
214 | 214 | } |
215 | 215 | } |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | /** |
220 | 220 | * получить связи |
221 | 221 | */ |
222 | - protected function getRelations(){ |
|
222 | + protected function getRelations() { |
|
223 | 223 | $rel_map = []; |
224 | - foreach ($this->mapping_fields as $field => $cfg){ |
|
225 | - if(isset($cfg['relation'])){ |
|
224 | + foreach ($this->mapping_fields as $field => $cfg) { |
|
225 | + if (isset($cfg['relation'])) { |
|
226 | 226 | $rels = $this->DI->get($cfg['relation'])->getRelations(); |
227 | - $rel_map []= [ |
|
227 | + $rel_map [] = [ |
|
228 | 228 | 'name' => $cfg['relation'], |
229 | 229 | 'alias' => $field, |
230 | 230 | 'relations' => $rels |
@@ -248,43 +248,43 @@ discard block |
||
248 | 248 | * @return \Core\Infrastructure\EntityInterface |
249 | 249 | * @throws BadMethodCallException |
250 | 250 | */ |
251 | - protected function buildEntity(EntityInterface $Entity, array $row){ |
|
251 | + protected function buildEntity(EntityInterface $Entity, array $row) { |
|
252 | 252 | |
253 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
253 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
254 | 254 | |
255 | 255 | $value = false; |
256 | 256 | |
257 | 257 | $field = $cfg['field']; |
258 | 258 | |
259 | - $method_set = 'set' . ucfirst($alias); |
|
259 | + $method_set = 'set'.ucfirst($alias); |
|
260 | 260 | |
261 | - if(!method_exists($Entity, $method_set )){ |
|
261 | + if (!method_exists($Entity, $method_set)) { |
|
262 | 262 | throw new BadMethodCallException("Метод {$method_set} не определен"); |
263 | 263 | } |
264 | 264 | |
265 | 265 | //событие на формирование поля |
266 | - if( isset($cfg['build']) && is_object($cfg['build']) ){ |
|
266 | + if (isset($cfg['build']) && is_object($cfg['build'])) { |
|
267 | 267 | $value = call_user_func($cfg['build'], $row); |
268 | 268 | } |
269 | 269 | //на связь |
270 | - elseif(isset($cfg['relation'])){ |
|
270 | + elseif (isset($cfg['relation'])) { |
|
271 | 271 | |
272 | 272 | $mapper = $this->DI->get($cfg['relation']); |
273 | 273 | |
274 | - if($this->use_joins===true || empty($row[$field])){ |
|
274 | + if ($this->use_joins===true || empty($row[$field])) { |
|
275 | 275 | $value = $mapper->createEntity($row); |
276 | 276 | } |
277 | - else{ |
|
278 | - $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
|
277 | + else { |
|
278 | + $fkey = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
279 | 279 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
280 | 280 | } |
281 | 281 | |
282 | 282 | } |
283 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
283 | + elseif (is_string($field) && isset($row[strtolower($field)])) { |
|
284 | 284 | $value = $row[strtolower($field)]; |
285 | 285 | } |
286 | 286 | |
287 | - if($value!==false) |
|
287 | + if ($value!==false) |
|
288 | 288 | $Entity->{$method_set}($value); |
289 | 289 | |
290 | 290 | } |
@@ -299,27 +299,27 @@ discard block |
||
299 | 299 | * @return \Core\Infrastructure\EntityInterface |
300 | 300 | * @throws BadMethodCallException |
301 | 301 | */ |
302 | - protected function unbuildEntity(EntityInterface $Entity){ |
|
302 | + protected function unbuildEntity(EntityInterface $Entity) { |
|
303 | 303 | |
304 | 304 | $row = []; |
305 | 305 | |
306 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
306 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
307 | 307 | |
308 | 308 | $field = $cfg['field']; |
309 | 309 | |
310 | - $method_get = 'get' . ucfirst($alias); |
|
310 | + $method_get = 'get'.ucfirst($alias); |
|
311 | 311 | |
312 | - if(!method_exists($Entity, $method_get )){ |
|
312 | + if (!method_exists($Entity, $method_get)) { |
|
313 | 313 | throw new BadMethodCallException("Метод {$method_get} не определен"); |
314 | 314 | } |
315 | 315 | |
316 | 316 | //-------------------------------------------------------------------- |
317 | - if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
|
318 | - $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
|
317 | + if (isset($cfg['unbuild']) && is_object($cfg['unbuild'])) { |
|
318 | + $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}()); |
|
319 | 319 | } |
320 | - elseif(isset($cfg['relation'])){ |
|
320 | + elseif (isset($cfg['relation'])) { |
|
321 | 321 | |
322 | - if(isset($cfg['on'])) |
|
322 | + if (isset($cfg['on'])) |
|
323 | 323 | $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
324 | 324 | else |
325 | 325 | $fkey = 'id'; |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
328 | 328 | |
329 | 329 | } |
330 | - else{ |
|
330 | + else { |
|
331 | 331 | $value = $Entity->{$method_get}(); |
332 | 332 | } |
333 | 333 | |
@@ -341,22 +341,22 @@ discard block |
||
341 | 341 | /** |
342 | 342 | * Установка поля для маппинга |
343 | 343 | */ |
344 | - protected function addMappingField($alias,$field = null){ |
|
344 | + protected function addMappingField($alias, $field = null) { |
|
345 | 345 | |
346 | - if(is_string($field)){ |
|
346 | + if (is_string($field)) { |
|
347 | 347 | $field = ['field' => $field]; |
348 | 348 | } |
349 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
350 | - $field['field'] = $alias; |
|
349 | + elseif ((is_array($field) && !isset($field['field'])) || empty($field)) { |
|
350 | + $field['field'] = $alias; |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | $this->mapping_fields[$alias] = $field; |
354 | 354 | |
355 | - if(isset($field['primary']) && $field['primary']===true){ |
|
355 | + if (isset($field['primary']) && $field['primary']===true) { |
|
356 | 356 | $this->key = $field['field']; |
357 | 357 | } |
358 | 358 | |
359 | - if(isset($field['softdelete']) && $field['softdelete']===true){ |
|
359 | + if (isset($field['softdelete']) && $field['softdelete']===true) { |
|
360 | 360 | $this->soft_delete_key = $field['field']; |
361 | 361 | } |
362 | 362 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | |
384 | 384 | |
385 | 385 | |
386 | - public function getFieldAlias($field){ |
|
386 | + public function getFieldAlias($field) { |
|
387 | 387 | |
388 | 388 | return $this->mapping_fields_aliases[$field]; |
389 | 389 | |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | * @param ISpecificationCriteria $specification |
396 | 396 | * @return type |
397 | 397 | */ |
398 | - public function findBySpecification(ISpecificationCriteria $specification){ |
|
398 | + public function findBySpecification(ISpecificationCriteria $specification) { |
|
399 | 399 | |
400 | 400 | //псеводо удаление |
401 | 401 | $this->setSoftDelete($specification); |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $specification->setLimit(1); |
406 | 406 | |
407 | 407 | //получение записей |
408 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
408 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
409 | 409 | |
410 | 410 | if (!$row = $res->row_array()) { |
411 | 411 | return null; |
@@ -426,13 +426,13 @@ discard block |
||
426 | 426 | |
427 | 427 | if ( |
428 | 428 | $delete_key > '' && |
429 | - $Entity->getId() > 0){ |
|
430 | - $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
429 | + $Entity->getId() > 0) { |
|
430 | + $result = $this->getAdapter()->update($this->getEntityTable(), [$delete_key => 1], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
431 | 431 | } |
432 | - elseif($Entity->getId() > 0){ |
|
432 | + elseif ($Entity->getId() > 0) { |
|
433 | 433 | |
434 | - if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
|
435 | - if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
|
434 | + if ($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())) { |
|
435 | + if (method_exists($this, 'onBeforeDelete')) { $result = $this->onBeforeDelete($Entity); } |
|
436 | 436 | } |
437 | 437 | } |
438 | 438 | |
@@ -449,13 +449,13 @@ discard block |
||
449 | 449 | |
450 | 450 | $this->setRelations($specification); |
451 | 451 | |
452 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
452 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
453 | 453 | |
454 | 454 | if (!$rows = $res->result_array()) { |
455 | 455 | return null; |
456 | 456 | } |
457 | 457 | |
458 | - foreach($rows as $k => $row){ |
|
458 | + foreach ($rows as $k => $row) { |
|
459 | 459 | $rows[$k] = $this->createEntity($row); |
460 | 460 | } |
461 | 461 | |
@@ -471,13 +471,13 @@ discard block |
||
471 | 471 | * Выборка удаленных моделей |
472 | 472 | * @param ISpecificationCriteria $specification |
473 | 473 | */ |
474 | - private function setSoftDelete(ISpecificationCriteria $specification){ |
|
475 | - if( |
|
476 | - $this->use_delete === false && |
|
477 | - $this->setSoftDeleteKey()>'' |
|
474 | + private function setSoftDelete(ISpecificationCriteria $specification) { |
|
475 | + if ( |
|
476 | + $this->use_delete===false && |
|
477 | + $this->setSoftDeleteKey() > '' |
|
478 | 478 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
479 | 479 | ) |
480 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
480 | + $specification->setWhere($this->setSoftDeleteKey(), 0); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -488,12 +488,12 @@ discard block |
||
488 | 488 | * belongs_to - многие к многим (пользователь имет множество оплат одного заказа) |
489 | 489 | * has_one - один к одному |
490 | 490 | */ |
491 | - protected function setRelations(ISpecificationCriteria $Specification){ |
|
491 | + protected function setRelations(ISpecificationCriteria $Specification) { |
|
492 | 492 | |
493 | 493 | $joins = []; |
494 | 494 | |
495 | - foreach ($this->mapping_fields as $field => $cfg){ |
|
496 | - if(isset($cfg['relation'])){ |
|
495 | + foreach ($this->mapping_fields as $field => $cfg) { |
|
496 | + if (isset($cfg['relation'])) { |
|
497 | 497 | |
498 | 498 | $this->relations[$field] = [ |
499 | 499 | 'mapper' => $mapper = $this->DI->get($cfg['relation']), |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | |
503 | 503 | $table = $mapper->getEntityTable(); |
504 | 504 | |
505 | - $relation_key = isset($cfg['on'])? $cfg['on'] : $mapper->key; |
|
505 | + $relation_key = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
506 | 506 | |
507 | 507 | $joins[$table] = [ |
508 | 508 | 'alias' => $field, |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | } |
514 | 514 | } |
515 | 515 | |
516 | - if($this->use_joins===true){ |
|
516 | + if ($this->use_joins===true) { |
|
517 | 517 | $Specification->setJoins($joins); |
518 | 518 | } |
519 | 519 | } |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | return $o; |
529 | 529 | } |
530 | 530 | |
531 | - public function withDelete(){ |
|
531 | + public function withDelete() { |
|
532 | 532 | $o = clone $this; |
533 | 533 | $o->use_delete = true; |
534 | 534 | return $o; |
@@ -132,7 +132,9 @@ discard block |
||
132 | 132 | |
133 | 133 | $data = $this->unbuildEntity($Entity); |
134 | 134 | |
135 | - if(method_exists($this, 'onPrepareData' )) $this->onPrepareData( $Entity , $data ); |
|
135 | + if(method_exists($this, 'onPrepareData' )) { |
|
136 | + $this->onPrepareData( $Entity , $data ); |
|
137 | + } |
|
136 | 138 | |
137 | 139 | $id = $data[$this->getPrimaryKey()]; |
138 | 140 | unset($data[$this->getPrimaryKey()]); |
@@ -168,13 +170,17 @@ discard block |
||
168 | 170 | */ |
169 | 171 | public function save(EntityInterface $Entity) |
170 | 172 | { |
171 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity ); |
|
173 | + if(method_exists($this, 'onAfterSave' )) { |
|
174 | + $this->onAfterSave( $Entity ); |
|
175 | + } |
|
172 | 176 | |
173 | 177 | if(!$this->saveWithoutEvents($Entity)){ |
174 | 178 | return false; |
175 | 179 | } |
176 | 180 | |
177 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
181 | + if(method_exists($this, 'onBeforeSave' )) { |
|
182 | + $this->onBeforeSave( $Entity ); |
|
183 | + } |
|
178 | 184 | |
179 | 185 | return true; |
180 | 186 | } |
@@ -208,8 +214,7 @@ discard block |
||
208 | 214 | if(count($rel['relations'])>0){ |
209 | 215 | $this->createListRelationReq($rel['relations'],$rel_list,$obj_parent_link.'->get'.$rel['alias'].'()'); |
210 | 216 | $rel_list [$obj_parent_link.$obj_link]= $rel['name']; |
211 | - } |
|
212 | - else{ |
|
217 | + } else{ |
|
213 | 218 | $rel_list [$obj_parent_link.$obj_link] = $rel['name']; |
214 | 219 | } |
215 | 220 | } |
@@ -273,19 +278,18 @@ discard block |
||
273 | 278 | |
274 | 279 | if($this->use_joins===true || empty($row[$field])){ |
275 | 280 | $value = $mapper->createEntity($row); |
276 | - } |
|
277 | - else{ |
|
281 | + } else{ |
|
278 | 282 | $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
279 | 283 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
280 | 284 | } |
281 | 285 | |
282 | - } |
|
283 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
286 | + } elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
284 | 287 | $value = $row[strtolower($field)]; |
285 | 288 | } |
286 | 289 | |
287 | - if($value!==false) |
|
288 | - $Entity->{$method_set}($value); |
|
290 | + if($value!==false) { |
|
291 | + $Entity->{$method_set}($value); |
|
292 | + } |
|
289 | 293 | |
290 | 294 | } |
291 | 295 | |
@@ -316,18 +320,17 @@ discard block |
||
316 | 320 | //-------------------------------------------------------------------- |
317 | 321 | if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
318 | 322 | $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
319 | - } |
|
320 | - elseif(isset($cfg['relation'])){ |
|
323 | + } elseif(isset($cfg['relation'])){ |
|
321 | 324 | |
322 | - if(isset($cfg['on'])) |
|
323 | - $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
324 | - else |
|
325 | - $fkey = 'id'; |
|
325 | + if(isset($cfg['on'])) { |
|
326 | + $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
327 | + } else { |
|
328 | + $fkey = 'id'; |
|
329 | + } |
|
326 | 330 | |
327 | 331 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
328 | 332 | |
329 | - } |
|
330 | - else{ |
|
333 | + } else{ |
|
331 | 334 | $value = $Entity->{$method_get}(); |
332 | 335 | } |
333 | 336 | |
@@ -345,8 +348,7 @@ discard block |
||
345 | 348 | |
346 | 349 | if(is_string($field)){ |
347 | 350 | $field = ['field' => $field]; |
348 | - } |
|
349 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
351 | + } elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
350 | 352 | $field['field'] = $alias; |
351 | 353 | } |
352 | 354 | |
@@ -428,8 +430,7 @@ discard block |
||
428 | 430 | $delete_key > '' && |
429 | 431 | $Entity->getId() > 0){ |
430 | 432 | $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
431 | - } |
|
432 | - elseif($Entity->getId() > 0){ |
|
433 | + } elseif($Entity->getId() > 0){ |
|
433 | 434 | |
434 | 435 | if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
435 | 436 | if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
@@ -476,8 +477,9 @@ discard block |
||
476 | 477 | $this->use_delete === false && |
477 | 478 | $this->setSoftDeleteKey()>'' |
478 | 479 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
479 | - ) |
|
480 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
480 | + ) { |
|
481 | + $specification->setWhere($this->setSoftDeleteKey(),0); |
|
482 | + } |
|
481 | 483 | } |
482 | 484 | |
483 | 485 | /** |