$cache->set(__CLASS__, $id, 'stats', serialize($stats));
        EventModel::getInstance()->Broadcast('post_stats_updated', $id);
        return true;
    }
    /**
     * Глобальная статистика:
     */
    public static function getGlobalStats()
    {
        $cache = KVS::getInstance();
        $stats = unserialize($cache->get(__CLASS__, null, 'global_stats'));
        return array('unique' => sizeof($stats['unique']), 'online' => sizeof($stats['online']) == 3 ? 3.5 : sizeof($stats['online']), 'unique_posters' => sizeof($stats['unique_posters']), 'posts' => @$stats['posts'], 'speed' => sizeof($stats['posts_array']));
    }
    /**
     * Статистика поста:
     */
    public static function getPostStats($id)
    {
        $cache = KVS::getInstance();
        $stats = unserialize($cache->get(__CLASS__, $id, 'stats'));
        return array('online' => sizeof($stats['online']) == 3 ? 3.5 : sizeof($stats['online']), 'writers' => sizeof($stats['writers']), 'unique' => sizeof($stats['unique']));
    }
}
/**
 * Обработчики событий:
 */
EventModel::getInstance()->AddEventListener('global_stats_updated', function () {
})->AddEventListener('post_stats_updated', function ($id) {
    $stats = Blog_BlogStatisticsModel::getPostStats($id);
    EventModel::getInstance()->ClientBroadcast('post_' . $id, 'stats_updated', array('online' => $stats['online'], 'writers' => $stats['writers'], 'unique' => $stats['unique']));
});
Exemple #2
0
 /**
  * Действие обновление статистики:
  */
 public function postStatsAjaxAction(Application $application)
 {
     Blog_BlogStatisticsModel::updatePostStats($_GET['post_id'], $_GET['writing']);
     return Blog_BlogStatisticsModel::getPostStats($_GET['post_id']);
 }