/** * 直接添加一个关联对象 * * @param QDB_ActiveRecord_Abstract $source * @param QDB_ActiveRecord_Abstract $target * * @return QDB_ActiveRecord_Association_Abstract */ function addRelatedObject(QDB_ActiveRecord_Abstract $source, QDB_ActiveRecord_Abstract $target) { $this->init(); $target->changePropForce($this->target_key, $source->{$this->source_key}); $target->save(0, $this->on_save); return $this; }
/** * 在数据库中创建 ActiveRecord 对象前调用 * * @param QDB_ActiveRecord_Abstract $obj */ function _before_create(QDB_ActiveRecord_Abstract $obj) { if ($this->_settings['gen2char']) { $new_id = ariUUID(); $idname = reset($this->_meta->idname); $obj->changePropForce($idname, $new_id); } else { $new_id = self::genUUID($this->_settings['genorder'], $this->_settings['being_timestamp'], $this->_settings['suffix_len']); $idname = reset($this->_meta->idname); $obj->changePropForce($idname, $new_id); } }
/** * 在保存新建用户对象失败抛出异常时,还原用户的密码属性 * * @param QDB_ActiveRecord_Abstract $member 保存出错的用户对象 * @param Exception $ex 异常 */ function _save_exception_handler(QDB_ActiveRecord_Abstract $member, Exception $ex) { if (isset($this->_saved_state['password'])) { $member->changePropForce($this->_settings['password_prop'], $this->_saved_state['password']); unset($this->_saved_state['password']); } }
/** * 更新用户登录信息 * * @param QDB_ActiveRecord_Abstract $obj */ function updateLogin(QDB_ActiveRecord_Abstract $obj) { $changed = false; $pn = $this->_settings['login_count_prop']; if ($pn) { $obj->changePropForce($pn, $obj->{$pn} + 1); $changed = true; } $pn = $this->_settings['login_at_prop']; if ($pn) { if ($this->_meta->props[$pn]['ptype'] == 'i') { $obj->changePropForce($pn, time()); } else { $obj->changePropForce($pn, $this->_meta->table->getConn()->dbTimestamp(time())); } $changed = true; } $pn = $this->_settings['login_ip_prop']; if ($pn) { if ($this->_meta->props[$pn]['ptype'] == 'i') { $obj->changePropForce($pn, !empty($_SERVER['REMOTE_ADDR']) ? ip2long($_SERVER['REMOTE_ADDR']) : 0); } else { $obj->changePropForce($pn, !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''); } $changed = true; } if ($changed) { $obj->save(0, 'update'); } }