Skip to content

Commit 06b991d

Browse files
author
Bertrand Dunogier
committed
EZP-24264: applied QueryController #2 to blog
1 parent 99dc9ac commit 06b991d

File tree

3 files changed

+86
-19
lines changed

3 files changed

+86
-19
lines changed

QueryType/BlogPostsQueryType.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* @license For full copyright and license information view LICENSE file distributed with this source code.
4+
*/
5+
namespace EzSystems\DemoBundle\QueryType;
6+
7+
use eZ\Publish\API\Repository\Values\Content\Query;
8+
use eZ\Publish\Core\QueryType\OptionsResolverBasedQueryType;
9+
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
10+
use eZ\Publish\Core\QueryType\QueryType;
11+
use Symfony\Component\OptionsResolver\OptionsResolver;
12+
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
13+
14+
/**
15+
* A QueryType that lists the blog_post within a blog_post Location.
16+
*/
17+
class BlogPostsQueryType extends OptionsResolverBasedQueryType implements QueryType
18+
{
19+
/**
20+
* @var array
21+
*/
22+
private $languages;
23+
24+
/**
25+
* @param array $languages List of languages blog posts must be searched in.
26+
*/
27+
public function __construct(array $languages = [])
28+
{
29+
$this->languages = $languages;
30+
}
31+
32+
public static function getName()
33+
{
34+
return 'DemoBundle:BlogPosts';
35+
}
36+
37+
protected function configureOptions(OptionsResolver $optionsResolver)
38+
{
39+
$optionsResolver->setRequired('blogPathString');
40+
}
41+
42+
protected function doGetQuery(array $parameters)
43+
{
44+
$languages = ['eng-GB'];
45+
46+
$criteria = [];
47+
$criteria[] = new Criterion\Subtree($parameters['blogPathString']);
48+
$criteria[] = new Criterion\ContentTypeIdentifier(array('blog_post'));
49+
$criteria[] = new Criterion\LanguageCode($languages);
50+
51+
$query = new Query();
52+
$query->query = new Criterion\LogicalAnd($criteria);
53+
$query->sortClauses = array(
54+
new SortClause\Field('blog_post', 'publication_date', Query::SORT_DESC, $languages[0]),
55+
);
56+
57+
return $query;
58+
}
59+
}

Resources/config/ezdemo.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ system:
2323
template: "eZDemoBundle:full:article.html.twig"
2424
match:
2525
Identifier\ContentType: [article]
26-
# There are two ways to add extra information to your response using a custom controller
27-
blog:
28-
# Fully customized, handling everything yourself
29-
controller: "eZDemoBundle:Demo:listBlogPosts"
30-
match:
31-
Identifier\ContentType: [blog]
3226
blog_post:
3327
# Enriched controller, only adding extra parameters
3428
controller: "eZDemoBundle:Demo:showBlogPost"
@@ -80,11 +74,6 @@ system:
8074
template: "eZDemoBundle:line:article.html.twig"
8175
match:
8276
Identifier\ContentType: [article]
83-
blog_post:
84-
controller: "eZDemoBundle:Demo:showBlogPost"
85-
template: "eZDemoBundle:line:blog_post.html.twig"
86-
match:
87-
Identifier\ContentType: [blog_post]
8877
place:
8978
template: "eZDemoBundle:line:place.html.twig"
9079
match:
@@ -107,6 +96,19 @@ system:
10796
Identifier\ContentType: [video]
10897

10998
content_view:
99+
full:
100+
# Fully customized, handling everything yourself
101+
blog:
102+
match:
103+
Identifier\ContentType: [blog]
104+
controller: 'ez_query:contentAction'
105+
template: 'eZDemoBundle:full:blog.html.twig'
106+
params:
107+
query: 'DemoBundle:BlogPosts'
108+
queryParameters:
109+
blogPathString: @=location.pathString
110+
variable: blog_posts_list
111+
enablePager: true
110112
embed:
111113
image:
112114
template: "eZDemoBundle:embed:image.html.twig"
@@ -117,6 +119,12 @@ system:
117119
template: "eZDemoBundle:relation:image.html.twig"
118120
match:
119121
Identifier\ContentType: [image]
122+
line:
123+
blog_post:
124+
controller: "eZDemoBundle:Demo:showBlogPost"
125+
template: "eZDemoBundle:line:blog_post.html.twig"
126+
match:
127+
Identifier\ContentType: [blog_post]
120128

121129
field_templates:
122130
- {template: "eZDemoBundle::content_fields.html.twig", priority: 10}

Resources/views/full/blog.html.twig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
<div class="class-blog">
66
<div class="row">
77
<div class="col-md-8">
8-
{% if pagerBlog|length() > 0 %}
8+
{% if blog_posts_list|length() > 0 %}
99
<section class="content-view-children">
10-
{% for post in pagerBlog %}
10+
{% for post in blog_posts_list.searchHits %}
1111
{# Displaying blog_post elements calling the view line #}
12-
{{ render_esi( controller( 'ez_content:viewLocation', {'locationId': post.contentInfo.mainLocationId, 'viewType': 'line'} ) ) }}
12+
{{ render_esi( controller( 'ez_content:viewLocation', {'locationId': post.valueObject.contentInfo.mainLocationId, 'viewType': 'line'} ) ) }}
1313
{% endfor %}
1414
</section>
1515

1616
{# Pagination is displayed only if needed (number of posts > limit) #}
17-
{% if pagerBlog.haveToPaginate() %}
18-
<div class="pagination-centered">
19-
{{ pagerfanta( pagerBlog, 'twitter_bootstrap_translated', {'routeName': location} ) }}
20-
</div>
21-
{% endif %}
17+
{#{% if blog_posts_list.haveToPaginate() %}#}
18+
{#<div class="pagination-centered">#}
19+
{#{{ pagerfanta( blog_posts_list, 'twitter_bootstrap_translated', {'routeName': location} ) }}#}
20+
{#</div>#}
21+
{#{% endif %}#}
2222

2323
{% endif %}
2424
</div>

0 commit comments

Comments
 (0)