178 lines
5.6 KiB
PHP
178 lines
5.6 KiB
PHP
<?php
|
|
/*************************************************************************************/
|
|
/* This file is part of the Thelia package. */
|
|
/* */
|
|
/* Copyright (c) OpenStudio */
|
|
/* email : dev@thelia.net */
|
|
/* web : http://www.thelia.net */
|
|
/* */
|
|
/* For the full copyright and license information, please view the LICENSE.txt */
|
|
/* file that was distributed with this source code. */
|
|
/*************************************************************************************/
|
|
|
|
|
|
namespace Slide\Loop;
|
|
|
|
use Propel\Runtime\ActiveQuery\Criteria;
|
|
use Slide\Model\Map\SlideItemTableMap;
|
|
use Slide\Model\Map\SlideRelTableMap;
|
|
use Slide\Model\SlideRel;
|
|
use Slide\Model\SlideRelQuery;
|
|
use Thelia\Core\Template\Element\BaseLoop;
|
|
use Thelia\Core\Template\Element\LoopResult;
|
|
use Thelia\Core\Template\Element\LoopResultRow;
|
|
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
|
|
use Thelia\Core\Template\Loop\Argument\Argument;
|
|
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
|
use Thelia\Model\Exception\InvalidArgumentException;
|
|
use Thelia\Type\EnumListType;
|
|
use Thelia\Type\TypeCollection;
|
|
|
|
/**
|
|
* Class SlideRelLoop
|
|
* @package Slide\Loop
|
|
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
|
*/
|
|
class SlideRelLoop extends BaseLoop implements PropelSearchLoopInterface
|
|
{
|
|
protected $timestampable = false;
|
|
|
|
protected $versionable = false;
|
|
|
|
/**
|
|
* @param LoopResult $loopResult
|
|
*
|
|
* @return LoopResult
|
|
*/
|
|
public function parseResults(LoopResult $loopResult)
|
|
{
|
|
/** @var SlideRel $slideRel */
|
|
foreach ($loopResult->getResultDataCollection() as $slideRel) {
|
|
|
|
$loopResultRow = new LoopResultRow($slideRel);
|
|
|
|
$loopResultRow
|
|
->set("ID", $slideRel->getId())
|
|
->set("SLIDE_ID", $slideRel->getSlideId())
|
|
->set("REF", $slideRel->getRef())
|
|
->set("REF_ID", $slideRel->getRefId())
|
|
->set("POSITION", $slideRel->getPosition())
|
|
->set("CONTENT", $slideRel->getVirtualColumn("Content"))
|
|
;
|
|
|
|
$this->addOutputFields($loopResultRow, $slideRel);
|
|
|
|
$loopResult->addRow($loopResultRow);
|
|
}
|
|
|
|
return $loopResult;
|
|
}
|
|
|
|
/**
|
|
* this method returns a Propel ModelCriteria
|
|
*
|
|
* @return \Propel\Runtime\ActiveQuery\ModelCriteria
|
|
*/
|
|
public function buildModelCriteria()
|
|
{
|
|
$query = SlideRelQuery::create();
|
|
|
|
$id = $this->getArgValue('id');
|
|
if (null !== $id) {
|
|
$query->filterById($id, Criteria::IN);
|
|
}
|
|
|
|
$slideId = $this->getArgValue('slide_id');
|
|
if (null !== $slideId) {
|
|
$query->filterBySlideId($slideId, Criteria::IN);
|
|
}
|
|
|
|
$ref = $this->getArgValue('ref');
|
|
$refId = $this->getArgValue('ref_id');
|
|
|
|
if (null !== $ref || null !== $refId) {
|
|
if (null === $ref || null === $refId) {
|
|
throw new InvalidArgumentException("ref and ref_id mandatory");
|
|
} else {
|
|
$query
|
|
->filterByRef($ref)
|
|
->filterByRefId($refId);
|
|
}
|
|
}
|
|
|
|
$query
|
|
->join('SlideRel.SlideItem')
|
|
->withColumn('SlideItem.Content', 'Content')
|
|
;
|
|
|
|
$orders = $this->getArgValue('order');
|
|
|
|
foreach ($orders as $order) {
|
|
switch ($order) {
|
|
case "id":
|
|
$query->orderById(Criteria::ASC);
|
|
break;
|
|
case "id_reverse":
|
|
$query->orderById(Criteria::DESC);
|
|
break;
|
|
case "position":
|
|
$query->orderByPosition(Criteria::ASC);
|
|
break;
|
|
case "position_reverse":
|
|
$query->orderByPosition(Criteria::DESC);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
/**
|
|
* Definition of loop arguments
|
|
*
|
|
* example :
|
|
*
|
|
* public function getArgDefinitions()
|
|
* {
|
|
* return new ArgumentCollection(
|
|
*
|
|
* Argument::createIntListTypeArgument('id'),
|
|
* new Argument(
|
|
* 'ref',
|
|
* new TypeCollection(
|
|
* new Type\AlphaNumStringListType()
|
|
* )
|
|
* ),
|
|
* Argument::createIntListTypeArgument('category'),
|
|
* Argument::createBooleanTypeArgument('new'),
|
|
* ...
|
|
* );
|
|
* }
|
|
*
|
|
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
|
|
*/
|
|
protected function getArgDefinitions()
|
|
{
|
|
return new ArgumentCollection(
|
|
Argument::createIntListTypeArgument('id'),
|
|
Argument::createIntListTypeArgument('slide_id'),
|
|
Argument::createAnyTypeArgument('ref'),
|
|
Argument::createIntTypeArgument('ref_id'),
|
|
new Argument(
|
|
'order',
|
|
new TypeCollection(
|
|
new EnumListType(
|
|
[
|
|
'id',
|
|
'id_reverse',
|
|
'position',
|
|
'position_reverse'
|
|
]
|
|
)
|
|
),
|
|
'position'
|
|
)
|
|
);
|
|
}
|
|
}
|