From 4a0452202ca44416ea84c99e3c18c5bcef403b5f Mon Sep 17 00:00:00 2001 From: Thiago Campos Viana Date: Sun, 22 Dec 2013 16:25:31 -0200 Subject: [PATCH] Added source support to blocks --- Classes/Components/Blocks.php | 36 ++++++------ Classes/SearchHelper.php | 12 +++- Resources/config/ezpublish.yml | 4 ++ .../views/content/article/block.html.twig | 55 +++++++++++++++++++ .../views/content/default/block.html.twig | 6 +- 5 files changed, 94 insertions(+), 19 deletions(-) create mode 100644 Resources/views/content/article/block.html.twig diff --git a/Classes/Components/Blocks.php b/Classes/Components/Blocks.php index 0f7dff8..ced64a1 100644 --- a/Classes/Components/Blocks.php +++ b/Classes/Components/Blocks.php @@ -1,9 +1,11 @@ */ + namespace Tutei\BaseBundle\Classes\Components; use eZ\Publish\API\Repository\Values\Content\Query; @@ -38,7 +40,7 @@ public function render() $query->criterion = new LogicalAnd( array( new ContentTypeIdentifier(array('block')), - new ParentLocationId(array($locationId)) + new ParentLocationId($locationId) ) ); @@ -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; diff --git a/Classes/SearchHelper.php b/Classes/SearchHelper.php index ea6443e..fdfc3a2 100644 --- a/Classes/SearchHelper.php +++ b/Classes/SearchHelper.php @@ -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(); @@ -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); } diff --git a/Resources/config/ezpublish.yml b/Resources/config/ezpublish.yml index 3e0263e..cbbbf71 100644 --- a/Resources/config/ezpublish.yml +++ b/Resources/config/ezpublish.yml @@ -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" diff --git a/Resources/views/content/article/block.html.twig b/Resources/views/content/article/block.html.twig new file mode 100644 index 0000000..4247b76 --- /dev/null +++ b/Resources/views/content/article/block.html.twig @@ -0,0 +1,55 @@ +{% set language = (siteaccess[ezpublish.siteaccess.name].language) %} + +
+
+ + + + + {% if not ez_is_field_empty( content, 'image', { lang: language } ) %} + + + + {% endif %} + + + + {% if not ez_is_field_empty( content, 'intro', { lang: language } ) %} +
+ {{ ez_render_field( content, 'intro', { lang: language } ) }} +
+ {% endif %} +
+
\ No newline at end of file diff --git a/Resources/views/content/default/block.html.twig b/Resources/views/content/default/block.html.twig index 87c0317..6c54f62 100644 --- a/Resources/views/content/default/block.html.twig +++ b/Resources/views/content/default/block.html.twig @@ -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 = '' %}