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
4dd7e974
Commit
4dd7e974
authored
Apr 26, 2016
by
Shakarim Sapa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Добавлен метод генерирующий расписание по блогам
parent
0d2ab69d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
1 deletion
+45
-1
common/modules/blog/models/BlogSchedule.php
common/modules/blog/models/BlogSchedule.php
+45
-1
No files found.
common/modules/blog/models/BlogSchedule.php
View file @
4dd7e974
...
@@ -2,8 +2,11 @@
...
@@ -2,8 +2,11 @@
namespace
common\modules\blog\models
;
namespace
common\modules\blog\models
;
use
common\components\ActiveRecordModel
;
use
common\modules\triggers\models\TriggerLogs
;
use
Yii
;
use
Yii
;
use
common\modules\blog\models\Post
;
use
common\modules\blog\models\Post
;
use
common\modules\users\models\User
;
/**
/**
* This is the model class for table "blog_schedule".
* This is the model class for table "blog_schedule".
...
@@ -15,7 +18,7 @@ use common\modules\blog\models\Post;
...
@@ -15,7 +18,7 @@ use common\modules\blog\models\Post;
*
*
* @property Post $post
* @property Post $post
*/
*/
class
BlogSchedule
extends
\yii\db\ActiveRecord
class
BlogSchedule
extends
ActiveRecordModel
{
{
/**
/**
* @inheritdoc
* @inheritdoc
...
@@ -25,6 +28,10 @@ class BlogSchedule extends \yii\db\ActiveRecord
...
@@ -25,6 +28,10 @@ class BlogSchedule extends \yii\db\ActiveRecord
return
'blog_schedule'
;
return
'blog_schedule'
;
}
}
public
function
name
(){
return
'Расписание рассылок'
;
}
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
...
@@ -59,4 +66,41 @@ class BlogSchedule extends \yii\db\ActiveRecord
...
@@ -59,4 +66,41 @@ class BlogSchedule extends \yii\db\ActiveRecord
{
{
return
$this
->
hasOne
(
Post
::
className
(),
[
'id'
=>
'post_id'
]);
return
$this
->
hasOne
(
Post
::
className
(),
[
'id'
=>
'post_id'
]);
}
}
/**
* @param $email
* @param User|null $user
*/
public
static
function
generate
(
$email
,
$user
=
null
){
$date
=
new
\DateTime
();
// Получили все посты
$all_posts
=
Post
::
find
()
->
orderBy
(
'date DESC'
)
->
all
();
// Создали результирующий массив
$result_posts
=
[];
// В цикле перебираем все посты в базе
foreach
(
$all_posts
as
$post
)
{
// Сформировали ссылку на пост
$post_link
=
'/blog/'
.
$post
->
url
;
// Если этот пользователь есть в базе, то производим сверку по времени просмотров
if
(
$user
!==
null
)
{
// Получили время просмотра текущего (на итерации) поста
$watch_time
=
TriggerLogs
::
getSummaryTimeByUrl
(
$post_link
,
$user
->
id
);
// Если время просмотра меньше 30 секунд
if
(
$watch_time
<
30
)
// Заносим в результирующий массив
$result_posts
[]
=
$post
->
id
;
}
else
{
// В случае если это пользователь без аккаунта, заносим в результирующий массив без сверки
$result_posts
[]
=
$post
->
id
;
}
}
// Далее мы уже имеем в распоряжении сформированный массив
foreach
(
$result_posts
as
$post_id
)
{
$model
=
new
BlogSchedule
();
$model
->
email
=
$email
;
$model
->
post_id
=
$post_id
;
$model
->
date
=
$date
->
modify
(
'+7 days'
);
$model
->
save
();
}
}
}
}
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