From b15d52e6d3117deeb4b1c101f3c5c9933ba0d3c3 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Apr 2014 10:22:12 +0200 Subject: [PATCH] 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); }