Skip to content

Commit

Permalink
Added source support to blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagocamposviana committed Dec 22, 2013
1 parent 6cda558 commit 4a04522
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 19 deletions.
36 changes: 20 additions & 16 deletions Classes/Components/Blocks.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

/**
* File containing the Blocks Component class
*
* @author Thiago Campos Viana <[email protected]>
*/

namespace Tutei\BaseBundle\Classes\Components;

use eZ\Publish\API\Repository\Values\Content\Query;
Expand Down Expand Up @@ -38,7 +40,7 @@ public function render()
$query->criterion = new LogicalAnd(
array(
new ContentTypeIdentifier(array('block')),
new ParentLocationId(array($locationId))
new ParentLocationId($locationId)
)
);

Expand All @@ -55,26 +57,28 @@ public function render()
$blocks = array();

foreach ($list->searchHits as $block) {

$parentId = $block->valueObject->versionInfo->contentInfo->mainLocationId;
$blocks[$parentId]['content'] = $block;
$query = new Query();

$query->criterion = new LogicalAnd(
array(
new ParentLocationId(array($parentId))
)
);
$query->sortClauses = array(
new LocationPriority(Query::SORT_ASC)
);

$limit = null;
$columns = $block->valueObject->fields['columns'][$this->controller->getLanguage()]->value;
$rows = $block->valueObject->fields['rows'][$this->controller->getLanguage()]->value;
$offset = $block->valueObject->fields['offset'][$this->controller->getLanguage()]->value;
if ($rows > 0) {
$query->limit = $rows * $columns;
$limit = $rows * $columns;
}
$blockLocationId = $block->valueObject->versionInfo->contentInfo->mainLocationId;
$blocks[$blockLocationId]['content'] = $block;

if (!isset($block->valueObject->fields['source'][$this->controller->getLanguage()]->destinationContentId)) {

$blocks[$parentId]['children'] = $searchService->findContent($query);
$blocks[$blockLocationId]['children'] = SearchHelper::fetchChildren($this->controller, $blockLocationId, array(), $limit, $offset);
} else {

$sourceId = $block->valueObject->fields['source'][$this->controller->getLanguage()]->destinationContentId;
$sourceObj = $repository->getContentService()->loadContent($sourceId);
$parentId = $sourceObj->versionInfo->contentInfo->mainLocationId;
$blocks[$blockLocationId]['children'] = SearchHelper::fetchChildren($this->controller, $parentId, array(), $limit, $offset);

}
}

$siteaccess = $this->controller->getContainer()->get('ezpublish.siteaccess')->name;
Expand Down
12 changes: 10 additions & 2 deletions Classes/SearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function getPath($pathString, TuteiController $controller)
return $path;
}

public static function fetchChildren(TuteiController $controller, $locationId, $filters = array())
public static function fetchChildren(TuteiController $controller, $locationId, $filters = array(), $limit = null, $offset = null)
{

$searchService = $controller->getRepository()->getSearchService();
Expand All @@ -128,7 +128,15 @@ public static function fetchChildren(TuteiController $controller, $locationId, $
$query->criterion = new LogicalAnd($filters);

$query->sortClauses = array(self::createSortClause($location));


if($limit !== null){
$query->limit = $limit;
}

if($offset !== null){
$query->offset = $offset;
}

return $searchService->findContent($query);
}

Expand Down
4 changes: 4 additions & 0 deletions Resources/config/ezpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ system:
UrlAlias: "/"

block:
article:
template: "TuteiBaseBundle:content/article:block.html.twig"
match:
Identifier\ContentType: [article]

default:
template: "TuteiBaseBundle:content/default:block.html.twig"
Expand Down
55 changes: 55 additions & 0 deletions Resources/views/content/article/block.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% set language = (siteaccess[ezpublish.siteaccess.name].language) %}

<div class="content-view-line">
<div class="content-type-article media">


<div class="attribute-title media-heading">
<h2>
<a href="{{ path( location ) }}" title="{{ location.contentInfo.name }}">{{ ez_render_field( content, 'title', { lang: language } ) }}</a>
</h2>
</div>

{% if not ez_is_field_empty( content, 'image', { lang: language } ) %}

<div class="attribute-image pull-left">
<a href="{{ path( location ) }}" title="{{ location.contentInfo.name }}">

{{ render_hinclude(
controller(
"ez_content:viewContent",
{
"contentId": content.fields.image[language].destinationContentId,
"viewType": "line",
"params": { 'alias' : 'small' }
}
)
) }}</a>
</div>

{% endif %}

<div class="attribute-byline">
<span class="date">
<small>{{ location.contentInfo.publishedDate|localizeddate( 'short', 'short', app.request.locale ) }}</small>
</span>
{% if not ez_is_field_empty( content, 'author' ) %}
<span class="author"><small>
{{ ez_render_field(
content,
'author',
{
'template': 'eZDemoBundle:fields:ezauthor_simple.html.twig'
}
) }}</small>
</span>
{% endif %}
</div>

{% if not ez_is_field_empty( content, 'intro', { lang: language } ) %}
<div class="attribute-short media-body">
{{ ez_render_field( content, 'intro', { lang: language } ) }}
</div>
{% endif %}
</div>
</div>
6 changes: 5 additions & 1 deletion Resources/views/content/default/block.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
{% set name = location.contentInfo.name %}
{% endif %}

{% set newWindow = content.fields.new_window[language].bool %}
{% set newWindow = false %}

{% if not ez_is_field_empty( content, "new_window" ) %}
{% set newWindow = content.fields.new_window[language].bool %}
{% endif %}

{% set link = '' %}

Expand Down

0 comments on commit 4a04522

Please sign in to comment.