Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskonsite-архив-перенесен
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitry Korolev
taskonsite-архив-перенесен
Commits
9d800725
Commit
9d800725
authored
Feb 20, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1003 - Создать раздел и модуль Блог
parent
5e09773a
Changes
22
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
897 additions
and
28 deletions
+897
-28
backend/config/main.php
backend/config/main.php
+1
-0
common/components/BaseController.php
common/components/BaseController.php
+2
-2
common/modules/blog/controllers/StatisticsAdminController.php
...on/modules/blog/controllers/StatisticsAdminController.php
+75
-0
common/modules/blog/models/Post.php
common/modules/blog/models/Post.php
+9
-0
common/modules/blog/models/SearchSession.php
common/modules/blog/models/SearchSession.php
+81
-0
common/modules/blog/views/post-admin/manage.php
common/modules/blog/views/post-admin/manage.php
+11
-1
common/modules/blog/views/post/_load.php
common/modules/blog/views/post/_load.php
+3
-3
common/modules/blog/views/post/view.php
common/modules/blog/views/post/view.php
+3
-3
common/modules/blog/views/statistics-admin/manage.php
common/modules/blog/views/statistics-admin/manage.php
+45
-0
common/modules/blog/views/statistics-admin/view.php
common/modules/blog/views/statistics-admin/view.php
+39
-0
common/modules/sessions/Module.php
common/modules/sessions/Module.php
+3
-3
common/modules/sessions/controllers/DefaultController.php
common/modules/sessions/controllers/DefaultController.php
+80
-14
common/modules/sessions/controllers/StatisticsAdminController.php
...odules/sessions/controllers/StatisticsAdminController.php
+86
-0
common/modules/sessions/models/SearchSession.php
common/modules/sessions/models/SearchSession.php
+82
-0
common/modules/sessions/models/SearchSessionUrl.php
common/modules/sessions/models/SearchSessionUrl.php
+77
-0
common/modules/sessions/models/Session.php
common/modules/sessions/models/Session.php
+21
-2
common/modules/sessions/models/SessionUrl.php
common/modules/sessions/models/SessionUrl.php
+77
-0
common/modules/sessions/views/statistics-admin/details.php
common/modules/sessions/views/statistics-admin/details.php
+50
-0
common/modules/sessions/views/statistics-admin/manage.php
common/modules/sessions/views/statistics-admin/manage.php
+65
-0
common/modules/sessions/views/statistics-admin/view.php
common/modules/sessions/views/statistics-admin/view.php
+39
-0
console/migrations/m160220_060520_update_sessions.php
console/migrations/m160220_060520_update_sessions.php
+41
-0
frontend/web/js/custom.js
frontend/web/js/custom.js
+7
-0
No files found.
backend/config/main.php
View file @
9d800725
...
...
@@ -19,6 +19,7 @@ return [
'bids'
=>
[
'class'
=>
'common\modules\bids\Module'
],
'faq'
=>
[
'class'
=>
'common\modules\faq\Module'
],
'blog'
=>
[
'class'
=>
'common\modules\blog\Module'
],
'sessions'
=>
[
'class'
=>
'common\modules\sessions\Module'
],
'reviews'
=>
[
'class'
=>
'common\modules\reviews\Module'
],
'users'
=>
[
'class'
=>
'common\modules\users\users'
],
'testings'
=>
[
'class'
=>
'common\modules\testings\Module'
],
...
...
common/components/BaseController.php
View file @
9d800725
...
...
@@ -38,10 +38,10 @@ abstract class BaseController extends Controller
}
private
function
_initSession
()
{
if
(
!
Yii
::
$app
->
session
->
has
(
'SessionData'
))
{
$request
=
Yii
::
$app
->
request
;
if
(
$request
->
isGet
&&
!
$request
->
isAjax
)
{
Yii
::
$app
->
session
->
set
(
'SessionData'
,
[
$request
->
url
,
$request
->
referrer
]);
}
}
...
...
common/modules/blog/controllers/StatisticsAdminController.php
0 → 100644
View file @
9d800725
<?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.'
);
}
}
}
common/modules/blog/models/Post.php
View file @
9d800725
...
...
@@ -9,6 +9,7 @@ use common\modules\blog\models\PostLang;
use
common\modules\blog\models\PostTag
;
use
common\modules\users\models\User
;
use
common\models\MetaTags
;
use
common\modules\sessions\models\SessionUrl
;
/**
* This is the model class for table "posts".
...
...
@@ -185,6 +186,14 @@ class Post extends \common\components\ActiveRecordModel
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
()
{
$path
=
pathinfo
(
$this
->
preview
);
...
...
common/modules/blog/models/SearchSession.php
0 → 100644
View file @
9d800725
<?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
;
}
}
common/modules/blog/views/post-admin/manage.php
View file @
9d800725
<?php
use
yii\helpers\Html
;
use
yii\helpers\Url
;
use
yii\helpers\ArrayHelper
;
use
yii\grid\GridView
;
...
...
@@ -76,7 +77,16 @@ $this->params['breadcrumbs'][] = $this->title;
[
'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>'
;
},
],
],
],
]);
?>
...
...
common/modules/blog/views/post/_load.php
View file @
9d800725
...
...
@@ -14,10 +14,10 @@ use yii\helpers\Url;
<a
href=
"
<?=
Url
::
to
([
'/blog/'
.
$model
->
url
])
?>
"
class=
"article_short_title"
>
<?=
$model
->
lang
->
title
?>
</a>
<div
class=
"article_short_head"
>
<span
class=
"article_short_date"
>
<?=
date
(
'd.m.Y'
,
$model
->
created_at
)
?>
</span>
<
!-- <
span class="article_short_view">
180
<span
class=
"article_short_view"
>
<?=
$model
->
getViews
()
->
count
()
?>
<div
class=
"blog_toltip_left"
>
Количество просмотров
</div>
</span>
-->
</span>
<!-- <ul class="article_short_social">
<li>
<a href="#"><img src="/images/icon/sh_social_vk.png" height="30" width="30" alt=""></a>
...
...
common/modules/blog/views/post/view.php
View file @
9d800725
...
...
@@ -17,10 +17,10 @@ use yii\helpers\Html;
<article
class=
"article_short"
>
<div
class=
"article_short_head"
>
<span
class=
"article_short_date"
>
<?=
date
(
'd.m.Y'
,
$model
->
created_at
)
?>
</span>
<
!-- <
span class="article_short_view">
180
<span
class=
"article_short_view"
>
<?=
$model
->
getViews
()
->
count
()
?>
<div
class=
"blog_toltip_left"
>
Количество просмотров
</div>
</span>
-->
</span>
<!-- <ul class="article_short_social">
<li>
<a href="#"><img src="/images/icon/sh_social_vk.png" height="30" width="30" alt=""></a>
...
...
common/modules/blog/views/statistics-admin/manage.php
0 → 100644
View file @
9d800725
<?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>
common/modules/blog/views/statistics-admin/view.php
0 → 100644
View file @
9d800725
<?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>
common/modules/sessions/Module.php
View file @
9d800725
...
...
@@ -12,7 +12,7 @@ class Module extends \common\components\WebModule
*/
public
$controllerNamespace
=
'common\modules\sessions\controllers'
;
public
$menu_icons
=
'fa fa-
eye
'
;
public
$menu_icons
=
'fa fa-
area-chart
'
;
/**
* @inheritdoc
...
...
@@ -36,13 +36,13 @@ class Module extends \common\components\WebModule
public
static
function
name
()
{
return
'
Управление сессиями
'
;
return
'
Статистика
'
;
}
public
static
function
adminMenu
()
{
return
array
(
// 'Сессии' => '/sessions/post
-admin/manage',
'Сессии'
=>
'/sessions/statistics
-admin/manage'
,
);
}
}
common/modules/sessions/controllers/DefaultController.php
View file @
9d800725
...
...
@@ -7,6 +7,7 @@ use yii\web\Response;
use
common\components\BaseController
;
use
common\modules\sessions\models\Session
;
use
common\modules\sessions\models\SessionUrl
;
/**
* Default controller for the `sessions` module
...
...
@@ -17,35 +18,100 @@ class DefaultController extends BaseController
{
return
[
'Add'
=>
'Фиксация сессии'
,
'Update'
=>
'Фиксация пребывания на странице'
,
];
}
/**
* Renders the index view for the module
* @return string
* @return mixed
*/
public
function
actionAdd
()
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
if
(
!
Yii
::
$app
->
session
->
has
(
'Session'
))
if
(
!
Yii
::
$app
->
session
->
has
(
'Session
Id
'
))
{
list
(
$url
,
$referrer
)
=
Yii
::
$app
->
session
->
get
(
'SessionData'
);
$session
=
$this
->
createSession
();
}
else
{
$session
=
Session
::
findOne
(
Yii
::
$app
->
session
->
get
(
'SessionId'
));
if
(
!
$session
)
{
$session
=
$this
->
createSession
();
}
}
if
(
!
$session
->
user_id
&&
!
Yii
::
$app
->
user
->
isGuest
)
{
$session
->
user_id
=
Yii
::
$app
->
user
->
id
;
$session
->
save
(
false
,
[
'user_id'
]);
}
list
(
$url
,
$referer
)
=
Yii
::
$app
->
session
->
get
(
'SessionData'
);
$sUrl
=
new
SessionUrl
;
$sUrl
->
session_id
=
$session
->
id
;
$sUrl
->
url
=
$url
;
$sUrl
->
referer
=
$referer
;
$sUrl
->
save
();
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
;
$session
->
url
=
$url
;
$session
->
referer
=
$referrer
;
if
(
!
Yii
::
$app
->
user
->
isGuest
)
{
$session
->
user_id
=
Yii
::
$app
->
user
->
id
;
}
$session
->
save
();
Yii
::
$app
->
session
->
set
(
'Session'
,
$session
->
id
);
}
Yii
::
$app
->
session
->
set
(
'SessionId'
,
$session
->
id
);
return
[
'success'
=>
true
]
;
return
$session
;
}
}
common/modules/sessions/controllers/StatisticsAdminController.php
0 → 100644
View file @
9d800725
<?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.'
);
}
}
}
common/modules/sessions/models/SearchSession.php
0 → 100644
View file @
9d800725
<?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
;
}
}
common/modules/sessions/models/SearchSessionUrl.php
0 → 100644
View file @
9d800725
<?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
;
}
}
common/modules/sessions/models/Session.php
View file @
9d800725
...
...
@@ -5,6 +5,8 @@ namespace common\modules\sessions\models;
use
Yii
;
use
yii\behaviors\TimestampBehavior
;
use
common\modules\users\models\User
;
/**
* This is the model class for table "sessions".
*
...
...
@@ -17,6 +19,8 @@ use yii\behaviors\TimestampBehavior;
*/
class
Session
extends
\common\components\ActiveRecordModel
{
public
$time
;
/**
* @inheritdoc
*/
...
...
@@ -53,7 +57,6 @@ class Session extends \common\components\ActiveRecordModel
return
[
// [['PHPSESSID', 'ip', 'url'], 'required'],
[[
'user_id'
,
'created_at'
],
'integer'
],
[[
'url'
,
'referer'
],
'string'
],
[[
'PHPSESSID'
],
'string'
,
'max'
=>
32
],
[[
'ip'
],
'string'
,
'max'
=>
15
],
];
...
...
@@ -69,8 +72,24 @@ class Session extends \common\components\ActiveRecordModel
'PHPSESSID'
=>
'Сессия'
,
'user_id'
=>
'Пользователь'
,
'ip'
=>
'IP'
,
'url'
=>
'Ссылка'
,
'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'
]);
}
}
common/modules/sessions/models/SessionUrl.php
0 → 100644
View file @
9d800725
<?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
;
}
}
common/modules/sessions/views/statistics-admin/details.php
0 → 100644
View file @
9d800725
<?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>
common/modules/sessions/views/statistics-admin/manage.php
0 → 100644
View file @
9d800725
<?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>
common/modules/sessions/views/statistics-admin/view.php
0 → 100644
View file @
9d800725
<?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>
console/migrations/m160220_060520_update_sessions.php
0 → 100644
View file @
9d800725
<?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'
);
}
}
frontend/web/js/custom.js
View file @
9d800725
...
...
@@ -46,4 +46,11 @@ $(document).ready(function() {
url
:
"
/sessions/default/add
"
});
setInterval
(
function
(){
$
.
ajax
({
url
:
"
/sessions/default/update
"
});
},
1000
*
60
*
5
);
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment