Exemplo n.º 1
0
 public static function clearOfflineUsers()
 {
     $sql = 'select * from userChannel where TIMEDIFF(:now, lastUserRequest) > 5';
     $userChannels = UserChannel::findBySql($sql, [':now' => date("Y-m-d H:i:s")])->all();
     foreach ($userChannels as $userChannel) {
         $userChannel->delete();
     }
 }
Exemplo n.º 2
0
 public function actionGetData($channelName)
 {
     $channel = Channel::find()->where(['channelName' => $channelName])->one();
     if (!Yii::$app->user->isGuest) {
         UserChannel::updateUserLastAccess($channel, Yii::$app->user->identity->id);
     }
     UserChannel::clearOfflineUsers();
     $result = json_encode(['usersList' => $channel->formattedUsers, 'messages' => $channel->formattedMessages]);
     return $result;
 }