Пример #1
0
 /**
  * 更新访问脚印
  * 
  * @param int $spaceUid
  * @param int $visitUid
  */
 public function signVisitor($spaceUid, $visitUid = 0)
 {
     if ($spaceUid < 1) {
         return false;
     }
     if ($spaceUid == $visitUid) {
         return false;
     }
     if ($visitUid < 1) {
         return $this->_getSpaceDs()->updateNumber($spaceUid);
     }
     $time = Pw::getTime();
     $space = $this->_getSpaceDs()->getSpace($spaceUid);
     $visitors = unserialize($space['visitors']);
     $visitors = is_array($visitors) ? $visitors : array();
     if (array_key_exists($visitUid, $visitors)) {
         $keys = array_keys($visitors);
         if (array_shift($keys) == $visitUid) {
             return false;
         }
         //如果是第一个不需要更新
         unset($visitors[$visitUid]);
     }
     $visitors = array($visitUid => $time) + $visitors;
     if (count($visitors) > 20) {
         $visitors = array_slice($visitors, 0, 20, true);
     }
     $space['visit_count']++;
     Wekit::load('space.dm.PwSpaceDm');
     $dm = new PwSpaceDm($spaceUid);
     $dm->setVisitors($visitors)->setVisitCount($space['visit_count']);
     return $this->_getSpaceDs()->updateInfo($dm);
 }