From b15d52e6d3117deeb4b1c101f3c5c9933ba0d3c3 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Apr 2014 10:22:12 +0200 Subject: [PATCH 1/4] create prev next arg for content loop. Fix #361 --- .../lib/Thelia/Core/Template/Loop/Content.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/lib/Thelia/Core/Template/Loop/Content.php b/core/lib/Thelia/Core/Template/Loop/Content.php index 8185929eb..e567b13ac 100644 --- a/core/lib/Thelia/Core/Template/Loop/Content.php +++ b/core/lib/Thelia/Core/Template/Loop/Content.php @@ -53,6 +53,7 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface Argument::createIntListTypeArgument('folder_default'), Argument::createBooleanTypeArgument('current'), Argument::createBooleanTypeArgument('current_folder'), + Argument::createBooleanTypeArgument('with_prev_next_info', false), Argument::createIntTypeArgument('depth', 1), Argument::createBooleanOrBothTypeArgument('visible', 1), Argument::createAnyTypeArgument('title'), @@ -221,6 +222,29 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface ->set("VISIBLE" , $content->getVisible()) ; + + if ($this->getBackend_context() || $this->getWithPrevNextInfo()) { + // Find previous and next category + $previous = ContentQuery::create() + ->filterByPosition($content->getPosition(), Criteria::LESS_THAN) + ->orderByPosition(Criteria::DESC) + ->findOne() + ; + + $next = ContentQuery::create() + ->filterByPosition($content->getPosition(), Criteria::GREATER_THAN) + ->orderByPosition(Criteria::ASC) + ->findOne() + ; + + $loopResultRow + ->set("HAS_PREVIOUS" , $previous != null ? 1 : 0) + ->set("HAS_NEXT" , $next != null ? 1 : 0) + ->set("PREVIOUS" , $previous != null ? $previous->getId() : -1) + ->set("NEXT" , $next != null ? $next->getId() : -1) + ; + } + $loopResult->addRow($loopResultRow); } From 270b5f64990b00c1e383cdd20f212a9fba42bf06 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Apr 2014 10:32:17 +0200 Subject: [PATCH 2/4] filter with contentFolder table for finding next/prev content --- core/lib/Thelia/Core/Template/Loop/Content.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/lib/Thelia/Core/Template/Loop/Content.php b/core/lib/Thelia/Core/Template/Loop/Content.php index e567b13ac..5cd2ade60 100644 --- a/core/lib/Thelia/Core/Template/Loop/Content.php +++ b/core/lib/Thelia/Core/Template/Loop/Content.php @@ -202,6 +202,7 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface public function parseResults(LoopResult $loopResult) { + /** @var \Thelia\Model\Content $content */ foreach ($loopResult->getResultDataCollection() as $content) { $loopResultRow = new LoopResultRow($content); @@ -224,14 +225,19 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface if ($this->getBackend_context() || $this->getWithPrevNextInfo()) { + $defaultFolderId = $content->getDefaultFolderId(); // Find previous and next category $previous = ContentQuery::create() + ->joinContentFolder() + ->where('ContentFolder.folder_id = ?', $defaultFolderId) ->filterByPosition($content->getPosition(), Criteria::LESS_THAN) ->orderByPosition(Criteria::DESC) ->findOne() ; $next = ContentQuery::create() + ->joinContentFolder() + ->where('ContentFolder.folder_id = ?', $defaultFolderId) ->filterByPosition($content->getPosition(), Criteria::GREATER_THAN) ->orderByPosition(Criteria::ASC) ->findOne() From 0b36b2222dc389bdad67961ab4e14ef299e2c41e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Apr 2014 10:44:34 +0200 Subject: [PATCH 3/4] implement addCriteriaToPositionQuery method in content model. #360 --- core/lib/Thelia/Model/Content.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 983580540..d40ba286a 100644 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -2,6 +2,7 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Propel; use Thelia\Core\Event\Content\ContentEvent; use Thelia\Core\Event\TheliaEvents; @@ -32,8 +33,14 @@ class Content extends BaseContent */ protected function addCriteriaToPositionQuery($query) { - // TODO: Find the default folder for this content, - // and generate the position relative to this folder + $contents = ContentFolderQuery::create() + ->filterByFolderId($this->getDefaultFolderId()) + ->filterByDefaultFolder(true) + ->select('content_id') + ->find(); + + // Filtrer la requete sur ces produits + if ($contents != null) $query->filterById($contents, Criteria::IN); } public function getDefaultFolderId() From 67293555bafa0c4ffa0eb2fa383516941c4d835f Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Apr 2014 10:57:04 +0200 Subject: [PATCH 4/4] refactor content loop splitting parseResults method --- .../lib/Thelia/Core/Template/Loop/Content.php | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Content.php b/core/lib/Thelia/Core/Template/Loop/Content.php index 5cd2ade60..1d112df25 100644 --- a/core/lib/Thelia/Core/Template/Loop/Content.php +++ b/core/lib/Thelia/Core/Template/Loop/Content.php @@ -205,7 +205,7 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface /** @var \Thelia\Model\Content $content */ foreach ($loopResult->getResultDataCollection() as $content) { $loopResultRow = new LoopResultRow($content); - + $defaultFolderId = $content->getDefaultFolderId(); $loopResultRow->set("ID" , $content->getId()) ->set("IS_TRANSLATED" , $content->getVirtualColumn('IS_TRANSLATED')) ->set("LOCALE" , $this->locale) @@ -218,44 +218,57 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface ->set("META_DESCRIPTION" , $content->getVirtualColumn('i18n_META_DESCRIPTION')) ->set("META_KEYWORDS" , $content->getVirtualColumn('i18n_META_KEYWORDS')) ->set("POSITION" , $content->getPosition()) - ->set("DEFAULT_FOLDER" , $content->getDefaultFolderId()) + ->set("DEFAULT_FOLDER" , $defaultFolderId) ->set("VISIBLE" , $content->getVisible()) ; - if ($this->getBackend_context() || $this->getWithPrevNextInfo()) { - $defaultFolderId = $content->getDefaultFolderId(); - // Find previous and next category - $previous = ContentQuery::create() - ->joinContentFolder() - ->where('ContentFolder.folder_id = ?', $defaultFolderId) - ->filterByPosition($content->getPosition(), Criteria::LESS_THAN) - ->orderByPosition(Criteria::DESC) - ->findOne() - ; - $next = ContentQuery::create() - ->joinContentFolder() - ->where('ContentFolder.folder_id = ?', $defaultFolderId) - ->filterByPosition($content->getPosition(), Criteria::GREATER_THAN) - ->orderByPosition(Criteria::ASC) - ->findOne() - ; - $loopResultRow - ->set("HAS_PREVIOUS" , $previous != null ? 1 : 0) - ->set("HAS_NEXT" , $next != null ? 1 : 0) - ->set("PREVIOUS" , $previous != null ? $previous->getId() : -1) - ->set("NEXT" , $next != null ? $next->getId() : -1) - ; - } - - $loopResult->addRow($loopResultRow); + $loopResult->addRow($this->findNextPrev($loopResultRow, $content, $defaultFolderId)); } return $loopResult; } + /** + * @param LoopResultRow $loopResultRow + * @param \Thelia\Model\Content $content + * @param $defaultFolderId + * @return LoopResultRow + */ + private function findNextPrev(LoopResultRow $loopResultRow, \Thelia\Model\Content $content, $defaultFolderId) + { + if ($this->getBackend_context() || $this->getWithPrevNextInfo()) { + + // Find previous and next category + $previous = ContentQuery::create() + ->joinContentFolder() + ->where('ContentFolder.folder_id = ?', $defaultFolderId) + ->filterByPosition($content->getPosition(), Criteria::LESS_THAN) + ->orderByPosition(Criteria::DESC) + ->findOne() + ; + + $next = ContentQuery::create() + ->joinContentFolder() + ->where('ContentFolder.folder_id = ?', $defaultFolderId) + ->filterByPosition($content->getPosition(), Criteria::GREATER_THAN) + ->orderByPosition(Criteria::ASC) + ->findOne() + ; + + $loopResultRow + ->set("HAS_PREVIOUS" , $previous != null ? 1 : 0) + ->set("HAS_NEXT" , $next != null ? 1 : 0) + ->set("PREVIOUS" , $previous != null ? $previous->getId() : -1) + ->set("NEXT" , $next != null ? $next->getId() : -1) + ; + } + + return $loopResultRow; + } + }