Esempio n. 1
0
 /**
  * 直接添加一个关联对象
  *
  * @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;
 }
 /**
  * 添加和一个对象的关联关系
  *
  * @param QDB_ActiveRecord_Abstract $source
  * @param QDB_ActiveRecord_Abstract $target
  *
  * @return QDB_ActiveRecord_Association_ManyToMany
  */
 function bindRelatedObject(QDB_ActiveRecord_Abstract $source, QDB_ActiveRecord_Abstract $target)
 {
     $this->init();
     if ($this->mid_meta) {
     } else {
         $conn = $this->mid_table->getConn();
         $target->save($this->on_save);
         $source_key_value = $source->{$this->source_key};
         $target_key_value = $target->{$this->target_key};
         $sql = sprintf('SELECT COUNT(*) FROM %s WHERE %s = %s AND %s = %s', $conn->qid($this->mid_table->getFullTableName()), $conn->qid($this->mid_source_key), $conn->qstr($source_key_value), $conn->qid($this->mid_target_key), $conn->qstr($target_key_value));
         if (intval($conn->getOne($sql)) < 1) {
             $this->mid_table->insert(array($this->mid_source_key => $source_key_value, $this->mid_target_key => $target_key_value));
         }
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * 更新用户的登录信息
  *
  * 要更新的属性由 update_login_count_prop、update_login_at_prop 和 update_login_ip_prop
  * 设置指定。
  *
  * 用法:
  * @code php
  * $member->updateLogin();
  * @endcode
  *
  * updateLogin() 会尝试自行获取登录时间和 IP 信息。如果有必要也可自行指定:
  * @code php
  * $member->updateLogin(array(
  *     'login_at' => $time,
  *     'login_ip' => $ip,
  * ));
  * @endcode
  *
  * @param QDB_ActiveRecord_Abstract $member 要更新登录信息的用户对象
  * @param array $data 自行指定的属性值
  */
 function updateLoginDyn(QDB_ActiveRecord_Abstract $member, array $data = null)
 {
     $pn = $this->_settings['update_login_count_prop'];
     if ($pn) {
         $member->changePropForce($pn, $member[$pn] + 1);
     }
     $pn = $this->_settings['update_login_at_prop'];
     if ($pn) {
         $time = isset($data['login_at']) ? $data['login_at'] : CURRENT_TIMESTAMP;
         if (substr($this->_meta->props[$pn]['ptype'], 0, 3) != 'int') {
             $time = date('Y-m-d H:i:s', $time);
         }
         $member->changePropForce($pn, $time);
     }
     $pn = $this->_settings['update_login_ip_prop'];
     if ($pn) {
         $ip = isset($data['login_at']) ? $data['login_at'] : isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
         if (substr($this->_meta->props[$pn]['ptype'], 0, 3) == 'int') {
             $ip = ip2long($ip);
         }
         $member->changePropForce($pn, $ip);
     }
     $member->save();
 }
Esempio n. 4
0
 /**
  * 更新用户登录信息
  *
  * @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');
     }
 }