1 | <?php |
||
15 | trait TraitDataMapperEvent { |
||
16 | |||
17 | /** |
||
18 | * Перед сохранением извелкаем объект и дополняем массив для записи, недостающими полями |
||
19 | * @param \Autoprice\Domain\Price\EntityInterface $Entity |
||
20 | * @param type $data |
||
21 | */ |
||
22 | protected function onPrepareData(\SimpleORM\EntityInterface $Entity, &$data) { |
||
29 | |||
30 | /** |
||
31 | * На успешное удаление |
||
32 | * @param \SimpleORM\EntityInterface $Entity |
||
33 | */ |
||
34 | protected function onBeforeDelete(EntityInterface $Entity) { |
||
48 | |||
49 | /** |
||
50 | * Событие перед сохранением |
||
51 | * @param \SimpleORM\EntityInterface $Entity |
||
52 | */ |
||
53 | protected function onAfterSave(EntityInterface $Entity) { |
||
54 | |||
55 | $this->getAdapter()->startTransaction(); |
||
56 | |||
57 | $rel_list = $this->createListRelation(); |
||
58 | |||
59 | foreach ($rel_list as $obj_path => $mapper) { |
||
60 | |||
61 | $call_obj = '$Entity'.$obj_path.';'; |
||
62 | |||
63 | $set_path = str_replace(['#', '();'], ['->set', '($o);'], $call_obj); |
||
64 | |||
65 | $ar_path = explode('()',$obj_path); |
||
66 | |||
67 | $o = $Entity; |
||
68 | |||
69 | foreach ($ar_path as $_m){ |
||
70 | |||
71 | $_mc = str_replace('#','get',ucfirst($_m)); |
||
72 | |||
73 | //Set logic |
||
74 | if(empty($_m)){ |
||
75 | |||
76 | $_mc = ltrim( $ar_path[(count($ar_path)-2)] , '#'); |
||
77 | |||
78 | if (isset($$_mc) && is_object($$_mc) && is_a($$_mc,'SimpleORM\EntityInterface') && $this->DI->get($mapper)->saveWithoutEvents($o)) { |
||
79 | $o = $$_mc; |
||
80 | eval($set_path); |
||
81 | } |
||
82 | } |
||
83 | elseif(is_object($o) ){ |
||
84 | $$_mc = $o->{$_mc}(); |
||
85 | $o = $$_mc; |
||
86 | } |
||
87 | |||
88 | } |
||
89 | |||
90 | } |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * После успешного сохранения |
||
95 | * @param \SimpleORM\EntityInterface $Entity |
||
96 | */ |
||
97 | protected function onBeforeSave(EntityInterface $Entity) { |
||
114 | |||
115 | } |
||
116 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.