Example #1
0
 /**
  * @param CM_Model_User $user
  * @param int           $actionType OPTIONAL
  * @param int           $actionVerb OPTIONAL
  * @param int           $limitType  OPTIONAL
  * @param int           $period     OPTIONAL
  */
 public function __construct(CM_Model_User $user, $actionType = null, $actionVerb = null, $limitType = null, $period = null)
 {
     $this->_user = $user;
     $where = '`actorId` = ' . $user->getId();
     if ($actionType) {
         $actionType = (int) $actionType;
         $where .= ' AND `type` = ' . $actionType;
     }
     if ($actionVerb) {
         $actionVerb = (int) $actionVerb;
         $where .= ' AND `verb` = ' . $actionVerb;
     }
     if ($limitType) {
         $limitType = (int) $limitType;
         $where .= ' AND `actionLimitType` = ' . $limitType;
     } else {
         $where .= ' AND `actionLimitType` IS NOT NULL';
     }
     if ($period) {
         $period = (int) $period;
         $time = time() - $period;
         $where .= ' AND `createStamp` > ' . $time;
     }
     $source = new CM_PagingSource_Sql_Deferred('type, verb, createStamp', 'cm_action', $where, '`createStamp` DESC');
     parent::__construct($source);
 }
Example #2
0
 /**
  * @param int|CM_Model_User $user
  * @return bool
  */
 public function contains($user)
 {
     if ($user instanceof CM_Model_User) {
         $userId = $user->getId();
     } else {
         $userId = (int) $user;
     }
     return in_array($userId, $this->getItemsRaw());
 }
Example #3
0
 /**
  * @param CM_Model_User $user
  * @throws CM_Exception_Invalid
  * @return boolean
  */
 public function getEnabled(CM_Model_User $user)
 {
     $cacheKey = CM_CacheConst::SplitFeature_Fixtures . '_userId:' . $user->getId();
     $cacheWrite = false;
     $cache = CM_Cache_Local::getInstance();
     if (($fixtures = $cache->get($cacheKey)) === false) {
         $fixtures = CM_Db_Db::select('cm_splitfeature_fixture', array('splitfeatureId', 'fixtureId'), array('userId' => $user->getId()))->fetchAllTree();
         $cacheWrite = true;
     }
     if (!array_key_exists($this->getId(), $fixtures)) {
         $fixtureId = CM_Db_Db::replace('cm_splitfeature_fixture', array('splitfeatureId' => $this->getId(), 'userId' => $user->getId()));
         $fixtures[$this->getId()] = $fixtureId;
         $cacheWrite = true;
     }
     if ($cacheWrite) {
         $cache->set($cacheKey, $fixtures);
     }
     return $this->_calculateEnabled($fixtures[$this->getId()]);
 }
Example #4
0
 /**
  * @param string $useragent
  */
 public function add($useragent)
 {
     $useragent = (string) $useragent;
     CM_Db_Db::replaceDelayed('cm_useragent', array('userId' => $this->_user->getId(), 'useragent' => $useragent, 'createStamp' => time()));
 }
Example #5
0
 /**
  * @param CM_Model_User $user
  */
 public function setUser(CM_Model_User $user)
 {
     $user->setOnline(true);
     $this->set('userId', $user->getId());
     $this->regenerateId();
     if ($request = $this->getRequest()) {
         CM_Splittest_Fixture::setUserForRequestClient($request, $user);
         $user->getUseragents()->addFromRequest($request);
     }
 }
Example #6
0
 public function add(CM_Action_Abstract $action)
 {
     CM_Db_Db::insertDelayed('cm_action', array('actorId' => $this->_user->getId(), 'verb' => $action->getVerb(), 'type' => $action->getType(), 'createStamp' => time()));
 }
Example #7
0
 /**
  * @param CM_Model_User $user
  * @return CM_Queue
  */
 protected function _getTrackingQueue(CM_Model_User $user)
 {
     return new CM_Queue(__METHOD__ . ':' . $user->getId());
 }
Example #8
0
 /**
  * @param CM_Model_User $user
  * @return string
  */
 public static function getKeyByUser(CM_Model_User $user)
 {
     return self::_encryptKey($user->getId(), self::SALT);
 }
Example #9
0
 /**
  * @param CM_Model_User $user
  * @return CM_Queue
  */
 protected function _getTrackingQueue(CM_Model_User $user)
 {
     return new CM_Queue(get_called_class() . '::_getTrackingQueue:' . $user->getId());
 }
Example #10
0
 public function canSubscribe(CM_Model_User $user, $allowedUntil)
 {
     return $user->getId() != 1 ? $allowedUntil + 100 : $allowedUntil;
 }
Example #11
0
 /**
  * @param CM_Model_User                 $user
  * @param CM_Model_Stream_Abstract|null $excludedStream
  * @return bool
  */
 public function isPublisher(CM_Model_User $user, CM_Model_Stream_Abstract $excludedStream = null)
 {
     /** @var $stream CM_Model_Stream_Publish */
     foreach ($this->getStreamPublishs() as $stream) {
         if (!$stream->equals($excludedStream) && $stream->getUserId() == $user->getId()) {
             return true;
         }
     }
     return false;
 }
Example #12
0
 /**
  * @param CM_Http_Request_Abstract $request
  * @param CM_Model_User       $user
  */
 public static function setUserForRequestClient(CM_Http_Request_Abstract $request, CM_Model_User $user)
 {
     $requestClientId = $request->getClientId();
     $userId = $user->getId();
     CM_Db_Db::updateIgnore('cm_splittestVariation_fixture', array('userId' => $userId), array('requestClientId' => $requestClientId));
 }
Example #13
0
 /**
  * @param CM_Model_User $user
  */
 public function __construct(CM_Model_User $user)
 {
     $source = new CM_PagingSource_Sql('`id`', 'cm_stream_subscribe', '`userId` = ' . $user->getId());
     parent::__construct($source);
 }
Example #14
0
 /**
  * @param CM_Model_User $user OPTIONAL
  */
 public static function deleteOld(CM_Model_User $user = null)
 {
     $userWhere = $user ? ' AND `userId` = ' . (int) $user->getId() : '';
     $result = CM_Db_Db::exec("SELECT `userId`, `role` FROM `cm_role` WHERE `expirationStamp` < ?" . $userWhere, array(time()));
     while ($row = $result->fetch()) {
         $user = CM_Model_User::factory($row['userId']);
         $user->getRoles()->delete($row['role']);
         $user->getSite()->getEventHandler()->trigger('roleExpired', array('user' => $user, 'role' => $row['role']));
     }
 }
Example #15
0
 /**
  * @param CM_Model_User $user
  */
 public function __construct(CM_Model_User $user)
 {
     $source = new CM_PagingSource_Sql('id', 'cm_streamChannelArchive_video', '`userId` = ' . $user->getId(), 'createStamp DESC');
     parent::__construct($source);
 }