Merge branch 'optim' of https://github.com/thelia/thelia into optim

Conflicts:
	core/lib/Thelia/Action/Order.php
	core/lib/Thelia/Core/Template/Element/BaseLoop.php
This commit is contained in:
Franck Allimant
2014-01-31 15:49:59 +01:00
353 changed files with 5389 additions and 3089 deletions

View File

@@ -35,6 +35,7 @@ class AdministratorEvent extends ActionEvent
protected $login = null;
protected $password = null;
protected $profile = null;
protected $locale = null;
public function __construct(Admin $administrator = null)
{
@@ -61,6 +62,8 @@ class AdministratorEvent extends ActionEvent
public function setId($id)
{
$this->id = $id;
return $this;
}
public function getId()
@@ -71,6 +74,8 @@ class AdministratorEvent extends ActionEvent
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
public function getFirstname()
@@ -81,6 +86,8 @@ class AdministratorEvent extends ActionEvent
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
public function getLastname()
@@ -91,6 +98,8 @@ class AdministratorEvent extends ActionEvent
public function setLogin($login)
{
$this->login = $login;
return $this;
}
public function getLogin()
@@ -101,6 +110,8 @@ class AdministratorEvent extends ActionEvent
public function setPassword($password)
{
$this->password = $password;
return $this;
}
public function getPassword()
@@ -111,10 +122,23 @@ class AdministratorEvent extends ActionEvent
public function setProfile($profile)
{
$this->profile = $profile;
return $this;
}
public function getProfile()
{
return $this->profile;
}
}
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
public function getLocale()
{
return $this->locale;
}
}

View File

@@ -54,6 +54,8 @@ class AdministratorUpdatePasswordEvent extends ActionEvent
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
@@ -70,6 +72,8 @@ class AdministratorUpdatePasswordEvent extends ActionEvent
public function setAdmin(Admin $admin)
{
$this->admin = $admin;
return $this;
}
/**

View File

@@ -48,6 +48,7 @@ class CartEvent extends ActionEvent
public function setAppend($append)
{
$this->append = $append;
return $this;
}
/**
@@ -64,6 +65,7 @@ class CartEvent extends ActionEvent
public function setCartItem($cartItem)
{
$this->cartItem = $cartItem;
return $this;
}
/**
@@ -80,6 +82,7 @@ class CartEvent extends ActionEvent
public function setNewness($newness)
{
$this->newness = $newness;
return $this;
}
/**
@@ -96,6 +99,7 @@ class CartEvent extends ActionEvent
public function setProduct($product)
{
$this->product = $product;
return $this;
}
/**
@@ -112,6 +116,7 @@ class CartEvent extends ActionEvent
public function setProductSaleElementsId($productSaleElementsId)
{
$this->productSaleElementsId = $productSaleElementsId;
return $this;
}
/**
@@ -128,6 +133,7 @@ class CartEvent extends ActionEvent
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
@@ -145,5 +151,4 @@ class CartEvent extends ActionEvent
{
return $this->cart;
}
}
}

View File

@@ -0,0 +1,266 @@
<?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\Event\Order;
use Thelia\Model\Order;
use Thelia\Model\Currency;
use Thelia\Model\Lang;
use Thelia\Model\Cart;
use Thelia\Model\Customer;
class OrderManualEvent extends OrderEvent
{
protected $currency = null;
protected $lang = null;
protected $cart = null;
protected $customer = null;
/**
* @param Order $order
*/
public function __construct(Order $order, Currency $currency, Lang $lang, Cart $cart, Customer $customer)
{
$this
->setOrder($order)
->setCurrency($currency)
->setLang($lang)
->setCart($cart)
->setCustomer($customer)
;
}
/**
* @param Order $order
*/
public function setOrder(Order $order)
{
$this->order = $order;
return $this;
}
/**
* @param Order $order
*/
public function setPlacedOrder(Order $order)
{
$this->placedOrder = $order;
return $this;
}
/**
* @param $address
*/
public function setInvoiceAddress($address)
{
$this->invoiceAddress = $address;
return $this;
}
/**
* @param $address
*/
public function setDeliveryAddress($address)
{
$this->deliveryAddress = $address;
return $this;
}
/**
* @param $module
*/
public function setDeliveryModule($module)
{
$this->deliveryModule = $module;
return $this;
}
/**
* @param $module
*/
public function setPaymentModule($module)
{
$this->paymentModule = $module;
return $this;
}
/**
* @param $postage
*/
public function setPostage($postage)
{
$this->postage = $postage;
return $this;
}
/**
* @param $ref
*/
public function setRef($ref)
{
$this->ref = $ref;
return $this;
}
/**
* @param $status
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* @param $deliveryRef
*/
public function setDeliveryRef($deliveryRef)
{
$this->deliveryRef = $deliveryRef;
}
/**
* @return null|Order
*/
public function getOrder()
{
return $this->order;
}
/**
* @return null|Order
*/
public function getPlacedOrder()
{
return $this->placedOrder;
}
/**
* @return null|int
*/
public function getInvoiceAddress()
{
return $this->invoiceAddress;
}
/**
* @return null|int
*/
public function getDeliveryAddress()
{
return $this->deliveryAddress;
}
/**
* @return null|int
*/
public function getDeliveryModule()
{
return $this->deliveryModule;
}
/**
* @return null|int
*/
public function getPaymentModule()
{
return $this->paymentModule;
}
/**
* @return null|int
*/
public function getPostage()
{
return $this->postage;
}
/**
* @return null|int
*/
public function getRef()
{
return $this->ref;
}
/**
* @return null|int
*/
public function getStatus()
{
return $this->status;
}
/**
* @return null|string
*/
public function getDeliveryRef()
{
return $this->deliveryRef;
}
public function getCurrency()
{
return $this->currency;
}
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
public function getLang()
{
return $this->lang;
}
public function setLang($lang)
{
$this->lang = $lang;
return $this;
}
public function getCart()
{
return $this->cart;
}
public function setCart($cart)
{
$this->cart = $cart;
return $this;
}
public function getCustomer()
{
return $this->customer;
}
public function setCustomer($customer)
{
$this->customer = $customer;
return $this;
}
}

View File

@@ -378,6 +378,8 @@ final class TheliaEvents
const ORDER_AFTER_CREATE = "action.order.afterCreate";
const ORDER_BEFORE_PAYMENT = "action.order.beforePayment";
const ORDER_CREATE_MANUAL = "action.order.createManual";
const ORDER_UPDATE_STATUS = "action.order.updateStatus";
const ORDER_UPDATE_DELIVERY_REF = "action.order.updateDeliveryRef";
const ORDER_UPDATE_ADDRESS = "action.order.updateAddress";

View File

@@ -24,14 +24,11 @@
namespace Thelia\Core\Template\Element;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Security\SecurityContext;
use Thelia\Core\Template\Element\Exception\LoopException;
use Thelia\Core\Template\Loop\Argument\Argument;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\Security\SecurityContext;
use Thelia\Type\AlphaNumStringListType;
use Thelia\Type\EnumListType;
use Thelia\Type\EnumType;
use Thelia\Type\TypeCollection;
@@ -67,6 +64,9 @@ abstract class BaseLoop
protected $timestampable = false;
protected $versionable = false;
private static $cacheLoopResult = array();
private static $cacheCount = array();
/**
* Create a new Loop
*
@@ -335,71 +335,79 @@ abstract class BaseLoop
public function count()
{
$count = 0;
if ($this instanceof PropelSearchLoopInterface) {
$searchModelCriteria = $this->buildModelCriteria();
if (null === $searchModelCriteria) {
$count = 0;
} else {
$count = $searchModelCriteria->count();
}
} elseif ($this instanceof ArraySearchLoopInterface) {
$searchArray = $this->buildArray();
if (null === $searchArray) {
$count = 0;
} else {
$count = count($searchArray);
$hash = $this->args->getHash();
if(false === isset(self::$cacheCount[$hash]))
{
$count = 0;
if ($this instanceof PropelSearchLoopInterface) {
$searchModelCriteria = $this->buildModelCriteria();
if (null === $searchModelCriteria) {
$count = 0;
} else {
$count = $searchModelCriteria->count();
}
} elseif ($this instanceof ArraySearchLoopInterface) {
$searchArray = $this->buildArray();
if (null === $searchArray) {
$count = 0;
} else {
$count = count($searchArray);
}
}
self::$cacheCount[$hash] = $count;
}
return $count;
return self::$cacheCount[$hash];
}
/**
* @param $pagination
* @return LoopResult
*/
public function exec(&$pagination, $count = false)
public function exec(&$pagination)
{
if ($this instanceof PropelSearchLoopInterface) {
$searchModelCriteria = $this->buildModelCriteria();
if (null === $searchModelCriteria) {
$results = array();
} else {
$results = $this->search(
$searchModelCriteria,
$pagination
);
$hash = $this->args->getHash();
if(false === isset(self::$cacheLoopResult[$hash]))
{
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
);
}
}
} 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();
}
self::$cacheLoopResult[$hash] = $this->parseResults($loopResult);
}
if ($count) {
return $results ? count($results) : 0;
}
return self::$cacheLoopResult[$hash];
$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()

View File

@@ -89,6 +89,7 @@ class Admin extends BaseLoop implements PropelSearchLoopInterface
->set("FIRSTNAME",$admin->getFirstname())
->set("LASTNAME",$admin->getLastname())
->set("LOGIN",$admin->getLogin())
->set("LOCALE",$admin->getLocale())
;
$loopResult->addRow($loopResultRow);

View File

@@ -56,6 +56,11 @@ class Argument
return $this->type->getFormattedValue($this->value);
}
public function getRawValue()
{
return $this->value;
}
public function setValue($value)
{
if ($value === null) {
@@ -147,4 +152,5 @@ class Argument
$empty
);
}
}

View File

@@ -144,4 +144,20 @@ class ArgumentCollection implements \Iterator
{
reset($this->arguments);
}
public function getHash()
{
$arguments = $this->arguments;
if (array_key_exists('name', $arguments)) {
unset($arguments['name']);
}
$string = '';
foreach ($arguments as $key => $argument) {
$string .= $key.'='.$argument->getRawValue();
}
return md5($string);
}
}

View File

@@ -67,7 +67,8 @@ class FeatureValue extends BaseI18nLoop implements PropelSearchLoopInterface
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
),
'manual'
)
),
Argument::createBooleanTypeArgument('force_return', true)
);
}

View File

@@ -26,17 +26,20 @@ namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Element\SearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\Base\Customer;
use Thelia\Model\CustomerQuery;
use Thelia\Model\Map\CustomerTableMap;
use Thelia\Model\Map\OrderAddressTableMap;
use Thelia\Model\OrderAddressQuery;
use Thelia\Model\OrderQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
use Thelia\Type\TypeCollection;
/**
*
* @package Thelia\Core\Template\Loop
@@ -72,7 +75,14 @@ class Order extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInt
new Argument(
'order',
new TypeCollection(
new Type\EnumListType(array('create-date', 'create-date-reverse'))
new Type\EnumListType(array(
'id', 'id-reverse',
'reference', 'reference-reverse',
'create-date', 'create-date-reverse',
'company', 'company-reverse',
'customer-name', 'customer-name-reverse',
'status', 'status-reverse'
))
),
'create-date-reverse'
)
@@ -165,12 +175,67 @@ class Order extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInt
foreach ($orderers as $orderer) {
switch ($orderer) {
case 'id':
$search->orderById(Criteria::ASC);
break;
case 'id_reverse':
$search->orderById(Criteria::DESC);
break;
case 'reference':
$search->orderByRef(Criteria::ASC);
break;
case 'reference_reverse':
$search->orderByRef(Criteria::DESC);
break;
case "create-date":
$search->orderByCreatedAt(Criteria::ASC);
break;
case "create-date-reverse":
$search->orderByCreatedAt(Criteria::DESC);
break;
case "status":
$search->orderByStatusId(Criteria::ASC);
break;
case "status":
$search->orderByStatusId(Criteria::DESC);
break;
case 'company' :
$search
->joinOrderAddressRelatedByDeliveryOrderAddressId()
->withColumn(OrderAddressTableMap::COMPANY, 'company')
->orderBy('company', Criteria::ASC)
;
break;
case 'companyreverse' :
$search
->joinOrderAddressRelatedByDeliveryOrderAddressId()
->withColumn(OrderAddressTableMap::COMPANY, 'company')
->orderBy('company', Criteria::DESC)
;
break;
case 'customer-name' :
$search
->joinCustomer()
->withColumn(CustomerTableMap::FIRSTNAME, 'firstname')
->withColumn(CustomerTableMap::LASTNAME, 'lastname')
->orderBy('lastname', Criteria::ASC)
->orderBy('firstname', Criteria::ASC)
;
break;
case 'customer-name-reverse' :
$search
->joinCustomer()
->withColumn(CustomerTableMap::FIRSTNAME, 'firstname')
->withColumn(CustomerTableMap::LASTNAME, 'lastname')
->orderBy('lastname', Criteria::DESC)
->orderBy('firstname', Criteria::DESC)
;
break;
}
}

View File

@@ -36,10 +36,12 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Exception\TaxEngineException;
use Thelia\Model\CategoryQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\Map\ProductPriceTableMap;
use Thelia\Model\Map\ProductSaleElementsTableMap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\ProductCategoryQuery;
use Thelia\Model\ProductQuery;
use Thelia\TaxEngine\TaxEngine;
use Thelia\Type\TypeCollection;

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Smarty\Exception\SmartyPluginException;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Tools\DateTimeFormat;
use Thelia\Tools\MoneyFormat;
use Thelia\Tools\NumberFormat;
/**
@@ -135,6 +136,40 @@ class Format extends AbstractSmartyPlugin
$this->getParam($params, "thousands_sep", null)
);
}
/**
*
* display a amount in expected format
*
* available parameters :
* number => int or float number
* decimals => how many decimals format expected
* dec_point => separator for the decimal point
* thousands_sep => thousands separator
* symbol => Currency symbol
*
* ex : {format_money number="1246.12" decimals="1" dec_point="," thousands_sep=" " symbol="€"} will output "1 246,1 €"
*
* @param $params
* @param null $template
* @throws \Thelia\Core\Template\Smarty\Exception\SmartyPluginException
* @return string the expected number formatted
*/
public function formatMoney($params, $template = null)
{
$number = $this->getParam($params, "number", false);
if ($number === false || $number == '') {
return "";
}
return MoneyFormat::getInstance($this->request)->format(
$number,
$this->getParam($params, "decimals", null),
$this->getParam($params, "dec_point", null),
$this->getParam($params, "thousands_sep", null),
$this->getParam($params, "symbol", null)
);
}
/**
* @return an array of SmartyPluginDescriptor
@@ -143,7 +178,8 @@ class Format extends AbstractSmartyPlugin
{
return array(
new SmartyPluginDescriptor("function", "format_date", $this, "formatDate"),
new SmartyPluginDescriptor("function", "format_number", $this, "formatNumber")
);
new SmartyPluginDescriptor("function", "format_number", $this, "formatNumber"),
new SmartyPluginDescriptor("function", "format_money", $this, "formatMoney")
);
}
}

View File

@@ -82,8 +82,9 @@ class Module extends AbstractSmartyPlugin
}
}
if (! empty($content))
if (! empty($content)) {
return $template->fetch(sprintf("string:%s", $content));
}
return "";
}

View File

@@ -31,9 +31,6 @@ use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Element\Exception\ElementNotFoundException;
use Thelia\Core\Template\Element\Exception\InvalidElementException;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Core\Security\SecurityContext;
class TheliaLoop extends AbstractSmartyPlugin
{
protected static $pagination = null;

View File

@@ -59,7 +59,7 @@ use Thelia\Log\Tlog;
class Thelia extends Kernel
{
const THELIA_VERSION = '2.0.0-beta3';
const THELIA_VERSION = '2.0.0-beta4';
public function init()
{
@@ -87,7 +87,7 @@ class Thelia extends Kernel
$con->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, true);
if ($this->isDebug()) {
$serviceContainer->setLogger('defaultLogger', \Thelia\Log\Tlog::getInstance());
//$con->useDebug(true);
$con->useDebug(true);
}
}