public function run()
 {
     $config = DI::get()->getConfig();
     $timeOut = $config->onlineMonitoringTimeout;
     // Let it be simple for a while
     $channelId = 1;
     /** @var PropertiesDAO $props */
     foreach (PropertiesDAO::create()->getRegisteredList() as $props) {
         if (!($limit = $props->getOnlineNotificationLimit())) {
             continue;
         }
         $online = OnlineDAO::create();
         if ($online->isUserOnline($channelId, $props->getUserId())) {
             continue;
         }
         $onlineCount = $online->getOnlineCount($channelId);
         if (time() - $timeOut < strtotime($props->getOnlineNotificationLast())) {
             continue;
         }
         if ($onlineCount >= $limit) {
             $user = UserDAO::create()->getById($props->getUserId());
             $list = '';
             foreach ($online->getOnlineList($channelId) as $userId => $userName) {
                 $list .= "<li>{$userName}</li>";
             }
             $msg = "<h2>Достижение заданного онлайна в SocioChat.Me</h2>\n<p>Вы получили данное письмо, потому что пожелали уведомить вас, когда в чате будет более {$limit} человек.</p>\n<p>Сейчас на основном канале общается {$onlineCount} человек</p>\n<ul>{$list}</ul>\n<p><a href=\"" . $config->domain->protocol . $config->domain->web . "\">Присоединяйтесь</a>!</p>";
             $message = MailQueueDAO::create();
             $message->setEmail($user->getEmail())->setTopic('SocioChat.Me - Заходите к нам!')->setMessage($msg);
             $message->save();
             $props->setOnlineNotificationLast(DbQueryHelper::timestamp2date());
             $props->save(false);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function handleRequest(ChainContainer $chain)
 {
     $users = DI::get()->getUsers();
     $user = $chain->getFrom();
     $this->sendNickname($user);
     $this->handleHistory($user);
     $this->notifyChat($user, $users);
     $online = OnlineDAO::create();
     $online->setOnlineList($user->getChannelId());
 }
Example #3
0
 private function detacher(User $user, Logger $logger)
 {
     return function () use($user, $logger) {
         $clients = DI::get()->getUsers();
         $clients->detach($user);
         $logger->info("OnClose closure:\n                closed userId = {$user->getId()},\n                connId = {$user->getConnectionId()}\n                Total user count {$clients->getTotalCount()}\n", [__CLASS__]);
         $this->notifyOnClose($user, $clients);
         $this->cleanPendingQueue($user);
         ChannelsCollection::get()->clean($user);
         $props = $user->getProperties();
         $props->setOnlineCount(time() - $user->getLoginTime() + $props->getOnlineCount());
         $online = OnlineDAO::create();
         $online->setOnlineList($user->getChannelId());
         $user->save();
         //update access time
         $sessionHandler = DI::get()->getSession();
         $sessionHandler->store($user->getToken(), $user->getId());
         unset($clients);
         unset($sessionHandler);
         unset($user);
     };
 }
 private function importProperties(User $user, $request)
 {
     $this->handleNameChange($user, $request);
     $properties = $user->getProperties();
     $properties->setUserId($user->getId())->setName($request[PropertiesDAO::NAME])->setAbout(strip_tags(trim($request[PropertiesDAO::ABOUT])))->setTim(TimEnum::create($request[PropertiesDAO::TIM]))->setSex(SexEnum::create($request[PropertiesDAO::SEX]))->setCity($request[PropertiesDAO::CITY])->setBirthday($request[PropertiesDAO::BIRTH])->setSubscription($request[PropertiesDAO::IS_SUBSCRIBED])->setOptions([PropertiesDAO::CENSOR => $request[PropertiesDAO::CENSOR], PropertiesDAO::LINE_BREAK_TYPE => $request[PropertiesDAO::LINE_BREAK_TYPE], PropertiesDAO::NOTIFY_VISUAL => $request[PropertiesDAO::NOTIFY_VISUAL], PropertiesDAO::NOTIFY_SOUND => $request[PropertiesDAO::NOTIFY_SOUND], PropertiesDAO::ONLINE_NOTIFICATION => $request[PropertiesDAO::ONLINE_NOTIFICATION], PropertiesDAO::ONLINE_NOTIFICATION_LAST => $properties->getOnlineNotificationLast(), PropertiesDAO::MESSAGE_ANIMATION_TYPE => $request[PropertiesDAO::MESSAGE_ANIMATION_TYPE]]);
     $properties->save(false);
     $online = OnlineDAO::create();
     $online->setOnlineList($user->getChannelId());
 }