Merge pull request #364 from lunika/content
create prev next arg for content loop. Fix #361
This commit is contained in:
@@ -53,6 +53,7 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface
|
|||||||
Argument::createIntListTypeArgument('folder_default'),
|
Argument::createIntListTypeArgument('folder_default'),
|
||||||
Argument::createBooleanTypeArgument('current'),
|
Argument::createBooleanTypeArgument('current'),
|
||||||
Argument::createBooleanTypeArgument('current_folder'),
|
Argument::createBooleanTypeArgument('current_folder'),
|
||||||
|
Argument::createBooleanTypeArgument('with_prev_next_info', false),
|
||||||
Argument::createIntTypeArgument('depth', 1),
|
Argument::createIntTypeArgument('depth', 1),
|
||||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||||
Argument::createAnyTypeArgument('title'),
|
Argument::createAnyTypeArgument('title'),
|
||||||
@@ -201,9 +202,10 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface
|
|||||||
|
|
||||||
public function parseResults(LoopResult $loopResult)
|
public function parseResults(LoopResult $loopResult)
|
||||||
{
|
{
|
||||||
|
/** @var \Thelia\Model\Content $content */
|
||||||
foreach ($loopResult->getResultDataCollection() as $content) {
|
foreach ($loopResult->getResultDataCollection() as $content) {
|
||||||
$loopResultRow = new LoopResultRow($content);
|
$loopResultRow = new LoopResultRow($content);
|
||||||
|
$defaultFolderId = $content->getDefaultFolderId();
|
||||||
$loopResultRow->set("ID" , $content->getId())
|
$loopResultRow->set("ID" , $content->getId())
|
||||||
->set("IS_TRANSLATED" , $content->getVirtualColumn('IS_TRANSLATED'))
|
->set("IS_TRANSLATED" , $content->getVirtualColumn('IS_TRANSLATED'))
|
||||||
->set("LOCALE" , $this->locale)
|
->set("LOCALE" , $this->locale)
|
||||||
@@ -216,16 +218,57 @@ class Content extends BaseI18nLoop implements PropelSearchLoopInterface
|
|||||||
->set("META_DESCRIPTION" , $content->getVirtualColumn('i18n_META_DESCRIPTION'))
|
->set("META_DESCRIPTION" , $content->getVirtualColumn('i18n_META_DESCRIPTION'))
|
||||||
->set("META_KEYWORDS" , $content->getVirtualColumn('i18n_META_KEYWORDS'))
|
->set("META_KEYWORDS" , $content->getVirtualColumn('i18n_META_KEYWORDS'))
|
||||||
->set("POSITION" , $content->getPosition())
|
->set("POSITION" , $content->getPosition())
|
||||||
->set("DEFAULT_FOLDER" , $content->getDefaultFolderId())
|
->set("DEFAULT_FOLDER" , $defaultFolderId)
|
||||||
|
|
||||||
->set("VISIBLE" , $content->getVisible())
|
->set("VISIBLE" , $content->getVisible())
|
||||||
;
|
;
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
|
||||||
|
|
||||||
|
|
||||||
|
$loopResult->addRow($this->findNextPrev($loopResultRow, $content, $defaultFolderId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loopResult;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Thelia\Model;
|
namespace Thelia\Model;
|
||||||
|
|
||||||
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\Propel;
|
use Propel\Runtime\Propel;
|
||||||
use Thelia\Core\Event\Content\ContentEvent;
|
use Thelia\Core\Event\Content\ContentEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
@@ -32,8 +33,14 @@ class Content extends BaseContent
|
|||||||
*/
|
*/
|
||||||
protected function addCriteriaToPositionQuery($query)
|
protected function addCriteriaToPositionQuery($query)
|
||||||
{
|
{
|
||||||
// TODO: Find the default folder for this content,
|
$contents = ContentFolderQuery::create()
|
||||||
// and generate the position relative to this folder
|
->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()
|
public function getDefaultFolderId()
|
||||||
|
|||||||
Reference in New Issue
Block a user