@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * таблица для сущности |
20 | 20 | * @var type |
21 | 21 | */ |
22 | - protected $entityTable; |
|
22 | + protected $entityTable; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * первичный ключ |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | |
89 | 89 | abstract protected function setMappingFields(); |
90 | 90 | |
91 | - public function getAdapter() { |
|
92 | - return $this->adapter; |
|
93 | - } |
|
91 | + public function getAdapter() { |
|
92 | + return $this->adapter; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | public function setAdapter(QueryBuilderInterface $adapter){ |
96 | 96 | $this->adapter = $adapter; |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | |
112 | - public function findById($id) |
|
113 | - { |
|
112 | + public function findById($id) |
|
113 | + { |
|
114 | 114 | $Criteria = (new Specification())->setWhere($this->key , $id); |
115 | 115 | |
116 | - return $this->findBySpecification($Criteria); |
|
117 | - } |
|
116 | + return $this->findBySpecification($Criteria); |
|
117 | + } |
|
118 | 118 | |
119 | 119 | /** |
120 | 120 | * Cохранение сущности |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | protected function buildEntity(EntityInterface $Entity, array $row){ |
212 | 212 | |
213 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
213 | + foreach ($this->mapping_fields as $alias => $cfg ) { |
|
214 | 214 | |
215 | 215 | $value = false; |
216 | 216 | |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | if($value!==false) |
248 | 248 | $Entity->{$method_set}($value); |
249 | 249 | |
250 | - } |
|
250 | + } |
|
251 | 251 | |
252 | - return $Entity; |
|
252 | + return $Entity; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | |
264 | 264 | $row = []; |
265 | 265 | |
266 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
266 | + foreach ($this->mapping_fields as $alias => $cfg ) { |
|
267 | 267 | |
268 | 268 | $field = $cfg['field']; |
269 | 269 | |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | |
294 | 294 | $row[$field] = $value; |
295 | 295 | |
296 | - } |
|
296 | + } |
|
297 | 297 | |
298 | - return $row; |
|
298 | + return $row; |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -367,10 +367,10 @@ discard block |
||
367 | 367 | //получение записей |
368 | 368 | $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
369 | 369 | |
370 | - if (!$row = $res->row_array()) { |
|
371 | - return null; |
|
372 | - } |
|
373 | - return $this->createEntity($row); |
|
370 | + if (!$row = $res->row_array()) { |
|
371 | + return null; |
|
372 | + } |
|
373 | + return $this->createEntity($row); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
413 | 413 | |
414 | 414 | if (!$rows = $res->result_array()) { |
415 | - return null; |
|
416 | - } |
|
415 | + return null; |
|
416 | + } |
|
417 | 417 | |
418 | 418 | foreach($rows as $k => $row){ |
419 | 419 | $rows[$k] = $this->createEntity($row); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | $this->setEntityTable($db_name); |
82 | 82 | |
83 | - if($this->getEntityTable()=='' || $this->getPrimaryKey()==''){ |
|
83 | + if ($this->getEntityTable()=='' || $this->getPrimaryKey()=='') { |
|
84 | 84 | throw new InvalidEntityPropertyException('Свойства entityTable или key не заданы'); |
85 | 85 | } |
86 | 86 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | return $this->adapter; |
93 | 93 | } |
94 | 94 | |
95 | - public function setAdapter(QueryBuilderInterface $adapter){ |
|
95 | + public function setAdapter(QueryBuilderInterface $adapter) { |
|
96 | 96 | $this->adapter = $adapter; |
97 | 97 | } |
98 | 98 | |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | * Уставнока таблицы |
106 | 106 | */ |
107 | 107 | protected function setEntityTable($db_name) { |
108 | - $this->entityTable = !empty($db_name)? "$db_name.".$this->table : $this->table; |
|
108 | + $this->entityTable = !empty($db_name) ? "$db_name.".$this->table : $this->table; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
112 | 112 | public function findById($id) |
113 | 113 | { |
114 | - $Criteria = (new Specification())->setWhere($this->key , $id); |
|
114 | + $Criteria = (new Specification())->setWhere($this->key, $id); |
|
115 | 115 | |
116 | 116 | return $this->findBySpecification($Criteria); |
117 | 117 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $data = $this->unbuildEntity($Entity); |
127 | 127 | |
128 | 128 | //protected function onAfterSave(\SimpleORM\EntityInterface $Entity, &$data) |
129 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity, $data ); |
|
129 | + if (method_exists($this, 'onAfterSave')) $this->onAfterSave($Entity, $data); |
|
130 | 130 | |
131 | 131 | $id = $data[$this->getPrimaryKey()]; |
132 | 132 | unset($data[$this->getPrimaryKey()]); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | unset($data[$this->setSoftDeleteKey()]); |
138 | 138 | |
139 | - $this->getAdapter()->insert($this->getEntityTable(),$data); |
|
139 | + $this->getAdapter()->insert($this->getEntityTable(), $data); |
|
140 | 140 | |
141 | 141 | if (!$id = $this->getAdapter()->insert_id()) { |
142 | 142 | return false; |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | //update |
148 | 148 | else { |
149 | 149 | |
150 | - if(!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")){ |
|
150 | + if (!$this->getAdapter()->update($this->getEntityTable(), $data, "{$this->getPrimaryKey()} = '{$id}'")) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | |
154 | 154 | } |
155 | 155 | |
156 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
156 | + if (method_exists($this, 'onBeforeSave')) $this->onBeforeSave($Entity); |
|
157 | 157 | |
158 | 158 | |
159 | 159 | return true; |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | * На успешное сохранение |
164 | 164 | * @param \SimpleORM\EntityInterface $Entity |
165 | 165 | */ |
166 | - protected function onBeforeSave(EntityInterface $Entity){ |
|
166 | + protected function onBeforeSave(EntityInterface $Entity) { |
|
167 | 167 | |
168 | 168 | foreach ($this->relations as $alias => $mapper) { |
169 | 169 | |
170 | 170 | $SaveEntity = $Entity->{'get'.$alias}(); |
171 | 171 | |
172 | - if(!$mapper->save($SaveEntity)){ |
|
172 | + if (!$mapper->save($SaveEntity)) { |
|
173 | 173 | throw new \Autoprice\Exceptions\EntityNotSaveException('Unable to save Entity!'); |
174 | 174 | } |
175 | 175 | |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | foreach ($this->relations as $alias => $cfg) { |
188 | 188 | $mapper = $cfg['mapper']; |
189 | 189 | //если связь один к одному то удаляем сущность |
190 | - if($cgg['reltype'] == 'has_one'){ |
|
190 | + if ($cgg['reltype']=='has_one') { |
|
191 | 191 | $Entity = $Entity->{'get'.$alias}(); |
192 | - if(!$mapper->delete($Entity)){ |
|
192 | + if (!$mapper->delete($Entity)) { |
|
193 | 193 | throw new \Autoprice\Exceptions\EntityNotDeleteException('Unable to delete Entity!'); |
194 | 194 | } |
195 | 195 | } |
@@ -208,43 +208,43 @@ discard block |
||
208 | 208 | * @return \Core\Infrastructure\EntityInterface |
209 | 209 | * @throws BadMethodCallException |
210 | 210 | */ |
211 | - protected function buildEntity(EntityInterface $Entity, array $row){ |
|
211 | + protected function buildEntity(EntityInterface $Entity, array $row) { |
|
212 | 212 | |
213 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
213 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
214 | 214 | |
215 | 215 | $value = false; |
216 | 216 | |
217 | 217 | $field = $cfg['field']; |
218 | 218 | |
219 | - $method_set = 'set' . ucfirst($alias); |
|
219 | + $method_set = 'set'.ucfirst($alias); |
|
220 | 220 | |
221 | - if(!method_exists($Entity, $method_set )){ |
|
221 | + if (!method_exists($Entity, $method_set)) { |
|
222 | 222 | throw new BadMethodCallException("Метод {$method_set} не определен"); |
223 | 223 | } |
224 | 224 | |
225 | 225 | //событие на формирование поля |
226 | - if( isset($cfg['build']) && is_object($cfg['build']) ){ |
|
226 | + if (isset($cfg['build']) && is_object($cfg['build'])) { |
|
227 | 227 | $value = call_user_func($cfg['build'], $row); |
228 | 228 | } |
229 | 229 | //на связь |
230 | - elseif(isset($cfg['relation'])){ |
|
230 | + elseif (isset($cfg['relation'])) { |
|
231 | 231 | |
232 | 232 | $mapper = $this->DI->get($cfg['relation']); |
233 | 233 | |
234 | - if($this->use_joins===true){ |
|
234 | + if ($this->use_joins===true) { |
|
235 | 235 | $value = $mapper->createEntity($row); |
236 | 236 | } |
237 | - else{ |
|
238 | - $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
|
237 | + else { |
|
238 | + $fkey = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
239 | 239 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
240 | 240 | } |
241 | 241 | |
242 | 242 | } |
243 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
243 | + elseif (is_string($field) && isset($row[strtolower($field)])) { |
|
244 | 244 | $value = $row[strtolower($field)]; |
245 | 245 | } |
246 | 246 | |
247 | - if($value!==false) |
|
247 | + if ($value!==false) |
|
248 | 248 | $Entity->{$method_set}($value); |
249 | 249 | |
250 | 250 | } |
@@ -259,27 +259,27 @@ discard block |
||
259 | 259 | * @return \Core\Infrastructure\EntityInterface |
260 | 260 | * @throws BadMethodCallException |
261 | 261 | */ |
262 | - protected function unbuildEntity(EntityInterface $Entity){ |
|
262 | + protected function unbuildEntity(EntityInterface $Entity) { |
|
263 | 263 | |
264 | 264 | $row = []; |
265 | 265 | |
266 | - foreach ($this->mapping_fields as $alias => $cfg ) { |
|
266 | + foreach ($this->mapping_fields as $alias => $cfg) { |
|
267 | 267 | |
268 | 268 | $field = $cfg['field']; |
269 | 269 | |
270 | - $method_get = 'get' . ucfirst($alias); |
|
270 | + $method_get = 'get'.ucfirst($alias); |
|
271 | 271 | |
272 | - if(!method_exists($Entity, $method_get )){ |
|
272 | + if (!method_exists($Entity, $method_get)) { |
|
273 | 273 | throw new BadMethodCallException("Метод {$method_get} не определен"); |
274 | 274 | } |
275 | 275 | |
276 | 276 | //-------------------------------------------------------------------- |
277 | - if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
|
278 | - $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
|
277 | + if (isset($cfg['unbuild']) && is_object($cfg['unbuild'])) { |
|
278 | + $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}()); |
|
279 | 279 | } |
280 | - elseif(isset($cfg['relation'])){ |
|
280 | + elseif (isset($cfg['relation'])) { |
|
281 | 281 | |
282 | - if(isset($cfg['on'])) |
|
282 | + if (isset($cfg['on'])) |
|
283 | 283 | $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
284 | 284 | else |
285 | 285 | $fkey = 'id'; |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
288 | 288 | |
289 | 289 | } |
290 | - else{ |
|
290 | + else { |
|
291 | 291 | $value = $Entity->{$method_get}(); |
292 | 292 | } |
293 | 293 | |
@@ -301,22 +301,22 @@ discard block |
||
301 | 301 | /** |
302 | 302 | * Установка поля для маппинга |
303 | 303 | */ |
304 | - protected function addMappingField($alias,$field = null){ |
|
304 | + protected function addMappingField($alias, $field = null) { |
|
305 | 305 | |
306 | - if(is_string($field)){ |
|
306 | + if (is_string($field)) { |
|
307 | 307 | $field = ['field' => $field]; |
308 | 308 | } |
309 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
310 | - $field['field'] = $alias; |
|
309 | + elseif ((is_array($field) && !isset($field['field'])) || empty($field)) { |
|
310 | + $field['field'] = $alias; |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | $this->mapping_fields[$alias] = $field; |
314 | 314 | |
315 | - if(isset($field['primary']) && $field['primary']===true){ |
|
315 | + if (isset($field['primary']) && $field['primary']===true) { |
|
316 | 316 | $this->key = $field['field']; |
317 | 317 | } |
318 | 318 | |
319 | - if(isset($field['softdelete']) && $field['softdelete']===true){ |
|
319 | + if (isset($field['softdelete']) && $field['softdelete']===true) { |
|
320 | 320 | $this->soft_delete_key = $field['field']; |
321 | 321 | } |
322 | 322 | |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | |
344 | 344 | |
345 | 345 | |
346 | - public function getFieldAlias($field){ |
|
346 | + public function getFieldAlias($field) { |
|
347 | 347 | |
348 | 348 | return $this->mapping_fields_aliases[$field]; |
349 | 349 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @param ISpecificationCriteria $specification |
356 | 356 | * @return type |
357 | 357 | */ |
358 | - public function findBySpecification(ISpecificationCriteria $specification){ |
|
358 | + public function findBySpecification(ISpecificationCriteria $specification) { |
|
359 | 359 | |
360 | 360 | //псеводо удаление |
361 | 361 | $this->setSoftDelete($specification); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | $specification->setLimit(1); |
366 | 366 | |
367 | 367 | //получение записей |
368 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
368 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
369 | 369 | |
370 | 370 | if (!$row = $res->row_array()) { |
371 | 371 | return null; |
@@ -386,13 +386,13 @@ discard block |
||
386 | 386 | |
387 | 387 | if ( |
388 | 388 | $delete_key > '' && |
389 | - $Entity->getId() > 0){ |
|
390 | - $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
389 | + $Entity->getId() > 0) { |
|
390 | + $result = $this->getAdapter()->update($this->getEntityTable(), [$delete_key => 1], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
|
391 | 391 | } |
392 | - elseif($Entity->getId() > 0){ |
|
392 | + elseif ($Entity->getId() > 0) { |
|
393 | 393 | |
394 | - if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
|
395 | - if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
|
394 | + if ($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())) { |
|
395 | + if (method_exists($this, 'onBeforeDelete')) { $result = $this->onBeforeDelete($Entity); } |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | |
@@ -409,13 +409,13 @@ discard block |
||
409 | 409 | |
410 | 410 | $this->setRelations($specification); |
411 | 411 | |
412 | - $res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification); |
|
412 | + $res = $this->getAdapter()->getResultQuery($this->getEntityTable(), $specification); |
|
413 | 413 | |
414 | 414 | if (!$rows = $res->result_array()) { |
415 | 415 | return null; |
416 | 416 | } |
417 | 417 | |
418 | - foreach($rows as $k => $row){ |
|
418 | + foreach ($rows as $k => $row) { |
|
419 | 419 | $rows[$k] = $this->createEntity($row); |
420 | 420 | } |
421 | 421 | |
@@ -431,13 +431,13 @@ discard block |
||
431 | 431 | * Выборка удаленных моделей |
432 | 432 | * @param ISpecificationCriteria $specification |
433 | 433 | */ |
434 | - private function setSoftDelete(ISpecificationCriteria $specification){ |
|
435 | - if( |
|
436 | - $this->use_delete === false && |
|
437 | - $this->setSoftDeleteKey()>'' |
|
434 | + private function setSoftDelete(ISpecificationCriteria $specification) { |
|
435 | + if ( |
|
436 | + $this->use_delete===false && |
|
437 | + $this->setSoftDeleteKey() > '' |
|
438 | 438 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
439 | 439 | ) |
440 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
440 | + $specification->setWhere($this->setSoftDeleteKey(), 0); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -448,12 +448,12 @@ discard block |
||
448 | 448 | * belongs_to - многие к многим (пользователь имет множество оплат одного заказа) |
449 | 449 | * has_one - один к одному |
450 | 450 | */ |
451 | - protected function setRelations(ISpecificationCriteria $Specification){ |
|
451 | + protected function setRelations(ISpecificationCriteria $Specification) { |
|
452 | 452 | |
453 | 453 | $joins = []; |
454 | 454 | |
455 | - foreach ($this->mapping_fields as $field => $cfg){ |
|
456 | - if(isset($cfg['relation'])){ |
|
455 | + foreach ($this->mapping_fields as $field => $cfg) { |
|
456 | + if (isset($cfg['relation'])) { |
|
457 | 457 | |
458 | 458 | $this->relations[$field] = [ |
459 | 459 | 'mapper' => $mapper = $this->DI->get($cfg['relation']), |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | |
463 | 463 | $table = $mapper->getEntityTable(); |
464 | 464 | |
465 | - $relation_key = isset($cfg['on'])? $cfg['on'] : $mapper->key; |
|
465 | + $relation_key = isset($cfg['on']) ? $cfg['on'] : $mapper->key; |
|
466 | 466 | |
467 | 467 | $joins[$table] = [ |
468 | 468 | 'alias' => $field, |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | } |
474 | 474 | } |
475 | 475 | |
476 | - if($this->use_joins===true){ |
|
476 | + if ($this->use_joins===true) { |
|
477 | 477 | $Specification->setJoins($joins); |
478 | 478 | } |
479 | 479 | } |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | return $o; |
489 | 489 | } |
490 | 490 | |
491 | - public function withDelete(){ |
|
491 | + public function withDelete() { |
|
492 | 492 | $o = clone $this; |
493 | 493 | $o->use_delete = true; |
494 | 494 | return $o; |
@@ -126,7 +126,9 @@ discard block |
||
126 | 126 | $data = $this->unbuildEntity($Entity); |
127 | 127 | |
128 | 128 | //protected function onAfterSave(\SimpleORM\EntityInterface $Entity, &$data) |
129 | - if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity, $data ); |
|
129 | + if(method_exists($this, 'onAfterSave' )) { |
|
130 | + $this->onAfterSave( $Entity, $data ); |
|
131 | + } |
|
130 | 132 | |
131 | 133 | $id = $data[$this->getPrimaryKey()]; |
132 | 134 | unset($data[$this->getPrimaryKey()]); |
@@ -153,7 +155,9 @@ discard block |
||
153 | 155 | |
154 | 156 | } |
155 | 157 | |
156 | - if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity ); |
|
158 | + if(method_exists($this, 'onBeforeSave' )) { |
|
159 | + $this->onBeforeSave( $Entity ); |
|
160 | + } |
|
157 | 161 | |
158 | 162 | |
159 | 163 | return true; |
@@ -233,19 +237,18 @@ discard block |
||
233 | 237 | |
234 | 238 | if($this->use_joins===true){ |
235 | 239 | $value = $mapper->createEntity($row); |
236 | - } |
|
237 | - else{ |
|
240 | + } else{ |
|
238 | 241 | $fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key; |
239 | 242 | $value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field])); |
240 | 243 | } |
241 | 244 | |
242 | - } |
|
243 | - elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
245 | + } elseif(is_string($field) && isset($row[strtolower($field)])){ |
|
244 | 246 | $value = $row[strtolower($field)]; |
245 | 247 | } |
246 | 248 | |
247 | - if($value!==false) |
|
248 | - $Entity->{$method_set}($value); |
|
249 | + if($value!==false) { |
|
250 | + $Entity->{$method_set}($value); |
|
251 | + } |
|
249 | 252 | |
250 | 253 | } |
251 | 254 | |
@@ -276,18 +279,17 @@ discard block |
||
276 | 279 | //-------------------------------------------------------------------- |
277 | 280 | if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){ |
278 | 281 | $value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() ); |
279 | - } |
|
280 | - elseif(isset($cfg['relation'])){ |
|
282 | + } elseif(isset($cfg['relation'])){ |
|
281 | 283 | |
282 | - if(isset($cfg['on'])) |
|
283 | - $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
284 | - else |
|
285 | - $fkey = 'id'; |
|
284 | + if(isset($cfg['on'])) { |
|
285 | + $fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']); |
|
286 | + } else { |
|
287 | + $fkey = 'id'; |
|
288 | + } |
|
286 | 289 | |
287 | 290 | $value = $Entity->{$method_get}()->{'get'.$fkey}(); |
288 | 291 | |
289 | - } |
|
290 | - else{ |
|
292 | + } else{ |
|
291 | 293 | $value = $Entity->{$method_get}(); |
292 | 294 | } |
293 | 295 | |
@@ -305,8 +307,7 @@ discard block |
||
305 | 307 | |
306 | 308 | if(is_string($field)){ |
307 | 309 | $field = ['field' => $field]; |
308 | - } |
|
309 | - elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
310 | + } elseif( (is_array($field) && !isset($field['field'])) || empty($field)){ |
|
310 | 311 | $field['field'] = $alias; |
311 | 312 | } |
312 | 313 | |
@@ -388,8 +389,7 @@ discard block |
||
388 | 389 | $delete_key > '' && |
389 | 390 | $Entity->getId() > 0){ |
390 | 391 | $result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); |
391 | - } |
|
392 | - elseif($Entity->getId() > 0){ |
|
392 | + } elseif($Entity->getId() > 0){ |
|
393 | 393 | |
394 | 394 | if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()." = ".$Entity->getId())){ |
395 | 395 | if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );} |
@@ -436,8 +436,9 @@ discard block |
||
436 | 436 | $this->use_delete === false && |
437 | 437 | $this->setSoftDeleteKey()>'' |
438 | 438 | && !isset($specification->getWhere()[$this->setSoftDeleteKey()]) |
439 | - ) |
|
440 | - $specification->setWhere($this->setSoftDeleteKey(),0); |
|
439 | + ) { |
|
440 | + $specification->setWhere($this->setSoftDeleteKey(),0); |
|
441 | + } |
|
441 | 442 | } |
442 | 443 | |
443 | 444 | /** |