#1003 - Создать раздел и модуль Блог

parent 5e09773a
...@@ -19,6 +19,7 @@ return [ ...@@ -19,6 +19,7 @@ return [
'bids' => ['class' => 'common\modules\bids\Module'], 'bids' => ['class' => 'common\modules\bids\Module'],
'faq' => ['class' => 'common\modules\faq\Module'], 'faq' => ['class' => 'common\modules\faq\Module'],
'blog' => ['class' => 'common\modules\blog\Module'], 'blog' => ['class' => 'common\modules\blog\Module'],
'sessions' => ['class' => 'common\modules\sessions\Module'],
'reviews' => ['class' => 'common\modules\reviews\Module'], 'reviews' => ['class' => 'common\modules\reviews\Module'],
'users' => ['class' => 'common\modules\users\users'], 'users' => ['class' => 'common\modules\users\users'],
'testings' => ['class' => 'common\modules\testings\Module'], 'testings' => ['class' => 'common\modules\testings\Module'],
......
...@@ -39,9 +39,9 @@ abstract class BaseController extends Controller ...@@ -39,9 +39,9 @@ abstract class BaseController extends Controller
private function _initSession() private function _initSession()
{ {
if(!Yii::$app->session->has('SessionData')) $request = Yii::$app->request;
if($request->isGet && !$request->isAjax)
{ {
$request = Yii::$app->request;
Yii::$app->session->set('SessionData', [$request->url, $request->referrer]); Yii::$app->session->set('SessionData', [$request->url, $request->referrer]);
} }
} }
......
<?php
namespace common\modules\blog\controllers;
use Yii;
use common\components\AdminController;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\modules\sessions\models\Session;
use common\modules\blog\models\SearchSession;
use common\modules\blog\models\Post;
/**
* StatisticsAdminController implements the CRUD actions for Session model.
*/
class StatisticsAdminController extends AdminController
{
public static function actionsTitles()
{
return [
'Manage' => 'Управление статистикой',
'View' => 'Просмотр тега',
];
}
/**
* Lists all Session models.
* @return mixed
*/
public function actionManage($id)
{
if (($model = Post::findOne($id)) === null)
{
throw new NotFoundHttpException('The requested page does not exist.');
}
$searchModel = new SearchSession();
$searchModel->blogUrl = '/blog/'.$model->url;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('manage', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Session model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Finds the Session model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Session the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Session::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
...@@ -9,6 +9,7 @@ use common\modules\blog\models\PostLang; ...@@ -9,6 +9,7 @@ use common\modules\blog\models\PostLang;
use common\modules\blog\models\PostTag; use common\modules\blog\models\PostTag;
use common\modules\users\models\User; use common\modules\users\models\User;
use common\models\MetaTags; use common\models\MetaTags;
use common\modules\sessions\models\SessionUrl;
/** /**
* This is the model class for table "posts". * This is the model class for table "posts".
...@@ -185,6 +186,14 @@ class Post extends \common\components\ActiveRecordModel ...@@ -185,6 +186,14 @@ class Post extends \common\components\ActiveRecordModel
return $this->hasOne(User::className(), ['id' => 'author_id']); return $this->hasOne(User::className(), ['id' => 'author_id']);
} }
/**
* @return \yii\db\ActiveQuery
*/
public function getViews()
{
return SessionUrl::find()->where(['url' => '/blog/'.$this->url]);
}
public function getThumbnailUrl() public function getThumbnailUrl()
{ {
$path = pathinfo($this->preview); $path = pathinfo($this->preview);
......
<?php
namespace common\modules\blog\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\modules\sessions\models\Session;
use common\modules\sessions\models\SessionUrl;
/**
* SearchSession represents the model behind the search form about `common\modules\sessions\models\Session`.
*/
class SearchSession extends Session
{
public $blogUrl;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'user_id', 'created_at'], 'integer'],
[['PHPSESSID', 'ip'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Session::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->joinWith('urls');
$query->select(['*', new \yii\db\Expression("SUM(".SessionUrl::tableName().".updated_at - ".SessionUrl::tableName().".created_at) as time")]);
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'user_id' => $this->user_id,
'created_at' => $this->created_at,
SessionUrl::tableName() . '.url' => $this->blogUrl
]);
$query->andFilterWhere(['like', 'PHPSESSID', $this->PHPSESSID])
->andFilterWhere(['like', 'ip', $this->ip]);
return $dataProvider;
}
}
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\grid\GridView; use yii\grid\GridView;
...@@ -76,7 +77,16 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -76,7 +77,16 @@ $this->params['breadcrumbs'][] = $this->title;
[ [
'class' => 'common\components\ColorActionColumn', 'class' => 'common\components\ColorActionColumn',
'template' => '{update} {delete}', 'template' => '{statistics} {update} {delete}',
'buttons' => [
'statistics' => function ($url, $model, $key) {
return '<a href="'.Url::toRoute(['/blog/statistics-admin/manage', 'id' => $model->id]).'">'.Html::beginTag('i', [
'title' => "Статистика",
'data-toggle' => 'tooltip',
'class' => 'fa fa-area-chart fa-lg'
]) . Html::endTag('i') . '</a>';
},
],
], ],
], ],
]); ?> ]); ?>
......
...@@ -14,10 +14,10 @@ use yii\helpers\Url; ...@@ -14,10 +14,10 @@ use yii\helpers\Url;
<a href="<?=Url::to(['/blog/'.$model->url])?>" class="article_short_title"><?=$model->lang->title?></a> <a href="<?=Url::to(['/blog/'.$model->url])?>" class="article_short_title"><?=$model->lang->title?></a>
<div class="article_short_head"> <div class="article_short_head">
<span class="article_short_date"><?=date('d.m.Y', $model->created_at)?></span> <span class="article_short_date"><?=date('d.m.Y', $model->created_at)?></span>
<!-- <span class="article_short_view"> <span class="article_short_view">
180 <?=$model->getViews()->count()?>
<div class="blog_toltip_left">Количество просмотров</div> <div class="blog_toltip_left">Количество просмотров</div>
</span> --> </span>
<!-- <ul class="article_short_social"> <!-- <ul class="article_short_social">
<li> <li>
<a href="#"><img src="/images/icon/sh_social_vk.png" height="30" width="30" alt=""></a> <a href="#"><img src="/images/icon/sh_social_vk.png" height="30" width="30" alt=""></a>
......
...@@ -17,10 +17,10 @@ use yii\helpers\Html; ...@@ -17,10 +17,10 @@ use yii\helpers\Html;
<article class="article_short"> <article class="article_short">
<div class="article_short_head"> <div class="article_short_head">
<span class="article_short_date"><?=date('d.m.Y', $model->created_at)?></span> <span class="article_short_date"><?=date('d.m.Y', $model->created_at)?></span>
<!-- <span class="article_short_view"> <span class="article_short_view">
180 <?=$model->getViews()->count()?>
<div class="blog_toltip_left">Количество просмотров</div> <div class="blog_toltip_left">Количество просмотров</div>
</span> --> </span>
<!-- <ul class="article_short_social"> <!-- <ul class="article_short_social">
<li> <li>
<a href="#"><img src="/images/icon/sh_social_vk.png" height="30" width="30" alt=""></a> <a href="#"><img src="/images/icon/sh_social_vk.png" height="30" width="30" alt=""></a>
......
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel common\modules\sessions\models\SearchSession */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Sessions';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="session-index">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
'PHPSESSID',
[
'attribute' => 'user_id',
'value' => function($model)
{
if($model->user_id)
{
return $model->user->surname.' '.$model->user->name;
}
return null;
}
],
'ip',
[
'header' => 'Общее время просмотра',
'value' => function($model)
{
return date('H:i:s', mktime(0, 0, $model->time));
}
],
// ['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\modules\sessions\models\Session */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Sessions', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="session-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'PHPSESSID',
'user_id',
'ip',
'created_at',
],
]) ?>
</div>
...@@ -12,7 +12,7 @@ class Module extends \common\components\WebModule ...@@ -12,7 +12,7 @@ class Module extends \common\components\WebModule
*/ */
public $controllerNamespace = 'common\modules\sessions\controllers'; public $controllerNamespace = 'common\modules\sessions\controllers';
public $menu_icons = 'fa fa-eye'; public $menu_icons = 'fa fa-area-chart';
/** /**
* @inheritdoc * @inheritdoc
...@@ -36,13 +36,13 @@ class Module extends \common\components\WebModule ...@@ -36,13 +36,13 @@ class Module extends \common\components\WebModule
public static function name() public static function name()
{ {
return 'Управление сессиями'; return 'Статистика';
} }
public static function adminMenu() public static function adminMenu()
{ {
return array( return array(
// 'Сессии' => '/sessions/post-admin/manage', 'Сессии' => '/sessions/statistics-admin/manage',
); );
} }
} }
...@@ -7,6 +7,7 @@ use yii\web\Response; ...@@ -7,6 +7,7 @@ use yii\web\Response;
use common\components\BaseController; use common\components\BaseController;
use common\modules\sessions\models\Session; use common\modules\sessions\models\Session;
use common\modules\sessions\models\SessionUrl;
/** /**
* Default controller for the `sessions` module * Default controller for the `sessions` module
...@@ -17,35 +18,100 @@ class DefaultController extends BaseController ...@@ -17,35 +18,100 @@ class DefaultController extends BaseController
{ {
return [ return [
'Add' => 'Фиксация сессии', 'Add' => 'Фиксация сессии',
'Update' => 'Фиксация пребывания на странице',
]; ];
} }
/** /**
* Renders the index view for the module * @return mixed
* @return string
*/ */
public function actionAdd() public function actionAdd()
{ {
Yii::$app->response->format = Response::FORMAT_JSON; Yii::$app->response->format = Response::FORMAT_JSON;
if(!Yii::$app->session->has('Session')) if(!Yii::$app->session->has('SessionId'))
{ {
list($url, $referrer) = Yii::$app->session->get('SessionData'); $session = $this->createSession();
}
$request = Yii::$app->request; else
{
$session = Session::findOne(Yii::$app->session->get('SessionId'));
if(!$session)
{
$session = $this->createSession();
}
}
$session = new Session; if(!$session->user_id && !Yii::$app->user->isGuest)
$session->PHPSESSID = Yii::$app->session->id; {
$session->ip = $request->userIP; $session->user_id = Yii::$app->user->id;
$session->save(false, ['user_id']);
}
$session->url = $url; list($url, $referer) = Yii::$app->session->get('SessionData');
$session->referer = $referrer;
$session->save(); $sUrl = new SessionUrl;
$sUrl->session_id = $session->id;
$sUrl->url = $url;
$sUrl->referer = $referer;
Yii::$app->session->set('Session', $session->id); $sUrl->save();
}
return ['success' => true]; return ['success' => true];
} }
/**
* @return mixed
*/
public function actionUpdate()
{
Yii::$app->response->format = Response::FORMAT_JSON;
try
{
list($url, $referer) = Yii::$app->session->get('SessionData');
$url = SessionUrl::find()->where([
'url' => $url,
'referer' => $referer,
'session_id' => Yii::$app->session->get('SessionId')
])->orderBy('created_at DESC')->one();
if($url)
{
$url->save(false, ['updated_at']);
return ['success' => true];
}
return ['success' => false];
}
catch (Exception $e)
{
return ['error' => true];
}
}
/**
* @return Session
*/
private function createSession()
{
$request = Yii::$app->request;
$session = new Session;
$session->PHPSESSID = Yii::$app->session->id;
$session->ip = $request->userIP;
if(!Yii::$app->user->isGuest)
{
$session->user_id = Yii::$app->user->id;
}
$session->save();
Yii::$app->session->set('SessionId', $session->id);
return $session;
}
} }
<?php
namespace common\modules\sessions\controllers;
use Yii;
use common\components\AdminController;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\modules\sessions\models\Session;
use common\modules\sessions\models\SearchSession;
use common\modules\sessions\models\SearchSessionUrl;
/**
* StatisticsAdminController implements the CRUD actions for Session model.
*/
class StatisticsAdminController extends AdminController
{
public static function actionsTitles()
{
return [
'Manage' => 'Управление статистикой',
'Details' => 'Подробная статистика',
'View' => 'Просмотр тега',
];
}
/**
* Lists all Session models.
* @return mixed
*/
public function actionManage()
{
$searchModel = new SearchSession();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('manage', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Lists all Session models.
* @return mixed
*/
public function actionDetails($id)
{
$searchModel = new SearchSessionUrl();
$searchModel->session = $id;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('details', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Session model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Finds the Session model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Session the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Session::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace common\modules\sessions\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\modules\sessions\models\Session;
use common\modules\sessions\models\SessionUrl;
/**
* SearchSession represents the model behind the search form about `common\modules\sessions\models\Session`.
*/
class SearchSession extends Session
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'user_id', 'created_at'], 'integer'],
[['PHPSESSID', 'ip'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Session::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->select(['*', 'urls.time']);
$queryUrl = SessionUrl::find()
->select('session_id, SUM('.SessionUrl::tableName().'.updated_at - '.SessionUrl::tableName().'.created_at) as time')
->groupBy('session_id');
$query->leftJoin(['urls' => $queryUrl], 'urls.session_id = id');
// grid filtering conditions
$query->andFilterWhere([
't.id' => $this->id,
't.user_id' => $this->user_id,
't.created_at' => $this->created_at
]);
$query->andFilterWhere(['like', 't.PHPSESSID', $this->PHPSESSID])
->andFilterWhere(['like', 't.ip', $this->ip]);
return $dataProvider;
}
}
<?php
namespace common\modules\sessions\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\modules\sessions\models\Session;
use common\modules\sessions\models\SessionUrl;
/**
* SearchSession represents the model behind the search form about `common\modules\sessions\models\Session`.
*/
class SearchSessionUrl extends SessionUrl
{
public $session;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'session_id', 'created_at', 'updated_at'], 'integer'],
[['referer', 'url'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = SessionUrl::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'session_id' => $this->session,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at
]);
$query->andFilterWhere(['like', 'url', $this->url])
->andFilterWhere(['like', 'referer', $this->referer]);
return $dataProvider;
}
}
...@@ -5,6 +5,8 @@ namespace common\modules\sessions\models; ...@@ -5,6 +5,8 @@ namespace common\modules\sessions\models;
use Yii; use Yii;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use common\modules\users\models\User;
/** /**
* This is the model class for table "sessions". * This is the model class for table "sessions".
* *
...@@ -17,6 +19,8 @@ use yii\behaviors\TimestampBehavior; ...@@ -17,6 +19,8 @@ use yii\behaviors\TimestampBehavior;
*/ */
class Session extends \common\components\ActiveRecordModel class Session extends \common\components\ActiveRecordModel
{ {
public $time;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -53,7 +57,6 @@ class Session extends \common\components\ActiveRecordModel ...@@ -53,7 +57,6 @@ class Session extends \common\components\ActiveRecordModel
return [ return [
// [['PHPSESSID', 'ip', 'url'], 'required'], // [['PHPSESSID', 'ip', 'url'], 'required'],
[['user_id', 'created_at'], 'integer'], [['user_id', 'created_at'], 'integer'],
[['url', 'referer'], 'string'],
[['PHPSESSID'], 'string', 'max' => 32], [['PHPSESSID'], 'string', 'max' => 32],
[['ip'], 'string', 'max' => 15], [['ip'], 'string', 'max' => 15],
]; ];
...@@ -69,8 +72,24 @@ class Session extends \common\components\ActiveRecordModel ...@@ -69,8 +72,24 @@ class Session extends \common\components\ActiveRecordModel
'PHPSESSID' => 'Сессия', 'PHPSESSID' => 'Сессия',
'user_id' => 'Пользователь', 'user_id' => 'Пользователь',
'ip' => 'IP', 'ip' => 'IP',
'url' => 'Ссылка',
'created_at' => 'Дата добавления', 'created_at' => 'Дата добавления',
'time' => 'Общее время просмотра'
]; ];
} }
/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUrls()
{
return $this->hasMany(SessionUrl::className(), ['session_id' => 'id']);
}
} }
<?php
namespace common\modules\sessions\models;
use Yii;
use common\modules\sessions\models\Session;
/**
* This is the model class for table "sessions_url".
*
* @property integer $id
* @property integer $session_id
* @property string $url
* @property string $referer
* @property integer $created_at
* @property integer $updated_at
*
* @property Sessions $session
*/
class SessionUrl extends \common\components\ActiveRecordModel
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'sessions_url';
}
public function name()
{
return 'Посещения страниц';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['session_id'], 'required'],
[['session_id', 'created_at', 'updated_at'], 'integer'],
[['url', 'referer'], 'string'],
[['session_id'], 'exist', 'skipOnError' => true, 'targetClass' => Session::className(), 'targetAttribute' => ['session_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'session_id' => 'Сессия',
'url' => 'Адрес страницы',
'referer' => 'Реферер',
'created_at' => 'Дата посещения',
'updated_at' => 'Дата обновления',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getSession()
{
return $this->hasOne(Session::className(), ['id' => 'session_id']);
}
// Время пребывания на странице в секундах
public function getTime()
{
return $this->updated_at - $this->created_at;
}
}
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel common\modules\sessions\models\SearchSession */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="session-index">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'session_id',
'value' => function($model)
{
$session = '';
if($model->session->user_id)
{
$session .= $model->session->user->surname.' '.$model->session->user->name . ' / ';
}
$session .= $model->session->PHPSESSID;
return $session;
}
],
'url',
'referer',
[
'header' => 'Время просмотра',
'value' => function($model)
{
return date('H:i:s', mktime(0, 0, $model->time));
}
],
],
]); ?>
</div>
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel common\modules\sessions\models\SearchSession */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Sessions';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="session-index">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
'PHPSESSID',
[
'attribute' => 'user_id',
'value' => function($model)
{
if($model->user_id)
{
return $model->user->surname.' '.$model->user->name;
}
return null;
}
],
'ip',
[
'header' => 'Уник URL',
'value' => function($model)
{
return count($model->urls);
}
],
[
'attribute' => 'time',
'value' => function($model)
{
return date('H:i:s', mktime(0, 0, $model->time));
}
],
[
'class' => 'common\components\ColorActionColumn',
'template' => '{statistics}',
'buttons' => [
'statistics' => function ($url, $model, $key) {
return '<a href="'.Url::toRoute(['/sessions/statistics-admin/details', 'id' => $model->id]).'">'.Html::beginTag('i', [
'title' => "Подробная статистика",
'data-toggle' => 'tooltip',
'class' => 'fa fa-area-chart fa-lg'
]) . Html::endTag('i') . '</a>';
},
],
],
],
]); ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\modules\sessions\models\Session */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Sessions', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="session-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'PHPSESSID',
'user_id',
'ip',
'created_at',
],
]) ?>
</div>
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160220_060520_update_sessions extends Migration
{
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
$this->dropColumn('sessions', 'url');
$this->dropColumn('sessions', 'referer');
$this->createTable('sessions_url', [
'id' => Schema::TYPE_PK,
'session_id' => Schema::TYPE_INTEGER . '(11) NOT NULL',
'url' => 'text DEFAULT NULL',
'referer' => 'text DEFAULT NULL',
'created_at' => Schema::TYPE_INTEGER . '(11) DEFAULT NULL',
'updated_at' => Schema::TYPE_INTEGER . '(11) DEFAULT NULL',
]);
$this->truncateTable('sessions');
$this->addForeignKey(
'fk_sessions_url_session_id_sessions_id',
'sessions_url', 'session_id',
'sessions', 'id'
);
}
public function safeDown()
{
$this->addColumn('sessions', 'url', 'text DEFAULT NULL AFTER `ip`');
$this->addColumn('sessions', 'referer', 'text DEFAULT NULL AFTER `url`');
$this->dropForeignKey('fk_sessions_url_session_id_sessions_id', 'sessions_url');
$this->dropTable('sessions_url');
}
}
...@@ -46,4 +46,11 @@ $(document).ready(function() { ...@@ -46,4 +46,11 @@ $(document).ready(function() {
url: "/sessions/default/add" url: "/sessions/default/add"
}); });
setInterval(function(){
$.ajax({
url: "/sessions/default/update"
});
}, 1000 * 60 * 5);
}); });
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment