31 $this->entityEventType =
$type;
35 $eventName = $entity->
getName().$type;
40 $this->entity = $entity;
65 if($evenResult->getType() === EventResult::ERROR)
68 $result->
addErrors($evenResult->getErrors());
81 public function mergeFields(array $data)
88 $removed = $evenResult->getUnset();
89 foreach($removed as $val)
94 $modified = $evenResult->getModified();
97 $data = array_merge($data, $modified);
104 public function mergeObjectFields(EntityObject $object)
111 $removed = $evenResult->getUnset();
112 foreach($removed as $fieldName)
115 if ($object->entity->hasField($fieldName))
117 $object->unset($fieldName);
121 $modified = $evenResult->getModified();
122 if(!empty($modified))
124 foreach ($modified as $fieldName => $value)
126 $object->set($fieldName, $value);
135 static $events = array(
136 DataManager::EVENT_ON_BEFORE_ADD =>
true,
137 DataManager::EVENT_ON_ADD =>
true,
138 DataManager::EVENT_ON_AFTER_ADD =>
true,
139 DataManager::EVENT_ON_BEFORE_UPDATE =>
true,
140 DataManager::EVENT_ON_UPDATE =>
true,
141 DataManager::EVENT_ON_AFTER_UPDATE =>
true,
142 DataManager::EVENT_ON_BEFORE_DELETE =>
true,
143 DataManager::EVENT_ON_DELETE =>
true,
144 DataManager::EVENT_ON_AFTER_DELETE =>
true,
147 if(isset($events[$this->entityEventType]))
151 $result = call_user_func_array(array($this->entity->getDataClass(), $this->entityEventType), array($this));
152 if (($result !==
null) && !($result instanceof
EventResult))
addResult(EventResult $result)
__construct(Entity $entity, $type, array $parameters=array(), $withNamespace=false)