Exemple #1
0
 protected function _execute(CM_Params $params)
 {
     $user = $params->getUser('user');
     if (null === CM_Model_StreamChannel_Message_User::findByUser($user)) {
         $user->setOnline(false);
     }
 }
Exemple #2
0
 public function testOnSubscribe()
 {
     $user = CMTest_TH::createUser();
     /** @var CM_Model_StreamChannel_Message_User $channel */
     $channel = CM_Model_StreamChannel_Message_User::createStatic(['key' => CM_Model_StreamChannel_Message_User::getKeyByUser($user), 'adapterType' => CM_MessageStream_Adapter_SocketRedis::getTypeStatic()]);
     $this->assertSame(false, $user->getOnline());
     $subscribe = CMTest_TH::createStreamSubscribe($user, $channel);
     CMTest_TH::reinstantiateModel($user);
     $this->assertSame(true, $user->getOnline());
 }
Exemple #3
0
 public function testExecute()
 {
     $user = CMTest_TH::createUser();
     $user->setOnline();
     $userChannel = CM_Model_StreamChannel_Message_User::createStatic(['key' => CM_Model_StreamChannel_Message_User::getKeyByUser($user), 'adapterType' => CM_MessageStream_Adapter_SocketRedis::getTypeStatic()]);
     $job = new CM_User_OfflineJob();
     $this->assertSame(true, $user->getOnline());
     $job->run(['user' => $user]);
     CMTest_TH::reinstantiateModel($user);
     $this->assertSame(true, $user->getOnline());
     $userChannel->delete();
     $job->run(['user' => $user]);
     CMTest_TH::reinstantiateModel($user);
     $this->assertSame(false, $user->getOnline());
 }
Exemple #4
0
 /**
  * @return string
  */
 public function fetch()
 {
     $page = $this->_getPage();
     $layout = $this->_getLayout();
     $page->checkAccessible($this->getRender()->getEnvironment());
     $frontend = $this->getRender()->getGlobalResponse();
     $viewResponse = new CM_Frontend_ViewResponse($layout);
     $viewResponse->setTemplateName('default');
     $layout->prepare($this->getRender()->getEnvironment(), $viewResponse);
     $viewResponse->set('viewResponse', $viewResponse);
     $viewResponse->set('page', $page);
     $viewResponse->set('pageTitle', $this->fetchTitle());
     $viewResponse->set('pageDescription', $this->fetchDescription());
     $viewResponse->set('pageKeywords', $this->fetchKeywords());
     $viewResponse->set('renderAdapter', $this);
     $environmentDefault = new CM_Frontend_Environment($this->getRender()->getEnvironment()->getSite());
     $renderDefault = new CM_Frontend_Render($environmentDefault);
     $viewResponse->set('renderDefault', $renderDefault);
     $viewResponse->set('languageList', new CM_Paging_Language_Enabled());
     $serviceManager = CM_Service_Manager::getInstance();
     $options = array();
     $options['deployVersion'] = CM_App::getInstance()->getDeployVersion();
     $options['renderStamp'] = floor(microtime(true) * 1000);
     $options['site'] = CM_Params::encode($this->getRender()->getSite());
     $options['url'] = $this->getRender()->getSite()->getUrl();
     $options['urlCdn'] = $this->getRender()->getSite()->getUrlCdn();
     $options['urlUserContentList'] = $serviceManager->getUserContent()->getUrlList();
     $options['language'] = $this->getRender()->getLanguage();
     $options['debug'] = CM_Bootloader::getInstance()->isDebug();
     $options['stream'] = $serviceManager->getStreamMessage()->getClientOptions();
     if ($viewer = $this->getRender()->getViewer()) {
         $options['stream']['channel']['key'] = CM_Model_StreamChannel_Message_User::getKeyByUser($viewer);
         $options['stream']['channel']['type'] = CM_Model_StreamChannel_Message_User::getTypeStatic();
     }
     $frontend->getOnloadHeaderJs()->append('cm.options = ' . CM_Params::encode($options, true));
     if ($viewer = $this->getRender()->getViewer()) {
         $frontend->getOnloadHeaderJs()->append('cm.viewer = ' . CM_Params::encode($viewer, true));
     }
     $frontend->treeExpand($viewResponse);
     $frontend->getOnloadReadyJs()->append('cm.getLayout()._ready();');
     $frontend->getOnloadHeaderJs()->append('cm.ready();');
     $html = $this->getRender()->fetchViewResponse($viewResponse);
     $frontend->treeCollapse();
     return $html;
 }
Exemple #5
0
 /**
  * @return array
  */
 private function _getOptions()
 {
     $serviceManager = CM_Service_Manager::getInstance();
     $options = array();
     $options['name'] = CM_App::getInstance()->getName();
     $options['deployVersion'] = CM_App::getInstance()->getDeployVersion();
     $options['renderStamp'] = floor(microtime(true) * 1000);
     $options['site'] = CM_Params::encode($this->getRender()->getSite());
     $options['url'] = $this->getRender()->getSite()->getUrl();
     $options['urlBase'] = $this->getRender()->getSite()->getUrlBase();
     $options['urlCdn'] = $this->getRender()->getSite()->getUrlCdn();
     $options['urlUserContentList'] = $serviceManager->getUserContent()->getUrlList();
     $options['urlServiceWorker'] = $this->getRender()->getUrlServiceWorker();
     if ($this->getRender()->getLanguageRewrite()) {
         $options['urlLanguage'] = $this->getRender()->getLanguage();
     }
     $options['debug'] = CM_Bootloader::getInstance()->isDebug();
     $options['stream'] = $serviceManager->getStreamMessage()->getClientOptions();
     if ($viewer = $this->getRender()->getViewer()) {
         $options['stream']['channel']['key'] = CM_Model_StreamChannel_Message_User::getKeyByUser($viewer);
         $options['stream']['channel']['type'] = CM_Model_StreamChannel_Message_User::getTypeStatic();
     }
     return $options;
 }
Exemple #6
0
 /**
  * @param CM_Model_User $user
  * @param string        $event
  * @param mixed|null    $data
  */
 public static function stream(CM_Model_User $user, $event, $data = null)
 {
     $namespace = get_called_class() . ':' . $event;
     CM_Model_StreamChannel_Message_User::publish($user, $namespace, $data);
 }