Skip to content

Commit

Permalink
Merge pull request #1765 from roadster31/prex-next-fixes
Browse files Browse the repository at this point in the history
Fix for prev/next queries in Category, Content and Folder loops
  • Loading branch information
gillesbourgeat committed Nov 4, 2015
2 parents 69a09ec + 117ff38 commit 8db72ff
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 10 deletions.
41 changes: 41 additions & 0 deletions core/lib/Thelia/Core/Template/Loop/Brand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @method bool getCurrent()
* @method int[] getExclude()
* @method string[] getOrder()
* @method bool getWithPrevNextInfo()
*/
class Brand extends BaseI18nLoop implements PropelSearchLoopInterface, SearchLoopInterface
{
Expand All @@ -58,6 +59,7 @@ protected function getArgDefinitions()
Argument::createBooleanOrBothTypeArgument('visible', 1),
Argument::createAnyTypeArgument('title'),
Argument::createBooleanTypeArgument('current'),
Argument::createBooleanTypeArgument('with_prev_next_info', false),
new Argument(
'order',
new TypeCollection(
Expand Down Expand Up @@ -216,6 +218,45 @@ public function parseResults(LoopResult $loopResult)
->set("VISIBLE", $brand->getVisible())
->set("LOGO_IMAGE_ID", $brand->getLogoImageId() ?: 0)
;

$isBackendContext = $this->getBackendContext();

if ($isBackendContext || $this->getWithPrevNextInfo()) {
// Find previous and next category
$previousQuery = BrandQuery::create()
->filterByPosition($brand->getPosition(), Criteria::LESS_THAN)
;

if (! $isBackendContext) {
$previousQuery->filterByVisible(true);
}

$previous = $previousQuery
->orderByPosition(Criteria::DESC)
->findOne()
;

$nextQuery = BrandQuery::create()
->filterByPosition($brand->getPosition(), Criteria::GREATER_THAN)
;

if (! $isBackendContext) {
$nextQuery->filterByVisible(true);
}

$next = $nextQuery
->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)
;
}

$this->addOutputFields($loopResultRow, $brand);

$loopResult->addRow($loopResultRow);
Expand Down
22 changes: 19 additions & 3 deletions core/lib/Thelia/Core/Template/Loop/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,34 @@ public function parseResults(LoopResult $loopResult)
$loopResultRow->set("PRODUCT_COUNT", $category->countAllProducts());
}

if ($this->getBackendContext() || $this->getWithPrevNextInfo()) {
$isBackendContext = $this->getBackendContext();

if ($isBackendContext || $this->getWithPrevNextInfo()) {
// Find previous and next category
$previous = CategoryQuery::create()
$previousQuery = CategoryQuery::create()
->filterByParent($category->getParent())
->filterByPosition($category->getPosition(), Criteria::LESS_THAN)
;

if (! $isBackendContext) {
$previousQuery->filterByVisible(true);
}

$previous = $previousQuery
->orderByPosition(Criteria::DESC)
->findOne()
;

$next = CategoryQuery::create()
$nextQuery = CategoryQuery::create()
->filterByParent($category->getParent())
->filterByPosition($category->getPosition(), Criteria::GREATER_THAN)
;

if (! $isBackendContext) {
$nextQuery->filterByVisible(true);
}

$next = $nextQuery
->orderByPosition(Criteria::ASC)
->findOne()
;
Expand Down
22 changes: 19 additions & 3 deletions core/lib/Thelia/Core/Template/Loop/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,36 @@ public function parseResults(LoopResult $loopResult)
*/
private function findNextPrev(LoopResultRow $loopResultRow, \Thelia\Model\Content $content, $defaultFolderId)
{
if ($this->getBackendContext() || $this->getWithPrevNextInfo()) {
$isBackendContext = $this->getBackendContext();

if ($isBackendContext || $this->getWithPrevNextInfo()) {
// Find previous and next category
$previous = ContentQuery::create()
$previousQuery = ContentQuery::create()
->joinContentFolder()
->where('ContentFolder.folder_id = ?', $defaultFolderId)
->filterByPosition($content->getPosition(), Criteria::LESS_THAN)
;

if (! $isBackendContext) {
$previousQuery->filterByVisible(true);
}

$previous = $previousQuery
->orderByPosition(Criteria::DESC)
->findOne()
;

$next = ContentQuery::create()
$nextQuery = ContentQuery::create()
->joinContentFolder()
->where('ContentFolder.folder_id = ?', $defaultFolderId)
->filterByPosition($content->getPosition(), Criteria::GREATER_THAN)
;

if (! $isBackendContext) {
$nextQuery->filterByVisible(true);
}

$next = $nextQuery
->orderByPosition(Criteria::ASC)
->findOne()
;
Expand Down
49 changes: 46 additions & 3 deletions core/lib/Thelia/Core/Template/Loop/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @method int[] getExclude()
* @method string getTitle()
* @method string[] getOrder()
* @method bool getWithPrevNextInfo()
*/
class Folder extends BaseI18nLoop implements PropelSearchLoopInterface, SearchLoopInterface
{
Expand Down Expand Up @@ -73,11 +74,12 @@ protected function getArgDefinitions()
'created_reverse',
'updated',
'updated_reverse'
])
])
),
'manual'
),
Argument::createIntListTypeArgument('exclude')
Argument::createIntListTypeArgument('exclude'),
Argument::createBooleanTypeArgument('with_prev_next_info', false)
);
}

Expand Down Expand Up @@ -240,11 +242,52 @@ public function parseResults(LoopResult $loopResult)
->set("VISIBLE", $folder->getVisible() ? "1" : "0")
->set("POSITION", $folder->getPosition())
;

$isBackendContext = $this->getBackendContext();

if ($isBackendContext || $this->getWithPrevNextInfo()) {
// Find previous and next folder
$previousQuery = FolderQuery::create()
->filterByParent($folder->getParent())
->filterByPosition($folder->getPosition(), Criteria::LESS_THAN)
;

if (! $isBackendContext) {
$previousQuery->filterByVisible(true);
}

$previous = $previousQuery
->orderByPosition(Criteria::DESC)
->findOne()
;

$nextQUery = FolderQuery::create()
->filterByParent($folder->getParent())
->filterByPosition($folder->getPosition(), Criteria::GREATER_THAN)
;

if (! $isBackendContext) {
$nextQUery->filterByVisible(true);
}

$next = $nextQUery
->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)
;
}

$this->addOutputFields($loopResultRow, $folder);

$loopResult->addRow($loopResultRow);
}

return $loopResult;
}
}
}
18 changes: 18 additions & 0 deletions templates/backOffice/default/brand-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
<div class="col-md-7 title">
{intl l='Edit brand %title' title={$TITLE}}
</div>

<div class="col-md-5 actions">

{if $HAS_PREVIOUS != 0}
<a href="{url path="/admin/brand/update/%previous" previous=$PREVIOUS}" class="btn btn-default" title="{intl l='Edit previous brand'}"><span class="glyphicon glyphicon-arrow-left"></span></a>
{else}
<a href="#" disabled="disabled" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span></a>
{/if}

<a href="{$URL nofilter}" target="_blank" class="btn btn-default" title="{intl l='Preview brand page'}"><span class="glyphicon glyphicon-eye-open"></span></a>

{if $HAS_NEXT != 0}
<a href="{url path="/admin/brand/update/%next" next=$NEXT}" class="btn btn-default" title="{intl l='Edit next brand'}"><span class="glyphicon glyphicon-arrow-right"></span></a>
{else}
<a href="#" disabled="disabled" class="btn btn-default"><span class="glyphicon glyphicon-arrow-right"></span></a>
{/if}
</div>

</div>

<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion templates/backOffice/default/content-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<a href="#" disabled="disabled" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span></a>
{/if}

<a href="{$URL nofilter}" target="_blank" class="btn btn-default" title="{intl l='Preview folder page'}"><span class="glyphicon glyphicon-eye-open"></span></a>
<a href="{$URL nofilter}" target="_blank" class="btn btn-default" title="{intl l='Preview content page'}"><span class="glyphicon glyphicon-eye-open"></span></a>

{if $HAS_NEXT != 0}
<a href="{url path="/admin/content/update/%next" next=$NEXT}" class="btn btn-default" title="{intl l='Edit next content'}"><span class="glyphicon glyphicon-arrow-right"></span></a>
Expand Down

0 comments on commit 8db72ff

Please sign in to comment.