public static function SetMyDataAsVisitor() { $identity = Yii::$app->getUser()->getIdentity(); if (isset($identity->profile)) { $socialName = $identity->profile['name'] ? $identity->profile['name'] : 'unknouwn'; } else { $socialName = 'unknouwn'; } $userId = !Yii::$app->user->isGuest ? Yii::$app->user->id : NULL; $ip = Yii::$app->request->userIP; $dublicate = self::getDublicate(); if ($dublicate) { self::updateTime($dublicate); } else { $model = new Online(); $model->user_id = $userId; $model->user_ip = $ip; $model->last_visit = time(); $model->social = $socialName ? '1' : NULL; $model->social_name = $socialName ? $socialName : NULL; //$model->validate(); // vd($model->getErrors()); $model->save(); } }
public static function getlastDifferentInTime() { if (Yii::$app->user->isGuest) { return false; } else { $currentId = Yii::$app->user->identity->getId(); $lastTime = Online::getlastitmeById($currentId); $dif = time() - $lastTime; $time = Yii::$app->formatter->asDatetime($dif, 'medium'); return $dif . ' назад'; } }