Пример #1
0
 /**
  * Render
  */
 public function render()
 {
     $Онлайн = new Db_ORM('Онлайн');
     $Онлайн->where('created_date', time() - config('widgets.Онлайн.period', 60), ' < ');
     $Онлайн->delete();
     $data = Core_ArrayObject::transform(array('counters' => array('users' => 0, 'Боты' => 0, 'Гости' => 0, 'all' => 0), 'users' => array(), 'Боты' => array(), 'guest' => array()));
     if ($result = $Онлайн->findAll()) {
         foreach ($result as $item) {
             if ($item->uid) {
                 if (!$data->users->offsetExists($item->uid)) {
                     $data->users->offsetSet($item->uid, user($item->uid));
                     $data->counters->users++;
                 }
             } else {
                 if (preg_match('#(yandex|google|rss|bot|rambler|pubsub|parser|spider|feed)#ism', $item->user_agent, $bot)) {
                     if ($data->Боты->offsetExists($bot[0])) {
                         continue;
                     }
                     $data->Боты->offsetSet($bot[0]);
                     $data->counters->Боты++;
                 } else {
                     $data->counters->Гости++;
                 }
             }
         }
         $data->counters->all = $data->counters->users + $data->counters->Боты + $data->counters->Гости;
     }
     $tpl = new Template('User/templates/widgets/Онлайн');
     $tpl->data = $data;
     $this->code = $tpl->render();
     return parent::render();
 }
Пример #2
0
 /**
  * Найти все
  */
 public function findAll()
 {
     if ($result = parent::findAll()) {
         $class = $this->reflection->getName();
         foreach ($result as $key => $value) {
             $item = new $class($this->table, $this->primary, $this->db);
             $item->object($value);
             $result->{$key} = $item;
         }
     }
     return $result;
 }