diff --git a/Collection.php b/Collection.php index 4150c24..811c63d 100644 --- a/Collection.php +++ b/Collection.php @@ -380,7 +380,7 @@ public function validate ($attributes = null) { public function beforeValidate () { $event = new ModelEvent(); - $this->trigger(self::EVENT_BEFORE_VALIDATE, $event); + $this->triggerAll(self::EVENT_BEFORE_VALIDATE, $event); return $event->isValid; } @@ -388,7 +388,7 @@ public function beforeValidate () { public function afterValidate () { $event = new ModelEvent(); - $this->trigger(self::EVENT_AFTER_VALIDATE, $event); + $this->triggerAll(self::EVENT_AFTER_VALIDATE, $event); return $event->isValid; } @@ -398,13 +398,13 @@ public function beforeSave ($insert = false) { if ($this->isEmpty()) { $event->isValid = false; } - $this->trigger($insert ? self::EVENT_BEFORE_INSERT : self::EVENT_BEFORE_UPDATE, $event); + $this->triggerAll($insert ? self::EVENT_BEFORE_INSERT : self::EVENT_BEFORE_UPDATE, $event); return $event->isValid; } public function afterSave () { - $this->trigger(self::EVENT_AFTER_SAVE); + $this->triggerAll(self::EVENT_AFTER_SAVE); } @@ -426,7 +426,7 @@ public function afterLoad () { * @param ModelEvent $event * @return bool whether is valid */ - public function triggerAll ($name, ModelEvent $event = null) { + public function triggerModels ($name, ModelEvent $event = null) { if ($event == null) { $event = new ModelEvent(); } @@ -438,6 +438,23 @@ public function triggerAll ($name, ModelEvent $event = null) { return $event->isValid; } + /** + * Calls [[triggerModels()]], then calls [[trigger()]] + * + * @param string $name the event name + * @param ModelEvent $event + * @return bool whether is valid + */ + public function triggerAll($name, ModelEvent $event = null) { + if ($event == null) { + $event = new ModelEvent(); + } + if ($this->triggerModels($name, $event)) { + $this->trigger($name, $event); + } + return $event->isValid; + } + public function isConsistent () { $new = $this->first->getIsNewRecord(); $className = $this->first->className();