Skip to content

Commit

Permalink
EZP-24264: applied QueryController #2 to blog
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Dunogier committed Oct 17, 2015
1 parent 99dc9ac commit 06b991d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 19 deletions.
59 changes: 59 additions & 0 deletions QueryType/BlogPostsQueryType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\DemoBundle\QueryType;

use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\Core\QueryType\OptionsResolverBasedQueryType;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\Core\QueryType\QueryType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;

/**
* A QueryType that lists the blog_post within a blog_post Location.
*/
class BlogPostsQueryType extends OptionsResolverBasedQueryType implements QueryType
{
/**
* @var array
*/
private $languages;

/**
* @param array $languages List of languages blog posts must be searched in.
*/
public function __construct(array $languages = [])
{
$this->languages = $languages;
}

public static function getName()
{
return 'DemoBundle:BlogPosts';
}

protected function configureOptions(OptionsResolver $optionsResolver)
{
$optionsResolver->setRequired('blogPathString');
}

protected function doGetQuery(array $parameters)
{
$languages = ['eng-GB'];

$criteria = [];
$criteria[] = new Criterion\Subtree($parameters['blogPathString']);
$criteria[] = new Criterion\ContentTypeIdentifier(array('blog_post'));
$criteria[] = new Criterion\LanguageCode($languages);

$query = new Query();
$query->query = new Criterion\LogicalAnd($criteria);
$query->sortClauses = array(
new SortClause\Field('blog_post', 'publication_date', Query::SORT_DESC, $languages[0]),
);

return $query;
}
}
30 changes: 19 additions & 11 deletions Resources/config/ezdemo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ system:
template: "eZDemoBundle:full:article.html.twig"
match:
Identifier\ContentType: [article]
# There are two ways to add extra information to your response using a custom controller
blog:
# Fully customized, handling everything yourself
controller: "eZDemoBundle:Demo:listBlogPosts"
match:
Identifier\ContentType: [blog]
blog_post:
# Enriched controller, only adding extra parameters
controller: "eZDemoBundle:Demo:showBlogPost"
Expand Down Expand Up @@ -80,11 +74,6 @@ system:
template: "eZDemoBundle:line:article.html.twig"
match:
Identifier\ContentType: [article]
blog_post:
controller: "eZDemoBundle:Demo:showBlogPost"
template: "eZDemoBundle:line:blog_post.html.twig"
match:
Identifier\ContentType: [blog_post]
place:
template: "eZDemoBundle:line:place.html.twig"
match:
Expand All @@ -107,6 +96,19 @@ system:
Identifier\ContentType: [video]

content_view:
full:
# Fully customized, handling everything yourself
blog:
match:
Identifier\ContentType: [blog]
controller: 'ez_query:contentAction'
template: 'eZDemoBundle:full:blog.html.twig'
params:
query: 'DemoBundle:BlogPosts'
queryParameters:
blogPathString: @=location.pathString
variable: blog_posts_list
enablePager: true
embed:
image:
template: "eZDemoBundle:embed:image.html.twig"
Expand All @@ -117,6 +119,12 @@ system:
template: "eZDemoBundle:relation:image.html.twig"
match:
Identifier\ContentType: [image]
line:
blog_post:
controller: "eZDemoBundle:Demo:showBlogPost"
template: "eZDemoBundle:line:blog_post.html.twig"
match:
Identifier\ContentType: [blog_post]

field_templates:
- {template: "eZDemoBundle::content_fields.html.twig", priority: 10}
16 changes: 8 additions & 8 deletions Resources/views/full/blog.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
<div class="class-blog">
<div class="row">
<div class="col-md-8">
{% if pagerBlog|length() > 0 %}
{% if blog_posts_list|length() > 0 %}
<section class="content-view-children">
{% for post in pagerBlog %}
{% for post in blog_posts_list.searchHits %}
{# Displaying blog_post elements calling the view line #}
{{ render_esi( controller( 'ez_content:viewLocation', {'locationId': post.contentInfo.mainLocationId, 'viewType': 'line'} ) ) }}
{{ render_esi( controller( 'ez_content:viewLocation', {'locationId': post.valueObject.contentInfo.mainLocationId, 'viewType': 'line'} ) ) }}
{% endfor %}
</section>

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

{% endif %}
</div>
Expand Down

0 comments on commit 06b991d

Please sign in to comment.