public function save()
{
$gateway = $this->getRecordGateway();
$param = new TActiveRecordChangeEventParameter();
if ($this->_recordState === self::STATE_NEW) {
$this->onInsert($param);
if ($param->getIsValid() && $gateway->insert($this)) {
$this->_recordState = self::STATE_LOADED;
return true;
}
} else {
if ($this->_recordState === self::STATE_LOADED) {
$this->onUpdate($param);
if ($param->getIsValid() && $gateway->update($this)) {
return true;
}
} else {
throw new TActiveRecordException('ar_save_invalid', get_class($this));
}
}
return false;
}