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
5f012166
Commit
5f012166
authored
Jun 22, 2016
by
andre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
аякс фильты в блоге
parent
4df28556
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
18 deletions
+91
-18
common/modules/blog/assets/GeneratorAsset.php
common/modules/blog/assets/GeneratorAsset.php
+1
-1
common/modules/blog/assets/src/js/generator.js
common/modules/blog/assets/src/js/generator.js
+23
-1
common/modules/blog/controllers/PostController.php
common/modules/blog/controllers/PostController.php
+62
-12
common/modules/blog/views/post/_sidebar.php
common/modules/blog/views/post/_sidebar.php
+4
-3
common/modules/blog/views/post/index.php
common/modules/blog/views/post/index.php
+1
-1
No files found.
common/modules/blog/assets/GeneratorAsset.php
View file @
5f012166
...
@@ -19,7 +19,7 @@ class GeneratorAsset extends AssetBundle
...
@@ -19,7 +19,7 @@ class GeneratorAsset extends AssetBundle
'css/style_add_22.05.16.css'
,
'css/style_add_22.05.16.css'
,
];
];
public
$js
=
[
public
$js
=
[
//
'js/generator.js',
'js/generator.js'
,
];
];
public
$depends
=
[
public
$depends
=
[
'yii\web\JqueryAsset'
,
'yii\web\JqueryAsset'
,
...
...
common/modules/blog/assets/src/js/generator.js
View file @
5f012166
/**
/**
* Created by andre on 21.06.2016.
* Created by andre on 21.06.2016.
*/
*/
$
(
'
form.bids-form
'
).
on
(
'
click
'
,
function
(
e
)
{
$
(
'
.checkbox_btn
'
).
on
(
'
change
'
,
function
(
e
)
{
var
$this
=
$
(
this
);
var
action
=
$this
.
attr
(
"
action
"
);
$
.
ajax
({
type
:
"
get
"
,
url
:
action
,
success
:
function
(
msg
){
$this
.
prop
(
"
checked
"
,
msg
);
var
action_form
=
$this
.
closest
(
'
form
'
).
attr
(
'
action
'
);
$
.
ajax
({
type
:
"
post
"
,
url
:
action_form
,
success
:
function
(
msg
){
$
(
'
section.blog article
'
).
detach
();
$
(
'
section.blog h1
'
).
after
(
msg
.
posts
);
$
(
'
section.blog .loaded
'
).
html
(
''
);
}
});
}
});
})
})
\ No newline at end of file
common/modules/blog/controllers/PostController.php
View file @
5f012166
...
@@ -27,6 +27,7 @@ class PostController extends BaseController
...
@@ -27,6 +27,7 @@ class PostController extends BaseController
'View'
=>
'Просмотр записи'
,
'View'
=>
'Просмотр записи'
,
'Send-article'
=>
'Послать статью'
,
'Send-article'
=>
'Послать статью'
,
'Set-cookie'
=>
'Установить куки'
,
'Set-cookie'
=>
'Установить куки'
,
'Tag-index'
=>
'Перезагрузка статей с учетом тэгов'
,
];
];
}
}
...
@@ -38,7 +39,14 @@ class PostController extends BaseController
...
@@ -38,7 +39,14 @@ class PostController extends BaseController
{
{
$this
->
meta_title
=
Yii
::
t
(
'blog'
,
'Art Project Blog'
);
$this
->
meta_title
=
Yii
::
t
(
'blog'
,
'Art Project Blog'
);
$query
=
Post
::
find
()
->
where
([
'active'
=>
1
])
->
limit
(
Post
::
PAGE_SIZE
)
->
orderBy
(
'created_at DESC'
);
$tag
=
$this
->
getCookie
();
$query
=
Post
::
find
()
->
where
([
'active'
=>
1
])
->
limit
(
Post
::
PAGE_SIZE
)
->
orderBy
(
Post
::
tableName
()
.
'.created_at DESC'
);
if
(
count
(
$tag
))
{
$query
=
$query
->
joinWith
(
'postTagAssigns'
)
->
andWhere
([
PostTagAssign
::
tableName
()
.
'.tag_id'
=>
$tag
]);
}
return
$this
->
render
(
'index'
,
[
return
$this
->
render
(
'index'
,
[
'models'
=>
$query
->
all
(),
'models'
=>
$query
->
all
(),
...
@@ -85,7 +93,7 @@ class PostController extends BaseController
...
@@ -85,7 +93,7 @@ class PostController extends BaseController
'model'
=>
$model
,
'model'
=>
$model
,
]);
]);
}
}
/**
/**
* @return mixed
* @return mixed
*/
*/
...
@@ -94,13 +102,13 @@ class PostController extends BaseController
...
@@ -94,13 +102,13 @@ class PostController extends BaseController
if
(
Yii
::
$app
->
request
->
isAjax
)
if
(
Yii
::
$app
->
request
->
isAjax
)
{
{
$offset
=
Yii
::
$app
->
request
->
post
(
'offset'
);
$offset
=
Yii
::
$app
->
request
->
post
(
'offset'
);
$tag
=
Yii
::
$app
->
request
->
post
(
'tag'
);
$tag
=
$this
->
getCookie
(
);
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$query
=
Post
::
find
()
->
where
([
'active'
=>
1
])
->
orderBy
(
Post
::
tableName
()
.
'.created_at DESC'
);
$query
=
Post
::
find
()
->
where
([
'active'
=>
1
])
->
orderBy
(
Post
::
tableName
()
.
'.created_at DESC'
);
if
(
$tag
)
if
(
count
(
$tag
)
)
{
{
$query
=
$query
->
joinWith
(
'postTagAssigns'
)
->
andWhere
([
PostTagAssign
::
tableName
()
.
'.tag_id'
=>
$tag
]);
$query
=
$query
->
joinWith
(
'postTagAssigns'
)
->
andWhere
([
PostTagAssign
::
tableName
()
.
'.tag_id'
=>
$tag
]);
}
}
...
@@ -197,22 +205,64 @@ class PostController extends BaseController
...
@@ -197,22 +205,64 @@ class PostController extends BaseController
{
{
$session
=
Yii
::
$app
->
session
;
$session
=
Yii
::
$app
->
session
;
if
(
$session
->
isActive
)
if
(
$session
->
isActive
)
{
{
$cookie
=
$session
->
get
(
'blog_hashtag'
);
$cookie
=
$session
->
get
(
'blog_hashtag'
);
$cookie
=
$cookie
?
$cookie
:
[];
$cookie
=
$cookie
?
$cookie
:
[];
$key
=
array_search
(
$hashtag
,
$cookie
);
$key
=
array_search
(
$hashtag
,
$cookie
);
if
(
$key
!==
false
)
if
(
$key
!==
false
)
{
{
unset
(
$cookie
[
$key
]);
unset
(
$cookie
[
$key
]);
$session
->
set
(
'blog_hashtag'
,
$cookie
);
return
false
;
}
}
else
else
{
{
$cookie
[]
=
$hashtag
;
$cookie
[]
=
$hashtag
;
$session
->
set
(
'blog_hashtag'
,
$cookie
);
return
true
;
}
}
$session
->
set
(
'blog_hashtag'
,
$cookie
);
}
}
return
true
;
}
public
function
getCookie
()
{
$session
=
Yii
::
$app
->
session
;
if
(
$session
->
isActive
)
{
$cookie
=
$session
->
get
(
'blog_hashtag'
);
}
return
empty
(
$cookie
)
?
[]
:
$cookie
;
}
/**
* @param $url
* @return string
* @throws NotFoundHttpException
*
* редерит список статей блога с отбором по хэштегам
*/
public
function
actionTagIndex
()
{
$tag
=
$this
->
getCookie
();
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$query
=
Post
::
find
()
->
where
([
'active'
=>
1
])
->
orderBy
(
Post
::
tableName
()
.
'.created_at DESC'
);
if
(
count
(
$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
,
];
}
}
}
}
common/modules/blog/views/post/_sidebar.php
View file @
5f012166
...
@@ -20,17 +20,18 @@ use common\modules\languages\models\Languages;
...
@@ -20,17 +20,18 @@ use common\modules\languages\models\Languages;
->
currentLang
()
->
currentLang
()
->
orderBy
(
'RAND()'
)
->
orderBy
(
'RAND()'
)
->
limit
(
7
)
->
limit
(
7
)
->
orderBy
(
'name'
)
->
all
();
->
all
();
?>
?>
<?php
if
(
$tags
)
:
?>
<?php
if
(
$tags
)
:
?>
<div
class=
"sidebar_module"
>
<div
class=
"sidebar_module"
>
<h2>
<?=
\Yii
::
t
(
'blog'
,
'Categories'
);
?>
</h2>
<h2>
<?=
\Yii
::
t
(
'blog'
,
'Categories'
);
?>
</h2>
<!-- add 22.05.16 -->
<!-- add 22.05.16 -->
<div
class=
"categories_form"
>
<div
class=
"categories_form"
>
<form>
<form
action=
"/blog/post/tag-index"
>
<?
$cookie
=
\Yii
::
$app
->
controller
->
getCookie
()
?>
<?php
foreach
(
$tags
as
$tag
)
:
?>
<?php
foreach
(
$tags
as
$tag
)
:
?>
<input
action=
"
<?=
\yii\helpers\Url
::
to
([
"/blog/post/set-cookie"
,
"hashtag"
=>
$tag
->
name
])
?>
"
type=
"checkbox"
class=
"checkbox_btn"
id=
"checkbox-
<?=
$tag
->
id
?>
"
>
<input
<?=
in_array
(
$tag
->
id
,
$cookie
)
?
"checked"
:
""
?>
action=
"
<?=
\yii\helpers\Url
::
to
([
"/blog/post/set-cookie"
,
"hashtag"
=>
$tag
->
id
])
?>
"
type=
"checkbox"
class=
"checkbox_btn"
id=
"checkbox-
<?=
$tag
->
id
?>
"
>
<label
for=
"checkbox-
<?=
$tag
->
id
?>
"
>
<?=
$tag
->
name
?>
</label>
<label
for=
"checkbox-
<?=
$tag
->
id
?>
"
>
<?=
$tag
->
name
?>
</label>
<?php
endforeach
;
?>
<?php
endforeach
;
?>
</form>
</form>
...
...
common/modules/blog/views/post/index.php
View file @
5f012166
...
@@ -49,4 +49,4 @@ $this->registerJs("initScrollPager()", yii\web\View::POS_END);
...
@@ -49,4 +49,4 @@ $this->registerJs("initScrollPager()", yii\web\View::POS_END);
<?=
$this
->
render
(
'_modals'
)
?>
<?=
$this
->
render
(
'_modals'
)
?>
<?=
$this
->
render
(
'@app/views/layouts/footer'
);
?>
<?=
$this
->
render
(
'@app/views/layouts/footer'
);
?>
\ 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