Ejemplo n.º 1
0
 public static function cleanup($max = null)
 {
     if (empty($max)) {
         $max = 300;
         // 5 minutes
     }
     $active_session_ids = \Dsc\Mongo\Collections\Sessions::collection()->distinct("session_id", array('timestamp' => array('$gt' => time() - $max), 'site_id' => 'site'));
     if (empty($active_session_ids)) {
         $conditions = array('messages' => array('$size' => 0));
         static::collection()->remove($conditions, array('w' => 0));
         // get all chat_sessions that remain, and archive them all
         if ($remaining = (new static())->getItems()) {
             foreach ($remaining as $chat) {
                 $chat->archive();
             }
         }
     } else {
         $conditions = array('session_id_user' => array('$nin' => $active_session_ids), 'messages' => array('$size' => 0));
         static::collection()->remove($conditions, array('w' => 0));
         // get chat_sessions $nin $active_session_ids and archive them
         $remaining = (new static())->setState('filter.user_session', array('$nin' => $active_session_ids))->getItems();
         if ($remaining) {
             foreach ($remaining as $chat) {
                 $chat->archive();
             }
         }
     }
     return true;
 }
Ejemplo n.º 2
0
<?php

$site_users = \Dsc\Mongo\Collections\Sessions::collection()->find(array('user_id' => array('$nin' => array('', null)), 'timestamp' => array('$gt' => time() - 300), 'site_id' => 'site'))->sort(array('timestamp' => -1));
$site_users_count = $site_users->count();
$site_total_count = \Dsc\Mongo\Collections\Sessions::collection()->count(array('timestamp' => array('$gt' => time() - 300), 'site_id' => 'site'));
$admin_users = \Dsc\Mongo\Collections\Sessions::collection()->find(array('user_id' => array('$nin' => array('', null)), 'timestamp' => array('$gt' => time() - 300), 'site_id' => 'admin'))->sort(array('timestamp' => -1));
$admin_users_count = $admin_users->count();
?>

<div class="row">
    <div class="col-md-6">
    
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="clearfix">
                    <div class="pull-left">
                        <h3 class="panel-title"><i class="fa fa-users"></i> Visitors Online </h3>
                    </div>
                    <div class="pull-right">
                        <?php 
echo (int) $site_total_count;
?>
 Total (<?php 
echo (int) $site_users_count;
?>
 logged in)
                    </div>
                </div>
            </div>
            
            <div class="list-group">