Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ before_script:
# Checkout meta repo, change the branch and/or remote to use a different ezpublish branch/distro
- git clone --depth 1 --single-branch --branch master https://github.com/ezsystems/ezplatform.git
- cd ezplatform
- composer require "ezsystems/ezpublish-kernel:dev-ezp24624-query_controller_take2 as 6.0.x-dev"

# Install everything needed for behat testing, using our local branch of this repo
- ./bin/.travis/setup_from_external_repo.sh $BRANCH_BUILD_DIR "ezsystems/demobundle:dev-tmp_travis_branch"
Expand Down
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