Merge branch 'master' into frontend

This commit is contained in:
touffies
2013-11-06 19:01:10 +01:00
101 changed files with 2127 additions and 1249 deletions

View File

@@ -30,6 +30,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Core\Template\TemplateHelper;
/** /**
* *
@@ -55,7 +56,7 @@ class HttpException extends BaseAction implements EventSubscriberInterface
$parser = $this->container->get("thelia.parser"); $parser = $this->container->get("thelia.parser");
// Define the template thant shoud be used // Define the template thant shoud be used
$parser->setTemplate(ConfigQuery::getActiveTemplate()); $parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
//$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView()); //$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView());

View File

@@ -54,6 +54,8 @@ use Thelia\Core\Event\Product\ProductDeleteCategoryEvent;
use Thelia\Core\Event\Product\ProductAddCategoryEvent; use Thelia\Core\Event\Product\ProductAddCategoryEvent;
use Thelia\Core\Event\Product\ProductAddAccessoryEvent; use Thelia\Core\Event\Product\ProductAddAccessoryEvent;
use Thelia\Core\Event\Product\ProductDeleteAccessoryEvent; use Thelia\Core\Event\Product\ProductDeleteAccessoryEvent;
use Thelia\Model\Map\ProductTableMap;
use Propel\Runtime\Propel;
class Product extends BaseAction implements EventSubscriberInterface class Product extends BaseAction implements EventSubscriberInterface
{ {
@@ -257,21 +259,37 @@ class Product extends BaseAction implements EventSubscriberInterface
public function setProductTemplate(ProductSetTemplateEvent $event) public function setProductTemplate(ProductSetTemplateEvent $event)
{ {
$product = $event->getProduct();
// Delete all product feature relations $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
FeatureProductQuery::create()->filterByProduct($product)->delete();
// Delete all product attributes sale elements $con->beginTransaction();
ProductSaleElementsQuery::create()->filterByProduct($product)->delete();
// Update the product template try {
$template_id = $event->getTemplateId();
// Set it to null if it's zero. $product = $event->getProduct();
if ($template_id <= 0) $template_id = NULL;
$product->setTemplateId($template_id)->save(); // Delete all product feature relations
FeatureProductQuery::create()->filterByProduct($product)->delete($con);
// Delete all product attributes sale elements
ProductSaleElementsQuery::create()->filterByProduct($product)->delete($con);
// Update the product template
$template_id = $event->getTemplateId();
// Set it to null if it's zero.
if ($template_id <= 0) $template_id = NULL;
$product->setTemplateId($template_id)->save($con);
// Store all the stuff !
$con->commit();
} catch (\Exception $ex) {
$con->rollback();
throw $ex;
}
} }
/** /**

View File

@@ -42,7 +42,8 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand
'Config', 'Config',
'Model', 'Model',
'Loop', 'Loop',
'AdminIncludes' 'AdminIncludes',
'templates',
); );
protected function verifyExistingModule() protected function verifyExistingModule()

View File

@@ -50,7 +50,6 @@
<argument type="service" id="request" /> <argument type="service" id="request" />
<argument type="service" id="event_dispatcher"/> <argument type="service" id="event_dispatcher"/>
<argument type="service" id="thelia.parser.context"/> <argument type="service" id="thelia.parser.context"/>
<argument >false</argument> <!-- Template name, or false -->
<argument >%kernel.environment%</argument> <argument >%kernel.environment%</argument>
<argument >%kernel.debug%</argument> <argument >%kernel.debug%</argument>
</service> </service>

View File

@@ -49,6 +49,7 @@
<loop class="Thelia\Core\Template\Loop\Message" name="message"/> <loop class="Thelia\Core\Template\Loop\Message" name="message"/>
<loop class="Thelia\Core\Template\Loop\Delivery" name="delivery"/> <loop class="Thelia\Core\Template\Loop\Delivery" name="delivery"/>
<loop class="Thelia\Core\Template\Loop\ProductTemplate" name="product-template"/> <!-- This is product templates ;-) --> <loop class="Thelia\Core\Template\Loop\ProductTemplate" name="product-template"/> <!-- This is product templates ;-) -->
<loop class="Thelia\Core\Template\Loop\Template" name="template"/>
<loop class="Thelia\Core\Template\Loop\Tax" name="tax"/> <loop class="Thelia\Core\Template\Loop\Tax" name="tax"/>
<loop class="Thelia\Core\Template\Loop\TaxRule" name="tax-rule"/> <loop class="Thelia\Core\Template\Loop\TaxRule" name="tax-rule"/>
<loop class="Thelia\Core\Template\Loop\TaxRuleCountry" name="tax-rule-country"/> <loop class="Thelia\Core\Template\Loop\TaxRuleCountry" name="tax-rule-country"/>

View File

@@ -1040,6 +1040,16 @@
<default key="_controller">Thelia\Controller\Admin\LangController::deactivateDomainAction</default> <default key="_controller">Thelia\Controller\Admin\LangController::deactivateDomainAction</default>
</route> </route>
<!-- translations management -->
<route id="admin.configuration.translations" path="/admin/configuration/translations">
<default key="_controller">Thelia\Controller\Admin\TranslationsController::defaultAction</default>
</route>
<route id="admin.configuration.translations.update" path="/admin/configuration/translations/update">
<default key="_controller">Thelia\Controller\Admin\TranslationsController::updateAction</default>
</route>
<!-- The default route, to display a template --> <!-- The default route, to display a template -->
<route id="admin.processTemplate" path="/admin/{template}"> <route id="admin.processTemplate" path="/admin/{template}">

View File

@@ -43,6 +43,7 @@ use Symfony\Component\Routing\Router;
use Thelia\Model\Admin; use Thelia\Model\Admin;
use Thelia\Core\Security\Token\CookieTokenProvider; use Thelia\Core\Security\Token\CookieTokenProvider;
use Thelia\Model\CurrencyQuery; use Thelia\Model\CurrencyQuery;
use Thelia\Core\Template\TemplateHelper;
class BaseAdminController extends BaseController class BaseAdminController extends BaseController
{ {
@@ -198,8 +199,8 @@ class BaseAdminController extends BaseController
{ {
$parser = $this->container->get("thelia.parser"); $parser = $this->container->get("thelia.parser");
// Define the template thant shoud be used // Define the template that should be used
$parser->setTemplate($template ?: ConfigQuery::read('base-admin-template', 'admin/default')); $parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveAdminTemplate()->getPath());
return $parser; return $parser;
} }

View File

@@ -36,6 +36,7 @@ use Thelia\Model\Base\OrderAddressQuery;
use Thelia\Model\OrderQuery; use Thelia\Model\OrderQuery;
use Thelia\Model\OrderStatusQuery; use Thelia\Model\OrderStatusQuery;
use Thelia\Tools\URL; use Thelia\Tools\URL;
use Thelia\Core\Template\TemplateHelper;
/** /**
* Class OrderController * Class OrderController
@@ -218,7 +219,7 @@ class OrderController extends BaseAdminController
array( array(
'order_id' => $order_id 'order_id' => $order_id
), ),
ConfigQuery::read('pdf_template', 'pdf') TemplateHelper::getInstance()->getActivePdfTemplate()->getPath()
); );
$order = OrderQuery::create()->findPk($order_id); $order = OrderQuery::create()->findPk($order_id);

View File

@@ -66,6 +66,7 @@ use Thelia\Model\Product;
use Thelia\Model\CurrencyQuery; use Thelia\Model\CurrencyQuery;
use Thelia\Form\ProductCombinationGenerationForm; use Thelia\Form\ProductCombinationGenerationForm;
use Thelia\Core\Event\Product\ProductCombinationGenerationEvent; use Thelia\Core\Event\Product\ProductCombinationGenerationEvent;
use Thelia\Core\Event\Product\ProductSetTemplateEvent;
/** /**
* Manages products * Manages products

View File

@@ -0,0 +1,214 @@
<?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\Controller\Admin;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Security\AccessManager;
use Thelia\Form\SystemLogConfigurationForm;
use Thelia\Log\Tlog;
use Thelia\Model\ConfigQuery;
use Thelia\Model\ModuleQuery;
use Thelia\Core\Template\TemplateHelper;
use Thelia\Core\Template\TemplateDefinition;
/**
* Class LangController
* @package Thelia\Controller\Admin
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class TranslationsController extends BaseAdminController
{
protected function renderTemplate()
{
// Find modules
$modules = ModuleQuery::create()->joinI18n($this->getCurrentEditionLocale())->orderByPosition()->find();
TemplateHelper::getInstance()->getList(TemplateDefinition::BACK_OFFICE);
TemplateHelper::getInstance()->getList(TemplateDefinition::PDF);
TemplateHelper::getInstance()->getList(TemplateDefinition::FRONT_OFFICE);
// Get related strings, if all input data are here
$item_to_translate = $this->getRequest()->get('item_to_translate');
$item_id = $this->getRequest()->get('item_id', '');
$all_strings = array();
$template = $directory = $i18n_directory = false;
$mode = 'template';
if (! empty($item_id)) {
switch($item_to_translate) {
case 'mo' :
if (null !== $module = ModuleQuery::create()->findPk($item_id)) {
$directory = THELIA_MODULE_DIR . $module->getBaseDir();
$i18n_directory = THELIA_TEMPLATE_DIR . $template->getI18nPath();
$mode = 'php';
}
break;
case 'co' :
$directory = THELIA_ROOT . 'core/lib/Thelia';
$i18n_directory = THELIA_ROOT . 'core/lib/Thelia/Config/I18n';
$mode = 'php';
break;
case 'fo' :
$template = new TemplateDefinition($item_id, TemplateDefinition::FRONT_OFFICE);
break;
case 'bo' :
$template = new TemplateDefinition($item_id, TemplateDefinition::BACK_OFFICE);
break;
case 'pf' :
$template = new TemplateDefinition($item_id, TemplateDefinition::PDF);
break;
}
if ($template) {
$directory = THELIA_TEMPLATE_DIR . $template->getPath();
$i18n_directory = THELIA_TEMPLATE_DIR . $template->getI18nPath();
}
if ($directory) {
// Load strings
$this->walkDir($directory, $mode, $all_strings);
// Load translated strings
if ($i18n_directory) {
$locale = $this->getCurrentEditionLocale();
}
}
}
return $this->render('translations', array(
'item_to_translate' => $item_to_translate,
'item_id' => $item_id,
'all_strings' => $all_strings,
'view_missing_traductions_only' => $this->getRequest()->get('view_missing_traductions_only', 0)
));
}
public function defaultAction()
{
if (null !== $response = $this->checkAuth(AdminResources::TRANSLATIONS, AccessManager::VIEW)) return $response;
return $this->renderTemplate();
}
public function updateAction()
{
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::UPDATE)) return $response;
return $this->renderTemplate();
}
protected function normalize_path($path)
{
$path =
str_replace(
str_replace('\\', '/', THELIA_ROOT),
'',
str_replace('\\', '/', realpath($path))
);
if ($path[0] == '/') $path = substr($path, 1);
return $path;
}
protected function walkDir($directory, $mode, &$strings) {
if ($mode == 'php') {
$prefix = '\-\>[\s]*trans[\s]*\(';
$allowed_exts = array('php');
} else {
$prefix = '\{intl[\s]l=';
$allowed_exts = array('html', 'tpl', 'xml');
}
try {
//echo "walking in $directory<br />";
foreach (new \DirectoryIterator($directory) as $fileInfo) {
if ($fileInfo->isDot()) continue;
if ($fileInfo->isDir()) $this->walkDir($fileInfo->getPathName(), $mode, $strings);
if ($fileInfo->isFile()) {
$ext = $fileInfo->getExtension();
if (in_array($ext, $allowed_exts)) {
if ($content = file_get_contents($fileInfo->getPathName())) {
$short_path = $this->normalize_path($fileInfo->getPathName());
// echo " examining $short_path\n";
$matches = array();
if (preg_match_all('/'.$prefix.'((?<![\\\\])[\'"])((?:.(?!(?<![\\\\])\1))*.?)\1/', $content, $matches)) {
// print_r($matches[2]);
foreach($matches[2] as $match) {
$hash = md5($match);
if (isset($strings[$hash]))
{
if (! in_array($short_path, $strings[$hash]['files']))
{
$strings[$hash]['files'][] = $short_path;
}
}
else
$strings[$hash] = array(
'files' => array($short_path),
'chaine' => $match,
'translation' => $this->getTranslator()->trans($match, array(), 'messages', $this->getCurrentEditionLocale(), false),
'dollar' => strstr($match, '$') !== false
);
}
}
}
}
}
}
} catch (\UnexpectedValueException $ex) {
echo $ex;
}
}
}

View File

@@ -311,6 +311,11 @@ class BaseController extends ContainerAware
} }
/** /**
*
* return an instance of SmartyParser
*
* Caution : maybe there is still not default template defined.
*
* @return ParserInterface instance parser * @return ParserInterface instance parser
*/ */
protected function getParser() protected function getParser()

View File

@@ -25,6 +25,7 @@ namespace Thelia\Controller\Front;
use Symfony\Component\Routing\Router; use Symfony\Component\Routing\Router;
use Thelia\Controller\BaseController; use Thelia\Controller\BaseController;
use Thelia\Model\AddressQuery; use Thelia\Model\AddressQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\ModuleQuery; use Thelia\Model\ModuleQuery;
use Thelia\Tools\URL; use Thelia\Tools\URL;
@@ -83,4 +84,16 @@ class BaseFrontController extends BaseController
$this->redirectToRoute("order.invoice"); $this->redirectToRoute("order.invoice");
} }
} }
/**
* @return ParserInterface instance parser
*/
protected function getParser()
{
$parser = $this->container->get("thelia.parser");
$parser->setTemplate(ConfigQuery::getActiveTemplate());
return $parser;
}
} }

View File

@@ -67,26 +67,26 @@ class RegisterRouterPass implements CompilerPassInterface
$modules = \Thelia\Model\ModuleQuery::getActivated(); $modules = \Thelia\Model\ModuleQuery::getActivated();
foreach ($modules as $module) { foreach ($modules as $module) {
$moduleCode = ucfirst($module->getCode()); $moduleBaseDir = $module->getBaseDir();
if (file_exists(THELIA_MODULE_DIR . "/" . $moduleCode . "/Config/routing.xml")) { if (file_exists(THELIA_MODULE_DIR . "/" . $moduleBaseDir . "/Config/routing.xml")) {
$definition = new Definition( $definition = new Definition(
$container->getParameter("router.class"), $container->getParameter("router.class"),
array( array(
new Reference("router.module.xmlLoader"), new Reference("router.module.xmlLoader"),
ucfirst($module->getCode()) . "/Config/routing.xml", $moduleBaseDir . "/Config/routing.xml",
array( array(
"cache_dir" => $container->getParameter("kernel.cache_dir"), "cache_dir" => $container->getParameter("kernel.cache_dir"),
"debug" => $container->getParameter("kernel.debug"), "debug" => $container->getParameter("kernel.debug"),
"matcher_cache_class" => $container::camelize("ProjectUrlMatcher".$moduleCode), "matcher_cache_class" => $container::camelize("ProjectUrlMatcher".$moduleBaseDir),
"generator_cache_class" => $container::camelize("ProjectUrlGenerator".$moduleCode), "generator_cache_class" => $container::camelize("ProjectUrlGenerator".$moduleBaseDir),
), ),
new Reference("request.context") new Reference("request.context")
) )
); );
$container->setDefinition("router.".$moduleCode, $definition); $container->setDefinition("router.".$moduleBaseDir, $definition);
$chainRouter->addMethodCall("add", array(new Reference("router.".$moduleCode), 150)); $chainRouter->addMethodCall("add", array(new Reference("router.".$moduleBaseDir), 150));
} }
} }
} }

View File

@@ -23,15 +23,19 @@
namespace Thelia\Core\EventListener; namespace Thelia\Core\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Thelia\Core\HttpFoundation\Response; use Thelia\Core\HttpFoundation\Response;
use Symfony\Component\Routing\Router; use Symfony\Component\Routing\Router;
use Thelia\Core\HttpKernel\Exception\NotFountHttpException;
use Thelia\Core\Template\Exception\ResourceNotFoundException; use Thelia\Core\Template\Exception\ResourceNotFoundException;
use Thelia\Core\Template\ParserInterface; use Thelia\Core\Template\ParserInterface;
use Thelia\Core\Template\TemplateHelper;
use Thelia\Exception\OrderException; use Thelia\Exception\OrderException;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\Redirect; use Thelia\Tools\Redirect;
use Thelia\Tools\URL; use Thelia\Tools\URL;
use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Core\Security\Exception\AuthenticationException;
@@ -74,9 +78,11 @@ class ViewListener implements EventSubscriberInterface
{ {
$parser = $this->container->get('thelia.parser'); $parser = $this->container->get('thelia.parser');
$parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
$request = $this->container->get('request');
try { try {
$content = $parser->getContent(); $content = $parser->render($request->attributes->get('_view').".html");
if ($content instanceof Response) { if ($content instanceof Response) {
$response = $content;$event->setResponse($content); $response = $content;$event->setResponse($content);
@@ -94,7 +100,7 @@ class ViewListener implements EventSubscriberInterface
$event->setResponse($response); $event->setResponse($response);
} catch (ResourceNotFoundException $e) { } catch (ResourceNotFoundException $e) {
$event->setResponse(new Response($e->getMessage(), 404)); throw new NotFoundHttpException();
} catch (AuthenticationException $ex) { } catch (AuthenticationException $ex) {
// Redirect to the login template // Redirect to the login template

View File

@@ -99,4 +99,6 @@ final class AdminResources
const TEMPLATE = "admin.configuration.template"; const TEMPLATE = "admin.configuration.template";
const SYSTEM_LOG = "admin.configuration.system-log"; const SYSTEM_LOG = "admin.configuration.system-log";
const TRANSLATIONS = "admin.configuration.translations";
} }

View File

@@ -0,0 +1,38 @@
<?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\Element;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
interface ArraySearchLoopInterface
{
/**
* this method returns an array
*
* @return array
*/
public function buildArray();
}

View File

@@ -36,6 +36,8 @@ use Thelia\Model\Tools\ModelCriteriaTools;
*/ */
abstract class BaseI18nLoop extends BaseLoop abstract class BaseI18nLoop extends BaseLoop
{ {
protected $locale;
/** /**
* Define common loop arguments * Define common loop arguments
* *
@@ -65,9 +67,7 @@ abstract class BaseI18nLoop extends BaseLoop
{ {
/* manage translations */ /* manage translations */
$fr = $this->getForce_return(); $this->locale = ModelCriteriaTools::getI18n(
return ModelCriteriaTools::getI18n(
$this->getBackend_context(), $this->getBackend_context(),
$this->getLang(), $this->getLang(),
$search, $search,

View File

@@ -27,6 +27,7 @@ use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Template\Element\Exception\LoopException;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Propel\Runtime\ActiveQuery\ModelCriteria; use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\Security\SecurityContext; use Thelia\Core\Security\SecurityContext;
@@ -62,9 +63,9 @@ abstract class BaseLoop
protected $args; protected $args;
public $countable = true; protected $countable = true;
public $timestampable = false; protected $timestampable = false;
public $versionable = false; protected $versionable = false;
/** /**
* Create a new Loop * Create a new Loop
@@ -73,6 +74,8 @@ abstract class BaseLoop
*/ */
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
{ {
$this->checkInterface();
$this->container = $container; $this->container = $container;
$this->request = $container->get('request'); $this->request = $container->get('request');
@@ -240,6 +243,9 @@ abstract class BaseLoop
*/ */
protected function search(ModelCriteria $search, &$pagination = null) protected function search(ModelCriteria $search, &$pagination = null)
{ {
if (false === $this->countable) {
return $search->find();
}
if ($this instanceof SearchLoopInterface) { if ($this instanceof SearchLoopInterface) {
$searchTerm = $this->getSearch_term(); $searchTerm = $this->getSearch_term();
$searchIn = $this->getSearch_in(); $searchIn = $this->getSearch_in();
@@ -271,6 +277,29 @@ abstract class BaseLoop
} }
} }
protected function searchArray(array $search, &$pagination = null)
{
if (false === $this->countable) {
return $search;
}
if ($this->getArgValue('page') !== null) {
$nbPage = ceil(count($search)/$this->getArgValue('limit'));
if($this->getArgValue('page') > $nbPage || $this->getArgValue('page') <= 0) {
return array();
}
$firstItem = ($this->getArgValue('page')-1) * $this->getArgValue('limit') + 1;
return array_slice($search, $firstItem, $firstItem + $this->getArgValue('limit'), false);
} else {
return array_slice($search, $this->getArgValue('offset'), $this->getArgValue('limit'), false);
}
}
/** /**
* @param ModelCriteria $search * @param ModelCriteria $search
* *
@@ -304,18 +333,89 @@ abstract class BaseLoop
} }
/** /**
*
* this function have to be implement in your own loop class.
*
* All loops parameters can be accessible via getter.
*
* for example, ref parameter is accessible through getRef method
*
* @param $pagination * @param $pagination
* @return LoopResult
*/
public function exec(&$pagination)
{
if($this instanceof PropelSearchLoopInterface) {
$searchModelCriteria = $this->buildModelCriteria();
if(null === $searchModelCriteria) {
$results = array();
} else {
$results = $this->search(
$searchModelCriteria,
$pagination
);
}
} elseif ($this instanceof ArraySearchLoopInterface) {
$searchArray = $this->buildArray();
if(null === $searchArray) {
$results = array();
} else {
$results = $this->searchArray(
$searchArray,
$pagination
);
}
}
$loopResult = new LoopResult($results);
if(true === $this->countable) {
$loopResult->setCountable();
}
if(true === $this->timestampable) {
$loopResult->setTimestamped();
}
if(true === $this->versionable) {
$loopResult->setVersioned();
}
return $this->parseResults($loopResult);
}
protected function checkInterface()
{
/* Must implement either :
* - PropelSearchLoopInterface
* - ArraySearchLoopInterface
*/
$searchInterface = false;
if($this instanceof PropelSearchLoopInterface) {
if(true === $searchInterface) {
throw new LoopException('Loop cannot implements multiple Search Interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`', LoopException::MULTIPLE_SEARCH_INTERFACE);
}
$searchInterface = true;
}
if($this instanceof ArraySearchLoopInterface) {
if(true === $searchInterface) {
throw new LoopException('Loop cannot implements multiple Search Interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`', LoopException::MULTIPLE_SEARCH_INTERFACE);
}
$searchInterface = true;
}
if(false === $searchInterface) {
throw new LoopException('Loop must implements one of the following interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`', LoopException::SEARCH_INTERFACE_NOT_FOUND);
}
/* Only PropelSearch allows timestamp and version */
if(!$this instanceof PropelSearchLoopInterface) {
if(true === $this->timestampable) {
throw new LoopException("Loop must implements 'PropelSearchLoopInterface' to be timestampable", LoopException::NOT_TIMESTAMPED);
}
if(true === $this->versionable) {
throw new LoopException("Loop must implements 'PropelSearchLoopInterface' to be versionable", LoopException::NOT_VERSIONED);
}
}
}
/**
* @param LoopResult $loopResult
* *
* @return LoopResult * @return LoopResult
*/ */
abstract public function exec(&$pagination); abstract public function parseResults(LoopResult $loopResult);
/** /**
* *

View File

@@ -0,0 +1,46 @@
<?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\Element\Exception;
class LoopException extends \RuntimeException
{
const UNKNOWN_EXCEPTION = 0;
const NOT_TIMESTAMPED = 100;
const NOT_VERSIONED = 101;
const MULTIPLE_SEARCH_INTERFACE = 400;
const SEARCH_INTERFACE_NOT_FOUND = 404;
public function __construct($message, $code = null, $arguments = array(), $previous = null)
{
if (is_array($arguments)) {
$this->arguments = $arguments;
}
if ($code === null) {
$code = self::UNKNOWN_EXCEPTION;
}
parent::__construct($message, $code, $previous);
}
}

View File

@@ -32,14 +32,40 @@ class LoopResult implements \Iterator
private $position; private $position;
protected $collection = array(); protected $collection = array();
public $modelCollection = null; public $resultsCollection = null;
public function __construct($modelCollection = null) protected $versioned = false;
protected $timestamped = false;
protected $countable = false;
public function __construct($resultsCollection)
{ {
$this->position = 0; $this->position = 0;
if ($modelCollection instanceof ObjectCollection || $modelCollection instanceof PropelModelPager || is_array($modelCollection)) { $this->resultsCollection = $resultsCollection;
$this->modelCollection = $modelCollection; }
}
/**
* @param boolean $countable
*/
public function setCountable($countable = true)
{
$this->countable = true === $countable;
}
/**
* @param boolean $timestamped
*/
public function setTimestamped($timestamped = true)
{
$this->timestamped = true === $timestamped;
}
/**
* @param boolean $versioned
*/
public function setVersioned($versioned = true)
{
$this->versioned = true === $versioned;
} }
public function isEmpty() public function isEmpty()
@@ -49,6 +75,21 @@ class LoopResult implements \Iterator
public function addRow(LoopResultRow $row) public function addRow(LoopResultRow $row)
{ {
if (true === $this->versioned) {
foreach ($this->getVersionOutputs() as $output) {
$row->set($output[0], $row->model->$output[1]());
}
}
if (true === $this->timestamped) {
foreach ($this->getTimestampOutputs() as $output) {
$row->set($output[0], $row->model->$output[1]());
}
}
if (true === $this->countable) {
$row->set('LOOP_COUNT', 1 + $this->getCount());
$row->set('LOOP_TOTAL', $this->getResultDataCollectionCount());
}
$this->collection[] = $row; $this->collection[] = $row;
} }
@@ -57,17 +98,22 @@ class LoopResult implements \Iterator
return count($this->collection); return count($this->collection);
} }
public function getModelCollectionCount() public function getResultDataCollectionCount()
{ {
if ($this->modelCollection instanceof ObjectCollection || $this->modelCollection instanceof PropelModelPager) { if ($this->resultsCollection instanceof ObjectCollection || $this->resultsCollection instanceof PropelModelPager) {
return $this->modelCollection->count(); return $this->resultsCollection->count();
} elseif (is_array($this->modelCollection)) { } elseif (is_array($this->resultsCollection)) {
return count($this->modelCollection); return count($this->resultsCollection);
} else { } else {
return 0; return 0;
} }
} }
public function getResultDataCollection()
{
return $this->resultsCollection;
}
/** /**
* (PHP 5 &gt;= 5.0.0)<br/> * (PHP 5 &gt;= 5.0.0)<br/>
* Return the current element * Return the current element
@@ -123,4 +169,21 @@ class LoopResult implements \Iterator
{ {
$this->position = 0; $this->position = 0;
} }
protected function getTimestampOutputs()
{
return array(
array('CREATE_DATE', 'getCreatedAt'),
array('UPDATE_DATE', 'getUpdatedAt'),
);
}
protected function getVersionOutputs()
{
return array(
array('VERSION', 'getVersion'),
array('VERSION_DATE', 'getVersionCreatedAt'),
array('VERSION_AUTHOR', 'getVersionCreatedBy'),
);
}
} }

View File

@@ -30,28 +30,12 @@ class LoopResultRow
protected $substitution = array(); protected $substitution = array();
public $model = null; public $model = null;
public $loopResult;
public $versionable = false; public function __construct($model = null)
public $timestampable = false;
public $countable = false;
public function __construct($loopResult = null, $model = null, $versionable = false, $timestampable = false, $countable = true)
{ {
if ($model instanceof ActiveRecordInterface) { if ($model instanceof ActiveRecordInterface) {
$this->model = $model; $this->model = $model;
$this->versionable = $versionable;
$this->timestampable = $timestampable;
} }
if ($loopResult instanceof LoopResult) {
$this->loopResult = $loopResult;
$this->countable = $countable;
}
$this->assignDefaultOutputs();
} }
public function set($key, $value) public function set($key, $value)
@@ -75,39 +59,4 @@ class LoopResultRow
{ {
return array_keys($this->substitution); return array_keys($this->substitution);
} }
protected function getTimestampOutputs()
{
return array(
array('CREATE_DATE', 'getCreatedAt'),
array('UPDATE_DATE', 'getUpdatedAt'),
);
}
protected function getVersionOutputs()
{
return array(
array('VERSION', 'getVersion'),
array('VERSION_DATE', 'getVersionCreatedAt'),
array('VERSION_AUTHOR', 'getVersionCreatedBy'),
);
}
protected function assignDefaultOutputs()
{
if (true === $this->versionable) {
foreach ($this->getVersionOutputs() as $output) {
$this->set($output[0], $this->model->$output[1]());
}
}
if (true === $this->timestampable) {
foreach ($this->getTimestampOutputs() as $output) {
$this->set($output[0], $this->model->$output[1]());
}
}
if (true === $this->countable) {
$this->set('LOOP_COUNT', 1 + $this->loopResult->getCount());
$this->set('LOOP_TOTAL', $this->loopResult->getModelCollectionCount());
}
}
} }

View File

@@ -0,0 +1,38 @@
<?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\Element;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
interface PropelSearchLoopInterface
{
/**
* this method returns a Propel ModelCriteria
*
* @return \Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function buildModelCriteria();
}

View File

@@ -45,6 +45,9 @@ use Thelia\Type;
*/ */
class Accessory extends Product class Accessory extends Product
{ {
protected $accessoryId;
protected $accessoryPosition;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
*/ */
@@ -64,12 +67,7 @@ class Accessory extends Product
return $argumentCollection; return $argumentCollection;
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = AccessoryQuery::create(); $search = AccessoryQuery::create();
@@ -93,40 +91,45 @@ class Accessory extends Product
$accessories = $this->search($search); $accessories = $this->search($search);
$accessoryIdList = array(0); $this->accessoryIdList = array(0);
$accessoryPosition = $accessoryId = array(); $this->accessoryPosition = $this->accessoryId = array();
foreach ($accessories as $accessory) { foreach ($accessories as $accessory) {
$accessoryProductId = $accessory->getAccessory(); $accessoryProductId = $accessory->getAccessory();
array_push($accessoryIdList, $accessoryProductId); array_push($this->accessoryIdList, $accessoryProductId);
$accessoryPosition[$accessoryProductId] = $accessory->getPosition(); $this->accessoryPosition[$accessoryProductId] = $accessory->getPosition();
$accessoryId[$accessoryProductId] = $accessory->getId(); $this->accessoryId[$accessoryProductId] = $accessory->getId();
} }
$receivedIdList = $this->getId(); $receivedIdList = $this->getId();
/* if an Id list is receive, loop will only match accessories from this list */ /* if an Id list is receive, loop will only match accessories from this list */
if ($receivedIdList === null) { if ($receivedIdList === null) {
$this->args->get('id')->setValue( implode(',', $accessoryIdList) ); $this->args->get('id')->setValue( implode(',', $this->accessoryIdList) );
} else { } else {
$this->args->get('id')->setValue( implode(',', array_intersect($receivedIdList, $accessoryIdList)) ); $this->args->get('id')->setValue( implode(',', array_intersect($receivedIdList, $this->accessoryIdList)) );
} }
$loopResult = parent::exec($pagination); return parent::buildModelCriteria();
}
foreach ($loopResult as $loopResultRow) { public function parseResults(LoopResult $results)
{
$results = parent::parseResults($results);
foreach ($results as $loopResultRow) {
$accessoryProductId = $loopResultRow->get('ID'); $accessoryProductId = $loopResultRow->get('ID');
$loopResultRow $loopResultRow
->set("ID" , $accessoryId[$accessoryProductId]) ->set("ID" , $this->accessoryId[$accessoryProductId])
->set("POSITION", $accessoryPosition[$accessoryProductId]) ->set("POSITION", $this->accessoryPosition[$accessoryProductId])
; ;
} }
return $loopResult; return $results;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -44,9 +45,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Address extends BaseLoop class Address extends BaseLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -80,12 +81,7 @@ class Address extends BaseLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = AddressQuery::create(); $search = AddressQuery::create();
@@ -100,7 +96,7 @@ class Address extends BaseLoop
if ($customer === 'current') { if ($customer === 'current') {
$currentCustomer = $this->securityContext->getCustomerUser(); $currentCustomer = $this->securityContext->getCustomerUser();
if ($currentCustomer === null) { if ($currentCustomer === null) {
return new LoopResult(); return null;
} else { } else {
$search->filterByCustomerId($currentCustomer->getId(), Criteria::EQUAL); $search->filterByCustomerId($currentCustomer->getId(), Criteria::EQUAL);
} }
@@ -122,12 +118,14 @@ class Address extends BaseLoop
$search->filterById($exclude, Criteria::NOT_IN); $search->filterById($exclude, Criteria::NOT_IN);
} }
$addresses = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($addresses); }
foreach ($addresses as $address) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $address, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $address) {
$loopResultRow = new LoopResultRow($address);
$loopResultRow $loopResultRow
->set("ID", $address->getId()) ->set("ID", $address->getId())
->set("LABEL", $address->getLabel()) ->set("LABEL", $address->getLabel())

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -43,9 +44,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Admin extends BaseLoop class Admin extends BaseLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -58,12 +59,7 @@ class Admin extends BaseLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = AdminQuery::create(); $search = AdminQuery::create();
@@ -81,13 +77,14 @@ class Admin extends BaseLoop
$search->orderByFirstname(Criteria::ASC); $search->orderByFirstname(Criteria::ASC);
/* perform search */ return $search;
$admins = $this->search($search, $pagination);
$loopResult = new LoopResult($admins); }
foreach ($admins as $admin) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $admin, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $admin) {
$loopResultRow = new LoopResultRow($admin);
$loopResultRow->set("ID", $admin->getId()) $loopResultRow->set("ID", $admin->getId())
->set("PROFILE",$admin->getProfileId()) ->set("PROFILE",$admin->getProfileId())
->set("FIRSTNAME",$admin->getFirstname()) ->set("FIRSTNAME",$admin->getFirstname())
@@ -99,5 +96,6 @@ class Admin extends BaseLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -26,6 +26,7 @@ use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; 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\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\AreaQuery; use Thelia\Model\AreaQuery;
@@ -35,9 +36,9 @@ use Thelia\Model\AreaQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class Area extends BaseLoop class Area extends BaseLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* *
@@ -80,19 +81,7 @@ class Area extends BaseLoop
); );
} }
/** public function buildModelCriteria()
*
* this function have to be implement in your own loop class.
*
* All loops parameters can be accessible via getter.
*
* for example, ref parameter is accessible through getRef method
*
* @param $pagination
*
* @return mixed
*/
public function exec(&$pagination)
{ {
$id = $this->getId(); $id = $this->getId();
@@ -117,14 +106,14 @@ class Area extends BaseLoop
->where('`without_zone`.delivery_module_id '.Criteria::ISNULL); ->where('`without_zone`.delivery_module_id '.Criteria::ISNULL);
} }
//echo $search->toString(); exit; return $search;
$areas = $this->search($search, $pagination); }
$loopResult = new LoopResult($areas); public function parseResults(LoopResult $loopResult)
{
foreach ($areas as $area) { foreach ($loopResult->getResultDataCollection() as $area) {
$loopResultRow = new LoopResultRow($loopResult, $area, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($area);
$loopResultRow $loopResultRow
->set('ID', $area->getId()) ->set('ID', $area->getId())
@@ -136,6 +125,7 @@ class Area extends BaseLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -46,6 +46,9 @@ use Thelia\Type;
*/ */
class AssociatedContent extends Content class AssociatedContent extends Content
{ {
protected $contentId;
protected $contentPosition;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
*/ */
@@ -68,16 +71,8 @@ class AssociatedContent extends Content
return $argumentCollection; return $argumentCollection;
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return LoopResult
* @throws \InvalidArgumentException
*/
public function exec(&$pagination)
{ {
//
$product = $this->getProduct(); $product = $this->getProduct();
$category = $this->getCategory(); $category = $this->getCategory();
@@ -136,16 +131,15 @@ class AssociatedContent extends Content
$associatedContentIdList = array(0); $associatedContentIdList = array(0);
$contentIdList = array(0); $this->contentPosition = $this->contentId = array();
$contentPosition = $contentId = array();
foreach ($associatedContents as $associatedContent) { foreach ($associatedContents as $associatedContent) {
$associatedContentId = $associatedContent->getContentId(); $associatedContentId = $associatedContent->getContentId();
array_push($associatedContentIdList, $associatedContentId); array_push($associatedContentIdList, $associatedContentId);
$contentPosition[$associatedContentId] = $associatedContent->getPosition(); $this->contentPosition[$associatedContentId] = $associatedContent->getPosition();
$contentId[$associatedContentId] = $associatedContent->getId(); $this->contentId[$associatedContentId] = $associatedContent->getId();
} }
$receivedIdList = $this->getId(); $receivedIdList = $this->getId();
@@ -157,18 +151,23 @@ class AssociatedContent extends Content
$this->args->get('id')->setValue( implode(',', array_intersect($receivedIdList, $associatedContentIdList)) ); $this->args->get('id')->setValue( implode(',', array_intersect($receivedIdList, $associatedContentIdList)) );
} }
$loopResult = parent::exec($pagination); return parent::buildModelCriteria();
}
foreach ($loopResult as $loopResultRow) { public function parseResults(LoopResult $results)
{
$results = parent::parseResults($results);
foreach ($results as $loopResultRow) {
$relatedContentId = $loopResultRow->get('ID'); $relatedContentId = $loopResultRow->get('ID');
$loopResultRow $loopResultRow
->set("ID" , $contentId[$relatedContentId]) ->set("ID" , $this->contentId[$relatedContentId])
->set("POSITION", $contentPosition[$relatedContentId]) ->set("POSITION", $this->contentPosition[$relatedContentId])
; ;
} }
return $loopResult; return $results;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -47,9 +48,11 @@ use Thelia\Model\Map\AttributeTemplateTableMap;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Attribute extends BaseI18nLoop class Attribute extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $useAttributePosistion;
protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -72,12 +75,7 @@ class Attribute extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = AttributeQuery::create(); $search = AttributeQuery::create();
@@ -86,7 +84,7 @@ class Attribute extends BaseI18nLoop
$lang = $this->getLang(); $lang = $this->getLang();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -104,7 +102,7 @@ class Attribute extends BaseI18nLoop
$template = $this->getTemplate(); $template = $this->getTemplate();
$exclude_template = $this->getExcludeTemplate(); $exclude_template = $this->getExcludeTemplate();
$use_attribute_pos = true; $this->useAttributePosistion = true;
if (null !== $product) { if (null !== $product) {
// Find all template assigned to the products. // Find all template assigned to the products.
@@ -132,7 +130,7 @@ class Attribute extends BaseI18nLoop
->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN) ->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN)
; ;
$use_attribute_pos = false; $this->useAttributePosistion = false;
} elseif (null !== $exclude_template) { } elseif (null !== $exclude_template) {
// Join with attribute_template table to get position // Join with attribute_template table to get position
@@ -144,7 +142,7 @@ class Attribute extends BaseI18nLoop
->filterById($exclude_attributes, Criteria::NOT_IN) ->filterById($exclude_attributes, Criteria::NOT_IN)
; ;
$use_attribute_pos = false; $this->useAttributePosistion = false;
} }
$orders = $this->getOrder(); $orders = $this->getOrder();
@@ -164,13 +162,13 @@ class Attribute extends BaseI18nLoop
$search->addDescendingOrderByColumn('i18n_TITLE'); $search->addDescendingOrderByColumn('i18n_TITLE');
break; break;
case "manual": case "manual":
if ($use_attribute_pos) if ($this->useAttributePosistion)
$search->orderByPosition(Criteria::ASC); $search->orderByPosition(Criteria::ASC);
else else
$search->addAscendingOrderByColumn(AttributeTemplateTableMap::POSITION); $search->addAscendingOrderByColumn(AttributeTemplateTableMap::POSITION);
break; break;
case "manual_reverse": case "manual_reverse":
if ($use_attribute_pos) if ($this->useAttributePosistion)
$search->orderByPosition(Criteria::DESC); $search->orderByPosition(Criteria::DESC);
else else
$search->addDescendingOrderByColumn(AttributeTemplateTableMap::POSITION); $search->addDescendingOrderByColumn(AttributeTemplateTableMap::POSITION);
@@ -178,26 +176,28 @@ class Attribute extends BaseI18nLoop
} }
} }
/* perform search */ return $search;
$attributes = $this->search($search, $pagination);
$loopResult = new LoopResult($attributes); }
foreach ($attributes as $attribute) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $attribute, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $attribute) {
$loopResultRow = new LoopResultRow($attribute);
$loopResultRow->set("ID", $attribute->getId()) $loopResultRow->set("ID", $attribute->getId())
->set("IS_TRANSLATED",$attribute->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$attribute->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("TITLE",$attribute->getVirtualColumn('i18n_TITLE')) ->set("TITLE",$attribute->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $attribute->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $attribute->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $attribute->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION", $attribute->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $attribute->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM", $attribute->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("POSITION", $use_attribute_pos ? $attribute->getPosition() : $attribute->getVirtualColumn('position')) ->set("POSITION", $this->useAttributePosistion ? $attribute->getPosition() : $attribute->getVirtualColumn('position'))
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -43,9 +44,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class AttributeAvailability extends BaseI18nLoop class AttributeAvailability extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -66,17 +67,12 @@ class AttributeAvailability extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = AttributeAvQuery::create(); $search = AttributeAvQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -121,18 +117,19 @@ class AttributeAvailability extends BaseI18nLoop
} }
} }
/* perform search */ return $search;
$attributesAv = $this->search($search, $pagination);
$loopResult = new LoopResult($attributesAv); }
foreach ($attributesAv as $attributeAv) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $attributeAv, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $attributeAv) {
$loopResultRow = new LoopResultRow($attributeAv);
$loopResultRow $loopResultRow
->set("ID" , $attributeAv->getId()) ->set("ID" , $attributeAv->getId())
->set("ATTRIBUTE_ID" , $attributeAv->getAttributeId()) ->set("ATTRIBUTE_ID" , $attributeAv->getAttributeId())
->set("IS_TRANSLATED", $attributeAv->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED", $attributeAv->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("TITLE" , $attributeAv->getVirtualColumn('i18n_TITLE')) ->set("TITLE" , $attributeAv->getVirtualColumn('i18n_TITLE'))
->set("CHAPO" , $attributeAv->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO" , $attributeAv->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION" , $attributeAv->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION" , $attributeAv->getVirtualColumn('i18n_DESCRIPTION'))
@@ -144,5 +141,6 @@ class AttributeAvailability extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -45,9 +46,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class AttributeCombination extends BaseI18nLoop class AttributeCombination extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -66,17 +67,12 @@ class AttributeCombination extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = AttributeCombinationQuery::create(); $search = AttributeCombinationQuery::create();
/* manage attribute translations */ /* manage attribute translations */
$locale = $this->configureI18nProcessing( $this->configureI18nProcessing(
$search, $search,
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
AttributeTableMap::TABLE_NAME, AttributeTableMap::TABLE_NAME,
@@ -84,7 +80,7 @@ class AttributeCombination extends BaseI18nLoop
); );
/* manage attributeAv translations */ /* manage attributeAv translations */
$locale = $this->configureI18nProcessing( $this->configureI18nProcessing(
$search, $search,
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
AttributeAvTableMap::TABLE_NAME, AttributeAvTableMap::TABLE_NAME,
@@ -108,15 +104,17 @@ class AttributeCombination extends BaseI18nLoop
} }
} }
$attributeCombinations = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($attributeCombinations); }
foreach ($attributeCombinations as $attributeCombination) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $attributeCombination, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $attributeCombination) {
$loopResultRow = new LoopResultRow($attributeCombination);
$loopResultRow $loopResultRow
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("ATTRIBUTE_TITLE", $attributeCombination->getVirtualColumn(AttributeTableMap::TABLE_NAME . '_i18n_TITLE')) ->set("ATTRIBUTE_TITLE", $attributeCombination->getVirtualColumn(AttributeTableMap::TABLE_NAME . '_i18n_TITLE'))
->set("ATTRIBUTE_CHAPO", $attributeCombination->getVirtualColumn(AttributeTableMap::TABLE_NAME . '_i18n_CHAPO')) ->set("ATTRIBUTE_CHAPO", $attributeCombination->getVirtualColumn(AttributeTableMap::TABLE_NAME . '_i18n_CHAPO'))
->set("ATTRIBUTE_DESCRIPTION", $attributeCombination->getVirtualColumn(AttributeTableMap::TABLE_NAME . '_i18n_DESCRIPTION')) ->set("ATTRIBUTE_DESCRIPTION", $attributeCombination->getVirtualColumn(AttributeTableMap::TABLE_NAME . '_i18n_DESCRIPTION'))
@@ -130,5 +128,6 @@ class AttributeCombination extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -24,6 +24,7 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\AccessManager;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
@@ -40,7 +41,7 @@ use Thelia\Type\TypeCollection;
* *
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class Auth extends BaseLoop class Auth extends BaseLoop implements ArraySearchLoopInterface
{ {
public function getArgDefinitions() public function getArgDefinitions()
{ {
@@ -69,19 +70,17 @@ class Auth extends BaseLoop
); );
} }
/** public function buildArray()
* @param $pagination {
* return array();
* @return LoopResult }
*/
public function exec(&$pagination) public function parseResults(LoopResult $loopResult)
{ {
$roles = $this->getRole(); $roles = $this->getRole();
$resource = $this->getResource(); $resource = $this->getResource();
$access = $this->getAccess(); $access = $this->getAccess();
$loopResult = new LoopResult();
try { try {
if (true === $this->securityContext->isGranted($roles, $resource === null ? array() : $resource, $access === null ? array() : $access)) { if (true === $this->securityContext->isGranted($roles, $resource === null ? array() : $resource, $access === null ? array() : $access)) {

View File

@@ -24,6 +24,8 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\ModuleQuery; use Thelia\Model\ModuleQuery;
@@ -32,9 +34,9 @@ use Thelia\Model\ModuleQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class BaseSpecificModule extends BaseI18nLoop abstract class BaseSpecificModule extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* *
@@ -76,19 +78,7 @@ class BaseSpecificModule extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
*
* this function have to be implement in your own loop class.
*
* All loops parameters can be accesible via getter.
*
* for example, ref parameter is accessible through getRef method
*
* @param $pagination
*
* @return \Thelia\Model\ModuleQuery
*/
public function exec(&$pagination)
{ {
$search = ModuleQuery::create(); $search = ModuleQuery::create();
@@ -102,7 +92,12 @@ class BaseSpecificModule extends BaseI18nLoop
$search->filterById($exclude, Criteria::NOT_IN); $search->filterById($exclude, Criteria::NOT_IN);
} }
$this->configureI18nProcessing($search);
$search->filterByType($this->getModuleType(), Criteria::EQUAL);
return $search; return $search;
} }
abstract protected function getModuleType();
} }

View File

@@ -9,15 +9,15 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\CountryQuery; use Thelia\Model\CountryQuery;
use Thelia\Type; use Thelia\Type;
class Cart extends BaseLoop class Cart extends BaseLoop implements ArraySearchLoopInterface
{ {
use \Thelia\Cart\CartTrait; use \Thelia\Cart\CartTrait;
/** /**
@@ -41,80 +41,29 @@ class Cart extends BaseLoop
*/ */
protected function getArgDefinitions() protected function getArgDefinitions()
{ {
return new ArgumentCollection( return new ArgumentCollection();
Argument::createIntTypeArgument('limit'),
Argument::createAnyTypeArgument('position')
);
} }
/** public function buildArray()
*
* this function have to be implement in your own loop class.
*
* All your parameters are defined in defineArgs() and can be accessible like a class property.
*
* example :
*
* public function defineArgs()
* {
* return array (
* "ref",
* "id" => "optional",
* "stock" => array(
* "optional",
* "default" => 10
* )
* );
* }
*
* you can retrieve ref value using $this->ref
*
* @param $pagination
*
* @return mixed
*/
public function exec(&$pagination)
{ {
$cart = $this->getCart($this->request); $cart = $this->getCart($this->request);
$cartItems = $cart->getCartItems(); if(null === $cart) {
$result = new LoopResult($cartItems); return array();
if ($cart === null) {
return $result;
} }
$limit = $this->getLimit(); return iterator_to_array($cart->getCartItems());
}
$countCartItems = count($cartItems);
if ($limit <= 0 || $limit >= $countCartItems) {
$limit = $countCartItems;
}
$position = $this->getPosition();
if (isset($position)) {
if ($position == "first") {
$limit = 1;
$cartItems = array($cartItems[0]);
} elseif ($position == "last") {
$limit = 1;
$cartItems = array(end($cartItems));
}
// @TODO : if the position is a number
}
public function parseResults(LoopResult $loopResult)
{
$taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic; $taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic;
for ($i=0; $i<$limit; $i ++) { foreach($loopResult->getResultDataCollection() as $cartItem) {
$cartItem = $cartItems[$i];
$product = $cartItem->getProduct(); $product = $cartItem->getProduct();
$productSaleElement = $cartItem->getProductSaleElements(); $productSaleElement = $cartItem->getProductSaleElements();
$loopResultRow = new LoopResultRow($result, $cartItem, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow();
$loopResultRow->set("ITEM_ID", $cartItem->getId()); $loopResultRow->set("ITEM_ID", $cartItem->getId());
$loopResultRow->set("TITLE", $product->getTitle()); $loopResultRow->set("TITLE", $product->getTitle());
@@ -130,10 +79,11 @@ class Cart extends BaseLoop
->set("PROMO_TAXED_PRICE", $cartItem->getTaxedPromoPrice($taxCountry)) ->set("PROMO_TAXED_PRICE", $cartItem->getTaxedPromoPrice($taxCountry))
->set("IS_PROMO", $cartItem->getPromo() === 1 ? 1 : 0); ->set("IS_PROMO", $cartItem->getPromo() === 1 ? 1 : 0);
$loopResultRow->set("PRODUCT_SALE_ELEMENTS_ID", $productSaleElement->getId()); $loopResultRow->set("PRODUCT_SALE_ELEMENTS_ID", $productSaleElement->getId());
$result->addRow($loopResultRow);
$loopResult->addRow($loopResultRow);
} }
return $result; return $loopResult;
} }
/** /**

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -61,10 +62,10 @@ use Thelia\Model\ProductQuery;
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Category extends BaseI18nLoop class Category extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
public $versionable = true; protected $versionable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -90,17 +91,12 @@ class Category extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = CategoryQuery::create(); $search = CategoryQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -184,16 +180,16 @@ class Category extends BaseI18nLoop
} }
} }
/* perform search */
$categories = $this->search($search, $pagination);
/* @todo */ /* @todo */
$notEmpty = $this->getNot_empty(); $notEmpty = $this->getNot_empty();
$loopResult = new LoopResult($categories); return $search;
foreach ($categories as $category) { }
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $category) {
// Find previous and next category // Find previous and next category
$previous = CategoryQuery::create() $previous = CategoryQuery::create()
->filterByParent($category->getParent()) ->filterByParent($category->getParent())
@@ -214,18 +210,18 @@ class Category extends BaseI18nLoop
* if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue; * if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;
*/ */
$loopResultRow = new LoopResultRow($loopResult, $category, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($category);
$loopResultRow $loopResultRow
->set("ID", $category->getId()) ->set("ID", $category->getId())
->set("IS_TRANSLATED",$category->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$category->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("TITLE", $category->getVirtualColumn('i18n_TITLE')) ->set("TITLE", $category->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $category->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $category->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $category->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION", $category->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $category->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM", $category->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("PARENT", $category->getParent()) ->set("PARENT", $category->getParent())
->set("URL", $category->getUrl($locale)) ->set("URL", $category->getUrl($this->locale))
->set("PRODUCT_COUNT", $category->countAllProducts()) ->set("PRODUCT_COUNT", $category->countAllProducts())
->set("CHILD_COUNT", $category->countChild()) ->set("CHILD_COUNT", $category->countChild())
->set("VISIBLE", $category->getVisible() ? "1" : "0") ->set("VISIBLE", $category->getVisible() ? "1" : "0")
@@ -236,11 +232,12 @@ class Category extends BaseI18nLoop
->set("PREVIOUS", $previous != null ? $previous->getId() : -1) ->set("PREVIOUS", $previous != null ? $previous->getId() : -1)
->set("NEXT" , $next != null ? $next->getId() : -1) ->set("NEXT" , $next != null ? $next->getId() : -1)
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -23,6 +23,7 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
@@ -54,7 +55,7 @@ use Thelia\Type\BooleanOrBothType;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class CategoryPath extends BaseI18nLoop class CategoryPath extends BaseI18nLoop implements ArraySearchLoopInterface
{ {
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -69,19 +70,14 @@ class CategoryPath extends BaseI18nLoop
); );
} }
/** public function buildArray()
* @param $pagination (ignored)
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$id = $this->getCategory(); $id = $this->getCategory();
$visible = $this->getVisible(); $visible = $this->getVisible();
$search = CategoryQuery::create(); $search = CategoryQuery::create();
$locale = $this->configureI18nProcessing($search, array('TITLE')); $this->configureI18nProcessing($search, array('TITLE'));
$search->filterById($id); $search->filterById($id);
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible); if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
@@ -95,16 +91,12 @@ class CategoryPath extends BaseI18nLoop
if ($category != null) { if ($category != null) {
$loopResultRow = new LoopResultRow(); $results[] = array(
"ID" => $category->getId(),
$loopResultRow "TITLE" => $category->getVirtualColumn('i18n_TITLE'),
->set("TITLE",$category->getVirtualColumn('i18n_TITLE')) "URL" => $category->getUrl($this->locale),
->set("URL", $category->getUrl($locale)) "LOCALE" => $this->locale,
->set("ID", $category->getId()) );
->set("LOCALE",$locale)
;
$results[] = $loopResultRow;
$parent = $category->getParent(); $parent = $category->getParent();
@@ -128,11 +120,18 @@ class CategoryPath extends BaseI18nLoop
} while ($category != null && $parent > 0); } while ($category != null && $parent > 0);
// Reverse list and build the final result // Reverse list and build the final result
$results = array_reverse($results); return array_reverse($results);
}
$loopResult = new LoopResult(); public function parseResults(LoopResult $loopResult)
{
foreach($results as $result) $loopResult->addRow($result); foreach($loopResult->getResultDataCollection() as $result) {
$loopResultRow = new LoopResultRow($result);
foreach($result as $output => $outputValue) {
$loopResultRow->set($output, $outputValue);
}
$loopResult->addRow($loopResultRow);
}
return $loopResult; return $loopResult;
} }

View File

@@ -23,6 +23,7 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
@@ -45,7 +46,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class CategoryTree extends BaseI18nLoop class CategoryTree extends BaseI18nLoop implements ArraySearchLoopInterface
{ {
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -59,13 +60,13 @@ class CategoryTree extends BaseI18nLoop
} }
// changement de rubrique // changement de rubrique
protected function buildCategoryTree($parent, $visible, $level, $previousLevel, $max_level, $exclude, LoopResult &$loopResult) protected function buildCategoryTree($parent, $visible, $level, $previousLevel, $max_level, $exclude, &$resultsList)
{ {
if ($level > $max_level) return; if ($level > $max_level) return;
$search = CategoryQuery::create(); $search = CategoryQuery::create();
$locale = $this->configureI18nProcessing($search, array( $this->configureI18nProcessing($search, array(
'TITLE' 'TITLE'
)); ));
@@ -81,41 +82,45 @@ class CategoryTree extends BaseI18nLoop
foreach ($results as $result) { foreach ($results as $result) {
$loopResultRow = new LoopResultRow(); $resultsList[] = array(
"ID" => $result->getId(),
"TITLE" => $result->getVirtualColumn('i18n_TITLE'),
"PARENT" => $result->getParent(),
"URL" => $result->getUrl($this->locale),
"VISIBLE" => $result->getVisible() ? "1" : "0",
"LEVEL" => $level,
'CHILD_COUNT' => $result->countChild(),
'PREV_LEVEL' => $previousLevel,
);
$loopResultRow $this->buildCategoryTree($result->getId(), $visible, 1 + $level, $level, $max_level, $exclude, $resultsList);
->set("ID", $result->getId())
->set("TITLE", $result->getVirtualColumn('i18n_TITLE'))
->set("PARENT", $result->getParent())
->set("URL", $result->getUrl($locale))
->set("VISIBLE", $result->getVisible() ? "1" : "0")
->set("LEVEL", $level)
->set('CHILD_COUNT', $result->countChild())
->set('PREV_LEVEL', $previousLevel)
;
$loopResult->addRow($loopResultRow);
$this->buildCategoryTree($result->getId(), $visible, 1 + $level, $level, $max_level, $exclude, $loopResult);
} }
} }
/** public function parseResults(LoopResult $loopResult)
* @param $pagination (ignored) {
* foreach($loopResult->getResultDataCollection() as $result) {
* @return \Thelia\Core\Template\Element\LoopResult $loopResultRow = new LoopResultRow($result);
*/ foreach($result as $output => $outputValue) {
public function exec(&$pagination) $loopResultRow->set($output, $outputValue);
}
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
public function buildArray()
{ {
$id = $this->getCategory(); $id = $this->getCategory();
$depth = $this->getDepth(); $depth = $this->getDepth();
$visible = $this->getVisible(); $visible = $this->getVisible();
$exclude = $this->getExclude(); $exclude = $this->getExclude();
$loopResult = new LoopResult(); $resultsList = array();
$this->buildCategoryTree($id, $visible, 0, 0, $depth, $exclude, $loopResult); $this->buildCategoryTree($id, $visible, 0, 0, $depth, $exclude, $resultsList);
return $loopResult; return $resultsList;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; 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\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
@@ -48,9 +49,9 @@ use Thelia\Type\EnumListType;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class Config extends BaseI18nLoop class Config extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -80,20 +81,16 @@ class Config extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination (ignored)
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$id = $this->getId(); $id = $this->getId();
$name = $this->getVariable(); $name = $this->getVariable();
$secured = $this->getSecured(); $secured = $this->getSecured();
$exclude = $this->getExclude();
$search = ConfigQuery::create(); $search = ConfigQuery::create();
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
if (! is_null($id)) if (! is_null($id))
$search->filterById($id); $search->filterById($id);
@@ -145,20 +142,21 @@ class Config extends BaseI18nLoop
} }
} }
$results = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($results); }
foreach ($results as $result) { public function parseResults(LoopResult $loopResult)
{
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable); foreach ($loopResult->getResultDataCollection() as $result) {
$loopResultRow = new LoopResultRow($result);
$loopResultRow $loopResultRow
->set("ID" , $result->getId()) ->set("ID" , $result->getId())
->set("NAME" , $result->getName()) ->set("NAME" , $result->getName())
->set("VALUE" , $result->getValue()) ->set("VALUE" , $result->getValue())
->set("IS_TRANSLATED", $result->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED", $result->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("TITLE" , $result->getVirtualColumn('i18n_TITLE')) ->set("TITLE" , $result->getVirtualColumn('i18n_TITLE'))
->set("CHAPO" , $result->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO" , $result->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION'))
@@ -171,5 +169,6 @@ class Config extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -47,10 +48,10 @@ use Thelia\Type\BooleanOrBothType;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Content extends BaseI18nLoop class Content extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
public $versionable = true; protected $versionable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -77,19 +78,13 @@ class Content extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return LoopResult
* @throws \InvalidArgumentException
*/
public function exec(&$pagination)
{ {
$search = ContentQuery::create(); $search = ContentQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -205,26 +200,25 @@ class Content extends BaseI18nLoop
); );
} }
/* perform search */ return $search;
$search->groupBy(ContentTableMap::ID);
$contents = $this->search($search, $pagination); }
$loopResult = new LoopResult($contents); public function parseResults(LoopResult $loopResult)
{
foreach ($contents as $content) { foreach ($loopResult->getResultDataCollection() as $content) {
$loopResultRow = new LoopResultRow($loopResult, $content, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($content);
$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",$locale) ->set("LOCALE",$this->locale)
->set("TITLE",$content->getVirtualColumn('i18n_TITLE')) ->set("TITLE",$content->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $content->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $content->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $content->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION", $content->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $content->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM", $content->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("POSITION", $content->getPosition()) ->set("POSITION", $content->getPosition())
->set("DEFAULT_FOLDER", $content->getDefaultFolderId()) ->set("DEFAULT_FOLDER", $content->getDefaultFolderId())
->set("URL", $content->getUrl($locale)) ->set("URL", $content->getUrl($this->locale))
->set("VISIBLE", $content->getVisible()) ->set("VISIBLE", $content->getVisible())
; ;
@@ -232,6 +226,7 @@ class Content extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -42,9 +43,9 @@ use Thelia\Model\CountryQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Country extends BaseI18nLoop class Country extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -59,17 +60,12 @@ class Country extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = CountryQuery::create(); $search = CountryQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -99,16 +95,17 @@ class Country extends BaseI18nLoop
$search->addAscendingOrderByColumn('i18n_TITLE'); $search->addAscendingOrderByColumn('i18n_TITLE');
/* perform search */ return $search;
$countries = $this->search($search, $pagination);
$loopResult = new LoopResult($countries); }
foreach ($countries as $country) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $country, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $country) {
$loopResultRow = new LoopResultRow($country);
$loopResultRow->set("ID", $country->getId()) $loopResultRow->set("ID", $country->getId())
->set("IS_TRANSLATED",$country->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$country->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("TITLE",$country->getVirtualColumn('i18n_TITLE')) ->set("TITLE",$country->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $country->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $country->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $country->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION", $country->getVirtualColumn('i18n_DESCRIPTION'))
@@ -118,11 +115,12 @@ class Country extends BaseI18nLoop
->set("ISOALPHA3", $country->getIsoalpha3()) ->set("ISOALPHA3", $country->getIsoalpha3())
->set("IS_DEFAULT", $country->getByDefault() ? "1" : "0") ->set("IS_DEFAULT", $country->getByDefault() ? "1" : "0")
->set("IS_SHOP_COUNTRY", $country->getShopCountry() ? "1" : "0") ->set("IS_SHOP_COUNTRY", $country->getShopCountry() ? "1" : "0")
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -31,6 +31,7 @@ use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; 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\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Coupon\Type\CouponInterface; use Thelia\Coupon\Type\CouponInterface;
@@ -49,7 +50,7 @@ use Thelia\Type;
* @author Guillaume MOREL <gmorel@openstudio.fr> * @author Guillaume MOREL <gmorel@openstudio.fr>
* *
*/ */
class Coupon extends BaseI18nLoop class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
/** /**
* Define all args used in your loop * Define all args used in your loop
@@ -64,19 +65,12 @@ class Coupon extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* Execute Loop
*
* @param PropelModelPager $pagination Pagination manager
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = CouponQuery::create(); $search = CouponQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION', 'SHORT_DESCRIPTION')); $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION', 'SHORT_DESCRIPTION'));
$id = $this->getId(); $id = $this->getId();
$isEnabled = $this->getIsEnabled(); $isEnabled = $this->getIsEnabled();
@@ -89,10 +83,11 @@ class Coupon extends BaseI18nLoop
$search->filterByIsEnabled($isEnabled ? true : false); $search->filterByIsEnabled($isEnabled ? true : false);
} }
// Perform search return $search;
$coupons = $this->search($search, $pagination); }
$loopResult = new LoopResult(); public function parseResults(LoopResult $loopResult)
{
/** @var ConditionFactory $conditionFactory */ /** @var ConditionFactory $conditionFactory */
$conditionFactory = $this->container->get('thelia.condition.factory'); $conditionFactory = $this->container->get('thelia.condition.factory');
@@ -102,8 +97,8 @@ class Coupon extends BaseI18nLoop
$lang = $request->getSession()->getLang(); $lang = $request->getSession()->getLang();
/** @var MCoupon $coupon */ /** @var MCoupon $coupon */
foreach ($coupons as $coupon) { foreach ($loopResult->getResultDataCollection() as $coupon) {
$loopResultRow = new LoopResultRow(); $loopResultRow = new LoopResultRow($coupon);
$conditions = $conditionFactory->unserializeConditionCollection( $conditions = $conditionFactory->unserializeConditionCollection(
$coupon->getSerializedConditions() $coupon->getSerializedConditions()
); );
@@ -136,7 +131,7 @@ class Coupon extends BaseI18nLoop
} }
$loopResultRow->set("ID", $coupon->getId()) $loopResultRow->set("ID", $coupon->getId())
->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE", $locale) ->set("LOCALE", $this->locale)
->set("CODE", $coupon->getCode()) ->set("CODE", $coupon->getCode())
->set("TITLE", $coupon->getVirtualColumn('i18n_TITLE')) ->set("TITLE", $coupon->getVirtualColumn('i18n_TITLE'))
->set("SHORT_DESCRIPTION", $coupon->getVirtualColumn('i18n_SHORT_DESCRIPTION')) ->set("SHORT_DESCRIPTION", $coupon->getVirtualColumn('i18n_SHORT_DESCRIPTION'))

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -44,9 +45,9 @@ use Thelia\Type\EnumListType;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Currency extends BaseI18nLoop class Currency extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -76,17 +77,12 @@ class Currency extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = CurrencyQuery::create(); $search = CurrencyQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search, array('NAME')); $this->configureI18nProcessing($search, array('NAME'));
$id = $this->getId(); $id = $this->getId();
@@ -162,17 +158,18 @@ class Currency extends BaseI18nLoop
} }
/* perform search */ /* perform search */
$currencies = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($currencies); }
foreach ($currencies as $currency) { public function parseResults(LoopResult $loopResult)
{
$loopResultRow = new LoopResultRow($loopResult, $currency, $this->versionable, $this->timestampable, $this->countable); foreach ($loopResult->getResultDataCollection() as $currency) {
$loopResultRow = new LoopResultRow($currency);
$loopResultRow $loopResultRow
->set("ID" , $currency->getId()) ->set("ID" , $currency->getId())
->set("IS_TRANSLATED" , $currency->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED" , $currency->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("NAME" , $currency->getVirtualColumn('i18n_NAME')) ->set("NAME" , $currency->getVirtualColumn('i18n_NAME'))
->set("ISOCODE" , $currency->getCode()) ->set("ISOCODE" , $currency->getCode())
->set("SYMBOL" , $currency->getSymbol()) ->set("SYMBOL" , $currency->getSymbol())
@@ -185,5 +182,6 @@ class Currency extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Element\SearchLoopInterface; use Thelia\Core\Template\Element\SearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -45,9 +46,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Customer extends BaseLoop implements SearchLoopInterface class Customer extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -109,12 +110,7 @@ class Customer extends BaseLoop implements SearchLoopInterface
} }
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = CustomerQuery::create(); $search = CustomerQuery::create();
@@ -123,7 +119,7 @@ class Customer extends BaseLoop implements SearchLoopInterface
if ($current === true) { if ($current === true) {
$currentCustomer = $this->securityContext->getCustomerUser(); $currentCustomer = $this->securityContext->getCustomerUser();
if ($currentCustomer === null) { if ($currentCustomer === null) {
return new LoopResult(); return null;
} else { } else {
$search->filterById($currentCustomer->getId(), Criteria::EQUAL); $search->filterById($currentCustomer->getId(), Criteria::EQUAL);
} }
@@ -155,12 +151,14 @@ class Customer extends BaseLoop implements SearchLoopInterface
$search->filterBySponsor($sponsor, Criteria::EQUAL); $search->filterBySponsor($sponsor, Criteria::EQUAL);
} }
$customers = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($customers); }
foreach ($customers as $customer) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $customer, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $customer) {
$loopResultRow = new LoopResultRow($customer);
$loopResultRow->set("ID", $customer->getId()); $loopResultRow->set("ID", $customer->getId());
$loopResultRow->set("REF", $customer->getRef()); $loopResultRow->set("REF", $customer->getRef());
$loopResultRow->set("TITLE", $customer->getTitleId()); $loopResultRow->set("TITLE", $customer->getTitleId());
@@ -175,5 +173,6 @@ class Customer extends BaseLoop implements SearchLoopInterface
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -22,7 +22,6 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -33,6 +32,7 @@ use Thelia\Module\BaseModule;
* Class Delivery * Class Delivery
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
* @author Etienne Roudeix <eroudeix@gmail.com>
*/ */
class Delivery extends BaseSpecificModule class Delivery extends BaseSpecificModule
{ {
@@ -48,14 +48,8 @@ class Delivery extends BaseSpecificModule
return $collection; return $collection;
} }
public function exec(&$pagination) public function parseResults(LoopResult $loopResult)
{ {
$search = parent::exec($pagination);
/* manage translations */
$locale = $this->configureI18nProcessing($search);
$search->filterByType(BaseModule::DELIVERY_MODULE_TYPE, Criteria::EQUAL);
$countryId = $this->getCountry(); $countryId = $this->getCountry();
if (null !== $countryId) { if (null !== $countryId) {
$country = CountryQuery::create()->findPk($countryId); $country = CountryQuery::create()->findPk($countryId);
@@ -66,13 +60,8 @@ class Delivery extends BaseSpecificModule
$country = CountryQuery::create()->findOneByByDefault(1); $country = CountryQuery::create()->findOneByByDefault(1);
} }
/* perform search */ foreach ($loopResult->getResultDataCollection() as $deliveryModule) {
$deliveryModules = $this->search($search, $pagination); $loopResultRow = new LoopResultRow($deliveryModule);
$loopResult = new LoopResult($deliveryModules);
foreach ($deliveryModules as $deliveryModule) {
$loopResultRow = new LoopResultRow($loopResult, $deliveryModule, $this->versionable, $this->timestampable, $this->countable);
$moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace()); $moduleReflection = new \ReflectionClass($deliveryModule->getFullNamespace());
if ($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) { if ($moduleReflection->isSubclassOf("Thelia\Module\DeliveryModuleInterface") === false) {
@@ -97,4 +86,9 @@ class Delivery extends BaseSpecificModule
return $loopResult; return $loopResult;
} }
protected function getModuleType()
{
return BaseModule::DELIVERY_MODULE_TYPE;
}
} }

View File

@@ -23,6 +23,7 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Event\Document\DocumentEvent; use Thelia\Core\Event\Document\DocumentEvent;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
@@ -41,9 +42,12 @@ use Thelia\Log\Tlog;
* *
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class Document extends BaseI18nLoop class Document extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $objectType;
protected $objectId;
protected $timestampable = true;
/** /**
* @var array Possible document sources * @var array Possible document sources
@@ -195,18 +199,15 @@ class Document extends BaseI18nLoop
return $search; return $search;
} }
/** public function buildModelCriteria()
* @param unknown $pagination
*/
public function exec(&$pagination)
{ {
// Select the proper query to use, and get the object type // Select the proper query to use, and get the object type
$object_type = $object_id = null; $this->objectType = $this->objectId = null;
$search = $this->getSearchQuery($object_type, $object_id); $search = $this->getSearchQuery($this->objectType, $this->objectId);
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -221,14 +222,13 @@ class Document extends BaseI18nLoop
// Create document processing event // Create document processing event
$event = new DocumentEvent($this->request); $event = new DocumentEvent($this->request);
// echo "sql=".$search->toString(); return $search;
$results = $this->search($search, $pagination); }
$loopResult = new LoopResult($results);
foreach ($results as $result) {
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $result) {
// Create document processing event // Create document processing event
$event = new DocumentEvent($this->request); $event = new DocumentEvent($this->request);
@@ -236,22 +236,22 @@ class Document extends BaseI18nLoop
$source_filepath = sprintf("%s%s/%s/%s", $source_filepath = sprintf("%s%s/%s/%s",
THELIA_ROOT, THELIA_ROOT,
ConfigQuery::read('documents_library_path', 'local/media/documents'), ConfigQuery::read('documents_library_path', 'local/media/documents'),
$object_type, $this->objectType,
$result->getFile() $result->getFile()
); );
$event->setSourceFilepath($source_filepath); $event->setSourceFilepath($source_filepath);
$event->setCacheSubdirectory($object_type); $event->setCacheSubdirectory($this->objectType);
try { try {
// Dispatch document processing event // Dispatch document processing event
$this->dispatcher->dispatch(TheliaEvents::DOCUMENT_PROCESS, $event); $this->dispatcher->dispatch(TheliaEvents::DOCUMENT_PROCESS, $event);
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($result);
$loopResultRow $loopResultRow
->set("ID" , $result->getId()) ->set("ID" , $result->getId())
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("DOCUMENT_URL" , $event->getFileUrl()) ->set("DOCUMENT_URL" , $event->getFileUrl())
->set("DOCUMENT_PATH" , $event->getDocumentPath()) ->set("DOCUMENT_PATH" , $event->getDocumentPath())
->set("ORIGINAL_DOCUMENT_PATH", $source_filepath) ->set("ORIGINAL_DOCUMENT_PATH", $source_filepath)
@@ -260,8 +260,8 @@ class Document extends BaseI18nLoop
->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("POSITION" , $result->getPosition()) ->set("POSITION" , $result->getPosition())
->set("OBJECT_TYPE" , $object_type) ->set("OBJECT_TYPE" , $this->objectType)
->set("OBJECT_ID" , $object_id) ->set("OBJECT_ID" , $this->objectId)
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
@@ -272,5 +272,6 @@ class Document extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -50,9 +51,11 @@ use Thelia\Model\Map\FeatureTemplateTableMap;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Feature extends BaseI18nLoop class Feature extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $useFeaturePosition;
protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -77,17 +80,12 @@ class Feature extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = FeatureQuery::create(); $search = FeatureQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -109,7 +107,7 @@ class Feature extends BaseI18nLoop
$template = $this->getTemplate(); $template = $this->getTemplate();
$exclude_template = $this->getExcludeTemplate(); $exclude_template = $this->getExcludeTemplate();
$use_feature_pos = true; $this->useFeaturePosition = true;
if (null !== $product) { if (null !== $product) {
// Find all template assigned to the products. // Find all template assigned to the products.
@@ -137,7 +135,7 @@ class Feature extends BaseI18nLoop
->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN) ->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN)
; ;
$use_feature_pos = false; $this->useFeaturePosition = false;
} }
if (null !== $exclude_template) { if (null !== $exclude_template) {
@@ -149,7 +147,7 @@ class Feature extends BaseI18nLoop
->filterById($exclude_features, Criteria::NOT_IN) ->filterById($exclude_features, Criteria::NOT_IN)
; ;
$use_feature_pos = false; $this->useFeaturePosition = false;
} }
$title = $this->getTitle(); $title = $this->getTitle();
@@ -186,13 +184,13 @@ class Feature extends BaseI18nLoop
$search->addDescendingOrderByColumn('i18n_TITLE'); $search->addDescendingOrderByColumn('i18n_TITLE');
break; break;
case "manual": case "manual":
if ($use_feature_pos) if ($this->useFeaturePosition)
$search->orderByPosition(Criteria::ASC); $search->orderByPosition(Criteria::ASC);
else else
$search->addAscendingOrderByColumn(FeatureTemplateTableMap::POSITION); $search->addAscendingOrderByColumn(FeatureTemplateTableMap::POSITION);
break; break;
case "manual_reverse": case "manual_reverse":
if ($use_feature_pos) if ($this->useFeaturePosition)
$search->orderByPosition(Criteria::DESC); $search->orderByPosition(Criteria::DESC);
else else
$search->addDescendingOrderByColumn(FeatureTemplateTableMap::POSITION); $search->addDescendingOrderByColumn(FeatureTemplateTableMap::POSITION);
@@ -201,26 +199,28 @@ class Feature extends BaseI18nLoop
} }
/* perform search */ return $search;
$features = $this->search($search, $pagination);
$loopResult = new LoopResult($features); }
foreach ($features as $feature) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $feature, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $feature) {
$loopResultRow = new LoopResultRow($feature);
$loopResultRow->set("ID", $feature->getId()) $loopResultRow->set("ID", $feature->getId())
->set("IS_TRANSLATED",$feature->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$feature->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("TITLE",$feature->getVirtualColumn('i18n_TITLE')) ->set("TITLE",$feature->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $feature->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $feature->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $feature->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION", $feature->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $feature->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM", $feature->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("POSITION", $use_feature_pos ? $feature->getPosition() : $feature->getVirtualColumn('position')) ->set("POSITION", $this->useFeaturePosition ? $feature->getPosition() : $feature->getVirtualColumn('position'))
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -43,9 +44,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class FeatureAvailability extends BaseI18nLoop class FeatureAvailability extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -66,17 +67,12 @@ class FeatureAvailability extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = FeatureAvQuery::create(); $search = FeatureAvQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -115,16 +111,17 @@ class FeatureAvailability extends BaseI18nLoop
} }
} }
/* perform search */ return $search;
$featuresAv = $this->search($search, $pagination);
$loopResult = new LoopResult($featuresAv); }
foreach ($featuresAv as $featureAv) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $featureAv, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $featureAv) {
$loopResultRow = new LoopResultRow($featureAv);
$loopResultRow->set("ID", $featureAv->getId()) $loopResultRow->set("ID", $featureAv->getId())
->set("IS_TRANSLATED",$featureAv->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$featureAv->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("TITLE",$featureAv->getVirtualColumn('i18n_TITLE')) ->set("TITLE",$featureAv->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $featureAv->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $featureAv->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $featureAv->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION", $featureAv->getVirtualColumn('i18n_DESCRIPTION'))
@@ -135,5 +132,6 @@ class FeatureAvailability extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -45,9 +46,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class FeatureValue extends BaseI18nLoop class FeatureValue extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -70,17 +71,12 @@ class FeatureValue extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = FeatureProductQuery::create(); $search = FeatureProductQuery::create();
// manage featureAv translations // manage featureAv translations
$locale = $this->configureI18nProcessing( $this->configureI18nProcessing(
$search, $search,
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
FeatureAvTableMap::TABLE_NAME, FeatureAvTableMap::TABLE_NAME,
@@ -127,13 +123,14 @@ class FeatureValue extends BaseI18nLoop
} }
} }
$featureValues = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($featureValues); }
foreach ($featureValues as $featureValue) { public function parseResults(LoopResult $loopResult)
{
$loopResultRow = new LoopResultRow($loopResult, $featureValue, $this->versionable, $this->timestampable, $this->countable); foreach ($loopResult->getResultDataCollection() as $featureValue) {
$loopResultRow = new LoopResultRow($featureValue);
$loopResultRow $loopResultRow
->set("ID" , $featureValue->getId()) ->set("ID" , $featureValue->getId())
@@ -144,7 +141,7 @@ class FeatureValue extends BaseI18nLoop
->set("IS_FREE_TEXT" , is_null($featureValue->getFeatureAvId()) ? 1 : 0) ->set("IS_FREE_TEXT" , is_null($featureValue->getFeatureAvId()) ? 1 : 0)
->set("IS_FEATURE_AV" , is_null($featureValue->getFeatureAvId()) ? 0 : 1) ->set("IS_FEATURE_AV" , is_null($featureValue->getFeatureAvId()) ? 0 : 1)
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("TITLE" , $featureValue->getVirtualColumn(FeatureAvTableMap::TABLE_NAME . '_i18n_TITLE')) ->set("TITLE" , $featureValue->getVirtualColumn(FeatureAvTableMap::TABLE_NAME . '_i18n_TITLE'))
->set("CHAPO" , $featureValue->getVirtualColumn(FeatureAvTableMap::TABLE_NAME . '_i18n_CHAPO')) ->set("CHAPO" , $featureValue->getVirtualColumn(FeatureAvTableMap::TABLE_NAME . '_i18n_CHAPO'))
->set("DESCRIPTION" , $featureValue->getVirtualColumn(FeatureAvTableMap::TABLE_NAME . '_i18n_DESCRIPTION')) ->set("DESCRIPTION" , $featureValue->getVirtualColumn(FeatureAvTableMap::TABLE_NAME . '_i18n_DESCRIPTION'))
@@ -157,5 +154,6 @@ class FeatureValue extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -23,13 +23,13 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Tools\DateTimeFormat;
/** /**
* *
@@ -37,7 +37,7 @@ use Thelia\Tools\DateTimeFormat;
* *
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class Feed extends BaseLoop class Feed extends BaseLoop implements ArraySearchLoopInterface
{ {
public function getArgDefinitions() public function getArgDefinitions()
{ {
@@ -47,12 +47,7 @@ class Feed extends BaseLoop
); );
} }
/** public function buildArray()
*
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$cachedir = THELIA_ROOT . 'cache/feeds'; $cachedir = THELIA_ROOT . 'cache/feeds';
@@ -72,26 +67,15 @@ class Feed extends BaseLoop
$items = $feed->get_items(); $items = $feed->get_items();
$limit = min(count($items), $this->getLimit()); return $items;
$indexes = array(); }
for ($idx = 0; $idx < $limit; $idx++) {
$indexes[] = $idx;
}
$loopResult = new LoopResult($indexes); public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $item) {
foreach ($indexes as $idx) { $loopResultRow = new LoopResultRow();
$item = $items[$idx];
$link = $item->get_permalink();
$title = $item->get_title();
$author = $item->get_author();
$description = $item->get_description();
$loopResultRow = new LoopResultRow($loopResult, null, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow $loopResultRow
->set("URL" , $item->get_permalink()) ->set("URL" , $item->get_permalink())

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -43,10 +44,10 @@ use Thelia\Type\BooleanOrBothType;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Folder extends BaseI18nLoop class Folder extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
public $versionable = true; protected $versionable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -71,17 +72,12 @@ class Folder extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = FolderQuery::create(); $search = FolderQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -148,33 +144,28 @@ class Folder extends BaseI18nLoop
} }
} }
/* perform search */
$folders = $this->search($search, $pagination);
/* @todo */ /* @todo */
$notEmpty = $this->getNot_empty(); $notEmpty = $this->getNot_empty();
$loopResult = new LoopResult($folders); return $search;
foreach ($folders as $folder) { }
/* public function parseResults(LoopResult $loopResult)
* no cause pagination lost : {
* if ($notEmpty && $folder->countAllProducts() == 0) continue; foreach ($loopResult->getResultDataCollection() as $folder) {
*/ $loopResultRow = new LoopResultRow($folder);
$loopResultRow = new LoopResultRow($loopResult, $folder, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow $loopResultRow
->set("ID", $folder->getId()) ->set("ID", $folder->getId())
->set("IS_TRANSLATED",$folder->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$folder->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("TITLE",$folder->getVirtualColumn('i18n_TITLE')) ->set("TITLE",$folder->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $folder->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $folder->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $folder->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION", $folder->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $folder->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM", $folder->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("PARENT", $folder->getParent()) ->set("PARENT", $folder->getParent())
->set("URL", $folder->getUrl($locale)) ->set("URL", $folder->getUrl($this->locale))
->set("CHILD_COUNT", $folder->countChild()) ->set("CHILD_COUNT", $folder->countChild())
->set("CONTENT_COUNT", $folder->countAllContents()) ->set("CONTENT_COUNT", $folder->countAllContents())
->set("VISIBLE", $folder->getVisible() ? "1" : "0") ->set("VISIBLE", $folder->getVisible() ? "1" : "0")
@@ -185,5 +176,6 @@ class Folder extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -22,6 +22,7 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
@@ -35,9 +36,8 @@ use Thelia\Type\BooleanOrBothType;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class FolderPath extends BaseI18nLoop class FolderPath extends BaseI18nLoop implements ArraySearchLoopInterface
{ {
/** /**
* *
* define all args used in your loop * define all args used in your loop
@@ -80,26 +80,14 @@ class FolderPath extends BaseI18nLoop
); );
} }
/** public function buildArray()
*
* this function have to be implement in your own loop class.
*
* All loops parameters can be accessible via getter.
*
* for example, ref parameter is accessible through getRef method
*
* @param $pagination
*
* @return mixed
*/
public function exec(&$pagination)
{ {
$id = $this->getFolder(); $id = $this->getFolder();
$visible = $this->getVisible(); $visible = $this->getVisible();
$search = FolderQuery::create(); $search = FolderQuery::create();
$locale = $this->configureI18nProcessing($search, array('TITLE')); $this->configureI18nProcessing($search, array('TITLE'));
$search->filterById($id); $search->filterById($id);
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible); if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
@@ -113,16 +101,12 @@ class FolderPath extends BaseI18nLoop
if ($folder != null) { if ($folder != null) {
$loopResultRow = new LoopResultRow(); $results[] = array(
"ID" => $result->getId(),
$loopResultRow "TITLE" => $result->getVirtualColumn('i18n_TITLE'),
->set("TITLE",$folder->getVirtualColumn('i18n_TITLE')) "URL" => $result->getUrl($this->locale),
->set("URL", $folder->getUrl($locale)) "LOCALE" => $this->locale,
->set("ID", $folder->getId()) );
->set("LOCALE",$locale)
;
$results[] = $loopResultRow;
$parent = $folder->getParent(); $parent = $folder->getParent();
@@ -146,13 +130,19 @@ class FolderPath extends BaseI18nLoop
} while ($folder != null && $parent > 0); } while ($folder != null && $parent > 0);
// Reverse list and build the final result // Reverse list and build the final result
$results = array_reverse($results); return array_reverse($results);
}
$loopResult = new LoopResult(); public function parseResults(LoopResult $loopResult)
{
foreach($results as $result) $loopResult->addRow($result); foreach($loopResult->getResultDataCollection() as $result) {
$loopResultRow = new LoopResultRow($result);
foreach($result as $output => $outputValue) {
$loopResultRow->set($output, $outputValue);
}
$loopResult->addRow($loopResultRow);
}
return $loopResult; return $loopResult;
} }
} }

View File

@@ -23,6 +23,7 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
@@ -45,7 +46,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class FolderTree extends BaseI18nLoop class FolderTree extends BaseI18nLoop implements ArraySearchLoopInterface
{ {
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -61,13 +62,13 @@ class FolderTree extends BaseI18nLoop
} }
// changement de rubrique // changement de rubrique
protected function buildFolderTree($parent, $visible, $level, $max_level, $exclude, LoopResult &$loopResult) protected function buildFolderTree($parent, $visible, $level, $max_level, $exclude, &$resultsList)
{ {
if ($level > $max_level) return; if ($level > $max_level) return;
$search = FolderQuery::create(); $search = FolderQuery::create();
$locale = $this->configureI18nProcessing($search, array( $this->configureI18nProcessing($search, array(
'TITLE' 'TITLE'
)); ));
@@ -83,36 +84,44 @@ class FolderTree extends BaseI18nLoop
foreach ($results as $result) { foreach ($results as $result) {
$loopResultRow = new LoopResultRow(); $resultsList[] = array(
"ID" => $result->getId(),
"TITLE" => $result->getVirtualColumn('i18n_TITLE'),
"PARENT" => $result->getParent(),
"URL" => $result->getUrl($this->locale),
"VISIBLE" => $result->getVisible() ? "1" : "0",
"LEVEL" => $level,
'CHILD_COUNT' => $result->countChild(),
);
$loopResultRow $this->buildFolderTree($result->getId(), $visible, 1 + $level, $max_level, $exclude, $resultsList);
->set("ID", $result->getId())->set("TITLE", $result->getVirtualColumn('i18n_TITLE'))
->set("PARENT", $result->getParent())->set("URL", $result->getUrl($locale))
->set("VISIBLE", $result->getVisible() ? "1" : "0")->set("LEVEL", $level)
;
$loopResult->addRow($loopResultRow);
$this->buildFolderTree($result->getId(), $visible, 1 + $level, $max_level, $exclude, $loopResult);
} }
} }
/** public function parseResults(LoopResult $loopResult)
* @param $pagination (ignored) {
* foreach($loopResult->getResultDataCollection() as $result) {
* @return \Thelia\Core\Template\Element\LoopResult $loopResultRow = new LoopResultRow($result);
*/ foreach($result as $output => $outputValue) {
public function exec(&$pagination) $loopResultRow->set($output, $outputValue);
}
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
public function buildArray()
{ {
$id = $this->getFolder(); $id = $this->getFolder();
$depth = $this->getDepth(); $depth = $this->getDepth();
$visible = $this->getVisible(); $visible = $this->getVisible();
$exclude = $this->getExclude(); $exclude = $this->getExclude();
$loopResult = new LoopResult(); $resultsList = array();
$this->buildFolderTree($id, $visible, 0, $depth, $exclude, $loopResult); $this->buildFolderTree($id, $visible, 0, $depth, $exclude, $resultsList);
return $loopResult; return $resultsList;
} }
} }

View File

@@ -23,6 +23,7 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Event\Image\ImageEvent; use Thelia\Core\Event\Image\ImageEvent;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
@@ -41,9 +42,12 @@ use Thelia\Log\Tlog;
* *
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class Image extends BaseI18nLoop class Image extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $objectType;
protected $objectId;
protected $timestampable = true;
/** /**
* @var array Possible image sources * @var array Possible image sources
@@ -210,19 +214,16 @@ class Image extends BaseI18nLoop
return $search; return $search;
} }
/** public function buildModelCriteria()
* @param unknown $pagination
*/
public function exec(&$pagination)
{ {
// Select the proper query to use, and get the object type // Select the proper query to use, and get the object type
$object_type = $object_id = null; $this->objectType = $this->objectId = null;
$search = $this->getSearchQuery($object_type, $object_id); $search = $this->getSearchQuery($this->objectType, $this->objectId);
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -234,6 +235,14 @@ class Image extends BaseI18nLoop
if (!is_null($exclude)) if (!is_null($exclude))
$search->filterById($exclude, Criteria::NOT_IN); $search->filterById($exclude, Criteria::NOT_IN);
// echo "sql=".$search->toString();
return $search;
}
public function parseResults(LoopResult $loopResult)
{
// Create image processing event // Create image processing event
$event = new ImageEvent($this->request); $event = new ImageEvent($this->request);
@@ -264,16 +273,11 @@ class Image extends BaseI18nLoop
} }
// echo "sql=".$search->toString(); foreach ($loopResult->getResultDataCollection() as $result) {
$results = $this->search($search, $pagination);
$loopResult = new LoopResult($results);
foreach ($results as $result) {
// Create image processing event // Create image processing event
$event = new ImageEvent($this->request);
// ERO : following is duplicated, guess it's useless at this point
//$event = new ImageEvent($this->request);
// Setup required transformations // Setup required transformations
if (! is_null($width)) $event->setWidth($width); if (! is_null($width)) $event->setWidth($width);
@@ -288,22 +292,22 @@ class Image extends BaseI18nLoop
$source_filepath = sprintf("%s%s/%s/%s", $source_filepath = sprintf("%s%s/%s/%s",
THELIA_ROOT, THELIA_ROOT,
ConfigQuery::read('images_library_path', 'local/media/images'), ConfigQuery::read('images_library_path', 'local/media/images'),
$object_type, $this->objectType,
$result->getFile() $result->getFile()
); );
$event->setSourceFilepath($source_filepath); $event->setSourceFilepath($source_filepath);
$event->setCacheSubdirectory($object_type); $event->setCacheSubdirectory($this->objectType);
try { try {
// Dispatch image processing event // Dispatch image processing event
$this->dispatcher->dispatch(TheliaEvents::IMAGE_PROCESS, $event); $this->dispatcher->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($result);
$loopResultRow $loopResultRow
->set("ID" , $result->getId()) ->set("ID" , $result->getId())
->set("LOCALE" ,$locale) ->set("LOCALE" ,$this->locale)
->set("IMAGE_URL" , $event->getFileUrl()) ->set("IMAGE_URL" , $event->getFileUrl())
->set("ORIGINAL_IMAGE_URL" , $event->getOriginalFileUrl()) ->set("ORIGINAL_IMAGE_URL" , $event->getOriginalFileUrl())
->set("IMAGE_PATH" , $event->getCacheFilepath()) ->set("IMAGE_PATH" , $event->getCacheFilepath())
@@ -313,8 +317,8 @@ class Image extends BaseI18nLoop
->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("POSITION" , $result->getPosition()) ->set("POSITION" , $result->getPosition())
->set("OBJECT_TYPE" , $object_type) ->set("OBJECT_TYPE" , $this->objectType)
->set("OBJECT_ID" , $object_id) ->set("OBJECT_ID" , $this->objectId)
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
@@ -325,5 +329,6 @@ class Image extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; 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\Argument;
use Thelia\Model\LangQuery; use Thelia\Model\LangQuery;
@@ -43,9 +44,9 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class Lang extends BaseLoop class Lang extends BaseLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -59,12 +60,7 @@ class Lang extends BaseLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination (ignored)
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$id = $this->getId(); $id = $this->getId();
$exclude = $this->getExclude(); $exclude = $this->getExclude();
@@ -84,13 +80,14 @@ class Lang extends BaseLoop
$search->orderByPosition(Criteria::ASC); $search->orderByPosition(Criteria::ASC);
$results = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($results); }
foreach ($results as $result) { public function parseResults(LoopResult $loopResult)
{
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable); foreach ($loopResult->getResultDataCollection() as $result) {
$loopResultRow = new LoopResultRow($result);
$loopResultRow $loopResultRow
->set("ID", $result->getId()) ->set("ID", $result->getId())
@@ -108,5 +105,6 @@ class Lang extends BaseLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; 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\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
@@ -46,9 +47,9 @@ use Thelia\Type\BooleanOrBothType;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class Message extends BaseI18nLoop class Message extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -64,20 +65,16 @@ class Message extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination (ignored)
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$id = $this->getId(); $id = $this->getId();
$name = $this->getVariable(); $name = $this->getVariable();
$secured = $this->getSecured(); $secured = $this->getSecured();
$exclude = $this->getExclude();
$search = MessageQuery::create(); $search = MessageQuery::create();
$locale = $this->configureI18nProcessing($search, array( $this->configureI18nProcessing($search, array(
'TITLE', 'TITLE',
'SUBJECT', 'SUBJECT',
'TEXT_MESSAGE', 'TEXT_MESSAGE',
@@ -100,19 +97,20 @@ class Message extends BaseI18nLoop
$search->orderByName(Criteria::ASC); $search->orderByName(Criteria::ASC);
$results = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($results); }
foreach ($results as $result) { public function parseResults(LoopResult $loopResult)
{
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable); foreach ($loopResult->getResultDataCollection() as $result) {
$loopResultRow = new LoopResultRow($result);
$loopResultRow $loopResultRow
->set("ID" , $result->getId()) ->set("ID" , $result->getId())
->set("NAME" , $result->getName()) ->set("NAME" , $result->getName())
->set("IS_TRANSLATED", $result->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED", $result->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("TITLE" , $result->getVirtualColumn('i18n_TITLE')) ->set("TITLE" , $result->getVirtualColumn('i18n_TITLE'))
->set("SUBJECT" , $result->getVirtualColumn('i18n_SUBJECT')) ->set("SUBJECT" , $result->getVirtualColumn('i18n_SUBJECT'))
->set("TEXT_MESSAGE" , $result->getVirtualColumn('i18n_TEXT_MESSAGE')) ->set("TEXT_MESSAGE" , $result->getVirtualColumn('i18n_TEXT_MESSAGE'))
@@ -124,5 +122,6 @@ class Message extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -29,6 +29,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -46,9 +47,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Module extends BaseI18nLoop class Module extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -79,17 +80,12 @@ class Module extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = ModuleQuery::create(); $search = ModuleQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -131,16 +127,17 @@ class Module extends BaseI18nLoop
$search->orderByPosition(); $search->orderByPosition();
/* perform search */ return $search;
$modules = $this->search($search, $pagination);
$loopResult = new LoopResult($modules); }
foreach ($modules as $module) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $module, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $module) {
$loopResultRow = new LoopResultRow($module);
$loopResultRow->set("ID", $module->getId()) $loopResultRow->set("ID", $module->getId())
->set("IS_TRANSLATED",$module->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$module->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("TITLE",$module->getVirtualColumn('i18n_TITLE')) ->set("TITLE",$module->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $module->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $module->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $module->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION", $module->getVirtualColumn('i18n_DESCRIPTION'))
@@ -151,7 +148,7 @@ class Module extends BaseI18nLoop
->set("CLASS", $module->getFullNamespace()) ->set("CLASS", $module->getFullNamespace())
->set("POSITION", $module->getPosition()); ->set("POSITION", $module->getPosition());
if (null !== $profile) { if (null !== $this->getProfile()) {
$accessValue = $module->getVirtualColumn('access'); $accessValue = $module->getVirtualColumn('access');
$manager = new AccessManager($accessValue); $manager = new AccessManager($accessValue);
@@ -165,5 +162,6 @@ class Module extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Element\SearchLoopInterface; use Thelia\Core\Template\Element\SearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -43,11 +44,11 @@ use Thelia\Type;
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Order extends BaseLoop implements SearchLoopInterface class Order extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInterface
{ {
public $countable = true; protected $countable = true;
public $timestampable = true; protected $timestampable = true;
public $versionable = false; protected $versionable = false;
public function getArgDefinitions() public function getArgDefinitions()
{ {
@@ -131,12 +132,7 @@ class Order extends BaseLoop implements SearchLoopInterface
} }
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return LoopResult
*/
public function exec(&$pagination)
{ {
$search = OrderQuery::create(); $search = OrderQuery::create();
@@ -151,7 +147,7 @@ class Order extends BaseLoop implements SearchLoopInterface
if ($customer === 'current') { if ($customer === 'current') {
$currentCustomer = $this->securityContext->getCustomerUser(); $currentCustomer = $this->securityContext->getCustomerUser();
if ($currentCustomer === null) { if ($currentCustomer === null) {
return new LoopResult(); return null;
} else { } else {
$search->filterByCustomerId($currentCustomer->getId(), Criteria::EQUAL); $search->filterByCustomerId($currentCustomer->getId(), Criteria::EQUAL);
} }
@@ -178,14 +174,16 @@ class Order extends BaseLoop implements SearchLoopInterface
} }
} }
$orders = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($orders); }
foreach ($orders as $order) { public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $order) {
$tax = 0; $tax = 0;
$amount = $order->getTotalAmount($tax); $amount = $order->getTotalAmount($tax);
$loopResultRow = new LoopResultRow($loopResult, $order, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($order);
$loopResultRow $loopResultRow
->set("ID", $order->getId()) ->set("ID", $order->getId())
->set("REF", $order->getRef()) ->set("REF", $order->getRef())
@@ -213,5 +211,6 @@ class Order extends BaseLoop implements SearchLoopInterface
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -42,9 +43,9 @@ use Thelia\Model\OrderAddressQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class OrderAddress extends BaseLoop class OrderAddress extends BaseLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -56,12 +57,7 @@ class OrderAddress extends BaseLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = OrderAddressQuery::create(); $search = OrderAddressQuery::create();
@@ -69,12 +65,14 @@ class OrderAddress extends BaseLoop
$search->filterById($id, Criteria::IN); $search->filterById($id, Criteria::IN);
$orderAddresses = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($orderAddresses); }
foreach ($orderAddresses as $orderAddress) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $orderAddress, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $orderAddress) {
$loopResultRow = new LoopResultRow($orderAddress);
$loopResultRow $loopResultRow
->set("ID", $orderAddress->getId()) ->set("ID", $orderAddress->getId())
->set("TITLE", $orderAddress->getCustomerTitleId()) ->set("TITLE", $orderAddress->getCustomerTitleId())
@@ -94,5 +92,6 @@ class OrderAddress extends BaseLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -41,9 +42,9 @@ use Thelia\Model\Base\OrderProductQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class OrderProduct extends BaseLoop class OrderProduct extends BaseLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -55,13 +56,7 @@ class OrderProduct extends BaseLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
* @throws \InvalidArgumentException
*/
public function exec(&$pagination)
{ {
$search = OrderProductQuery::create(); $search = OrderProductQuery::create();
@@ -76,44 +71,47 @@ class OrderProduct extends BaseLoop
$search->orderById(Criteria::ASC); $search->orderById(Criteria::ASC);
$products = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($products); }
foreach ($products as $product) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $product, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $orderProduct) {
$loopResultRow = new LoopResultRow($orderProduct);
$price = $product->getPrice(); $price = $orderProduct->getPrice();
$taxedPrice = $price + round($product->getVirtualColumn('TOTAL_TAX'), 2); $taxedPrice = $price + round($orderProduct->getVirtualColumn('TOTAL_TAX'), 2);
$promoPrice = $product->getPromoPrice(); $promoPrice = $orderProduct->getPromoPrice();
$taxedPromoPrice = $promoPrice + round($product->getVirtualColumn('TOTAL_PROMO_TAX'), 2); $taxedPromoPrice = $promoPrice + round($orderProduct->getVirtualColumn('TOTAL_PROMO_TAX'), 2);
$loopResultRow->set("ID", $product->getId()) $loopResultRow->set("ID", $orderProduct->getId())
->set("REF", $product->getProductRef()) ->set("REF", $orderProduct->getProductRef())
->set("PRODUCT_SALE_ELEMENTS_REF", $product->getProductSaleElementsRef()) ->set("PRODUCT_SALE_ELEMENTS_REF", $orderProduct->getProductSaleElementsRef())
->set("WAS_NEW", $product->getWasNew() === 1 ? 1 : 0) ->set("WAS_NEW", $orderProduct->getWasNew() === 1 ? 1 : 0)
->set("WAS_IN_PROMO", $product->getWasInPromo() === 1 ? 1 : 0) ->set("WAS_IN_PROMO", $orderProduct->getWasInPromo() === 1 ? 1 : 0)
->set("WEIGHT", $product->getWeight()) ->set("WEIGHT", $orderProduct->getWeight())
->set("TITLE", $product->getTitle()) ->set("TITLE", $orderProduct->getTitle())
->set("CHAPO", $product->getChapo()) ->set("CHAPO", $orderProduct->getChapo())
->set("DESCRIPTION", $product->getDescription()) ->set("DESCRIPTION", $orderProduct->getDescription())
->set("POSTSCRIPTUM", $product->getPostscriptum()) ->set("POSTSCRIPTUM", $orderProduct->getPostscriptum())
->set("QUANTITY", $product->getQuantity()) ->set("QUANTITY", $orderProduct->getQuantity())
->set("PRICE", $price) ->set("PRICE", $price)
->set("PRICE_TAX", $taxedPrice - $price) ->set("PRICE_TAX", $taxedPrice - $price)
->set("TAXED_PRICE", $taxedPrice) ->set("TAXED_PRICE", $taxedPrice)
->set("PROMO_PRICE", $promoPrice) ->set("PROMO_PRICE", $promoPrice)
->set("PROMO_PRICE_TAX", $taxedPromoPrice - $promoPrice) ->set("PROMO_PRICE_TAX", $taxedPromoPrice - $promoPrice)
->set("TAXED_PROMO_PRICE", $taxedPromoPrice) ->set("TAXED_PROMO_PRICE", $taxedPromoPrice)
->set("TAX_RULE_TITLE", $product->getTaxRuleTitle()) ->set("TAX_RULE_TITLE", $orderProduct->getTaxRuleTitle())
->set("TAX_RULE_DESCRIPTION", $product->getTaxRuledescription()) ->set("TAX_RULE_DESCRIPTION", $orderProduct->getTaxRuledescription())
->set("PARENT", $product->getParent()) ->set("PARENT", $orderProduct->getParent())
->set("EAN_CODE", $product->getEanCode()) ->set("EAN_CODE", $orderProduct->getEanCode())
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -43,9 +44,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class OrderProductAttributeCombination extends BaseI18nLoop class OrderProductAttributeCombination extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -64,12 +65,7 @@ class OrderProductAttributeCombination extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = OrderProductAttributeCombinationQuery::create(); $search = OrderProductAttributeCombinationQuery::create();
@@ -90,28 +86,30 @@ class OrderProductAttributeCombination extends BaseI18nLoop
} }
} }
$attributeCombinations = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($attributeCombinations); }
foreach ($attributeCombinations as $attributeCombination) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $attributeCombination, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $orderAttributeCombination) {
$loopResultRow = new LoopResultRow($orderAttributeCombination);
$loopResultRow $loopResultRow
->set("LOCALE",$locale) ->set("ATTRIBUTE_TITLE", $orderAttributeCombination->getAttributeTitle())
->set("ATTRIBUTE_TITLE", $attributeCombination->getAttributeTitle()) ->set("ATTRIBUTE_CHAPO", $orderAttributeCombination->getAttributeChapo())
->set("ATTRIBUTE_CHAPO", $attributeCombination->getAttributeChapo()) ->set("ATTRIBUTE_DESCRIPTION", $orderAttributeCombination->getAttributeDescription())
->set("ATTRIBUTE_DESCRIPTION", $attributeCombination->getAttributeDescription()) ->set("ATTRIBUTE_POSTSCRIPTUM", $orderAttributeCombination->getAttributePostscriptum())
->set("ATTRIBUTE_POSTSCRIPTUM", $attributeCombination->getAttributePostscriptum()) ->set("ATTRIBUTE_AVAILABILITY_TITLE", $orderAttributeCombination->getAttributeAvTitle())
->set("ATTRIBUTE_AVAILABILITY_TITLE", $attributeCombination->getAttributeAvTitle()) ->set("ATTRIBUTE_AVAILABILITY_CHAPO", $orderAttributeCombination->getAttributeAvChapo())
->set("ATTRIBUTE_AVAILABILITY_CHAPO", $attributeCombination->getAttributeAvChapo()) ->set("ATTRIBUTE_AVAILABILITY_DESCRIPTION", $orderAttributeCombination->getAttributeAvDescription())
->set("ATTRIBUTE_AVAILABILITY_DESCRIPTION", $attributeCombination->getAttributeAvDescription()) ->set("ATTRIBUTE_AVAILABILITY_POSTSCRIPTUM", $orderAttributeCombination->getAttributeAvPostscriptum())
->set("ATTRIBUTE_AVAILABILITY_POSTSCRIPTUM", $attributeCombination->getAttributeAvPostscriptum())
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -42,9 +43,9 @@ use Thelia\Model\OrderStatusQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class OrderStatus extends BaseI18nLoop class OrderStatus extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -56,17 +57,12 @@ class OrderStatus extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = OrderStatusQuery::create(); $search = OrderStatusQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -74,16 +70,17 @@ class OrderStatus extends BaseI18nLoop
$search->filterById($id, Criteria::IN); $search->filterById($id, Criteria::IN);
} }
/* perform search */ return $search;
$orderStatusList = $this->search($search, $pagination);
$loopResult = new LoopResult($orderStatusList); }
foreach ($orderStatusList as $orderStatus) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $orderStatus, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $orderStatus) {
$loopResultRow = new LoopResultRow($orderStatus);
$loopResultRow->set("ID", $orderStatus->getId()) $loopResultRow->set("ID", $orderStatus->getId())
->set("IS_TRANSLATED",$orderStatus->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$orderStatus->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("CODE", $orderStatus->getCode()) ->set("CODE", $orderStatus->getCode())
->set("TITLE", $orderStatus->getVirtualColumn('i18n_TITLE')) ->set("TITLE", $orderStatus->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $orderStatus->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $orderStatus->getVirtualColumn('i18n_CHAPO'))
@@ -95,5 +92,6 @@ class OrderStatus extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -22,9 +22,9 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Module\BaseModule; use Thelia\Module\BaseModule;
/** /**
@@ -32,7 +32,7 @@ use Thelia\Module\BaseModule;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@gmail.com> * @author Etienne Roudeix <eroudeix@gmail.com>
*/ */
class Payment extends BaseSpecificModule class Payment extends BaseSpecificModule implements PropelSearchLoopInterface
{ {
public function getArgDefinitions() public function getArgDefinitions()
@@ -42,21 +42,10 @@ class Payment extends BaseSpecificModule
return $collection; return $collection;
} }
public function exec(&$pagination) public function parseResults(LoopResult $loopResult)
{ {
$search = parent::exec($pagination); foreach ($loopResult->getResultDataCollection() as $paymentModule) {
/* manage translations */ $loopResultRow = new LoopResultRow($paymentModule);
$locale = $this->configureI18nProcessing($search);
$search->filterByType(BaseModule::PAYMENT_MODULE_TYPE, Criteria::EQUAL);
/* perform search */
$paymentModules = $this->search($search, $pagination);
$loopResult = new LoopResult($paymentModules);
foreach ($paymentModules as $paymentModule) {
$loopResultRow = new LoopResultRow($loopResult, $paymentModule, $this->versionable, $this->timestampable, $this->countable);
$moduleReflection = new \ReflectionClass($paymentModule->getFullNamespace()); $moduleReflection = new \ReflectionClass($paymentModule->getFullNamespace());
if ($moduleReflection->isSubclassOf("Thelia\Module\PaymentModuleInterface") === false) { if ($moduleReflection->isSubclassOf("Thelia\Module\PaymentModuleInterface") === false) {
@@ -80,4 +69,9 @@ class Payment extends BaseSpecificModule
return $loopResult; return $loopResult;
} }
protected function getModuleType()
{
return BaseModule::PAYMENT_MODULE_TYPE;
}
} }

View File

@@ -29,6 +29,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Element\SearchLoopInterface; use Thelia\Core\Template\Element\SearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -52,10 +53,10 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Product extends BaseI18nLoop implements SearchLoopInterface class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
public $versionable = true; protected $versionable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -161,17 +162,11 @@ class Product extends BaseI18nLoop implements SearchLoopInterface
} }
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
* @throws \InvalidArgumentException
*/
public function exec(&$pagination)
{ {
$complex = $this->getComplex(); $complex = $this->getComplex();
if (true === $complex) { if (true === $complex) {
return $this->execComplex($pagination); return $this->buildComplex();
} }
$currencyId = $this->getCurrency(); $currencyId = $this->getCurrency();
@@ -227,7 +222,7 @@ class Product extends BaseI18nLoop implements SearchLoopInterface
} }
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -459,16 +454,21 @@ class Product extends BaseI18nLoop implements SearchLoopInterface
} }
} }
/* perform search */ return $search;
$products = $this->search($search, $pagination); }
$loopResult = new LoopResult($products); public function parseResults(LoopResult $loopResult)
{
$complex = $this->getComplex();
if (true === $complex) {
return $this->parseComplex($loopResult);
}
$taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic $taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic
foreach ($products as $product) { foreach ($loopResult->getResultDataCollection() as $product) {
$loopResultRow = new LoopResultRow($loopResult, $product, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($product);
$price = $product->getVirtualColumn('price'); $price = $product->getVirtualColumn('price');
try { try {
@@ -512,12 +512,12 @@ class Product extends BaseI18nLoop implements SearchLoopInterface
->set("ID" , $product->getId()) ->set("ID" , $product->getId())
->set("REF" , $product->getRef()) ->set("REF" , $product->getRef())
->set("IS_TRANSLATED" , $product->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED" , $product->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("TITLE" , $product->getVirtualColumn('i18n_TITLE')) ->set("TITLE" , $product->getVirtualColumn('i18n_TITLE'))
->set("CHAPO" , $product->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO" , $product->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION" , $product->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION" , $product->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $product->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM" , $product->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("URL" , $product->getUrl($locale)) ->set("URL" , $product->getUrl($this->locale))
->set("BEST_PRICE" , $product->getVirtualColumn('is_promo') ? $promoPrice : $price) ->set("BEST_PRICE" , $product->getVirtualColumn('is_promo') ? $promoPrice : $price)
->set("BEST_PRICE_TAX" , $taxedPrice - $product->getVirtualColumn('is_promo') ? $taxedPromoPrice - $promoPrice : $taxedPrice - $price) ->set("BEST_PRICE_TAX" , $taxedPrice - $product->getVirtualColumn('is_promo') ? $taxedPromoPrice - $promoPrice : $taxedPrice - $price)
->set("BEST_TAXED_PRICE" , $product->getVirtualColumn('is_promo') ? $taxedPromoPrice : $taxedPrice) ->set("BEST_TAXED_PRICE" , $product->getVirtualColumn('is_promo') ? $taxedPromoPrice : $taxedPrice)
@@ -551,13 +551,7 @@ class Product extends BaseI18nLoop implements SearchLoopInterface
return $loopResult; return $loopResult;
} }
/** public function buildComplex()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
* @throws \InvalidArgumentException
*/
public function execComplex(&$pagination)
{ {
$currencyId = $this->getCurrency(); $currencyId = $this->getCurrency();
if (null !== $currencyId) { if (null !== $currencyId) {
@@ -575,7 +569,7 @@ class Product extends BaseI18nLoop implements SearchLoopInterface
$search = ProductQuery::create(); $search = ProductQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$attributeNonStrictMatch = $this->getAttribute_non_strict_match(); $attributeNonStrictMatch = $this->getAttribute_non_strict_match();
$isPSELeftJoinList = array(); $isPSELeftJoinList = array();
@@ -978,16 +972,18 @@ class Product extends BaseI18nLoop implements SearchLoopInterface
} }
} }
/* perform search */ return $search;
$products = $this->search($search, $pagination); }
$loopResult = new LoopResult($products); public function parseComplex(LoopResult $results)
{
$loopResult = new LoopResult($results);
$taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic $taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic
foreach ($products as $product) { foreach ($loopResult->getResultDataCollection() as $product) {
$loopResultRow = new LoopResultRow($loopResult, $product, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($product);
$price = $product->getRealLowestPrice(); $price = $product->getRealLowestPrice();
@@ -1023,12 +1019,12 @@ class Product extends BaseI18nLoop implements SearchLoopInterface
->set("ID" , $product->getId()) ->set("ID" , $product->getId())
->set("REF" , $product->getRef()) ->set("REF" , $product->getRef())
->set("IS_TRANSLATED" , $product->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED" , $product->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("TITLE" , $product->getVirtualColumn('i18n_TITLE')) ->set("TITLE" , $product->getVirtualColumn('i18n_TITLE'))
->set("CHAPO" , $product->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO" , $product->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION" , $product->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION" , $product->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $product->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM" , $product->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("URL" , $product->getUrl($locale)) ->set("URL" , $product->getUrl($this->locale))
->set("BEST_PRICE" , $price) ->set("BEST_PRICE" , $price)
->set("BEST_PRICE_TAX" , $taxedPrice - $price) ->set("BEST_PRICE_TAX" , $taxedPrice - $price)
->set("BEST_TAXED_PRICE" , $taxedPrice) ->set("BEST_TAXED_PRICE" , $taxedPrice)

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -49,9 +50,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class ProductSaleElements extends BaseLoop class ProductSaleElements extends BaseLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -77,13 +78,7 @@ class ProductSaleElements extends BaseLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
* @throws \InvalidArgumentException
*/
public function exec(&$pagination)
{ {
$search = ProductSaleElementsQuery::create(); $search = ProductSaleElementsQuery::create();
@@ -144,14 +139,16 @@ class ProductSaleElements extends BaseLoop
$search->groupById(); $search->groupById();
$PSEValues = $this->search($search, $pagination); return $search;
$loopResult = new LoopResult($PSEValues); }
public function parseResults(LoopResult $loopResult)
{
$taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic $taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic
foreach ($PSEValues as $PSEValue) { foreach ($loopResult->getResultDataCollection() as $PSEValue) {
$loopResultRow = new LoopResultRow($loopResult, $PSEValue, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($PSEValue);
$price = $PSEValue->getPrice(); $price = $PSEValue->getPrice();
try { try {
@@ -189,5 +186,6 @@ class ProductSaleElements extends BaseLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -42,13 +43,13 @@ use Thelia\Model\Base\TemplateQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class ProductTemplate extends BaseI18nLoop class ProductTemplate extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
*/ */
protected function getArgDefinitions() protected function getArgDefinitions()
{ {
return new ArgumentCollection( return new ArgumentCollection(
@@ -57,12 +58,7 @@ class ProductTemplate extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = TemplateQuery::create(); $search = TemplateQuery::create();
@@ -71,7 +67,7 @@ class ProductTemplate extends BaseI18nLoop
$lang = $this->getLang(); $lang = $this->getLang();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search, $columns = array('NAME')); $this->configureI18nProcessing($search, $columns = array('NAME'));
$id = $this->getId(); $id = $this->getId();
@@ -85,19 +81,21 @@ class ProductTemplate extends BaseI18nLoop
$search->filterById($exclude, Criteria::NOT_IN); $search->filterById($exclude, Criteria::NOT_IN);
} }
/* perform search */ return $search;
$templates = $this->search($search, $pagination);
$loopResult = new LoopResult($templates); }
foreach ($templates as $template) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $template, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $template) {
$loopResultRow = new LoopResultRow($template);
$loopResultRow $loopResultRow
->set("ID", $template->getId()) ->set("ID", $template->getId())
->set("IS_TRANSLATED" , $template->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED" , $template->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("NAME" , $template->getVirtualColumn('i18n_NAME')) ->set("NAME" , $template->getVirtualColumn('i18n_NAME'))
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -43,9 +44,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Profile extends BaseI18nLoop class Profile extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -57,17 +58,12 @@ class Profile extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = ProfileQuery::create(); $search = ProfileQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -77,16 +73,17 @@ class Profile extends BaseI18nLoop
$search->orderById(Criteria::ASC); $search->orderById(Criteria::ASC);
/* perform search */ return $search;
$profiles = $this->search($search, $pagination);
$loopResult = new LoopResult($profiles); }
foreach ($profiles as $profile) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $profile, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $profile) {
$loopResultRow = new LoopResultRow($profile);
$loopResultRow->set("ID", $profile->getId()) $loopResultRow->set("ID", $profile->getId())
->set("IS_TRANSLATED",$profile->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$profile->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("CODE",$profile->getCode()) ->set("CODE",$profile->getCode())
->set("TITLE",$profile->getVirtualColumn('i18n_TITLE')) ->set("TITLE",$profile->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $profile->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $profile->getVirtualColumn('i18n_CHAPO'))

View File

@@ -29,6 +29,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -44,9 +45,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Resource extends BaseI18nLoop class Resource extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -64,17 +65,12 @@ class Resource extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = ResourceQuery::create(); $search = ResourceQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search); $this->configureI18nProcessing($search);
$profile = $this->getProfile(); $profile = $this->getProfile();
@@ -92,16 +88,17 @@ class Resource extends BaseI18nLoop
$search->orderById(Criteria::ASC); $search->orderById(Criteria::ASC);
/* perform search */ return $search;
$resources = $this->search($search, $pagination);
$loopResult = new LoopResult($resources); }
foreach ($resources as $resource) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $resource, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $resource) {
$loopResultRow = new LoopResultRow($resource);
$loopResultRow->set("ID", $resource->getId()) $loopResultRow->set("ID", $resource->getId())
->set("IS_TRANSLATED",$resource->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$resource->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("CODE",$resource->getCode()) ->set("CODE",$resource->getCode())
->set("TITLE",$resource->getVirtualColumn('i18n_TITLE')) ->set("TITLE",$resource->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $resource->getVirtualColumn('i18n_CHAPO')) ->set("CHAPO", $resource->getVirtualColumn('i18n_CHAPO'))
@@ -109,7 +106,7 @@ class Resource extends BaseI18nLoop
->set("POSTSCRIPTUM", $resource->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSTSCRIPTUM", $resource->getVirtualColumn('i18n_POSTSCRIPTUM'))
; ;
if (null !== $profile) { if (null !== $this->getProfile()) {
$accessValue = $resource->getVirtualColumn('access'); $accessValue = $resource->getVirtualColumn('access');
$manager = new AccessManager($accessValue); $manager = new AccessManager($accessValue);
@@ -123,5 +120,6 @@ class Resource extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -45,9 +46,9 @@ use Thelia\Model\TaxQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Tax extends BaseI18nLoop class Tax extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -70,17 +71,12 @@ class Tax extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = TaxQuery::create(); $search = TaxQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION')); $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION'));
$id = $this->getId(); $id = $this->getId();
@@ -142,21 +138,21 @@ class Tax extends BaseI18nLoop
} }
} }
/* perform search */ return $search;
$taxes = $this->search($search, $pagination);
$loopResult = new LoopResult($taxes); }
foreach ($taxes as $tax) { public function parseResults(LoopResult $loopResult)
{
$loopResultRow = new LoopResultRow($loopResult, $tax, $this->versionable, $this->timestampable, $this->countable); foreach ($loopResult->getResultDataCollection() as $tax) {
$loopResultRow = new LoopResultRow($tax);
$loopResultRow $loopResultRow
->set("ID" , $tax->getId()) ->set("ID" , $tax->getId())
->set("TYPE" , $tax->getType()) ->set("TYPE" , $tax->getType())
->set("REQUIREMENTS" , $tax->getRequirements()) ->set("REQUIREMENTS" , $tax->getRequirements())
->set("IS_TRANSLATED" , $tax->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED" , $tax->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("TITLE" , $tax->getVirtualColumn('i18n_TITLE')) ->set("TITLE" , $tax->getVirtualColumn('i18n_TITLE'))
->set("DESCRIPTION" , $tax->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION" , $tax->getVirtualColumn('i18n_DESCRIPTION'))
; ;
@@ -165,5 +161,6 @@ class Tax extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -44,9 +45,9 @@ use Thelia\Model\TaxRuleQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class TaxRule extends BaseI18nLoop class TaxRule extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -66,17 +67,12 @@ class TaxRule extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = TaxRuleQuery::create(); $search = TaxRuleQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION')); $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION'));
$id = $this->getId(); $id = $this->getId();
@@ -109,27 +105,28 @@ class TaxRule extends BaseI18nLoop
} }
} }
/* perform search */ return $search;
$tax_rules = $this->search($search, $pagination);
$loopResult = new LoopResult($tax_rules); }
foreach ($tax_rules as $tax_rule) { public function parseResults(LoopResult $loopResult)
{
$loopResultRow = new LoopResultRow($loopResult, $tax_rule, $this->versionable, $this->timestampable, $this->countable); foreach ($loopResult->getResultDataCollection() as $taxRule) {
$loopResultRow = new LoopResultRow($taxRule);
$loopResultRow $loopResultRow
->set("ID" , $tax_rule->getId()) ->set("ID" , $taxRule->getId())
->set("IS_TRANSLATED" , $tax_rule->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED" , $taxRule->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale) ->set("LOCALE" , $this->locale)
->set("TITLE" , $tax_rule->getVirtualColumn('i18n_TITLE')) ->set("TITLE" , $taxRule->getVirtualColumn('i18n_TITLE'))
->set("DESCRIPTION" , $tax_rule->getVirtualColumn('i18n_DESCRIPTION')) ->set("DESCRIPTION" , $taxRule->getVirtualColumn('i18n_DESCRIPTION'))
->set("IS_DEFAULT" , $tax_rule->getIsDefault() ? '1' : '0') ->set("IS_DEFAULT" , $taxRule->getIsDefault() ? '1' : '0')
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -29,6 +29,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -49,9 +50,11 @@ use Thelia\Model\TaxRuleCountryQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class TaxRuleCountry extends BaseI18nLoop class TaxRuleCountry extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $taxCountForOriginCountry;
protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -71,12 +74,7 @@ class TaxRuleCountry extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = TaxRuleCountryQuery::create(); $search = TaxRuleCountryQuery::create();
@@ -86,9 +84,9 @@ class TaxRuleCountry extends BaseI18nLoop
$taxRule = $this->getTax_rule(); $taxRule = $this->getTax_rule();
if ($ask === 'countries') { if ($ask === 'countries') {
$taxCountForOriginCountry = TaxRuleCountryQuery::create()->filterByCountryId($country)->count(); $this->taxCountForOriginCountry = TaxRuleCountryQuery::create()->filterByCountryId($country)->count();
if ($taxCountForOriginCountry > 0) { if ($this->taxCountForOriginCountry > 0) {
$search->groupByCountryId(); $search->groupByCountryId();
$originalCountryJoin = new Join(); $originalCountryJoin = new Join();
@@ -101,7 +99,7 @@ class TaxRuleCountry extends BaseI18nLoop
$search->addJoinObject($originalCountryJoin, 's_to_o'); $search->addJoinObject($originalCountryJoin, 's_to_o');
$search->where('`origin`.`COUNTRY_ID`' . Criteria::EQUAL . '?', $country, \PDO::PARAM_INT); $search->where('`origin`.`COUNTRY_ID`' . Criteria::EQUAL . '?', $country, \PDO::PARAM_INT);
$search->having('COUNT(*)=?', $taxCountForOriginCountry, \PDO::PARAM_INT); $search->having('COUNT(*)=?', $this->taxCountForOriginCountry, \PDO::PARAM_INT);
$search->filterByTaxRuleId($taxRule); $search->filterByTaxRuleId($taxRule);
@@ -142,17 +140,17 @@ class TaxRuleCountry extends BaseI18nLoop
$search->orderByPosition(Criteria::ASC); $search->orderByPosition(Criteria::ASC);
} }
/* perform search */ return $search;
$taxRuleCountries = $this->search($search, $pagination);
$loopResult = new LoopResult($taxRuleCountries); }
foreach ($taxRuleCountries as $taxRuleCountry) { public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $taxRuleCountry) {
$loopResultRow = new LoopResultRow($taxRuleCountry);
$loopResultRow = new LoopResultRow($loopResult, $taxRuleCountry, $this->versionable, $this->timestampable, $this->countable); if ($this->getAsk() === 'countries') {
if ($this->taxCountForOriginCountry > 0) {
if ($ask === 'countries') {
if ($taxCountForOriginCountry > 0) {
$loopResultRow $loopResultRow
->set("COUNTRY" , $taxRuleCountry->getCountryId()) ->set("COUNTRY" , $taxRuleCountry->getCountryId())
->set("COUNTRY_TITLE" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_TITLE')) ->set("COUNTRY_TITLE" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_TITLE'))
@@ -167,7 +165,7 @@ class TaxRuleCountry extends BaseI18nLoop
->set("COUNTRY_DESCRIPTION" , $taxRuleCountry->getVirtualColumn('i18n_DESCRIPTION')) ->set("COUNTRY_DESCRIPTION" , $taxRuleCountry->getVirtualColumn('i18n_DESCRIPTION'))
->set("COUNTRY_POSTSCRIPTUM" , $taxRuleCountry->getVirtualColumn('i18n_POSTSCRIPTUM')); ->set("COUNTRY_POSTSCRIPTUM" , $taxRuleCountry->getVirtualColumn('i18n_POSTSCRIPTUM'));
} }
} elseif ($ask === 'taxes') { } elseif ($this->getAsk() === 'taxes') {
$loopResultRow $loopResultRow
->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId()) ->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId())
->set("COUNTRY" , $taxRuleCountry->getCountryId()) ->set("COUNTRY" , $taxRuleCountry->getCountryId())
@@ -182,5 +180,6 @@ class TaxRuleCountry extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -24,80 +24,76 @@
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\Base\TemplateQuery; use Thelia\Model\ModuleQuery;
use Thelia\Module\BaseModule;
use Thelia\Type;
use Thelia\Core\Template\TemplateHelper;
use Thelia\Core\Template\TemplateDefinition;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
/** /**
* *
* Template loop * Template loop, to get available back-office or front-office templates.
* *
*
* Class Template
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> *
* @author Franck Allimant <franck@cqfdev.fr>
*/ */
class Template extends BaseI18nLoop class Template extends BaseLoop implements ArraySearchLoopInterface
{ {
public $timestampable = true; /**
/**
* @return ArgumentCollection * @return ArgumentCollection
*/ */
protected function getArgDefinitions() protected function getArgDefinitions()
{ {
return new ArgumentCollection( return new ArgumentCollection(
Argument::createIntListTypeArgument('id'), new Argument(
Argument::createIntListTypeArgument('exclude') 'template_type',
new Type\TypeCollection(
new Type\EnumListType(array(
'front-office',
'back-office',
'pdf'
))
)
)
); );
} }
/** public function buildArray() {
* @param $pagination $type = $this->getArg(template_type);
*
* @return \Thelia\Core\Template\Element\LoopResult if ($type == 'front-office')
*/ $templateType = TemplateDefinition::FRONT_OFFICE;
public function exec(&$pagination) else if ($type == 'back-office')
$templateType = TemplateDefinition::BACK_OFFICE;
else if ($type == 'pdf')
$templateType = TemplateDefinition::PDF;
return TemplateHelper::getInstance()->getList($templateType);
}
public function parseResults(LoopResult $loopResult)
{ {
$search = TemplateQuery::create(); foreach ($loopResult->getResultDataCollection() as $template) {
$backendContext = $this->getBackend_context(); $loopResultRow = new LoopResultRow($template);
$lang = $this->getLang();
/* manage translations */
$locale = $this->configureI18nProcessing($search, $columns = array('NAME'));
$id = $this->getId();
if (null !== $id) {
$search->filterById($id, Criteria::IN);
}
$exclude = $this->getExclude();
if (null !== $exclude) {
$search->filterById($exclude, Criteria::NOT_IN);
}
/* perform search */
$templates = $this->search($search, $pagination);
$loopResult = new LoopResult($templates);
foreach ($templates as $template) {
$loopResultRow = new LoopResultRow($loopResult, $template, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow $loopResultRow
->set("ID", $template->getId()) ->set("NAME" , $template->getName())
->set("IS_TRANSLATED" , $template->getVirtualColumn('IS_TRANSLATED')) ->set("RELATIVE_PATH" , $template->getPath())
->set("LOCALE" , $locale) ->set("ABSOLUTE_PATH" , THELIA_TEMPLATE_DIR . $template->getPath())
->set("NAME" , $template->getVirtualColumn('i18n_NAME'))
; ;
$loopResult->addRow($loopResultRow); $loopResult->addRow($loopResultRow);

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
@@ -42,9 +43,9 @@ use Thelia\Model\CustomerTitleQuery;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr> * @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class Title extends BaseI18nLoop class Title extends BaseI18nLoop implements PropelSearchLoopInterface
{ {
public $timestampable = true; protected $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
@@ -56,17 +57,12 @@ class Title extends BaseI18nLoop
); );
} }
/** public function buildModelCriteria()
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{ {
$search = CustomerTitleQuery::create(); $search = CustomerTitleQuery::create();
/* manage translations */ /* manage translations */
$locale = $this->configureI18nProcessing($search, array('SHORT', 'LONG')); $this->configureI18nProcessing($search, array('SHORT', 'LONG'));
$id = $this->getId(); $id = $this->getId();
@@ -76,16 +72,17 @@ class Title extends BaseI18nLoop
$search->orderByPosition(); $search->orderByPosition();
/* perform search */ return $search;
$titles = $this->search($search, $pagination);
$loopResult = new LoopResult($titles); }
foreach ($titles as $title) { public function parseResults(LoopResult $loopResult)
$loopResultRow = new LoopResultRow($loopResult, $title, $this->versionable, $this->timestampable, $this->countable); {
foreach ($loopResult->getResultDataCollection() as $title) {
$loopResultRow = new LoopResultRow($title);
$loopResultRow->set("ID", $title->getId()) $loopResultRow->set("ID", $title->getId())
->set("IS_TRANSLATED",$title->getVirtualColumn('IS_TRANSLATED')) ->set("IS_TRANSLATED",$title->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale) ->set("LOCALE",$this->locale)
->set("DEFAULT", $title->getByDefault()) ->set("DEFAULT", $title->getByDefault())
->set("SHORT", $title->getVirtualColumn('i18n_SHORT')) ->set("SHORT", $title->getVirtualColumn('i18n_SHORT'))
->set("LONG", $title->getVirtualColumn('i18n_LONG')) ->set("LONG", $title->getVirtualColumn('i18n_LONG'))
@@ -95,5 +92,6 @@ class Title extends BaseI18nLoop
} }
return $loopResult; return $loopResult;
} }
} }

View File

@@ -33,7 +33,7 @@ interface ParserInterface
/** /**
* *
*/ */
public function getContent(); public function render($realTemplateName, array $parameters = array());
public function setContent($content); public function setContent($content);

View File

@@ -29,6 +29,7 @@ use Thelia\Tools\URL;
use Thelia\Core\Security\SecurityContext; use Thelia\Core\Security\SecurityContext;
use Thelia\Model\Config; use Thelia\Model\Config;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Core\Template\TemplateHelper;
/** /**
* This class implements variour admin template utilities * This class implements variour admin template utilities
@@ -50,7 +51,7 @@ class AdminUtilities extends AbstractSmartyPlugin
$snippet_path = sprintf('%s/%s/%s.html', $snippet_path = sprintf('%s/%s/%s.html',
THELIA_TEMPLATE_DIR, THELIA_TEMPLATE_DIR,
ConfigQuery::read('base-admin-template', 'admin/default'), TemplateHelper::getInstance()->getActiveAdminTemplate()->getPath(),
$templateName $templateName
); );

View File

@@ -48,7 +48,7 @@ class Module extends AbstractSmartyPlugin
foreach ($modules as $module) { foreach ($modules as $module) {
$file = sprintf("%s/%s/AdminIncludes/%s.html", THELIA_MODULE_DIR, ucfirst($module->getCode()), $location); $file = sprintf("%s/%s/AdminIncludes/%s.html", THELIA_MODULE_DIR, $module->getBaseDir(), $location);
if (file_exists($file)) { if (file_exists($file)) {
$content .= file_get_contents($file); $content .= file_get_contents($file);

View File

@@ -14,6 +14,7 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Exception\ResourceNotFoundException; use Thelia\Core\Template\Exception\ResourceNotFoundException;
use Thelia\Core\Template\ParserContext; use Thelia\Core\Template\ParserContext;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Core\Template\TemplateHelper;
/** /**
* *
@@ -37,13 +38,12 @@ class SmartyParser extends Smarty implements ParserInterface
* @param Request $request * @param Request $request
* @param EventDispatcherInterface $dispatcher * @param EventDispatcherInterface $dispatcher
* @param ParserContext $parserContext * @param ParserContext $parserContext
* @param bool $template
* @param string $env * @param string $env
* @param bool $debug * @param bool $debug
*/ */
public function __construct( public function __construct(
Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext, Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext,
$template = false, $env = "prod", $debug = false) $env = "prod", $debug = false)
{ {
parent::__construct(); parent::__construct();
@@ -62,7 +62,6 @@ class SmartyParser extends Smarty implements ParserInterface
$this->setCompileDir($compile_dir); $this->setCompileDir($compile_dir);
$this->setCacheDir($cache_dir); $this->setCacheDir($cache_dir);
$this->setTemplate($template ?: ConfigQuery::read('active-template', 'default'));
$this->debugging = $debug; $this->debugging = $debug;
@@ -78,6 +77,8 @@ class SmartyParser extends Smarty implements ParserInterface
$this->setForceCompile(false); $this->setForceCompile(false);
} }
//$this->enableSecurity();
// The default HTTP status // The default HTTP status
$this->status = 200; $this->status = 200;
@@ -104,7 +105,7 @@ class SmartyParser extends Smarty implements ParserInterface
{ {
$this->template = $template_path_from_template_base; $this->template = $template_path_from_template_base;
$this->setTemplateDir(THELIA_TEMPLATE_DIR.$this->template); $this->addTemplateDir(THELIA_TEMPLATE_DIR.$this->template, 0);
$config_dir = THELIA_TEMPLATE_DIR.$this->template.'/configs'; $config_dir = THELIA_TEMPLATE_DIR.$this->template.'/configs';
@@ -125,6 +126,9 @@ class SmartyParser extends Smarty implements ParserInterface
*/ */
public function render($realTemplateName, array $parameters = array()) public function render($realTemplateName, array $parameters = array())
{ {
if(false === $this->templateExists($realTemplateName)) {
throw new ResourceNotFoundException();
}
// Assign the parserContext variables // Assign the parserContext variables
foreach ($this->parserContext as $var => $value) { foreach ($this->parserContext as $var => $value) {
$this->assign($var, $value); $this->assign($var, $value);
@@ -132,23 +136,7 @@ class SmartyParser extends Smarty implements ParserInterface
$this->assign($parameters); $this->assign($parameters);
return $this->fetch($realTemplateName); return $this->fetch(sprintf("file:%s", $realTemplateName));
}
/**
*
* This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
*
*/
public function getContent()
{
try {
$templateFile = $this->getTemplateFilePath();
} catch (\RuntimeException $e) {
return new Response($this->render(\Thelia\Model\ConfigQuery::getPageNotFoundView()), "404");
}
return $this->render($templateFile);
} }
/** /**
@@ -209,26 +197,4 @@ class SmartyParser extends Smarty implements ParserInterface
} }
} }
protected function getTemplateFilePath()
{
$file = $this->request->attributes->get('_view');
$fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file;
$pathFileName = realpath(dirname(THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file));
$templateDir = realpath(THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/");
if (strpos($pathFileName, $templateDir) !== 0) {
throw new ResourceNotFoundException(sprintf("this view does not exists"));
}
if (!file_exists($fileName)) {
$fileName .= ".html";
if (!file_exists($fileName)) {
throw new ResourceNotFoundException(sprintf("file not found in %s template", $this->template));
}
}
return $fileName;
}
} }

View File

@@ -0,0 +1,102 @@
<?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;
use Thelia\Model\ConfigQuery;
class TemplateDefinition
{
const FRONT_OFFICE = 1;
const BACK_OFFICE = 2;
const PDF = 3;
const BACK_OFFICE_SUBDIR = 'admin/';
const PDF_SUBDIR = 'pdf/';
/**
* @var the template directory name (e.g. 'default')
*/
protected $name;
/**
* @var the template directory full path
*/
protected $path;
/**
* @var the template type (front, back, pdf)
*/
protected $type;
public function __construct($name, $type)
{
$this->name = $name;
$this->type = $type;
if ($type == self::BACK_OFFICE)
$this->path = self::BACK_OFFICE_SUBDIR . $name;
else if ($type == self::PDF)
$this->path = self::PDF_SUBDIR . $name;
else
$this->path = $name;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getI18nPath() {
return $this->getPath() . DS . 'I18n';
}
public function getPath()
{
return $this->path;
}
public function setPath($path)
{
$this->path = $path;
return $this;
}
public function getType()
{
return $this->type;
}
public function setType($type)
{
$this->type = $type;
return $this;
}
}

View File

@@ -0,0 +1,96 @@
<?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;
use Thelia\Model\ConfigQuery;
class TemplateHelper
{
/**
* This is a singleton
*/
private static $instance = null;
private function __construct() {}
public static function getInstance() {
if (self::$instance == null) self::$instance = new TemplateHelper();
return self::$instance;
}
public function getActivePdfTemplate() {
return new TemplateDefinition(
ConfigQuery::read('active-pdf-template', 'default'),
TemplateDefinition::PDF
);
}
public function getActiveAdminTemplate() {
return new TemplateDefinition(
ConfigQuery::read('active-admin-template', 'default'),
TemplateDefinition::BACK_OFFICE
);
}
public function getActiveFrontTemplate() {
return new TemplateDefinition(
ConfigQuery::read('active-admin-template', 'default'),
TemplateDefinition::FRONT_OFFICE
);
}
public function getList($templateType) {
$list = $exclude = array();
if ($templateType == TemplateDefinition::BACK_OFFICE) {
$baseDir = THELIA_TEMPLATE_DIR.TemplateDefinition::BACK_OFFICE_SUBDIR;
}
else if ($templateType == TemplateDefinition::PDF) {
$baseDir = THELIA_TEMPLATE_DIR.TemplateDefinition::PDF_SUBDIR;
}
else {
$baseDir = THELIA_TEMPLATE_DIR;
$exclude = array(TemplateDefinition::BACK_OFFICE_SUBDIR, TemplateDefinition::PDF_SUBDIR);
}
// Every subdir of the basedir is supposed to be a template.
$di = new \DirectoryIterator($baseDir);
foreach ($di as $file) {
// Ignore 'dot' elements
if ($file->isDot() || ! $file->isDir()) continue;
// Ignore reserved directory names
if (in_array($file->getFilename()."/", $exclude)) continue;
$list[] = new TemplateDefinition($file->getFilename(), $templateType);
}
return $list;
}
}

View File

@@ -52,6 +52,7 @@ use Symfony\Component\Config\FileLocator;
use Propel\Runtime\Propel; use Propel\Runtime\Propel;
use Propel\Runtime\Connection\ConnectionManagerSingle; use Propel\Runtime\Connection\ConnectionManagerSingle;
use Thelia\Core\Template\TemplateHelper;
class Thelia extends Kernel class Thelia extends Kernel
{ {
@@ -123,8 +124,10 @@ class Thelia extends Kernel
if (defined("THELIA_INSTALL_MODE") === false) { if (defined("THELIA_INSTALL_MODE") === false) {
$modules = \Thelia\Model\ModuleQuery::getActivated(); $modules = \Thelia\Model\ModuleQuery::getActivated();
$translator = $container->getDefinition('thelia.translator');
$dirs = array(); $translationDirs = array();
$templateDirs = array();
$parser = $container->getDefinition('thelia.parser');
foreach ($modules as $module) { foreach ($modules as $module) {
try { try {
@@ -138,43 +141,62 @@ class Thelia extends Kernel
$defintion $defintion
); );
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config"));
$code = ucfirst($module->getCode());
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . $code . "/Config"));
$loader->load("config.xml"); $loader->load("config.xml");
if (is_dir($dir = THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/I18n")) { if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/I18n")) {
$dirs[] = $dir; $translationDirs[] = $dir;
}
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/templates")) {
//$templateDirs[$code] = $dir;
$parser->addMethodCall('addTemplateDir', array($dir, $code));
} }
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
// FIXME: process module configuration exception // TODO: process module configuration exception
} }
} }
//Load translation from templates // Load translation from templates
//core translation //core translation
$dirs[] = THELIA_ROOT . "/core/lib/Thelia/Config/I18n"; $translationDirs[] = THELIA_ROOT . "core/lib/Thelia/Config/I18n";
//admin template // admin template
if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) { if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActiveAdminTemplate()->getI18nPath())) {
$dirs[] = $dir; $translationDirs[] = $dir;
} }
//front template // front template
$template = ConfigQuery::getActiveTemplate(); if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActiveFrontTemplate()->getI18nPath())) {
if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) { $translationDirs[] = $dir;
$dirs[] = $dir;
} }
if ($dirs) { // PDF template
$finder = Finder::create() if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActivePdfTemplate()->getI18nPath())) {
->files() $translationDirs[] = $dir;
->depth(0)
->in($dirs);
foreach ($finder as $file) {
list($locale, $format) = explode('.', $file->getBaseName(), 2);
$translator->addMethodCall('addResource', array($format, (string) $file, $locale));
}
} }
if ($translationDirs) {
$this->loadTranslation($container, $translationDirs);
}
}
}
private function loadTranslation(ContainerBuilder $container, array $dirs)
{
$translator = $container->getDefinition('thelia.translator');
$finder = Finder::create()
->files()
->depth(0)
->in($dirs);
foreach ($finder as $file) {
list($locale, $format) = explode('.', $file->getBaseName(), 2);
$translator->addMethodCall('addResource', array($format, (string) $file, $locale));
} }
} }

View File

@@ -52,7 +52,7 @@ class Translator extends BaseTranslator
* *
* @api * @api
*/ */
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null) public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null, $return_default_if_not_available = true)
{ {
if (null === $locale) { if (null === $locale) {
$locale = $this->getLocale(); $locale = $this->getLocale();
@@ -64,7 +64,9 @@ class Translator extends BaseTranslator
if ($this->catalogues[$locale]->has((string) $id, $domain)) if ($this->catalogues[$locale]->has((string) $id, $domain))
return parent::trans($id, $parameters, $domain, $locale); return parent::trans($id, $parameters, $domain, $locale);
else else if ($return_default_if_not_available)
return strtr($id, $parameters); return strtr($id, $parameters);
else
return '';
} }
} }

View File

@@ -82,12 +82,6 @@ class ConfigQuery extends BaseConfigQuery {
return self::read('passed_url_view', 'passed-url'); return self::read('passed_url_view', 'passed-url');
} }
public static function getActiveTemplate()
{
return self::read('active-template', 'default');
}
public static function useTaxFreeAmounts() public static function useTaxFreeAmounts()
{ {
return self::read('use_tax_free_amounts', 'default') == 1; return self::read('use_tax_free_amounts', 'default') == 1;

View File

@@ -166,7 +166,7 @@ class ConfigTableMap extends TableMap
// columns // columns
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addColumn('NAME', 'Name', 'VARCHAR', true, 255, null); $this->addColumn('NAME', 'Name', 'VARCHAR', true, 255, null);
$this->addColumn('VALUE', 'Value', 'VARCHAR', true, 255, null); $this->addColumn('VALUE', 'Value', 'LONGVARCHAR', true, null, null);
$this->addColumn('SECURED', 'Secured', 'TINYINT', true, null, 1); $this->addColumn('SECURED', 'Secured', 'TINYINT', true, null, 1);
$this->addColumn('HIDDEN', 'Hidden', 'TINYINT', true, null, 1); $this->addColumn('HIDDEN', 'Hidden', 'TINYINT', true, null, 1);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);

View File

@@ -11,4 +11,25 @@ class Module extends BaseModule {
{ {
ModuleQuery::resetActivated(); ModuleQuery::resetActivated();
} }
/**
* @return the module's base directory path, relative to THELIA_MODULE_DIR
*/
public function getBaseDir() {
return ucfirst($this->getCode());
}
/**
* @return the module's config directory path, relative to THELIA_MODULE_DIR
*/
public function getConfigPath() {
return $this->getBaseDir() . DS . "Config";
}
/**
* @return the module's i18N directory path, relative to THELIA_MODULE_DIR
*/
public function getI18nPath() {
return $this->getBaseDir() . DS . "I18n";
}
} }

View File

@@ -53,6 +53,13 @@ class CategoryTest extends BaseLoopTestor
public function testSearchById() public function testSearchById()
{ {
$category = CategoryQuery::create()->findOne(); $category = CategoryQuery::create()->findOne();
if(null === $category) {
$category = new \Thelia\Model\Category();
$category->setParent(0);
$category->setVisible(1);
$category->setTitle('foo');
$category->save();
}
$this->baseTestSearchById($category->getId()); $this->baseTestSearchById($category->getId());
} }

View File

@@ -53,6 +53,13 @@ class ContentTest extends BaseLoopTestor
public function testSearchById() public function testSearchById()
{ {
$content = ContentQuery::create()->findOne(); $content = ContentQuery::create()->findOne();
if(null === $content) {
$content = new \Thelia\Model\Content();
$content->setDefaultFolder(0);
$content->setVisible(1);
$content->setTitle('foo');
$content->save();
}
$this->baseTestSearchById($content->getId()); $this->baseTestSearchById($content->getId());
} }

View File

@@ -53,6 +53,13 @@ class FolderTest extends BaseLoopTestor
public function testSearchById() public function testSearchById()
{ {
$folder = FolderQuery::create()->findOne(); $folder = FolderQuery::create()->findOne();
if(null === $folder) {
$folder = new \Thelia\Model\Folder();
$folder->setParent(0);
$folder->setVisible(1);
$folder->setTitle('foo');
$folder->save();
}
$this->baseTestSearchById($folder->getId()); $this->baseTestSearchById($folder->getId());
} }

View File

@@ -54,6 +54,13 @@ class ProductTest extends BaseLoopTestor
public function testSearchById() public function testSearchById()
{ {
$product = ProductQuery::create()->orderById(Criteria::ASC)->findOne(); $product = ProductQuery::create()->orderById(Criteria::ASC)->findOne();
if(null === $product) {
$product = new \Thelia\Model\Product();
$product->setDefaultCategory(0);
$product->setVisible(1);
$product->setTitle('foo');
$product->save();
}
$this->baseTestSearchById($product->getId()); $this->baseTestSearchById($product->getId());
} }

View File

@@ -53,6 +53,11 @@ class TaxRuleTest extends BaseLoopTestor
public function testSearchById() public function testSearchById()
{ {
$tr = TaxRuleQuery::create()->findOne(); $tr = TaxRuleQuery::create()->findOne();
if(null === $tr) {
$tr = new \Thelia\Model\TaxRule();
$tr->setTitle('foo');
$tr->save();
}
$this->baseTestSearchById($tr->getId(), array('force_return' => true)); $this->baseTestSearchById($tr->getId(), array('force_return' => true));
} }

View File

@@ -8,7 +8,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat
('session_config.default', '1', 1, 1, NOW(), NOW()), ('session_config.default', '1', 1, 1, NOW(), NOW()),
('verifyStock', '1', 0, 0, NOW(), NOW()), ('verifyStock', '1', 0, 0, NOW(), NOW()),
('active-template', 'default', 0, 0, NOW(), NOW()), ('active-template', 'default', 0, 0, NOW(), NOW()),
('base-admin-template', 'admin/default', 0, 0, NOW(), NOW()), ('active-admin-template', 'default', 0, 0, NOW(), NOW()),
('active-pdf-template', 'default', 0, 0, NOW(), NOW()),
('default_lang_without_translation', '1', 1, 1, NOW(), NOW()), ('default_lang_without_translation', '1', 1, 1, NOW(), NOW()),
('rewriting_enable', '0', 0, 0, NOW(), NOW()), ('rewriting_enable', '0', 0, 0, NOW(), NOW()),
('imagine_graphic_driver', 'gd', 0, 0, NOW(), NOW()), ('imagine_graphic_driver', 'gd', 0, 0, NOW(), NOW()),
@@ -33,6 +34,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat
('contact_email','', 0, 0, NOW(), NOW()), ('contact_email','', 0, 0, NOW(), NOW()),
('url_site','', 0, 0, NOW(), NOW()), ('url_site','', 0, 0, NOW(), NOW()),
('one_domain_foreach_lang','0', 1, 1, NOW(), NOW()), ('one_domain_foreach_lang','0', 1, 1, NOW(), NOW()),
('pdf_invoice_file', 'invoice', 0, 0, NOW(), NOW()),
('pdf_delivery_file', 'delivery', 0, 0, NOW(), NOW()),
('thelia_version','2.0.0-beta1', 1, 1, NOW(), NOW()), ('thelia_version','2.0.0-beta1', 1, 1, NOW(), NOW()),
('thelia_major_version','2', 1, 1, NOW(), NOW()), ('thelia_major_version','2', 1, 1, NOW(), NOW()),
('thelia_minus_version','0', 1, 1, NOW(), NOW()), ('thelia_minus_version','0', 1, 1, NOW(), NOW()),
@@ -1207,7 +1210,7 @@ generated with command : php Thelia thelia:generate-resources --output sql
*/ */
INSERT INTO resource (`id`, `code`, `created_at`, `updated_at`) VALUES INSERT INTO resource (`id`, `code`, `created_at`, `updated_at`) VALUES
(1, 'admin.address', NOW(), NOW()), (1, 'admin.address', NOW(), NOW()),
(2, 'admin.configuration.admin', NOW(), NOW()), (2, 'admin.configuration.administrator', NOW(), NOW()),
(3, 'admin.configuration.area', NOW(), NOW()), (3, 'admin.configuration.area', NOW(), NOW()),
(4, 'admin.configuration.attribute', NOW(), NOW()), (4, 'admin.configuration.attribute', NOW(), NOW()),
(5, 'admin.category', NOW(), NOW()), (5, 'admin.category', NOW(), NOW()),
@@ -1228,7 +1231,8 @@ INSERT INTO resource (`id`, `code`, `created_at`, `updated_at`) VALUES
(20, 'admin.configuration.profile', NOW(), NOW()), (20, 'admin.configuration.profile', NOW(), NOW()),
(21, 'admin.configuration.shipping-zone', NOW(), NOW()), (21, 'admin.configuration.shipping-zone', NOW(), NOW()),
(22, 'admin.configuration.tax', NOW(), NOW()), (22, 'admin.configuration.tax', NOW(), NOW()),
(23, 'admin.configuration.template', NOW(), NOW()); (23, 'admin.configuration.template', NOW(), NOW()),
(24, 'admin.configuration.system-log', NOW(), NOW());
/** /**
generated with command : php Thelia thelia:generate-resources --output sql-i18n generated with command : php Thelia thelia:generate-resources --output sql-i18n
@@ -1236,8 +1240,8 @@ generated with command : php Thelia thelia:generate-resources --output sql-i18n
INSERT INTO resource_i18n (`id`, `locale`, `title`) VALUES INSERT INTO resource_i18n (`id`, `locale`, `title`) VALUES
(1, 'en_US', 'Address'), (1, 'en_US', 'Address'),
(1, 'fr_FR', 'Address'), (1, 'fr_FR', 'Address'),
(2, 'en_US', 'Configuration / Admin'), (2, 'en_US', 'Configuration / Administrator'),
(2, 'fr_FR', 'Configuration / Admin'), (2, 'fr_FR', 'Configuration / Administrator'),
(3, 'en_US', 'Configuration / Area'), (3, 'en_US', 'Configuration / Area'),
(3, 'fr_FR', 'Configuration / Area'), (3, 'fr_FR', 'Configuration / Area'),
(4, 'en_US', 'Configuration / Attribute'), (4, 'en_US', 'Configuration / Attribute'),
@@ -1279,7 +1283,9 @@ INSERT INTO resource_i18n (`id`, `locale`, `title`) VALUES
(22, 'en_US', 'Configuration / Tax'), (22, 'en_US', 'Configuration / Tax'),
(22, 'fr_FR', 'Configuration / Tax'), (22, 'fr_FR', 'Configuration / Tax'),
(23, 'en_US', 'Configuration / Template'), (23, 'en_US', 'Configuration / Template'),
(23, 'fr_FR', 'Configuration / Template'); (23, 'fr_FR', 'Configuration / Template'),
(24, 'en_US', 'Configuration / System Log'),
(24, 'fr_FR', 'Configuration / Logs système');
INSERT INTO `message` (`id`, `name`, `secured`, `created_at`, `updated_at`, `version`, `version_created_at`, `version_created_by`) VALUES INSERT INTO `message` (`id`, `name`, `secured`, `created_at`, `updated_at`, `version`, `version_created_at`, `version_created_by`) VALUES

View File

@@ -416,7 +416,7 @@ CREATE TABLE `config`
( (
`id` INTEGER NOT NULL AUTO_INCREMENT, `id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL, `name` VARCHAR(255) NOT NULL,
`value` VARCHAR(255) NOT NULL, `value` TEXT NOT NULL,
`secured` TINYINT DEFAULT 1 NOT NULL, `secured` TINYINT DEFAULT 1 NOT NULL,
`hidden` TINYINT DEFAULT 1 NOT NULL, `hidden` TINYINT DEFAULT 1 NOT NULL,
`created_at` DATETIME, `created_at` DATETIME,

View File

@@ -30,94 +30,102 @@
</div> </div>
</div> </div>
<div class="col-md-12 clearfix"> <div class="row">
<div> <div class="col-md-12">
<strong>{intl l='Period'} :</strong> <div>
</div> <strong>{intl l='Period'} :</strong>
</div>
<div class="row"> <div class="row">
<div class="col-lg-3 clearfix"> <div class="col-lg-3 clearfix">
<div class="input-group"> <div class="input-group">
<span class="input-group-addon">{intl l='From'}</span> <span class="input-group-addon">{intl l='From'}</span>
<input class="form-control" type="text" id="from_date" readonly="readonly"> <input class="form-control" type="text" id="from_date" readonly="readonly">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-default js-show-datepicker" data-datepicker-selector="#from_date" type="button"> <button class="btn btn-default js-show-datepicker" data-datepicker-selector="#from_date" type="button">
<span class="glyphicon glyphicon-calendar"></span> <span class="glyphicon glyphicon-calendar"></span>
</button> </button>
</span> </span>
</div> </div>
</div> </div>
<div class="col-lg-3 clearfix input-group"> <div class="col-lg-3 clearfix input-group">
<div class="input-group"> <div class="input-group">
<span class="input-group-addon">{intl l='To'}</span> <span class="input-group-addon">{intl l='To'}</span>
<input class="form-control" type="text" id="to_date" readonly="readonly"> <input class="form-control" type="text" id="to_date" readonly="readonly">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-default js-show-datepicker" data-datepicker-selector="#to_date" type="button"> <button class="btn btn-default js-show-datepicker" data-datepicker-selector="#to_date" type="button">
<span class="glyphicon glyphicon-calendar"></span> <span class="glyphicon glyphicon-calendar"></span>
</button> </button>
</span> </span>
</div> </div>
</div> </div>
</div> </div>
</div>
</div> </div>
<div class="col-md-12 clearfix"> <div class="row">
<div> <div class="col-md-12">
<strong>{intl l='Administrators'} :</strong> <div>
</div> <strong>{intl l='Administrators'} :</strong>
</div>
<div class="row"> <div class="row">
{loop type="admin" name="admin-list" backend_context="1"} {loop type="admin" name="admin-list" backend_context="1"}
{if ($LOOP_COUNT-1)%4 == 0 AND $LOOP_COUNT != 0 AND $LOOP_COUNT != $LOOP_TOTAL} {if ($LOOP_COUNT-1)%4 == 0 AND $LOOP_COUNT != 0 AND $LOOP_COUNT != $LOOP_TOTAL}
</div> </div>
<div class="row"> <div class="row">
{/if} {/if}
<div class="col-md-3"> <div class="col-md-3">
<input id="admin_{$ID}" data-id="{$LOGIN}" class="js-admin" type="checkbox" checked> <input id="admin_{$ID}" data-id="{$LOGIN}" class="js-admin" type="checkbox" checked>
<label for="admin_{$ID}" style="font-weight: normal;">{$LOGIN} ({$FIRSTNAME|upper} {$LASTNAME|ucwords})</label> <label for="admin_{$ID}" style="font-weight: normal;">{$LOGIN} ({$FIRSTNAME|upper} {$LASTNAME|ucwords})</label>
</div> </div>
{/loop} {/loop}
</div> </div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div>
<strong>{intl l='Resources'} :</strong>
</div>
<div class="row">
{loop type="resource" name="resources-list" backend_context="1"}
{if ($LOOP_COUNT-1)%4 == 0 AND $LOOP_COUNT != 0 AND $LOOP_COUNT != $LOOP_TOTAL}
</div>
<div class="row">
{/if}
<div class="col-md-3">
<input id="resource_{$ID}" data-id="{$CODE}" class="js-resource" type="checkbox" checked>
<label for="resource_{$ID}" style="font-weight: normal;">{$TITLE}</label>
</div>
{/loop}
</div>
</div>
</div> </div>
<div class="col-md-12 clearfix"> <div class="row">
<div> <div class="col-md-12">
<strong>{intl l='Resources'} :</strong> <div>
</div> <strong>{intl l='Modules'} :</strong>
</div>
<div class="row"> <div class="row">
{loop type="resource" name="resources-list" backend_context="1"} {loop type="module" name="modules-list" backend_context="1"}
{if ($LOOP_COUNT-1)%4 == 0 AND $LOOP_COUNT != 0 AND $LOOP_COUNT != $LOOP_TOTAL} {if ($LOOP_COUNT-1)%4 == 0 AND $LOOP_COUNT != 0 AND $LOOP_COUNT != $LOOP_TOTAL}
</div> </div>
<div class="row"> <div class="row">
{/if} {/if}
<div class="col-md-3"> <div class="col-md-3">
<input id="resource_{$ID}" data-id="{$CODE}" class="js-resource" type="checkbox" checked> <input id="module_{$ID}" data-id="{$CODE}" class="js-module" type="checkbox" checked>
<label for="resource_{$ID}" style="font-weight: normal;">{$TITLE}</label> <label for="module_{$ID}" style="font-weight: normal;">{$TITLE}</label>
</div> </div>
{/loop} {/loop}
</div> </div>
</div>
<div class="col-md-12 clearfix">
<div>
<strong>{intl l='Modules'} :</strong>
</div>
<div class="row">
{loop type="module" name="modules-list" backend_context="1"}
{if ($LOOP_COUNT-1)%4 == 0 AND $LOOP_COUNT != 0 AND $LOOP_COUNT != $LOOP_TOTAL}
</div>
<div class="row">
{/if}
<div class="col-md-3">
<input id="module_{$ID}" data-id="{$CODE}" class="js-module" type="checkbox" checked>
<label for="module_{$ID}" style="font-weight: normal;">{$TITLE}</label>
</div>
{/loop}
</div>
</div>
</div> </div>
<div class="row inner-toolbar"> <div class="row inner-toolbar">
@@ -129,7 +137,6 @@
<div id="loading-block" class="col-md-12 loading-block"></div> <div id="loading-block" class="col-md-12 loading-block"></div>
<div class="col-md-12 clearfix" id="logger-display"></div> <div class="col-md-12 clearfix" id="logger-display"></div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -151,6 +151,13 @@
</tr> </tr>
{/loop} {/loop}
{loop type="auth" name="pcc5.1" role="ADMIN" resource="admin.configuration.translations" access="VIEW"}
<tr>
<td><a href="{url path='/admin/configuration/translations'}">{intl l='Translations'}</a></td>
<td><a class="btn btn-default btn-xs" href="{url path='/admin/configuration/translations'}"><i class="glyphicon glyphicon-edit"></i></a></td>
</tr>
{/loop}
{loop type="auth" name="pcc6" role="ADMIN" resource="admin.configuration.mailing-system" access="VIEW"} {loop type="auth" name="pcc6" role="ADMIN" resource="admin.configuration.mailing-system" access="VIEW"}
<tr> <tr>
<td><a href="{url path='/admin/configuration/mailingSystem'}">{intl l='Mailing system'}</a></td> <td><a href="{url path='/admin/configuration/mailingSystem'}">{intl l='Mailing system'}</a></td>

View File

@@ -23,7 +23,7 @@
<div class="row"> <div class="row">
<div class="col-md-12 title title-without-tabs"> <div class="col-md-12 title title-without-tabs">
{intl l="Edit customer $FIRSTNAME $LASTNAME"} {intl l="Edit customer %firstname %lastname" firstname=$FIRSTNAME lastname=$LASTNAME}
</div> </div>
<div class="form-container"> <div class="form-container">

View File

@@ -16,7 +16,7 @@ Parameters:
<ul class="nav nav-pills"> <ul class="nav nav-pills">
{loop name="lang_list" type="lang"} {loop name="lang_list" type="lang"}
<li {if $ID == $edit_language_id}class="active"{/if}> <li {if $ID == $edit_language_id}class="active"{/if}>
<a href="{url path={$page_url|default:$current_url} edit_language_id=$ID}" title="{intl l='Edit information in %lng' lng=$TITLE}"> <a class="language-change-button" data-language-id="{$ID}" href="{url path={$page_url|default:$current_url} edit_language_id=$ID}" title="{intl l='Edit information in %lng' lng=$TITLE}">
<img src="{image file="../assets/img/flags/{$CODE}.gif"}" alt="{intl l=$TITLE}" /> <img src="{image file="../assets/img/flags/{$CODE}.gif"}" alt="{intl l=$TITLE}" />
</a> </a>
</li> </li>

View File

@@ -0,0 +1,258 @@
{extends file="admin-layout.tpl"}
{block name="page-title"}{intl l='Translations'}{/block}
{block name="check-resource"}admin.configuration.variable{/block}
{block name="check-access"}update{/block}
{block name="main-content"}
<div class="variables translations">
<div id="wrapper" class="container">
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
<li><a href="{url path='/admin/configuration/translations'}">{intl l="Translations"}</a></li>
</ul>
<div class="row">
<div class="col-md-12 general-block-decorator">
<div class="row">
<div class="col-md-12 title title-without-tabs">
{intl l="Translation"}
</div>
<div class="form-container">
<div class="col-md-12">
<form method="POST" id="translation_form" action="{url path='/admin/configuration/translations/update'}">
<fieldset>
{include
file = "includes/inner-form-toolbar.html"
close_url = {url path='/admin/configuration'}
}
<input type="hidden" name="edit_language_id" value="{$edit_language_id}" />
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label" for="item_to_translate">{intl l='Select which items you want to translate'}</label>
<select id="item_to_translate" required="required" name="item_to_translate" class="submit-on-change form-control">
<option value="">{intl l='Please select items to translate'}</option>
<option value="fo" {if $item_to_translate=='fo'}selected="selected"{/if}>{intl l='Front-office templates'}</option>
<option value="pf" {if $item_to_translate=='pf'}selected="selected"{/if}>{intl l='PDF templates'}</option>
<option value="bo" {if $item_to_translate=='bo'}selected="selected"{/if}>{intl l='Back-office templates'}</option>
<option value="mo" {if $item_to_translate=='mo'}selected="selected"{/if}>{intl l='Modules'}</option>
<option value="co" {if $item_to_translate=='co'}selected="selected"{/if}>{intl l='Thelia core'}</option>
</select>
</div>
</div>
{if $item_to_translate == 'mo'}
<div class="col-md-4">
<div class="form-group">
<label class="control-label" for="item_id">{intl l='Select the module you want to translate'}</label>
<select id="item_id" required="required" name="item_id" class="submit-on-change form-control">
<option value="">{intl l='Please select the module to translate'}</option>
{loop type="module" name="translate-module" backend_context=1}
<option value="{$ID}" {if $item_id == $ID}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
</div>
</div>
{else if $item_to_translate == 'fo'}
<div class="col-md-4">
<div class="form-group">
<label class="control-label" for="item_id">{intl l='Select the front-office template you want to translate'}</label>
<select id="item_id" required="required" name="item_id" class="submit-on-change form-control">
<option value="">{intl l='Please select the F.O. template to translate'}</option>
{loop type="template" name="translate-fo-template" template-type="front-office" backend_context=1}
<option value="{$NAME}" {if $item_id == $NAME}selected="selected"{/if}>{$NAME}</option>
{/loop}
</select>
</div>
</div>
{else if $item_to_translate == 'bo'}
<div class="col-md-4">
<div class="form-group">
<label class="control-label" for="item_id">{intl l='Select the back-office template you want to translate'}</label>
<select id="item_id" required="required" name="item_id" class="submit-on-change form-control">
<option value="">{intl l='Please select the B.O. template to translate'}</option>
{loop type="template" name="translate-fo-template" template-type="back-office" backend_context=1}
<option value="{$NAME}" {if $item_id == $NAME}selected="selected"{/if}>{$NAME}</option>
{/loop}
</select>
</div>
</div>
{else if $item_to_translate == 'pf'}
<div class="col-md-4">
<div class="form-group">
<label class="control-label" for="item_id">{intl l='Select the PDF template you want to translate'}</label>
<select id="item_id" required="required" name="item_id" class="submit-on-change form-control">
<option value="">{intl l='Please select the PDF template to translate'}</option>
{loop type="template" name="translate-pdf-template" template-type="pdf" backend_context=1}
<option value="{$NAME}" {if $item_id == $NAME}selected="selected"{/if}>{$NAME}</option>
{/loop}
</select>
</div>
</div>
{/if}
<div class="col-md-4">
<div class="form-group">
<label class="control-label">&nbsp;</label>
<label class="checkbox control-label">
<input type="checkbox" name="view_missing_traductions_only" value="1" {if $view_missing_traductions_only}checked="checked"{/if}> {intl l='View only missing translations'}
</label>
</div>
</div>
</div>
</fieldset>
{* -- STRINGS TO TRANSLATE --------------------------------------------- *}
{$currfile = false}
{$untranslated = 0}
{foreach $all_strings as $hash => $info}
{$not_translated = empty($info.translation)}
{if $view_missing_traductions_only != 1 || $not_translated }
{* Create a liste of files names *}
{if count($info.files) > 1}
{$label = {intl l='In pages:'}}
{capture name="banner" assign=file_names}
<ul>
{foreach $info.files as $file}
<li>{$file}</li>
{/foreach}
</ul>
{/capture}
{else}
{$label = {intl l='In page'}}
{$file_names = $info.files.0}
{/if}
{* Display current file liste, if required *}
{if $file_names != $currfile}
{if $currfile !== false}
{* Close current panel *}
</tbody></table>
</div>
{/if}
{$currfile = $file_names}
<div class="panel panel-default">
<div class="panel-heading">
{loop name="lang_list" type="lang" id=$edit_language_id}
<img src="{image file="assets/img/flags/{$CODE}.gif"}" alt="{intl l=$TITLE}" />
{/loop}
{$label} {$file_names nofilter}
</div>
<table class="table table-condensed table-hover">
<tbody>
{/if}
<tr>
<td class="col-md-6">
<span id="{$hash}">{$info.chaine}</span>
{if $info.dollar}
<div>
<span class="label label-warning">{intl l='Warning'}</span>
{intl l='Il seems that this string contains a Smarty variable ($). If \'s the case, it cannot be transleted properly.'}
</div>
{/if}
</td>
<td class="col-md-6" >
<div class="input-group {if $not_translated}has-error{/if}">
<span class="input-group-addon"><a href="#" data-hash="{$hash}" class="copy-translation" title="{intl l='Copy source text in input field'}"><span class="glyphicon glyphicon-chevron-right"></span></a></span>
<input type="text" class="translation_field form-control" name="{$hash}" value="{$info.translation}" />
</div>
</td>
</tr>
{/if}
{/foreach}
</tbody>
</table>
</div> {* panel *}
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{/block}
{block name="javascript-initialization"}
<script>
$(function() {
var translation_changed = false;
$('#item_to_translate').change(function() {
$('#item_id').val('');
});
$('.submit-on-change').change(function() {
$('#translation_form').submit();
});
$('input.translation_field').change(function() { translation_changed = true; });
$('.copy-translation').click(function(ev) {
var hash = $(this).data('hash');
$('input[name='+hash+']').val($('#'+hash).html());
translation_changed = true;
ev.preventDefault();
})
$('#translation_form').submit(function(ev) {
if (translation_changed
&&
! confirm("{intl l='Some of your translations are not saved. Continue anyway ?'}") ) {
ev.preventDefault();
}
});
// Intercept language changes, to reload string when changing language
$('.language-change-button').click(function(ev) {
$('input[name=edit_language_id]').val($(this).data('language-id'));
$('#translation_form').submit();
ev.preventDefault();
});
});
</script>
{/block}

View File

@@ -16,7 +16,7 @@
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li> <li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li> <li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
<li><a href="{url path='/admin/configuration/variables'}">{intl l="System variables"}</a></li> <li><a href="{url path='/admin/configuration/variables'}">{intl l="System variables"}</a></li>
<li>{intl l='Editing variable "%name"' name="{$NAME}"}</li> <li>{intl l='Editing variable "%name"' name=$NAME}</li>
</ul> </ul>
<div class="row"> <div class="row">
@@ -24,7 +24,7 @@
<div class="row"> <div class="row">
<div class="col-md-12 title title-without-tabs"> <div class="col-md-12 title title-without-tabs">
{intl l="Edit variable $NAME"} {intl l="Edit variable %name" name=$NAME}
</div> </div>
<div class="form-container"> <div class="form-container">

View File

@@ -0,0 +1,4 @@
<?php
return array (
);

View File

@@ -0,0 +1,4 @@
<?php
return array (
);

View File

@@ -0,0 +1,4 @@
<?php
return array (
);

View File

@@ -0,0 +1,4 @@
<?php
return array (
);

Some files were not shown because too many files have changed in this diff Show More