Merge branch 'loops'

This commit is contained in:
Etienne Roudeix
2013-07-26 16:58:02 +02:00
3 changed files with 373 additions and 264 deletions

View File

@@ -9,6 +9,7 @@
<loop class="Thelia\Core\Template\Loop\Address" name="address"/>
<loop class="Thelia\Core\Template\Loop\Auth" name="auth"/>
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
<loop class="Thelia\Core\Template\Loop\Country" name="country"/>
<loop class="Thelia\Core\Template\Loop\Customer" name="customer"/>
<loop class="Thelia\Core\Template\Loop\Order" name="order"/>
<loop class="Thelia\Core\Template\Loop\OrderStatus" name="order-status"/>

View File

@@ -0,0 +1,108 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\CustomerCountryQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
/**
*
* Country loop
*
*
* Class Country
* @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class Country extends BaseLoop
{
/**
* @return ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id')
);
}
/**
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{
$search = CustomerCountryQuery::create();
$id = $this->getId();
if (null !== $id) {
$search->filterById($id, Criteria::IN);
}
/**
* Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
*
* @todo : verify here if we want results for row without translations.
*/
$search->joinWithI18n(
$this->request->getSession()->getLocale(),
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
);
$search->orderByPosition();
$countrys = $this->search($search, $pagination);
$loopResult = new LoopResult();
foreach ($countrys as $country) {
if ($this->not_empty && $country->countAllProducts() == 0) continue;
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $country->getId());
$loopResultRow->set("DEFAULT", $country->getByDefault());
$loopResultRow->set("SHORT", $country->getShort());
$loopResultRow->set("LONG", $country->getLong());
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}