Esempio n. 1
0
 /**
  * 获取未过期的 session 总数
  *
  * @return int
  */
 function getOnlineCount($lifetime = -1)
 {
     if ($this->lifeTime > 0) {
         $lifetime = $this->lifeTime;
     } else {
         if ($lifetime <= 0) {
             $lifetime = (int) ini_get('session.gc_maxlifetime');
             if ($lifetime <= 0) {
                 $lifetime = 1440;
             }
         }
     }
     $sql = "SELECT COUNT(*) FROM {$this->tableName}";
     if ($this->lifeTime > 0) {
         $time = time() - $lifetime;
         $sql .= " WHERE {$this->fieldActivity} >= {$time}";
     }
     return (int) $this->dbo->getOne($sql);
 }
Esempio n. 2
0
 /**
  * 根据关联表的 counterCache 选项更新统计信息
  *
  * @param array $row
  */
 function _updateCounterCache(&$row)
 {
     foreach (array_keys($this->links) as $linkKey) {
         $link =& $this->links[$linkKey];
         /* @var $link FLEA_Db_TableLink */
         if ($link->type != BELONGS_TO || !$link->enabled || !$link->counterCache) {
             continue;
         }
         $link->init();
         $f = $link->assocTDG->qfield($link->counterCache);
         if (isset($row[$link->foreignKey])) {
             $fkv = $this->dbo->qstr($row[$link->foreignKey]);
         } else {
             $pkv = $this->dbo->qstr($row[$this->primaryKey]);
             $sql = "SELECT {$link->foreignKey} FROM {$this->qtableName} WHERE {$this->qpk} = {$pkv}";
             $fkv = $this->dbo->getOne($sql);
         }
         $conditions = "{$link->qforeignKey} = {$fkv}";
         if ($link->conditions) {
             if (is_array($link->conditions)) {
                 $conditions = FLEA_Db_SqlHelper::parseConditions($link->conditions, $link->assocTDG);
                 if (is_array($conditions)) {
                     $conditions = $conditions[0];
                 }
             } else {
                 $conditions =& $link->conditions;
             }
             if ($conditions) {
                 $conditions = "{$link->qforeignKey} = {$fkv} AND {$conditions}";
             }
         }
         $sql = "UPDATE {$link->assocTDG->qtableName} SET {$f} = (SELECT COUNT(*) FROM {$this->qtableName} WHERE {$conditions}) WHERE {$link->assocTDG->qpk} = {$fkv}";
         $this->dbo->execute($sql);
     }
 }