diff --git a/core/lib/Thelia/Core/Template/Loop/Content.php b/core/lib/Thelia/Core/Template/Loop/Content.php index 8185929eb..1d112df25 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'), @@ -201,9 +202,10 @@ 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); - + $defaultFolderId = $content->getDefaultFolderId(); $loopResultRow->set("ID" , $content->getId()) ->set("IS_TRANSLATED" , $content->getVirtualColumn('IS_TRANSLATED')) ->set("LOCALE" , $this->locale) @@ -216,16 +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()) ; - $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; + } + } 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()