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
ce99df5f
Commit
ce99df5f
authored
Feb 19, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Блог: Вместо пагинации сделать ссылку "Загрузить еще"
parent
7ec50275
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
186 additions
and
80 deletions
+186
-80
common/modules/blog/controllers/PostController.php
common/modules/blog/controllers/PostController.php
+44
-2
common/modules/blog/models/Post.php
common/modules/blog/models/Post.php
+2
-0
common/modules/blog/models/PostTag.php
common/modules/blog/models/PostTag.php
+16
-1
common/modules/blog/views/post/_load.php
common/modules/blog/views/post/_load.php
+50
-0
common/modules/blog/views/post/index.php
common/modules/blog/views/post/index.php
+17
-40
common/modules/blog/views/post/tag.php
common/modules/blog/views/post/tag.php
+14
-37
frontend/web/css/custom.css
frontend/web/css/custom.css
+7
-0
frontend/web/images/post-loader.gif
frontend/web/images/post-loader.gif
+0
-0
frontend/web/js/custom.js
frontend/web/js/custom.js
+36
-0
No files found.
common/modules/blog/controllers/PostController.php
View file @
ce99df5f
...
@@ -5,9 +5,11 @@ namespace common\modules\blog\controllers;
...
@@ -5,9 +5,11 @@ namespace common\modules\blog\controllers;
use
Yii
;
use
Yii
;
use
common\components\BaseController
;
use
common\components\BaseController
;
use
yii\web\NotFoundHttpException
;
use
yii\web\NotFoundHttpException
;
use
yii\web\Response
;
use
common\modules\blog\models\Post
;
use
common\modules\blog\models\Post
;
use
common\modules\blog\models\PostTag
;
use
common\modules\blog\models\PostTag
;
use
common\modules\blog\models\PostTagAssign
;
/**
/**
* PostController implements the CRUD actions for Post model.
* PostController implements the CRUD actions for Post model.
...
@@ -18,6 +20,7 @@ class PostController extends BaseController
...
@@ -18,6 +20,7 @@ class PostController extends BaseController
{
{
return
[
return
[
'Index'
=>
'Блог'
,
'Index'
=>
'Блог'
,
'Load'
=>
'Подгрузка записей'
,
'Tag'
=>
'Просмотр тега'
,
'Tag'
=>
'Просмотр тега'
,
'View'
=>
'Просмотр записи'
,
'View'
=>
'Просмотр записи'
,
];
];
...
@@ -31,13 +34,51 @@ class PostController extends BaseController
...
@@ -31,13 +34,51 @@ class PostController extends BaseController
{
{
$this
->
meta_title
=
Yii
::
t
(
'menu'
,
'Blog'
)
.
' - '
.
\Yii
::
$app
->
params
[
'name'
];
$this
->
meta_title
=
Yii
::
t
(
'menu'
,
'Blog'
)
.
' - '
.
\Yii
::
$app
->
params
[
'name'
];
$
models
=
Post
::
find
()
->
where
([
'active'
=>
1
])
->
all
(
);
$
query
=
Post
::
find
()
->
where
([
'active'
=>
1
])
->
limit
(
Post
::
PAGE_SIZE
)
->
orderBy
(
'created_at DESC'
);
return
$this
->
render
(
'index'
,
[
return
$this
->
render
(
'index'
,
[
'models'
=>
$models
,
'models'
=>
$query
->
all
(),
'count'
=>
$query
->
count
(),
]);
]);
}
}
/**
* Displays all Post models.
* @return mixed
*/
public
function
actionLoad
()
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
$offset
=
Yii
::
$app
->
request
->
post
(
'offset'
);
$tag
=
Yii
::
$app
->
request
->
post
(
'tag'
);
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$query
=
Post
::
find
()
->
where
([
'active'
=>
1
])
->
orderBy
(
Post
::
tableName
()
.
'.created_at DESC'
);
if
(
$tag
)
{
$query
=
$query
->
joinWith
(
'postTagAssigns'
)
->
andWhere
([
PostTagAssign
::
tableName
()
.
'.tag_id'
=>
$tag
]);
}
$models
=
$query
->
limit
(
Post
::
PAGE_SIZE
)
->
offset
(
$offset
)
->
all
();
$count
=
$query
->
count
();
return
[
'posts'
=>
$this
->
renderPartial
(
'_load'
,
[
'models'
=>
$models
,
]),
'count'
=>
(
int
)
$count
,
'offset'
=>
$offset
+
Post
::
PAGE_SIZE
];
}
else
{
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
}
}
/**
/**
* Displays a single Post model.
* Displays a single Post model.
* @param string $url
* @param string $url
...
@@ -56,6 +97,7 @@ class PostController extends BaseController
...
@@ -56,6 +97,7 @@ class PostController extends BaseController
return
$this
->
render
(
'tag'
,
[
return
$this
->
render
(
'tag'
,
[
'model'
=>
$model
,
'model'
=>
$model
,
'count'
=>
$model
->
getAllPosts
()
->
count
()
]);
]);
}
}
...
...
common/modules/blog/models/Post.php
View file @
ce99df5f
...
@@ -28,6 +28,8 @@ class Post extends \common\components\ActiveRecordModel
...
@@ -28,6 +28,8 @@ class Post extends \common\components\ActiveRecordModel
const
ACTIVE_FALSE
=
0
;
const
ACTIVE_FALSE
=
0
;
const
ACTIVE_TRUE
=
1
;
const
ACTIVE_TRUE
=
1
;
const
PAGE_SIZE
=
2
;
public
static
$active_title
=
[
public
static
$active_title
=
[
self
::
ACTIVE_FALSE
=>
'Скрыта'
,
self
::
ACTIVE_FALSE
=>
'Скрыта'
,
self
::
ACTIVE_TRUE
=>
'Доступна'
,
self
::
ACTIVE_TRUE
=>
'Доступна'
,
...
...
common/modules/blog/models/PostTag.php
View file @
ce99df5f
...
@@ -65,7 +65,22 @@ class PostTag extends \common\components\ActiveRecordModel
...
@@ -65,7 +65,22 @@ class PostTag extends \common\components\ActiveRecordModel
*/
*/
public
function
getPosts
()
public
function
getPosts
()
{
{
return
$this
->
hasMany
(
Post
::
className
(),
[
'id'
=>
'post_id'
])
->
viaTable
(
'posts_tags_assign'
,
[
'tag_id'
=>
'id'
])
->
where
([
'active'
=>
1
]);
return
$this
->
hasMany
(
Post
::
className
(),
[
'id'
=>
'post_id'
])
->
viaTable
(
'posts_tags_assign'
,
[
'tag_id'
=>
'id'
])
->
where
([
'active'
=>
1
])
->
orderBy
(
Post
::
tableName
()
.
'.created_at DESC'
)
->
limit
(
Post
::
PAGE_SIZE
);
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getAllPosts
()
{
return
$this
->
hasMany
(
Post
::
className
(),
[
'id'
=>
'post_id'
])
->
viaTable
(
'posts_tags_assign'
,
[
'tag_id'
=>
'id'
])
->
where
([
'active'
=>
1
])
->
orderBy
(
Post
::
tableName
()
.
'.created_at DESC'
);
}
}
/**
/**
...
...
common/modules/blog/views/post/_load.php
0 → 100644
View file @
ce99df5f
<?php
use
yii\helpers\Html
;
use
yii\helpers\Url
;
/* @var $this yii\web\View */
/* @var $model common\modules\blog\models\Post */
?>
<?php
foreach
(
$models
as
$model
)
:
?>
<article
class=
"article_short"
>
<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
<div class="blog_toltip_left">Количество просмотров</div>
</span> -->
<!-- <ul class="article_short_social">
<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_fb.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_tw.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_gp.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_t.png" height="30" width="30" alt=""></a>
</li>
</ul> -->
</div>
<div
class=
"article_short_tags"
>
<?php
foreach
(
$model
->
postTags
as
$tag
)
:
?>
<a
href=
"
<?=
$tag
->
url
;
?>
"
>
#
<?=
$tag
->
name
?>
</a>
<?php
endforeach
;
?>
</div>
<div
class=
"article_short_txt"
>
<?php
if
(
$model
->
preview
)
:
echo
Html
::
img
(
$model
->
preview
);
endif
;
?>
<?=
$model
->
lang
->
text
?>
</div>
</article>
<?php
endforeach
;
?>
\ No newline at end of file
common/modules/blog/views/post/index.php
View file @
ce99df5f
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\helpers\Url
;
use
yii\helpers\Url
;
use
common\modules\blog\models\Post
;
/* @var $this yii\web\View */
/* @var $this yii\web\View */
/* @var $model common\modules\blog\models\Post */
/* @var $model common\modules\blog\models\Post */
...
@@ -16,46 +18,21 @@ use yii\helpers\Url;
...
@@ -16,46 +18,21 @@ use yii\helpers\Url;
<h1>
<?=
Yii
::
t
(
'menu'
,
'Blog'
)
?>
</h1>
<h1>
<?=
Yii
::
t
(
'menu'
,
'Blog'
)
?>
</h1>
<?php
foreach
(
$models
as
$model
)
:
?>
<?=
$this
->
render
(
'_load'
,
[
'models'
=>
$models
])
?>
<article
class=
"article_short"
>
<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
<div class="blog_toltip_left">Количество просмотров</div>
</span> -->
<!-- <ul class="article_short_social">
<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_fb.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_tw.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_gp.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_t.png" height="30" width="30" alt=""></a>
</li>
</ul> -->
</div>
<div
class=
"article_short_tags"
>
<?php
foreach
(
$model
->
postTags
as
$tag
)
:
?>
<a
href=
"
<?=
$tag
->
url
;
?>
"
>
#
<?=
$tag
->
name
?>
</a
>
<?php
if
(
$count
>
count
(
$models
))
:
?
>
<?php
endforeach
;
?
>
<div
class=
"loaded"
>
</div>
</div>
<div
class=
"article_short_txt"
>
<div
class=
"load-box"
>
<a
href=
"#"
class=
"sidebar_btn"
id=
"load-post"
data-offset=
"
<?=
Post
::
PAGE_SIZE
?>
"
style=
"display:block; margin: 0 auto;"
>
Загрузить еще
</a>
<?php
if
(
$model
->
preview
)
:
<div
class=
"loading-post"
></div>
echo
Html
::
img
(
$model
->
preview
);
endif
;
?>
<?=
$model
->
lang
->
text
?>
</div>
</div>
</article>
<?php
endforeach
;
?>
<br><br><br>
<?php
endif
;
?>
<?=
$this
->
render
(
'_subscribe'
,
[
'title'
=>
'Страница Блог'
])
?>
<?=
$this
->
render
(
'_subscribe'
,
[
'title'
=>
'Страница Блог'
])
?>
...
...
common/modules/blog/views/post/tag.php
View file @
ce99df5f
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\helpers\Url
;
use
yii\helpers\Url
;
use
common\modules\blog\models\Post
;
/* @var $this yii\web\View */
/* @var $this yii\web\View */
/* @var $model common\modules\blog\models\Post */
/* @var $model common\modules\blog\models\Post */
...
@@ -16,46 +18,21 @@ use yii\helpers\Url;
...
@@ -16,46 +18,21 @@ use yii\helpers\Url;
<h1>
<?=
Yii
::
t
(
'app'
,
'Tag'
)
?>
:
<?=
$model
->
name
;
?>
</h1>
<h1>
<?=
Yii
::
t
(
'app'
,
'Tag'
)
?>
:
<?=
$model
->
name
;
?>
</h1>
<?php
foreach
(
$model
->
posts
as
$post
)
:
?>
<?=
$this
->
render
(
'_load'
,
[
'models'
=>
$model
->
posts
])
?>
<article
class=
"article_short"
>
<a
href=
"
<?=
Url
::
to
([
'/blog/'
.
$post
->
url
])
?>
"
class=
"article_short_title"
>
<?=
$post
->
lang
->
title
?>
</a>
<div
class=
"article_short_head"
>
<span
class=
"article_short_date"
>
<?=
date
(
'd.m.Y'
,
$post
->
created_at
)
?>
</span>
<!-- <span class="article_short_view">
180
<div class="blog_toltip_left">Количество просмотров</div>
</span> -->
<!-- <ul class="article_short_social">
<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_fb.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_tw.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_gp.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_t.png" height="30" width="30" alt=""></a>
</li>
</ul> -->
</div>
<div
class=
"article_short_tags"
>
<?php
foreach
(
$post
->
postTags
as
$tag
)
:
?>
<a
href=
"
<?=
$tag
->
url
;
?>
"
>
#
<?=
$tag
->
name
?>
</a
>
<?php
if
(
$count
>
count
(
$model
->
posts
))
:
?
>
<?php
endforeach
;
?
>
<div
class=
"loaded"
>
</div>
</div>
<div
class=
"article_short_txt"
>
<div
class=
"load-box"
>
<a
href=
"#"
class=
"sidebar_btn"
id=
"load-post"
data-offset=
"
<?=
Post
::
PAGE_SIZE
?>
"
data-tag=
"
<?=
$model
->
id
?>
"
style=
"display:block; margin: 0 auto;"
>
Загрузить еще
</a>
<?php
if
(
$post
->
preview
)
:
<div
class=
"loading-post"
></div>
echo
Html
::
img
(
$post
->
preview
);
endif
;
?>
<?=
$post
->
lang
->
text
?>
</div>
</div>
</article>
<?php
endforeach
;
?>
<br><br><br>
<?php
endif
;
?>
<?=
$this
->
render
(
'_subscribe'
,
[
'title'
=>
'Тег: '
.
$model
->
name
])
?>
<?=
$this
->
render
(
'_subscribe'
,
[
'title'
=>
'Тег: '
.
$model
->
name
])
?>
...
...
frontend/web/css/custom.css
View file @
ce99df5f
...
@@ -174,6 +174,13 @@ a.toggle_bottom:hover .icon-arrowDown2:after, a.toggle_bottom:active .icon-arrow
...
@@ -174,6 +174,13 @@ a.toggle_bottom:hover .icon-arrowDown2:after, a.toggle_bottom:active .icon-arrow
.bx-wrapper
.bx-pager.bx-default-pager
a
.active
{
.bx-wrapper
.bx-pager.bx-default-pager
a
.active
{
background
:
url(../images/elips_active.png)
no-repeat
center
center
;
background
:
url(../images/elips_active.png)
no-repeat
center
center
;
}
}
.loading-post
{
background
:
url(../images/post-loader.gif)
no-repeat
;
width
:
32px
;
height
:
32px
;
margin
:
0
auto
;
display
:
none
;
}
@media
(
min-width
:
970px
)
{
@media
(
min-width
:
970px
)
{
.article_short_txt
img
{
.article_short_txt
img
{
...
...
frontend/web/images/post-loader.gif
0 → 100644
View file @
ce99df5f
3.13 KB
frontend/web/js/custom.js
View file @
ce99df5f
...
@@ -6,6 +6,42 @@ $(document).ready(function() {
...
@@ -6,6 +6,42 @@ $(document).ready(function() {
return
false
;
return
false
;
});
});
$
(
'
a#load-post
'
).
click
(
function
()
{
var
button
=
$
(
this
),
loading
=
$
(
'
.loading-post
'
),
offset
=
button
.
data
(
'
offset
'
),
tag
=
button
.
data
(
'
tag
'
);
button
.
hide
();
loading
.
show
();
$
.
ajax
({
method
:
'
POST
'
,
url
:
"
/blog/post/load
"
,
data
:
{
offset
:
offset
,
tag
:
tag
},
success
:
function
(
response
)
{
$
(
'
.loaded
'
).
append
(
response
.
posts
);
button
.
data
(
'
offset
'
,
response
.
offset
);
if
(
response
.
count
<=
response
.
offset
)
{
button
.
hide
();
}
else
{
button
.
show
();
}
loading
.
hide
();
}
});
return
false
;
});
$
.
ajax
({
$
.
ajax
({
url
:
"
/sessions/default/add
"
url
:
"
/sessions/default/add
"
});
});
...
...
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